summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Installer
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-12-06 00:37:12 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-12-06 00:37:12 -0500
commitf625fd51a0fa33c87feeb6890390a6b253ef38a1 (patch)
tree196248bb08ef68ca4447f16a3b5eaf3f8e2ec917 /src/StardewModdingAPI.Installer
parent315943614573f0e1973bafc761c27207b8ea2b45 (diff)
downloadSMAPI-f625fd51a0fa33c87feeb6890390a6b253ef38a1.tar.gz
SMAPI-f625fd51a0fa33c87feeb6890390a6b253ef38a1.tar.bz2
SMAPI-f625fd51a0fa33c87feeb6890390a6b253ef38a1.zip
always clean up files during install (#188)
Diffstat (limited to 'src/StardewModdingAPI.Installer')
-rw-r--r--src/StardewModdingAPI.Installer/InteractiveInstaller.cs156
1 files changed, 77 insertions, 79 deletions
diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs
index 1d3802ab..7b082893 100644
--- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs
+++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs
@@ -131,90 +131,88 @@ namespace StardewModdingApi.Installer
Console.WriteLine();
/****
- ** Perform action
+ ** Always uninstall old files
****/
- switch (action)
+ // restore game launcher
+ if (platform == Platform.Mono && File.Exists(paths.unixLauncherBackup))
{
- case ScriptAction.Uninstall:
- {
- // restore game launcher
- if (platform == Platform.Mono && File.Exists(paths.unixLauncherBackup))
- {
- this.PrintDebug("Restoring game launcher...");
- if (File.Exists(paths.unixLauncher))
- File.Delete(paths.unixLauncher);
- File.Move(paths.unixLauncherBackup, paths.unixLauncher);
- }
-
- // remove SMAPI files
- this.PrintDebug("Removing SMAPI files...");
- foreach (string filename in this.UninstallFiles)
- {
- string targetPath = Path.Combine(installDir.FullName, filename);
- if (File.Exists(targetPath))
- File.Delete(targetPath);
- }
- }
- break;
+ this.PrintDebug("Removing SMAPI launcher...");
+ if (File.Exists(paths.unixLauncher))
+ File.Delete(paths.unixLauncher);
+ File.Move(paths.unixLauncherBackup, paths.unixLauncher);
+ }
+
+ // remove old files
+ string[] removeFiles = this.UninstallFiles
+ .Select(path => Path.Combine(installDir.FullName, path))
+ .Where(File.Exists)
+ .ToArray();
+ if (removeFiles.Any())
+ {
+ this.PrintDebug(action == ScriptAction.Install ? "Removing previous SMAPI files..." : "Removing SMAPI files...");
+ foreach (string path in removeFiles)
+ File.Delete(path);
+ }
+
+ /****
+ ** Install new files
+ ****/
+ if (action == ScriptAction.Install)
+ {
+ // copy SMAPI files to game dir
+ this.PrintDebug("Adding SMAPI files...");
+ foreach (FileInfo sourceFile in packageDir.EnumerateFiles())
+ {
+ string targetPath = Path.Combine(installDir.FullName, sourceFile.Name);
+ if (File.Exists(targetPath))
+ File.Delete(targetPath);
+ sourceFile.CopyTo(targetPath);
+ }
- case ScriptAction.Install:
+ // replace mod launcher (if possible)
+ if (platform == Platform.Mono)
+ {
+ this.PrintDebug("Safely replacing game launcher...");
+ if (!File.Exists(paths.unixLauncherBackup))
+ File.Move(paths.unixLauncher, paths.unixLauncherBackup);
+ else if (File.Exists(paths.unixLauncher))
+ File.Delete(paths.unixLauncher);
+
+ File.Move(paths.unixSmapiLauncher, paths.unixLauncher);
+ }
+
+ // create mods directory (if needed)
+ DirectoryInfo modsDir = new DirectoryInfo(Path.Combine(installDir.FullName, "Mods"));
+ if (!modsDir.Exists)
+ {
+ this.PrintDebug("Creating mods directory...");
+ modsDir.Create();
+ }
+
+ // add or replace bundled mods
+ Directory.CreateDirectory(Path.Combine(installDir.FullName, "Mods"));
+ DirectoryInfo packagedModsDir = new DirectoryInfo(Path.Combine(packageDir.FullName, "Mods"));
+ if (packagedModsDir.Exists && packagedModsDir.EnumerateDirectories().Any())
+ {
+ this.PrintDebug("Adding bundled mods...");
+ foreach (DirectoryInfo sourceDir in packagedModsDir.EnumerateDirectories())
{
- // copy SMAPI files to game dir
- this.PrintDebug("Copying SMAPI files to game directory...");
- foreach (FileInfo sourceFile in packageDir.EnumerateFiles())
- {
- string targetPath = Path.Combine(installDir.FullName, sourceFile.Name);
- if (File.Exists(targetPath))
- File.Delete(targetPath);
- sourceFile.CopyTo(targetPath);
- }
-
- // replace mod launcher (if possible)
- if (platform == Platform.Mono)
- {
- this.PrintDebug("Safely replacing game launcher...");
- if (!File.Exists(paths.unixLauncherBackup))
- File.Move(paths.unixLauncher, paths.unixLauncherBackup);
- else if (File.Exists(paths.unixLauncher))
- File.Delete(paths.unixLauncher);
-
- File.Move(paths.unixSmapiLauncher, paths.unixLauncher);
- }
-
- // create mods directory (if needed)
- DirectoryInfo modsDir = new DirectoryInfo(Path.Combine(installDir.FullName, "Mods"));
- if (!modsDir.Exists)
- {
- this.PrintDebug("Creating mods directory...");
- modsDir.Create();
- }
-
- // add or replace bundled mods
- Directory.CreateDirectory(Path.Combine(installDir.FullName, "Mods"));
- DirectoryInfo packagedModsDir = new DirectoryInfo(Path.Combine(packageDir.FullName, "Mods"));
- if (packagedModsDir.Exists && packagedModsDir.EnumerateDirectories().Any())
- {
- this.PrintDebug("Adding bundled mods...");
- foreach (DirectoryInfo sourceDir in packagedModsDir.EnumerateDirectories())
- {
- this.PrintDebug($" adding {sourceDir.Name}...");
-
- // initialise target dir
- DirectoryInfo targetDir = new DirectoryInfo(Path.Combine(modsDir.FullName, sourceDir.Name));
- if (targetDir.Exists)
- targetDir.Delete(recursive: true);
- targetDir.Create();
-
- // copy files
- foreach (FileInfo sourceFile in sourceDir.EnumerateFiles())
- sourceFile.CopyTo(Path.Combine(targetDir.FullName, sourceFile.Name));
- }
- }
-
- // remove obsolete appdata mods
- this.InteractivelyRemoveAppDataMods(platform, modsDir);
+ this.PrintDebug($" adding {sourceDir.Name}...");
+
+ // initialise target dir
+ DirectoryInfo targetDir = new DirectoryInfo(Path.Combine(modsDir.FullName, sourceDir.Name));
+ if (targetDir.Exists)
+ targetDir.Delete(recursive: true);
+ targetDir.Create();
+
+ // copy files
+ foreach (FileInfo sourceFile in sourceDir.EnumerateFiles())
+ sourceFile.CopyTo(Path.Combine(targetDir.FullName, sourceFile.Name));
}
- break;
+ }
+
+ // remove obsolete appdata mods
+ this.InteractivelyRemoveAppDataMods(platform, modsDir);
}
Console.WriteLine();