Skip to content

Commit bf8d186

Browse files
committed
添加修改设置时暂停一分钟功能
1 parent 1c2ca37 commit bf8d186

File tree

11 files changed

+294
-34
lines changed

11 files changed

+294
-34
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,5 @@ ASALocalRun/
337337
.localhistory/
338338

339339
# BeatPulse healthcheck temp database
340-
healthchecksdb
340+
healthchecksdb
341+
/TimeControl/Properties/launchSettings.json

TimeControl/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
<setting name="AutoRefresh" serializeAs="String">
1414
<value>False</value>
1515
</setting>
16+
<setting name="StopBeforeSetting" serializeAs="String">
17+
<value>False</value>
18+
</setting>
1619
</TimeControl.Properties.Settings>
1720
</userSettings>
1821
</configuration>

TimeControl/Properties/Settings.Designer.cs

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TimeControl/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
<Setting Name="AutoRefresh" Type="System.Boolean" Scope="User">
99
<Value Profile="(Default)">False</Value>
1010
</Setting>
11+
<Setting Name="StopBeforeSetting" Type="System.Boolean" Scope="User">
12+
<Value Profile="(Default)">False</Value>
13+
</Setting>
1114
</Settings>
1215
</SettingsFile>

TimeControl/Properties/launchSettings.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

TimeControl/Windows/ControlPanel.Designer.cs

Lines changed: 27 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: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public partial class ControlPanel : Form
2020
private AppController appController;//Controller for list and apps.
2121
private TimeData timeData;//The data of current aim.
2222
private bool isLoaded;//Show the state of initialization.
23+
private bool isChangeable = true;
2324

