Added toggleable daily DB backups on OB start (enabled by default in Settings > OB > General).

This commit is contained in:
ruri
2019-10-01 15:55:09 +02:00
parent 294e6f93ca
commit 6e9513ad4c
4 changed files with 21 additions and 0 deletions
+1
View File
@@ -45,6 +45,7 @@ namespace OpenBullet
// Constant file paths
public static string dataBaseFile = @"DB/OpenBullet.db";
public static string dataBaseBackupFile = @"DB/OpenBullet-BackupCopy.db";
public static string obSettingsFile = @"Settings/OBSettings.json";
public static string rlSettingsFile = @"Settings/RLSettings.json";
public static string envFile = @"Settings/Environment.ini";
+17
View File
@@ -116,6 +116,23 @@ namespace OpenBullet
Globals.LogInfo(Components.Main, "Loaded the existing OpenBullet Settings file");
}
// If there is no DB backup or if it's more than 1 day old, back up the DB
try
{
if (Globals.obSettings.General.BackupDB &&
(!File.Exists(Globals.dataBaseBackupFile) ||
(File.Exists(Globals.dataBaseBackupFile) && ((DateTime.Now - File.GetCreationTime(Globals.dataBaseBackupFile)).TotalDays > 1))))
{
File.Delete(Globals.dataBaseBackupFile);
File.Copy(Globals.dataBaseFile, Globals.dataBaseBackupFile);
Globals.LogInfo(Components.Main, "Backed up the DB");
}
}
catch (Exception ex)
{
Globals.LogError(Components.Main, $"Could not backup the DB: {ex.Message}");
}
Topmost = Globals.obSettings.General.AlwaysOnTop;
RunnerManagerPage = new RunnerManager(Globals.obSettings.General.AutoCreateRunner);
@@ -29,6 +29,7 @@
<CheckBox Content="Persist Debugger Log" IsChecked="{Binding PersistDebuggerLog}" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
<CheckBox Content="Disable Syntax Helper" IsChecked="{Binding DisableSyntaxHelper}" VerticalAlignment="Center" VerticalContentAlignment="Center" />
<CheckBox Content="Display Captures Last in Debugger" IsChecked="{Binding DisplayCapturesLast}" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
<CheckBox Content="Backup the Database daily upon start" IsChecked="{Binding BackupDB}" VerticalAlignment="Center" VerticalContentAlignment="Center"/>
</StackPanel>
<StackPanel Grid.Column="1">
@@ -48,6 +48,8 @@ namespace OpenBullet.ViewModels
public bool LogToFile { get { return logToFile; } set { logToFile = value; OnPropertyChanged(); } }
private int logBufferSize = 10000;
public int LogBufferSize { get { return logBufferSize; } set { logBufferSize = value; OnPropertyChanged(); } }
private bool backupDB = true;
public bool BackupDB { get { return backupDB; } set { backupDB = value; OnPropertyChanged(); } }
public void Reset()
{