mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-06 16:10:42 +08:00
Compare commits
4 Commits
v0.9.8-bet
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5b60d7079 | ||
|
|
f8192063a4 | ||
|
|
cd1abd3e33 | ||
|
|
cc577948b7 |
223
AboutForm.cs
223
AboutForm.cs
@@ -1,82 +1,141 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace AppStore
|
namespace AppStore
|
||||||
{
|
{
|
||||||
public class AboutUserControl : UserControl
|
public class AboutUserControl : UserControl
|
||||||
{
|
{
|
||||||
private PictureBox logo = null!;
|
private PictureBox logo = null!;
|
||||||
private Label infoLabel = null!;
|
private Label infoLabel = null!;
|
||||||
|
|
||||||
public AboutUserControl()
|
public AboutUserControl()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.Dock = DockStyle.Fill;
|
this.Dock = DockStyle.Fill;
|
||||||
this.BackColor = Color.White;
|
this.BackColor = Color.White;
|
||||||
this.Padding = new Padding(20);
|
this.Padding = new Padding(20);
|
||||||
|
|
||||||
// 创建主布局面板
|
// 创建主布局面板
|
||||||
TableLayoutPanel mainLayout = new TableLayoutPanel();
|
TableLayoutPanel mainLayout = new TableLayoutPanel();
|
||||||
mainLayout.Dock = DockStyle.Fill;
|
mainLayout.Dock = DockStyle.Fill;
|
||||||
mainLayout.ColumnCount = 1;
|
mainLayout.ColumnCount = 1;
|
||||||
mainLayout.RowCount = 2;
|
mainLayout.RowCount = 2;
|
||||||
mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
|
mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
|
||||||
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
||||||
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
||||||
mainLayout.Padding = new Padding(0, 20, 0, 20);
|
mainLayout.Padding = new Padding(0, 20, 0, 20);
|
||||||
|
|
||||||
// 初始化并添加应用图标
|
// 初始化并添加应用图标
|
||||||
logo = new PictureBox();
|
logo = new PictureBox();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logo.Image = Image.FromFile("img/png/kortapp-z.png");
|
logo.Image = Image.FromFile("img/png/kortapp-z.png");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.LogError($"无法加载应用图标: {ex.Message}");
|
Logger.LogError($"无法加载应用图标: {ex.Message}");
|
||||||
logo.Image = SystemIcons.Application.ToBitmap();
|
logo.Image = SystemIcons.Application.ToBitmap();
|
||||||
}
|
}
|
||||||
logo.SizeMode = PictureBoxSizeMode.Zoom;
|
logo.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
logo.Width = 200;
|
logo.Width = 200;
|
||||||
logo.Height = 200;
|
logo.Height = 200;
|
||||||
logo.Anchor = AnchorStyles.None;
|
logo.Anchor = AnchorStyles.None;
|
||||||
logo.Margin = new Padding(0, 0, 0, 20);
|
logo.Margin = new Padding(0, 0, 0, 20);
|
||||||
mainLayout.Controls.Add(logo, 0, 0);
|
mainLayout.Controls.Add(logo, 0, 0);
|
||||||
|
|
||||||
// 初始化并添加应用信息
|
// 初始化并添加应用信息
|
||||||
infoLabel = new Label();
|
infoLabel = new Label();
|
||||||
infoLabel.Text = "kortapp-z\n版本: 0.9.8\n一个简单、开源的应用商店\nkortapp-z是完全免费的基于.NET8和C++的软件";
|
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.Font = new Font("Microsoft YaHei", 12);
|
||||||
infoLabel.AutoSize = false;
|
infoLabel.AutoSize = false;
|
||||||
infoLabel.Width = 300;
|
infoLabel.Width = 300;
|
||||||
infoLabel.Height = 100;
|
infoLabel.Height = 130; // 增加高度确保文字完整显示
|
||||||
infoLabel.TextAlign = ContentAlignment.MiddleCenter;
|
infoLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
infoLabel.Anchor = AnchorStyles.None;
|
infoLabel.Anchor = AnchorStyles.None;
|
||||||
mainLayout.Controls.Add(infoLabel, 0, 1);
|
mainLayout.Controls.Add(infoLabel, 0, 1);
|
||||||
|
|
||||||
this.Controls.Add(mainLayout);
|
// 调整主布局为3行
|
||||||
}
|
mainLayout.RowCount = 3;
|
||||||
}
|
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
||||||
|
mainLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
|
||||||
// 保留原AboutForm作为容器(可选)
|
mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
|
||||||
public class AboutForm : Form
|
|
||||||
{
|
// 在底部添加GitHub链接区域
|
||||||
public AboutForm()
|
TableLayoutPanel githubPanel = new TableLayoutPanel();
|
||||||
{
|
githubPanel.Dock = DockStyle.Bottom;
|
||||||
this.Text = "关于 kortapp-z";
|
githubPanel.Height = 60;
|
||||||
this.Size = new Size(500, 400);
|
githubPanel.ColumnCount = 3;
|
||||||
this.StartPosition = FormStartPosition.CenterScreen;
|
githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
|
||||||
this.MaximizeBox = false;
|
githubPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
||||||
this.MinimizeBox = false;
|
githubPanel.RowCount = 1;
|
||||||
|
githubPanel.Padding = new Padding(10);
|
||||||
var aboutControl = new AboutUserControl();
|
|
||||||
this.Controls.Add(aboutControl);
|
// 添加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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
706
AppCard.cs
706
AppCard.cs
@@ -1,353 +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()
|
||||||
{
|
{
|
||||||
// 确保关键对象不为null
|
// 确保关键对象不为null
|
||||||
iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage };
|
iconBox = new PictureBox() { SizeMode = PictureBoxSizeMode.StretchImage };
|
||||||
nameLabel = new Label() { Text = string.Empty };
|
nameLabel = new Label() { Text = string.Empty };
|
||||||
downloadBtn = new Button() { Text = "下载" };
|
downloadBtn = new Button() { Text = "下载" };
|
||||||
|
|
||||||
// 确保DownloadManager已初始化
|
// 确保DownloadManager已初始化
|
||||||
var _ = DownloadManager.Instance;
|
var _ = DownloadManager.Instance;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> BorderCache =
|
private static readonly ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath> BorderCache =
|
||||||
new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>();
|
new ConcurrentDictionary<string, System.Drawing.Drawing2D.GraphicsPath>();
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.Size = new Size(240, 200);
|
this.Size = new Size(240, 200);
|
||||||
this.BackColor = Color.White;
|
this.BackColor = Color.White;
|
||||||
this.Padding = new Padding(10);
|
this.Padding = new Padding(10);
|
||||||
|
|
||||||
// 异步初始化卡片路径和边框
|
// 异步初始化卡片路径和边框
|
||||||
Task.Run(() => {
|
Task.Run(() => {
|
||||||
InitializeCardPath();
|
InitializeCardPath();
|
||||||
InitializeBorder();
|
InitializeBorder();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 应用图标
|
// 应用图标
|
||||||
iconBox = new PictureBox();
|
iconBox = new PictureBox();
|
||||||
iconBox.Size = new Size(80, 80);
|
iconBox.Size = new Size(80, 80);
|
||||||
iconBox.Location = new Point((Width - 80) / 2, 15);
|
iconBox.Location = new Point((Width - 80) / 2, 15);
|
||||||
iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
|
iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
|
||||||
this.Controls.Add(iconBox);
|
this.Controls.Add(iconBox);
|
||||||
|
|
||||||
// 应用名称
|
// 应用名称
|
||||||
nameLabel = new Label();
|
nameLabel = new Label();
|
||||||
nameLabel.AutoSize = false;
|
nameLabel.AutoSize = false;
|
||||||
nameLabel.Size = new Size(Width - 20, 40);
|
nameLabel.Size = new Size(Width - 20, 40);
|
||||||
nameLabel.Location = new Point(10, 100);
|
nameLabel.Location = new Point(10, 100);
|
||||||
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
|
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
|
||||||
nameLabel.TextAlign = ContentAlignment.MiddleCenter;
|
nameLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
this.Controls.Add(nameLabel);
|
this.Controls.Add(nameLabel);
|
||||||
|
|
||||||
// 下载按钮
|
// 下载按钮
|
||||||
downloadBtn = new Button();
|
downloadBtn = new Button();
|
||||||
downloadBtn.Text = "下载";
|
downloadBtn.Text = "下载";
|
||||||
downloadBtn.Size = new Size(100, 32);
|
downloadBtn.Size = new Size(100, 32);
|
||||||
downloadBtn.Location = new Point((Width - 100) / 2, 150);
|
downloadBtn.Location = new Point((Width - 100) / 2, 150);
|
||||||
downloadBtn.BackColor = Color.FromArgb(0, 120, 215);
|
downloadBtn.BackColor = Color.FromArgb(0, 120, 215);
|
||||||
downloadBtn.ForeColor = Color.White;
|
downloadBtn.ForeColor = Color.White;
|
||||||
downloadBtn.FlatStyle = FlatStyle.Flat;
|
downloadBtn.FlatStyle = FlatStyle.Flat;
|
||||||
downloadBtn.FlatAppearance.BorderSize = 0;
|
downloadBtn.FlatAppearance.BorderSize = 0;
|
||||||
downloadBtn.Cursor = Cursors.Hand;
|
downloadBtn.Cursor = Cursors.Hand;
|
||||||
downloadBtn.Font = new Font("Microsoft YaHei", 9);
|
downloadBtn.Font = new Font("Microsoft YaHei", 9);
|
||||||
|
|
||||||
// 按钮悬停效果
|
// 按钮悬停效果
|
||||||
downloadBtn.MouseEnter += (s, e) => {
|
downloadBtn.MouseEnter += (s, e) => {
|
||||||
downloadBtn.BackColor = Color.FromArgb(0, 150, 255);
|
downloadBtn.BackColor = Color.FromArgb(0, 150, 255);
|
||||||
};
|
};
|
||||||
|
|
||||||
downloadBtn.MouseLeave += (s, e) => {
|
downloadBtn.MouseLeave += (s, e) => {
|
||||||
downloadBtn.BackColor = Color.FromArgb(0, 120, 215);
|
downloadBtn.BackColor = Color.FromArgb(0, 120, 215);
|
||||||
};
|
};
|
||||||
|
|
||||||
downloadBtn.Click += DownloadBtn_Click;
|
downloadBtn.Click += DownloadBtn_Click;
|
||||||
this.Controls.Add(downloadBtn);
|
this.Controls.Add(downloadBtn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化卡片边框路径
|
/// 初始化卡片边框路径
|
||||||
/// 使用C++程序计算高性能边框路径并缓存结果
|
/// 使用C++程序计算高性能边框路径并缓存结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeBorder()
|
private void InitializeBorder()
|
||||||
{
|
{
|
||||||
// 使用卡片尺寸作为缓存键
|
// 使用卡片尺寸作为缓存键
|
||||||
string cacheKey = $"{Width}_{Height}_10";
|
string cacheKey = $"{Width}_{Height}_10";
|
||||||
|
|
||||||
// 检查缓存中是否已有路径
|
// 检查缓存中是否已有路径
|
||||||
if (!BorderCache.TryGetValue(cacheKey, out var borderPath))
|
if (!BorderCache.TryGetValue(cacheKey, out var borderPath))
|
||||||
{
|
{
|
||||||
// 创建临时文件存储路径数据
|
// 创建临时文件存储路径数据
|
||||||
string tempFile = Path.GetTempFileName();
|
string tempFile = Path.GetTempFileName();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 配置C++程序启动参数
|
// 配置C++程序启动参数
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = Path.Combine(Application.StartupPath, "resource", "border_renderer.exe"),
|
FileName = Path.Combine(Application.StartupPath, "resource", "border_renderer.exe"),
|
||||||
Arguments = $"{Width} {Height} 10 \"{tempFile}\"", // 传递宽高和圆角半径
|
Arguments = $"{Width} {Height} 10 \"{tempFile}\"", // 传递宽高和圆角半径
|
||||||
UseShellExecute = false, // 不显示命令行窗口
|
UseShellExecute = false, // 不显示命令行窗口
|
||||||
CreateNoWindow = true // 静默运行
|
CreateNoWindow = true // 静默运行
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动C++程序计算路径
|
// 启动C++程序计算路径
|
||||||
using (var process = Process.Start(startInfo))
|
using (var process = Process.Start(startInfo))
|
||||||
{
|
{
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
|
||||||
// 检查计算结果
|
// 检查计算结果
|
||||||
if (process.ExitCode == 0 && File.Exists(tempFile))
|
if (process.ExitCode == 0 && File.Exists(tempFile))
|
||||||
{
|
{
|
||||||
// 读取C++程序生成的路径点
|
// 读取C++程序生成的路径点
|
||||||
var lines = File.ReadAllLines(tempFile);
|
var lines = File.ReadAllLines(tempFile);
|
||||||
PointF[] points = lines.Select(line => {
|
PointF[] points = lines.Select(line => {
|
||||||
var parts = line.Split(','); // 解析坐标点
|
var parts = line.Split(','); // 解析坐标点
|
||||||
return new PointF(float.Parse(parts[0]), float.Parse(parts[1]));
|
return new PointF(float.Parse(parts[0]), float.Parse(parts[1]));
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
// 创建GraphicsPath对象
|
// 创建GraphicsPath对象
|
||||||
borderPath = new System.Drawing.Drawing2D.GraphicsPath();
|
borderPath = new System.Drawing.Drawing2D.GraphicsPath();
|
||||||
borderPath.AddLines(points); // 添加路径点
|
borderPath.AddLines(points); // 添加路径点
|
||||||
|
|
||||||
// 缓存路径对象
|
// 缓存路径对象
|
||||||
BorderCache.TryAdd(cacheKey, borderPath);
|
BorderCache.TryAdd(cacheKey, borderPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// 确保临时文件被删除
|
// 确保临时文件被删除
|
||||||
if (File.Exists(tempFile))
|
if (File.Exists(tempFile))
|
||||||
{
|
{
|
||||||
File.Delete(tempFile);
|
File.Delete(tempFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 边框和阴影效果
|
// 边框和阴影效果
|
||||||
protected override void OnPaint(PaintEventArgs e)
|
protected override void OnPaint(PaintEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPaint(e);
|
base.OnPaint(e);
|
||||||
|
|
||||||
// 绘制背景
|
// 绘制背景
|
||||||
using (var brush = new SolidBrush(this.BackColor)) {
|
using (var brush = new SolidBrush(this.BackColor)) {
|
||||||
e.Graphics.FillRectangle(brush, this.ClientRectangle);
|
e.Graphics.FillRectangle(brush, this.ClientRectangle);
|
||||||
}
|
}
|
||||||
|
|
||||||
string cacheKey = $"{Width}_{Height}_10";
|
string cacheKey = $"{Width}_{Height}_10";
|
||||||
if (BorderCache.TryGetValue(cacheKey, out var borderPath))
|
if (BorderCache.TryGetValue(cacheKey, out var borderPath))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 绘制阴影
|
// 绘制阴影
|
||||||
using (var shadowBrush = new SolidBrush(Color.FromArgb(20, 0, 0, 0))) {
|
using (var shadowBrush = new SolidBrush(Color.FromArgb(20, 0, 0, 0))) {
|
||||||
e.Graphics.FillPath(shadowBrush, borderPath);
|
e.Graphics.FillPath(shadowBrush, borderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制边框(调整为蓝色系)
|
// 绘制边框(调整为蓝色系)
|
||||||
using (var pen = new Pen(Color.FromArgb(70, 130, 200), 4)) {
|
using (var pen = new Pen(Color.FromArgb(70, 130, 200), 4)) {
|
||||||
e.Graphics.DrawPath(pen, borderPath);
|
e.Graphics.DrawPath(pen, borderPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"边框绘制错误: {ex.Message}");
|
Debug.WriteLine($"边框绘制错误: {ex.Message}");
|
||||||
// 回退到简单矩形边框
|
// 回退到简单矩形边框
|
||||||
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) {
|
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) {
|
||||||
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1));
|
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 缓存未命中时绘制默认边框
|
// 缓存未命中时绘制默认边框
|
||||||
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) {
|
using (var pen = new Pen(Color.FromArgb(100, 150, 220), 2)) {
|
||||||
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1));
|
e.Graphics.DrawRectangle(pen, new Rectangle(0, 0, Width-1, Height-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化卡片形状路径
|
/// 初始化卡片形状路径
|
||||||
/// 使用C++程序计算圆角矩形路径并缓存结果
|
/// 使用C++程序计算圆角矩形路径并缓存结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeCardPath()
|
private void InitializeCardPath()
|
||||||
{
|
{
|
||||||
int radius = 10; // 圆角半径
|
int radius = 10; // 圆角半径
|
||||||
string cacheKey = $"{Width}_{Height}_{radius}"; // 缓存键
|
string cacheKey = $"{Width}_{Height}_{radius}"; // 缓存键
|
||||||
|
|
||||||
// 检查缓存
|
// 检查缓存
|
||||||
if (!PathCache.TryGetValue(cacheKey, out var path))
|
if (!PathCache.TryGetValue(cacheKey, out var path))
|
||||||
{
|
{
|
||||||
string tempFile = Path.GetTempFileName(); // 临时文件路径
|
string tempFile = Path.GetTempFileName(); // 临时文件路径
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 配置C++程序启动参数
|
// 配置C++程序启动参数
|
||||||
ProcessStartInfo startInfo = new ProcessStartInfo {
|
ProcessStartInfo startInfo = new ProcessStartInfo {
|
||||||
FileName = Path.Combine(Application.StartupPath, "resource", "card_calculator.exe"),
|
FileName = Path.Combine(Application.StartupPath, "resource", "card_calculator.exe"),
|
||||||
Arguments = $"{Width} {Height} {radius} {tempFile}", // 传递宽高半径和输出文件
|
Arguments = $"{Width} {Height} {radius} {tempFile}", // 传递宽高半径和输出文件
|
||||||
UseShellExecute = false, // 不显示命令行窗口
|
UseShellExecute = false, // 不显示命令行窗口
|
||||||
CreateNoWindow = true // 静默运行
|
CreateNoWindow = true // 静默运行
|
||||||
};
|
};
|
||||||
|
|
||||||
// 启动C++程序计算路径
|
// 启动C++程序计算路径
|
||||||
using (var process = Process.Start(startInfo)) {
|
using (var process = Process.Start(startInfo)) {
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
|
|
||||||
// 检查计算结果
|
// 检查计算结果
|
||||||
if (process.ExitCode == 0 && File.Exists(tempFile)) {
|
if (process.ExitCode == 0 && File.Exists(tempFile)) {
|
||||||
// 读取生成的路径点
|
// 读取生成的路径点
|
||||||
var lines = File.ReadAllLines(tempFile);
|
var lines = File.ReadAllLines(tempFile);
|
||||||
PointF[] points = lines.Select(line => {
|
PointF[] points = lines.Select(line => {
|
||||||
var parts = line.Split(','); // 解析坐标
|
var parts = line.Split(','); // 解析坐标
|
||||||
return new PointF(float.Parse(parts[0]), float.Parse(parts[1]));
|
return new PointF(float.Parse(parts[0]), float.Parse(parts[1]));
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
// 创建并缓存路径对象
|
// 创建并缓存路径对象
|
||||||
path = new System.Drawing.Drawing2D.GraphicsPath();
|
path = new System.Drawing.Drawing2D.GraphicsPath();
|
||||||
path.AddLines(points);
|
path.AddLines(points);
|
||||||
PathCache.TryAdd(cacheKey, path);
|
PathCache.TryAdd(cacheKey, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// C++程序失败时使用C#回退方案
|
// C++程序失败时使用C#回退方案
|
||||||
path = CalculatePathFallback(Width, Height, radius);
|
path = CalculatePathFallback(Width, Height, radius);
|
||||||
} finally {
|
} finally {
|
||||||
// 确保删除临时文件
|
// 确保删除临时文件
|
||||||
if (File.Exists(tempFile)) {
|
if (File.Exists(tempFile)) {
|
||||||
File.Delete(tempFile);
|
File.Delete(tempFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用计算好的路径 - 更严格的null检查和异常处理
|
// 应用计算好的路径 - 更严格的null检查和异常处理
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var safePath = path ?? CalculatePathFallback(Width, Height, 10);
|
var safePath = path ?? CalculatePathFallback(Width, Height, 10);
|
||||||
// 更严格的null检查,包括路径和控件状态
|
// 更严格的null检查,包括路径和控件状态
|
||||||
if (safePath != null &&
|
if (safePath != null &&
|
||||||
safePath.PointCount > 0 &&
|
safePath.PointCount > 0 &&
|
||||||
this.IsHandleCreated &&
|
this.IsHandleCreated &&
|
||||||
!this.IsDisposed)
|
!this.IsDisposed)
|
||||||
{
|
{
|
||||||
this.Invoke((MethodInvoker)delegate {
|
this.Invoke((MethodInvoker)delegate {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 委托内部再次验证safePath
|
// 委托内部再次验证safePath
|
||||||
if (safePath != null && safePath.PointCount > 0)
|
if (safePath != null && safePath.PointCount > 0)
|
||||||
{
|
{
|
||||||
var validPath = safePath; // 确保非null
|
var validPath = safePath; // 确保非null
|
||||||
using (var region = new Region(validPath))
|
using (var region = new Region(validPath))
|
||||||
{
|
{
|
||||||
this.Region = region;
|
this.Region = region;
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"创建Region失败: {ex.Message}");
|
Debug.WriteLine($"创建Region失败: {ex.Message}");
|
||||||
this.Region = null;
|
this.Region = null;
|
||||||
this.Refresh();
|
this.Refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"初始化卡片路径失败: {ex.Message}");
|
Debug.WriteLine($"初始化卡片路径失败: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private System.Drawing.Drawing2D.GraphicsPath CalculatePathFallback(int width, int height, int radius)
|
private System.Drawing.Drawing2D.GraphicsPath CalculatePathFallback(int width, int height, int radius)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var path = new System.Drawing.Drawing2D.GraphicsPath();
|
var path = new System.Drawing.Drawing2D.GraphicsPath();
|
||||||
path.AddArc(0, 0, radius * 2, radius * 2, 180, 90);
|
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, 0, radius * 2, radius * 2, 270, 90);
|
||||||
path.AddArc(width - radius * 2, height - radius * 2, radius * 2, radius * 2, 0, 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.AddArc(0, height - radius * 2, radius * 2, radius * 2, 90, 90);
|
||||||
path.CloseFigure();
|
path.CloseFigure();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// 绝对回退方案 - 返回最小有效路径
|
// 绝对回退方案 - 返回最小有效路径
|
||||||
var path = new System.Drawing.Drawing2D.GraphicsPath();
|
var path = new System.Drawing.Drawing2D.GraphicsPath();
|
||||||
path.AddRectangle(new Rectangle(0, 0, width, height));
|
path.AddRectangle(new Rectangle(0, 0, width, height));
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateDisplay()
|
public void UpdateDisplay()
|
||||||
{
|
{
|
||||||
nameLabel.Text = AppName;
|
nameLabel.Text = AppName;
|
||||||
iconBox.Image = AppIcon;
|
iconBox.Image = AppIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DownloadBtn_Click(object sender, EventArgs e)
|
private void DownloadBtn_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 更严格的null检查
|
// 更严格的null检查
|
||||||
// 更严格的null检查,包括DownloadManager.Instance和其方法
|
// 更严格的null检查,包括DownloadManager.Instance和其方法
|
||||||
// 全面的null和状态检查
|
// 全面的null和状态检查
|
||||||
if (sender == null || e == null ||
|
if (sender == null || e == null ||
|
||||||
string.IsNullOrWhiteSpace(DownloadUrl) ||
|
string.IsNullOrWhiteSpace(DownloadUrl) ||
|
||||||
string.IsNullOrWhiteSpace(AppName) ||
|
string.IsNullOrWhiteSpace(AppName) ||
|
||||||
!this.IsHandleCreated ||
|
!this.IsHandleCreated ||
|
||||||
this.IsDisposed ||
|
this.IsDisposed ||
|
||||||
DownloadManager.Instance == null ||
|
DownloadManager.Instance == null ||
|
||||||
DownloadManager.Instance.DownloadItems == null ||
|
DownloadManager.Instance.DownloadItems == null ||
|
||||||
DownloadManager.Instance.StartDownload == null)
|
DownloadManager.Instance.StartDownload == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string safeAppName = AppName ?? "未知应用";
|
string safeAppName = AppName ?? "未知应用";
|
||||||
string fileName = $"{safeAppName.Replace(" ", "_")}.exe";
|
string fileName = $"{safeAppName.Replace(" ", "_")}.exe";
|
||||||
|
|
||||||
DownloadManager.Instance.StartDownload(fileName, DownloadUrl);
|
DownloadManager.Instance.StartDownload(fileName, DownloadUrl);
|
||||||
|
|
||||||
string message = $"已开始下载: {safeAppName}";
|
string message = $"已开始下载: {safeAppName}";
|
||||||
this.Invoke((MethodInvoker)delegate {
|
this.Invoke((MethodInvoker)delegate {
|
||||||
MessageBox.Show(this, message, "下载中", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(this, message, "下载中", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine($"下载按钮点击处理失败: {ex.Message}");
|
Debug.WriteLine($"下载按钮点击处理失败: {ex.Message}");
|
||||||
this.Invoke((MethodInvoker)delegate {
|
this.Invoke((MethodInvoker)delegate {
|
||||||
MessageBox.Show(this, "下载处理发生错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(this, "下载处理发生错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1799
MainForm.cs
1799
MainForm.cs
File diff suppressed because it is too large
Load Diff
4
del.bat
4
del.bat
@@ -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/github.jpg
Normal file
BIN
img/jpg/github.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.7 KiB |
BIN
img/png/SpaceSniffer.png
Normal file
BIN
img/png/SpaceSniffer.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
img/png/nanazip.png
Normal file
BIN
img/png/nanazip.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
114
log_cleaner.cpp
114
log_cleaner.cpp
@@ -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
111
logger.cs
@@ -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.
Reference in New Issue
Block a user