added workshop update checker

This commit is contained in:
Evil Factory
2022-04-13 19:41:43 -03:00
parent e87e9341ef
commit 5dd44dacf3
4 changed files with 88 additions and 10 deletions

View File

@@ -563,6 +563,11 @@ namespace Barotrauma
{
DebugConsole.NewMessage("LOADING COROUTINE FINISHED", Color.Lime);
}
#if CLIENT
LuaCsUpdateChecker.Check();
#endif
yield return CoroutineStatus.Success;
}

View File

@@ -0,0 +1,66 @@
using System;
using System.IO;
namespace Barotrauma
{
static class LuaCsUpdateChecker
{
public static void Check()
{
if (!File.Exists(LuaSetup.VERSION_FILE)) { return; }
ContentPackage luaCsPackage = LuaSetup.GetPackage();
string luaCsPath = Path.GetDirectoryName(luaCsPackage.Path);
if (luaCsPackage == null) { return; }
string clientVersion = File.ReadAllText(LuaSetup.VERSION_FILE);
string serverVersion = luaCsPackage.ModVersion;
if (clientVersion == serverVersion) { return; }
var msg = new GUIMessageBox("LuaCs Update", $"Your LuaCs client version is different from the version found in the LuaCsForBarotrauma workshop files. Do you want to update?\n\n Client Version: {clientVersion}\n Server Version: {serverVersion}",
new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
{
string[] filesToUpdate = new string[]
{
"Barotrauma.dll", "Barotrauma.deps.json",
"0harmony.dll", "MoonSharp.Interpreter.dll",
};
try
{
foreach (string file in filesToUpdate)
{
File.Move(file, file + ".todelete", true);
File.Copy(Path.Combine(luaCsPath, "Binary", file), file, true);
}
File.WriteAllText(LuaSetup.VERSION_FILE, serverVersion);
}
catch (Exception e)
{
new GUIMessageBox("Failed", $"Failed to update, error: {e}");
msg.Close();
return true;
}
new GUIMessageBox("Restart", "LuaCs updated! Restart your game to apply the changes.");
msg.Close();
return true;
};
msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
{
msg.Close();
return true;
};
}
}
}

View File

@@ -1253,7 +1253,7 @@ namespace Barotrauma
commands.Add(new Command("install_cl_lua", "Installs client-Side Lua into your client.", (string[] args) =>
{
ContentPackage luaPackage = LuaSetup.GetLuaPackage();
ContentPackage luaPackage = LuaSetup.GetPackage();
if (luaPackage == null)
{
@@ -1265,7 +1265,7 @@ namespace Barotrauma
{
string path = Path.GetDirectoryName(luaPackage.Path);
string[] filesToMove = new string[]
string[] filesToCopy = new string[]
{
"Barotrauma.dll", "Barotrauma.deps.json",
"0harmony.dll", "Mono.Cecil.dll",
@@ -1278,15 +1278,21 @@ namespace Barotrauma
File.Move("Barotrauma.dll", "Barotrauma.dll.old", true);
File.Move("Barotrauma.deps.json", "Barotrauma.deps.json.old", true);
foreach (string file in filesToMove)
foreach (string file in filesToCopy)
{
File.Copy(Path.Combine(path, "Binary", file), file, true);
}
File.WriteAllText(LuaSetup.VERSION_FILE, luaPackage.ModVersion);
}
catch (UnauthorizedAccessException e)
{
GameMain.Lua.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).");
return;
}
catch (Exception e)
{
// GameMain.Lua.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).");
GameMain.Lua.HandleLuaException(e);
return;

View File

@@ -13,7 +13,8 @@ namespace Barotrauma
{
partial class LuaSetup
{
public const string LUA_PATH = "Lua/LuaSetup.lua";
public const string LUASETUP_FILE = "Lua/LuaSetup.lua";
public const string VERSION_FILE = "luacsversion.txt";
public Script lua;
@@ -24,7 +25,7 @@ namespace Barotrauma
public LuaScriptLoader luaScriptLoader;
public static ContentPackage GetLuaPackage()
public static ContentPackage GetPackage()
{
foreach (ContentPackage package in ContentPackageManager.LocalPackages)
{
@@ -313,13 +314,13 @@ namespace Barotrauma
// LuaDocs.GenerateDocsAll();
ContentPackage luaPackage = GetLuaPackage();
ContentPackage luaPackage = GetPackage();
if (File.Exists(LUA_PATH))
if (File.Exists(LUASETUP_FILE))
{
try
{
lua.Call(lua.LoadFile(LUA_PATH), Path.GetDirectoryName(Path.GetFullPath(LUA_PATH)));
lua.Call(lua.LoadFile(LUASETUP_FILE), Path.GetDirectoryName(Path.GetFullPath(LUASETUP_FILE)));
}
catch (Exception e)
{