Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions TCSetup/TCSetup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
}
"{3C67513D-01DD-4637-8A68-80971EB9504F}:_57FF55C0487B4507A7ADC64F8E5966A5"
{
"DefaultLocation" = "8:[ProgramFilesFolder][Manufacturer]\\[ProductName]"
"DefaultLocation" = "8:[ProgramFiles64Folder][Manufacturer]\\[ProductName]"
"Name" = "8:#1925"
"AlwaysCreate" = "11:FALSE"
"Condition" = "8:"
Expand Down Expand Up @@ -183,29 +183,29 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:TimeControl"
"ProductCode" = "8:{232A368F-8E6F-4FBB-B176-718FE5FE9F46}"
"PackageCode" = "8:{9FEA6838-90F7-4F96-9D10-00374CF5ABA5}"
"ProductCode" = "8:{BB3E5E5C-6F52-48B4-893C-57EB236F23D6}"
"PackageCode" = "8:{65B804AE-9561-4656-8793-2FB8B8BEBCDF}"
"UpgradeCode" = "8:{A7DC5BC4-7E3E-4B58-A0AD-3C9AC9F873C1}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:3.1.0"
"ProductVersion" = "8:3.1.1"
"Manufacturer" = "8:SamHou"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
"Title" = "8:TCSetup"
"Subject" = "8:"
"ARPCONTACT" = "8:SamHou"
"Keywords" = "8:"
"ARPCOMMENTS" = "8:"
"ARPCOMMENTS" = "8:TimeControl安装程序"
"ARPURLINFOABOUT" = "8:"
"ARPPRODUCTICON" = "8:"
"ARPIconIndex" = "3:0"
"SearchPath" = "8:"
"UseSystemSearchPath" = "11:TRUE"
"TargetPlatform" = "3:0"
"TargetPlatform" = "3:1"
"PreBuildEvent" = "8:"
"PostBuildEvent" = "8:"
"RunPostBuildEvent" = "3:0"
Expand Down Expand Up @@ -797,7 +797,7 @@
{
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF"
{
"SourcePath" = "8:..\\TimeControlConsole\\obj\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
"SourcePath" = "8:..\\TimeControlConsole\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
Expand Down Expand Up @@ -825,7 +825,7 @@
}
"{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7"
{
"SourcePath" = "8:..\\TimeControl\\obj\\Release\\net6.0-windows\\apphost.exe"
"SourcePath" = "8:..\\TimeControl\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
Expand Down
25 changes: 19 additions & 6 deletions TimeControl/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,39 @@

namespace TimeControl
{
internal class App
public class App
{
private string name;
private string location;
public string Name { get { return name; }}
private int time;

public string ReportApp()
internal int time;
/// <summary>
/// 返回进程的简要概述
/// </summary>
/// <returns>进程的简要概述</returns>
public override string ToString()
{
return Name + " 已使用 " + time+" 秒!";
}
public App(string name, string location)
{
this.name = name;
this.location = location;
time = 0;
Reset();
}
public void Run()
/// <summary>
/// 运行一次(一秒)
/// </summary>
public virtual void Run()
{
time++;
}
/// <summary>
/// 重设时间
/// </summary>
public void Reset()
{
time = 0;
}
}
}
63 changes: 38 additions & 25 deletions TimeControl/ControlPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 28 additions & 31 deletions TimeControl/ControlPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ public partial class ControlPanel : Form
{
private bool hide = false;//指示启动后是否需要隐藏
private bool isClosable = false;//指示当前是否可以关闭
List<App> appList = new();//所有监控软件列表
private int unlockPasswordHash = 0;//密码哈希值,用作比对
private ListController controller;//列表、计时控制器
public ControlPanel(bool hide)
{
InitializeComponent();
this.hide = hide;
if (File.Exists(PasswordFile.tcPassLocation))//加载密码哈希值
{
unlockPasswordHash = Convert.ToInt32(File.ReadAllText(PasswordFile.tcPassLocation));
PasswordSet();
}
controller = new(usageBox, processMonitorTimer);
}

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

private void AppAddButton_Click(object sender, EventArgs e)//添加打开的窗口
{
processMonitorTimer.Stop();
Process[] processes=Process.GetProcessesByName(processNameBox.Text);
try
if (processNameBox.Text.ToLower() == "timecontrol" ||
processNameBox.Text.ToLower() == "timecontrolconsole")
{
foreach (Process process in processes)
{
appList.Add(new App(process.ProcessName, process.MainModule.FileName));
}
}
catch (Exception ex)
{
MessageBox.Show("错误",ex.Message,MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
CalculateTime();
TimeInput timeInput = new(controller, processNameBox.Text);
timeInput.ShowDialog();
}

private void RemoveButton_Click(object sender, EventArgs e)//移除所有的已添加窗口
{
if (usageBox.SelectedIndex >=0)
appList.RemoveAt(usageBox.SelectedIndex);
CalculateTime();
//检测密码设置
if (unlockPasswordHash != 0)
{
PasswordInput passwordInput = new(unlockPasswordHash);
if (passwordInput.ShowDialog() == DialogResult.OK)
controller.Remove();
}
else
controller.Remove();
}

private void RefreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间
{
CalculateTime();
controller.Refresh();
}

private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
{
foreach (App app in appList)//计算进程时间
{
if (Process.GetProcessesByName(app.Name).Length != 0)
{ app.Run(); }
}
controller.Run();
if (autoRefreshBox.Checked)
controller.Refresh();
if (Process.GetProcessesByName("TimeControlConsole").Length == 0)//检查保护程序状态
{
ProcessStartInfo process = new();
process.FileName = "TimeControlConsole.exe";
Process.Start(process);
}
}
private void CalculateTime()//将进程时间推送到ListBox控件
{
processMonitorTimer.Stop();
ListBoxController.Refresh(usageBox, appList);
processMonitorTimer.Start();
}
private void ForceClose()//可以正常关闭
{
isClosable = true;
Expand All @@ -148,13 +141,17 @@ private void ControlPanel_Shown(object sender, EventArgs e)//启动隐藏参数

processMonitorTimer.Start();
}
private void unloackPassWordSetButton_Click(object sender, EventArgs e)//保存密码
private void UnloackPasswordSetButton_Click(object sender, EventArgs e)//保存密码
{
unlockPasswordHash = unlockPasswordBox.Text.GetHashCode();//保存哈希值
PasswordSet();
File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件
}
private void PasswordSet()//密码设置后调用
{
unlockPasswordBox.Text = "";
unlockPasswordBox.Enabled = false;
unloackPassWordSetButton.Enabled = false;
File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件
unloackPasswordSetButton.Enabled = false;
}
}
}
Loading