back up saves in a background thread

This commit is contained in:
Jesse Plamondon-Willard 2019-07-29 13:15:27 -04:00
parent 95f261b1f3
commit 2b4bc2c282
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 8 additions and 4 deletions

View File

@ -12,6 +12,7 @@ These changes have not been released yet.
* Now ignores metadata files/folders like `__MACOSX` and `__folder_managed_by_vortex`. * Now ignores metadata files/folders like `__MACOSX` and `__folder_managed_by_vortex`.
* Now ignores content files like `.txt` or `.png`, which avoids missing-manifest errors in some common cases. * Now ignores content files like `.txt` or `.png`, which avoids missing-manifest errors in some common cases.
* Now detects XNB mods more accurately, and consolidates multi-folder XNB mods. * Now detects XNB mods more accurately, and consolidates multi-folder XNB mods.
* Save Backup now works in the background, to avoid affecting startup time for players with a large number of saves.
* Duplicate-mod errors now show the mod version in each folder. * Duplicate-mod errors now show the mod version in each folder.
* Updated mod compatibility list. * Updated mod compatibility list.
* Fixed mods needing to load custom `Map` assets before the game accesses them (SMAPI will now do so automatically). * Fixed mods needing to load custom `Map` assets before the game accesses them (SMAPI will now do so automatically).

View File

@ -4,6 +4,7 @@ using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using StardewValley; using StardewValley;
namespace StardewModdingAPI.Mods.SaveBackup namespace StardewModdingAPI.Mods.SaveBackup
@ -40,9 +41,10 @@ namespace StardewModdingAPI.Mods.SaveBackup
DirectoryInfo backupFolder = new DirectoryInfo(this.BackupFolder); DirectoryInfo backupFolder = new DirectoryInfo(this.BackupFolder);
backupFolder.Create(); backupFolder.Create();
// back up saves // back up & prune saves
this.CreateBackup(backupFolder); Task
this.PruneBackups(backupFolder, this.BackupsToKeep); .Run(() => this.CreateBackup(backupFolder))
.ContinueWith(backupTask => this.PruneBackups(backupFolder, this.BackupsToKeep));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -68,7 +70,7 @@ namespace StardewModdingAPI.Mods.SaveBackup
// create zip // create zip
// due to limitations with the bundled Mono on Mac, we can't reference System.IO.Compression. // due to limitations with the bundled Mono on Mac, we can't reference System.IO.Compression.
this.Monitor.Log($"Adding {targetFile.Name}...", LogLevel.Trace); this.Monitor.Log($"Backing up saves to {targetFile.FullName}...", LogLevel.Trace);
switch (Constants.TargetPlatform) switch (Constants.TargetPlatform)
{ {
case GamePlatform.Linux: case GamePlatform.Linux:
@ -108,6 +110,7 @@ namespace StardewModdingAPI.Mods.SaveBackup
} }
break; break;
} }
this.Monitor.Log("Backup done!", LogLevel.Trace);
} }
catch (Exception ex) catch (Exception ex)
{ {