Add startup drill tape parameter cleanup
This commit is contained in:
38
App.xaml.cs
38
App.xaml.cs
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user