@@ -18,16 +18,18 @@ public partial class ControlPanel : Form
18
18
{
19
19
private bool hide = false ; //指示启动后是否需要隐藏
20
20
private bool isClosable = false ; //指示当前是否可以关闭
21
- List < App > appList = new ( ) ; //所有监控软件列表
22
21
private int unlockPasswordHash = 0 ; //密码哈希值,用作比对
22
+ private ListController controller ; //列表、计时控制器
23
23
public ControlPanel ( bool hide )
24
24
{
25
25
InitializeComponent ( ) ;
26
26
this . hide = hide ;
27
27
if ( File . Exists ( PasswordFile . tcPassLocation ) ) //加载密码哈希值
28
28
{
29
29
unlockPasswordHash = Convert . ToInt32 ( File . ReadAllText ( PasswordFile . tcPassLocation ) ) ;
30
+ PasswordSet ( ) ;
30
31
}
32
+ controller = new ( usageBox , processMonitorTimer ) ;
31
33
}
32
34
33
35
private void StartButton_Click ( object sender , EventArgs e ) //启动屏保程序
@@ -86,54 +88,45 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
86
88
87
89
private void AppAddButton_Click ( object sender , EventArgs e ) //添加打开的窗口
88
90
{
89
- processMonitorTimer . Stop ( ) ;
90
- Process [ ] processes = Process . GetProcessesByName ( processNameBox . Text ) ;
91
- try
91
+ if ( processNameBox . Text . ToLower ( ) == "timecontrol" ||
92
+ processNameBox . Text . ToLower ( ) == "timecontrolconsole" )
92
93
{
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 ;
101
95
}
102
- CalculateTime ( ) ;
96
+ TimeInput timeInput = new ( controller , processNameBox . Text ) ;
97
+ timeInput . ShowDialog ( ) ;
103
98
}
104
99
105
100
private void RemoveButton_Click ( object sender , EventArgs e ) //移除所有的已添加窗口
106
101
{
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 ( ) ;
110
111
}
111
112
112
113
private void RefreshButton_Click ( object sender , EventArgs e ) //重新获取所有软件所用时间
113
114
{
114
- CalculateTime ( ) ;
115
+ controller . Refresh ( ) ;
115
116
}
116
117
117
118
private void ProcessMonitorTimer_Tick ( object sender , EventArgs e )
118
119
{
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 ( ) ;
124
123
if ( Process . GetProcessesByName ( "TimeControlConsole" ) . Length == 0 ) //检查保护程序状态
125
124
{
126
125
ProcessStartInfo process = new ( ) ;
127
126
process . FileName = "TimeControlConsole.exe" ;
128
127
Process . Start ( process ) ;
129
128
}
130
129
}
131
- private void CalculateTime ( ) //将进程时间推送到ListBox控件
132
- {
133
- processMonitorTimer . Stop ( ) ;
134
- ListBoxController . Refresh ( usageBox , appList ) ;
135
- processMonitorTimer . Start ( ) ;
136
- }
137
130
private void ForceClose ( ) //可以正常关闭
138
131
{
139
132
isClosable = true ;
@@ -148,13 +141,17 @@ private void ControlPanel_Shown(object sender, EventArgs e)//启动隐藏参数
148
141
149
142
processMonitorTimer . Start ( ) ;
150
143
}
151
- private void unloackPassWordSetButton_Click ( object sender , EventArgs e ) //保存密码
144
+ private void UnloackPasswordSetButton_Click ( object sender , EventArgs e ) //保存密码
152
145
{
153
146
unlockPasswordHash = unlockPasswordBox . Text . GetHashCode ( ) ; //保存哈希值
147
+ PasswordSet ( ) ;
148
+ File . WriteAllText ( PasswordFile . tcPassLocation , unlockPasswordHash . ToString ( ) ) ; //保存哈希值到文件
149
+ }
150
+ private void PasswordSet ( ) //密码设置后调用
151
+ {
154
152
unlockPasswordBox . Text = "" ;
155
153
unlockPasswordBox . Enabled = false ;
156
- unloackPassWordSetButton . Enabled = false ;
157
- File . WriteAllText ( PasswordFile . tcPassLocation , unlockPasswordHash . ToString ( ) ) ; //保存哈希值到文件
154
+ unloackPasswordSetButton . Enabled = false ;
158
155
}
159
156
}
160
157
}
0 commit comments