diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 7d25a17..7328ca5 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -190,18 +190,32 @@ namespace VHDMounter return; } - // 查找package文件夹 - string packagePath = await vhdManager.FindPackageFolder(); - if (string.IsNullOrEmpty(packagePath)) + // 根据文件名选择目标目录(SDHD -> bin,否则 -> package),忽略大小写 + bool isSDHD = System.IO.Path.GetFileName(vhdPath) + .IndexOf("SDHD", StringComparison.OrdinalIgnoreCase) >= 0; + + string targetFolder; + if (isSDHD) { - OnStatusChanged("未找到package文件夹"); + OnStatusChanged("检测到 SDHD 文件,正在搜索 bin 目录..."); + targetFolder = await vhdManager.FindFolder("bin"); + } + else + { + OnStatusChanged("正在搜索 package 目录..."); + targetFolder = await vhdManager.FindPackageFolder(); + } + + if (string.IsNullOrEmpty(targetFolder)) + { + OnStatusChanged(isSDHD ? "未找到bin目录" : "未找到package文件夹"); await Task.Delay(3000); await SafeShutdown(); return; } // 启动start.bat - bool started = await vhdManager.StartBatchFile(packagePath); + bool started = await vhdManager.StartBatchFile(targetFolder); if (!started) { OnStatusChanged("启动start.bat失败"); @@ -220,7 +234,7 @@ namespace VHDMounter }); // 开始监控和重启循环 - await vhdManager.MonitorAndRestart(packagePath); + await vhdManager.MonitorAndRestart(targetFolder); } catch (Exception ex) { diff --git a/README.md b/README.md index 81b6f93..8d67a26 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ - **键盘操作**:支持方向键选择、回车确认、ESC退出 ### 🔄 自动化运行 -- **程序启动**:自动查找并启动package文件夹中的start.bat +- **程序启动**:根据文件名关键词自动选择启动目录(SDHD → bin,其余 → package),并执行 start.bat(目录名忽略大小写) - **进程监控**:持续监控 `sinmai`、`chusanapp`、`mu3` 相关进程 - **智能重启**:目标进程异常退出时自动重新启动 @@ -70,8 +70,8 @@ dotnet publish --configuration Release --self-contained true --runtime win-x64 3. **自动挂载与启动** - VHD文件挂载到M盘 - - 自动搜索package文件夹 - - 启动start.bat文件 + - 自动搜索启动目录:SDHD → bin,其余 → package(忽略大小写) + - 在上述目录执行 start.bat 文件 4. **后台监控** - 程序最小化到系统托盘 @@ -115,7 +115,8 @@ VHDMounter.exe --debug - `ScanForVHDFiles()` - VHD文件扫描 - `MountVHD()` - VHD挂载操作 - `UnmountVHD()` - VHD卸载操作 -- `FindPackageFolder()` - Package文件夹定位 +- `FindFolder(folderName)` - 通用目录定位(忽略大小写) +- `FindPackageFolder()` - Package文件夹定位(对 `FindFolder("package")` 的封装) - `StartBatchFile()` - 批处理文件启动 - `IsTargetProcessRunning()` - 进程状态检查 @@ -144,7 +145,7 @@ A: 检查VHD文件名是否包含SDEZ、SDHD或SDDT关键词,且文件位于 A: 检查M盘是否被其他程序占用,程序会自动尝试清理但可能需要手动处理。 **Q: start.bat启动失败** -A: 确认package文件夹中存在start.bat文件,且文件具有执行权限。 +A: 确认对应启动目录中存在 start.bat 文件(SDHD: bin;其他关键词: package),且目录名大小写不影响搜索和定位。 **Q: 进程监控不工作** A: 检查目标程序是否正常运行,进程名是否包含预定义的关键词。 diff --git a/VHDManager.cs b/VHDManager.cs index 5752f17..45b8d1b 100644 --- a/VHDManager.cs +++ b/VHDManager.cs @@ -406,9 +406,9 @@ exit"; } } - public async Task FindPackageFolder() + public async Task FindFolder(string folderName) { - StatusChanged?.Invoke("正在搜索package文件夹..."); + StatusChanged?.Invoke($"正在搜索{folderName}文件夹..."); if (!Directory.Exists(TARGET_DRIVE)) { @@ -420,7 +420,7 @@ exit"; { try { - StatusChanged?.Invoke($"开始在 {TARGET_DRIVE} 中搜索package文件夹..."); + StatusChanged?.Invoke($"开始在 {TARGET_DRIVE} 中搜索{folderName}文件夹..."); // 首先检查根目录 var rootDirs = Directory.GetDirectories(TARGET_DRIVE) @@ -434,41 +434,46 @@ exit"; Debug.WriteLine($"根目录文件夹: {dir.Name}"); } - // 检查根目录中是否有package文件夹(不区分大小写) - var packageInRoot = rootDirs.FirstOrDefault(d => - string.Equals(d.Name, "package", StringComparison.OrdinalIgnoreCase)); + // 检查根目录中是否有目标文件夹(不区分大小写) + var targetInRoot = rootDirs.FirstOrDefault(d => + string.Equals(d.Name, folderName, StringComparison.OrdinalIgnoreCase)); - if (packageInRoot != null) + if (targetInRoot != null) { - StatusChanged?.Invoke($"在根目录找到package文件夹: {packageInRoot.Path}"); - return packageInRoot.Path; + StatusChanged?.Invoke($"在根目录找到{folderName}文件夹: {targetInRoot.Path}"); + return targetInRoot.Path; } - // 如果根目录没有,递归搜索所有子目录 - StatusChanged?.Invoke("根目录未找到package文件夹,开始递归搜索..."); + // 如果根目录没有,递归搜索所有子目录(不区分大小写) + StatusChanged?.Invoke($"根目录未找到{folderName}文件夹,开始递归搜索..."); var allDirectories = Directory.GetDirectories(TARGET_DRIVE, "*", SearchOption.AllDirectories) - .Where(d => string.Equals(Path.GetFileName(d), "package", StringComparison.OrdinalIgnoreCase)) + .Where(d => string.Equals(Path.GetFileName(d), folderName, StringComparison.OrdinalIgnoreCase)) .ToList(); - StatusChanged?.Invoke($"递归搜索找到 {allDirectories.Count} 个package文件夹"); + StatusChanged?.Invoke($"递归搜索找到 {allDirectories.Count} 个{folderName}文件夹"); foreach (var dir in allDirectories) { StatusChanged?.Invoke($" 找到: {dir}"); - Debug.WriteLine($"找到package文件夹: {dir}"); + Debug.WriteLine($"找到{folderName}文件夹: {dir}"); } return allDirectories.FirstOrDefault(); } catch (Exception ex) { - StatusChanged?.Invoke($"搜索package文件夹时出错: {ex.Message}"); - Debug.WriteLine($"FindPackageFolder错误: {ex}"); + StatusChanged?.Invoke($"搜索{folderName}文件夹时出错: {ex.Message}"); + Debug.WriteLine($"FindFolder错误: {ex}"); return null; } }); } + public async Task FindPackageFolder() + { + return await FindFolder("package"); + } + public async Task StartBatchFile(string packagePath) { var startBatPath = Path.Combine(packagePath, "start.bat"); diff --git a/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs b/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs new file mode 100644 index 0000000..0e18c2b --- /dev/null +++ b/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] diff --git a/obj/Debug/net6.0/VHDDebugger.AssemblyInfo.cs b/obj/Debug/net6.0/VHDDebugger.AssemblyInfo.cs new file mode 100644 index 0000000..8ad901f --- /dev/null +++ b/obj/Debug/net6.0/VHDDebugger.AssemblyInfo.cs @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +using System; +using System.Reflection; + +[assembly: System.Reflection.AssemblyCompanyAttribute("VHDDebugger")] +[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] +[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+52f9fb8a1c07b0e8fc7830b5c48ff0509ddac348")] +[assembly: System.Reflection.AssemblyProductAttribute("VHDDebugger")] +[assembly: System.Reflection.AssemblyTitleAttribute("VHDDebugger")] +[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] + +// 由 MSBuild WriteCodeFragment 类生成。 + diff --git a/obj/Debug/net6.0/VHDDebugger.AssemblyInfoInputs.cache b/obj/Debug/net6.0/VHDDebugger.AssemblyInfoInputs.cache new file mode 100644 index 0000000..b1bb0c0 --- /dev/null +++ b/obj/Debug/net6.0/VHDDebugger.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +52222945a691464abc7f64ec264d357a0ae3c0a3b0665818b20c4cbc42dc8bed diff --git a/obj/Debug/net6.0/VHDDebugger.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net6.0/VHDDebugger.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..13a59b1 --- /dev/null +++ b/obj/Debug/net6.0/VHDDebugger.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,15 @@ +is_global = true +build_property.TargetFramework = net6.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = VHDDebugger +build_property.ProjectDir = /Users/ningxi/Desktop/vhdmount/ +build_property.EnableComHosting = +build_property.EnableGeneratedComInterfaceComImportInterop = +build_property.EffectiveAnalysisLevelStyle = 6.0 +build_property.EnableCodeStyleSeverity =