2425
public ControlPanel(bool hide)
2526
{
@@ -80,6 +81,7 @@ private void ControlPanel_FormClosing(object sender, FormClosingEventArgs e)//
8081
if (!isClosable)//隐藏窗口
8182
{
8283
e.Cancel = true;
84+
DisableSet();
8385
Hide();
8486
}
8587
else//退出前关闭保护进程
@@ -221,11 +223,15 @@ private void AddTitleButton_Click(object sender, EventArgs e)
221223

222224
private void RemoveTitleButton_Click(object sender, EventArgs e)
223225
{
224-
if (titleListBox.SelectedIndex >= 0)
226+
227+
if (CheckPassword() && CheckStop())
225228
{
226-
titleListBox.Items.RemoveAt(titleListBox.SelectedIndex);
229+
if (titleListBox.SelectedIndex >= 0)
230+
{
231+
titleListBox.Items.RemoveAt(titleListBox.SelectedIndex);
232+
}
233+
SaveTitles();
227234
}
228-
SaveTitles();
229235
}
230236
private void SaveTitles()
231237
{
@@ -267,7 +273,7 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
267273

268274
private void ClearButton_Click(object sender, EventArgs e)
269275
{
270-
if (PasswordCheck())
276+
if (CheckPassword() && CheckStop())
271277
{
272278
appController.RemoveAll();
273279
}
@@ -282,7 +288,7 @@ private void AppAddButton_Click(object sender, EventArgs e)
282288
private void RemoveButton_Click(object sender, EventArgs e)
283289
{
284290
//检测密码设置
285-
if (PasswordCheck())
291+
if (CheckPassword() && CheckStop())
286292
{
287293
appController.Remove();
288294
}
@@ -306,11 +312,11 @@ private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
306312
};
307313
Process.Start(process);
308314
}
309-
Process[] processes=Process.GetProcesses();
315+
Process[] processes = Process.GetProcesses();
310316
//Title Management
311317
foreach (Process process in processes)
312318
{
313-
if(!string.IsNullOrWhiteSpace(process.MainWindowTitle))
319+
if (!string.IsNullOrWhiteSpace(process.MainWindowTitle))
314320
{
315321
foreach (string str in titleListBox.Items)
316322
{
@@ -322,7 +328,7 @@ private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
322328

323329
private void ResetButton_Click(object sender, EventArgs e)
324330
{
325-
if (PasswordCheck())
331+
if (CheckPassword())
326332
{
327333
appController.Reset();
328334
}
@@ -395,15 +401,14 @@ private void UnloackPasswordSetButton_Click(object sender, EventArgs e)//保存
395401

396402
private void UnlockPasswordRemoveButton_Click(object sender, EventArgs e)
397403
{
398-
if (PasswordCheck())
404+
if (CheckPassword())
399405
{
400406
File.Delete(TCFile.PassLocation);
401407
unlockPasswordHash = "";
402408
unlockPasswordBox.Text = "";
403409
unlockPasswordBox.Enabled = true;
404410
unlockPasswordSetButton.Enabled = true;
405411
unlockPasswordRemoveButton.Enabled = false;
406-
removeTitleButton.Enabled = true;
407412
removeBootButton.Enabled = true;
408413
}
409414
}
@@ -414,11 +419,10 @@ private void PasswordSet()//密码设置后调用
414419
unlockPasswordBox.Enabled = false;
415420
unlockPasswordSetButton.Enabled = false;
416421
unlockPasswordRemoveButton.Enabled = true;
417-
removeTitleButton.Enabled = false;
418422
removeBootButton.Enabled = false;
419423
}
420424

421-
private bool PasswordCheck()//检测密码是否正确
425+
private bool CheckPassword()//检测密码是否正确
422426
{
423427
if (!string.IsNullOrEmpty(unlockPasswordHash))
424428
{
@@ -443,7 +447,58 @@ private void RemoveBootButton_Click(object sender, EventArgs e)
443447
{
444448
TaskSchedulerControl.RemoveBoot();
445449
}
450+
private bool CheckStop()
451+
{
452+
if (!isChangeable)
453+
{
454+
IntPtr nowDesktop = Dllimport.GetThreadDesktop(Dllimport.GetCurrentThreadId());
455+
IntPtr newDesktop = Dllimport.CreateDesktop("Lock", null, null, 0, Dllimport.ACCESS_MASK.GENERIC_ALL, IntPtr.Zero);
456+
Dllimport.SwitchDesktop(newDesktop);
457+
Task.Factory.StartNew(() =>
458+
{
459+
Dllimport.SetThreadDesktop(newDesktop);
460+
InterruptWindow interruptWindow = new InterruptWindow();
461+
Application.Run(interruptWindow);
462+
}).Wait();
463+
Dllimport.SwitchDesktop(nowDesktop);
464+
Dllimport.CloseDesktop(newDesktop);
465+
if (InterruptWindow.result == DialogResult.OK)
466+
{
467+
return true;
468+
}
469+
else return false;
470+
}
471+
else return true;
472+
}
473+
private void StopCheckBox_CheckedChanged(object sender, EventArgs e)
474+
{
475+
if (stopCheckBox.Checked)
476+
{
477+
stopCheckBox.Enabled = false;
478+
}
479+
SettingsChanged(sender, e);
480+
}
481+
private void EnableButton_Click(object sender, EventArgs e)
482+
{
483+
if (CheckPassword() && CheckStop())
484+
{
485+
removeBootButton.Enabled = true;
486+
stopCheckBox.Enabled = true;
487+
}
488+
}
489+
private void DisableSet()
490+
{
491+
if (!string.IsNullOrWhiteSpace(unlockPasswordHash))
492+
{
493+
removeBootButton.Enabled = false;
446494

495+
}
496+
if (stopCheckBox.Checked)
497+
{
498+
stopCheckBox.Enabled = false;
499+
isChangeable = false;
500+
}
501+
}
447502
#endregion ProtectPage
448503

449504
#region DataPage
@@ -536,6 +591,7 @@ private void SettingsChanged(object sender, EventArgs e)
536591
{
537592
Settings.Default.AutoReset = autoResetBox.Checked;
538593
Settings.Default.AutoRefresh = autoRefreshBox.Checked;
594+
Settings.Default.StopBeforeSetting = stopCheckBox.Checked;
539595
Settings.Default.Save();
540596
}
541597
}
@@ -544,6 +600,11 @@ private void InitializeSettings()
544600
{
545601
autoResetBox.Checked = Settings.Default.AutoReset;
546602
autoRefreshBox.Checked = Settings.Default.AutoRefresh;
603+
stopCheckBox.Checked = Settings.Default.StopBeforeSetting;
604+
if (stopCheckBox.Checked)
605+
{
606+
isChangeable = false;
607+
}
547608
}
548609

549610
private void DataDirButton_Click(object sender, EventArgs e)

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)