Form1.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using Microsoft.Toolkit.Uwp.Notifications;
  2. using System;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Windows.Forms;
  6. using 新一代CaptB点名器.Properties;
  7. namespace 新一代CaptB点名器
  8. {
  9. public partial class Form1 : Form
  10. {
  11. public Form1(string paths)
  12. {
  13. if (paths != null)
  14. {
  15. if (MessageBox.Show("是否导入此名单?", "打开名单文件", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  16. {
  17. Program.Import(paths);
  18. }
  19. }
  20. try
  21. {
  22. if (!File.Exists(Program.ProgramDatadirectoryPath))
  23. {
  24. Directory.CreateDirectory(Program.ProgramDatadirectoryPath);
  25. }
  26. }
  27. catch (Exception e)
  28. {
  29. MessageBox.Show(e.Message + Resources.ExRe_Reinstall, "Err", MessageBoxButtons.OK, MessageBoxIcon.Error);
  30. }
  31. InitializeComponent();
  32. if (Program.called_name == string.Empty)
  33. {
  34. button1.Text = Settings.Default.InitialWord;
  35. }
  36. else
  37. {
  38. button1.Text = Program.called_name;
  39. }
  40. if (Settings.Default.doCheckUpdate)
  41. {
  42. if (Settings.Default.LastestUpdateCheckTime != DateTime.Now.Date)
  43. {
  44. Process checkupdate = new Process();
  45. checkupdate.StartInfo.FileName = Application.StartupPath + @"\CBRC_Update.exe";
  46. try
  47. {
  48. checkupdate.Start();
  49. Settings.Default.LastestUpdateCheckTime = DateTime.Now.Date;
  50. Settings.Default.Save();
  51. }
  52. catch (Exception ex)
  53. {
  54. Settings.Default.LastestUpdateCheckTime = DateTime.Now.Date;
  55. Settings.Default.Save();
  56. notifyIcon1.ShowBalloonTip(1000, Resources.UpdateErrToastTitle, ex.Message + Resources.ExRe_Reinstall, ToolTipIcon.Error);
  57. }
  58. }
  59. }
  60. if (Program.called_num == 0)
  61. {
  62. if (File.Exists(Program.cbcfpath))
  63. {
  64. if (File.Exists(Program.cfpath))
  65. {
  66. try
  67. {
  68. string[] strings = File.ReadAllLines(Program.cfpath);
  69. int.TryParse(strings[0], out Program.num);
  70. Settings.Default.编辑名单_Enabled = true;
  71. Settings.Default.导出名单_Enabled = true;
  72. Settings.Default.完整名单_Enabled = true;
  73. Settings.Default.未点名单_Enabled = true;
  74. Settings.Default.Save();
  75. 编辑名单BToolStripMenuItem.Enabled = true;
  76. 导出名单CToolStripMenuItem.Enabled = true;
  77. 完整名单ToolStripMenuItem.Enabled = true;
  78. 未点名单ToolStripMenuItem.Enabled = true;
  79. }
  80. catch (Exception e)
  81. {
  82. MessageBox.Show(e.Message + "\n" + Resources.ExRe_RR, Resources.StartupErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  83. }
  84. }
  85. try
  86. {
  87. File.Copy(Program.cbcfpath, Program.cfpath, true);
  88. }
  89. catch (Exception ex)
  90. {
  91. MessageBox.Show(ex.Message + "\n" + Resources.ExRe_ReImport, Resources.ExitErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  92. }
  93. }
  94. else
  95. {
  96. Settings.Default.编辑名单_Enabled = false;
  97. Settings.Default.导出名单_Enabled = false;
  98. Settings.Default.完整名单_Enabled = false;
  99. Settings.Default.未点名单_Enabled = false;
  100. Settings.Default.Save();
  101. 编辑名单BToolStripMenuItem.Enabled = false;
  102. 导出名单CToolStripMenuItem.Enabled = false;
  103. 完整名单ToolStripMenuItem.Enabled = false;
  104. 未点名单ToolStripMenuItem.Enabled = false;
  105. }
  106. }
  107. ActiveControl = button2;
  108. }
  109. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  110. {
  111. if (Settings.Default.doExitConfirm)
  112. {
  113. if (MessageBox.Show(Resources.ExitContent, Resources.ExitCTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
  114. {
  115. if (File.Exists(Program.cfpath))
  116. {
  117. try
  118. {
  119. File.Delete(Program.cfpath);
  120. }
  121. catch (Exception ex)
  122. {
  123. MessageBox.Show(ex.Message, Resources.ExitErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  124. }
  125. }
  126. if (File.Exists(Program.cbcfpath))
  127. {
  128. try
  129. {
  130. File.Copy(Program.cbcfpath, Program.cfpath, true);
  131. }
  132. catch (Exception ex)
  133. {
  134. MessageBox.Show(ex.Message, Resources.ExitErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  135. }
  136. }
  137. ToastNotificationManagerCompat.Uninstall();
  138. Environment.Exit(0);
  139. }
  140. else
  141. {
  142. e.Cancel = true;
  143. }
  144. }
  145. else
  146. {
  147. ToastNotificationManagerCompat.Uninstall();
  148. Environment.Exit(0);
  149. }
  150. }
  151. private void 导入名单AToolStripMenuItem_Click(object sender, EventArgs e)
  152. {
  153. Program.Reset();
  154. OpenFileDialog openFileDialog = new OpenFileDialog
  155. {
  156. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer),
  157. Filter = "支持的文件类型(*.cbcf,*.txt)|*.cbcf;*.txt|所有文件(*.*)|*.*",
  158. FilterIndex = 1,
  159. Multiselect = false,
  160. RestoreDirectory = true,
  161. Title = Resources.OpenFileDialogTitle
  162. };
  163. if (openFileDialog.ShowDialog() == DialogResult.OK)
  164. Program.Import(openFileDialog.FileName);
  165. Settings.Default.编辑名单_Enabled = true;
  166. Settings.Default.导出名单_Enabled = true;
  167. Settings.Default.完整名单_Enabled = true;
  168. Settings.Default.未点名单_Enabled = true;
  169. Settings.Default.Save();
  170. 编辑名单BToolStripMenuItem.Enabled = true;
  171. 导出名单CToolStripMenuItem.Enabled = true;
  172. 完整名单ToolStripMenuItem.Enabled = true;
  173. 未点名单ToolStripMenuItem.Enabled = true;
  174. button1.Text = Settings.Default.InitialWord; ;
  175. }
  176. private void 导出名单CToolStripMenuItem_Click(object sender, EventArgs e)
  177. {
  178. Program.Save();
  179. }
  180. private void 退出CaptB点名器ToolStripMenuItem_Click(object sender, EventArgs e)
  181. {
  182. if (Settings.Default.doExitConfirm)
  183. {
  184. if (MessageBox.Show(Resources.ExitContent, Resources.ExitCTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
  185. {
  186. if (File.Exists(Program.cfpath))
  187. {
  188. try
  189. {
  190. File.Delete(Program.cfpath);
  191. }
  192. catch (Exception ex)
  193. {
  194. MessageBox.Show(ex.Message, Resources.ExitErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  195. }
  196. }
  197. if (File.Exists(Program.cbcfpath))
  198. {
  199. try
  200. {
  201. File.Copy(Program.cbcfpath, Program.cfpath, true);
  202. }
  203. catch (Exception ex)
  204. {
  205. MessageBox.Show(ex.Message, Resources.ExitErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  206. }
  207. }
  208. ToastNotificationManagerCompat.Uninstall();
  209. Environment.Exit(0);
  210. }
  211. }
  212. else
  213. {
  214. ToastNotificationManagerCompat.Uninstall();
  215. Environment.Exit(0);
  216. }
  217. }
  218. private void 完整名单ToolStripMenuItem_Click(object sender, EventArgs e)
  219. {
  220. Settings.Default.Content = true;
  221. Settings.Default.Save();
  222. new Content().Show();
  223. }
  224. private void 未点名单ToolStripMenuItem_Click(object sender, EventArgs e)
  225. {
  226. Settings.Default.Content = false;
  227. Settings.Default.Save();
  228. new Content().Show();
  229. }
  230. private void 入门GToolStripMenuItem_Click(object sender, EventArgs e)
  231. {
  232. Process.Start("https://dev.lykns.tk/CBRC/publish/Gettingstarted");
  233. }
  234. private void 新增功能WToolStripMenuItem_Click(object sender, EventArgs e)
  235. {
  236. Process.Start("https://dev.lykns.tk/CBRC/publish/newfeatures");
  237. }
  238. private void 报告问题ToolStripMenuItem_Click(object sender, EventArgs e)
  239. {
  240. Process.Start("https://eow.lykns.tk/connect/feedback");
  241. }
  242. private void 建议功能LToolStripMenuItem_Click(object sender, EventArgs e)
  243. {
  244. Process.Start("https://eow.lykns.tk/connect/SubmitSuggestions");
  245. }
  246. private void 检查更新LToolStripMenuItem_Click(object sender, EventArgs e)
  247. {
  248. Process checkupdate = new Process();
  249. checkupdate.StartInfo.FileName = Application.StartupPath + @"\CBRC_Update.exe";
  250. try
  251. {
  252. checkupdate.Start();
  253. Settings.Default.LastestUpdateCheckTime = DateTime.Now.Date;
  254. Settings.Default.Save();
  255. }
  256. catch (Exception ex)
  257. {
  258. notifyIcon1.ShowBalloonTip(1000, Resources.UpdateErrToastTitle, ex.Message + Resources.ExRe_Reinstall, ToolTipIcon.Error);
  259. }
  260. }
  261. private void 技术支持TToolStripMenuItem_Click(object sender, EventArgs e)
  262. {
  263. Process.Start("https://eow.lykns.tk/connect");
  264. }
  265. private void 隐私政策PToolStripMenuItem_Click(object sender, EventArgs e)
  266. {
  267. Process.Start("https://eow.lykns.tk/Privacy");
  268. }
  269. private void 关于CaptB点名器ToolStripMenuItem1_Click(object sender, EventArgs e)
  270. {
  271. new AboutBox1().Show();
  272. }
  273. private void 首选项PToolStripMenuItem_Click(object sender, EventArgs e)
  274. {
  275. new Setting().ShowDialog();
  276. }
  277. private void button2_Click(object sender, EventArgs e)
  278. {
  279. Program.call();
  280. button1.Text = Program.called_name;
  281. ActiveControl = button2;
  282. }
  283. private void button3_Click(object sender, EventArgs e)
  284. {
  285. Program.Reset();
  286. button1.Text = Settings.Default.InitialWord;
  287. ActiveControl = button2;
  288. }
  289. private void button4_Click(object sender, EventArgs e)
  290. {
  291. Hide();
  292. new Form2().ShowDialog();
  293. ActiveControl = button2;
  294. }
  295. private void button1_Click(object sender, EventArgs e)
  296. {
  297. ActiveControl = button2;
  298. }
  299. private void 编辑名单BToolStripMenuItem_Click(object sender, EventArgs e)
  300. {
  301. notifyIcon1.ShowBalloonTip(1000, "此功能暂未开放", "名单编辑功能仍在开发中,敬请期待!", ToolTipIcon.Warning);
  302. }
  303. private void 复制当前值ToolStripMenuItem_Click(object sender, EventArgs e)
  304. {
  305. Clipboard.SetText(button1.Text);
  306. }
  307. private void 删除名单ToolStripMenuItem_Click(object sender, EventArgs e)
  308. {
  309. try
  310. {
  311. Program.Reset();
  312. if (File.Exists(Program.cfpath))
  313. File.Delete(Program.cfpath);
  314. if (File.Exists(Program.cbcfpath))
  315. File.Delete(Program.cbcfpath);
  316. Settings.Default.编辑名单_Enabled = false;
  317. Settings.Default.导出名单_Enabled = false;
  318. Settings.Default.完整名单_Enabled = false;
  319. Settings.Default.未点名单_Enabled = false;
  320. Settings.Default.Save();
  321. 编辑名单BToolStripMenuItem.Enabled = false;
  322. 导出名单CToolStripMenuItem.Enabled = false;
  323. 完整名单ToolStripMenuItem.Enabled = false;
  324. 未点名单ToolStripMenuItem.Enabled = false;
  325. notifyIcon1.ShowBalloonTip(1000, Resources.DelToastTitle, Resources.DelToastContent, ToolTipIcon.Info);
  326. }
  327. catch (Exception ex)
  328. {
  329. MessageBox.Show(ex.Message + "\n" + Resources.ExRe_ReImport, Resources.DelErrTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
  330. }
  331. }
  332. }
  333. }