Program.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. using System.Runtime.Serialization.Formatters.Binary;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace felixyin
  10. {
  11. static class Program
  12. {
  13. /// <summary>
  14. /// 应用程序的主入口点。
  15. /// </summary>
  16. [STAThread]
  17. static void Main()
  18. {
  19. Application.EnableVisualStyles();
  20. Application.SetCompatibleTextRenderingDefault(false);
  21. //用于序列化和反序列化的对象
  22. IFormatter serializer = new BinaryFormatter();
  23. bool isRegister = false;
  24. //反序列化
  25. try
  26. {
  27. string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
  28. Environment.OSVersion.Platform == PlatformID.MacOSX)
  29. ? Environment.GetEnvironmentVariable("HOME")
  30. : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
  31. if (File.Exists(homePath+"/.ap_serial"))
  32. {
  33. FileStream loadFile = new FileStream(homePath + "/.ap_serial", FileMode.Open, FileAccess.Read);
  34. string auth_code_by_file = serializer.Deserialize(loadFile) as string;
  35. loadFile.Close();
  36. SoftReg sr = new SoftReg();
  37. string serialText = sr.getRNum();
  38. string auth_code = sr.MD5Encrypt(sr.MD5Encrypt(serialText));
  39. isRegister = auth_code_by_file == auth_code;
  40. }
  41. else
  42. {
  43. isRegister = false;
  44. }
  45. }
  46. catch (FileNotFoundException e)
  47. {
  48. isRegister = false;
  49. }
  50. if (isRegister)
  51. {
  52. MainForm mainForm = new MainForm();
  53. Application.Run(mainForm);
  54. }
  55. else// 如果没有注册,则弹出注册对话框
  56. {
  57. RegisterForm mainForm = new RegisterForm();
  58. Application.Run(mainForm);
  59. }
  60. }
  61. }
  62. }