From 1539c665f0a210fa9b80b3ddd489f4506af1a457 Mon Sep 17 00:00:00 2001 From: zsyg <3872006562@qq.com> Date: Wed, 2 Jul 2025 09:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E4=BB=A3=E7=A0=81=E8=B4=A8?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppCard.cs | 10 ++++++++-- DownloadManager.cs | 17 +++++++++++++---- ThemeManager.cs | 2 ++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/AppCard.cs b/AppCard.cs index eef218f..7d522a7 100644 --- a/AppCard.cs +++ b/AppCard.cs @@ -347,8 +347,14 @@ namespace AppStore public void UpdateDisplay() { - nameLabel.Text = AppName; - iconBox.Image = AppIcon; + if (nameLabel != null) + { + nameLabel.Text = AppName; + } + if (iconBox != null && AppIcon != null) + { + iconBox.Image = AppIcon; + } } private void DownloadBtn_Click(object sender, EventArgs e) diff --git a/DownloadManager.cs b/DownloadManager.cs index 912b2be..e1f3c2b 100644 --- a/DownloadManager.cs +++ b/DownloadManager.cs @@ -101,11 +101,12 @@ namespace AppStore throw new Exception("无法获取下载文件夹路径"); } - downloadsDir = Marshal.PtrToStringUni(pathPtr); + downloadsDir = Marshal.PtrToStringUni(pathPtr) ?? + Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); } catch { - throw new Exception("无法确定下载文件夹位置,请手动指定下载路径"); + downloadsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); } finally { @@ -114,7 +115,15 @@ namespace AppStore Marshal.FreeCoTaskMem(pathPtr); } } - Directory.CreateDirectory(downloadsDir); + + if (!string.IsNullOrEmpty(downloadsDir)) + { + Directory.CreateDirectory(downloadsDir); + } + else + { + throw new Exception("无法确定下载文件夹位置"); + } @@ -322,7 +331,7 @@ namespace AppStore try { var process = currentProcess; - if (process == null || process.HasExited || process.StartInfo == null) + if (process?.StartInfo == null || process.HasExited) { item.Status = "已取消"; DownloadProgressChanged?.Invoke(item); diff --git a/ThemeManager.cs b/ThemeManager.cs index f9b7e1d..cb45330 100644 --- a/ThemeManager.cs +++ b/ThemeManager.cs @@ -42,6 +42,8 @@ namespace AppStore try { var dir = Path.GetDirectoryName(ThemeConfigPath); + if (dir == null) return; + if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir);