Skip to content

Commit 494a74a

Browse files
authored
Merge pull request #12 from SamHou2007/develop
3.2.0
2 parents 0579d63 + 0189f8f commit 494a74a

10 files changed

+147
-124
lines changed

TCSetup/TCSetup.vdproj

+7-7
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,24 @@
209209
{
210210
"Name" = "8:Microsoft Visual Studio"
211211
"ProductName" = "8:TimeControl"
212-
"ProductCode" = "8:{58790286-6BF3-4D15-BE41-3514CFB9D21B}"
213-
"PackageCode" = "8:{15145DC8-E457-4268-AA72-57CBF07212D1}"
212+
"ProductCode" = "8:{363F9324-4EDC-45ED-8286-322CA5109544}"
213+
"PackageCode" = "8:{07EBB234-3576-4FAD-8A56-24A64982FEB6}"
214214
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
215215
"AspNetVersion" = "8:4.0.30319.0"
216216
"RestartWWWService" = "11:FALSE"
217217
"RemovePreviousVersions" = "11:TRUE"
218218
"DetectNewerInstalledVersion" = "11:TRUE"
219219
"InstallAllUsers" = "11:FALSE"
220-
"ProductVersion" = "8:3.1.3"
220+
"ProductVersion" = "8:3.2.0"
221221
"Manufacturer" = "8:SamHou"
222222
"ARPHELPTELEPHONE" = "8:"
223-
"ARPHELPLINK" = "8:"
223+
"ARPHELPLINK" = "8:https://github.com/SamHou2007/ComputerTimeControl"
224224
"Title" = "8:TCSetup"
225225
"Subject" = "8:"
226226
"ARPCONTACT" = "8:SamHou"
227227
"Keywords" = "8:"
228228
"ARPCOMMENTS" = "8:TimeControl安装程序"
229-
"ARPURLINFOABOUT" = "8:"
229+
"ARPURLINFOABOUT" = "8:https://github.com/SamHou2007"
230230
"ARPPRODUCTICON" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
231231
"ARPIconIndex" = "3:0"
232232
"SearchPath" = "8:"
@@ -823,7 +823,7 @@
823823
{
824824
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF"
825825
{
826-
"SourcePath" = "8:..\\TimeControlConsole\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe"
826+
"SourcePath" = "8:..\\TimeControlConsole\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
827827
"TargetName" = "8:"
828828
"Tag" = "8:"
829829
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
@@ -851,7 +851,7 @@
851851
}
852852
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
853853
{
854-
"SourcePath" = "8:..\\TimeControl\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe"
854+
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
855855
"TargetName" = "8:"
856856
"Tag" = "8:"
857857
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"

TimeControl/App.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,39 @@
77

88
namespace TimeControl
99
{
10+
[Serializable]
1011
public class App
1112
{
1213
private readonly string name;
13-
public string Name { get { return name; }}
14+
15+
public string Name
16+
{ get { return name; } }
17+
1418
internal int time;
19+
1520
/// <summary>
1621
/// 返回进程的简要概述
1722
/// </summary>
1823
/// <returns>进程的简要概述</returns>
1924
public override string ToString()
2025
{
21-
return Name + " 已使用 " + time+" 秒!";
26+
return Name + " 已使用 " + time + " 秒!";
2227
}
23-
public App(string name,int time)
28+
29+
public App(string name, int time)
2430
{
2531
this.time = time;
2632
this.name = name;
2733
}
34+
2835
/// <summary>
2936
/// 运行一次(一秒)
3037
/// </summary>
31-
public virtual void Run(StreamWriter streamWriter)
38+
public virtual void Run()
3239
{
3340
time++;
34-
streamWriter.WriteLine(Name);
35-
streamWriter.WriteLine(time);
36-
streamWriter.WriteLine("//");
3741
}
42+
3843
/// <summary>
3944
/// 重设时间
4045
/// </summary>
@@ -43,4 +48,4 @@ public void Reset()
4348
time = 0;
4449
}
4550
}
46-
}
51+
}

TimeControl/AppController.cs

+26-58
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,21 @@
99

1010
namespace TimeControl
1111
{
12+
[Serializable]
1213
public class AppController
1314
{
14-
private FileStream fileStream = new(TimeControlFile.TimeFileLocation,
15-
FileMode.OpenOrCreate,
16-
FileAccess.ReadWrite, FileShare.None);
17-
private StreamWriter streamWriter;
18-
private ListBox listBox;
1915
private List<App> apps;
20-
private Timer timer;
2116

2217
public AppController(ListBox listBox, Timer timer)
2318
{
24-
streamWriter = new(fileStream);
25-
this.listBox = listBox;
2619
apps = new List<App>();
27-
this.timer = timer;
28-
StreamReader streamReader = new(fileStream);
29-
int lineNumber = 1;
30-
string name = null;
31-
int time = 0;
32-
int timeLimit = 0;
33-
while (!streamReader.EndOfStream)//读取文件,添加进程
34-
{
35-
string line = streamReader.ReadLine();
36-
if (line == "//")
37-
{
38-
if (timeLimit == 0)
39-
apps.Add(new App(name, time));
40-
else
41-
apps.Add(new LimitedApp(name, time, timeLimit));
42-
43-
lineNumber = 1;
44-
name = null;
45-
time = 0;
46-
timeLimit = 0;
47-
48-
continue;
49-
}
50-
else
51-
{
52-
if (lineNumber == 1)
53-
name = line;
54-
else if (lineNumber == 2)
55-
time = Convert.ToInt32(line);
56-
else if (lineNumber == 3)
57-
timeLimit = Convert.ToInt32(line);
58-
59-
lineNumber++;
60-
}
61-
}
62-
Refresh();
20+
Refresh(timer, listBox);
6321
}
6422

6523
/// <summary>
6624
/// 刷新列表显示
6725
/// </summary>
68-
public void Refresh()
26+
public void Refresh(Timer timer, ListBox listBox)
6927
{
7028
timer.Stop();
7129
listBox.Items.Clear();
@@ -75,11 +33,12 @@ public void Refresh()
7533
}
7634
timer.Start();
7735
}
36+
7837
/// <summary>
7938
/// 根据名称添加进程
8039
/// </summary>
8140
/// <param name="name">要添加的进程名称</param>
82-
public void AddByName(string name)
41+
public void AddByName(string name, Timer timer, ListBox listBox)
8342
{
8443
timer.Stop();
8544
Process[] processes = Process.GetProcessesByName(name);
@@ -94,14 +53,15 @@ public void AddByName(string name)
9453
{
9554
MessageBox.Show("错误", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
9655
}
97-
this.Refresh();
56+
Refresh(timer, listBox);
9857
}
58+
9959
/// <summary>
10060
/// 根据名称添加时间受限的进程
10161
/// </summary>
10262
/// <param name="name">进程名称</param>
10363
/// <param name="limitTime">限制时长(秒)</param>
104-
public void AddByName(string name, int limitTime)
64+
public void AddByName(string name, int limitTime, Timer timer, ListBox listBox)
10565
{
10666
timer.Stop();
10767
Process[] processes = Process.GetProcessesByName(name);
@@ -116,47 +76,55 @@ public void AddByName(string name, int limitTime)
11676
{
11777
MessageBox.Show("错误", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
11878
}
119-
this.Refresh();
79+
Refresh(timer, listBox);
12080
}
81+
12182
/// <summary>
12283
/// 跟踪所有进程,增加一秒
12384
/// </summary>
12485
public void Run()
12586
{
126-
fileStream.SetLength(0);
12787
foreach (App app in apps)//计算进程时间
12888
{
12989
if (Process.GetProcessesByName(app.Name).Length != 0)
13090
{
13191
if (app is LimitedApp)
13292
{
13393
LimitedApp limitedApp = app as LimitedApp;
134-
limitedApp.Run(streamWriter);
94+
limitedApp.Run();
13595
}
13696
else
137-
app.Run(streamWriter);
97+
app.Run();
13898
}
13999
}
140-
streamWriter.Flush();
141100
}
101+
142102
/// <summary>
143103
/// 移除所列表所选的进程
144104
/// </summary>
145-
public void Remove()
105+
public void Remove(Timer timer, ListBox listBox)
146106
{
147107
timer.Stop();
148108
if (listBox.SelectedIndex >= 0)
149109
apps.RemoveAt(listBox.SelectedIndex);
150-
Refresh();
110+
Refresh(timer, listBox);
151111
}
112+
152113
/// <summary>
153114
/// 删除所有监控
154115
/// </summary>
155-
public void RemoveAll()
116+
public void RemoveAll(Timer timer, ListBox listBox)
156117
{
157118
timer.Stop();
158119
apps.Clear();
159-
Refresh();
120+
Refresh(timer, listBox);
121+
}
122+
123+
public void ResetAll(Timer timer, ListBox listBox)
124+
{
125+
foreach (App app in apps)
126+
app.Reset();
127+
Refresh(timer, listBox);
160128
}
161129
}
162-
}
130+
}

TimeControl/ControlPanel.Designer.cs

+27-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)