懒人记时 代码仓库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

165 righe
5.1 KiB

  1. 
  2. using AppTime.Properties;
  3. using Microsoft.Win32;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Data.OleDb;
  9. using System.Diagnostics;
  10. using System.Drawing;
  11. using System.Drawing.Imaging;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Runtime.InteropServices;
  15. using System.Security.AccessControl;
  16. using System.Text;
  17. using System.Web.ModelBinding;
  18. using System.Web.UI.WebControls;
  19. using System.Windows.Forms;
  20. namespace AppTime
  21. {
  22. public partial class FrmMain : Form
  23. {
  24. const string appname = "AppTime";
  25. const string regkey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
  26. public FrmMain()
  27. {
  28. InitializeComponent();
  29. }
  30. private void FrmMain_Load(object sender, EventArgs e)
  31. {
  32. cboRecordScreen.DataSource = new[] {
  33. new {Text="最近30天", Value=30},
  34. new {Text="最近15天", Value=15},
  35. new {Text="无限制", Value=int.MaxValue},
  36. new {Text="不留存", Value=0},
  37. };
  38. cboRecordScreen.DisplayMember = "Text";
  39. cboRecordScreen.ValueMember = "Value";
  40. cboImageQuality.DataSource = new[] {
  41. new {Text="最省磁盘", Value=63},
  42. new {Text="均衡", Value=50},
  43. new {Text="高质量", Value=40},
  44. };
  45. cboImageQuality.DisplayMember = "Text";
  46. cboImageQuality.ValueMember = "Value";
  47. }
  48. private void btnOpen_Click(object sender, EventArgs e)
  49. {
  50. Process.Start($@"http://localhost:{Program.Port}/");
  51. }
  52. private void notifyIcon_DoubleClick(object sender, EventArgs e)
  53. {
  54. btnOpen_Click(null, null);
  55. }
  56. private void btnCancel_Click(object sender, EventArgs e)
  57. {
  58. this.Hide();
  59. }
  60. bool cancelClose = true;
  61. private void btnExit_Click(object sender, EventArgs e)
  62. {
  63. this.Hide();
  64. cancelClose = false;
  65. Program.recorder.FlushScreenBuffer();
  66. this.Close();
  67. }
  68. private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
  69. {
  70. this.Hide();
  71. e.Cancel = cancelClose;
  72. }
  73. private void btnOK_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. Directory.CreateDirectory(txtDataPath.Text);
  78. Settings.Default.DataPath = txtDataPath.Text == Application.StartupPath ? "" : txtDataPath.Text;
  79. Program.recorder.BuildDataPath();
  80. }
  81. catch
  82. {
  83. MessageBox.Show("数据存储位置无效,请重新选择。");
  84. }
  85. Settings.Default.ImageQuality = (int) cboImageQuality.SelectedValue;
  86. Settings.Default.RecordScreenDays = (int)cboRecordScreen.SelectedValue;
  87. Settings.Default.Save();
  88. using var reg = Registry.CurrentUser.CreateSubKey(regkey);
  89. try
  90. {
  91. if (chkAutoRun.Checked)
  92. {
  93. reg.SetValue(appname, Application.ExecutablePath);
  94. }
  95. else
  96. {
  97. reg.DeleteValue(appname);
  98. }
  99. }
  100. catch (UnauthorizedAccessException)
  101. {
  102. MessageBox.Show("设置启动失败,请检查:\r\n\r\n1、关闭杀毒软件(如360等);\r\n2、以管理员身份运行本程序。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  103. }
  104. this.Hide();
  105. }
  106. private void FrmMain_Shown(object sender, EventArgs e)
  107. {
  108. this.Hide();
  109. }
  110. private void btnSetting_Click(object sender, EventArgs e)
  111. {
  112. if (!this.Visible)
  113. {
  114. if (string.IsNullOrEmpty(Settings.Default.DataPath))
  115. {
  116. txtDataPath.Text = Application.StartupPath;
  117. }
  118. else
  119. {
  120. txtDataPath.Text = Settings.Default.DataPath;
  121. }
  122. cboRecordScreen.SelectedValue = Settings.Default.RecordScreenDays;
  123. cboImageQuality.SelectedValue = Settings.Default.ImageQuality;
  124. using var reg = Registry.CurrentUser.CreateSubKey(regkey);
  125. chkAutoRun.Checked = (reg.GetValue(appname) as string) == Application.ExecutablePath;
  126. this.Show();
  127. }
  128. }
  129. private void btnAbout_Click(object sender, EventArgs e)
  130. {
  131. MessageBox.Show($"AppTime桌面时间管理\r\nV{Application.ProductVersion}\r\n\r\n联系作者:newdraw@hotmail.com", "关于", MessageBoxButtons.OK, MessageBoxIcon.Information);
  132. }
  133. private void btnDataPath_Click(object sender, EventArgs e)
  134. {
  135. using var dlg = new FolderBrowserDialog();
  136. if(dlg.ShowDialog()== DialogResult.OK)
  137. {
  138. txtDataPath.Text = dlg.SelectedPath;
  139. }
  140. }
  141. }
  142. }