添加艺术字

This commit is contained in:
zsyg
2025-07-02 11:09:21 +08:00
committed by GitHub
parent 125bf6b0d4
commit e34a954777
15 changed files with 753 additions and 663 deletions

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@@ -1,125 +1,131 @@
using System; // _ _
using System.Drawing; //| | _____ _ __| |_ __ _ _ __ _ __ ____
using System.Windows.Forms; //| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
namespace AppStore //|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
{ // |_| |_|
public class DownloadItem : UserControl using System;
{ using System.Drawing;
private Label nameLabel; using System.Windows.Forms;
private ProgressBar progressBar;
private Label statusLabel; namespace AppStore
private Button cancelBtn; {
public class DownloadItem : UserControl
public string FileName { get; set; } = string.Empty; {
public int Progress { get; set; } private Label nameLabel;
public string Status { get; set; } = string.Empty; private ProgressBar progressBar;
private Label statusLabel;
public DownloadItem() private Button cancelBtn;
{
nameLabel = new Label(); public string FileName { get; set; } = string.Empty;
progressBar = new ProgressBar(); public int Progress { get; set; }
statusLabel = new Label(); public string Status { get; set; } = string.Empty;
cancelBtn = new Button();
public DownloadItem()
InitializeComponent(); {
nameLabel = new Label();
// 监听主题变化 progressBar = new ProgressBar();
ThemeManager.ThemeChanged += (theme) => { statusLabel = new Label();
this.Invoke((MethodInvoker)delegate { cancelBtn = new Button();
ApplyTheme();
}); InitializeComponent();
};
} // 监听主题变化
ThemeManager.ThemeChanged += (theme) => {
private void ApplyTheme() this.Invoke((MethodInvoker)delegate {
{ ApplyTheme();
this.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light });
? Color.White };
: Color.Black; }
this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
? Color.Black private void ApplyTheme()
: Color.White; {
this.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
cancelBtn.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light ? Color.White
? SystemColors.Control : Color.Black;
: Color.FromArgb(70, 70, 70); this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
cancelBtn.ForeColor = ThemeManager.TextColor; ? Color.Black
} : Color.White;
private void InitializeComponent() cancelBtn.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
{ ? SystemColors.Control
this.Size = new Size(400, 60); : Color.FromArgb(70, 70, 70);
this.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light cancelBtn.ForeColor = ThemeManager.TextColor;
? Color.White }
: Color.Black;
this.BorderStyle = BorderStyle.FixedSingle; private void InitializeComponent()
this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light {
? Color.Black this.Size = new Size(400, 60);
: Color.White; this.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
? Color.White
// 文件名标签 : Color.Black;
nameLabel = new Label(); this.BorderStyle = BorderStyle.FixedSingle;
nameLabel.AutoSize = true; this.ForeColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
nameLabel.Location = new Point(10, 10); ? Color.Black
nameLabel.Font = new Font("Microsoft YaHei", 9, FontStyle.Bold); : Color.White;
this.Controls.Add(nameLabel);
// 文件名标签
// 进度条 nameLabel = new Label();
progressBar = new ProgressBar(); nameLabel.AutoSize = true;
progressBar.Size = new Size(200, 20); nameLabel.Location = new Point(10, 10);
progressBar.Location = new Point(10, 30); nameLabel.Font = new Font("Microsoft YaHei", 9, FontStyle.Bold);
this.Controls.Add(progressBar); this.Controls.Add(nameLabel);
// 状态标签 // 进度条
statusLabel = new Label(); progressBar = new ProgressBar();
statusLabel.AutoSize = true; progressBar.Size = new Size(200, 20);
statusLabel.Location = new Point(220, 30); progressBar.Location = new Point(10, 30);
statusLabel.Font = new Font("Microsoft YaHei", 8); this.Controls.Add(progressBar);
this.Controls.Add(statusLabel);
// 状态标签
// 取消按钮 statusLabel = new Label();
cancelBtn = new Button(); statusLabel.AutoSize = true;
cancelBtn.Text = "取消"; statusLabel.Location = new Point(220, 30);
cancelBtn.Size = new Size(60, 25); statusLabel.Font = new Font("Microsoft YaHei", 8);
cancelBtn.Location = new Point(320, 30); this.Controls.Add(statusLabel);
cancelBtn.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
? SystemColors.Control // 取消按钮
: Color.FromArgb(70, 70, 70); cancelBtn = new Button();
cancelBtn.ForeColor = ThemeManager.TextColor; cancelBtn.Text = "取消";
cancelBtn.FlatStyle = FlatStyle.Flat; cancelBtn.Size = new Size(60, 25);
cancelBtn.FlatAppearance.BorderSize = 0; cancelBtn.Location = new Point(320, 30);
cancelBtn.Click += CancelBtn_Click; cancelBtn.BackColor = ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Light
this.Controls.Add(cancelBtn); ? SystemColors.Control
} : Color.FromArgb(70, 70, 70);
cancelBtn.ForeColor = ThemeManager.TextColor;
public void UpdateDisplay() cancelBtn.FlatStyle = FlatStyle.Flat;
{ cancelBtn.FlatAppearance.BorderSize = 0;
nameLabel.Text = FileName; cancelBtn.Click += CancelBtn_Click;
progressBar.Value = Progress; this.Controls.Add(cancelBtn);
statusLabel.Text = Status; }
}
public void UpdateDisplay()
private void CancelBtn_Click(object sender, EventArgs e) {
{ nameLabel.Text = FileName;
if (sender == null || e == null) return; progressBar.Value = Progress;
if (InvokeRequired) statusLabel.Text = Status;
{ }
Invoke(new EventHandler(CancelBtn_Click), sender, e);
return; private void CancelBtn_Click(object sender, EventArgs e)
} {
if (sender == null || e == null) return;
try if (InvokeRequired)
{ {
DownloadManager.Instance.CancelDownload(this); Invoke(new EventHandler(CancelBtn_Click), sender, e);
Status = "已取消"; return;
UpdateDisplay(); }
}
catch (Exception ex) try
{ {
Status = $"取消失败: {ex.Message}"; DownloadManager.Instance.CancelDownload(this);
UpdateDisplay(); Status = "已取消";
} UpdateDisplay();
} }
} catch (Exception ex)
} {
Status = $"取消失败: {ex.Message}";
UpdateDisplay();
}
}
}
}

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;

