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
42 changes: 34 additions & 8 deletions TCSetup/TCSetup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
}
"Entry"
{
"MsmKey" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_B7C31D1C4E42443D89CA87F9596A43B7"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
Expand Down Expand Up @@ -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"
{
Expand Down Expand Up @@ -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:"
Expand All @@ -201,7 +227,7 @@
"Keywords" = "8:"
"ARPCOMMENTS" = "8:TimeControl安装程序"
"ARPURLINFOABOUT" = "8:"
"ARPPRODUCTICON" = "8:"
"ARPPRODUCTICON" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
"ARPIconIndex" = "3:0"
"SearchPath" = "8:"
"UseSystemSearchPath" = "11:TRUE"
Expand Down Expand Up @@ -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"
Expand All @@ -393,7 +419,7 @@
"Target" = "8:_B7C31D1C4E42443D89CA87F9596A43B7"
"Folder" = "8:_24D444A51FBD4D6AB659A544BB198230"
"WorkingFolder" = "8:_57FF55C0487B4507A7ADC64F8E5966A5"
"Icon" = "8:"
"Icon" = "8:_9BF8F60AD5F2474D82994CD2D95F44A1"
"Feature" = "8:"
}
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions TimeControl/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/// <summary>
Expand All @@ -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();
}
/// <summary>
/// 运行一次(一秒)
/// </summary>
public virtual void Run()
public virtual void Run(StreamWriter streamWriter)
{
time++;
streamWriter.WriteLine(Name);
streamWriter.WriteLine(time);
streamWriter.WriteLine("//");
}
/// <summary>
/// 重设时间
Expand Down
68 changes: 60 additions & 8 deletions TimeControl/ListController.cs → TimeControl/AppController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<App> 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<App>();
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();
}

/// <summary>
Expand Down Expand Up @@ -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)
Expand All @@ -60,15 +101,15 @@ public void AddByName(string name)
/// </summary>
/// <param name="name">进程名称</param>
/// <param name="limitTime">限制时长(秒)</param>
public void AddByName(string name,int limitTime)
public void AddByName(string name, int limitTime)
{
timer.Stop();
Process[] processes = Process.GetProcessesByName(name);
try
{
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)
Expand All @@ -82,19 +123,21 @@ public void AddByName(string name,int limitTime)
/// </summary>
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();
}
/// <summary>
/// 移除所列表所选的进程
Expand All @@ -106,5 +149,14 @@ public void Remove()
apps.RemoveAt(listBox.SelectedIndex);
Refresh();
}
/// <summary>
/// 删除所有监控
/// </summary>
public void RemoveAll()
{
timer.Stop();
apps.Clear();
Refresh();
}
}
}
31 changes: 22 additions & 9 deletions TimeControl/ControlPanel.Designer.cs

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

Loading