diff --git a/src/StatisticsAnalysisTool/Backup/BackupController.cs b/src/StatisticsAnalysisTool/Backup/BackupController.cs index ec0ede75..d5e8ebc3 100644 --- a/src/StatisticsAnalysisTool/Backup/BackupController.cs +++ b/src/StatisticsAnalysisTool/Backup/BackupController.cs @@ -36,7 +36,7 @@ public static bool Save() _isBackupRunning = true; var sourceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.UserDataDirectoryName); - var backupDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.BackupDirectoryName); + var backupDirPath = SettingsController.CurrentSettings.BackupStorageDirectoryPath; if (!DirectoryController.CreateDirectoryWhenNotExists(backupDirPath)) { @@ -80,7 +80,7 @@ private static string GetBackupFileName() public static bool ExistBackupOnSettingConditions() { - var backupDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.BackupDirectoryName); + var backupDirPath = SettingsController.CurrentSettings.BackupStorageDirectoryPath; if (!Directory.Exists(backupDirPath)) { @@ -112,7 +112,7 @@ public static bool ExistBackupOnSettingConditions() public static async Task DeleteOldestBackupsIfNeededAsync() { - var backupDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.BackupDirectoryName); + var backupDirPath = SettingsController.CurrentSettings.BackupStorageDirectoryPath; if (!Directory.Exists(backupDirPath)) { diff --git a/src/StatisticsAnalysisTool/Common/UserSettings/SettingsObject.cs b/src/StatisticsAnalysisTool/Common/UserSettings/SettingsObject.cs index 29b5a5fb..5eba4c5c 100644 --- a/src/StatisticsAnalysisTool/Common/UserSettings/SettingsObject.cs +++ b/src/StatisticsAnalysisTool/Common/UserSettings/SettingsObject.cs @@ -19,6 +19,7 @@ public class SettingsObject public string MainTrackingCharacterName { get; set; } public int BackupIntervalByDays { get; set; } = 1; public int MaximumNumberOfBackups { get; set; } = 10; + public string BackupStorageDirectoryPath { get; set; } public bool IsOpenItemWindowInNewWindowChecked { get; set; } = true; public bool IsInfoWindowShownOnStart { get; set; } = true; public string SelectedAlertSound { get; set; } diff --git a/src/StatisticsAnalysisTool/Common/Validation/PathValidationRule.cs b/src/StatisticsAnalysisTool/Common/Validation/PathValidationRule.cs new file mode 100644 index 00000000..c49d1497 --- /dev/null +++ b/src/StatisticsAnalysisTool/Common/Validation/PathValidationRule.cs @@ -0,0 +1,25 @@ +using System.Globalization; +using System.IO; +using System.Windows.Controls; + +namespace StatisticsAnalysisTool.Common.Validation; + +public class PathValidationRule : ValidationRule +{ + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + string path = value as string; + + if (string.IsNullOrWhiteSpace(path)) + { + return new ValidationResult(false, "Path cannot be empty."); + } + + if (!Directory.Exists(path)) + { + return new ValidationResult(false, "Path does not exist."); + } + + return ValidationResult.ValidResult; + } +} \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Localization/localization.json b/src/StatisticsAnalysisTool/Localization/localization.json index 9e829b49..71cec17e 100644 --- a/src/StatisticsAnalysisTool/Localization/localization.json +++ b/src/StatisticsAnalysisTool/Localization/localization.json @@ -37326,6 +37326,19 @@ "seg": "Select the AlbionOnline folder in the steamapps. Usually found under 'C:\\Program Files\\Steam\\steamapps\\common'" } ] + }, + { + "tuid": "BACKUP_STORAGE_DIRECTORY_PATH", + "tuv": [ + { + "lang": "de-DE", + "seg": "Backup Speicherverzeichnis Pfad" + }, + { + "lang": "en-US", + "seg": "Backup storage directory path" + } + ] } ] } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/Models/TranslationModel/SettingsWindowTranslation.cs b/src/StatisticsAnalysisTool/Models/TranslationModel/SettingsWindowTranslation.cs index 5541c548..49948333 100644 --- a/src/StatisticsAnalysisTool/Models/TranslationModel/SettingsWindowTranslation.cs +++ b/src/StatisticsAnalysisTool/Models/TranslationModel/SettingsWindowTranslation.cs @@ -61,4 +61,5 @@ public class SettingsWindowTranslation public static string AnotherAppToStartPath => LocalizationController.Translation("ANOTHER_APP_TO_START_PATH"); public static string Party => LocalizationController.Translation("PARTY"); public static string DeathAlarmSoundUsed => LocalizationController.Translation("DEATH_ALERT_SOUND_USED"); + public static string BackupStorageDirectoryPath => LocalizationController.Translation("BACKUP_STORAGE_DIRECTORY_PATH"); } \ No newline at end of file diff --git a/src/StatisticsAnalysisTool/UserControls/SettingsControl.xaml b/src/StatisticsAnalysisTool/UserControls/SettingsControl.xaml index 97aeb99b..2dbb0689 100644 --- a/src/StatisticsAnalysisTool/UserControls/SettingsControl.xaml +++ b/src/StatisticsAnalysisTool/UserControls/SettingsControl.xaml @@ -5,9 +5,11 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:viewModels="clr-namespace:StatisticsAnalysisTool.ViewModels" xmlns:common="clr-namespace:StatisticsAnalysisTool.Common" + xmlns:validation="clr-namespace:StatisticsAnalysisTool.Common.Validation" mc:Ignorable="d" d:DesignHeight="1600" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=viewModels:SettingsWindowViewModel}"> + @@ -182,6 +184,24 @@ + +