feat: 添加VHD调试工具用于扫描和测试VHD文件
添加调试工具用于扫描驱动器中的VHD文件并测试特定文件 包含批处理脚本、C#项目文件和调试程序实现
This commit is contained in:
+105
-27
@@ -7,72 +7,150 @@ on:
|
||||
branches: [ main, master ]
|
||||
release:
|
||||
types: [ published ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
DOTNET_VERSION: '6.0.x'
|
||||
BUILD_CONFIGURATION: 'Release'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
|
||||
outputs:
|
||||
version: ${{ steps.version.outputs.version }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '6.0.x'
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Get version
|
||||
id: version
|
||||
run: |
|
||||
$version = "1.0.0"
|
||||
if ($env:GITHUB_REF -like "refs/tags/*") {
|
||||
$version = $env:GITHUB_REF -replace "refs/tags/v?", ""
|
||||
} elseif ($env:GITHUB_EVENT_NAME -eq "pull_request") {
|
||||
$version = "$version-pr${{ github.event.number }}"
|
||||
} else {
|
||||
$shortSha = $env:GITHUB_SHA.Substring(0, 7)
|
||||
$version = "$version-$shortSha"
|
||||
}
|
||||
echo "version=$version" >> $env:GITHUB_OUTPUT
|
||||
echo "Version: $version"
|
||||
|
||||
- name: Cache NuGet packages
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-nuget-
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
run: dotnet restore --verbosity minimal
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
run: dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore --verbosity minimal
|
||||
|
||||
- name: Test
|
||||
run: dotnet test --no-build --verbosity normal
|
||||
run: dotnet test --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --verbosity normal --logger trx --results-directory TestResults
|
||||
continue-on-error: true
|
||||
|
||||
- name: Publish Test Results
|
||||
uses: dorny/test-reporter@v1
|
||||
if: always()
|
||||
with:
|
||||
name: Test Results
|
||||
path: TestResults/*.trx
|
||||
reporter: dotnet-trx
|
||||
fail-on-error: false
|
||||
|
||||
- name: Publish Windows x64
|
||||
run: dotnet publish --configuration Release --runtime win-x64 --self-contained true --output ./publish/win-x64
|
||||
run: |
|
||||
dotnet publish VHDMounter.csproj `
|
||||
--configuration ${{ env.BUILD_CONFIGURATION }} `
|
||||
--runtime win-x64 `
|
||||
--self-contained true `
|
||||
--output ./publish/win-x64 `
|
||||
-p:PublishSingleFile=true `
|
||||
-p:IncludeNativeLibrariesForSelfExtract=true `
|
||||
-p:Version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: Publish Windows x86
|
||||
run: dotnet publish --configuration Release --runtime win-x86 --self-contained true --output ./publish/win-x86
|
||||
run: |
|
||||
dotnet publish VHDMounter.csproj `
|
||||
--configuration ${{ env.BUILD_CONFIGURATION }} `
|
||||
--runtime win-x86 `
|
||||
--self-contained true `
|
||||
--output ./publish/win-x86 `
|
||||
-p:PublishSingleFile=true `
|
||||
-p:IncludeNativeLibrariesForSelfExtract=true `
|
||||
-p:Version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: Upload Windows x64 artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: VHDMounter-win-x64
|
||||
name: VHDMounter-win-x64-${{ steps.version.outputs.version }}
|
||||
path: ./publish/win-x64/
|
||||
retention-days: 30
|
||||
|
||||
- name: Upload Windows x86 artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: VHDMounter-win-x86
|
||||
name: VHDMounter-win-x86-${{ steps.version.outputs.version }}
|
||||
path: ./publish/win-x86/
|
||||
retention-days: 30
|
||||
|
||||
- name: Create Release Assets
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
Compress-Archive -Path ./publish/win-x64/* -DestinationPath VHDMounter-win-x64.zip
|
||||
Compress-Archive -Path ./publish/win-x86/* -DestinationPath VHDMounter-win-x86.zip
|
||||
$version = "${{ steps.version.outputs.version }}"
|
||||
Compress-Archive -Path ./publish/win-x64/* -DestinationPath "VHDMounter-v$version-win-x64.zip" -Force
|
||||
Compress-Archive -Path ./publish/win-x86/* -DestinationPath "VHDMounter-v$version-win-x86.zip" -Force
|
||||
|
||||
# Create checksums
|
||||
$x64Hash = (Get-FileHash "VHDMounter-v$version-win-x64.zip" -Algorithm SHA256).Hash
|
||||
$x86Hash = (Get-FileHash "VHDMounter-v$version-win-x86.zip" -Algorithm SHA256).Hash
|
||||
|
||||
@"
|
||||
# VHD Mounter v$version - Checksums
|
||||
|
||||
## SHA256 Checksums
|
||||
|
||||
- **VHDMounter-v$version-win-x64.zip**: `$x64Hash`
|
||||
- **VHDMounter-v$version-win-x86.zip**: `$x86Hash`
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download the appropriate version for your system (x64 or x86)
|
||||
2. Extract the ZIP file
|
||||
3. Run `run_as_admin.bat` to start the application with administrator privileges
|
||||
|
||||
## Requirements
|
||||
|
||||
- Windows 10/11
|
||||
- Administrator privileges (required for VHD mounting)
|
||||
- .NET 6.0 Runtime (included in self-contained builds)
|
||||
"@ | Out-File -FilePath "CHECKSUMS.md" -Encoding UTF8
|
||||
|
||||
- name: Upload Release Assets
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./VHDMounter-win-x64.zip
|
||||
asset_name: VHDMounter-win-x64.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
- name: Upload Release Assets x86
|
||||
if: github.event_name == 'release'
|
||||
uses: actions/upload-release-asset@v1
|
||||
files: |
|
||||
VHDMounter-v${{ steps.version.outputs.version }}-win-x64.zip
|
||||
VHDMounter-v${{ steps.version.outputs.version }}-win-x86.zip
|
||||
CHECKSUMS.md
|
||||
generate_release_notes: true
|
||||
draft: false
|
||||
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./VHDMounter-win-x86.zip
|
||||
asset_name: VHDMounter-win-x86.zip
|
||||
asset_content_type: application/zip
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VHDMounter
|
||||
{
|
||||
class DebugProgram
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("VHD Mounter 调试工具");
|
||||
Console.WriteLine("===================");
|
||||
|
||||
var debugger = new VHDDebugger();
|
||||
|
||||
// 测试特定文件
|
||||
var testFile = @"C:\SDEZ_1.56.00_20250317134137.vhd";
|
||||
debugger.TestSpecificFile(testFile);
|
||||
|
||||
Console.WriteLine("\n按任意键开始扫描所有驱动器...");
|
||||
Console.ReadKey();
|
||||
|
||||
// 扫描所有VHD文件
|
||||
var vhdFiles = await debugger.DebugScanVHDFiles();
|
||||
|
||||
Console.WriteLine("\n=== 总结 ===");
|
||||
if (vhdFiles.Count > 0)
|
||||
{
|
||||
Console.WriteLine($"✅ 成功找到 {vhdFiles.Count} 个符合条件的VHD文件");
|
||||
Console.WriteLine("\n如果主程序仍然找不到文件,可能的原因:");
|
||||
Console.WriteLine("1. 程序没有以管理员身份运行");
|
||||
Console.WriteLine("2. 文件被其他程序占用");
|
||||
Console.WriteLine("3. 权限不足");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("❌ 未找到符合条件的VHD文件");
|
||||
Console.WriteLine("\n请检查:");
|
||||
Console.WriteLine("1. VHD文件是否存在");
|
||||
Console.WriteLine("2. 文件名是否包含 SDEZ、SDHD 或 SDDT 关键词");
|
||||
Console.WriteLine("3. 文件扩展名是否为 .vhd");
|
||||
}
|
||||
|
||||
Console.WriteLine("\n按任意键退出...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -53,13 +53,23 @@ namespace VHDMounter
|
||||
{
|
||||
isProcessing = true;
|
||||
|
||||
// 调试:测试特定文件
|
||||
var testFile = @"C:\SDEZ_1.56.00_20250317134137.vhd";
|
||||
if (System.IO.File.Exists(testFile))
|
||||
{
|
||||
bool isValid = vhdManager.IsVHDFileValid(testFile);
|
||||
OnStatusChanged($"测试文件 {testFile}: {(isValid ? "符合条件" : "不符合条件")}");
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
|
||||
// 扫描VHD文件
|
||||
var vhdFiles = await vhdManager.ScanForVHDFiles();
|
||||
|
||||
if (vhdFiles.Count == 0)
|
||||
{
|
||||
OnStatusChanged("未找到符合条件的VHD文件");
|
||||
await Task.Delay(3000);
|
||||
OnStatusChanged("请检查文件名是否包含SDEZ、SDHD或SDDT关键词");
|
||||
await Task.Delay(5000);
|
||||
Application.Current.Shutdown();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VHDMounter
|
||||
{
|
||||
public class VHDDebugger
|
||||
{
|
||||
private readonly string[] TARGET_KEYWORDS = { "SDEZ", "SDHD", "SDDT" };
|
||||
|
||||
public async Task<List<string>> DebugScanVHDFiles()
|
||||
{
|
||||
Console.WriteLine("=== VHD文件扫描调试 ===");
|
||||
var vhdFiles = new List<string>();
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var drives = DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveType == DriveType.Fixed);
|
||||
Console.WriteLine($"找到 {drives.Count()} 个可用驱动器");
|
||||
|
||||
foreach (var drive in drives)
|
||||
{
|
||||
Console.WriteLine($"\n正在扫描驱动器: {drive.Name}");
|
||||
Console.WriteLine($"驱动器类型: {drive.DriveType}");
|
||||
Console.WriteLine($"可用空间: {drive.AvailableFreeSpace / (1024 * 1024 * 1024)} GB");
|
||||
|
||||
try
|
||||
{
|
||||
// 只扫描根目录
|
||||
Console.WriteLine("扫描根目录...");
|
||||
var allVhdFiles = Directory.GetFiles(drive.RootDirectory.FullName, "*.vhd", SearchOption.TopDirectoryOnly);
|
||||
Console.WriteLine($"根目录找到 {allVhdFiles.Length} 个.vhd文件");
|
||||
|
||||
foreach (var file in allVhdFiles)
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
var isMatch = TARGET_KEYWORDS.Any(keyword => fileName.ToUpper().Contains(keyword));
|
||||
Console.WriteLine($" 文件: {fileName} - {(isMatch ? "匹配" : "不匹配")}");
|
||||
|
||||
if (isMatch)
|
||||
{
|
||||
vhdFiles.Add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"扫描驱动器 {drive.Name} 时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"\n=== 扫描结果 ===");
|
||||
Console.WriteLine($"共找到 {vhdFiles.Count} 个符合条件的VHD文件:");
|
||||
foreach (var file in vhdFiles)
|
||||
{
|
||||
Console.WriteLine($" {file}");
|
||||
}
|
||||
});
|
||||
|
||||
return vhdFiles;
|
||||
}
|
||||
|
||||
public void TestSpecificFile(string filePath)
|
||||
{
|
||||
Console.WriteLine($"\n=== 测试特定文件 ===");
|
||||
Console.WriteLine($"文件路径: {filePath}");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Console.WriteLine("❌ 文件不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("✅ 文件存在");
|
||||
|
||||
var fileName = Path.GetFileName(filePath).ToUpper();
|
||||
Console.WriteLine($"文件名: {fileName}");
|
||||
Console.WriteLine($"目标关键词: {string.Join(", ", TARGET_KEYWORDS)}");
|
||||
|
||||
foreach (var keyword in TARGET_KEYWORDS)
|
||||
{
|
||||
bool contains = fileName.Contains(keyword);
|
||||
Console.WriteLine($" 包含 '{keyword}': {(contains ? "是" : "否")}");
|
||||
}
|
||||
|
||||
bool isValid = TARGET_KEYWORDS.Any(keyword => fileName.Contains(keyword));
|
||||
Console.WriteLine($"\n结果: {(isValid ? "✅ 符合条件" : "❌ 不符合条件")}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<StartupObject>VHDMounter.DebugProgram</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="VHDDebugger.cs" />
|
||||
<Compile Include="DebugProgram.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+46
-3
@@ -16,6 +16,34 @@ namespace VHDMounter
|
||||
|
||||
public event Action<string> StatusChanged;
|
||||
public event Action<List<string>> VHDFilesFound;
|
||||
|
||||
// 调试方法:检查特定文件是否符合条件
|
||||
public bool IsVHDFileValid(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Debug.WriteLine($"文件不存在: {filePath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var fileName = Path.GetFileName(filePath).ToUpper();
|
||||
var isValid = TARGET_KEYWORDS.Any(keyword => fileName.Contains(keyword));
|
||||
|
||||
Debug.WriteLine($"检查文件: {filePath}");
|
||||
Debug.WriteLine($"文件名: {fileName}");
|
||||
Debug.WriteLine($"是否包含关键词: {isValid}");
|
||||
Debug.WriteLine($"关键词: {string.Join(", ", TARGET_KEYWORDS)}");
|
||||
|
||||
return isValid;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"检查文件时出错: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<string>> ScanForVHDFiles()
|
||||
{
|
||||
@@ -30,18 +58,33 @@ namespace VHDMounter
|
||||
{
|
||||
try
|
||||
{
|
||||
var files = Directory.GetFiles(drive.RootDirectory.FullName, "*.vhd", SearchOption.AllDirectories)
|
||||
StatusChanged?.Invoke($"正在扫描驱动器 {drive.Name} 根目录...");
|
||||
|
||||
// 只扫描根目录
|
||||
var rootFiles = Directory.GetFiles(drive.RootDirectory.FullName, "*.vhd", SearchOption.TopDirectoryOnly)
|
||||
.Where(f => TARGET_KEYWORDS.Any(keyword => Path.GetFileName(f).ToUpper().Contains(keyword)))
|
||||
.ToList();
|
||||
|
||||
vhdFiles.AddRange(files);
|
||||
vhdFiles.AddRange(rootFiles);
|
||||
Debug.WriteLine($"在 {drive.Name} 根目录找到 {rootFiles.Count} 个符合条件的VHD文件");
|
||||
|
||||
foreach (var file in rootFiles)
|
||||
{
|
||||
Debug.WriteLine($" 找到: {Path.GetFileName(file)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 忽略无法访问的目录
|
||||
Debug.WriteLine($"扫描驱动器 {drive.Name} 时出错: {ex.Message}");
|
||||
StatusChanged?.Invoke($"扫描驱动器 {drive.Name} 时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
StatusChanged?.Invoke($"扫描完成,共找到 {vhdFiles.Count} 个VHD文件");
|
||||
foreach (var file in vhdFiles)
|
||||
{
|
||||
Debug.WriteLine($"找到VHD文件: {file}");
|
||||
}
|
||||
});
|
||||
|
||||
return vhdFiles;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
echo VHD Mounter 调试工具
|
||||
echo ==================
|
||||
|
||||
echo 正在编译调试工具...
|
||||
dotnet build VHDDebugger.csproj --configuration Release
|
||||
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo.
|
||||
echo 编译成功!正在启动调试工具...
|
||||
echo.
|
||||
dotnet run --project VHDDebugger.csproj --configuration Release
|
||||
) else (
|
||||
echo 编译失败!
|
||||
pause
|
||||
)
|
||||
|
||||
echo.
|
||||
echo 调试完成
|
||||
pause
|
||||
Reference in New Issue
Block a user