From 218e1456f28f7c028842fd90883b195f31860b5f Mon Sep 17 00:00:00 2001 From: dong <1278815766@qq.com> Date: Fri, 22 Aug 2025 22:55:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=B4=E6=97=B6=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0=E7=A8=8B=E5=BA=8F=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Update.cs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/Update.cs b/Update.cs index a6f49e8..724c3c3 100644 --- a/Update.cs +++ b/Update.cs @@ -1189,25 +1189,28 @@ namespace CheckDownload /// /// 初始化程序使用的临时目录,用于存储下载过程中的临时文件 /// - private void InitializeTempDirectory() - { - try - { - _tempDirectory = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - "Temp", - _appName - ); - - if (!Directory.Exists(_tempDirectory)) - { - Directory.CreateDirectory(_tempDirectory); - } - } - catch (Exception ex) - { - throw new Exception("初始化临时目录 (InitializeTempDirectory)", ex); - } + private void InitializeTempDirectory() + { + try + { + string exeDir = AppDomain.CurrentDomain.BaseDirectory; + + _tempDirectory = Path.Combine(exeDir, "Temp"); + + if (File.Exists(_tempDirectory)) + { + throw new IOException($"无法创建目录,因为已存在同名文件: {_tempDirectory}"); + } + + if (!Directory.Exists(_tempDirectory)) + { + Directory.CreateDirectory(_tempDirectory); + } + } + catch (Exception ex) + { + throw new Exception("初始化临时目录 (InitializeTempDirectory)", ex); + } } ///