diff --git a/App.xaml.cs b/App.xaml.cs
index 159fbd1..7ec5514 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -4,6 +4,7 @@ namespace Ona_Pix
{
public partial class App : Application
{
+ //程序启动事件
protected override void OnStartup(StartupEventArgs e)
{
Define.MAIN_WINDOW = new(e.Args);
diff --git a/Commons/Define.cs b/Commons/Define.cs
index 00c0cf8..22f1e81 100644
--- a/Commons/Define.cs
+++ b/Commons/Define.cs
@@ -3,6 +3,7 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
+using Ona_Pix.Pages;
namespace Ona_Pix
{
@@ -16,6 +17,10 @@ internal static class Define
internal static MainWindow? MAIN_WINDOW;
internal static readonly SettingWindow SETTING_WINDOW = new();
+ //页面
+ internal static readonly AppearancePage APPEARANCE_PAGE = (AppearancePage)SETTING_WINDOW.Resources["appearancePage"];
+ internal static readonly BehaviorPage BEHAVIOR_PAGE = (BehaviorPage)SETTING_WINDOW.Resources["behaviorPage"];
+
//字段
internal static readonly HttpClient MAIN_CLIENT = new();
internal static readonly string CURRENT_VERSION = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[0..^2];
diff --git a/Commons/IconRemover.cs b/Commons/IconRemover.cs
index e5413e5..1a932d6 100644
--- a/Commons/IconRemover.cs
+++ b/Commons/IconRemover.cs
@@ -5,6 +5,7 @@
namespace Ona_Pix
{
+ //定义IconRemover
internal static class IconRemover
{
private const int GWL_EXSTYLE = -20;
@@ -41,6 +42,7 @@ internal static void RemoveIcon(Window window)
}
}
+ //使用IconRemover
public partial class MainWindow
{
protected override void OnSourceInitialized(EventArgs e)
diff --git a/Commons/Smms.cs b/Commons/Smms.cs
index b9da813..8d02d7b 100644
--- a/Commons/Smms.cs
+++ b/Commons/Smms.cs
@@ -20,8 +20,10 @@ public Smms() : base("Ona-Pix-Smms.exe")
//Control.CheckForIllegalCrossThreadCalls = false;
}
+ //Smms程序调用事件
public override async void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
+ //输出事件(输出结果)
try
{
if (!string.IsNullOrEmpty(e.Data) && !string.IsNullOrWhiteSpace(e.Data))
@@ -55,6 +57,7 @@ public override async void Process_OutputDataReceived(object sender, DataReceive
}
public override void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
+ //报错事件(输出错误)
if (!string.IsNullOrEmpty(e.Data) && !string.IsNullOrWhiteSpace(e.Data))
{
ShowError!(e.Data);
@@ -63,6 +66,7 @@ public override void Process_ErrorDataReceived(object sender, DataReceivedEventA
}
public override void Process_Exited(object sender, EventArgs e)
{
+ //退出事件
SetControlsEnabled!();
}
}
diff --git a/Commons/Updater.cs b/Commons/Updater.cs
index 46b99bc..82517ce 100644
--- a/Commons/Updater.cs
+++ b/Commons/Updater.cs
@@ -19,8 +19,10 @@ private void PartialAboutWindow()
GITHUB_CLIENT.DefaultRequestHeaders.Add("User-Agent", Define.USER_AGENT_HEADER);
}
+ //用户交互流程
private async void UpdateLink_Click(object sender, RoutedEventArgs e)
{
+ //用户点击关于页面的版本号
try
{
Title = "正在获取更新";
@@ -59,6 +61,7 @@ private async void UpdateLink_Click(object sender, RoutedEventArgs e)
}
private async void ReleaseListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
+ //用户选择下载内容
Title = "继续执行更新";
try
diff --git a/Controls/ToggleSwitch.xaml.cs b/Controls/ToggleSwitch.xaml.cs
index 802a434..74a895e 100644
--- a/Controls/ToggleSwitch.xaml.cs
+++ b/Controls/ToggleSwitch.xaml.cs
@@ -19,6 +19,7 @@ public ToggleSwitch()
InitializeComponent();
}
+ //点击事件
private void ForeDot_MouseDown(object sender, MouseButtonEventArgs e)
{
SwitchStatus();
@@ -28,6 +29,7 @@ private void BackRec_MouseDown(object sender, MouseButtonEventArgs e)
SwitchStatus();
}
+ //切换Toggle状态
internal void SwitchStatus()
{
if (!IS_TOGGLED)
diff --git a/Pages/AppearancePage.xaml b/Pages/AppearancePage.xaml
index a69929b..e4835c2 100644
--- a/Pages/AppearancePage.xaml
+++ b/Pages/AppearancePage.xaml
@@ -27,7 +27,7 @@
-
+
diff --git a/Pages/AppearancePage.xaml.cs b/Pages/AppearancePage.xaml.cs
index c9fbd0a..d5136af 100644
--- a/Pages/AppearancePage.xaml.cs
+++ b/Pages/AppearancePage.xaml.cs
@@ -14,8 +14,10 @@ public AppearancePage()
InitializeComponent();
}
+ //Toggle点击事件
internal void DarkModeToggle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
+ //暗色模式
if (DarkModeToggle.IS_TOGGLED)
{
((BundledTheme)Application.Current.Resources.MergedDictionaries[0]).BaseTheme = BaseTheme.Dark;
@@ -33,6 +35,7 @@ internal void DarkModeToggle_MouseDown(object sender, System.Windows.Input.Mouse
}
internal void IconButtonToggle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
+ //按钮图标
if (IconButtonToggle.IS_TOGGLED)
Properties.Settings.Default.IsIconButton = true;
else
@@ -44,6 +47,7 @@ internal void IconButtonToggle_MouseDown(object sender, System.Windows.Input.Mou
}
internal void LockAnimationToggle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
+ //固定菜单
if (LockAnimationToggle.IS_TOGGLED)
{
Define.MAIN_WINDOW!.ActiveSpace_MouseIn(this, null!);
@@ -59,6 +63,7 @@ internal void LockAnimationToggle_MouseDown(object sender, System.Windows.Input.
}
private void HideBorderToggle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
+ //隐藏边框
Define.MAIN_WINDOW!.SizeToContent = SizeToContent.Manual;
if (HideBorderToggle.IS_TOGGLED)
@@ -72,6 +77,7 @@ private void HideBorderToggle_MouseDown(object sender, System.Windows.Input.Mous
Define.MAIN_WINDOW!.SizeToContent = SizeToContent.WidthAndHeight;
}
+ //为按钮应用暗色模式和图标按钮
private void SetButtonContent()
{
if (IconButtonToggle.IS_TOGGLED)
diff --git a/Pages/BehaviorPage.xaml.cs b/Pages/BehaviorPage.xaml.cs
index 2bc5ae9..bd073ed 100644
--- a/Pages/BehaviorPage.xaml.cs
+++ b/Pages/BehaviorPage.xaml.cs
@@ -9,8 +9,10 @@ public BehaviorPage()
InitializeComponent();
}
+ //Toggle点击事件
internal void DisableExceptionToggle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
+ //禁用报错
if (DisableExceptionToggle.IS_TOGGLED)
Properties.Settings.Default.IsExceptionDisabled = true;
else
@@ -20,6 +22,7 @@ internal void DisableExceptionToggle_MouseDown(object sender, System.Windows.Inp
}
internal void DisableTipsToggle_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
+ //禁用一言
if (DisableTipsToggle.IS_TOGGLED)
Properties.Settings.Default.IsTipsDisabled = true;
else
diff --git a/Windows/AboutWindow.xaml.cs b/Windows/AboutWindow.xaml.cs
index c062c2a..a94bdac 100644
--- a/Windows/AboutWindow.xaml.cs
+++ b/Windows/AboutWindow.xaml.cs
@@ -4,7 +4,6 @@
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Imaging;
-using Ona_Pix.Pages;
using WpfAnimatedGif;
namespace Ona_Pix
@@ -31,6 +30,7 @@ public AboutWindow(bool isDarkMode)
InitializeComponent();
PartialAboutWindow();
+ //检查暗色模式
if (isDarkMode)
{
MemoryStream memoryStream = new();
@@ -44,7 +44,8 @@ public AboutWindow(bool isDarkMode)
ImageBehavior.SetAnimatedSource(TanImage, bitmapImage);
}
- if (!((BehaviorPage)Define.SETTING_WINDOW.Resources["behaviorPage"]).DisableTipsToggle.IS_TOGGLED)
+ //显示随机一言(Tips)
+ if (!Define.BEHAVIOR_PAGE.DisableTipsToggle.IS_TOGGLED)
{
Random random = new(Convert.ToInt32(DateTime.Now.Ticks & 0x0000FFFF));
Title = $"关于: {TIPS[random.Next(0, TIPS.Length)]}";
@@ -70,8 +71,10 @@ private void AboutWin_Loaded(object sender, RoutedEventArgs e)
catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Title = "操作执行失败"; return; }
}
+ //链接点击事件
private void HyperLink_Click(object sender, RoutedEventArgs e)
{
+ //打开链接
try
{
Title = "正在打开链接";
diff --git a/Windows/MainWindow.xaml.cs b/Windows/MainWindow.xaml.cs
index a8a8f35..705d033 100644
--- a/Windows/MainWindow.xaml.cs
+++ b/Windows/MainWindow.xaml.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Specialized;
using System.ComponentModel;
+using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Text;
@@ -13,7 +14,7 @@
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Newtonsoft.Json.Linq;
-using Ona_Pix.Pages;
+using Ona_Pix.Controls;
using OnaCore;
using WpfAnimatedGif;
using DataFormats = System.Windows.DataFormats;
@@ -34,6 +35,7 @@ public MainWindow(string[] args)
{
InitializeComponent();
+ //填充拖入图标的文件路径
if (args.Length >= 1 && File.Exists(args[0]))
{
if (Array.IndexOf(Define.FILE_SUFFIXES, Path.GetExtension(args[0])) != -1)
@@ -55,19 +57,22 @@ private void MainWin_Loaded(object sender, RoutedEventArgs e)
{
try
{
+ //检查是否是第一次运行
if (Properties.Settings.Default.IsFirstRun)
Welcome();
else
- RestoreSettings();
+ PickSettings();
- if (Directory.Exists(Define.CACHE_PATH))
- new DirectoryInfo(Define.CACHE_PATH).Delete(true);
+ //清理安装包
+ ClearCache();
}
catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Title = "操作执行失败"; return; }
}
- private void Welcome()
+
+ //部分初始化操作
+ private static void Welcome()
{
- //第一次运行
+ //第一次运行显示提示和关于窗口
MessageBox.Show
(
@"欢迎回家,主人! 我是 Ona Pix,你的专属女仆★
@@ -81,42 +86,60 @@ private void Welcome()
Properties.Settings.Default.IsFirstRun = false;
Properties.Settings.Default.Save();
}
- private void RestoreSettings()
+ private void PickSettings()
{
+ //检查是否需要还原设置
if (Properties.Settings.Default.IsDarkMode)
- {
- ((AppearancePage)Define.SETTING_WINDOW.Resources["appearancePage"]).DarkModeToggle.SwitchStatus();
- ((AppearancePage)Define.SETTING_WINDOW.Resources["appearancePage"]).DarkModeToggle_MouseDown(this, null!);
- }
+ RestoreSettings(Define.APPEARANCE_PAGE.DarkModeToggle, Define.APPEARANCE_PAGE.DarkModeToggle_MouseDown);
if (Properties.Settings.Default.IsIconButton)
- {
- ((AppearancePage)Define.SETTING_WINDOW.Resources["appearancePage"]).IconButtonToggle.SwitchStatus();
- ((AppearancePage)Define.SETTING_WINDOW.Resources["appearancePage"]).IconButtonToggle_MouseDown(this, null!);
- }
+ RestoreSettings(Define.APPEARANCE_PAGE.IconButtonToggle, Define.APPEARANCE_PAGE.IconButtonToggle_MouseDown);
if (Properties.Settings.Default.IsAnimationLocked)
- {
- ((AppearancePage)Define.SETTING_WINDOW.Resources["appearancePage"]).LockAnimationToggle.SwitchStatus();
- ((AppearancePage)Define.SETTING_WINDOW.Resources["appearancePage"]).LockAnimationToggle_MouseDown(this, null!);
- }
+ RestoreSettings(Define.APPEARANCE_PAGE.LockAnimationToggle, Define.APPEARANCE_PAGE.LockAnimationToggle_MouseDown);
if (Properties.Settings.Default.IsExceptionDisabled)
+ RestoreSettings(Define.BEHAVIOR_PAGE.DisableExceptionToggle, Define.BEHAVIOR_PAGE.DisableExceptionToggle_MouseDown);
+ if (Properties.Settings.Default.IsTipsDisabled)
+ RestoreSettings(Define.BEHAVIOR_PAGE.DisableTipsToggle, Define.BEHAVIOR_PAGE.DisableTipsToggle_MouseDown);
+ }
+ private void RestoreSettings(ToggleSwitch toggle, Action