diff --git a/TCSetup/TCSetup.vdproj b/TCSetup/TCSetup.vdproj index 91f4db3..16d26ff 100644 --- a/TCSetup/TCSetup.vdproj +++ b/TCSetup/TCSetup.vdproj @@ -21,6 +21,12 @@ } "Entry" { + "MsmKey" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1" + "OwnerKey" = "8:_UNDEFINED" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { "MsmKey" = "8:_B7C31D1C4E42443D89CA87F9596A43B7" "OwnerKey" = "8:_UNDEFINED" "MsmSig" = "8:_UNDEFINED" @@ -127,6 +133,26 @@ } "File" { + "{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_9BF8F60AD5F2474D82994CD2D95F44A1" + { + "SourcePath" = "8:..\\TimeControl\\icons8_sand_watch.ico" + "TargetName" = "8:icons8_sand_watch.ico" + "Tag" = "8:" + "Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" + "Condition" = "8:" + "Transitive" = "11:FALSE" + "Vital" = "11:TRUE" + "ReadOnly" = "11:FALSE" + "Hidden" = "11:FALSE" + "System" = "11:FALSE" + "Permanent" = "11:FALSE" + "SharedLegacy" = "11:FALSE" + "PackageAs" = "3:1" + "Register" = "3:1" + "Exclude" = "11:FALSE" + "IsDependency" = "11:FALSE" + "IsolateTo" = "8:" + } } "FileType" { @@ -183,15 +209,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:TimeControl" - "ProductCode" = "8:{BB3E5E5C-6F52-48B4-893C-57EB236F23D6}" - "PackageCode" = "8:{65B804AE-9561-4656-8793-2FB8B8BEBCDF}" + "ProductCode" = "8:{58790286-6BF3-4D15-BE41-3514CFB9D21B}" + "PackageCode" = "8:{15145DC8-E457-4268-AA72-57CBF07212D1}" "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.1" + "ProductVersion" = "8:3.1.3" "Manufacturer" = "8:SamHou" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" @@ -201,7 +227,7 @@ "Keywords" = "8:" "ARPCOMMENTS" = "8:TimeControl安装程序" "ARPURLINFOABOUT" = "8:" - "ARPPRODUCTICON" = "8:" + "ARPPRODUCTICON" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1" "ARPIconIndex" = "3:0" "SearchPath" = "8:" "UseSystemSearchPath" = "11:TRUE" @@ -379,7 +405,7 @@ "Target" = "8:_B7C31D1C4E42443D89CA87F9596A43B7" "Folder" = "8:_EF355E43AD4E49F3B0AE27E1F063797B" "WorkingFolder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" - "Icon" = "8:" + "Icon" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1" "Feature" = "8:" } "{970C0BB2-C7D0-45D7-ABFA-7EC378858BC0}:_5426797F4F7D48478759844D9558460B" @@ -393,7 +419,7 @@ "Target" = "8:_B7C31D1C4E42443D89CA87F9596A43B7" "Folder" = "8:_24D444A51FBD4D6AB659A544BB198230" "WorkingFolder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" - "Icon" = "8:" + "Icon" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1" "Feature" = "8:" } } @@ -797,7 +823,7 @@ { "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_5003B007B32D429B83CC5372AB9FC0AF" { - "SourcePath" = "8:..\\TimeControlConsole\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe" + "SourcePath" = "8:..\\TimeControlConsole\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" @@ -825,7 +851,7 @@ } "{5259A561-127C-4D43-A0A1-72F10C7B3BF8}:_B7C31D1C4E42443D89CA87F9596A43B7" { - "SourcePath" = "8:..\\TimeControl\\obj\\x64\\Release\\net6.0-windows10.0.22000.0\\apphost.exe" + "SourcePath" = "8:..\\TimeControl\\obj\\Debug\\net6.0-windows10.0.22000.0\\apphost.exe" "TargetName" = "8:" "Tag" = "8:" "Folder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5" diff --git a/TimeControl/App.cs b/TimeControl/App.cs index 78d21be..9c3e565 100644 --- a/TimeControl/App.cs +++ b/TimeControl/App.cs @@ -3,13 +3,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.IO; namespace TimeControl { public class App { - private string name; - private string location; + private readonly string name; public string Name { get { return name; }} internal int time; /// @@ -20,18 +20,20 @@ public override string ToString() { return Name + " 已使用 " + time+" 秒!"; } - public App(string name, string location) + public App(string name,int time) { + this.time = time; this.name = name; - this.location = location; - Reset(); } /// /// 运行一次(一秒) /// - public virtual void Run() + public virtual void Run(StreamWriter streamWriter) { time++; + streamWriter.WriteLine(Name); + streamWriter.WriteLine(time); + streamWriter.WriteLine("//"); } /// /// 重设时间 diff --git a/TimeControl/ListController.cs b/TimeControl/AppController.cs similarity index 57% rename from TimeControl/ListController.cs rename to TimeControl/AppController.cs index a8fea5a..ff69198 100644 --- a/TimeControl/ListController.cs +++ b/TimeControl/AppController.cs @@ -5,20 +5,61 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.IO; namespace TimeControl { - public class ListController + public class AppController { + private FileStream fileStream = new(TimeControlFile.TimeFileLocation, + FileMode.OpenOrCreate, + FileAccess.ReadWrite, FileShare.None); + private StreamWriter streamWriter; private ListBox listBox; private List apps; private Timer timer; - public ListController(ListBox listBox,Timer timer) + public AppController(ListBox listBox, Timer timer) { + streamWriter = new(fileStream); this.listBox = listBox; apps = new List(); this.timer = timer; + StreamReader streamReader = new(fileStream); + int lineNumber = 1; + string name = null; + int time = 0; + int timeLimit = 0; + while (!streamReader.EndOfStream)//读取文件,添加进程 + { + string line = streamReader.ReadLine(); + if (line == "//") + { + if (timeLimit == 0) + apps.Add(new App(name, time)); + else + apps.Add(new LimitedApp(name, time, timeLimit)); + + lineNumber = 1; + name = null; + time = 0; + timeLimit = 0; + + continue; + } + else + { + if (lineNumber == 1) + name = line; + else if (lineNumber == 2) + time = Convert.ToInt32(line); + else if (lineNumber == 3) + timeLimit = Convert.ToInt32(line); + + lineNumber++; + } + } + Refresh(); } /// @@ -46,7 +87,7 @@ public void AddByName(string name) { foreach (Process process in processes) { - apps.Add(new App(process.ProcessName, process.MainModule.FileName)); + apps.Add(new App(process.ProcessName, 0)); } } catch (Exception ex) @@ -60,7 +101,7 @@ public void AddByName(string name) /// /// 进程名称 /// 限制时长(秒) - public void AddByName(string name,int limitTime) + public void AddByName(string name, int limitTime) { timer.Stop(); Process[] processes = Process.GetProcessesByName(name); @@ -68,7 +109,7 @@ public void AddByName(string name,int limitTime) { foreach (Process process in processes) { - apps.Add(new LimitedApp(process.ProcessName, process.MainModule.FileName,limitTime)); + apps.Add(new LimitedApp(process.ProcessName, 0, limitTime)); } } catch (Exception ex) @@ -82,19 +123,21 @@ public void AddByName(string name,int limitTime) /// public void Run() { + fileStream.SetLength(0); foreach (App app in apps)//计算进程时间 { if (Process.GetProcessesByName(app.Name).Length != 0) { if (app is LimitedApp) { - LimitedApp limitedApp=app as LimitedApp; - limitedApp.Run(); + LimitedApp limitedApp = app as LimitedApp; + limitedApp.Run(streamWriter); } else - app.Run(); + app.Run(streamWriter); } } + streamWriter.Flush(); } /// /// 移除所列表所选的进程 @@ -106,5 +149,14 @@ public void Remove() apps.RemoveAt(listBox.SelectedIndex); Refresh(); } + /// + /// 删除所有监控 + /// + public void RemoveAll() + { + timer.Stop(); + apps.Clear(); + Refresh(); + } } } diff --git a/TimeControl/ControlPanel.Designer.cs b/TimeControl/ControlPanel.Designer.cs index a9ee2b8..48d7262 100644 --- a/TimeControl/ControlPanel.Designer.cs +++ b/TimeControl/ControlPanel.Designer.cs @@ -36,6 +36,7 @@ private void InitializeComponent() this.controlTab = new System.Windows.Forms.TabControl(); this.startNow = new System.Windows.Forms.TabPage(); this.processMonitor = new System.Windows.Forms.TabPage(); + this.autoRefreshBox = new System.Windows.Forms.CheckBox(); this.refreshButton = new System.Windows.Forms.Button(); this.processNameBox = new System.Windows.Forms.TextBox(); this.removeButton = new System.Windows.Forms.Button(); @@ -53,7 +54,7 @@ private void InitializeComponent() this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.ExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.processMonitorTimer = new System.Windows.Forms.Timer(this.components); - this.autoRefreshBox = new System.Windows.Forms.CheckBox(); + this.clearButton = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.timeBox)).BeginInit(); this.controlTab.SuspendLayout(); this.startNow.SuspendLayout(); @@ -121,6 +122,7 @@ private void InitializeComponent() // // processMonitor // + this.processMonitor.Controls.Add(this.clearButton); this.processMonitor.Controls.Add(this.autoRefreshBox); this.processMonitor.Controls.Add(this.refreshButton); this.processMonitor.Controls.Add(this.processNameBox); @@ -135,6 +137,16 @@ private void InitializeComponent() this.processMonitor.Text = "进程计时"; this.processMonitor.UseVisualStyleBackColor = true; // + // autoRefreshBox + // + this.autoRefreshBox.AutoSize = true; + this.autoRefreshBox.Location = new System.Drawing.Point(557, 78); + this.autoRefreshBox.Name = "autoRefreshBox"; + this.autoRefreshBox.Size = new System.Drawing.Size(91, 24); + this.autoRefreshBox.TabIndex = 6; + this.autoRefreshBox.Text = "自动刷新"; + this.autoRefreshBox.UseVisualStyleBackColor = true; + // // refreshButton // this.refreshButton.Location = new System.Drawing.Point(528, 156); @@ -292,15 +304,15 @@ private void InitializeComponent() this.processMonitorTimer.Interval = 1000; this.processMonitorTimer.Tick += new System.EventHandler(this.ProcessMonitorTimer_Tick); // - // autoRefreshBox + // clearButton // - this.autoRefreshBox.AutoSize = true; - this.autoRefreshBox.Location = new System.Drawing.Point(557, 78); - this.autoRefreshBox.Name = "autoRefreshBox"; - this.autoRefreshBox.Size = new System.Drawing.Size(91, 24); - this.autoRefreshBox.TabIndex = 6; - this.autoRefreshBox.Text = "自动刷新"; - this.autoRefreshBox.UseVisualStyleBackColor = true; + this.clearButton.Location = new System.Drawing.Point(528, 318); + this.clearButton.Name = "clearButton"; + this.clearButton.Size = new System.Drawing.Size(143, 45); + this.clearButton.TabIndex = 7; + this.clearButton.Text = "删除所有监控"; + this.clearButton.UseVisualStyleBackColor = true; + this.clearButton.Click += new System.EventHandler(this.ClearButton_Click); // // ControlPanel // @@ -355,5 +367,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox processNameBox; private System.Windows.Forms.Button refreshButton; private System.Windows.Forms.CheckBox autoRefreshBox; + private System.Windows.Forms.Button clearButton; } } \ No newline at end of file diff --git a/TimeControl/ControlPanel.cs b/TimeControl/ControlPanel.cs index 3ac9d65..5258c04 100644 --- a/TimeControl/ControlPanel.cs +++ b/TimeControl/ControlPanel.cs @@ -18,15 +18,15 @@ public partial class ControlPanel : Form { private bool hide = false;//指示启动后是否需要隐藏 private bool isClosable = false;//指示当前是否可以关闭 - private int unlockPasswordHash = 0;//密码哈希值,用作比对 - private ListController controller;//列表、计时控制器 + private string unlockPasswordHash = "";//密码哈希值,用作比对 + private AppController controller;//列表、计时控制器 public ControlPanel(bool hide) { InitializeComponent(); this.hide = hide; - if (File.Exists(PasswordFile.tcPassLocation))//加载密码哈希值 + if (File.Exists(TimeControlFile.PassLocation))//加载密码哈希值 { - unlockPasswordHash = Convert.ToInt32(File.ReadAllText(PasswordFile.tcPassLocation)); + unlockPasswordHash = File.ReadAllText(TimeControlFile.PassLocation); PasswordSet(); } controller = new(usageBox, processMonitorTimer); @@ -72,7 +72,7 @@ private void ControlPanel_FormClosing(object sender, FormClosingEventArgs e)// private void ExitToolStripMenuItem_Click(object sender, EventArgs e)//正常退出程序 { PasswordInput passwordInput = new(unlockPasswordHash); - if (unlockPasswordHash != 0)//检测是否设置了管理码 + if (!string.IsNullOrEmpty( unlockPasswordHash))//检测是否设置了管理码 { if (passwordInput.ShowDialog() == DialogResult.OK) ForceClose(); @@ -86,28 +86,24 @@ private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs Process.Start("explorer.exe", "https://icons8.com/icon/19614/icon"); } - private void AppAddButton_Click(object sender, EventArgs e)//添加打开的窗口 + private void AppAddButton_Click(object sender, EventArgs e)//添加进程 { if (processNameBox.Text.ToLower() == "timecontrol" || processNameBox.Text.ToLower() == "timecontrolconsole") { return; } - TimeInput timeInput = new(controller, processNameBox.Text); + TimeInput timeInput = new(controller, processNameBox.Text);//打开进程限时控制窗口 timeInput.ShowDialog(); } - private void RemoveButton_Click(object sender, EventArgs e)//移除所有的已添加窗口 + private void RemoveButton_Click(object sender, EventArgs e)//移除窗口 { //检测密码设置 - if (unlockPasswordHash != 0) + if (PasswordCheck()) { - PasswordInput passwordInput = new(unlockPasswordHash); - if (passwordInput.ShowDialog() == DialogResult.OK) - controller.Remove(); - } - else controller.Remove(); + } } private void RefreshButton_Click(object sender, EventArgs e)//重新获取所有软件所用时间 @@ -143,9 +139,10 @@ private void ControlPanel_Shown(object sender, EventArgs e)//启动隐藏参数 } private void UnloackPasswordSetButton_Click(object sender, EventArgs e)//保存密码 { - unlockPasswordHash = unlockPasswordBox.Text.GetHashCode();//保存哈希值 + + unlockPasswordHash = Password.ComputeHash( unlockPasswordBox.Text);//保存哈希值 + File.WriteAllText(TimeControlFile.PassLocation, unlockPasswordHash.ToString());//保存哈希值到文件 PasswordSet(); - File.WriteAllText(PasswordFile.tcPassLocation, unlockPasswordHash.ToString());//保存哈希值到文件 } private void PasswordSet()//密码设置后调用 { @@ -153,5 +150,26 @@ private void PasswordSet()//密码设置后调用 unlockPasswordBox.Enabled = false; unloackPasswordSetButton.Enabled = false; } + + private void ClearButton_Click(object sender, EventArgs e)//移除所有的已添加窗口 + { + if (PasswordCheck()) + { + controller.RemoveAll(); + } + } + private bool PasswordCheck()//检测密码是否正确 + { + if (!string.IsNullOrEmpty( unlockPasswordHash)) + { + PasswordInput passwordInput = new(unlockPasswordHash); + if (passwordInput.ShowDialog() == DialogResult.OK) + return true; + else + return false; + } + else + return true; + } } } diff --git a/TimeControl/LimitWarningWindow.Designer.cs b/TimeControl/LimitWarningWindow.Designer.cs index 5c0be9f..a008976 100644 --- a/TimeControl/LimitWarningWindow.Designer.cs +++ b/TimeControl/LimitWarningWindow.Designer.cs @@ -49,7 +49,7 @@ private void InitializeComponent() this.closeButton.TabIndex = 1; this.closeButton.Text = "立即强制关闭(请确保已保存任何文件)"; this.closeButton.UseVisualStyleBackColor = true; - this.closeButton.Click += new System.EventHandler(this.closeButton_Click); + this.closeButton.Click += new System.EventHandler(this.CloseButton_Click); // // LimitWarningWindow // diff --git a/TimeControl/LimitWarningWindow.cs b/TimeControl/LimitWarningWindow.cs index f83a31d..3a0e1fc 100644 --- a/TimeControl/LimitWarningWindow.cs +++ b/TimeControl/LimitWarningWindow.cs @@ -20,7 +20,7 @@ public LimitWarningWindow(LimitedApp warningApp) this.warningApp = warningApp; } - private void closeButton_Click(object sender, EventArgs e) + private void CloseButton_Click(object sender, EventArgs e) { warningApp.Ban();//禁用掉app Close(); diff --git a/TimeControl/LimitedApp.cs b/TimeControl/LimitedApp.cs index dcb72e3..7c25db7 100644 --- a/TimeControl/LimitedApp.cs +++ b/TimeControl/LimitedApp.cs @@ -5,22 +5,23 @@ using System.Threading.Tasks; using System.Diagnostics; using System.Windows.Forms; +using System.IO; namespace TimeControl { public class LimitedApp : App { - private int timeLimit; - public LimitedApp(string name, string location,int timeLimit) : base(name, location) + private readonly int timeLimit; + public LimitedApp(string name,int time,int timeLimit) : base(name,time) { this.timeLimit = timeLimit; } /// /// 运行一次(一秒),并根据情况显示警告或关闭进程 /// - public override void Run() + public override void Run(StreamWriter streamWriter) { - base.Run(); + time++; if (time == timeLimit - 30) { LimitWarningWindow warningWindow = new(this); @@ -30,6 +31,10 @@ public override void Run() { Ban(); } + streamWriter.WriteLine(Name); + streamWriter.WriteLine(time); + streamWriter.WriteLine(timeLimit); + streamWriter.WriteLine("//"); } /// /// 返回时间受限进程的简要概述 diff --git a/TimeControl/Lock.cs b/TimeControl/Lock.cs index 6f3143c..8f68d6c 100644 --- a/TimeControl/Lock.cs +++ b/TimeControl/Lock.cs @@ -14,12 +14,12 @@ namespace TimeControl public partial class Lock : Form { private bool usePassword = true; - private int unlockPasswordHash; - public Lock(int minutes,int unlockPasswordHash) + private string unlockPasswordHash; + public Lock(int minutes,string unlockPasswordHash) { InitializeComponent(); progressBar.Maximum = minutes * 60; - if(unlockPasswordHash==0) + if (string.IsNullOrEmpty(unlockPasswordHash)) { usePassword = false; } this.unlockPasswordHash = unlockPasswordHash; } @@ -53,7 +53,7 @@ private void UnlockButton_Click(object sender, EventArgs e) { if (usePassword == true) { - if (unlockPasswordBox.Text.GetHashCode() == unlockPasswordHash) + if (Password.ComputeHash(unlockPasswordBox.Text) == unlockPasswordHash) { progressBar.Value = progressBar.Maximum; Close(); diff --git a/TimeControl/Password.cs b/TimeControl/Password.cs new file mode 100644 index 0000000..a3bd7ee --- /dev/null +++ b/TimeControl/Password.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Security.Cryptography; + +namespace TimeControl +{ + internal static class Password + { + public static string ComputeHash(string str) + { + byte[] bytes = Encoding.UTF8.GetBytes(str); + MD5 md5 = MD5.Create(); + md5.ComputeHash(bytes); + return Encoding.UTF8.GetString(md5.ComputeHash(bytes)); + } + } +} diff --git a/TimeControl/PasswordFile.cs b/TimeControl/PasswordFile.cs deleted file mode 100644 index 3ab0fd1..0000000 --- a/TimeControl/PasswordFile.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TimeControl -{ - internal class PasswordFile - { - public static readonly string tcPassLocation = Environment.GetFolderPath - (Environment.SpecialFolder.ApplicationData) + "\\TCPass.txt";//获取密码位置 - } -} diff --git a/TimeControl/PasswordInput.Designer.cs b/TimeControl/PasswordInput.Designer.cs index ebc6285..40f4b99 100644 --- a/TimeControl/PasswordInput.Designer.cs +++ b/TimeControl/PasswordInput.Designer.cs @@ -48,7 +48,7 @@ private void InitializeComponent() this.okButton.TabIndex = 1; this.okButton.Text = "确认"; this.okButton.UseVisualStyleBackColor = true; - this.okButton.Click += new System.EventHandler(this.okButton_Click); + this.okButton.Click += new System.EventHandler(this.OkButton_Click); // // PasswordInput // diff --git a/TimeControl/PasswordInput.cs b/TimeControl/PasswordInput.cs index 6b68b77..78f714b 100644 --- a/TimeControl/PasswordInput.cs +++ b/TimeControl/PasswordInput.cs @@ -8,24 +8,26 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.IO; +using System.Security.Cryptography; namespace TimeControl { public partial class PasswordInput : Form { - private int passwordHash; - public PasswordInput(int passwordHash) + private string passwordHash; + public PasswordInput(string passwordHash) { InitializeComponent(); this.passwordHash = passwordHash; DialogResult = DialogResult.No; } - private void okButton_Click(object sender, EventArgs e) + private void OkButton_Click(object sender, EventArgs e) { - if (passwordTextBox.Text.GetHashCode()==passwordHash) + + if (Password.ComputeHash(passwordTextBox.Text)==passwordHash ) { - File.Delete(PasswordFile.tcPassLocation); + File.Delete(TimeControlFile.PassLocation); DialogResult = DialogResult.OK; Close(); } diff --git a/TimeControl/Program.cs b/TimeControl/Program.cs index 1403c74..5b3d2aa 100644 --- a/TimeControl/Program.cs +++ b/TimeControl/Program.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using System.Diagnostics; namespace TimeControl { @@ -22,6 +23,24 @@ static void Main(string[] args) hide = true; } } + Process[] processes = Process.GetProcessesByName("TimeControl"); + if (processes.Length > 1) + { + if (MessageBox.Show( + "ǰѾTimeControlʵǷҪ", + "ʾ", + MessageBoxButtons.OKCancel, + MessageBoxIcon.Information) == DialogResult.OK) + { + foreach (Process process in processes) + { + if (process.Id != Environment.ProcessId) + process.Kill(); + } + } + else + return; + } Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); diff --git a/TimeControl/TimeControl.csproj b/TimeControl/TimeControl.csproj index 7f10d86..ba01615 100644 --- a/TimeControl/TimeControl.csproj +++ b/TimeControl/TimeControl.csproj @@ -5,7 +5,7 @@ net6.0-windows10.0.22000.0 true SamHou - 3.1.1 + 3.1.3 TimeControl.Program False @@ -13,6 +13,7 @@ AnyCPU 7.0 AnyCPU;x64;x86 + False diff --git a/TimeControl/TimeControlFile.cs b/TimeControl/TimeControlFile.cs new file mode 100644 index 0000000..37e6e9a --- /dev/null +++ b/TimeControl/TimeControlFile.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TimeControl +{ + internal class TimeControlFile + { + public static readonly string PassLocation = Environment.GetFolderPath + (Environment.SpecialFolder.ApplicationData) + "\\TCPass.txt";//获取密码位置 + public static readonly string TimeFileLocation = Environment.GetFolderPath + (Environment.SpecialFolder.ApplicationData) + "\\TCTimeData.txt"; + } +} diff --git a/TimeControl/TimeInput.Designer.cs b/TimeControl/TimeInput.Designer.cs index b064ead..ac91dcf 100644 --- a/TimeControl/TimeInput.Designer.cs +++ b/TimeControl/TimeInput.Designer.cs @@ -51,7 +51,7 @@ private void InitializeComponent() this.okButton.TabIndex = 1; this.okButton.Text = "确定"; this.okButton.UseVisualStyleBackColor = true; - this.okButton.Click += new System.EventHandler(this.okButton_Click); + this.okButton.Click += new System.EventHandler(this.OkButton_Click); // // timeBox // diff --git a/TimeControl/TimeInput.cs b/TimeControl/TimeInput.cs index 1f208d5..887c11b 100644 --- a/TimeControl/TimeInput.cs +++ b/TimeControl/TimeInput.cs @@ -12,24 +12,29 @@ namespace TimeControl { public partial class TimeInput : Form { - private ListController listController; - private string appName; - public TimeInput(ListController listController,string appName) + private AppController appController; + private readonly string appName; + /// + /// 创建一个新的输入窗口,并添加进程 + /// + /// 进程列表控制器,用于添加进程 + /// 需要添加进程的名称 + public TimeInput(AppController appController, string appName) { InitializeComponent(); - this.listController = listController; + this.appController = appController; this.appName = appName; } - private void okButton_Click(object sender, EventArgs e) + private void OkButton_Click(object sender, EventArgs e) { - if (timeBox.Value==0) + if (timeBox.Value == 0) { - listController.AddByName(appName); + appController.AddByName(appName); } else { - listController.AddByName(appName,Convert.ToInt32( timeBox.Value)); + appController.AddByName(appName, Convert.ToInt32(timeBox.Value)); } Close(); }