From 41e3c2802174562f356116eda81c8ddfff1edaeb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 18 Nov 2018 00:44:56 -0500 Subject: fix installer allowing custom mods to be bundled with the install (#602) This led to confusion since the installer didn't copy mod subfolders correctly. The installer now explains where to add custom mods instead. --- src/SMAPI.Installer/InteractiveInstaller.cs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 85882283..cef0d26c 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -28,6 +28,13 @@ namespace StardewModdingApi.Installer /// The value that represents Windows 7. private readonly Version Windows7Version = new Version(6, 1); + /// The mod IDs which the installer should allow as bundled mods. + private readonly string[] BundledModIDs = new[] + { + "SMAPI.SaveBackup", + "SMAPI.ConsoleCommands" + }; + /// The default file paths where Stardew Valley can be installed. /// The target platform. /// Derived from the crossplatform mod config: https://github.com/Pathoschild/Stardew.ModBuildConfig. @@ -486,6 +493,11 @@ namespace StardewModdingApi.Installer this.PrintWarning($" ignored invalid bundled mod {sourceMod.DisplayName}: {sourceMod.ManifestParseError}"); continue; } + if (!this.BundledModIDs.Contains(sourceMod.Manifest.UniqueID)) + { + this.PrintWarning($" ignored unknown '{sourceMod.DisplayName}' mod in the installer folder. To add mods, put them here instead: {paths.ModsPath}"); + continue; + } // find target folder ModFolder targetMod = targetMods.FirstOrDefault(p => p.Manifest?.UniqueID?.Equals(sourceMod.Manifest.UniqueID, StringComparison.InvariantCultureIgnoreCase) == true); @@ -496,14 +508,12 @@ namespace StardewModdingApi.Installer : $" adding {sourceMod.Manifest.Name} to {Path.Combine(paths.ModsDir.Name, PathUtilities.GetRelativePath(paths.ModsPath, targetFolder.FullName))}..." ); - // (re)create target folder + // remove existing folder if (targetFolder.Exists) this.InteractivelyDelete(targetFolder.FullName); - targetFolder.Create(); // copy files - foreach (FileInfo sourceFile in sourceMod.Directory.EnumerateFiles().Where(this.ShouldCopy)) - sourceFile.CopyTo(Path.Combine(targetFolder.FullName, sourceFile.Name)); + this.RecursiveCopy(sourceMod.Directory, paths.ModsDir, filter: this.ShouldCopy); } } @@ -686,8 +696,12 @@ namespace StardewModdingApi.Installer /// Recursively copy a directory or file. /// The file or folder to copy. /// The folder to copy into. - private void RecursiveCopy(FileSystemInfo source, DirectoryInfo targetFolder) + /// A filter which matches directories and files to copy, or null to match all. + private void RecursiveCopy(FileSystemInfo source, DirectoryInfo targetFolder, Func filter = null) { + if (filter != null && !filter(source)) + return; + if (!targetFolder.Exists) targetFolder.Create(); @@ -700,7 +714,7 @@ namespace StardewModdingApi.Installer case DirectoryInfo sourceDir: DirectoryInfo targetSubfolder = new DirectoryInfo(Path.Combine(targetFolder.FullName, sourceDir.Name)); foreach (var entry in sourceDir.EnumerateFileSystemInfos()) - this.RecursiveCopy(entry, targetSubfolder); + this.RecursiveCopy(entry, targetSubfolder, filter); break; default: -- cgit