Add startup drill tape parameter cleanup

This commit is contained in:
2026-05-21 12:49:19 +08:00
parent 21fc6d4c4c
commit 951486202e
4 changed files with 212 additions and 5 deletions

View File

@@ -34,7 +34,8 @@ namespace DrillTools
// 防止选择窗口关闭后触发 OnLastWindowClose 导致应用退出
ShutdownMode = ShutdownMode.OnExplicitShutdown;
var selectionWindow = new StartupSelectionWindow(filePath);
bool canClearParameters = CanClearDrillTapeParameters(filePath);
var selectionWindow = new StartupSelectionWindow(filePath, canClearParameters);
selectionWindow.ShowDialog();
switch (selectionWindow.SelectedAction)
@@ -47,6 +48,10 @@ namespace DrillTools
PerformHeadlessExport(filePath);
Shutdown();
break;
case StartupAction.ClearParameters:
PerformParameterCleanup(filePath);
Shutdown();
break;
default:
Shutdown();
break;
@@ -97,6 +102,37 @@ namespace DrillTools
}
}
private static bool CanClearDrillTapeParameters(string filePath)
{
try
{
string content = CommandTypeFileReader.ReadAllText(filePath);
return DrillTapeParameterCleaner.CanClearParameters(content);
}
catch
{
return false;
}
}
private static void PerformParameterCleanup(string filePath)
{
try
{
DrillTapeParameterCleaner.ClearParametersAndSave(filePath);
System.Windows.MessageBox.Show(
$"参数已清空,原文件已备份为:\n{Path.GetFileName(filePath)}.bak",
"清空参数完成",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"清空参数失败:\n{ex.Message}",
"错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
/// <summary>
/// 验证是否为有效的钻带文件
/// </summary>