View File

@@ -1,190 +1,196 @@
using System; // _ _
using System.Diagnostics; //| | _____ _ __| |_ __ _ _ __ _ __ ____
using System.Drawing; //| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
using System.IO; //| | (_) | | | || (_| | |_) | |_) |_____/ /
using System.Windows.Forms; //|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
namespace AppStore using System;
{ using System.Diagnostics;
public class ImageCompressorForm : Form using System.Drawing;
{ using System.IO;
private Button btnSelectInput = new Button(); using System.Windows.Forms;
private Button btnSelectOutput = new Button();
private Button btnCompress = new Button(); namespace AppStore
private TextBox txtInput = new TextBox(); {
private TextBox txtOutput = new TextBox(); public class ImageCompressorForm : Form
private RadioButton rbLossy = new RadioButton(); {
private RadioButton rbLossless = new RadioButton(); private Button btnSelectInput = new Button();
private TrackBar tbQuality = new TrackBar(); private Button btnSelectOutput = new Button();
private Label lblQuality = new Label(); private Button btnCompress = new Button();
private CheckBox cbKeepExif = new CheckBox(); private TextBox txtInput = new TextBox();
private ProgressBar progressBar = new ProgressBar(); private TextBox txtOutput = new TextBox();
private RadioButton rbLossy = new RadioButton();
public ImageCompressorForm() private RadioButton rbLossless = new RadioButton();
{ private TrackBar tbQuality = new TrackBar();
InitializeComponent(); private Label lblQuality = new Label();
} private CheckBox cbKeepExif = new CheckBox();
private ProgressBar progressBar = new ProgressBar();
private void InitializeComponent()
{ public ImageCompressorForm()
this.Text = "图片压缩工具"; {
this.Size = new Size(500, 350); InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen; }
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false; private void InitializeComponent()
{
// 输入文件选择 this.Text = "图片压缩工具";
btnSelectInput.Text = "选择..."; this.Size = new Size(500, 350);
btnSelectInput.Location = new Point(400, 20); this.StartPosition = FormStartPosition.CenterScreen;
btnSelectInput.Click += (s, e) => SelectFile(txtInput); this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.Controls.Add(btnSelectInput); this.MaximizeBox = false;
txtInput.Location = new Point(20, 20); // 输入文件选择
txtInput.Size = new Size(370, 20); btnSelectInput.Text = "选择...";
txtInput.ReadOnly = true; btnSelectInput.Location = new Point(400, 20);
this.Controls.Add(txtInput); btnSelectInput.Click += (s, e) => SelectFile(txtInput);
this.Controls.Add(btnSelectInput);
Label lblInput = new Label();
lblInput.Text = "输入文件:"; txtInput.Location = new Point(20, 20);
lblInput.Location = new Point(20, 0); txtInput.Size = new Size(370, 20);
this.Controls.Add(lblInput); txtInput.ReadOnly = true;
this.Controls.Add(txtInput);
// 输出文件选择
btnSelectOutput.Text = "选择..."; Label lblInput = new Label();
btnSelectOutput.Location = new Point(400, 70); lblInput.Text = "输入文件:";
btnSelectOutput.Click += (s, e) => SelectFile(txtOutput, true); lblInput.Location = new Point(20, 0);
this.Controls.Add(btnSelectOutput); this.Controls.Add(lblInput);
txtOutput.Location = new Point(20, 70); // 输出文件选择
txtOutput.Size = new Size(370, 20); btnSelectOutput.Text = "选择...";
this.Controls.Add(txtOutput); btnSelectOutput.Location = new Point(400, 70);
btnSelectOutput.Click += (s, e) => SelectFile(txtOutput, true);
Label lblOutput = new Label(); this.Controls.Add(btnSelectOutput);
lblOutput.Text = "输出文件:";
lblOutput.Location = new Point(20, 50); txtOutput.Location = new Point(20, 70);
this.Controls.Add(lblOutput); txtOutput.Size = new Size(370, 20);
this.Controls.Add(txtOutput);
// 压缩类型
rbLossy.Text = "有损压缩 (JPEG)"; Label lblOutput = new Label();
rbLossy.Location = new Point(20, 110); lblOutput.Text = "输出文件:";
rbLossy.Checked = true; lblOutput.Location = new Point(20, 50);
this.Controls.Add(rbLossy); this.Controls.Add(lblOutput);
rbLossless.Text = "无损压缩 (PNG)"; // 压缩类型
rbLossless.Location = new Point(20, 135); rbLossy.Text = "有损压缩 (JPEG)";
this.Controls.Add(rbLossless); rbLossy.Location = new Point(20, 110);
rbLossy.Checked = true;
// 质量设置 this.Controls.Add(rbLossy);
tbQuality.Minimum = 1;
tbQuality.Maximum = 1000; rbLossless.Text = "无损压缩 (PNG)";
tbQuality.Value = 800; rbLossless.Location = new Point(20, 135);
tbQuality.Location = new Point(20, 190); this.Controls.Add(rbLossless);
tbQuality.Size = new Size(300, 50);
tbQuality.Scroll += (s, e) => lblQuality.Text = $"压缩质量: {tbQuality.Value}"; // 质量设置
this.Controls.Add(tbQuality); tbQuality.Minimum = 1;
tbQuality.Maximum = 1000;
lblQuality.Text = $"压缩质量: {tbQuality.Value}"; tbQuality.Value = 800;
lblQuality.Location = new Point(20, 170); tbQuality.Location = new Point(20, 190);
this.Controls.Add(lblQuality); tbQuality.Size = new Size(300, 50);
tbQuality.Scroll += (s, e) => lblQuality.Text = $"压缩质量: {tbQuality.Value}";
// EXIF选项 this.Controls.Add(tbQuality);
cbKeepExif.Text = "保留EXIF信息";
cbKeepExif.Location = new Point(20, 240); lblQuality.Text = $"压缩质量: {tbQuality.Value}";
this.Controls.Add(cbKeepExif); lblQuality.Location = new Point(20, 170);
this.Controls.Add(lblQuality);
// 压缩按钮
btnCompress.Text = "开始压缩"; // EXIF选项
btnCompress.Location = new Point(20, 280); cbKeepExif.Text = "保留EXIF信息";
btnCompress.Size = new Size(460, 30); cbKeepExif.Location = new Point(20, 240);
btnCompress.Click += BtnCompress_Click; this.Controls.Add(cbKeepExif);
this.Controls.Add(btnCompress);
// 压缩按钮
// 调整窗体大小 btnCompress.Text = "开始压缩";
this.Size = new Size(500, 370); btnCompress.Location = new Point(20, 280);
} btnCompress.Size = new Size(460, 30);
btnCompress.Click += BtnCompress_Click;
private void SelectFile(TextBox target, bool isSave = false) this.Controls.Add(btnCompress);
{
var dialog = isSave ? new SaveFileDialog() : new OpenFileDialog() as FileDialog; // 调整窗体大小
dialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp|所有文件|*.*"; this.Size = new Size(500, 370);
}
if (dialog.ShowDialog() == DialogResult.OK)
{ private void SelectFile(TextBox target, bool isSave = false)
target.Text = dialog.FileName; {
} var dialog = isSave ? new SaveFileDialog() : new OpenFileDialog() as FileDialog;
} dialog.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.bmp|所有文件|*.*";
private void BtnCompress_Click(object sender, EventArgs e) if (dialog.ShowDialog() == DialogResult.OK)
{ {
if (string.IsNullOrEmpty(txtInput.Text) || !File.Exists(txtInput.Text)) target.Text = dialog.FileName;
{ }
MessageBox.Show("请选择有效的输入文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
return;
} private void BtnCompress_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtOutput.Text)) if (string.IsNullOrEmpty(txtInput.Text) || !File.Exists(txtInput.Text))
{ {
MessageBox.Show("请指定输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("请选择有效的输入文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
btnCompress.Enabled = false; if (string.IsNullOrEmpty(txtOutput.Text))
{
try MessageBox.Show("请指定输出文件", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
{ return;
string toolPath = Path.Combine(Application.StartupPath, "resource", "image_compressor.exe"); }
if (!File.Exists(toolPath))
{ btnCompress.Enabled = false;
MessageBox.Show("图片压缩工具未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; try
} {
string toolPath = Path.Combine(Application.StartupPath, "resource", "image_compressor.exe");
string args = $"\"{txtInput.Text}\" \"{txtOutput.Text}\""; if (!File.Exists(toolPath))
args += $" -t {(rbLossy.Checked ? "lossy" : "lossless")}"; {
args += $" -q {tbQuality.Value}"; MessageBox.Show("图片压缩工具未找到", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (cbKeepExif.Checked) args += " -e"; return;
}
var process = new Process();
process.StartInfo.FileName = toolPath; string args = $"\"{txtInput.Text}\" \"{txtOutput.Text}\"";
process.StartInfo.Arguments = args; args += $" -t {(rbLossy.Checked ? "lossy" : "lossless")}";
process.StartInfo.UseShellExecute = false; args += $" -q {tbQuality.Value}";
process.StartInfo.CreateNoWindow = true; if (cbKeepExif.Checked) args += " -e";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true; var process = new Process();
process.StartInfo.FileName = toolPath;
process.OutputDataReceived += (s, ev) => { process.StartInfo.Arguments = args;
if (!string.IsNullOrEmpty(ev.Data)) process.StartInfo.UseShellExecute = false;
Console.WriteLine(ev.Data); process.StartInfo.CreateNoWindow = true;
}; process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.ErrorDataReceived += (s, ev) => {
if (!string.IsNullOrEmpty(ev.Data)) process.OutputDataReceived += (s, ev) => {
Console.Error.WriteLine(ev.Data); if (!string.IsNullOrEmpty(ev.Data))
}; Console.WriteLine(ev.Data);
};
process.Start();
process.BeginOutputReadLine(); process.ErrorDataReceived += (s, ev) => {
process.BeginErrorReadLine(); if (!string.IsNullOrEmpty(ev.Data))
process.WaitForExit(); Console.Error.WriteLine(ev.Data);
};
if (process.ExitCode == 0)
{ process.Start();
MessageBox.Show("图片压缩完成", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); process.BeginOutputReadLine();
} process.BeginErrorReadLine();
else process.WaitForExit();
{
MessageBox.Show("图片压缩失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); if (process.ExitCode == 0)
} {
} MessageBox.Show("图片压缩完成", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
catch (Exception ex) }
{ else
MessageBox.Show($"压缩过程中发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); {
} MessageBox.Show("图片压缩失败", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
finally }
{ }
btnCompress.Enabled = true; catch (Exception ex)
progressBar.Visible = false; {
} MessageBox.Show($"压缩过程中发生错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} finally
} {
btnCompress.Enabled = true;
progressBar.Visible = false;
}
}
}
}

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
#nullable enable #nullable enable
using System; using System;
using System.Drawing; using System.Drawing;

View File

@@ -1,16 +1,22 @@
using System; // _ _
using System.Windows.Forms; //| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
namespace AppStore //| | (_) | | | || (_| | |_) | |_) |_____/ /
{ //|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
static class Program // |_| |_|
{ using System;
[STAThread] using System.Windows.Forms;
static void Main()
{ namespace AppStore
Application.EnableVisualStyles(); {
Application.SetCompatibleTextRenderingDefault(false); static class Program
Application.Run(new MainForm()); {
} [STAThread]
} static void Main()
} {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;

View File

@@ -1,113 +1,119 @@
using System; // _ _
using System.Drawing; //| | _____ _ __| |_ __ _ _ __ _ __ ____
using System.Windows.Forms; //| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
namespace AppStore //|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
{ // |_| |_|
public class ToolCard : UserControl using System;
{ using System.Drawing;
private PictureBox iconBox = new PictureBox(); using System.Windows.Forms;
private Label nameLabel = new Label();
private Panel namePanel = new Panel(); namespace AppStore
private Color borderColor = SystemColors.ControlDark; {
public class ToolCard : UserControl
public string ToolName { get; set; } = string.Empty; {
public Image ToolIcon { get; set; } = SystemIcons.Shield.ToBitmap(); private PictureBox iconBox = new PictureBox();
private Label nameLabel = new Label();
// 自定义点击事件初始化为空委托 private Panel namePanel = new Panel();
public event EventHandler ToolCardClicked = delegate {}; private Color borderColor = SystemColors.ControlDark;
public ToolCard() public string ToolName { get; set; } = string.Empty;
{ public Image ToolIcon { get; set; } = SystemIcons.Shield.ToBitmap();
// 启用双缓冲
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | // 自定义点击事件初始化为空委托
ControlStyles.ResizeRedraw, true); public event EventHandler ToolCardClicked = delegate {};
InitializeComponent();
} public ToolCard()
{
private void InitializeComponent() // 启用双缓冲
{ this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
this.Size = new Size(240, 220); ControlStyles.ResizeRedraw, true);
this.BackColor = Color.White; InitializeComponent();
this.Padding = new Padding(5); }
this.BorderStyle = BorderStyle.FixedSingle;
private void InitializeComponent()
// 工具图标 {
iconBox = new PictureBox(); this.Size = new Size(240, 220);
iconBox.Size = new Size(80, 80); this.BackColor = Color.White;
iconBox.Location = new Point((Width - 80) / 2, 15); this.Padding = new Padding(5);
iconBox.SizeMode = PictureBoxSizeMode.StretchImage; this.BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(iconBox);
// 工具图标
// 工具名称 - 使用Panel包裹Label实现边框颜色 iconBox = new PictureBox();
namePanel = new Panel(); iconBox.Size = new Size(80, 80);
namePanel.Size = new Size(Width - 20, 30); iconBox.Location = new Point((Width - 80) / 2, 15);
namePanel.Location = new Point(10, 100); iconBox.SizeMode = PictureBoxSizeMode.StretchImage;
namePanel.Paint += (sender, e) => { this.Controls.Add(iconBox);
ControlPaint.DrawBorder(e.Graphics, namePanel.ClientRectangle,
borderColor, ButtonBorderStyle.Solid); // 工具名称 - 使用Panel包裹Label实现边框颜色
}; namePanel = new Panel();
namePanel.Size = new Size(Width - 20, 30);
nameLabel = new Label(); namePanel.Location = new Point(10, 100);
nameLabel.Dock = DockStyle.Fill; namePanel.Paint += (sender, e) => {
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold); ControlPaint.DrawBorder(e.Graphics, namePanel.ClientRectangle,
nameLabel.TextAlign = ContentAlignment.MiddleCenter; borderColor, ButtonBorderStyle.Solid);
namePanel.Controls.Add(nameLabel); };
// 初始主题设置 nameLabel = new Label();
UpdateLabelTheme(); nameLabel.Dock = DockStyle.Fill;
nameLabel.Font = new Font("Microsoft YaHei", 10, FontStyle.Bold);
// 订阅主题变化事件 nameLabel.TextAlign = ContentAlignment.MiddleCenter;
ThemeManager.ThemeChanged += (theme) => UpdateLabelTheme(); namePanel.Controls.Add(nameLabel);
this.Controls.Add(namePanel); // 初始主题设置
UpdateLabelTheme();
// 打开按钮
var openButton = new Button(); // 订阅主题变化事件
openButton.Text = "打开工具"; ThemeManager.ThemeChanged += (theme) => UpdateLabelTheme();
openButton.Size = new Size(100, 30);
openButton.Location = new Point((Width - 100) / 2, 140); this.Controls.Add(namePanel);
openButton.BackColor = Color.FromArgb(0, 120, 215);
openButton.ForeColor = Color.White; // 打开按钮
openButton.FlatStyle = FlatStyle.Flat; var openButton = new Button();
openButton.FlatAppearance.BorderSize = 0; openButton.Text = "打开工具";
openButton.Cursor = Cursors.Hand; openButton.Size = new Size(100, 30);
// 按钮点击直接触发ToolCardClicked事件 openButton.Location = new Point((Width - 100) / 2, 140);
openButton.Click += (s, e) => { openButton.BackColor = Color.FromArgb(0, 120, 215);
ToolCardClicked?.Invoke(this, e); openButton.ForeColor = Color.White;
}; openButton.FlatStyle = FlatStyle.Flat;
this.Controls.Add(openButton); openButton.FlatAppearance.BorderSize = 0;
openButton.Cursor = Cursors.Hand;
// 设置按钮悬停效果 // 按钮点击直接触发ToolCardClicked事件
openButton.BackColor = Color.FromArgb(0, 120, 215); openButton.Click += (s, e) => {
openButton.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 100, 180); ToolCardClicked?.Invoke(this, e);
openButton.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 80, 160); };
} this.Controls.Add(openButton);
private void UpdateLabelTheme() // 设置按钮悬停效果
{ openButton.BackColor = Color.FromArgb(0, 120, 215);
if (ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Dark) openButton.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 100, 180);
{ openButton.FlatAppearance.MouseDownBackColor = Color.FromArgb(0, 80, 160);
nameLabel.BackColor = Color.Black; }
nameLabel.ForeColor = Color.White;
namePanel.BackColor = Color.Black; private void UpdateLabelTheme()
borderColor = Color.White; {
} if (ThemeManager.CurrentTheme == ThemeManager.ThemeMode.Dark)
else {
{ nameLabel.BackColor = Color.Black;
nameLabel.BackColor = Color.White; nameLabel.ForeColor = Color.White;
nameLabel.ForeColor = Color.Black; namePanel.BackColor = Color.Black;
namePanel.BackColor = Color.White; borderColor = Color.White;
borderColor = SystemColors.ControlDark; }
} else
namePanel.Invalidate(); // 触发重绘 {
} nameLabel.BackColor = Color.White;
nameLabel.ForeColor = Color.Black;
public void UpdateDisplay() namePanel.BackColor = Color.White;
{ borderColor = SystemColors.ControlDark;
nameLabel.Text = ToolName; }
iconBox.Image = ToolIcon; namePanel.Invalidate(); // 触发重绘
UpdateLabelTheme(); }
}
} public void UpdateDisplay()
} {
nameLabel.Text = ToolName;
iconBox.Image = ToolIcon;
UpdateLabelTheme();
}
}
}

View File

@@ -1,64 +1,70 @@
#include <windows.h> // _ _
#include <vector> //| | _____ _ __| |_ __ _ _ __ _ __ ____
#include <fstream> //| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
#include <cmath> //| | (_) | | | || (_| | |_) | |_) |_____/ /
#include <d2d1.h> //|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
// 高性能边框路径生成 #include <windows.h>
void GenerateBorderPath(int width, int height, int radius, const char* outputPath) { #include <vector>
std::ofstream out(outputPath); #include <fstream>
const float pi = 3.1415926f; #include <cmath>
const int segments = 24; // 高分段数确保平滑 #include <d2d1.h>
std::vector<POINTFLOAT> points; // 高性能边框路径生成
void GenerateBorderPath(int width, int height, int radius, const char* outputPath) {
// 优化后的圆角路径生成 std::ofstream out(outputPath);
auto addArc = [&](float startAngle, float endAngle, float cx, float cy) { const float pi = 3.1415926f;
for (int i = 0; i <= segments; ++i) { const int segments = 24; // 高分段数确保平滑
float angle = startAngle + (endAngle - startAngle) * i / segments;
points.push_back({ std::vector<POINTFLOAT> points;
cx + radius * cosf(angle),
cy + radius * sinf(angle) // 优化后的圆角路径生成
}); auto addArc = [&](float startAngle, float endAngle, float cx, float cy) {
} for (int i = 0; i <= segments; ++i) {
}; float angle = startAngle + (endAngle - startAngle) * i / segments;
points.push_back({
// 左上角 cx + radius * cosf(angle),
addArc(pi, 3*pi/2, radius, radius); cy + radius * sinf(angle)
});
// 右上角 }
addArc(3*pi/2, 2*pi, width - radius, radius); };
// 右下 // 左上
addArc(0, pi/2, width - radius, height - radius); addArc(pi, 3*pi/2, radius, radius);
// 左下角 // 右上角
addArc(pi/2, pi, radius, height - radius); addArc(3*pi/2, 2*pi, width - radius, radius);
// 闭合路径 // 右下角
points.push_back(points[0]); addArc(0, pi/2, width - radius, height - radius);
// 写入优化格式 // 左下角
if (out.is_open()) { addArc(pi/2, pi, radius, height - radius);
for (const auto& p : points) {
out << p.x << "," << p.y << "\n"; // 闭合路径
} points.push_back(points[0]);
}
} // 写入优化格式
if (out.is_open()) {
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { for (const auto& p : points) {
int argc; out << p.x << "," << p.y << "\n";
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); }
}
if (argc != 5) return 1; }
int width = _wtoi(argv[1]); int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
int height = _wtoi(argv[2]); int argc;
int radius = _wtoi(argv[3]); LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
char outputPath[MAX_PATH]; if (argc != 5) return 1;
wcstombs(outputPath, argv[4], MAX_PATH);
int width = _wtoi(argv[1]);
GenerateBorderPath(width, height, radius, outputPath); int height = _wtoi(argv[2]);
return 0; int radius = _wtoi(argv[3]);
}
char outputPath[MAX_PATH];
wcstombs(outputPath, argv[4], MAX_PATH);
GenerateBorderPath(width, height, radius, outputPath);
return 0;
}

View File

@@ -1,90 +1,96 @@
#include <iostream> // _ _
#include <fstream> //| | _____ _ __| |_ __ _ _ __ _ __ ____
#include <vector> //| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
#include <cmath> //| | (_) | | | || (_| | |_) | |_) |_____/ /
#include <windows.h> //|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using namespace std; #include <iostream>
#include <fstream>
struct Point { #include <vector>
float x; #include <cmath>
float y; #include <windows.h>
};
using namespace std;
void WritePathToFile(const vector<Point>& path, const string& filename) {
ofstream outFile(filename); struct Point {
if (!outFile) { float x;
cerr << "无法打开输出文件: " << filename << endl; float y;
return; };
}
void WritePathToFile(const vector<Point>& path, const string& filename) {
for (const auto& point : path) { ofstream outFile(filename);
outFile << point.x << "," << point.y << "\n"; if (!outFile) {
} cerr << "无法打开输出文件: " << filename << endl;
outFile.close(); return;
} }
vector<Point> CalculateRoundedRectPath(int width, int height, int radius) { for (const auto& point : path) {
vector<Point> pathPoints; outFile << point.x << "," << point.y << "\n";
}
const int segments = 10; outFile.close();
const float angleStep = 3.1415926f / (2 * segments); }
// 左上角 vector<Point> CalculateRoundedRectPath(int width, int height, int radius) {
for (int i = 0; i <= segments; i++) { vector<Point> pathPoints;
float angle = 3.1415926f + i * angleStep;
pathPoints.push_back({ const int segments = 10;
radius + radius * cosf(angle), const float angleStep = 3.1415926f / (2 * segments);
radius + radius * sinf(angle)
}); // 左上角
} for (int i = 0; i <= segments; i++) {
float angle = 3.1415926f + i * angleStep;
// 右上角 pathPoints.push_back({
for (int i = 0; i <= segments; i++) { radius + radius * cosf(angle),
float angle = 3 * 3.1415926f / 2 + i * angleStep; radius + radius * sinf(angle)
pathPoints.push_back({ });
width - radius + radius * cosf(angle), }
radius + radius * sinf(angle)
}); // 右上角
} for (int i = 0; i <= segments; i++) {
float angle = 3 * 3.1415926f / 2 + i * angleStep;
// 右下角 pathPoints.push_back({
for (int i = 0; i <= segments; i++) { width - radius + radius * cosf(angle),
float angle = 0 + i * angleStep; radius + radius * sinf(angle)
pathPoints.push_back({ });
width - radius + radius * cosf(angle), }
height - radius + radius * sinf(angle)
}); // 右下角
} for (int i = 0; i <= segments; i++) {
float angle = 0 + i * angleStep;
// 左下角 pathPoints.push_back({
for (int i = 0; i <= segments; i++) { width - radius + radius * cosf(angle),
float angle = 3.1415926f / 2 + i * angleStep; height - radius + radius * sinf(angle)
pathPoints.push_back({ });
radius + radius * cosf(angle), }
height - radius + radius * sinf(angle)
}); // 左下角
} for (int i = 0; i <= segments; i++) {
float angle = 3.1415926f / 2 + i * angleStep;
// 闭合路径 pathPoints.push_back({
pathPoints.push_back(pathPoints[0]); radius + radius * cosf(angle),
height - radius + radius * sinf(angle)
return pathPoints; });
} }
int main(int argc, char* argv[]) { // 闭合路径
if (argc != 5) { pathPoints.push_back(pathPoints[0]);
cout << "用法: card_calculator [宽度] [高度] [圆角半径] [输出文件]" << endl;
return 1; return pathPoints;
} }
int width = stoi(argv[1]); int main(int argc, char* argv[]) {
int height = stoi(argv[2]); if (argc != 5) {
int radius = stoi(argv[3]); cout << "用法: card_calculator [宽度] [高度] [圆角半径] [输出文件]" << endl;
string outputFile = argv[4]; return 1;
}
auto path = CalculateRoundedRectPath(width, height, radius);
WritePathToFile(path, outputFile); int width = stoi(argv[1]);
int height = stoi(argv[2]);
return 0; int radius = stoi(argv[3]);
} string outputFile = argv[4];
auto path = CalculateRoundedRectPath(width, height, radius);
WritePathToFile(path, outputFile);
return 0;
}

View File

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

View File

@@ -1,3 +1,9 @@
// _ _
//| | _____ _ __| |_ __ _ _ __ _ __ ____
//| |/ / _ \| '__| __/ _` | '_ \| '_ \ ____|_ /
//| | (_) | | | || (_| | |_) | |_) |_____/ /
//|_|\_\___/|_| \__\__,_| .__/| .__/ /___|
// |_| |_|
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;