From ff2941134dbaa7e1bc9e23ee1f1c5774b64131b4 Mon Sep 17 00:00:00 2001 From: aiqinxuancai Date: Thu, 1 Aug 2024 17:26:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=87=E7=BA=A7=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DiscordProxyStart/Servers/WinStartManager.cs | 67 +++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/DiscordProxyStart/Servers/WinStartManager.cs b/DiscordProxyStart/Servers/WinStartManager.cs index 6d157dd..493bb77 100644 --- a/DiscordProxyStart/Servers/WinStartManager.cs +++ b/DiscordProxyStart/Servers/WinStartManager.cs @@ -277,47 +277,52 @@ private static bool CopyVersionDll(string setupPath) foreach (var path in appPath.allPaths) { - var discordExeName = GetPathDiscordName(path); - if (!string.IsNullOrEmpty(discordExeName)) + try { - runCount++; - var discordExePath = Path.Combine(path, discordExeName); - var exeMachineType = PEUtils.GetExecutableMachineType(discordExePath); - var targetDllPath = Path.Combine(path, "version.dll"); - var dllFilePath = Path.Combine(AppContext.BaseDirectory, "x86", "version.dll"); - - if (exeMachineType == PEUtils.MachineType.IMAGE_FILE_MACHINE_AMD64) + var discordExeName = GetPathDiscordName(path); + if (!string.IsNullOrEmpty(discordExeName)) { - dllFilePath = Path.Combine(AppContext.BaseDirectory, "x64", "version.dll"); - } + var discordExePath = Path.Combine(path, discordExeName); + var exeMachineType = PEUtils.GetExecutableMachineType(discordExePath); + var targetDllPath = Path.Combine(path, "version.dll"); + var dllFilePath = Path.Combine(AppContext.BaseDirectory, "x86", "version.dll"); + if (exeMachineType == PEUtils.MachineType.IMAGE_FILE_MACHINE_AMD64) + { + dllFilePath = Path.Combine(AppContext.BaseDirectory, "x64", "version.dll"); + } - if (!File.Exists(dllFilePath)) - { - throw new FileNotFoundException($"没有找到本地的 {dllFilePath}"); - } - if (!File.Exists(discordExePath)) - { - throw new FileNotFoundException($"目标路径没有 {discordExePath} ???"); - } - if (!File.Exists(targetDllPath)) - { - File.Copy(dllFilePath, targetDllPath, true); //TODO 文件有可能被占用? - } - else - { - //用于处理已经存在旧版本的情况 - var nowDllInfo = new FileInfo(targetDllPath); - var dllInfo = new FileInfo(dllFilePath); - if (dllInfo.Length != nowDllInfo.Length) + if (!File.Exists(dllFilePath)) + { + throw new FileNotFoundException($"没有找到本地的 {dllFilePath}"); + } + if (!File.Exists(discordExePath)) + { + throw new FileNotFoundException($"目标路径没有 {discordExePath} ???"); + } + + if (!File.Exists(targetDllPath)) { File.Copy(dllFilePath, targetDllPath, true); //TODO 文件有可能被占用? } + else + { + //用于处理已经存在旧版本的情况 + var nowDllInfo = new FileInfo(targetDllPath); + var dllInfo = new FileInfo(dllFilePath); + if (dllInfo.Length != nowDllInfo.Length) + { + File.Copy(dllFilePath, targetDllPath, true); //TODO 文件有可能被占用? + } + } + runCount++; } } - - + catch (Exception ex) + { + //某个目录无法复制,可能是原因目录是空的,或者没有权限等问题。 + } }