Client LuaCsForBarotrauma
BarotraumaClient/ClientSource/LuaCs/LuaCsInstaller.cs
1 using System;
2 using System.IO;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
7  static partial class LuaCsInstaller
8  {
9  public static void Uninstall()
10  {
11  if (!File.Exists("Temp/Original/Barotrauma.dll"))
12  {
13  new GUIMessageBox("Error", "Error: Temp/Original/Barotrauma.dll not found, Github version? Use Steam validate files instead.");
14 
15  return;
16  }
17 
18  var msg = new GUIMessageBox("Confirm", "Are you sure you want to remove Client-Side LuaCs?", new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
19 
20  msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
21  {
22  msg.Close();
23 
24  string[] filesToRemove = new string[]
25  {
26  "Barotrauma.dll", "Barotrauma.deps.json", "Barotrauma.pdb", "BarotraumaCore.dll", "BarotraumaCore.pdb",
27  "System.Reflection.Metadata.dll", "System.Collections.Immutable.dll",
28  "System.Runtime.CompilerServices.Unsafe.dll"
29  };
30  try
31  {
32  CreateMissingDirectory();
33 
34  foreach (string file in filesToRemove)
35  {
36  File.Move(file, "Temp/ToDelete/" + file, true);
37  File.Move("Temp/Original/" + file, file, true);
38  }
39  }
40  catch (Exception e)
41  {
42  new GUIMessageBox("Error", $"{e} {e.InnerException} \nTry verifying files instead.");
43  return false;
44  }
45 
46  new GUIMessageBox("Restart", "Restart your game to apply the changes. If the mod continues to stay active after the restart, try verifying games instead.");
47 
48  return true;
49  };
50 
51  msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
52  {
53  msg.Close();
54  return true;
55  };
56  }
57 
58  public static void CheckUpdate()
59  {
60  if (!File.Exists(LuaCsSetup.VersionFile)) { return; }
61 
62  ContentPackage luaPackage = LuaCsSetup.GetPackage(LuaCsSetup.LuaForBarotraumaId);
63 
64  if (luaPackage == null) { return; }
65 
66  string luaCsPath = Path.GetDirectoryName(luaPackage.Path);
67  string clientVersion = File.ReadAllText(LuaCsSetup.VersionFile);
68  string workshopVersion = luaPackage.ModVersion;
69 
70  if (clientVersion == workshopVersion || File.Exists("debugsomething")) { return; }
71 
72  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 Workshop Version: {workshopVersion}",
73  new LocalizedString[2] { TextManager.Get("Yes"), TextManager.Get("Cancel") });
74 
75  msg.Buttons[0].OnClicked = (GUIButton button, object obj) =>
76  {
77  string[] filesToUpdate = trackingFiles.Concat(Directory.EnumerateFiles(luaCsPath, "*.dll", SearchOption.AllDirectories)
78  .Where(s => s.Contains("mscordaccore_amd64_amd64")).Select(s => Path.GetFileName(s))).ToArray();
79 
80  try
81  {
82  CreateMissingDirectory();
83 
84  foreach (string file in filesToUpdate)
85  {
86  try
87  {
88  File.Move(file, "Temp/Old/" + file, true);
89  File.Copy(Path.Combine(luaCsPath, "Binary", file), file, true);
90  }
91  catch (Exception e)
92  {
93  DebugConsole.ThrowError($"Failed to update file {e}");
94  }
95 
96  }
97 
98  File.WriteAllText(LuaCsSetup.VersionFile, workshopVersion);
99  }
100  catch (Exception e)
101  {
102  new GUIMessageBox("Failed", $"Failed to update, error: {e}");
103 
104  msg.Close();
105  return true;
106  }
107 
108  new GUIMessageBox("Restart", $"LuaCs updated! Restart your game to apply the changes.");
109 
110  msg.Close();
111  return true;
112  };
113 
114  msg.Buttons[1].OnClicked = (GUIButton button, object obj) =>
115  {
116  msg.Close();
117  return true;
118  };
119 
120  }
121  }
122 }