diff --git a/MiniInstaller/BackUp.cs b/MiniInstaller/BackUp.cs index aece3d4bb..fa50563e5 100644 --- a/MiniInstaller/BackUp.cs +++ b/MiniInstaller/BackUp.cs @@ -65,7 +65,7 @@ static void ApplyVanillaPatchLibs(string patchLibsDir, string targetDir) { Logger.LogLine("Applying patch vanilla libraries"); ApplyVanillaPatchLibs(patchLibsDir, Globals.PathOrig); - Directory.Delete(patchLibsDir, true); + Directory.Delete(patchLibsDir, recursive: true); } //Create symlinks @@ -140,4 +140,4 @@ private static void Backup(string from, string backupDst = null) { } } } -} \ No newline at end of file +} diff --git a/MiniInstaller/DepCalls.cs b/MiniInstaller/DepCalls.cs index 7cdc4f7fd..d8454a981 100644 --- a/MiniInstaller/DepCalls.cs +++ b/MiniInstaller/DepCalls.cs @@ -63,7 +63,7 @@ public static void RunMonoMod(string asmFrom, string asmTo = null, string[] dllP string asmTmp = Path.Combine(Globals.PathTmp, Path.GetFileName(asmTo)); try { // We're lazy. - Environment.SetEnvironmentVariable("MONOMOD_DEPDIRS", Globals.PathGame); + Environment.SetEnvironmentVariable("MONOMOD_DEPDIRS", $"{Globals.PathMiniInstallerWorkspace}{Path.PathSeparator}{Globals.PathGame}"); // Prioritize workspace Environment.SetEnvironmentVariable("MONOMOD_DEPENDENCY_MISSING_THROW", "0"); int returnCode = (int) AsmMonoMod.EntryPoint.Invoke(null, new object[] { Enumerable.Repeat(asmFrom, 1).Concat(dllPaths).Append(asmTmp).ToArray() }); @@ -84,7 +84,7 @@ public static void RunMonoMod(string asmFrom, string asmTo = null, string[] dllP public static void RunHookGen(string asm, string targetName) { Logger.LogLine($"Running MonoMod.RuntimeDetour.HookGen for {asm}"); // We're lazy. - Environment.SetEnvironmentVariable("MONOMOD_DEPDIRS", Globals.PathGame); + Environment.SetEnvironmentVariable("MONOMOD_DEPDIRS", $"{Globals.PathMiniInstallerWorkspace}{Path.PathSeparator}{Globals.PathGame}"); // Prioritize workspace Environment.SetEnvironmentVariable("MONOMOD_DEPENDENCY_MISSING_THROW", "0"); AsmHookGen.EntryPoint.Invoke(null, new object[] { new string[] { "--private", asm, Path.Combine(Path.GetDirectoryName(targetName), "MMHOOK_" + Path.ChangeExtension(Path.GetFileName(targetName), "dll")) } }); } @@ -132,4 +132,4 @@ public static void ConvertToNETCoreSingle(string asmFrom, string asmTo) { File.Delete(Path.ChangeExtension(asmTmp, "mdb")); } } -} \ No newline at end of file +} diff --git a/MiniInstaller/Globals.cs b/MiniInstaller/Globals.cs index 2c2688d55..486c3d7d3 100644 --- a/MiniInstaller/Globals.cs +++ b/MiniInstaller/Globals.cs @@ -22,9 +22,12 @@ public static class Globals { public static string PathOrig; public static string PathLog; public static string PathTmp; + public static string PathMiniInstallerWorkspace; + public static bool SetupPaths() { PathGame = Directory.GetCurrentDirectory(); Console.WriteLine(PathGame); + PathMiniInstallerWorkspace = Path.Combine(PathGame, "MiniInstallerWorkspace"); if (Path.GetFileName(PathGame) == "everest-update" && ( File.Exists(Path.Combine(Path.GetDirectoryName(PathGame), "Celeste.exe")) || @@ -87,4 +90,4 @@ public static void DetermineInstallPlatform() { Logger.LogLine($"Determined install platform: {Platform}"); } -} \ No newline at end of file +} diff --git a/MiniInstaller/InGameUpdaterHelper.cs b/MiniInstaller/InGameUpdaterHelper.cs index a2b9ebf33..4db6fd839 100644 --- a/MiniInstaller/InGameUpdaterHelper.cs +++ b/MiniInstaller/InGameUpdaterHelper.cs @@ -18,7 +18,7 @@ public static void MoveFilesFromUpdate(string srcPath = null, string dstPath = n // Check if we have a new runtime (=there is a piton-runtime folder both in the game and the update directory) if (Directory.Exists(Path.Combine(Globals.PathGame, "piton-runtime")) && Directory.Exists(Path.Combine(Globals.PathUpdate, "piton-runtime"))) - Directory.Delete(Path.Combine(Globals.PathGame, "piton-runtime"), true); + Directory.Delete(Path.Combine(Globals.PathGame, "piton-runtime"), recursive: true); } if (!Directory.Exists(dstPath)) @@ -29,7 +29,7 @@ public static void MoveFilesFromUpdate(string srcPath = null, string dstPath = n if (File.Exists(entrySrc)) { Logger.LogLine($"Copying {entrySrc} +> {entryDst}"); - File.Copy(entrySrc, entryDst, true); + File.Copy(entrySrc, entryDst, overwrite: true); } else MoveFilesFromUpdate(entrySrc, entryDst); } diff --git a/MiniInstaller/LibAndDepHandling.cs b/MiniInstaller/LibAndDepHandling.cs index 161684567..78539e331 100644 --- a/MiniInstaller/LibAndDepHandling.cs +++ b/MiniInstaller/LibAndDepHandling.cs @@ -85,7 +85,7 @@ void CopyNativeLib(string src, string dst) { dst = Path.Combine(Path.GetDirectoryName(dst), mappedName); } - File.Copy(src, dst, true); + File.Copy(src, dst, overwrite: true); if (symlinkPath != null && symlinkPath != dst) { File.Delete(symlinkPath); @@ -106,8 +106,7 @@ void CopyNativeLib(string src, string dst) { // Copy our Steamworks.NET.dll string steamworksLibDst = Path.Combine(Globals.PathGame, "Steamworks.NET.dll"); - File.Delete(steamworksLibDst); - File.Copy(steamworksLibSrc, steamworksLibDst); + File.Copy(steamworksLibSrc, steamworksLibDst, overwrite: true); // Delete old libraries foreach (string libFile in Globals.WindowsNativeLibFileNames) @@ -115,11 +114,11 @@ void CopyNativeLib(string src, string dst) { foreach (string libDir in new string[] { "lib", "lib64", "everest-lib64", "runtimes" }) { if (Directory.Exists(Path.Combine(Globals.PathGame, libDir))) - Directory.Delete(Path.Combine(Globals.PathGame, libDir), true); + Directory.Delete(Path.Combine(Globals.PathGame, libDir), recursive: true); } if (Globals.PathOSXExecDir != null && Path.Exists(Path.Combine(Globals.PathOSXExecDir, "osx"))) - Directory.Delete(Path.Combine(Globals.PathOSXExecDir, "osx"), true); + Directory.Delete(Path.Combine(Globals.PathOSXExecDir, "osx"), recursive: true); // Finally make EverestSplash executable if (Globals.Platform is Globals.InstallPlatform.Linux or Globals.InstallPlatform.MacOS) { @@ -138,7 +137,7 @@ void CopyNativeLib(string src, string dst) { } public static void CopyControllerDB() { - File.Copy(Path.Combine(Globals.PathEverestLib, "gamecontrollerdb.txt"), Path.Combine(Globals.PathGame, "gamecontrollerdb.txt"), true); + File.Copy(Path.Combine(Globals.PathEverestLib, "gamecontrollerdb.txt"), Path.Combine(Globals.PathGame, "gamecontrollerdb.txt"), overwrite: true); Logger.LogLine("Copied gamecontrollerdb.txt"); } @@ -268,6 +267,7 @@ public static void SetupAppHosts(string appExe, string appDll, string resDll = n // Bind Linux apphost Logger.LogLine($"Binding Linux apphost {Path.ChangeExtension(appExe, null)}"); HostWriter.CreateAppHost(Path.Combine(hostsDir, "linux"), Path.ChangeExtension(appExe, null), Path.GetRelativePath(Path.GetDirectoryName(appExe), appDll)); + File.Delete(Globals.PathCelesteExe); } break; case Globals.InstallPlatform.MacOS: { // Bind OS X apphost @@ -277,6 +277,7 @@ public static void SetupAppHosts(string appExe, string appDll, string resDll = n File.Delete(Path.Combine(Globals.PathOSXExecDir, Path.GetFileNameWithoutExtension(appExe))); File.CreateSymbolicLink(Path.Combine(Globals.PathOSXExecDir, Path.GetFileNameWithoutExtension(appExe)), Path.GetRelativePath(Globals.PathOSXExecDir, Path.ChangeExtension(appExe, null))); + File.Delete(Globals.PathCelesteExe); } break; } } diff --git a/MiniInstaller/MiscUtil.cs b/MiniInstaller/MiscUtil.cs index 91ad471e7..8b5ee44f9 100644 --- a/MiniInstaller/MiscUtil.cs +++ b/MiniInstaller/MiscUtil.cs @@ -72,18 +72,15 @@ public static bool IsSteamworksNet(string file) { } // This is not "pure" but I guess it also somewhat fits here public static void MoveExecutable(string srcPath, string dstPath) { - File.Delete(dstPath); - File.Move(srcPath, dstPath); + File.Move(srcPath, dstPath, overwrite: true); if (Path.GetFullPath(Path.ChangeExtension(srcPath, null)) != Path.GetFullPath(Path.ChangeExtension(dstPath, null))) { if (File.Exists(Path.ChangeExtension(srcPath, ".pdb"))) { - File.Delete(Path.ChangeExtension(dstPath, ".pdb")); - File.Move(Path.ChangeExtension(srcPath, ".pdb"), Path.ChangeExtension(dstPath, ".pdb")); + File.Move(Path.ChangeExtension(srcPath, ".pdb"), Path.ChangeExtension(dstPath, ".pdb"), overwrite: true); } if (File.Exists(Path.ChangeExtension(srcPath, ".mdb"))) { - File.Delete(Path.ChangeExtension(dstPath, ".mdb")); - File.Move(Path.ChangeExtension(srcPath, ".mdb"), Path.ChangeExtension(dstPath, ".mdb")); + File.Move(Path.ChangeExtension(srcPath, ".mdb"), Path.ChangeExtension(dstPath, ".mdb"), overwrite: true); } } } diff --git a/MiniInstaller/Program.cs b/MiniInstaller/Program.cs index 2f8d16cfc..0f0658160 100644 --- a/MiniInstaller/Program.cs +++ b/MiniInstaller/Program.cs @@ -80,25 +80,43 @@ public static int StandardMode(string[] args) { LibAndDepHandling.SetupNativeLibs(); LibAndDepHandling.CopyControllerDB(); + if (Directory.Exists(Globals.PathMiniInstallerWorkspace)) { + Logger.LogLine("MiniInstaller workspace already exists, cleaning before continuing."); + Directory.Delete(Globals.PathMiniInstallerWorkspace, recursive: true); + } + + Directory.CreateDirectory(Globals.PathMiniInstallerWorkspace); + + string coreifiedCeleste = Path.Combine(Globals.PathMiniInstallerWorkspace, "Celeste.Core.dll"); + string coreifiedModdedCeleste = Path.Combine(Globals.PathMiniInstallerWorkspace, "Celeste.dll"); + string moddedFNA = Path.Combine(Globals.PathMiniInstallerWorkspace, "FNA.dll"); + string hookGenTempOutput = Path.Combine(Globals.PathMiniInstallerWorkspace, "MMHOOK_" + Path.ChangeExtension(Path.GetFileName(Globals.PathCelesteExe), ".dll")); + DepCalls.LoadModders(); - DepCalls.ConvertToNETCore(Path.Combine(Globals.PathOrig, "Celeste.exe"), Globals.PathCelesteExe); + DepCalls.ConvertToNETCore(Path.Combine(Globals.PathOrig, "Celeste.exe"), coreifiedCeleste); string everestModDLL = Path.ChangeExtension(Globals.PathCelesteExe, ".Mod.mm.dll"); string[] mods = new string[] { Globals.PathEverestLib, everestModDLL }; - DepCalls.RunMonoMod(Path.Combine(Globals.PathEverestLib, "FNA.dll"), Path.Combine(Globals.PathGame, "FNA.dll"), dllPaths: mods); // We need to patch some methods in FNA as well - DepCalls.RunMonoMod(Globals.PathCelesteExe, dllPaths: mods); + DepCalls.RunMonoMod(Path.Combine(Globals.PathEverestLib, "FNA.dll"), moddedFNA, dllPaths: mods); // We need to patch some methods in FNA as well + DepCalls.RunMonoMod(coreifiedCeleste, coreifiedModdedCeleste, dllPaths: mods); string hookGenOutput = Path.Combine(Globals.PathGame, "MMHOOK_" + Path.ChangeExtension(Path.GetFileName(Globals.PathCelesteExe), ".dll")); - DepCalls.RunHookGen(Globals.PathCelesteExe, Globals.PathCelesteExe); - DepCalls.RunMonoMod(hookGenOutput, dllPaths: mods); // We need to fix some MonoMod crimes, so relink it against the legacy MonoMod layer + DepCalls.RunHookGen(coreifiedModdedCeleste, coreifiedModdedCeleste); + DepCalls.RunMonoMod(hookGenTempOutput, dllPaths: mods); // We need to fix some MonoMod crimes, so relink it against the legacy MonoMod layer + + MiscUtil.MoveExecutable(coreifiedModdedCeleste, Globals.PathEverestDLL); + MiscUtil.MoveExecutable(moddedFNA, Path.Combine(Globals.PathGame, "FNA.dll")); + MiscUtil.MoveExecutable(hookGenTempOutput, hookGenOutput); - MiscUtil.MoveExecutable(Globals.PathCelesteExe, Globals.PathEverestDLL); LibAndDepHandling.CreateRuntimeConfigFiles(Globals.PathEverestDLL, new string[] { everestModDLL, hookGenOutput }); LibAndDepHandling.SetupAppHosts(Globals.PathCelesteExe, Globals.PathEverestDLL, Globals.PathEverestDLL); XmlDoc.CombineXMLDoc(Path.ChangeExtension(Globals.PathCelesteExe, ".Mod.mm.xml"), Path.ChangeExtension(Globals.PathCelesteExe, ".xml")); + // Everything went well, cleaning MiniInstaller workspace + Directory.Delete(Globals.PathMiniInstallerWorkspace, recursive: true); + // If we're updating, start the game. Otherwise, close the window. if (Globals.PathUpdate != null) { InGameUpdaterHelper.StartGame(); @@ -126,7 +144,7 @@ public static int StandardMode(string[] args) { return 0; } - + /// /// Fast mode serves as a way to speed up development environments, /// allowing disabling most parts of the installation process to only focus on the ones @@ -180,10 +198,10 @@ public static int FastMode(string[] args) { string[] mods = new string[] { Globals.PathEverestLib, everestModDLL }; string coreGameCacheFile = Path.ChangeExtension(Globals.PathCelesteExe, ".CoreGameCache.dll"); - + if (doMainGame && !File.Exists(coreGameCacheFile)) coreGameCacheRegen = true; - + if (coreGameCacheRegen && File.Exists(coreGameCacheFile)) File.Delete(coreGameCacheFile);