Compare commits

..

3 Commits

Author SHA1 Message Date
zznty
2b1a5d4c6e fix script compiler compat with event block mods 2023-02-19 19:44:00 +07:00
zznty
2860dda41b windows moment 2023-02-17 16:32:48 +07:00
zznty
5483728a4e use depot downloader instead of steamcmd because its having some troubles with branching 2023-02-17 16:11:35 +07:00
4 changed files with 41 additions and 29 deletions

View File

@@ -27,10 +27,10 @@ namespace Torch.Server
private static readonly Logger Log = LogManager.GetLogger(nameof(Initializer)); private static readonly Logger Log = LogManager.GetLogger(nameof(Initializer));
private bool _init; private bool _init;
private const string STEAMCMD_DIR = "steamcmd"; private const string TOOL_DIR = "tool";
private const string STEAMCMD_ZIP = "temp.zip"; private const string TOOL_ZIP = "temp.zip";
private static readonly string STEAMCMD_EXE = "steamcmd.exe"; private static readonly string TOOL_EXE = "DepotDownloader.exe";
private const string STEAMCMD_ARGS = "+force_install_dir \"{0}\" +login anonymous +app_update 298740 -beta automtatons-beta +quit"; private const string TOOL_ARGS = "-app 298740 -depot 298741 -beta automatons-beta -dir \"{0}\"";
private TorchServer _server; private TorchServer _server;
internal Persistent<TorchConfig> ConfigPersistent { get; } internal Persistent<TorchConfig> ConfigPersistent { get; }
@@ -57,7 +57,7 @@ namespace Torch.Server
#endif #endif
if (configuration.GetValue("getGameUpdates", true) && !configuration.GetValue("noupdate", false)) if (configuration.GetValue("getGameUpdates", true) && !configuration.GetValue("noupdate", false))
RunSteamCmd(configuration); RunSteamCmdAsync(configuration).Wait();
var processPid = configuration.GetValue<int>("waitForPid"); var processPid = configuration.GetValue<int>("waitForPid");
if (processPid != 0) if (processPid != 0)
@@ -124,36 +124,36 @@ namespace Torch.Server
} }
} }
public static void RunSteamCmd(IConfiguration configuration) public static async Task RunSteamCmdAsync(IConfiguration configuration)
{ {
var log = LogManager.GetLogger("SteamCMD"); var log = LogManager.GetLogger("SteamTool");
var path = configuration.GetValue<string>("steamCmdPath") ?? ApplicationContext.Current.TorchDirectory var path = configuration.GetValue<string>("steamToolPath") ?? ApplicationContext.Current.TorchDirectory
.CreateSubdirectory(STEAMCMD_DIR).FullName; .CreateSubdirectory(TOOL_DIR).FullName;
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {
Directory.CreateDirectory(path); Directory.CreateDirectory(path);
} }
var steamCmdExePath = Path.Combine(path, STEAMCMD_EXE); var steamCmdExePath = Path.Combine(path, TOOL_EXE);
if (!File.Exists(steamCmdExePath)) if (!File.Exists(steamCmdExePath))
{ {
try try
{ {
log.Info("Downloading SteamCMD."); log.Info("Downloading Steam Tool.");
using (var client = new HttpClient()) using (var client = new HttpClient())
using (var file = File.Create(STEAMCMD_ZIP)) await using (var file = File.Create(TOOL_ZIP))
using (var stream = client.GetStreamAsync("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip").Result) await using (var stream = await client.GetStreamAsync("https://github.com/SteamRE/DepotDownloader/releases/download/DepotDownloader_2.4.7/depotdownloader-2.4.7.zip"))
stream.CopyTo(file); await stream.CopyToAsync(file);
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, path); ZipFile.ExtractToDirectory(TOOL_ZIP, path);
File.Delete(STEAMCMD_ZIP); File.Delete(TOOL_ZIP);
log.Info("SteamCMD downloaded successfully!"); log.Info("Steam Tool downloaded successfully!");
} }
catch (Exception e) catch (Exception e)
{ {
log.Error(e, "Failed to download SteamCMD, unable to update the DS."); log.Error(e, "Failed to download Steam Tool, unable to update the DS.");
return; return;
} }
} }
@@ -161,19 +161,16 @@ namespace Torch.Server
log.Info("Checking for DS updates."); log.Info("Checking for DS updates.");
var steamCmdProc = new ProcessStartInfo(steamCmdExePath) var steamCmdProc = new ProcessStartInfo(steamCmdExePath)
{ {
Arguments = string.Format(STEAMCMD_ARGS, configuration.GetValue("gamePath", "../")), Arguments = string.Format(TOOL_ARGS, configuration.GetValue("gamePath", "../")),
WorkingDirectory = path, WorkingDirectory = path,
UseShellExecute = false, RedirectStandardOutput = true
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.ASCII
}; };
var cmd = Process.Start(steamCmdProc); var cmd = Process.Start(steamCmdProc)!;
// ReSharper disable once PossibleNullReferenceException
while (!cmd.HasExited) while (!cmd.HasExited)
{ {
log.Info(cmd.StandardOutput.ReadLine()); if (await cmd.StandardOutput.ReadLineAsync() is { } line)
Thread.Sleep(100); log.Info(line);
} }
} }
} }

View File

@@ -68,7 +68,14 @@ namespace Torch.Managers
if (File.Exists(tempFilePath)) if (File.Exists(tempFilePath))
File.Delete(tempFilePath); File.Delete(tempFilePath);
File.Move(source, tempFilePath); try
{
File.Move(source, tempFilePath);
}
catch (UnauthorizedAccessException)
{
// ignore
}
} }
} }
} }

View File

@@ -109,7 +109,14 @@ namespace Torch.Managers
else else
{ {
_fsManager.SoftDelete(extractPath, file.FullName); _fsManager.SoftDelete(extractPath, file.FullName);
file.ExtractToFile(targetFile, true); try
{
file.ExtractToFile(targetFile, true);
}
catch (Exception e)
{
_log.Warn(e, "unable to extract {0}", targetFile);
}
} }
} }

View File

@@ -60,6 +60,7 @@ namespace Torch.Patches
typeof(System.Security.Policy.Evidence).Assembly.Location, typeof(System.Security.Policy.Evidence).Assembly.Location,
typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location, typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location,
typeof(ProtoContractAttribute).Assembly.Location, typeof(ProtoContractAttribute).Assembly.Location,
Path.Combine(baseDir, "System.Xml.ReaderWriter.dll"),
Path.Combine(baseDir, "netstandard.dll"), Path.Combine(baseDir, "netstandard.dll"),
Path.Combine(baseDir, "System.Runtime.dll"), Path.Combine(baseDir, "System.Runtime.dll"),
Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"), Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"),