Compare commits

...

2 Commits

Author SHA1 Message Date
zznty
850b313269 fix updates again 2023-01-12 23:29:37 +07:00
zznty
fe985e1a9c fix restart again 2023-01-12 23:20:44 +07:00
2 changed files with 21 additions and 15 deletions

View File

@@ -3,11 +3,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Microsoft.Diagnostics.Runtime; using Microsoft.Diagnostics.Runtime;
using NLog; using NLog;
using PropertyChanged; using PropertyChanged;
@@ -21,8 +20,6 @@ using Torch.API.Session;
using Torch.Commands; using Torch.Commands;
using Torch.Managers.PatchManager; using Torch.Managers.PatchManager;
using Torch.Mod; using Torch.Mod;
using Torch.Mod.Messages;
using Torch.Patches;
using Torch.Server.Commands; using Torch.Server.Commands;
using Torch.Server.Managers; using Torch.Server.Managers;
using Torch.Utils; using Torch.Utils;
@@ -211,7 +208,7 @@ namespace Torch.Server
Environment.Exit(0); Environment.Exit(0);
#endif #endif
var exe = Assembly.GetExecutingAssembly().Location.Replace("dll", "exe"); var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
var args = Environment.GetCommandLineArgs(); var args = Environment.GetCommandLineArgs();

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog; using NLog;
@@ -9,7 +10,7 @@ using Torch.API;
namespace Torch.Managers namespace Torch.Managers
{ {
public class FilesystemManager : Manager public partial class FilesystemManager : Manager
{ {
private static readonly Logger _log = LogManager.GetCurrentClassLogger(); private static readonly Logger _log = LogManager.GetCurrentClassLogger();
/// <summary> /// <summary>
@@ -51,19 +52,27 @@ namespace Torch.Managers
} }
} }
/// <summary>
/// Move the given file (if it exists) to a temporary directory that will be cleared the next time the application starts.
/// </summary>
public void SoftDelete(string path, string file) public void SoftDelete(string path, string file)
{ {
string source = Path.Combine(path, file); var source = Path.Combine(path, file);
if (!File.Exists(source)) if (!File.Exists(source))
return; return;
var rand = Path.GetRandomFileName();
var dest = Path.Combine(TempDirectory, rand); var tempFilePath = Path.Combine(path, file + ".old");
File.Move(source, rand); if (File.Exists(tempFilePath))
string rsource = Path.Combine(path, rand); File.Delete(tempFilePath);
File.Move(rsource, dest);
var errorCode = Rename(source, tempFilePath);
if (Marshal.GetExceptionForHR(errorCode) is { } exception)
throw exception;
} }
[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);
} }
} }