From f2a2f48020d67748176b7df97f1c91f9aab34a23 Mon Sep 17 00:00:00 2001 From: zsyg <3872006562@qq.com> Date: Thu, 19 Jun 2025 20:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppCard.cs | 116 +++++++++++++++++++++++++++++++++++++----------- MainForm.cs | 125 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 185 insertions(+), 56 deletions(-) diff --git a/AppCard.cs b/AppCard.cs index 46c7388..a69b584 100644 --- a/AppCard.cs +++ b/AppCard.cs @@ -23,9 +23,14 @@ namespace AppStore public AppCard() { - iconBox = new PictureBox(); - nameLabel = new Label(); - downloadBtn = new Button(); + // 确保关键对象不为null + iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage }; + nameLabel = new Label() { Text = string.Empty }; + downloadBtn = new Button() { Text = "下载" }; + + // 确保DownloadManager已初始化 + var _ = DownloadManager.Instance; + InitializeComponent(); } @@ -241,25 +246,64 @@ namespace AppStore } } - // 应用计算好的路径 - if (path != null) + // 应用计算好的路径 - 更严格的null检查和异常处理 + try { - this.Invoke((MethodInvoker)delegate { - this.Region = new Region(path); // 设置控件区域 - this.Refresh(); // 重绘控件 - }); + var safePath = path ?? CalculatePathFallback(Width, Height, 10); + // 更严格的null检查,包括路径和控件状态 + if (safePath != null && + safePath.PointCount > 0 && + this.IsHandleCreated && + !this.IsDisposed) + { + this.Invoke((MethodInvoker)delegate { + try + { + // 委托内部再次验证safePath + if (safePath != null && safePath.PointCount > 0) + { + var validPath = safePath; // 确保非null + using (var region = new Region(validPath)) + { + this.Region = region; + this.Refresh(); + } + } + } + catch (Exception ex) + { + Debug.WriteLine($"创建Region失败: {ex.Message}"); + this.Region = null; + this.Refresh(); + } + }); + } + } + catch (Exception ex) + { + Debug.WriteLine($"初始化卡片路径失败: {ex.Message}"); } } private System.Drawing.Drawing2D.GraphicsPath CalculatePathFallback(int width, int height, int radius) { - var path = new System.Drawing.Drawing2D.GraphicsPath(); - path.AddArc(0, 0, radius * 2, radius * 2, 180, 90); - path.AddArc(width - radius * 2, 0, radius * 2, radius * 2, 270, 90); - path.AddArc(width - radius * 2, height - radius * 2, radius * 2, radius * 2, 0, 90); - path.AddArc(0, height - radius * 2, radius * 2, radius * 2, 90, 90); - path.CloseFigure(); - return path; + try + { + var path = new System.Drawing.Drawing2D.GraphicsPath(); + path.AddArc(0, 0, radius * 2, radius * 2, 180, 90); + path.AddArc(width - radius * 2, 0, radius * 2, radius * 2, 270, 90); + path.AddArc(width - radius * 2, height - radius * 2, radius * 2, radius * 2, 0, 90); + path.AddArc(0, height - radius * 2, radius * 2, radius * 2, 90, 90); + path.CloseFigure(); + return path; + } + catch + { + // 绝对回退方案 - 返回最小有效路径 + var path = new System.Drawing.Drawing2D.GraphicsPath(); + path.AddRectangle(new Rectangle(0, 0, width, height)); + return path; + } } public void UpdateDisplay() @@ -270,19 +314,39 @@ namespace AppStore private void DownloadBtn_Click(object sender, EventArgs e) { - if (sender == null || e == null) return; - if (!string.IsNullOrEmpty(DownloadUrl)) + try { - try + // 更严格的null检查 + // 更严格的null检查,包括DownloadManager.Instance和其方法 + // 全面的null和状态检查 + if (sender == null || e == null || + string.IsNullOrWhiteSpace(DownloadUrl) || + string.IsNullOrWhiteSpace(AppName) || + !this.IsHandleCreated || + this.IsDisposed || + DownloadManager.Instance == null || + DownloadManager.Instance.DownloadItems == null || + DownloadManager.Instance.StartDownload == null) { - string fileName = $"{AppName.Replace(" ", "_")}.exe"; - DownloadManager.Instance.StartDownload(fileName, DownloadUrl); - MessageBox.Show($"已开始下载: {AppName}", "下载中", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - catch (Exception ex) - { - MessageBox.Show($"下载失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } + + string safeAppName = AppName ?? "未知应用"; + string fileName = $"{safeAppName.Replace(" ", "_")}.exe"; + + DownloadManager.Instance.StartDownload(fileName, DownloadUrl); + + string message = $"已开始下载: {safeAppName}"; + this.Invoke((MethodInvoker)delegate { + MessageBox.Show(this, message, "下载中", MessageBoxButtons.OK, MessageBoxIcon.Information); + }); + } + catch (Exception ex) + { + Debug.WriteLine($"下载按钮点击处理失败: {ex.Message}"); + this.Invoke((MethodInvoker)delegate { + MessageBox.Show(this, "下载处理发生错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + }); } } } diff --git a/MainForm.cs b/MainForm.cs index 0c38305..ff420ba 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -201,11 +201,86 @@ namespace AppStore // 添加所有应用卡片 + flowPanel.Controls.Add(CreateAppCard( + "XDM", + "https://github.com/subhra74/xdm/releases/download/7.2.11/xdm-setup.msi", + "img/png/XDM.png")); + + flowPanel.Controls.Add(CreateAppCard( + "FDM", + "https://files2.freedownloadmanager.org/6/latest/fdm_x64_setup.exe", + "img/png/FDM.png")); + + flowPanel.Controls.Add(CreateAppCard( + "ABDM", + "https://ghproxy.net/https://github.com/amir1376/ab-download-manager/releases/download/v1.6.4/ABDownloadManager_1.6.4_windows_x64.exe", + "img/png/ABDM.png")); + flowPanel.Controls.Add(CreateAppCard( "python3.8", "https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe", "img/png/python.png")); + + flowPanel.Controls.Add(CreateAppCard( + "Oracle Java8", + "https://sdlc-esd.oracle.com/ESD6/JSCDL/jdk/8u451-b10/8a1589aa0fe24566b4337beee47c2d29/jre-8u451-windows-x64.exe?GroupName=JSC&FilePath=/ESD6/JSCDL/jdk/8u451-b10/8a1589aa0fe24566b4337beee47c2d29/jre-8u451-windows-x64.exe&BHost=javadl.sun.com&File=jre-8u451-windows-x64.exe&AuthParam=1750252610_4d0f61835e3392b8f0158398fd5ebd90&ext=.exe", + "img/png/java.png")); + + flowPanel.Controls.Add(CreateAppCard( + "Rust", + "https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe", + "img/png/rust.png")); + + flowPanel.Controls.Add(CreateAppCard( + "Ruby", + "https://mirror.sjtu.edu.cn/github-release/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.4.4-2/rubyinstaller-devkit-3.4.4-2-x64.exe", + "img/png/ruby.png")); + + flowPanel.Controls.Add(CreateAppCard( + "D", + "https://downloads.dlang.org/releases/2.x/2.111.0/dmd-2.111.0.exe", + "img/jpg/D.jpg")); + + flowPanel.Controls.Add(CreateAppCard( + "Go", + "https://golang.google.cn/dl/go1.24.4.windows-amd64.msi", + "img/png/Go.png")); + + flowPanel.Controls.Add(CreateAppCard( + "Node.js", + "https://nodejs.org/dist/v22.16.0/node-v22.16.0-x64.msi", + "img/png/nodejs.png")); + flowPanel.Controls.Add(CreateAppCard( + "mingw-64", + "https://ghproxy.net/https://github.com/niXman/mingw-builds-binaries/releases/download/15.1.0-rt_v12-rev0/x86_64-15.1.0-release-posix-seh-ucrt-rt_v12-rev0.7z", + "img/png/mingw-64.png")); + + flowPanel.Controls.Add(CreateAppCard( + "Msys2", + "https://github.com/msys2/msys2-installer/releases/download/2025-02-21/msys2-x86_64-20250221.exe", + "img/png/MSYS2.png")); + + flowPanel.Controls.Add(CreateAppCard( + ".NET SDK 8.0", + "https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/sdk-8.0.411-windows-x64-installer", + "img/png/.NET.png")); + + flowPanel.Controls.Add(CreateAppCard( + "ASP.NET Core 运行时 8.0", + "https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/runtime-aspnetcore-8.0.17-windows-x64-installer", + "img/png/.NET.png")); + + flowPanel.Controls.Add(CreateAppCard( + ".NET 桌面运行时 8.0", + "https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/runtime-desktop-8.0.17-windows-x64-installer", + "img/png/.NET.png")); + + flowPanel.Controls.Add(CreateAppCard( + ".NET 运行时 8.0", + "https://dotnet.microsoft.com/zh-cn/download/dotnet/thank-you/runtime-8.0.17-windows-x64-installer", + "img/png/.NET.png")); + flowPanel.Controls.Add(CreateAppCard( "openlist", "https://ghproxy.net/https://github.com/OpenListTeam/OpenList/releases/download/beta/openlist-windows-amd64.zip", @@ -226,6 +301,11 @@ namespace AppStore "https://vscode.download.prss.microsoft.com/dbazure/download/stable/dfaf44141ea9deb3b4096f7cd6d24e00c147a4b1/VSCodeSetup-x64-1.101.0.exe", "img/png/vscode.png")); + flowPanel.Controls.Add(CreateAppCard( + "vs community 2022", + "https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false", + "img/jpg/vs.jpg")); + flowPanel.Controls.Add(CreateAppCard( "7-Zip", "https://objects.githubusercontent.com/github-production-release-asset-2e65be/466446150/1645817e-3677-4207-93ff-e62de7e147be?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250613%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250613T035936Z&X-Amz-Expires=300&X-Amz-Signature=5e02d5fc34f45bd8308029c9fc78052007e9475ce0e32775619921cb8f3b83ea&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3D7z2409-x64.exe&response-content-type=application%2Foctet-stream", @@ -236,6 +316,11 @@ namespace AppStore "https://ghproxy.net/https://github.com/zs-yg/package/releases/download/v0.1/7-Zip.7z", "img/png/7ziplogo.png")); + flowPanel.Controls.Add(CreateAppCard( + "peazip", + "https://ghproxy.net/https://github.com/peazip/PeaZip/releases/download/10.4.0/peazip-10.4.0.WIN64.exe", + "img/jpg/peazip.jpg")); + flowPanel.Controls.Add(CreateAppCard( "GreenShot", "https://objects.githubusercontent.com/github-production-release-asset-2e65be/36756917/239aedb0-7d29-11e7-9f9c-d36ec4466ade?X-Amz-Algorithm=AWS4-HMAC-SSHA256&X-Amz-Credential=releaseassetproduction%2F20250613%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250613T041723Z&X-Amz-Expires=300&X-Amz-Signature=be1ef88a68bbc7065af5111809d11de881022933b44f6d961eb6bd6e6b7e60a8&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3DGreenshot-INSTALLER-1.2.10.6-RELEASE.exe&response-content-type=application%2Foctet-stream", @@ -276,26 +361,26 @@ namespace AppStore "https://ghproxy.net/https://github.com/mifi/lossless-cut/releases/download/v3.64.0/LosslessCut-win-x64.7z", "img/png/LosslessCut.png")); - flowPanel.Controls.Add(CreateAppCard( - "mingw-64", - "https://ghproxy.net/https://github.com/niXman/mingw-builds-binaries/releases/download/15.1.0-rt_v12-rev0/x86_64-15.1.0-release-posix-seh-ucrt-rt_v12-rev0.7z", - "img/png/mingw-64.png")); - flowPanel.Controls.Add(CreateAppCard( "Edge", "https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/cb21e6b5-3f63-4df2-bec3-a2015b80dc56/MicrosoftEdgeEnterpriseX64.msi", "img/jpg/edge.jpg")); + flowPanel.Controls.Add(CreateAppCard( + "Min", + "https://ghproxy.net/https://github.com/minbrowser/min/releases/download/v1.35.0/min-1.35.0-setup.exe", + "img/jpg/Min.jpg")); + + flowPanel.Controls.Add(CreateAppCard( + "Brave", + "https://ghproxy.net/https://github.com/brave/brave-browser/releases/download/v1.79.126/BraveBrowserSetup.exe", + "img/png/brave.png")); + flowPanel.Controls.Add(CreateAppCard( "Firefox", "https://download-ssl.firefox.com.cn/releases-sha2/full/116.0/zh-CN/Firefox-full-latest-win64.exe", "img/jpg/firefox.jpg")); - flowPanel.Controls.Add(CreateAppCard( - "Msys2", - "https://github.com/msys2/msys2-installer/releases/download/2025-02-21/msys2-x86_64-20250221.exe", - "img/png/MSYS2.png")); - flowPanel.Controls.Add(CreateAppCard( "Mem Reduct", "https://memreduct.org/files/memreduct-3.5.2-setup.exe", @@ -371,11 +456,6 @@ namespace AppStore "https://ghproxy.net/https://github.com/microsoft/TypeScript/releases/download/v5.8.3/typescript-5.8.3.tgz", "")); - flowPanel.Controls.Add(CreateAppCard( - "peazip", - "https://ghproxy.net/https://github.com/peazip/PeaZip/releases/download/10.4.0/peazip-10.4.0.WIN64.exe", - "img/jpg/peazip.jpg")); - flowPanel.Controls.Add(CreateAppCard( "Gimp", "https://mirror.nju.edu.cn/gimp/gimp/v3.0/windows/gimp-3.0.4-setup.exe", @@ -625,21 +705,6 @@ namespace AppStore "Ditto", "https://ghproxy.net/https://github.com/sabrogden/Ditto/releases/download/3.24.246.0/DittoSetup_64bit_3_24_246_0.exe", "img/png/Ditto.png")); - - flowPanel.Controls.Add(CreateAppCard( - "XDM", - "https://github.com/subhra74/xdm/releases/download/7.2.11/xdm-setup.msi", - "img/png/XDM.png")); - - flowPanel.Controls.Add(CreateAppCard( - "FDM", - "https://files2.freedownloadmanager.org/6/latest/fdm_x64_setup.exe", - "img/png/FDM.png")); - - flowPanel.Controls.Add(CreateAppCard( - "ABDM", - "https://ghproxy.net/https://github.com/amir1376/ab-download-manager/releases/download/v1.6.4/ABDownloadManager_1.6.4_windows_x64.exe", - "img/png/ABDM.png")); } private FlowLayoutPanel downloadsFlowPanel = new FlowLayoutPanel();