From d454ac0fdc54555f155e32a2f09aad68666ea2f2 Mon Sep 17 00:00:00 2001 From: zsyg <3872006562@qq.com> Date: Wed, 2 Jul 2025 10:10:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AboutForm.cs | 288 ++++++++++++++++++++--------------------- DownloadManager.cs | 206 ++++++++++++++++++++++++----- MainForm.cs | 2 +- SettingsForm.cs | 135 +++++++++++++++++++ inno/innosetup_x64.iss | 2 +- inno/innosetup_x86.iss | 2 +- 6 files changed, 453 insertions(+), 182 deletions(-) diff --git a/AboutForm.cs b/AboutForm.cs index af28fac..ccbcabb 100644 --- a/AboutForm.cs +++ b/AboutForm.cs @@ -1,144 +1,144 @@ -using System; -using System.Drawing; -using System.Windows.Forms; - -namespace AppStore -{ - public class AboutUserControl : UserControl - { - private PictureBox logo = null!; - private Label infoLabel = null!; - - public AboutUserControl() - { - InitializeComponent(); - } - - private void InitializeComponent() - { - this.Dock = DockStyle.Fill; - this.BackColor = ThemeManager.BackgroundColor; - this.Padding = new Padding(20); - - // 创建主布局面板 - TableLayoutPanel mainLayout = new TableLayoutPanel(); - mainLayout.Dock = DockStyle.Fill; - mainLayout.BackColor = ThemeManager.BackgroundColor; - mainLayout.ColumnCount = 1; - mainLayout.RowCount = 2; - mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); - mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); - mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); - mainLayout.Padding = new Padding(0, 20, 0, 20); - - // 初始化并添加应用图标 - logo = new PictureBox(); - try - { - logo.Image = Image.FromFile("img/png/kortapp-z.png"); - } - catch (Exception ex) - { - Logger.LogError($"无法加载应用图标: {ex.Message}"); - logo.Image = SystemIcons.Application.ToBitmap(); - } - logo.SizeMode = PictureBoxSizeMode.Zoom; - logo.Width = 200; - logo.Height = 200; - logo.Anchor = AnchorStyles.None; - logo.Margin = new Padding(0, 0, 0, 20); - mainLayout.Controls.Add(logo, 0, 0); - - // 初始化并添加应用信息 - infoLabel = new Label(); - infoLabel.Text = "kortapp-z\n版本: 1.1.1\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和C/C++的软件"; - infoLabel.Font = new Font("Microsoft YaHei", 12); - infoLabel.AutoSize = false; - infoLabel.Width = 300; - infoLabel.Height = 130; // 增加高度确保文字完整显示 - infoLabel.TextAlign = ContentAlignment.MiddleCenter; - infoLabel.Anchor = AnchorStyles.None; - mainLayout.Controls.Add(infoLabel, 0, 1); - - // 调整主布局为3行 - mainLayout.RowCount = 3; - mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); - mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); - mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); - - // 在底部添加GitHub链接区域 - TableLayoutPanel githubPanel = new TableLayoutPanel(); - githubPanel.Dock = DockStyle.Bottom; - githubPanel.BackColor = ThemeManager.BackgroundColor; - githubPanel.Height = 60; - githubPanel.ColumnCount = 3; - githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); - githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); - githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); - githubPanel.RowCount = 1; - githubPanel.Padding = new Padding(10); - - // 添加GitHub图标 - PictureBox githubIcon = new PictureBox(); - try - { - githubIcon.Image = Image.FromFile("img/jpg/github.jpg"); - } - catch (Exception ex) - { - Logger.LogError($"无法加载GitHub图标: {ex.Message}"); - githubIcon.Image = SystemIcons.Application.ToBitmap(); - } - githubIcon.SizeMode = PictureBoxSizeMode.Zoom; - githubIcon.Width = 30; - githubIcon.Height = 30; - githubIcon.Cursor = Cursors.Hand; - githubIcon.Click += (s, e) => { - System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo - { - FileName = "https://github.com/zs-yg/kortapp-z", - UseShellExecute = true - }); - }; - - // 添加文字说明 - Label githubLabel = new Label(); - githubLabel.Text = "🤗🤗🤗开源地址 🌟 欢迎点star和提交pr 🚀"; - githubLabel.Font = new Font("Microsoft YaHei", 10); - githubLabel.AutoSize = true; - githubLabel.Margin = new Padding(10, 0, 0, 0); - - // 创建包含图标和文字的面板 - Panel linkPanel = new Panel(); - linkPanel.AutoSize = true; - linkPanel.BackColor = ThemeManager.BackgroundColor; - linkPanel.Controls.Add(githubIcon); - linkPanel.Controls.Add(githubLabel); - githubIcon.Location = new Point(0, 0); - githubLabel.Location = new Point(githubIcon.Width + 10, 5); - - // 将链接面板添加到中间列 - githubPanel.Controls.Add(linkPanel, 1, 0); - - this.Controls.Add(mainLayout); - this.Controls.Add(githubPanel); - } - } - - // 保留原AboutForm作为容器(可选) - public class AboutForm : Form - { - public AboutForm() - { - this.Text = "关于 kortapp-z"; - this.Size = new Size(500, 400); - this.StartPosition = FormStartPosition.CenterScreen; - this.FormBorderStyle = FormBorderStyle.FixedDialog; - this.MaximizeBox = false; - this.MinimizeBox = false; - - var aboutControl = new AboutUserControl(); - this.Controls.Add(aboutControl); - } - } -} +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace AppStore +{ + public class AboutUserControl : UserControl + { + private PictureBox logo = null!; + private Label infoLabel = null!; + + public AboutUserControl() + { + InitializeComponent(); + } + + private void InitializeComponent() + { + this.Dock = DockStyle.Fill; + this.BackColor = ThemeManager.BackgroundColor; + this.Padding = new Padding(20); + + // 创建主布局面板 + TableLayoutPanel mainLayout = new TableLayoutPanel(); + mainLayout.Dock = DockStyle.Fill; + mainLayout.BackColor = ThemeManager.BackgroundColor; + mainLayout.ColumnCount = 1; + mainLayout.RowCount = 2; + mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); + mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); + mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); + mainLayout.Padding = new Padding(0, 20, 0, 20); + + // 初始化并添加应用图标 + logo = new PictureBox(); + try + { + logo.Image = Image.FromFile("img/png/kortapp-z.png"); + } + catch (Exception ex) + { + Logger.LogError($"无法加载应用图标: {ex.Message}"); + logo.Image = SystemIcons.Application.ToBitmap(); + } + logo.SizeMode = PictureBoxSizeMode.Zoom; + logo.Width = 200; + logo.Height = 200; + logo.Anchor = AnchorStyles.None; + logo.Margin = new Padding(0, 0, 0, 20); + mainLayout.Controls.Add(logo, 0, 0); + + // 初始化并添加应用信息 + infoLabel = new Label(); + infoLabel.Text = "kortapp-z\n版本: 1.1.3\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和C/C++的软件"; + infoLabel.Font = new Font("Microsoft YaHei", 12); + infoLabel.AutoSize = false; + infoLabel.Width = 300; + infoLabel.Height = 130; // 增加高度确保文字完整显示 + infoLabel.TextAlign = ContentAlignment.MiddleCenter; + infoLabel.Anchor = AnchorStyles.None; + mainLayout.Controls.Add(infoLabel, 0, 1); + + // 调整主布局为3行 + mainLayout.RowCount = 3; + mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); + mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize)); + mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); + + // 在底部添加GitHub链接区域 + TableLayoutPanel githubPanel = new TableLayoutPanel(); + githubPanel.Dock = DockStyle.Bottom; + githubPanel.BackColor = ThemeManager.BackgroundColor; + githubPanel.Height = 60; + githubPanel.ColumnCount = 3; + githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); + githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F)); + githubPanel.RowCount = 1; + githubPanel.Padding = new Padding(10); + + // 添加GitHub图标 + PictureBox githubIcon = new PictureBox(); + try + { + githubIcon.Image = Image.FromFile("img/jpg/github.jpg"); + } + catch (Exception ex) + { + Logger.LogError($"无法加载GitHub图标: {ex.Message}"); + githubIcon.Image = SystemIcons.Application.ToBitmap(); + } + githubIcon.SizeMode = PictureBoxSizeMode.Zoom; + githubIcon.Width = 30; + githubIcon.Height = 30; + githubIcon.Cursor = Cursors.Hand; + githubIcon.Click += (s, e) => { + System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo + { + FileName = "https://github.com/zs-yg/kortapp-z", + UseShellExecute = true + }); + }; + + // 添加文字说明 + Label githubLabel = new Label(); + githubLabel.Text = "🤗🤗🤗开源地址 🌟 欢迎点star和提交pr 🚀"; + githubLabel.Font = new Font("Microsoft YaHei", 10); + githubLabel.AutoSize = true; + githubLabel.Margin = new Padding(10, 0, 0, 0); + + // 创建包含图标和文字的面板 + Panel linkPanel = new Panel(); + linkPanel.AutoSize = true; + linkPanel.BackColor = ThemeManager.BackgroundColor; + linkPanel.Controls.Add(githubIcon); + linkPanel.Controls.Add(githubLabel); + githubIcon.Location = new Point(0, 0); + githubLabel.Location = new Point(githubIcon.Width + 10, 5); + + // 将链接面板添加到中间列 + githubPanel.Controls.Add(linkPanel, 1, 0); + + this.Controls.Add(mainLayout); + this.Controls.Add(githubPanel); + } + } + + // 保留原AboutForm作为容器(可选) + public class AboutForm : Form + { + public AboutForm() + { + this.Text = "关于 kortapp-z"; + this.Size = new Size(500, 400); + this.StartPosition = FormStartPosition.CenterScreen; + this.FormBorderStyle = FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + + var aboutControl = new AboutUserControl(); + this.Controls.Add(aboutControl); + } + } +} diff --git a/DownloadManager.cs b/DownloadManager.cs index e1f3c2b..152d8fb 100644 --- a/DownloadManager.cs +++ b/DownloadManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; +using System.Text.Json; using System.Threading.Tasks; using System.Windows.Forms; @@ -85,44 +86,38 @@ namespace AppStore private void DownloadFile(DownloadItem downloadItem, string fileName, string url) { + string downloadsDir = string.Empty; try { - // 设置下载目录为用户文件夹中的Downloads - // 获取系统下载文件夹路径 - // 获取系统下载文件夹路径 - string downloadsDir; - IntPtr pathPtr = IntPtr.Zero; + // 获取并验证下载路径 + downloadsDir = GetDownloadPath(); + try { - // 使用SHGetKnownFolderPath API获取下载文件夹 - var downloadsFolderGuid = new Guid("374DE290-123F-4565-9164-39C4925E467B"); - if (SHGetKnownFolderPath(downloadsFolderGuid, 0, IntPtr.Zero, out pathPtr) != 0) + // 检查路径是否有效 + if (string.IsNullOrWhiteSpace(downloadsDir)) { - throw new Exception("无法获取下载文件夹路径"); + throw new Exception("下载路径为空"); } - - downloadsDir = Marshal.PtrToStringUni(pathPtr) ?? - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); - } - catch - { - downloadsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); - } - finally - { - if (pathPtr != IntPtr.Zero) - { - Marshal.FreeCoTaskMem(pathPtr); - } - } - - if (!string.IsNullOrEmpty(downloadsDir)) - { + + // 尝试创建目录(如果不存在) Directory.CreateDirectory(downloadsDir); + + // 验证目录是否可写 + string testFile = Path.Combine(downloadsDir, "write_test.tmp"); + File.WriteAllText(testFile, "test"); + File.Delete(testFile); } - else + catch (Exception ex) { - throw new Exception("无法确定下载文件夹位置"); + // 回退到默认下载路径 + string defaultPath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + "Downloads"); + + Logger.LogError($"下载路径{downloadsDir}不可用,将使用默认路径: {defaultPath}", ex); + downloadsDir = defaultPath; + Directory.CreateDirectory(downloadsDir); } @@ -318,12 +313,20 @@ namespace AppStore currentProcess.BeginErrorReadLine(); progressTimer.Start(); } - catch (Exception ex) - { - downloadItem.Status = $"下载错误: {ex.Message}"; - DownloadCompleted?.Invoke(downloadItem); - - } + catch (Exception ex) + { + string errorDetails = $"下载错误: {ex.Message}\n"; + errorDetails += $"目标路径: {downloadsDir}\n"; + errorDetails += $"URL: {url}"; + + downloadItem.Status = $"下载失败: {ex.Message}"; + Logger.LogError(errorDetails, ex); + + MessageBox.Show($"下载失败:\n{errorDetails}", "错误", + MessageBoxButtons.OK, MessageBoxIcon.Error); + + DownloadCompleted?.Invoke(downloadItem); + } } public void CancelDownload(DownloadItem item) @@ -351,5 +354,138 @@ namespace AppStore DownloadProgressChanged?.Invoke(item); } } + + private string GetDownloadPath() + { + // 1. 优先读取用户设置的下载路径 + try + { + string jsonPath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "zsyg", "kortapp-z", ".date", "dl_path", "download_path.json"); + + Logger.Log($"尝试读取下载路径配置文件: {jsonPath}"); + + if (File.Exists(jsonPath)) + { + string jsonString = File.ReadAllText(jsonPath); + Logger.Log($"配置文件内容: {jsonString}"); + + var jsonData = JsonSerializer.Deserialize(jsonString); + string customPath = jsonData.GetProperty("DownloadPath").GetString()?.Trim(); + + if (!string.IsNullOrWhiteSpace(customPath)) + { + Logger.Log($"读取到自定义路径: {customPath}"); + + // 处理路径格式 + customPath = customPath.Replace(@"\\", @"\"); + try + { + // 处理路径中的环境变量和特殊字符 + customPath = Environment.ExpandEnvironmentVariables(customPath); + customPath = Path.GetFullPath(customPath); + Logger.Log($"标准化后的路径: {customPath}"); + + // 确保路径以目录分隔符结尾 + if (!customPath.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + customPath += Path.DirectorySeparatorChar; + } + + // 验证驱动器是否存在 + string drive = Path.GetPathRoot(customPath); + if (!Directory.Exists(drive)) + { + Logger.LogError($"驱动器不存在: {drive}"); + throw new Exception($"驱动器 {drive} 不存在"); + } + + // 验证路径 + if (!Directory.Exists(customPath)) + { + Logger.Log($"创建目录: {customPath}"); + Directory.CreateDirectory(customPath); + } + + // 更严格的路径可写性测试 + string testFile = Path.Combine(customPath, $"write_test_{Guid.NewGuid()}.tmp"); + Logger.Log($"测试路径可写性: {testFile}"); + try + { + File.WriteAllText(testFile, DateTime.Now.ToString()); + string content = File.ReadAllText(testFile); + File.Delete(testFile); + Logger.Log($"路径验证成功: {customPath}"); + return customPath.TrimEnd(Path.DirectorySeparatorChar); + } + catch (Exception ex) + { + Logger.LogError($"路径不可写: {customPath}", ex); + throw new Exception($"路径不可写: {customPath}"); + } + } + catch (Exception ex) + { + Logger.LogError($"路径处理失败: {customPath}", ex); + throw; + } + } + } + else + { + Logger.Log("未找到下载路径配置文件"); + } + } + catch (Exception ex) + { + Logger.LogError("读取自定义下载路径失败", ex); + } + + // 2. 回退到系统默认下载路径 + IntPtr pathPtr = IntPtr.Zero; + try + { + var downloadsFolderGuid = new Guid("374DE290-123F-4565-9164-39C4925E467B"); + if (SHGetKnownFolderPath(downloadsFolderGuid, 0, IntPtr.Zero, out pathPtr) == 0) + { + string defaultPath = Marshal.PtrToStringUni(pathPtr); + if (!string.IsNullOrEmpty(defaultPath)) + { + Directory.CreateDirectory(defaultPath); + return defaultPath; + } + } + } + catch (Exception ex) + { + Logger.LogError("获取系统下载路径失败", ex); + } + finally + { + if (pathPtr != IntPtr.Zero) + { + Marshal.FreeCoTaskMem(pathPtr); + } + } + + // 3. 最终回退到相对路径 ~/Downloads + string relativePath = "~/Downloads"; + string fallbackPath = relativePath.Replace("~", + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); + fallbackPath = Path.GetFullPath(fallbackPath); + + try { + Directory.CreateDirectory(fallbackPath); + // 测试路径可写性 + string testFile = Path.Combine(fallbackPath, "write_test.tmp"); + File.WriteAllText(testFile, "test"); + File.Delete(testFile); + return fallbackPath; + } + catch { + throw new Exception($"无法使用默认下载路径: {fallbackPath}"); + } + } } } diff --git a/MainForm.cs b/MainForm.cs index e9a7708..1942d62 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -715,7 +715,7 @@ namespace AppStore flowPanel.Controls.Add(CreateAppCard( "XDM", - "https://hub.gitmirror.com/https://github.com/subhra74/xdm/releases/download/7.2.11/xdm-setup.msi", + "https://ghproxy.net/https://github.com/subhra74/xdm/releases/download/7.2.11/xdm-setup.msi", "img/png/XDM.png")); flowPanel.Controls.Add(CreateAppCard( diff --git a/SettingsForm.cs b/SettingsForm.cs index 5f06260..067037f 100644 --- a/SettingsForm.cs +++ b/SettingsForm.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Windows.Forms; using System.Drawing; +using System.Text.Json; namespace AppStore { @@ -49,7 +50,43 @@ namespace AppStore btnCleanLogs.Click += (s, e) => CleanLogs(); this.Controls.Add(btnCleanLogs); + // 下载路径设置 + Label lblDownloadPath = new Label(); + lblDownloadPath.Text = "下载路径:"; + lblDownloadPath.AutoSize = true; + lblDownloadPath.Location = new Point((this.Width - 300) / 2, 170); + lblDownloadPath.Font = new Font("Microsoft YaHei", 10); + lblDownloadPath.Anchor = AnchorStyles.Top; + this.Controls.Add(lblDownloadPath); + + TextBox txtDownloadPath = new TextBox(); + txtDownloadPath.Size = new Size(300, 30); + txtDownloadPath.Location = new Point((this.Width - 300) / 2, 200); + txtDownloadPath.Font = new Font("Microsoft YaHei", 10); + txtDownloadPath.Anchor = AnchorStyles.Top; + txtDownloadPath.ReadOnly = true; + this.Controls.Add(txtDownloadPath); + + Button btnBrowse = new Button(); + btnBrowse.Text = "浏览..."; + btnBrowse.Size = new Size(80, 30); + btnBrowse.Location = new Point(txtDownloadPath.Right + 10, 200); + btnBrowse.Font = new Font("Microsoft YaHei", 10); + btnBrowse.Anchor = AnchorStyles.Top; + btnBrowse.Click += (s, e) => BrowseDownloadPath(txtDownloadPath); + this.Controls.Add(btnBrowse); + + Button btnSavePath = new Button(); + btnSavePath.Text = "保存路径"; + btnSavePath.Size = new Size(100, 30); + btnSavePath.Location = new Point((this.Width - 100) / 2, 240); + btnSavePath.Font = new Font("Microsoft YaHei", 10); + btnSavePath.Anchor = AnchorStyles.Top; + btnSavePath.Click += (s, e) => SaveDownloadPath(txtDownloadPath.Text); + this.Controls.Add(btnSavePath); + ThemeManager.ThemeChanged += OnThemeChanged; + LoadDownloadPath(txtDownloadPath); } private void SwitchTheme(ThemeManager.ThemeMode theme) @@ -84,5 +121,103 @@ namespace AppStore MessageBox.Show($"清理日志时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void BrowseDownloadPath(TextBox txtBox) + { + using (FolderBrowserDialog dialog = new FolderBrowserDialog()) + { + dialog.Description = "选择下载路径"; + if (dialog.ShowDialog() == DialogResult.OK) + { + txtBox.Text = dialog.SelectedPath; + } + } + } + + private void SaveDownloadPath(string path) + { + try + { + // 验证路径 + if (string.IsNullOrWhiteSpace(path)) + { + MessageBox.Show("下载路径不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // 尝试创建目录(如果不存在) + try + { + Directory.CreateDirectory(path); + + // 验证目录是否可写 + string testFile = Path.Combine(path, "write_test.tmp"); + File.WriteAllText(testFile, "test"); + File.Delete(testFile); + } + catch + { + MessageBox.Show($"无法访问路径: {path}\n请确保路径存在且有写入权限", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + // 保存路径 + string dlPathDir = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "zsyg", "kortapp-z", ".date", "dl_path"); + + if (!Directory.Exists(dlPathDir)) + { + Directory.CreateDirectory(dlPathDir); + } + + string jsonPath = Path.Combine(dlPathDir, "download_path.json"); + var jsonData = new { DownloadPath = path }; + string jsonString = JsonSerializer.Serialize(jsonData); + + File.WriteAllText(jsonPath, jsonString); + + MessageBox.Show($"下载路径已保存到:\n{path}", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + Logger.LogError("保存下载路径时出错", ex); + MessageBox.Show($"保存下载路径时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadDownloadPath(TextBox txtBox) + { + // 默认下载路径为用户文件夹下的Downloads + string defaultPath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), + "Downloads"); + + try + { + string jsonPath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "zsyg", "kortapp-z", ".date", "dl_path", "download_path.json"); + + if (File.Exists(jsonPath)) + { + string jsonString = File.ReadAllText(jsonPath); + var jsonData = JsonSerializer.Deserialize(jsonString); + string customPath = jsonData.GetProperty("DownloadPath").GetString(); + + // 如果自定义路径有效则显示,否则显示默认路径 + txtBox.Text = !string.IsNullOrWhiteSpace(customPath) ? customPath : defaultPath; + } + else + { + txtBox.Text = defaultPath; + } + } + catch (Exception ex) + { + Logger.LogError("加载下载路径时出错", ex); + txtBox.Text = defaultPath; + } + } } } diff --git a/inno/innosetup_x64.iss b/inno/innosetup_x64.iss index c197f43..3fb8954 100644 --- a/inno/innosetup_x64.iss +++ b/inno/innosetup_x64.iss @@ -2,7 +2,7 @@ ; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档! #define MyAppName "kortapp-z" -#define MyAppVersion "1.1.2" +#define MyAppVersion "1.1.3" #define MyAppPublisher "zsyg" #define MyAppURL "https://github.com/zs-yg/kortapp-z" #define MyAppExeName "kortapp.exe" diff --git a/inno/innosetup_x86.iss b/inno/innosetup_x86.iss index 1a2d247..abef259 100644 --- a/inno/innosetup_x86.iss +++ b/inno/innosetup_x86.iss @@ -2,7 +2,7 @@ ; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档! #define MyAppName "kortapp-z" -#define MyAppVersion "1.1.2" +#define MyAppVersion "1.1.3" #define MyAppPublisher "zsyg" #define MyAppURL "https://github.com/zs-yg/kortapp-z" #define MyAppExeName "kortapp.exe"