Compare commits

..

11 Commits

Author SHA1 Message Date
zsyg
a5b60d7079 Add files via upload 2025-06-21 10:09:51 +08:00
zsyg
f8192063a4 Add files via upload 2025-06-21 10:08:50 +08:00
zsyg
cd1abd3e33 Add files via upload 2025-06-21 10:02:21 +08:00
zsyg
cc577948b7 Add files via upload 2025-06-21 10:00:38 +08:00
zsyg
0e550c746b Add files via upload 2025-06-20 21:02:53 +08:00
zsyg
7fb9b53e62 Add files via upload 2025-06-20 20:59:58 +08:00
zsyg
80ce2c6151 Add files via upload 2025-06-20 20:58:10 +08:00
zsyg
f2a2f48020 修复部分编译警告 2025-06-19 20:58:49 +08:00
zsyg
d85d2d67ea 添加关于界面 2025-06-18 20:33:12 +08:00
zsyg
532006297a Add files via upload 2025-06-18 20:32:45 +08:00
zsyg
8ccf566d88 修复资源文件链接问题 2025-06-18 20:31:45 +08:00
30 changed files with 1653 additions and 1135 deletions

141
AboutForm.cs Normal file
View File

@@ -0,0 +1,141 @@
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 = Color.White;
this.Padding = new Padding(20);
// 创建主布局面板
TableLayoutPanel mainLayout = new TableLayoutPanel();
mainLayout.Dock = DockStyle.Fill;
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.0.0\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和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.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.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);
}
}
}

View File

@@ -1,289 +1,353 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.IO; using System.IO;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace AppStore namespace AppStore
{ {
public class AppCard : UserControl public class AppCard : UserControl
{ {
private PictureBox iconBox; private PictureBox iconBox;
private Label nameLabel; private Label nameLabel;
private Button downloadBtn; private Button downloadBtn;
private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> PathCache = private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> PathCache =
new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>(); new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>();
public string AppName { get; set; } = string.Empty; public string AppName { get; set; } = string.Empty;
public Image AppIcon { get; set; } = SystemIcons.Application.ToBitmap(); public Image AppIcon { get; set; } = SystemIcons.Application.ToBitmap();
public string DownloadUrl { get; set; } = string.Empty; public string DownloadUrl { get; set; } = string.Empty;
public AppCard() public AppCard()
{ {
iconBox = new PictureBox(); // 确保关键对象不为null
nameLabel = new Label(); iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage };
downloadBtn = new Button(); nameLabel = new Label() { Text = string.Empty };
InitializeComponent(); downloadBtn = new Button() { Text = "下载" };
}
// 确保DownloadManager已初始化
private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> BorderCache = var _ = DownloadManager.Instance;
new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>();
InitializeComponent();
private void InitializeComponent() }
{
this.Size = new Size(240, 200); private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> BorderCache =
this.BackColor = Color.White; new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>();
this.Padding = new Padding(10);
private void InitializeComponent()
// 异步初始化卡片路径和边框 {
Task.Run(() => { this.Size = new Size(240, 200);
InitializeCardPath(); this.BackColor = Color.White;
InitializeBorder(); this.Padding = new Padding(10);
});
// 异步初始化卡片路径和边框
// 应用图标 Task.Run(() => {
iconBox = new PictureBox(); InitializeCardPath();
iconBox.Size = new Size(80, 80); InitializeBorder();
iconBox.Location = new Point((Width - 80) / 2, 15); });
iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
this.Controls.Add(iconBox); // 应用图标
iconBox = new PictureBox();
// 应用名称 iconBox.Size = new Size(80, 80);
nameLabel = new Label(); iconBox.Location = new Point((Width - 80) / 2, 15);
nameLabel.AutoSize = false; iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
nameLabel.Size = new Size(Width - 20, 40); this.Controls.Add(iconBox);
nameLabel.Location = new Point(10, 100);
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold); // 应用名称
nameLabel.TextAlign = ContentAlignment.MiddleCenter; nameLabel = new Label();
this.Controls.Add(nameLabel); nameLabel.AutoSize = false;
nameLabel.Size = new Size(Width - 20, 40);
// 下载按钮 nameLabel.Location = new Point(10, 100);
downloadBtn = new Button(); nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
downloadBtn.Text = "下载"; nameLabel.TextAlign = ContentAlignment.MiddleCenter;
downloadBtn.Size = new Size(100, 32); this.Controls.Add(nameLabel);
downloadBtn.Location = new Point((Width - 100) / 2, 150);
downloadBtn.BackColor = Color.FromArgb(0, 120, 215); // 下载按钮
downloadBtn.ForeColor = Color.White; downloadBtn = new Button();
downloadBtn.FlatStyle = FlatStyle.Flat; downloadBtn.Text = "下载";
downloadBtn.FlatAppearance.BorderSize = 0; downloadBtn.Size = new Size(100, 32);
downloadBtn.Cursor = Cursors.Hand; downloadBtn.Location = new Point((Width - 100) / 2, 150);
downloadBtn.Font = new Font("Microsoft YaHei", 9); downloadBtn.BackColor = Color.FromArgb(0, 120, 215);
downloadBtn.ForeColor = Color.White;
// 按钮悬停效果 downloadBtn.FlatStyle = FlatStyle.Flat;
downloadBtn.MouseEnter += (s, e) => { downloadBtn.FlatAppearance.BorderSize = 0;
downloadBtn.BackColor = Color.FromArgb(0, 150, 255); downloadBtn.Cursor = Cursors.Hand;
}; downloadBtn.Font = new Font("Microsoft YaHei", 9);
downloadBtn.MouseLeave += (s, e) => { // 按钮悬停效果
downloadBtn.BackColor = Color.FromArgb(0, 120, 215); downloadBtn.MouseEnter += (s, e) => {
}; downloadBtn.BackColor = Color.FromArgb(0, 150, 255);
};
downloadBtn.Click += DownloadBtn_Click;
this.Controls.Add(downloadBtn); downloadBtn.MouseLeave += (s, e) => {
} downloadBtn.BackColor = Color.FromArgb(0, 120, 215);
};
/// <summary>
/// 初始化卡片边框路径 downloadBtn.Click += DownloadBtn_Click;
/// 使用C++程序计算高性能边框路径并缓存结果 this.Controls.Add(downloadBtn);
/// </summary> }
private void InitializeBorder()
{ /// <summary>
// 使用卡片尺寸作为缓存键 /// 初始化卡片边框路径
string cacheKey = $"{Width}_{Height}_10"; /// 使用C++程序计算高性能边框路径并缓存结果
/// </summary>
// 检查缓存中是否已有路径 private void InitializeBorder()
if (!BorderCache.TryGetValue(cacheKey, out var borderPath)) {
{ // 使用卡片尺寸作为缓存键
// 创建临时文件存储路径数据 string cacheKey = $"{Width}_{Height}_10";
string tempFile = Path.GetTempFileName();
try // 检查缓存中是否已有路径
{ if (!BorderCache.TryGetValue(cacheKey, out var borderPath))
// 配置C++程序启动参数 {
ProcessStartInfo startInfo = new ProcessStartInfo // 创建临时文件存储路径数据
{ string tempFile = Path.GetTempFileName();
FileName = Path.Combine(Application.StartupPath, "resource", "border_renderer.exe"), try
Arguments = $"{Width} {Height} 10 \"{tempFile}\"", // 传递宽高和圆角半径 {
UseShellExecute = false, // 不显示命令行窗口 // 配置C++程序启动参数
CreateNoWindow = true // 静默运行 ProcessStartInfo startInfo = new ProcessStartInfo
}; {
FileName = Path.Combine(Application.StartupPath, "resource", "border_renderer.exe"),
// 启动C++程序计算路 Arguments = $"{Width} {Height} 10 \"{tempFile}\"", // 传递宽高和圆角半
using (var process = Process.Start(startInfo)) UseShellExecute = false, // 不显示命令行窗口
{ CreateNoWindow = true // 静默运行
process.WaitForExit(); };
// 检查计算结果 // 启动C++程序计算路径
if (process.ExitCode == 0 && File.Exists(tempFile)) using (var process = Process.Start(startInfo))
{ {
// 读取C++程序生成的路径点 process.WaitForExit();
var lines = File.ReadAllLines(tempFile);
PointF[] points = lines.Select(line => { // 检查计算结果
var parts = line.Split(','); // 解析坐标点 if (process.ExitCode == 0 && File.Exists(tempFile))
return new PointF(float.Parse(parts[0]), float.Parse(parts[1])); {
}).ToArray(); // 读取C++程序生成的路径点
var lines = File.ReadAllLines(tempFile);
// 创建GraphicsPath对象 PointF[] points = lines.Select(line => {
borderPath = new System.Drawing.Drawing2D.GraphicsPath(); var parts = line.Split(','); // 解析坐标点
borderPath.AddLines(points); // 添加路径点 return new PointF(float.Parse(parts[0]), float.Parse(parts[1]));
}).ToArray();
// 缓存路径对象
BorderCache.TryAdd(cacheKey, borderPath); // 创建GraphicsPath对象
} borderPath = new System.Drawing.Drawing2D.GraphicsPath();
} borderPath.AddLines(points); // 添加路径点
}
finally // 缓存路径对象
{ BorderCache.TryAdd(cacheKey, borderPath);
// 确保临时文件被删除 }
if (File.Exists(tempFile)) }
{ }
File.Delete(tempFile); finally
} {
} // 确保临时文件被删除
} if (File.Exists(tempFile))
} {
File.Delete(tempFile);
// 边框和阴影效果 }
protected override void OnPaint(PaintEventArgs e) }
{ }
base.OnPaint(e); }
// 绘制背景 // 边框和阴影效果
using (var brush = new SolidBrush(this.BackColor)) { protected override void OnPaint(PaintEventArgs e)
e.Graphics.FillRectangle(brush, this.ClientRectangle); {
} base.OnPaint(e);
string cacheKey = $"{Width}_{Height}_10"; // 绘制背景
if (BorderCache.TryGetValue(cacheKey, out var borderPath)) using (var brush = new SolidBrush(this.BackColor)) {
{ e.Graphics.FillRectangle(brush, this.ClientRectangle);
try }
{
// 绘制阴影 string cacheKey = $"{Width}_{Height}_10";
using (var shadowBrush = new SolidBrush(Color.FromArgb(20, 0, 0, 0))) { if (BorderCache.TryGetValue(cacheKey, out var borderPath))
e.Graphics.FillPath(shadowBrush, borderPath); {
} try
{
// 绘制边框(调整为蓝色系) // 绘制阴影
using (var pen = new Pen(Color.FromArgb(70, 130, 200), 4)) { using (var shadowBrush = new SolidBrush(Color.FromArgb(20, 0, 0, 0))) {
e.Graphics.DrawPath(pen, borderPath); e.Graphics.FillPath(shadowBrush, borderPath);
} }
}
catch (Exception ex) // 绘制边框(调整为蓝色系)
{ using (var pen = new Pen(Color.FromArgb(70, 130, 200), 4)) {
Debug.WriteLine($"边框绘制错误: {ex.Message}"); e.Graphics.DrawPath(pen, borderPath);
// 回退到简单矩形边框 }
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) { }
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1)); catch (Exception ex)
} {
} Debug.WriteLine($"边框绘制错误: {ex.Message}");
} // 回退到简单矩形边框
else using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) {
{ e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1));
// 缓存未命中时绘制默认边框 }
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) { }
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1)); }
} else
} {
} // 缓存未命中时绘制默认边框
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) {
/// <summary> e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1));
/// 初始化卡片形状路径 }
/// 使用C++程序计算圆角矩形路径并缓存结果 }
/// </summary> }
private void InitializeCardPath()
{ /// <summary>
int radius = 10; // 圆角半 /// 初始化卡片形状路
string cacheKey = $"{Width}_{Height}_{radius}"; // 缓存键 /// 使用C++程序计算圆角矩形路径并缓存结果
/// </summary>
// 检查缓存 private void InitializeCardPath()
if (!PathCache.TryGetValue(cacheKey, out var path)) {
{ int radius = 10; // 圆角半径
string tempFile = Path.GetTempFileName(); // 临时文件路径 string cacheKey = $"{Width}_{Height}_{radius}"; // 缓存键
try { // 检查缓存
// 配置C++程序启动参数 if (!PathCache.TryGetValue(cacheKey, out var path))
ProcessStartInfo startInfo = new ProcessStartInfo { {
FileName = Path.Combine(Application.StartupPath, "resource", "card_calculator.exe"), string tempFile = Path.GetTempFileName(); // 临时文件路径
Arguments = $"{Width} {Height} {radius} {tempFile}", // 传递宽高半径和输出文件
UseShellExecute = false, // 不显示命令行窗口 try {
CreateNoWindow = true // 静默运行 // 配置C++程序启动参数
}; ProcessStartInfo startInfo = new ProcessStartInfo {
FileName = Path.Combine(Application.StartupPath, "resource", "card_calculator.exe"),
// 启动C++程序计算路径 Arguments = $"{Width} {Height} {radius} {tempFile}", // 传递宽高半径和输出文件
using (var process = Process.Start(startInfo)) { UseShellExecute = false, // 不显示命令行窗口
process.WaitForExit(); CreateNoWindow = true // 静默运行
};
// 检查计算结果
if (process.ExitCode == 0 && File.Exists(tempFile)) { // 启动C++程序计算路径
// 读取生成的路径点 using (var process = Process.Start(startInfo)) {
var lines = File.ReadAllLines(tempFile); process.WaitForExit();
PointF[] points = lines.Select(line => {
var parts = line.Split(','); // 解析坐标 // 检查计算结果
return new PointF(float.Parse(parts[0]), float.Parse(parts[1])); if (process.ExitCode == 0 && File.Exists(tempFile)) {
}).ToArray(); // 读取生成的路径点
var lines = File.ReadAllLines(tempFile);
// 创建并缓存路径对象 PointF[] points = lines.Select(line => {
path = new System.Drawing.Drawing2D.GraphicsPath(); var parts = line.Split(','); // 解析坐标
path.AddLines(points); return new PointF(float.Parse(parts[0]), float.Parse(parts[1]));
PathCache.TryAdd(cacheKey, path); }).ToArray();
}
} // 创建并缓存路径对象
} catch { path = new System.Drawing.Drawing2D.GraphicsPath();
// C++程序失败时使用C#回退方案 path.AddLines(points);
path = CalculatePathFallback(Width, Height, radius); PathCache.TryAdd(cacheKey, path);
} finally { }
// 确保删除临时文件 }
if (File.Exists(tempFile)) { } catch {
File.Delete(tempFile); // C++程序失败时使用C#回退方案
} path = CalculatePathFallback(Width, Height, radius);
} } finally {
} // 确保删除临时文件
if (File.Exists(tempFile)) {
// 应用计算好的路径 File.Delete(tempFile);
if (path != null) }
{ }
this.Invoke((MethodInvoker)delegate { }
this.Region = new Region(path); // 设置控件区域
this.Refresh(); // 重绘控件 // 应用计算好的路径 - 更严格的null检查和异常处理
}); try
} {
} var safePath = path ?? CalculatePathFallback(Width, Height, 10);
// 更严格的null检查包括路径和控件状态
private System.Drawing.Drawing2D.GraphicsPath CalculatePathFallback(int width, int height, int radius) if (safePath != null &&
{ safePath.PointCount > 0 &&
var path = new System.Drawing.Drawing2D.GraphicsPath(); this.IsHandleCreated &&
path.AddArc(0, 0, radius * 2, radius * 2, 180, 90); !this.IsDisposed)
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); this.Invoke((MethodInvoker)delegate {
path.AddArc(0, height - radius * 2, radius * 2, radius * 2, 90, 90); try
path.CloseFigure(); {
return path; // 委托内部再次验证safePath
} if (safePath != null && safePath.PointCount > 0)
{
public void UpdateDisplay() var validPath = safePath; // 确保非null
{ using (var region = new Region(validPath))
nameLabel.Text = AppName; {
iconBox.Image = AppIcon; this.Region = region;
} this.Refresh();
}
private void DownloadBtn_Click(object sender, EventArgs e) }
{ }
if (sender == null || e == null) return; catch (Exception ex)
if (!string.IsNullOrEmpty(DownloadUrl)) {
{ Debug.WriteLine($"创建Region失败: {ex.Message}");
try this.Region = null;
{ this.Refresh();
string fileName = $"{AppName.Replace(" ", "_")}.exe"; }
DownloadManager.Instance.StartDownload(fileName, DownloadUrl); });
MessageBox.Show($"已开始下载: {AppName}", "下载中", MessageBoxButtons.OK, MessageBoxIcon.Information); }
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show($"下载失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); Debug.WriteLine($"初始化卡片路径失败: {ex.Message}");
} }
} }
}
} private System.Drawing.Drawing2D.GraphicsPath CalculatePathFallback(int width, int height, int radius)
} {
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()
{
nameLabel.Text = AppName;
iconBox.Image = AppIcon;
}
private void DownloadBtn_Click(object sender, EventArgs e)
{
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)
{
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);
});
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,50 +1,53 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
namespace AppStore namespace AppStore
{ {
public class SettingsForm : Form public class SettingsUserControl : UserControl
{ {
private Button btnCleanLogs; private Button btnCleanLogs;
public SettingsForm() public SettingsUserControl()
{ {
this.Text = "设置"; this.Dock = DockStyle.Fill;
this.Size = new Size(400, 300); this.BackColor = Color.White;
this.StartPosition = FormStartPosition.CenterParent;
// 设置顶部内边距
btnCleanLogs = new Button(); this.Padding = new Padding(0, 30, 0, 0);
btnCleanLogs.Text = "清理日志";
btnCleanLogs.Size = new Size(150, 40); btnCleanLogs = new Button();
btnCleanLogs.Location = new Point(120, 100); btnCleanLogs.Text = "清理日志";
btnCleanLogs.Font = new Font("Microsoft YaHei", 10); btnCleanLogs.Size = new Size(150, 40);
btnCleanLogs.Click += (s, e) => CleanLogs(); btnCleanLogs.Location = new Point((this.Width - 150) / 2, 50); // 调整Y坐标为50靠近顶部
this.Controls.Add(btnCleanLogs); btnCleanLogs.Font = new Font("Microsoft YaHei", 10);
} btnCleanLogs.Anchor = AnchorStyles.Top; // 添加顶部锚点
btnCleanLogs.Click += (s, e) => CleanLogs();
private void CleanLogs() this.Controls.Add(btnCleanLogs);
{ }
try
{ private void CleanLogs()
string logCleanerPath = Path.Combine("resource", "log_cleaner.exe"); {
try
if (File.Exists(logCleanerPath)) {
{ string logCleanerPath = Path.Combine("resource", "log_cleaner.exe");
Process.Start(logCleanerPath);
MessageBox.Show("日志清理程序已启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); if (File.Exists(logCleanerPath))
} {
else Process.Start(logCleanerPath);
{ MessageBox.Show("日志清理程序已启动", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("日志清理程序未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
} else
} {
catch (Exception ex) MessageBox.Show("日志清理程序未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
{ }
Logger.LogError("清理日志时出错", ex); }
MessageBox.Show($"清理日志时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); catch (Exception ex)
} {
} Logger.LogError("清理日志时出错", ex);
} MessageBox.Show($"清理日志时出错: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
}
}
}

View File

@@ -1,4 +1,2 @@
rmdir bin /s /q rmdir bin /s /q
rmdir obj /s /q rmdir obj /s /q
rmdir logs /s /q
mkdir logs

BIN
img/jpg/D.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
img/jpg/Min.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
img/jpg/NDM.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
img/jpg/github.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

BIN
img/jpg/vs.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
img/png/ABDM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
img/png/Ditto.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
img/png/FDM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

BIN
img/png/Go.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
img/png/SSM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
img/png/SpaceSniffer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
img/png/XDM.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
img/png/brave.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
img/png/codium_cnl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
img/png/java.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
img/png/nanazip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
img/png/nodejs.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
img/png/openark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
img/png/ruby.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
img/png/rust.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -1,49 +1,65 @@
#include <iostream> #include <iostream>
#include <filesystem> #include <filesystem>
#include <chrono> #include <chrono>
namespace fs = std::filesystem; namespace fs = std::filesystem;
int main() { int main() {
try { try {
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
// 定义日志目录路径 // 定义日志目录路径
fs::path logDir = "logs"; fs::path logDir;
size_t deletedCount = 0;
size_t errorCount = 0; #ifdef _WIN32
// Windows系统获取AppData路径
// 检查目录是否存在 char* appData = nullptr;
if (fs::exists(logDir) && fs::is_directory(logDir)) { size_t len = 0;
// 遍历并删除所有日志文件 if (_dupenv_s(&appData, &len, "APPDATA") == 0 && appData != nullptr) {
for (const auto& entry : fs::directory_iterator(logDir)) { logDir = fs::path(appData) / "zsyg" / "kortapp-z" / ".logs";
try { free(appData);
if (fs::is_regular_file(entry)) { } else {
fs::remove(entry); std::cerr << "无法获取APPDATA环境变量" << std::endl;
deletedCount++; return 1;
} }
} catch (const std::exception& e) { #else
std::cerr << "删除文件失败: " << entry.path() << " - " << e.what() << std::endl; // 非Windows系统使用默认路径
errorCount++; logDir = fs::path(getenv("HOME")) / ".zsyg" / "kortapp-z" / ".logs";
} #endif
} size_t deletedCount = 0;
} else { size_t errorCount = 0;
std::cout << "日志目录不存在,无需清理" << std::endl;
return 0; // 检查目录是否存在
} if (fs::exists(logDir) && fs::is_directory(logDir)) {
// 遍历并删除所有日志文件
auto end = std::chrono::high_resolution_clock::now(); for (const auto& entry : fs::directory_iterator(logDir)) {
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); try {
if (fs::is_regular_file(entry)) {
std::cout << "日志清理完成: " << std::endl; fs::remove(entry);
std::cout << "删除文件数: " << deletedCount << std::endl; deletedCount++;
std::cout << "错误数: " << errorCount << std::endl; }
std::cout << "耗时: " << duration.count() << " 毫秒" << std::endl; } catch (const std::exception& e) {
std::cerr << "删除文件失败: " << entry.path() << " - " << e.what() << std::endl;
} catch (const std::exception& e) { errorCount++;
std::cerr << "发生错误: " << e.what() << std::endl; }
return 1; }
} } else {
std::cout << "日志目录不存在,无需清理" << std::endl;
return 0; return 0;
} }
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << "日志清理完成: " << std::endl;
std::cout << "删除文件数: " << deletedCount << std::endl;
std::cout << "错误数: " << errorCount << std::endl;
std::cout << "耗时: " << duration.count() << " 毫秒" << std::endl;
} catch (const std::exception& e) {
std::cerr << "发生错误: " << e.what() << std::endl;
return 1;
}
return 0;
}

111
logger.cs
View File

@@ -1,48 +1,63 @@
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace AppStore
{ namespace AppStore
public static class Logger {
{ public static class Logger
private static readonly string LogsDirectory = "logs"; {
private static readonly object LockObject = new object(); private static readonly string LogsDirectory = Path.Combine(
static Logger() Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
{ "zsyg", "kortapp-z", ".logs");
// 确保logs目录存在 private static readonly object LockObject = new object();
if (!Directory.Exists(LogsDirectory))
{ static Logger()
Directory.CreateDirectory(LogsDirectory); {
} try
} {
public static void Log(string message) // 确保logs目录存在
{ if (!Directory.Exists(LogsDirectory))
lock (LockObject) {
{ Directory.CreateDirectory(LogsDirectory);
try }
{ }
string fileName = $"{DateTime.Now:yyyyMMddHHmmss}.log"; catch (Exception ex)
string filePath = Path.Combine(LogsDirectory, fileName); {
using (StreamWriter writer = new StreamWriter(filePath, true, Encoding.UTF8)) Console.WriteLine($"无法创建日志目录: {LogsDirectory}, 错误: {ex.Message}");
{ throw;
writer.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}"); }
} }
}
catch (Exception ex) public static void Log(string message)
{ {
// 日志记录失败时输出到控制台 lock (LockObject)
Console.WriteLine($"日志记录失败: {ex.Message}"); {
} try
} {
} string fileName = $"{DateTime.Now:yyyyMMddHHmmss}.log";
public static void LogError(string message, Exception? ex = null) string filePath = Path.Combine(LogsDirectory, fileName);
{
string errorMessage = $"ERROR: {message}"; using (StreamWriter writer = new StreamWriter(filePath, true, Encoding.UTF8))
if (ex != null) {
{ writer.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}");
errorMessage += $"\nException: {ex}\nStackTrace: {ex.StackTrace}"; }
} }
Log(errorMessage); catch (Exception ex)
} {
} // 日志记录失败时输出到控制台
} Console.WriteLine($"日志记录失败: {ex.Message}");
}
}
}
public static void LogError(string message, Exception? ex = null)
{
string errorMessage = $"ERROR: {message}";
if (ex != null)
{
errorMessage += $"\nException: {ex}\nStackTrace: {ex.StackTrace}";
}
Log(errorMessage);
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.