adjust SaveBackup mod to simplify installer logic (#583)
This commit is contained in:
parent
100e303b48
commit
307bf6ce55
|
@ -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.
|
||||
|
|
|
@ -22,12 +22,6 @@ namespace StardewModdingApi.Installer
|
|||
/// <summary>The name of the installer file in the package.</summary>
|
||||
private readonly string InstallerFileName = "install.exe";
|
||||
|
||||
/// <summary>Mod files which shouldn't be deleted when deploying bundled mods (mod folder name => file names).</summary>
|
||||
private readonly IDictionary<string, HashSet<string>> ProtectBundledFiles = new Dictionary<string, HashSet<string>>(StringComparer.InvariantCultureIgnoreCase)
|
||||
{
|
||||
["SaveBackup"] = new HashSet<string>(new[] { "backups", "config.json" }, StringComparer.InvariantCultureIgnoreCase)
|
||||
};
|
||||
|
||||
/// <summary>The <see cref="Environment.OSVersion"/> value that represents Windows 7.</summary>
|
||||
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<string> 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))
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
namespace StardewModdingAPI.Mods.SaveBackup.Framework
|
||||
{
|
||||
/// <summary>The mod configuration.</summary>
|
||||
internal class ModConfig
|
||||
{
|
||||
/// <summary>The number of backups to keep.</summary>
|
||||
public int BackupsToKeep { get; set; } = 10;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*********/
|
||||
/// <summary>The number of backups to keep.</summary>
|
||||
private readonly int BackupsToKeep = 10;
|
||||
|
||||
/// <summary>The absolute path to the folder in which to store save backups.</summary>
|
||||
private readonly string BackupFolder = Path.Combine(Constants.ExecutionPath, "save-backups");
|
||||
|
||||
/// <summary>The name of the save archive to create.</summary>
|
||||
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<ModConfig>();
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
|
@ -36,7 +36,6 @@
|
|||
<Compile Include="..\..\build\GlobalAssemblyInfo.cs">
|
||||
<Link>Properties\GlobalAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Framework\ModConfig.cs" />
|
||||
<Compile Include="ModEntry.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue