Skip to content

Commit 0579d63

Browse files
authored
Merge pull request #11 from SamHou2007/develop
v3.1.3
2 parents 625c6d5 + c460a21 commit 0579d63

18 files changed

+252
-87
lines changed

TCSetup/TCSetup.vdproj

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
}
2222
"Entry"
2323
{
24+
"MsmKey" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
25+
"OwnerKey" = "8:_UNDEFINED"
26+
"MsmSig" = "8:_UNDEFINED"
27+
}
28+
"Entry"
29+
{
2430
"MsmKey" = "8:_B7C31D1C4E42443D89CA87F9596A43B7"
2531
"OwnerKey" = "8:_UNDEFINED"
2632
"MsmSig" = "8:_UNDEFINED"
@@ -127,6 +133,26 @@
127133
}
128134
"File"
129135
{
136+
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_9BF8F60AD5F2474D82994CD2D95F44A1"
137+
{
138+
"SourcePath" = "8:..\\TimeControl\\icons8_sand_watch.ico"
139+
"TargetName" = "8:icons8_sand_watch.ico"
140+
"Tag" = "8:"
141+
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
142+
"Condition" = "8:"
143+
"Transitive" = "11:FALSE"
144+
"Vital" = "11:TRUE"
145+
"ReadOnly" = "11:FALSE"
146+
"Hidden" = "11:FALSE"
147+
"System" = "11:FALSE"
148+
"Permanent" = "11:FALSE"
149+
"SharedLegacy" = "11:FALSE"
150+
"PackageAs" = "3:1"
151+
"Register" = "3:1"
152+
"Exclude" = "11:FALSE"
153+
"IsDependency" = "11:FALSE"
154+
"IsolateTo" = "8:"
155+
}
130156
}
131157
"FileType"
132158
{
@@ -183,15 +209,15 @@
183209
{
184210
"Name" = "8:Microsoft Visual Studio"
185211
"ProductName" = "8:TimeControl"
186-
"ProductCode" = "8:{BB3E5E5C-6F52-48B4-893C-57EB236F23D6}"
187-
"PackageCode" = "8:{65B804AE-9561-4656-8793-2FB8B8BEBCDF}"
212+
"ProductCode" = "8:{58790286-6BF3-4D15-BE41-3514CFB9D21B}"
213+
"PackageCode" = "8:{15145DC8-E457-4268-AA72-57CBF07212D1}"
188214
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
189215
"AspNetVersion" = "8:4.0.30319.0"
190216
"RestartWWWService" = "11:FALSE"
191217
"RemovePreviousVersions" = "11:TRUE"
192218
"DetectNewerInstalledVersion" = "11:TRUE"
193219
"InstallAllUsers" = "11:FALSE"
194-
"ProductVersion" = "8:3.1.1"
220+
"ProductVersion" = "8:3.1.3"
195221
"Manufacturer" = "8:SamHou"
196222
"ARPHELPTELEPHONE" = "8:"
197223
"ARPHELPLINK" = "8:"
@@ -201,7 +227,7 @@
201227
"Keywords" = "8:"
202228
"ARPCOMMENTS" = "8:TimeControl安装程序"
203229
"ARPURLINFOABOUT" = "8:"
204-
"ARPPRODUCTICON" = "8:"
230+
"ARPPRODUCTICON" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
205231
"ARPIconIndex" = "3:0"
206232
"SearchPath" = "8:"
207233
"UseSystemSearchPath" = "11:TRUE"
@@ -379,7 +405,7 @@
379405
"Target" = "8:_B7C31D1C4E42443D89CA87F9596A43B7"
380406
"Folder" = "8:_EF355E43AD4E49F3B0AE27E1F063797B"
381407
"WorkingFolder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
382-
"Icon" = "8:"
408+
"Icon" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
383409
"Feature" = "8:"
384410
}
385411
"{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_5426797F4F7D48478759844D9558460B"
@@ -393,7 +419,7 @@
393419
"Target" = "8:_B7C31D1C4E42443D89CA87F9596A43B7"
394420
"Folder" = "8:_24D444A51FBD4D6AB659A544BB198230"
395421
"WorkingFolder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
396-
"Icon" = "8:"
422+
"Icon" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
397423
"Feature" = "8:"
398424
}
399425
}
@@ -797,7 +823,7 @@
797823
{
798824
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF"
799825
{
800-
"SourcePath" = "8:..\\TimeControlConsole\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
826+
"SourcePath" = "8:..\\TimeControlConsole\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe"
801827
"TargetName" = "8:"
802828
"Tag" = "8:"
803829
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
@@ -825,7 +851,7 @@
825851
}
826852
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
827853
{
828-
"SourcePath" = "8:..\\TimeControl\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
854+
"SourcePath" = "8:..\\TimeControl\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe"
829855
"TargetName" = "8:"
830856
"Tag" = "8:"
831857
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"

TimeControl/App.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using System.IO;
67

78
namespace TimeControl
89
{
910
public class App
1011
{
11-
private string name;
12-
private string location;
12+
private readonly string name;
1313
public string Name { get { return name; }}
1414
internal int time;
1515
/// <summary>
@@ -20,18 +20,20 @@ public override string ToString()
2020
{
2121
return Name + " 已使用 " + time+" 秒!";
2222
}
23-
public App(string name, string location)
23+
public App(string name,int time)
2424
{
25+
this.time = time;
2526
this.name = name;
26-
this.location = location;
27-
Reset();
2827
}
2928
/// <summary>
3029
/// 运行一次(一秒)
3130
/// </summary>
32-
public virtual void Run()
31+
public virtual void Run(StreamWriter streamWriter)
3332
{
3433
time++;
34+
streamWriter.WriteLine(Name);
35+
streamWriter.WriteLine(time);
36+
streamWriter.WriteLine("//");
3537
}
3638
/// <summary>
3739
/// 重设时间
Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,61 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Windows.Forms;
8+
using System.IO;
89

910
namespace TimeControl
1011
{
11-
public class ListController
12+
public class AppController
1213
{
14+
private FileStream fileStream = new(TimeControlFile.TimeFileLocation,
15+
FileMode.OpenOrCreate,
16+
FileAccess.ReadWrite, FileShare.None);
17+
private StreamWriter streamWriter;
1318
private ListBox listBox;
1419
private List<App> apps;
1520
private Timer timer;
1621

17-
public ListController(ListBox listBox,Timer timer)
22+
public AppController(ListBox listBox, Timer timer)
1823
{
24+
streamWriter = new(fileStream);
1925
this.listBox = listBox;
2026
apps = new List<App>();
2127
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();
2263
}
2364

2465
/// <summary>
@@ -46,7 +87,7 @@ public void AddByName(string name)
4687
{
4788
foreach (Process process in processes)
4889
{
49-
apps.Add(new App(process.ProcessName, process.MainModule.FileName));
90+
apps.Add(new App(process.ProcessName, 0));
5091
}
5192
}
5293
catch (Exception ex)
@@ -60,15 +101,15 @@ public void AddByName(string name)
60101
/// </summary>
61102
/// <param name="name">进程名称</param>
62103
/// <param name="limitTime">限制时长(秒)</param>
63-
public void AddByName(string name,int limitTime)
104+
public void AddByName(string name, int limitTime)
64105
{
65106
timer.Stop();
66107
Process[] processes = Process.GetProcessesByName(name);
67108
try
68109
{
69110
foreach (Process process in processes)
70111
{
71-
apps.Add(new LimitedApp(process.ProcessName, process.MainModule.FileName,limitTime));
112+
apps.Add(new LimitedApp(process.ProcessName, 0, limitTime));
72113
}
73114
}
74115
catch (Exception ex)
@@ -82,19 +123,21 @@ public void AddByName(string name,int limitTime)
82123
/// </summary>
83124
public void Run()
84125
{
126+
fileStream.SetLength(0);
85127
foreach (App app in apps)//计算进程时间
86128
{
87129
if (Process.GetProcessesByName(app.Name).Length != 0)
88130
{
89131
if (app is LimitedApp)
90132
{
91-
LimitedApp limitedApp=app as LimitedApp;
92-
limitedApp.Run();
133+
LimitedApp limitedApp = app as LimitedApp;
134+
limitedApp.Run(streamWriter);
93135
}
94136
else
95-
app.Run();
137+
app.Run(streamWriter);
96138
}
97139
}
140+
streamWriter.Flush();
98141
}
99142
/// <summary>
100143
/// 移除所列表所选的进程
@@ -106,5 +149,14 @@ public void Remove()
106149
apps.RemoveAt(listBox.SelectedIndex);
107150
Refresh();
108151
}
152+
/// <summary>
153+
/// 删除所有监控
154+
/// </summary>
155+
public void RemoveAll()
156+
{
157+
timer.Stop();
158+
apps.Clear();
159+
Refresh();
160+
}
109161
}
110162
}

TimeControl/ControlPanel.Designer.cs

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

0 commit comments

Comments
 (0)