Skip to content

Commit ed7d4f2

Browse files
committed
添加多个白名单功能
1 parent c61ab83 commit ed7d4f2

File tree

9 files changed

+227
-42
lines changed

9 files changed

+227
-42
lines changed

TimeControl/ControlPanel.Designer.cs

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

TimeControl/ControlPanel.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ public ControlPanel(bool hide)
4040
if (File.Exists(TimeControlFile.WhiteAppLocation))
4141
whiteProcessBox.Text = File.ReadAllText(TimeControlFile.WhiteAppLocation);
4242
if (File.Exists(TimeControlFile.TempTimeFile))
43-
StartLock(unlockPasswordHash, whiteProcessBox.Text);
44-
43+
{
44+
MessageBox.Show("恢复屏保");
45+
StartLock(unlockPasswordHash);
46+
}
4547
}
4648

4749
private void StartButton_Click(object sender, EventArgs e)//启动屏保程序
4850
{
49-
StartLock(unlockPasswordHash, whiteProcessBox.Text, (int)timeBox.Value);
51+
StartLock(unlockPasswordHash, (int)timeBox.Value);
5052
}
51-
private void StartLock(string unlockPasswordHash, string processLocation, int minutes = 0)
53+
private void StartLock(string unlockPasswordHash, int minutes = 0)
5254
{
5355
IntPtr nowDesktop = Dllimport.GetThreadDesktop(Dllimport.GetCurrentThreadId());
5456
IntPtr newDesktop = Dllimport.CreateDesktop("Lock", null, null, 0, Dllimport.ACCESS_MASK.GENERIC_ALL, IntPtr.Zero);
@@ -58,9 +60,9 @@ private void StartLock(string unlockPasswordHash, string processLocation, int mi
5860
Dllimport.SetThreadDesktop(newDesktop);
5961
Lock _lock;
6062
if (minutes != 0)
61-
_lock = new(minutes, unlockPasswordHash, processLocation);
63+
_lock = new(minutes, unlockPasswordHash);
6264
else
63-
_lock = new(unlockPasswordHash, processLocation);
65+
_lock = new(unlockPasswordHash);
6466
Application.Run(_lock);
6567
}).Wait();
6668
Dllimport.SwitchDesktop(nowDesktop);
@@ -232,5 +234,10 @@ private void helpLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventA
232234
Process.Start("explorer.exe",
233235
"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");
234236
}
237+
238+
private void whiteProcessBox_TextChanged(object sender, EventArgs e)
239+
{
240+
File.WriteAllText(TimeControlFile.WhiteAppLocation, whiteProcessBox.Text);
241+
}
235242
}
236243
}

TimeControl/Lock.Designer.cs

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

