diff --git a/BetterGenshinImpact/Core/Recorder/KeyMouseRecorderJsonLine.cs b/BetterGenshinImpact/Core/Recorder/KeyMouseRecorderJsonLine.cs index 89327d6d..e4edfdcc 100644 --- a/BetterGenshinImpact/Core/Recorder/KeyMouseRecorderJsonLine.cs +++ b/BetterGenshinImpact/Core/Recorder/KeyMouseRecorderJsonLine.cs @@ -69,7 +69,7 @@ public class KeyMouseRecorderJsonLine StartTimeUnixTimestamp = (startTime - new DateTime(1970, 1, 1)).TotalNanoseconds.ToString("F0") }; var infoJson = JsonSerializer.Serialize(Info, JsonOptions); - File.WriteAllText(Path.Combine(path, "info.json"), infoJson); + File.WriteAllText(Path.Combine(path, $"{folderName}.json"), infoJson); _consumerTask = Task.Run(async () => await ConsumeEventsAsync(path)); } diff --git a/BetterGenshinImpact/View/Pages/KeyMouseRecordPage.xaml b/BetterGenshinImpact/View/Pages/KeyMouseRecordPage.xaml index 69d8c12c..028f3615 100644 --- a/BetterGenshinImpact/View/Pages/KeyMouseRecordPage.xaml +++ b/BetterGenshinImpact/View/Pages/KeyMouseRecordPage.xaml @@ -120,9 +120,9 @@ - + Header="修改名称" />--> diff --git a/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs index 7874565d..7f1ba9b9 100644 --- a/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/KeyMouseRecordPageViewModel.cs @@ -36,7 +36,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation private readonly ISnackbarService _snackbarService; public AllConfig Config { get; set; } - + string fileName = $"{DateTime.Now:yyyyMMddHH_mmssffff}"; public KeyMouseRecordPageViewModel(ISnackbarService snackbarService, IConfigService configService) @@ -92,6 +92,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation Toast.Warning("请先在启动页,启动截图器再使用本功能"); return; } + if (!IsRecording) { IsRecording = true; @@ -156,6 +157,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation { return; } + try { var str = PromptDialog.Prompt("请输入要修改为的名称(实际就是文件名)", "修改名称"); @@ -200,9 +202,26 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation { return; } + try { - File.Delete(Path.Combine(scriptPath, item.Name)); + var path = new FileInfo(item.Path).Directory!.FullName; + // 校验文件夹是否在 scriptPath 下 + if (!path.StartsWith(scriptPath)) + { + _snackbarService.Show( + "删除失败", + $"{path} 删除失败,不在脚本目录下", + ControlAppearance.Danger, + null, + TimeSpan.FromSeconds(3) + ); + return; + } + + // 删除目录 + Directory.Delete(path, true); + _snackbarService.Show( "删除成功", $"{item.Name} 已经被删除", @@ -239,4 +258,4 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation Config.ScriptConfig.ScriptRepoHintDotVisible = false; ScriptRepoUpdater.Instance.OpenLocalRepoInWebView(); } -} +} \ No newline at end of file