Skip to content

Commit 8f80fb1

Browse files
committed
添加每日自动重置计时功能
1 parent 747592b commit 8f80fb1

File tree

7 files changed

+136
-16
lines changed

7 files changed

+136
-16
lines changed

TimeControl/App.config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="TimeControl.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<userSettings>
9+
<TimeControl.Properties.Settings>
10+
<setting name="AutoReset" serializeAs="String">
11+
<value>False</value>
12+
</setting>
13+
<setting name="AutoRefresh" serializeAs="String">
14+
<value>False</value>
15+
</setting>
16+
</TimeControl.Properties.Settings>
17+
</userSettings>
18+
</configuration>

TimeControl/Properties/Settings.Designer.cs

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
3-
<Profiles>
4-
<Profile Name="(Default)" />
5-
</Profiles>
6-
</SettingsFile>
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="TimeControl.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="AutoReset" Type="System.Boolean" Scope="User">
6+
<Value Profile="(Default)">False</Value>
7+
</Setting>
8+
<Setting Name="AutoRefresh" Type="System.Boolean" Scope="User">
9+
<Value Profile="(Default)">False</Value>
10+
</Setting>
11+
</Settings>
12+
</SettingsFile>

TimeControl/Settings.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace TimeControl.Properties {
2+
3+
4+
// 通过此类可以处理设置类的特定事件:
5+
// 在更改某个设置的值之前将引发 SettingChanging 事件。
6+
// 在更改某个设置的值之后将引发 PropertyChanged 事件。
7+
// 在加载设置值之后将引发 SettingsLoaded 事件。
8+
// 在保存设置值之前将引发 SettingsSaving 事件。
9+
internal sealed partial class Settings {
10+
11+
public Settings() {
12+
// // 若要为保存和更改设置添加事件处理程序,请取消注释下列行:
13+
//
14+
// this.SettingChanging += this.SettingChangingEventHandler;
15+
//
16+
// this.SettingsSaving += this.SettingsSavingEventHandler;
17+
//
18+
}
19+
20+
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
21+
// 在此处添加用于处理 SettingChangingEvent 事件的代码。
22+
}
23+
24+
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
25+
// 在此处添加用于处理 SettingsSaving 事件的代码。
26+
}
27+
}
28+
}

TimeControl/Windows/ControlPanel.Designer.cs

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

TimeControl/Windows/ControlPanel.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Windows.Forms;
88
using TimeControl.AppControl;
99
using TimeControl.Data;
10+
using TimeControl.Properties;
1011
using TimeControl.Tools;
1112
using Windows.ApplicationModel.Contacts;
1213
using Windows.UI;
@@ -20,8 +21,10 @@ public partial class ControlPanel : Form
2021
private string unlockPasswordHash = "";//密码哈希值,用作比对
2122
private AppController appController;//列表、计时控制器
2223
private TimeData timeData;//数据
24+
private bool isLoaded;//指示加载是否已经完成
2325
public ControlPanel(bool hide)
2426
{
27+
isLoaded = false;
2528
Process[] processes = Process.GetProcessesByName("TimeControl");
2629
if (processes.Length > 1)
2730
{
@@ -41,6 +44,7 @@ public ControlPanel(bool hide)
4144
Environment.Exit(0);
4245
}
4346
InitializeComponent();
47+
InitializeSettings();
4448
this.hide = hide;
4549
//数据记录
4650
if (File.Exists(TimeControlFile.SavedData))
@@ -87,6 +91,10 @@ public ControlPanel(bool hide)
8791
Directory.CreateDirectory(TimeControlFile.BaseLocation);
8892
}
8993
appController = new(usageBox, processMonitorTimer);
94+
if ((Directory.GetLastWriteTime(TimeControlFile.TimeFileDirectory).ToString("yyyy-MM-dd")
95+
!= DateTime.Now.ToString("yyyy-MM-dd"))
96+
&& autoResetBox.Checked)
97+
appController.Reset();
9098
fileSaveTimer.Start();
9199
//自动关机
92100
if (File.Exists(TimeControlFile.ShutdownSpan))
@@ -109,6 +117,7 @@ public ControlPanel(bool hide)
109117
}
110118
else
111119
unlockPasswordRemoveButton.Enabled = false;
120+
isLoaded = true;
112121
}
113122

114123
#region Form
@@ -193,7 +202,7 @@ private void StartLock(string unlockPasswordHash, int minutes = 0)
193202
Dllimport.CloseDesktop(newDesktop);
194203
int index = dataGridView.Rows.Add();
195204
timeData.AddTime(Lock.TempTimeSpan);
196-
ResultWindow resultWindow=new(Lock.TempTimeSpan);
205+
ResultWindow resultWindow = new(Lock.TempTimeSpan);
197206
resultWindow.Show();
198207
RefreshAndSaveData();
199208
}
@@ -397,11 +406,11 @@ private void ShowProgress(TimeData timeData)
397406

398407
progressLabel.Text = $"进入下一级还需要专注{Math.Round((targetTimeSpan - timeSpan).TotalHours, 3)}小时";
399408
levelLabel.Text = $"当前等级:{level}/100级";
400-
progressBar.Value =Convert.ToInt32( (timeSpan / targetTimeSpan) *100);
409+
progressBar.Value = Convert.ToInt32((timeSpan / targetTimeSpan) * 100);
401410
if (level == 100)
402411
{
403412
encourageLabel.Text = "恭喜通关!你可以通过删除TimeControl文件夹里的SavedData.xml来重新开始!";
404-
progressLabel.Visible= false;
413+
progressLabel.Visible = false;
405414
progressBar.Value = 100;
406415
}
407416
}
@@ -424,7 +433,20 @@ private void HelpLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventA
424433
Process.Start("explorer.exe",
425434
"https://gitee.com/Sam-Hou/ComputerTimeControl/wikis/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98&%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E");
426435
}
436+
private void SettingsChanged(object sender, EventArgs e)
437+
{
438+
if (isLoaded)
439+
{
440+
Settings.Default.AutoReset = autoResetBox.Checked;
441+
Settings.Default.AutoRefresh = autoRefreshBox.Checked;
442+
Settings.Default.Save();
443+
}
444+
}
445+
private void InitializeSettings()
446+
{
447+
autoResetBox.Checked = Settings.Default.AutoReset;
448+
autoRefreshBox.Checked = Settings.Default.AutoRefresh;
449+
}
427450
#endregion
428-
429451
}
430452
}

TimeControl/Windows/ControlPanel.resx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@
6363
<metadata name="nameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
6464
<value>True</value>
6565
</metadata>
66-
<metadata name="timeColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
67-
<value>True</value>
68-
</metadata>
69-
<metadata name="nameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
70-
<value>True</value>
71-
</metadata>
7266
<metadata name="notifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
7367
<value>17, 17</value>
7468
</metadata>

0 commit comments

Comments
 (0)