77using System . Windows . Forms ;
88using TimeControl . AppControl ;
99using TimeControl . Data ;
10+ using TimeControl . Properties ;
1011using TimeControl . Tools ;
1112using Windows . ApplicationModel . Contacts ;
1213using 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}
0 commit comments