Skip to content

Commit

Permalink
Added --server-only option
Browse files Browse the repository at this point in the history
  • Loading branch information
evilfactory committed Sep 23, 2024
1 parent 3f2b792 commit f0c25d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
23 changes: 17 additions & 6 deletions Luatrauma.AutoUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,28 @@ static void Main(string[] args)

public async static Task Start()
{
await Updater.Update();
List<string> args = new List<string>(Args);

if (Args.Length > 0)
bool serverOnly = false;

int index = args.FindIndex(x => x == "--server-only");
if (index != -1)
{
args.RemoveAt(index);
serverOnly = true;
}

await Updater.Update(serverOnly);

if (args.Count > 0)
{
Logger.Log("Starting " + string.Join(" ", Args));
Logger.Log("Starting " + string.Join(" ", args));

var info = new ProcessStartInfo
{
FileName = Args[0],
Arguments = string.Join(" ", Args.Skip(1)),
WorkingDirectory = Path.GetDirectoryName(Args[0]),
FileName = args[0],
Arguments = string.Join(" ", args.Skip(1)),
WorkingDirectory = Path.GetDirectoryName(args[0]),
};

Process.Start(info);
Expand Down
25 changes: 17 additions & 8 deletions Luatrauma.AutoUpdater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,25 @@ private static void CopyFilesRecursively(string sourcePath, string targetPath)
}
}

public async static Task Update()
public async static Task Update(bool serverOnly = false)
{
Logger.Log("Starting update...");

string patchUrl = null;
if (OperatingSystem.IsWindows())
{
patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_windows_client.zip";
if (serverOnly) { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_windows_server.zip"; }
else { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_windows_client.zip"; }
}
else if (OperatingSystem.IsLinux())
{
patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_linux_client.zip";
if (serverOnly) { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_linux_server.zip"; }
else { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_linux_client.zip"; }
}
else if (OperatingSystem.IsMacOS())
{
patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_mac_client.zip";
if (serverOnly) { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_mac_server.zip"; }
else { patchUrl = "https://github.com/evilfactory/LuaCsForBarotrauma/releases/download/latest/luacsforbarotrauma_patch_mac_client.zip"; }
}

if (patchUrl == null)
Expand Down Expand Up @@ -91,19 +94,25 @@ public async static Task Update()

Logger.Log($"Applying patch...");

string dllFile = "Barotrauma.dll";
if (serverOnly)
{
dllFile = "DedicatedServer.dll";
}

// Verify that the dll version is the same as the current one
string currentDll = Path.Combine(Directory.GetCurrentDirectory(), "Barotrauma.dll");
string newDll = Path.Combine(extractionFolder, "Barotrauma.dll");
string currentDll = Path.Combine(Directory.GetCurrentDirectory(), dllFile);
string newDll = Path.Combine(extractionFolder, dllFile);

if (!File.Exists(currentDll))
{
Logger.Log("Failed to find the current Barotrauma.dll", ConsoleColor.Red);
Logger.Log($"Failed to find the current {dllFile}", ConsoleColor.Red);
return;
}

if (!File.Exists(newDll))
{
Logger.Log("Failed to find the new Barotrauma.dll", ConsoleColor.Red);
Logger.Log($"Failed to find the new {dllFile}", ConsoleColor.Red);
return;
}

Expand Down

0 comments on commit f0c25d1

Please sign in to comment.