From ae44f17205961116baef018bae0b8fe9196b27f0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 7 Dec 2016 22:43:05 -0500 Subject: fix installer not moving mods out of appdata if the game isn't installed on the same Windows partition (#184) --- .../InteractiveInstaller.cs | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index cfd64458..ffdef37b 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -406,10 +406,7 @@ namespace StardewModdingApi.Installer // move into mods this.PrintDebug($" Moving {entry.Name} into the game's mod directory..."); - if (isDir) - (entry as DirectoryInfo).MoveTo(newPath); - else - (entry as FileInfo).MoveTo(newPath); + this.Move(entry, newPath); } // delete if empty @@ -421,5 +418,32 @@ namespace StardewModdingApi.Installer modDir.Delete(); } } + + /// Move a filesystem entry to a new parent directory. + /// The filesystem entry to move. + /// The destination path. + /// We can't use or , because those don't work across partitions. + private void Move(FileSystemInfo entry, string newPath) + { + // file + if (entry is FileInfo) + { + FileInfo file = (FileInfo)entry; + file.CopyTo(newPath); + file.Delete(); + } + + // directory + else + { + Directory.CreateDirectory(newPath); + + DirectoryInfo directory = (DirectoryInfo)entry; + foreach (FileSystemInfo child in directory.EnumerateFileSystemInfos()) + this.Move(child, Path.Combine(newPath, child.Name)); + + directory.Delete(); + } + } } } -- cgit