it was needed, but with some checks

This commit is contained in:
z__
2022-02-09 20:25:09 +07:00
parent 67f25ab20b
commit 0632f68aaf

View File

@@ -91,9 +91,20 @@ namespace Torch.Server
}
private static void CopyNative(string binPath)
{
var log = LogManager.GetLogger("TorchLauncher");
var workingDir = new DirectoryInfo(Directory.GetCurrentDirectory());
if (workingDir.Attributes.HasFlag(FileAttributes.ReadOnly))
{
log.Warn("Game directory is readonly. You should copy steam_api64.dll, Havok.dll from bin manually");
return;
}
try
{
var apiSource = Path.Combine(binPath, "steam_api64.dll");
var apiTarget = Path.Combine(AppContext.BaseDirectory, "steam_api64.dll");
var apiTarget = Path.Combine(workingDir.FullName, "steam_api64.dll");
if (!File.Exists(apiTarget))
{
File.Copy(apiSource, apiTarget);
@@ -105,7 +116,7 @@ namespace Torch.Server
}
var havokSource = Path.Combine(binPath, "Havok.dll");
var havokTarget = Path.Combine(AppContext.BaseDirectory, "Havok.dll");
var havokTarget = Path.Combine(workingDir.FullName, "Havok.dll");
if (!File.Exists(havokTarget))
{
@@ -117,5 +128,14 @@ namespace Torch.Server
File.Copy(havokSource, havokTarget);
}
}
catch (UnauthorizedAccessException)
{
// file is being used by another process, probably previous torch has not been closed yet
}
catch (Exception e)
{
log.Error(e);
}
}
}
}