From 3fc4283183374050ef157e8f88fa472d3e712ee8 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Sat, 21 Oct 2017 17:08:38 -0400 Subject: [PATCH] Guards the interface DLL copy operation --- TGServerService/DreamDaemon.cs | 31 +++++++++++++++++++++++++++++-- TGServerService/ServerService.cs | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/TGServerService/DreamDaemon.cs b/TGServerService/DreamDaemon.cs index ff6fac5c66..c56993a803 100644 --- a/TGServerService/DreamDaemon.cs +++ b/TGServerService/DreamDaemon.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using System.Threading; using System.Timers; @@ -438,11 +439,37 @@ namespace TGServerService void UpdateInterfaceDll(bool overwrite) { - if (File.Exists(InterfaceDLLName) && !overwrite) + var FileExists = File.Exists(InterfaceDLLName); + if (FileExists && !overwrite) return; //Copy the interface dll to the static dir var InterfacePath = Assembly.GetAssembly(typeof(DDInteropCallHolder)).Location; - File.Copy(InterfacePath, InterfaceDLLName, overwrite); + try + { + if (FileExists) + { + var Old = File.ReadAllBytes(InterfaceDLLName); + var New = File.ReadAllBytes(InterfacePath); + if (Old.SequenceEqual(New)) + return; //no need + } + File.Copy(InterfacePath, InterfaceDLLName, overwrite); + TGServerService.WriteInfo("Updated interface DLL", TGServerService.EventID.InterfaceDLLUpdated); + } + catch + { + try + { + //ok the things being stupid and hasn't released the dll yet, try ONCE more + Thread.Sleep(1000); + File.Copy(InterfacePath, InterfaceDLLName, overwrite); + } + catch (Exception e) + { + //intentionally using the fi + TGServerService.WriteError("Failed to update interface DLL! Error: " + e.ToString(), TGServerService.EventID.InterfaceDLLUpdateFail); + } + } } //used by Start and Watchdog to start a DD instance diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index f277dfd2f9..426024138f 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -70,6 +70,8 @@ namespace TGServerService RepoPushFail = 5500, RepoChangelog = 5600, RepoChangelogFail = 5700, + InterfaceDLLUpdated = 5800, + InterfaceDLLUpdateFail = 5900, ServiceShutdownFail = 6100, WorldReboot = 6200, ServerUpdateApplied = 6300,