Skip to content

Commit 625c6d5

Browse files
authored
Merge pull request #10 from SamHou2007/develop
v3.1.1
2 parents b81156c + 08c4f80 commit 625c6d5

16 files changed

+643
-98
lines changed

TCSetup/TCSetup.vdproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
}
147147
"{3C67513D-01DD-4637-8A68-80971EB9504F}:_57FF55C0487B4507A7ADC64F8E5966A5"
148148
{
149-
"DefaultLocation" = "8:[ProgramFilesFolder][Manufacturer]\\[ProductName]"
149+
"DefaultLocation" = "8:[ProgramFiles64Folder][Manufacturer]\\[ProductName]"
150150
"Name" = "8:#1925"
151151
"AlwaysCreate" = "11:FALSE"
152152
"Condition" = "8:"
@@ -183,29 +183,29 @@
183183
{
184184
"Name" = "8:Microsoft Visual Studio"
185185
"ProductName" = "8:TimeControl"
186-
"ProductCode" = "8:{232A368F-8E6F-4FBB-B176-718FE5FE9F46}"
187-
"PackageCode" = "8:{9FEA6838-90F7-4F96-9D10-00374CF5ABA5}"
186+
"ProductCode" = "8:{BB3E5E5C-6F52-48B4-893C-57EB236F23D6}"
187+
"PackageCode" = "8:{65B804AE-9561-4656-8793-2FB8B8BEBCDF}"
188188
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
189189
"AspNetVersion" = "8:4.0.30319.0"
190190
"RestartWWWService" = "11:FALSE"
191191
"RemovePreviousVersions" = "11:TRUE"
192192
"DetectNewerInstalledVersion" = "11:TRUE"
193193
"InstallAllUsers" = "11:FALSE"
194-
"ProductVersion" = "8:3.1.0"
194+
"ProductVersion" = "8:3.1.1"
195195
"Manufacturer" = "8:SamHou"
196196
"ARPHELPTELEPHONE" = "8:"
197197
"ARPHELPLINK" = "8:"
198198
"Title" = "8:TCSetup"
199199
"Subject" = "8:"
200200
"ARPCONTACT" = "8:SamHou"
201201
"Keywords" = "8:"
202-
"ARPCOMMENTS" = "8:"
202+
"ARPCOMMENTS" = "8:TimeControl安装程序"
203203
"ARPURLINFOABOUT" = "8:"
204204
"ARPPRODUCTICON" = "8:"
205205
"ARPIconIndex" = "3:0"
206206
"SearchPath" = "8:"
207207
"UseSystemSearchPath" = "11:TRUE"
208-
"TargetPlatform" = "3:0"
208+
"TargetPlatform" = "3:1"
209209
"PreBuildEvent" = "8:"
210210
"PostBuildEvent" = "8:"
211211
"RunPostBuildEvent" = "3:0"
@@ -797,7 +797,7 @@
797797
{
798798
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF"
799799
{
800-
"SourcePath" = "8:..\\TimeControlConsole\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
800+
"SourcePath" = "8:..\\TimeControlConsole\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
801801
"TargetName" = "8:"
802802
"Tag" = "8:"
803803
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
@@ -825,7 +825,7 @@
825825
}
826826
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
827827
{
828-
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows\\apphost.exe"
828+
"SourcePath" = "8:..\\TimeControl\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
829829
"TargetName" = "8:"
830830
"Tag" = "8:"
831831
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"

TimeControl/App.cs

+19-6
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,39 @@
66

77
namespace TimeControl
88
{
9-
internal class App
9+
public class App
1010
{
1111
private string name;
1212
private string location;
1313
public string Name { get { return name; }}
14-
private int time;
15-
16-
public string ReportApp()
14+
internal int time;
15+
/// <summary>
16+
/// 返回进程的简要概述
17+
/// </summary>
18+
/// <returns>进程的简要概述</returns>
19+
public override string ToString()
1720
{
1821
return Name + " 已使用 " + time+" 秒!";
1922
}
2023
public App(string name, string location)
2124
{
2225
this.name = name;
2326
this.location = location;
24-
time = 0;
27+
Reset();
2528
}
26-
public void Run()
29+
/// <summary>
30+
/// 运行一次(一秒)
31+
/// </summary>
32+
public virtual void Run()
2733
{
2834
time++;
2935
}
36+
/// <summary>
37+
/// 重设时间
38+
/// </summary>
39+
public void Reset()
40+
{
41+
time = 0;
42+
}
3043
}
3144
}

TimeControl/ControlPanel.Designer.cs

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

TimeControl/ControlPanel.cs

+28-31
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ public partial class ControlPanel : Form
1818
{
1919
private bool hide = false;//指示启动后是否需要隐藏
2020
private bool isClosable = false;//指示当前是否可以关闭
21-
List<App> appList = new();//所有监控软件列表
2221
private int unlockPasswordHash = 0;//密码哈希值,用作比对
22+
private ListController controller;//列表、计时控制器
2323
public ControlPanel(bool hide)
2424
{
2525
InitializeComponent();
2626
this.hide = hide;
2727
if (File.Exists(PasswordFile.tcPassLocation))//加载密码哈希值
2828
{
2929
unlockPasswordHash = Convert.ToInt32(File.ReadAllText(PasswordFile.tcPassLocation));
30+
PasswordSet();
3031
}
32+
controller = new(usageBox, processMonitorTimer);
3133
}
3234

3335
private void StartButton_Click(object sender, EventArgs e)//启动屏保程序
@@ -86,54 +88,45 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
8688

8789
private void AppAddButton_Click(object sender, EventArgs e)//添加打开的窗口
8890
{
89-
processMonitorTimer.Stop();
90-
Process[] processes=Process.GetProcessesByName(processNameBox.Text);
91-
try
91+
if (processNameBox.Text.ToLower() == "timecontrol" ||
92+
processNameBox.Text.ToLower() == "timecontrolconsole")
9293
{
93-
foreach (Process process in processes)
94-
{
95-
appList.Add(new App(process.ProcessName, process.MainModule.FileName));
96-
}
97-
}
98-
catch (Exception ex)
99-
{
100-
MessageBox.Show("错误",ex.Message,MessageBoxButtons.OK,MessageBoxIcon.Error);
94+
return;
10195
}
102-
CalculateTime();
96+
TimeInput timeInput = new(controller, processNameBox.Text);
97+
timeInput.ShowDialog();
10398
}
10499

105100
private void RemoveButton_Click(object sender, EventArgs e)//移除所有的已添加窗口
106101
{
107-
if (usageBox.SelectedIndex >=0)
108-
appList.RemoveAt(usageBox.SelectedIndex);
109-
CalculateTime();
102+
//检测密码设置
103+
if (unlockPasswordHash != 0)
104+
{
105+
PasswordInput passwordInput = new(unlockPasswordHash);
106+
if (passwordInput.ShowDialog() == DialogResult.OK)
107+
controller.Remove();
108+
}
109+
else
110+
controller.Remove();
110111
}
111112

112113
private void RefreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间
113114
{
114-
CalculateTime();
115+
controller.Refresh();
115116
}
116117

117118
private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
118119
{
119-
foreach (App app in appList)//计算进程时间
120-
{
121-
if (Process.GetProcessesByName(app.Name).Length != 0)
122-
{ app.Run(); }
123-
}
120+
controller.Run();
121+
if (autoRefreshBox.Checked)
122+
controller.Refresh();
124123
if (Process.GetProcessesByName("TimeControlConsole").Length == 0)//检查保护程序状态
125124
{
126125
ProcessStartInfo process = new();
127126
process.FileName = "TimeControlConsole.exe";
128127
Process.Start(process);
129128
}
130129
}
131-
private void CalculateTime()//将进程时间推送到ListBox控件
132-
{
133-
processMonitorTimer.Stop();
134-
ListBoxController.Refresh(usageBox, appList);
135-
processMonitorTimer.Start();
136-
}
137130
private void ForceClose()//可以正常关闭
138131
{
139132
isClosable = true;
@@ -148,13 +141,17 @@ private void ControlPanel_Shown(object sender, EventArgs e)//启动隐藏参数
148141

149142
processMonitorTimer.Start();
150143
}
151-
private void unloackPassWordSetButton_Click(object sender, EventArgs e)//保存密码
144+
private void UnloackPasswordSetButton_Click(object sender, EventArgs e)//保存密码
152145
{
153146
unlockPasswordHash = unlockPasswordBox.Text.GetHashCode();//保存哈希值
147+
PasswordSet();
148+
File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件
149+
}
150+
private void PasswordSet()//密码设置后调用
151+
{
154152
unlockPasswordBox.Text = "";
155153
unlockPasswordBox.Enabled = false;
156-
unloackPassWordSetButton.Enabled = false;
157-
File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件
154+
unloackPasswordSetButton.Enabled = false;
158155
}
159156
}
160157
}

0 commit comments

Comments
 (0)