0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-12 16:50:43 -05:00

update clear game settings command

This commit is contained in:
IsWaffle 2023-08-22 18:54:54 -04:00
parent 567e891df1
commit b64aef8953

View File

@ -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);