mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 10:57:45 +08:00
feat: 在启动时检测额外的DLL文件 (#13850)
* feat: 在启动时检测额外的DLL文件 * chore: 改一下弹窗样式 * chore: 修改检测逻辑与翻译 * chore: 显示一下不属于 maa 的 dll * feat: 启动弹窗都加个图标 * chore: 就要大写就要大写 * chore: MessageBoxHelper --------- Co-authored-by: uye <99072975+ABA2396@users.noreply.github.com>
This commit is contained in:
@@ -74,6 +74,7 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Epilog/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=esource/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Eyjafjalla/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=fastdeploy/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Favourite/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=filetime/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=findstr/@EntryIndexedValue">True</s:Boolean>
|
||||
@@ -137,6 +138,7 @@
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pormpt/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=powrprof/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ppidl/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=ppocr/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prts/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=pwfi/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=qmsg/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
@@ -15,6 +15,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -66,6 +67,35 @@ namespace MaaWpfGui.Main
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
private static extern bool FreeLibrary(IntPtr hModule);
|
||||
|
||||
private static List<string> UnknownDllDetected()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 属于 MAA 的 DLL 列表
|
||||
// 因为经常有人把 MAA 和别的东西解压到一起然后发生 DLL 劫持然后报错,遂检测
|
||||
var maaDlls = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"DirectML.dll",
|
||||
"fastdeploy_ppocr.dll",
|
||||
"MaaCore.dll",
|
||||
"onnxruntime_maa.dll",
|
||||
"opencv_world4_maa.dll",
|
||||
};
|
||||
|
||||
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
var dllFiles = Directory.GetFiles(currentDirectory, "*.dll");
|
||||
|
||||
return dllFiles
|
||||
.Select(Path.GetFileName)
|
||||
.Where(fileName => !maaDlls.Contains(fileName))
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsVCppInstalled()
|
||||
{
|
||||
IntPtr handle = IntPtr.Zero;
|
||||
@@ -191,9 +221,26 @@ namespace MaaWpfGui.Main
|
||||
throw new DirectoryNotFoundException("resource folder not found!");
|
||||
}
|
||||
|
||||
// Debug 模式下 DLL 是未打包的
|
||||
if (maaEnv != "Debug")
|
||||
{
|
||||
var unknownDlls = UnknownDllDetected();
|
||||
if (unknownDlls.Count > 0)
|
||||
{
|
||||
MessageBoxHelper.Show(
|
||||
LocalizationHelper.GetString("UnknownDllDetected") + "\n" + string.Join("\n", unknownDlls),
|
||||
"MAA",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
_logger.Fatal("Unknown DLL(s) detected: {UnknownDlls}", string.Join(", ", unknownDlls));
|
||||
Shutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsVCppInstalled())
|
||||
{
|
||||
var ret = MessageBox.Show(LocalizationHelper.GetString("VC++NotInstalled"), "MAA", MessageBoxButton.OKCancel);
|
||||
var ret = MessageBoxHelper.Show(LocalizationHelper.GetString("VC++NotInstalled"), "MAA", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
||||
if (ret == MessageBoxResult.OK)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
@@ -218,7 +265,7 @@ namespace MaaWpfGui.Main
|
||||
|
||||
if (!IsWritable(AppDomain.CurrentDomain.BaseDirectory))
|
||||
{
|
||||
Task.Run(() => MessageBoxHelper.Show(LocalizationHelper.GetString("SoftwareLocationWarning"), LocalizationHelper.GetString("Warning"), MessageBoxButton.OK, MessageBoxImage.Error));
|
||||
Task.Run(() => MessageBoxHelper.Show(LocalizationHelper.GetString("SoftwareLocationWarning"), LocalizationHelper.GetString("Error"), MessageBoxButton.OK, MessageBoxImage.Error));
|
||||
}
|
||||
|
||||
base.OnStart();
|
||||
@@ -231,7 +278,7 @@ namespace MaaWpfGui.Main
|
||||
|
||||
if (parsedArgs.TryGetValue(ConfigFlag, out string configArgs) && Config(configArgs))
|
||||
{
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +300,7 @@ namespace MaaWpfGui.Main
|
||||
return true;
|
||||
}
|
||||
|
||||
MessageBox.Show(LocalizationHelper.GetString("MultiInstanceUnderSamePath"));
|
||||
MessageBoxHelper.Show(LocalizationHelper.GetString("MultiInstanceUnderSamePath"), "MAA", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return false;
|
||||
}
|
||||
catch (AbandonedMutexException)
|
||||
@@ -264,7 +311,7 @@ namespace MaaWpfGui.Main
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageBox.Show(LocalizationHelper.GetString("MultiInstanceUnderSamePath") + e.Message);
|
||||
MessageBoxHelper.Show(LocalizationHelper.GetString("MultiInstanceUnderSamePath") + e.Message, "MAA", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,12 +1177,13 @@ With save file: farm points through crafting (advanced).
|
||||
<system:String x:Key="ReclamationToolToCraftPlaceholder">Glow Stick</system:String>
|
||||
<!-- !Reclamation -->
|
||||
<!-- Boot -->
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">
|
||||
Detected that Microsoft Visual C++ Redistributable 2015-2022 (x64) is NOT installed or the version is too low.
|
||||
<system:String x:Key="UnknownDllDetected" xml:space="preserve">Unknown DLL files have been detected in the MAA runtime directory, which may cause DLL hijacking and unexpected consequences.
|
||||
Please extract MAA into a separate new folder, or remove any DLL files that do not belong to MAA.
|
||||
</system:String>
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">Detected that Microsoft Visual C++ Redistributable 2015-2022 (x64) is NOT installed or the version is too low.
|
||||
Click "OK" to execute the installation script and exit MAA. Click "Cancel" to exit MAA directly.
|
||||
</system:String>
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">
|
||||
Only one instance can be launched under the same path!
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">Only one instance can be launched under the same path!
|
||||
If you want to run multiple MAA at the same time, please copy the whole MAA and start under different path with the same adb and different connect address.
|
||||
</system:String>
|
||||
<system:String x:Key="SoftwareLocationWarning">The current software location cannot save data, which may cause settings loss or runtime errors. Please move the software to a writable directory. Do not place it in system-protected directories (e.g., Program Files, System32, or Windows directories).</system:String>
|
||||
|
||||
@@ -1177,12 +1177,13 @@ C:\\leidian\\LDPlayer9
|
||||
<system:String x:Key="ReclamationToolToCraftPlaceholder">ケミカルライト</system:String>
|
||||
<!-- !Reclamation -->
|
||||
<!-- Boot -->
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">
|
||||
Microsoft Visual C++ redistributable 2015-2022 (x64) がインストールされていないか、バージョンが低すぎることが検出されました。
|
||||
<system:String x:Key="UnknownDllDetected" xml:space="preserve">MAA の実行ディレクトリに不明な DLL ファイルが検出されました。DLL ハイジャックが発生し、予期しない結果を招く可能性があります。
|
||||
MAA を新しい独立したフォルダーに解凍するか、MAA に属さない DLL ファイルを削除してください。
|
||||
</system:String>
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">Microsoft Visual C++ redistributable 2015-2022 (x64) がインストールされていないか、バージョンが低すぎることが検出されました。
|
||||
「OK」をクリックするとインストールスクリプトが実行され、MAA が終了します。「キャンセル」をクリックすると MAA が直接終了します。
|
||||
</system:String>
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">
|
||||
同じパスの下で起動できるのは1つのインスタンスのみ!
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">同じパスの下で起動できるのは1つのインスタンスのみ!
|
||||
MAA を複数開くには、新しい MAA を他のフォルダにコピーし、異なる MAA、同じ adb、異なるシミュレータアドレスを使用して複数の操作を行うように設定します。
|
||||
</system:String>
|
||||
<system:String x:Key="SoftwareLocationWarning">現在のソフトウェアの場所ではデータを保存できません。設定が失われるか、実行時に問題が発生する可能性があります。書き込み可能なディレクトリに移動してください。システム保護ディレクトリ(Program Files、System32、Windows ディレクトリなど)には配置しないでください。</system:String>
|
||||
|
||||
@@ -1175,12 +1175,13 @@ C:\\leidian\\LDPlayer9
|
||||
<system:String x:Key="ReclamationToolToCraftPlaceholder">형광봉</system:String>
|
||||
<!-- !Reclamation -->
|
||||
<!-- Boot -->
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">
|
||||
Microsoft Visual C++ redistributable 2015-2022(x64) 가 설치되지 않았거나 버전이 너무 낮은 것으로 감지되었습니다..
|
||||
<system:String x:Key="UnknownDllDetected" xml:space="preserve">MAA 실행 디렉터리에서 알 수 없는 DLL 파일이 감지되었습니다. 이는 DLL 하이재킹을 일으켜 예상치 못한 결과를 초래할 수 있습니다.
|
||||
MAA를 독립된 새 폴더에 압축 해제하거나, MAA에 속하지 않는 DLL 파일을 제거해 주십시오.
|
||||
</system:String>
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">Microsoft Visual C++ redistributable 2015-2022(x64) 가 설치되지 않았거나 버전이 너무 낮은 것으로 감지되었습니다..
|
||||
"확인"을 클릭하여 설치 스크립트를 실행하고 MAA를 종료하세요. "취소"를 클릭하여 MAA를 바로 종료하세요.
|
||||
</system:String>
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">
|
||||
동일한 경로에서는 하나의 인스턴스만 실행할 수 있습니다!
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">동일한 경로에서는 하나의 인스턴스만 실행할 수 있습니다!
|
||||
여러 개의 MAA를 동시에 실행하려면 MAA 전체 폴더를 복사한 뒤, 같은 adb를 사용하되 연결 주소는 다르게 설정하여 서로 다른 경로에서 실행하세요.
|
||||
</system:String>
|
||||
<system:String x:Key="SoftwareLocationWarning">현재 소프트웨어 위치에서는 데이터를 저장할 수 없어 설정이 손실되거나 실행 오류가 발생할 수 있습니다. 쓰기 가능한 디렉터리로 이동하십시오. 시스템 보호 디렉터리(예: Program Files, System32 또는 Windows 디렉터리)에 두지 마십시오.</system:String>
|
||||
|
||||
@@ -1177,12 +1177,13 @@ C:\\leidian\\LDPlayer9。\n
|
||||
<system:String x:Key="ReclamationToolToCraftPlaceholder">荧光棒</system:String>
|
||||
<!-- !Reclamation -->
|
||||
<!-- Boot -->
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">
|
||||
检测到 Microsoft Visual C++ Redistributable 2015-2022 (x64) 未安装或版本过低,
|
||||
<system:String x:Key="UnknownDllDetected" xml:space="preserve">检测到 MAA 运行目录下存在未知 DLL 文件,可能导致 DLL 劫持并产生意外后果。
|
||||
请将 MAA 解压到一个独立的新文件夹中,或移除不属于 MAA 的 DLL 文件。
|
||||
</system:String>
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">检测到 Microsoft Visual C++ Redistributable 2015-2022 (x64) 未安装或版本过低,
|
||||
点击 "确定" 执行安装脚本并退出 MAA, 点击 "取消" 将直接退出.
|
||||
</system:String>
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">
|
||||
同一路径下只能启动一个实例!
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">同一路径下只能启动一个实例!
|
||||
如需多开 MAA,请复制一份新的 MAA 到其他文件夹下,并设置使用不同的 MAA,相同的 adb 和不同的模拟器地址进行多开操作。
|
||||
</system:String>
|
||||
<system:String x:Key="SoftwareLocationWarning">当前软件所在的位置无法保存数据,可能会导致设置丢失或运行异常。建议将软件移动到可写目录中运行,请勿放置在系统保护目录(如 Program Files、System32 或 Windows 目录)中。</system:String>
|
||||
|
||||
@@ -1177,12 +1177,13 @@ C:\\leidian\\LDPlayer9。\n
|
||||
<system:String x:Key="ReclamationToolToCraftPlaceholder">螢光棒</system:String>
|
||||
<!-- !Reclamation -->
|
||||
<!-- Boot -->
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">
|
||||
偵測到 Microsoft Visual C++ Redistributable 2015-2022 (x64) 未安裝或版本過低,
|
||||
<system:String x:Key="UnknownDllDetected" xml:space="preserve">檢測到 MAA 執行目錄下存在未知的 DLL 檔案,可能導致 DLL 劫持並產生意外後果。
|
||||
請將 MAA 解壓縮到一個獨立的新資料夾中,或移除不屬於 MAA 的 DLL 檔案。
|
||||
</system:String>
|
||||
<system:String x:Key="VC++NotInstalled" xml:space="preserve">偵測到 Microsoft Visual C++ Redistributable 2015-2022 (x64) 未安裝或版本過低,
|
||||
點擊 "確定" 將執行安裝腳本並退出 MAA,點擊 "取消" 將直接退出 MAA。
|
||||
</system:String>
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">
|
||||
同一路徑下只能啟動一個實例!
|
||||
<system:String x:Key="MultiInstanceUnderSamePath" xml:space="preserve">同一路徑下只能啟動一個實例!
|
||||
如需多開 MAA,請複製一份新的 MAA 到其他資料夾下,並設定使用不同的 MAA,相同的 adb 和不同的模擬器地址進行多開操作。
|
||||
</system:String>
|
||||
<system:String x:Key="SoftwareLocationWarning">目前軟體所在的位置無法儲存資料,可能會導致設定遺失或執行異常。建議將軟體移動到可寫入的目錄中執行,請勿放置在系統保護目錄(如 Program Files、System32 或 Windows 目錄)中。</system:String>
|
||||
|
||||
Reference in New Issue
Block a user