mirror of
https://github.com/chylex/Backup-Essentials.git
synced 2025-08-02 09:59:09 +02:00
Made scheduled saving optional
This commit is contained in:
parent
bad72a9e9b
commit
92cd2d059e
BackupEssentials
@ -14,6 +14,7 @@ namespace BackupEssentials.Backup.Data{
|
||||
}
|
||||
|
||||
private static ScheduledUpdate SaveTimer;
|
||||
private static bool IsSetupForSaving = false;
|
||||
|
||||
private static Dictionary<Type,bool> LoadedData = new Dictionary<Type,bool>();
|
||||
|
||||
@ -33,12 +34,8 @@ namespace BackupEssentials.Backup.Data{
|
||||
/// <summary>
|
||||
/// Run this to allow data saving (loading is available automatically).
|
||||
/// </summary>
|
||||
public static void SetupForSaving(){
|
||||
SaveTimer = ScheduledUpdate.Forever(10,() => {
|
||||
Save(true);
|
||||
});
|
||||
|
||||
SaveTimer.Start();
|
||||
public static void SetupForSaving(bool scheduled){
|
||||
IsSetupForSaving = true;
|
||||
|
||||
BackupLocationList.CollectionChanged += Tracker(BackupLocationListTracker);
|
||||
HistoryEntryList.CollectionChanged += Tracker(HistoryEntryListTracker);
|
||||
@ -46,6 +43,14 @@ namespace BackupEssentials.Backup.Data{
|
||||
foreach(Type type in Enum.GetValues(typeof(Type))){
|
||||
LoadedData[type] = false;
|
||||
}
|
||||
|
||||
if (scheduled){
|
||||
SaveTimer = ScheduledUpdate.Forever(10,() => {
|
||||
Save(true);
|
||||
});
|
||||
|
||||
SaveTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
static bool ShouldLoad(Type[] types, Type type){
|
||||
@ -81,7 +86,8 @@ namespace BackupEssentials.Backup.Data{
|
||||
}
|
||||
|
||||
public static void Save(bool force){
|
||||
if (SaveTimer == null)throw new NotSupportedException("DataStorage was not initialized for saving!");
|
||||
if (!IsSetupForSaving)throw new NotSupportedException("DataStorage was not initialized for saving!");
|
||||
else if (SaveTimer == null && !force)throw new NotSupportedException("DataStorage was not initialized for scheduled saving!");
|
||||
|
||||
if (!force){
|
||||
SaveTimer.NeedsUpdate = true;
|
||||
|
@ -30,7 +30,7 @@ namespace BackupEssentials{
|
||||
|
||||
Loaded += (sender, args) => {
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Loaded,new Action(() => {
|
||||
DataStorage.SetupForSaving();
|
||||
DataStorage.SetupForSaving(true);
|
||||
DataStorage.Load();
|
||||
}));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user