TimeControl/Lock.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,37 @@ public partial class Lock : Form
1616
{
1717
private bool usePassword = true;
1818
private string unlockPasswordHash;
19-
private string processLocation;
19+
private string[] processLocation;
2020
private readonly DateTime startTime;
2121
private readonly TimeSpan targetTimeSpan;
2222

23-
public Lock(int minutes, string unlockPasswordHash, string processLocation)
23+
public Lock(int minutes, string unlockPasswordHash)
2424
{
2525
InitializeComponent();
2626

2727
targetTimeSpan = new TimeSpan(0, 0, minutes, 0);
2828
startTime = DateTime.Now;
29-
30-
File.WriteAllText(TimeControlFile.WhiteAppLocation, processLocation);
3129
File.AppendAllText(TimeControlFile.TempTimeFile, startTime.ToString() + Environment.NewLine);
3230
File.AppendAllText(TimeControlFile.TempTimeFile, targetTimeSpan.ToString());
3331

34-
Init(unlockPasswordHash, processLocation);
32+
Init(unlockPasswordHash);
3533
}
36-
public Lock(string unlockPasswordHash, string processLocation)
34+
public Lock(string unlockPasswordHash)
3735
{
3836
InitializeComponent();
3937

4038
string[] strings = File.ReadAllLines(TimeControlFile.TempTimeFile);
4139
startTime = DateTime.Parse(strings[0]);
4240
targetTimeSpan = TimeSpan.Parse(strings[1]);
4341

44-
Init(unlockPasswordHash, processLocation);
42+
Init(unlockPasswordHash);
4543
}
46-
private void Init(string unlockPasswordHash, string processLocation)
44+
private void Init(string unlockPasswordHash)
4745
{
46+
processLocation = File.ReadAllLines(TimeControlFile.WhiteAppLocation);
4847
if (string.IsNullOrEmpty(unlockPasswordHash))
4948
{ usePassword = false; }
5049
this.unlockPasswordHash = unlockPasswordHash;
51-
this.processLocation = processLocation;
5250
progressBar.Maximum = (int)targetTimeSpan.TotalSeconds;
5351
}
5452

@@ -98,13 +96,10 @@ private void UnlockButton_Click(object sender, EventArgs e)
9896
MessageBox.Show("你没有设置管理码!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
9997
}
10098

101-
private void startProcessButton_Click(object sender, EventArgs e)
99+
private void ToolBoxButton_Click(object sender, EventArgs e)
102100
{
103-
Dllimport.STARTUPINFO sTARTUPINFO = new();
104-
sTARTUPINFO.lpDesktop = "Lock";
105-
Dllimport.PROCESS_INFORMATION pROCESS_INFORMATION = new();
106-
Dllimport.CreateProcess(processLocation, null, IntPtr.Zero, IntPtr.Zero, true, 0, IntPtr.Zero, null, ref sTARTUPINFO,
107-
ref pROCESS_INFORMATION);
101+
ToolBox toolBox=new(processLocation);
102+
toolBox.ShowDialog();
108103
}
109104
}
110105
}

TimeControl/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static class Program
1616
[STAThread]
1717
static void Main(string[] args)
1818
{
19+
IntPtr nowDesktop = Dllimport.GetThreadDesktop(Dllimport.GetCurrentThreadId());
1920
try
2021
{
2122
bool hide = false;
@@ -51,6 +52,7 @@ static void Main(string[] args)
5152
}
5253
catch(Exception ex)
5354
{
55+
Dllimport.SwitchDesktop(nowDesktop);
5456
File.Delete(TimeControlFile.TempTimeFile);
5557
File.AppendAllText(TimeControlFile.LogFile, DateTime.Now.ToString() + Environment.NewLine + "===Error==="
5658
+ Environment.NewLine);
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{
22
"profiles": {
3-
"Remote": {
3+
"local": {
4+
"commandName": "Project"
5+
},
6+
"VitrualRemote": {
47
"commandName": "Project",
58
"nativeDebugging": false,
69
"remoteDebugEnabled": true,
710
"authenticationMode": "Windows",
811
"remoteDebugMachine": "192.168.31.90:6666"
912
},
10-
"local": {
11-
"commandName": "Project"
13+
"RedMiRemote": {
14+
"commandName": "Project",
15+
"remoteDebugEnabled": true,
16+
"remoteDebugMachine": "192.168.31.134:6666",
17+
"authenticationMode": "Windows"
1218
}
1319
}
1420
}

TimeControl/ToolBox.Designer.cs

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

TimeControl/ToolBox.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace TimeControl
12+
{
13+
public partial class ToolBox : Form
14+
{
15+
public ToolBox(string[] whiteList)
16+
{
17+
InitializeComponent();
18+
whiteListBox.Items.Clear();
19+
foreach (string whiteProcess in whiteList)
20+
{
21+
whiteListBox.Items.Add(whiteProcess);
22+
}
23+
}
24+
25+
private void whiteListBox_DoubleClick(object sender, EventArgs e)
26+
{
27+
if (whiteListBox.SelectedItems.Count > 0)
28+
{
29+
Dllimport.STARTUPINFO sTARTUPINFO = new();
30+
sTARTUPINFO.lpDesktop = "Lock";
31+
Dllimport.PROCESS_INFORMATION pROCESS_INFORMATION = new();
32+
Dllimport.CreateProcess(whiteListBox.SelectedItem.ToString(), null, IntPtr.Zero, IntPtr.Zero, true, 0, IntPtr.Zero, null, ref sTARTUPINFO,
33+
ref pROCESS_INFORMATION);
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)