From b64aef89534e0ca41502633e4ecaf59e8f9b48a1 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Tue, 22 Aug 2023 18:54:54 -0400 Subject: [PATCH] update clear game settings command --- .../ViewModels/SettingsViewModel.cs | 73 ++----------------- 1 file changed, 8 insertions(+), 65 deletions(-) diff --git a/project/Aki.Launcher/ViewModels/SettingsViewModel.cs b/project/Aki.Launcher/ViewModels/SettingsViewModel.cs index e23ce4c..ea685a4 100644 --- a/project/Aki.Launcher/ViewModels/SettingsViewModel.cs +++ b/project/Aki.Launcher/ViewModels/SettingsViewModel.cs @@ -76,76 +76,19 @@ namespace Aki.Launcher.ViewModels public async Task ClearGameSettingsCommand() { + var SPTSettingsDir = new DirectoryInfo(Path.Join(LauncherSettingsProvider.Instance.GamePath, "user", "sptsettings")); - bool BackupAndRemove(string backupFolderPath, FileInfo file) + try { - try - { - file.Refresh(); + SPTSettingsDir.Delete(true); - //if for some reason the file no longer exists /shrug - if (!file.Exists) - { - return false; - } - - //create backup dir and copy file - Directory.CreateDirectory(backupFolderPath); - - string newFilePath = Path.Combine(backupFolderPath, $"{file.Name}_{DateTime.Now.ToString("MM-dd-yyyy_hh-mm-ss-tt")}.bak"); - - File.Copy(file.FullName, newFilePath); - - //copy check - if (!File.Exists(newFilePath)) - { - return false; - } - - //delete old file - file.Delete(); - } - catch (Exception ex) - { - LogManager.Instance.Exception(ex); - } - - //delete check - if (file.Exists) - { - return false; - } - - return true; + Directory.CreateDirectory(SPTSettingsDir.FullName); } - - string EFTSettingsFolder = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Escape from Tarkov"); - string backupFolderPath = Path.Combine(EFTSettingsFolder, "Backups"); - - if (Directory.Exists(EFTSettingsFolder)) + catch(Exception ex) { - FileInfo local_ini = new FileInfo(Path.Combine(EFTSettingsFolder, "local.ini")); - FileInfo shared_ini = new FileInfo(Path.Combine(EFTSettingsFolder, "shared.ini")); - - string Message = string.Format(LocalizationProvider.Instance.clear_game_settings_warning, backupFolderPath); - ConfirmationDialogViewModel confirmDelete = new ConfirmationDialogViewModel(null, Message, LocalizationProvider.Instance.clear_game_settings, LocalizationProvider.Instance.cancel); - - var confirmation = await ShowDialog(confirmDelete); - - if (confirmation is bool proceed && !proceed) - { - return; - } - - bool localSucceeded = BackupAndRemove(backupFolderPath, local_ini); - bool sharedSucceeded = BackupAndRemove(backupFolderPath, shared_ini); - - //if one fails, I'm considering it bad. Send failed notification. - if (!localSucceeded || !sharedSucceeded) - { - SendNotification("", LocalizationProvider.Instance.clear_game_settings_failed, Avalonia.Controls.Notifications.NotificationType.Error); - return; - } + SendNotification("", ex.Message, Avalonia.Controls.Notifications.NotificationType.Error); + LogManager.Instance.Exception(ex); + return; } SendNotification("", LocalizationProvider.Instance.clear_game_settings_succeeded, Avalonia.Controls.Notifications.NotificationType.Success);