refactor workshop installation: make LuaCsInstaller a little less cursed
This commit is contained in:
@@ -577,7 +577,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
#if CLIENT
|
||||
LuaCsUpdateChecker.Check();
|
||||
LuaCsInstaller.CheckUpdate();
|
||||
#endif
|
||||
|
||||
yield return CoroutineStatus.Success;
|
||||
|
||||
@@ -4,9 +4,58 @@ using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static class LuaCsUpdateChecker
|
||||
static partial class LuaCsInstaller
|
||||
{
|
||||
public static void Check()
|
||||
public static void Uninstall()
|
||||
{
|
||||
if (!File.Exists("Temp/Original/Barotrauma.dll"))
|
||||
{
|
||||
new GUIMessageBox("Error", "Error: Temp/Original/Barotrauma.dll not found, Github version? Use Steam validate files instead.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = new GUIMessageBox("Confirm", "Are you sure you want to remove Client-Side LuaCs?", new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
|
||||
|
||||
msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
|
||||
{
|
||||
msg.Close();
|
||||
|
||||
string[] filesToRemove = new string[]
|
||||
{
|
||||
"Barotrauma.dll", "Barotrauma.deps.json",
|
||||
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
|
||||
"System.Runtime.CompilerServices.Unsafe.dll"
|
||||
};
|
||||
try
|
||||
{
|
||||
CreateMissingDirectory();
|
||||
|
||||
foreach (string file in filesToRemove)
|
||||
{
|
||||
File.Move(file, "Temp/ToDelete/" + file, true);
|
||||
File.Move("Temp/Original/" + file, file, true);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
new GUIMessageBox("Error", $"{e} {e.InnerException} \nTry verifying files instead.");
|
||||
return false;
|
||||
}
|
||||
|
||||
new GUIMessageBox("Restart", "Restart your game to apply the changes. If the mod continues to stay active after the restart, try verifying games instead.");
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
|
||||
{
|
||||
msg.Close();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
public static void CheckUpdate()
|
||||
{
|
||||
if (!File.Exists(LuaCsSetup.VersionFile)) { return; }
|
||||
|
||||
@@ -48,11 +97,13 @@ namespace Barotrauma
|
||||
|
||||
try
|
||||
{
|
||||
CreateMissingDirectory();
|
||||
|
||||
foreach (string file in filesToUpdate)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Move(file, file + ".todelete", true);
|
||||
File.Move(file, "Temp/Old/" + file, true);
|
||||
File.Copy(Path.Combine(luaCsPath, "Binary", file), file, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -406,57 +406,7 @@ namespace Barotrauma
|
||||
ToolTip = "Remove Client-Side LuaCs.",
|
||||
OnClicked = (tb, userdata) =>
|
||||
{
|
||||
if (!File.Exists("Barotrauma.dll.old"))
|
||||
{
|
||||
new GUIMessageBox("Error", "Error: Barotrauma.dll.original not found, Github version? Use Steam validate files instead.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!File.Exists("Barotrauma.deps.json.old"))
|
||||
{
|
||||
new GUIMessageBox("Error", "Error: Barotrauma.deps.json.original not found, Github version? Use Steam validate files instead.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var msg = new GUIMessageBox("Confirm", "Are you sure you want to remove Client-Side LuaCs?", new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
|
||||
|
||||
msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
|
||||
{
|
||||
msg.Close();
|
||||
|
||||
string[] filesToRemove = new string[]
|
||||
{
|
||||
"Barotrauma.dll", "Barotrauma.deps.json",
|
||||
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
|
||||
"System.Runtime.CompilerServices.Unsafe.dll"
|
||||
};
|
||||
try
|
||||
{
|
||||
foreach (string file in filesToRemove)
|
||||
{
|
||||
System.IO.File.Move(file, file + ".todelete", true);
|
||||
System.IO.File.Move(file + ".old", file, true);
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
new GUIMessageBox("Error", $"{e} {e.InnerException}");
|
||||
return false;
|
||||
}
|
||||
|
||||
new GUIMessageBox("Restart", "Restart your game to apply the changes.");
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
|
||||
{
|
||||
msg.Close();
|
||||
return true;
|
||||
};
|
||||
|
||||
LuaCsInstaller.Uninstall();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1268,69 +1268,7 @@ namespace Barotrauma
|
||||
#if WINDOWS
|
||||
commands.Add(new Command("install_cl_lua", "Installs Client-Side Lua into your client.", (string[] args) =>
|
||||
{
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage("Lua For Barotrauma");
|
||||
|
||||
if (luaPackage == null)
|
||||
{
|
||||
GameMain.Server.SendChatMessage("Couldn't find the Lua For Barotrauma package.", ChatMessageType.ServerMessageBox);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string path = Path.GetDirectoryName(luaPackage.Path);
|
||||
|
||||
string[] filesToCopy = new string[]
|
||||
{
|
||||
"Barotrauma.dll", "Barotrauma.deps.json",
|
||||
"0harmony.dll", "Mono.Cecil.dll",
|
||||
"Sigil.dll",
|
||||
"Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll",
|
||||
"Mono.Cecil.Rocks.dll", "MonoMod.Common.dll",
|
||||
"MoonSharp.Interpreter.dll",
|
||||
|
||||
"Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
|
||||
"Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll",
|
||||
|
||||
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
|
||||
"System.Runtime.CompilerServices.Unsafe.dll"
|
||||
};
|
||||
filesToCopy = filesToCopy.Concat(Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories)
|
||||
.Where(s => s.Contains("mscordaccore_amd64_amd64_4.")).Select(s => Path.GetFileName(s))).ToArray();
|
||||
|
||||
File.Move("Barotrauma.dll", "Barotrauma.dll.old", true);
|
||||
File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.old", true);
|
||||
|
||||
File.Move("System.Reflection.Metadata.dll", "System.Reflection.Metadata.dll.old", true);
|
||||
File.Move("System.Collections.Immutable.dll", "System.Collections.Immutable.dll.old", true);
|
||||
File.Move("System.Runtime.CompilerServices.Unsafe.dll", "System.Runtime.CompilerServices.Unsafe.dll.old", true);
|
||||
|
||||
foreach (string file in filesToCopy)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
{
|
||||
File.Move(file, file + ".todelete", true);
|
||||
}
|
||||
File.Copy(Path.Combine(path, "Binary", file), file, true);
|
||||
}
|
||||
|
||||
File.WriteAllText(LuaCsSetup.VersionFile, luaPackage.ModVersion);
|
||||
File.WriteAllText("LuaDedicatedServer.bat", "\"%LocalAppData%/Daedalic Entertainment GmbH/Barotrauma/WorkshopMods/Installed/2559634234/Binary/DedicatedServer.exe\"");
|
||||
}
|
||||
catch (UnauthorizedAccessException e)
|
||||
{
|
||||
GameMain.LuaCs.PrintError("You seem to already have Client Side Lua installed, if you are trying to reinstall, make sure uninstall it first (mainmenu button located top left).", LuaCsMessageOrigin.LuaCs);
|
||||
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GameMain.LuaCs.HandleException(e, LuaCsMessageOrigin.LuaCs);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GameMain.Server.SendChatMessage("Client-Side Lua installed, restart your game to apply changes.", ChatMessageType.ServerMessageBox);
|
||||
LuaCsInstaller.Install();
|
||||
}));
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static partial class LuaCsInstaller
|
||||
{
|
||||
public static void Install()
|
||||
{
|
||||
ContentPackage luaPackage = LuaCsSetup.GetPackage("Lua For Barotrauma");
|
||||
|
||||
if (luaPackage == null)
|
||||
{
|
||||
GameMain.Server.SendChatMessage("Couldn't find the Lua For Barotrauma package.", ChatMessageType.ServerMessageBox);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string path = Path.GetDirectoryName(luaPackage.Path);
|
||||
|
||||
string[] filesToCopy = new string[]
|
||||
{
|
||||
"Barotrauma.dll", "Barotrauma.deps.json",
|
||||
"0harmony.dll", "Mono.Cecil.dll",
|
||||
"Sigil.dll",
|
||||
"Mono.Cecil.Mdb.dll", "Mono.Cecil.Pdb.dll",
|
||||
"Mono.Cecil.Rocks.dll", "MonoMod.Common.dll",
|
||||
"MoonSharp.Interpreter.dll",
|
||||
|
||||
"Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
|
||||
"Microsoft.CodeAnalysis.CSharp.Scripting.dll", "Microsoft.CodeAnalysis.Scripting.dll",
|
||||
|
||||
"System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
|
||||
"System.Runtime.CompilerServices.Unsafe.dll"
|
||||
};
|
||||
filesToCopy = filesToCopy.Concat(Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories)
|
||||
.Where(s => s.Contains("mscordaccore_amd64_amd64_4.")).Select(s => Path.GetFileName(s))).ToArray();
|
||||
|
||||
CreateMissingDirectory();
|
||||
|
||||
File.Move("Barotrauma.dll", "Temp/Original/Barotrauma.dll", true);
|
||||
File.Move("Barotrauma.deps.json", "Temp/Original/Barotrauma.deps.json", true);
|
||||
|
||||
File.Move("System.Reflection.Metadata.dll", "Temp/Original/System.Reflection.Metadata.dll", true);
|
||||
File.Move("System.Collections.Immutable.dll", "Temp/Original/System.Collections.Immutable.dll", true);
|
||||
File.Move("System.Runtime.CompilerServices.Unsafe.dll", "Temp/Original/System.Runtime.CompilerServices.Unsafe.dll", true);
|
||||
|
||||
foreach (string file in filesToCopy)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
{
|
||||
File.Move(file, "Temp/ToDelete/" + file, true);
|
||||
}
|
||||
File.Copy(Path.Combine(path, "Binary", file), file, true);
|
||||
}
|
||||
|
||||
File.WriteAllText(LuaCsSetup.VersionFile, luaPackage.ModVersion);
|
||||
File.WriteAllText("LuaDedicatedServer.bat", "\"%LocalAppData%/Daedalic Entertainment GmbH/Barotrauma/WorkshopMods/Installed/2559634234/Binary/DedicatedServer.exe\"");
|
||||
}
|
||||
catch (UnauthorizedAccessException e)
|
||||
{
|
||||
GameMain.LuaCs.PrintError("You seem to already have Client Side Lua installed, if you are trying to reinstall, make sure uninstall it first (mainmenu button located top left).", LuaCsMessageOrigin.LuaCs);
|
||||
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GameMain.LuaCs.HandleException(e, LuaCsMessageOrigin.LuaCs);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
GameMain.Server.SendChatMessage("Client-Side Lua installed, restart your game to apply changes.", ChatMessageType.ServerMessageBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
static partial class LuaCsInstaller
|
||||
{
|
||||
private static void CreateMissingDirectory()
|
||||
{
|
||||
Directory.CreateDirectory("Temp/Original");
|
||||
Directory.CreateDirectory("Temp/ToDelete");
|
||||
Directory.CreateDirectory("Temp/Old");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user