Skip to content

Commit cf13ebc

Browse files
committed
更新关于程序页面
1 parent 1b94645 commit cf13ebc

18 files changed

Lines changed: 480 additions & 69 deletions

File tree

ContextMenuManager/BluePointLilac.Methods/IniReader.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -31,7 +31,10 @@ public void LoadStringBuilder(StringBuilder sb)
3131
if (sb.ToString().IsNullOrWhiteSpace()) return;
3232
var lines = sb.ToString().Split(new[] { "\r\n", "\n" },
3333
StringSplitOptions.RemoveEmptyEntries).ToList();//拆分为行
34-
lines.ForEach(line => line.Trim());
34+
for (int i = 0; i < lines.Count; i++)
35+
{
36+
lines[i] = lines[i].Trim();
37+
}
3538
ReadLines(lines);
3639
}
3740

@@ -69,18 +72,20 @@ private void ReadLines(List<string> lines)
6972
for (var i = 0; i < indexs.Count - 1; i++)
7073
{
7174
var section = lines[indexs[i]];
72-
var m = section.IndexOf(']') - 1;
73-
if (m < 0) continue;
74-
section = section.Substring(1, m);
75+
var startIndex = section.IndexOf('[') + 1;
76+
var endIndex = section.IndexOf(']');
77+
if (endIndex <= startIndex) continue;
78+
section = section.Substring(startIndex, endIndex - startIndex).Trim();// 修剪section名称
7579
if (RootDic.ContainsKey(section)) continue;
7680
var keyValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
7781
RootDic.Add(section, keyValues);
7882

7983
for (var j = indexs[i] + 1; j < indexs[i + 1]; j++)
8084
{
8185
var k = lines[j].IndexOf('=');
82-
var key = lines[j][..k].TrimEnd();
83-
var value = lines[j][(k + 1)..].TrimStart();
86+
if (k <= 0) continue;
87+
var key = lines[j][..k].Trim();// 修剪key名称
88+
var value = lines[j][(k + 1)..].Trim();// 修剪value值
8489
if (keyValues.ContainsKey(key)) continue;
8590
keyValues.Add(key, value);
8691
}
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
using BluePointLilac.Controls;
2+
using BluePointLilac.Methods;
3+
using ContextMenuManager.Methods;
4+
using ContextMenuManager.Properties;
5+
using System;
6+
using System.Drawing;
7+
using System.IO;
8+
using System.Windows.Forms;
9+
10+
namespace ContextMenuManager.Controls
11+
{
12+
internal sealed class AboutAppBox : Panel
13+
{
14+
public AboutAppBox()
15+
{
16+
SuspendLayout();
17+
Dock = DockStyle.Fill;
18+
BackColor = DarkModeHelper.FormBack;
19+
Font = SystemFonts.MenuFont;
20+
Font = new Font(Font.FontFamily, Font.Size + 1F);
21+
22+
// 重置所有控件属性,使用最简单可靠的设置
23+
24+
// 设置logo图片
25+
pbLogo.Image = Resources.Logo;
26+
pbLogo.SizeMode = PictureBoxSizeMode.Zoom;
27+
pbLogo.Size = new Size(100, 100);
28+
pbLogo.Visible = true;
29+
30+
// 设置标题标签
31+
lblTitle.Text = AppString.General.AppName;
32+
lblTitle.Font = new Font(Font.FontFamily, Font.Size + 3F, FontStyle.Bold);
33+
lblTitle.ForeColor = Color.Orange;
34+
lblTitle.TextAlign = ContentAlignment.MiddleCenter;
35+
lblTitle.Size = new Size(400, 30);
36+
lblTitle.Visible = true;
37+
38+
// 设置描述标签 - 重写为更简单可靠的设置
39+
lblDescription.Text = AppString.About.Description; // 使用多语言文本
40+
lblDescription.TextAlign = ContentAlignment.MiddleCenter;
41+
lblDescription.Size = new Size(300, 30); // 调整高度为30像素
42+
lblDescription.Visible = true;
43+
lblDescription.ForeColor = DarkModeHelper.FormFore;
44+
lblDescription.BackColor = Color.Transparent;
45+
lblDescription.BorderStyle = BorderStyle.None;
46+
47+
// 设置GitHub标签
48+
lblGitHub.Text = $"{AppString.About.GitHub}: https://github.com/Jack251970/ContextMenuManager"; // 使用多语言文本
49+
lblGitHub.TextAlign = ContentAlignment.MiddleCenter;
50+
lblGitHub.ForeColor = Color.Orange;
51+
lblGitHub.Cursor = Cursors.Hand;
52+
lblGitHub.Size = new Size(400, 20);
53+
lblGitHub.Visible = true;
54+
lblGitHub.MouseDown += (sender, e) => ExternalProgram.OpenWebUrl("https://github.com/Jack251970/ContextMenuManager");
55+
56+
// 设置Gitee标签
57+
lblGitee.Text = $"{AppString.About.Gitee}: https://gitee.com/Jack251970/ContextMenuManager"; // 使用多语言文本
58+
lblGitee.TextAlign = ContentAlignment.MiddleCenter;
59+
lblGitee.ForeColor = Color.Orange;
60+
lblGitee.Cursor = Cursors.Hand;
61+
lblGitee.Size = new Size(400, 20);
62+
lblGitee.Visible = true;
63+
lblGitee.MouseDown += (sender, e) => ExternalProgram.OpenWebUrl("https://gitee.com/Jack251970/ContextMenuManager");
64+
65+
// 设置许可证标签
66+
lblLicense.Text = $"{AppString.About.License}: GPL License"; // 使用多语言文本
67+
lblLicense.TextAlign = ContentAlignment.MiddleCenter;
68+
lblLicense.Size = new Size(400, 20);
69+
lblLicense.Visible = true;
70+
71+
// 设置检查更新按钮
72+
btnCheckUpdate.Text = AppString.About.CheckUpdate; // 使用多语言文本
73+
btnCheckUpdate.Size = new Size(120, 30);
74+
btnCheckUpdate.BackColor = Color.Orange;
75+
btnCheckUpdate.ForeColor = Color.White;
76+
btnCheckUpdate.FlatStyle = FlatStyle.Flat;
77+
btnCheckUpdate.FlatAppearance.BorderSize = 0;
78+
btnCheckUpdate.Cursor = Cursors.Hand;
79+
btnCheckUpdate.Visible = true;
80+
btnCheckUpdate.Click += (sender, e) => Updater.Update(true);
81+
82+
// 直接在面板上添加控件
83+
Controls.AddRange(new Control[] { pbLogo, lblTitle, lblDescription, lblGitHub, lblGitee, lblLicense, btnCheckUpdate });
84+
85+
// 监听主题变化事件
86+
DarkModeHelper.ThemeChanged += OnThemeChanged;
87+
88+
// 设置控件初始颜色
89+
UpdateControlColors();
90+
91+
// 监听大小变化,调整控件位置和宽度(实现垂直居中)
92+
Resize += (sender, e) => {
93+
// 计算各个控件之间的间距
94+
const int spacingLogoTitle = 20;
95+
const int spacingTitleDesc = 10;
96+
const int spacingDescGitHub = 15;
97+
const int spacingGitHubGitee = 10;
98+
const int spacingGiteeLicense = 10;
99+
const int spacingLicenseBtn = 30;
100+
101+
// 计算总高度
102+
int totalHeight = pbLogo.Height + spacingLogoTitle +
103+
lblTitle.Height + spacingTitleDesc +
104+
lblDescription.Height + spacingDescGitHub +
105+
lblGitHub.Height + spacingGitHubGitee +
106+
lblGitee.Height + spacingGiteeLicense +
107+
lblLicense.Height + spacingLicenseBtn +
108+
btnCheckUpdate.Height;
109+
110+
// 计算起始Y坐标,实现垂直居中
111+
int startY = (Height - totalHeight) / 2;
112+
113+
// 设置各个控件的位置
114+
pbLogo.Location = new Point((Width - pbLogo.Width) / 2, startY);
115+
116+
lblTitle.Location = new Point(0, pbLogo.Bottom + spacingLogoTitle);
117+
lblTitle.Width = Width;
118+
119+
lblDescription.Location = new Point(50, lblTitle.Bottom + spacingTitleDesc);
120+
lblDescription.Width = Width - 100;
121+
122+
lblGitHub.Location = new Point(0, lblDescription.Bottom + spacingDescGitHub);
123+
lblGitHub.Width = Width;
124+
125+
lblGitee.Location = new Point(0, lblGitHub.Bottom + spacingGitHubGitee);
126+
lblGitee.Width = Width;
127+
128+
lblLicense.Location = new Point(0, lblGitee.Bottom + spacingGiteeLicense);
129+
lblLicense.Width = Width;
130+
131+
btnCheckUpdate.Location = new Point((Width - btnCheckUpdate.Width) / 2, lblLicense.Bottom + spacingLicenseBtn);
132+
};
133+
134+
// 初始布局
135+
OnResize(null);
136+
137+
ResumeLayout();
138+
}
139+
140+
private readonly PictureBox pbLogo = new();
141+
private readonly Label lblTitle = new();
142+
private readonly Label lblGitHub = new();
143+
private readonly Label lblGitee = new(); // 添加Gitee标签
144+
private readonly Label lblLicense = new();
145+
private readonly Label lblDescription = new();
146+
private readonly Button btnCheckUpdate = new();
147+
148+
public void LoadAboutInfo()
149+
{
150+
// 恢复使用多语言文本
151+
lblTitle.Text = AppString.General.AppName;
152+
153+
// 手动加载About类的文本,确保它们被正确初始化
154+
string description = AppString.About.Description;
155+
string gitHub = AppString.About.GitHub;
156+
string gitee = AppString.About.Gitee;
157+
string license = AppString.About.License;
158+
string checkUpdate = AppString.About.CheckUpdate;
159+
160+
// 添加默认值支持,确保即使语言文件加载失败也能正常显示
161+
if (string.IsNullOrEmpty(description)) description = "一个纯粹的Windows右键菜单管理器";
162+
if (string.IsNullOrEmpty(gitHub)) gitHub = "GitHub";
163+
if (string.IsNullOrEmpty(gitee)) gitee = "Gitee";
164+
if (string.IsNullOrEmpty(license)) license = "许可证";
165+
if (string.IsNullOrEmpty(checkUpdate)) checkUpdate = "检查更新";
166+
167+
// 设置控件文本
168+
lblDescription.Text = description;
169+
lblGitHub.Text = $"{gitHub}: https://github.com/Jack251970/ContextMenuManager";
170+
lblGitee.Text = $"{gitee}: https://gitee.com/Jack251970/ContextMenuManager";
171+
lblLicense.Text = $"{license}: GPL License";
172+
btnCheckUpdate.Text = checkUpdate;
173+
174+
// 确保控件可见
175+
Visible = true;
176+
}
177+
178+
// 主题变化事件处理程序
179+
private void OnThemeChanged(object sender, EventArgs e)
180+
{
181+
UpdateControlColors();
182+
}
183+
184+
// 更新控件颜色以适应主题变化
185+
private void UpdateControlColors()
186+
{
187+
// 更新面板背景色
188+
BackColor = DarkModeHelper.FormBack;
189+
190+
// 更新标签文字颜色
191+
lblTitle.ForeColor = Color.Orange; // 保持橘色
192+
lblDescription.ForeColor = DarkModeHelper.FormFore;
193+
lblGitHub.ForeColor = Color.Orange; // 保持橘色
194+
lblGitee.ForeColor = Color.Orange; // 保持橘色
195+
lblLicense.ForeColor = DarkModeHelper.FormFore;
196+
197+
// 更新按钮颜色
198+
btnCheckUpdate.BackColor = Color.Orange; // 保持橘色
199+
btnCheckUpdate.ForeColor = Color.White; // 保持白色文字
200+
}
201+
202+
// 重写Dispose方法,取消订阅事件
203+
protected override void Dispose(bool disposing)
204+
{
205+
if (disposing)
206+
{
207+
DarkModeHelper.ThemeChanged -= OnThemeChanged;
208+
}
209+
base.Dispose(disposing);
210+
}
211+
}
212+
}

ContextMenuManager/MainForm.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public MainForm()
9090
private readonly AppSettingBox appSettingBox = new();
9191
private readonly LanguagesBox languagesBox = new();
9292
private readonly DictionariesBox dictionariesBox = new();
93-
private readonly ReadOnlyRichTextBox aboutMeBox = new();
93+
private readonly AboutAppBox aboutMeBox = new();
9494
private readonly DonateBox donateBox = new();
9595
private readonly BackupListBox backupListBox = new();
9696
private readonly ExplorerRestarter explorerRestarter = new();
@@ -457,8 +457,7 @@ private void SwitchAboutItem()
457457
dictionariesBox.LoadText(); dictionariesBox.Visible = true;
458458
break;
459459
case 4:
460-
if (aboutMeBox.TextLength == 0) aboutMeBox.LoadIni(AppString.Other.AboutApp);
461-
aboutMeBox.Visible = true;
460+
aboutMeBox.LoadAboutInfo(); aboutMeBox.Visible = true;
462461
break;
463462
case 5:
464463
donateBox.Visible = true;

ContextMenuManager/Methods/AppConfig.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using BluePointLilac.Methods;
1+
using BluePointLilac.Methods;
22
using ContextMenuManager.Controls;
33
using System;
44
using System.Collections.Generic;
@@ -171,7 +171,21 @@ private static void LoadLanguage()
171171
return;
172172
}
173173
if (language == "") language = CultureInfo.CurrentUICulture.Name;
174+
175+
#if DEBUG
176+
// 在开发环境中使用项目根目录下的languages目录
177+
string devLangsDir = $@"{Application.StartupPath}\..\languages";
178+
LanguageIniPath = $@"{devLangsDir}\{language}.ini";
179+
if (!File.Exists(LanguageIniPath))
180+
{
181+
// 如果开发目录中的语言文件不存在,回退到Config\Languages目录
182+
LanguageIniPath = $@"{LangsDir}\{language}.ini";
183+
}
184+
#else
185+
// 在发布环境中使用Config\Languages目录
174186
LanguageIniPath = $@"{LangsDir}\{language}.ini";
187+
#endif
188+
175189
if (!File.Exists(LanguageIniPath))
176190
{
177191
LanguageIniPath = "";

ContextMenuManager/Methods/AppString.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ namespace ContextMenuManager.Methods
55
{
66
internal static class AppString
77
{
8-
private static readonly IniReader UserLangReader = new(AppConfig.LanguageIniPath);
8+
private static IniReader _userLangReader;
9+
private static IniReader UserLangReader
10+
{
11+
get
12+
{
13+
if (_userLangReader == null)
14+
{
15+
// 延迟初始化,确保AppConfig.LanguageIniPath已经被正确设置
16+
_userLangReader = new IniReader(AppConfig.LanguageIniPath);
17+
}
18+
return _userLangReader;
19+
}
20+
}
921
public static readonly IniReader DefLangReader = new(new StringBuilder(Properties.Resources.AppLanguageDic));
1022

1123
private static string GetValue(string section, string key)
@@ -18,6 +30,8 @@ private static string GetValue(string section, string key)
1830
/// <summary>加载语言</summary>
1931
public static void LoadStrings()
2032
{
33+
// 重置UserLangReader,确保使用最新的LanguageIniPath
34+
_userLangReader = new IniReader(AppConfig.LanguageIniPath);
2135
foreach (var type in typeof(AppString).GetNestedTypes())
2236
{
2337
foreach (var pi in type.GetProperties())
@@ -311,6 +325,16 @@ public static class Tip
311325
public static string ImmediatelyCheck { get; set; }
312326
}
313327

328+
/// <summary>关于页面</summary>
329+
public static class About
330+
{
331+
public static string Description { get; set; }
332+
public static string CheckUpdate { get; set; }
333+
public static string GitHub { get; set; }
334+
public static string Gitee { get; set; }
335+
public static string License { get; set; }
336+
}
337+
314338
/// <summary>其他文本</summary>
315339
public static class Other
316340
{

ContextMenuManager/Properties/Resources.Designer.cs

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ContextMenuManager/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@
172172
<data name="Jump" type="System.Resources.ResXFileRef, System.Windows.Forms">
173173
<value>resources\images\jump.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
174174
</data>
175+
<data name="Logo" type="System.Resources.ResXFileRef, System.Windows.Forms">
176+
<value>resources\images\logo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
177+
</data>
175178
<data name="MicrosoftStore" type="System.Resources.ResXFileRef, System.Windows.Forms">
176179
<value>resources\images\microsoftstore.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
177180
</data>
33.1 KB
Loading

0 commit comments

Comments
 (0)