Skip to content

Commit

Permalink
Added backup storage directory change setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Oct 12, 2024
1 parent 46a4045 commit bdc11cd
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/StatisticsAnalysisTool/Backup/BackupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
25 changes: 25 additions & 0 deletions src/StatisticsAnalysisTool/Common/Validation/PathValidationRule.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
13 changes: 13 additions & 0 deletions src/StatisticsAnalysisTool/Localization/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
22 changes: 21 additions & 1 deletion src/StatisticsAnalysisTool/UserControls/SettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">

<Grid IsVisibleChanged="ReloadSettings_OnIsVisibleChanged">
<Grid Margin="0,0,0,44">
<ScrollViewer>
Expand Down Expand Up @@ -182,6 +184,24 @@
<ComboBox ItemsSource="{Binding MaximumNumberOfBackups}" SelectedItem="{Binding MaximumNumberOfBackupsSelection}"
IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Name" SelectedValuePath="Value" HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Height="26" />
</DockPanel>
<DockPanel Margin="0,5,0,0">
<Label Content="Backup Storage Directory Path" MinWidth="300" VerticalAlignment="Top" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<TextBox Height="40" Width="400" TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,0,5,0">
<TextBox.Text>
<Binding Path="BackupStorageDirectoryPath" UpdateSourceTrigger="PropertyChanged" ValidatesOnExceptions="True" NotifyOnValidationError="True">
<Binding.ValidationRules>
<validation:PathValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
<TextBox.ToolTip>
<Binding Path="(Validation.Errors)[0].ErrorContent" RelativeSource="{RelativeSource Self}" />
</TextBox.ToolTip>
</TextBox>
<Button Content="{Binding Translation.Reset, FallbackValue=RESET}" Height="24" MaxWidth="100" VerticalAlignment="Center" Click="ResetBackupStorageDirPath_Click" />
</StackPanel>
</DockPanel>
<DockPanel Margin="0,5,0,0">
<Label MinWidth="300" VerticalAlignment="Top" />
<Button Content="{Binding Translation.BackupNow, FallbackValue=BACKUP__NOW}" MinWidth="120" IsEnabled="{Binding IsBackupNowButtonEnabled}"
Expand All @@ -194,4 +214,4 @@
<Button Content="{Binding Translation.Save, FallbackValue=SAVE}" HorizontalAlignment="Left" Margin="5,10,0,10" Width="110" Click="BtnSave_Click" />
</Grid>
</Grid>
</UserControl>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ private void ResetPlayerSelectionWithSameNameInDb_Click(object sender, RoutedEve
_settingsWindowViewModel.ResetPlayerSelectionWithSameNameInDb();
}

private void ResetBackupStorageDirPath_Click(object sender, RoutedEventArgs e)
{
_settingsWindowViewModel.ResetBackupStorageDirPath();
}

private void ResetPacketFilter_Click(object sender, RoutedEventArgs e)
{
_settingsWindowViewModel.ResetPacketFilter();
Expand Down
47 changes: 47 additions & 0 deletions src/StatisticsAnalysisTool/ViewModels/SettingsWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using StatisticsAnalysisTool.Models.TranslationModel;
using StatisticsAnalysisTool.Network.PacketProviders;
using StatisticsAnalysisTool.Notification;
using StatisticsAnalysisTool.Properties;
using StatisticsAnalysisTool.Views;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class SettingsWindowViewModel : BaseViewModel
private BitmapImage _anotherAppToStartExeIcon;
private string _packetFilter;
private Visibility _packetFilterVisibility = Visibility.Collapsed;
private string _backupStorageDirectoryPath;

public SettingsWindowViewModel()
{
Expand All @@ -82,6 +84,10 @@ private void InitializeSettings()
InitMaxAmountOfBackups(MaximumNumberOfBackups);
MaximumNumberOfBackupsSelection = MaximumNumberOfBackups.FirstOrDefault(x => x.Value == SettingsController.CurrentSettings.MaximumNumberOfBackups);

// Backup storage dir path
BackupStorageDirectoryPath = string.IsNullOrEmpty(SettingsController.CurrentSettings.BackupStorageDirectoryPath)
? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.BackupDirectoryName) : SettingsController.CurrentSettings.BackupStorageDirectoryPath;

// Another app to start path
AnotherAppToStartPath = SettingsController.CurrentSettings.AnotherAppToStartPath;

Expand Down Expand Up @@ -141,6 +147,7 @@ public void SaveSettings()
SettingsController.CurrentSettings.IsSuggestPreReleaseUpdatesActive = IsSuggestPreReleaseUpdatesActive;
SettingsController.CurrentSettings.ExactMatchPlayerNamesLineNumber = PlayerSelectionWithSameNameInDb;

SetBackupStorageDirPathIfExist(BackupStorageDirectoryPath);
SetAppSettingsAndTranslations();
SetNaviTabVisibilities(mainWindowViewModel);
SetNotificationFilter();
Expand Down Expand Up @@ -333,6 +340,35 @@ public static void OpenEventValidationWindow()
}
}

private void SetBackupStorageDirPathIfExist(string newPath)
{
if (string.IsNullOrWhiteSpace(newPath))
{
BackupStorageDirectoryPath = SettingsController.CurrentSettings.BackupStorageDirectoryPath;
return;
}

if (!Directory.Exists(newPath))
{
BackupStorageDirectoryPath = SettingsController.CurrentSettings.BackupStorageDirectoryPath;
return;
}

SettingsController.CurrentSettings.BackupStorageDirectoryPath = newPath;
}

public void ResetBackupStorageDirPath()
{
string defaultPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.BackupDirectoryName);

if (BackupStorageDirectoryPath == defaultPath)
{
return;
}

BackupStorageDirectoryPath = defaultPath;
}

#region Inits

private void InitLanguageFiles()
Expand Down Expand Up @@ -610,6 +646,17 @@ public ObservableCollection<SettingDataInformation> MaximumNumberOfBackups
}
}

public string BackupStorageDirectoryPath
{
get => _backupStorageDirectoryPath;
set
{
_backupStorageDirectoryPath = value;
OnPropertyChanged();
}
}


public SettingDataInformation RefreshRatesSelection
{
get => _refreshRatesSelection;
Expand Down

0 comments on commit bdc11cd

Please sign in to comment.