fix auto-updates and crash handler restart
This commit is contained in:
@@ -32,9 +32,25 @@ internal class UnhandledExceptionHandler
|
||||
{
|
||||
Console.WriteLine("Restarting in 5 seconds.");
|
||||
Thread.Sleep(5000);
|
||||
|
||||
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
|
||||
|
||||
Process.Start(exe, $"-waitForPid {Environment.ProcessId} {_config}");
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i].Contains(' '))
|
||||
args[i] = $"\"{args[i]}\"";
|
||||
|
||||
if (!args[i].Contains("--tempAutostart", StringComparison.InvariantCultureIgnoreCase) &&
|
||||
!args[i].Contains("--waitForPid", StringComparison.InvariantCultureIgnoreCase))
|
||||
continue;
|
||||
|
||||
args[i] = string.Empty;
|
||||
args[++i] = string.Empty;
|
||||
}
|
||||
|
||||
Process.Start(exe, $"--waitForPid {Environment.ProcessId} --tempAutostart true {string.Join(" ", args)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -58,21 +58,18 @@ namespace Torch.Managers
|
||||
if (!File.Exists(source))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
File.Delete(source);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
var tempFilePath = Path.Combine(path, file + ".old");
|
||||
if (File.Exists(tempFilePath))
|
||||
File.Delete(tempFilePath);
|
||||
|
||||
var errorCode = Rename(source, tempFilePath);
|
||||
if (Marshal.GetExceptionForHR(errorCode) is { } exception)
|
||||
throw exception;
|
||||
File.Move(source, tempFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
[LibraryImport("msvcrt", SetLastError = true, EntryPoint = "rename")]
|
||||
[UnmanagedCallConv(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
|
||||
private static partial int Rename(
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
string oldpath,
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
string newpath);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user