From 307bf6ce55e8880f0e0382cb678d7fcc6c74c11e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 19 Aug 2018 21:08:58 -0400 Subject: [PATCH] adjust SaveBackup mod to simplify installer logic (#583) --- docs/release-notes.md | 4 +++ src/SMAPI.Installer/InteractiveInstaller.cs | 30 ++----------------- .../Framework/ModConfig.cs | 9 ------ src/SMAPI.Mods.SaveBackup/ModEntry.cs | 13 ++++---- .../StardewModdingAPI.Mods.SaveBackup.csproj | 3 +- 5 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 src/SMAPI.Mods.SaveBackup/Framework/ModConfig.cs diff --git a/docs/release-notes.md b/docs/release-notes.md index c742204e..7a30b0b6 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,7 @@ * For players: * Added support for subfolders under `Mods`, for players who want to organise their mods. * Moved most SMAPI files into a `smapi-internal` subfolder. + * Moved save backups into a `save-backups` subfolder (instead of `Mods/SaveBackup/backups`). * Updated compatibility list. * For modders: @@ -12,6 +13,9 @@ * Fixed `IContentPack.ReadJsonFile` allowing non-relative paths. * **Breaking change:** most SMAPI files have been moved into a `smapi-internal` subfolder. This won't affect compiled mods, but you'll need to update the mod build config NuGet package when compiling mods. +* For SMAPI developers: + * Adjusted `SaveBackup` mod to make it easier to account for custom mod subfolders in the installer. + ## 2.7 * For players: * Updated for Stardew Valley 1.3.28. diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index f9e1ff94..a92edadf 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -22,12 +22,6 @@ namespace StardewModdingApi.Installer /// The name of the installer file in the package. private readonly string InstallerFileName = "install.exe"; - /// Mod files which shouldn't be deleted when deploying bundled mods (mod folder name => file names). - private readonly IDictionary> ProtectBundledFiles = new Dictionary>(StringComparer.InvariantCultureIgnoreCase) - { - ["SaveBackup"] = new HashSet(new[] { "backups", "config.json" }, StringComparer.InvariantCultureIgnoreCase) - }; - /// The value that represents Windows 7. private readonly Version Windows7Version = new Version(6, 1); @@ -474,18 +468,6 @@ namespace StardewModdingApi.Installer { this.PrintDebug("Adding bundled mods..."); - // special case: rename Omegasis' SaveBackup mod - { - DirectoryInfo oldFolder = new DirectoryInfo(Path.Combine(paths.ModsDir.FullName, "SaveBackup")); - DirectoryInfo newFolder = new DirectoryInfo(Path.Combine(paths.ModsDir.FullName, "AdvancedSaveBackup")); - FileInfo manifest = new FileInfo(Path.Combine(oldFolder.FullName, "manifest.json")); - if (manifest.Exists && !newFolder.Exists && File.ReadLines(manifest.FullName).Any(p => p.IndexOf("Omegasis", StringComparison.InvariantCultureIgnoreCase) != -1)) - { - this.PrintDebug($" moving {oldFolder.Name} to {newFolder.Name}..."); - this.Move(oldFolder, newFolder.FullName); - } - } - // add bundled mods foreach (DirectoryInfo sourceDir in packagedModsDir.EnumerateDirectories()) { @@ -494,16 +476,8 @@ namespace StardewModdingApi.Installer // init/clear target dir DirectoryInfo targetDir = new DirectoryInfo(Path.Combine(paths.ModsDir.FullName, sourceDir.Name)); if (targetDir.Exists) - { - this.ProtectBundledFiles.TryGetValue(targetDir.Name, out HashSet protectedFiles); - foreach (FileSystemInfo entry in targetDir.EnumerateFileSystemInfos()) - { - if (protectedFiles == null || !protectedFiles.Contains(entry.Name)) - this.InteractivelyDelete(entry.FullName); - } - } - else - targetDir.Create(); + this.InteractivelyDelete(targetDir.FullName); + targetDir.Create(); // copy files foreach (FileInfo sourceFile in sourceDir.EnumerateFiles().Where(this.ShouldCopy)) diff --git a/src/SMAPI.Mods.SaveBackup/Framework/ModConfig.cs b/src/SMAPI.Mods.SaveBackup/Framework/ModConfig.cs deleted file mode 100644 index c9dcb216..00000000 --- a/src/SMAPI.Mods.SaveBackup/Framework/ModConfig.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace StardewModdingAPI.Mods.SaveBackup.Framework -{ - /// The mod configuration. - internal class ModConfig - { - /// The number of backups to keep. - public int BackupsToKeep { get; set; } = 10; - } -} diff --git a/src/SMAPI.Mods.SaveBackup/ModEntry.cs b/src/SMAPI.Mods.SaveBackup/ModEntry.cs index 78578c3c..4d56789a 100644 --- a/src/SMAPI.Mods.SaveBackup/ModEntry.cs +++ b/src/SMAPI.Mods.SaveBackup/ModEntry.cs @@ -4,7 +4,6 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; -using StardewModdingAPI.Mods.SaveBackup.Framework; using StardewValley; namespace StardewModdingAPI.Mods.SaveBackup @@ -15,6 +14,12 @@ namespace StardewModdingAPI.Mods.SaveBackup /********* ** Properties *********/ + /// The number of backups to keep. + private readonly int BackupsToKeep = 10; + + /// The absolute path to the folder in which to store save backups. + private readonly string BackupFolder = Path.Combine(Constants.ExecutionPath, "save-backups"); + /// The name of the save archive to create. private readonly string FileName = $"{DateTime.UtcNow:yyyy-MM-dd} - SMAPI {Constants.ApiVersion} with Stardew Valley {Game1.version}.zip"; @@ -28,15 +33,13 @@ namespace StardewModdingAPI.Mods.SaveBackup { try { - ModConfig config = this.Helper.ReadConfig(); - // init backup folder - DirectoryInfo backupFolder = new DirectoryInfo(Path.Combine(this.Helper.DirectoryPath, "backups")); + DirectoryInfo backupFolder = new DirectoryInfo(this.BackupFolder); backupFolder.Create(); // back up saves this.CreateBackup(backupFolder); - this.PruneBackups(backupFolder, config.BackupsToKeep); + this.PruneBackups(backupFolder, this.BackupsToKeep); } catch (Exception ex) { diff --git a/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj b/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj index 0ccbcc6c..fafa4d25 100644 --- a/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj +++ b/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj @@ -1,4 +1,4 @@ - + @@ -36,7 +36,6 @@ Properties\GlobalAssemblyInfo.cs -