RegisterForm.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.IO;
  3. using System.Runtime.Serialization;
  4. using System.Runtime.Serialization.Formatters.Binary;
  5. using System.Windows.Forms;
  6. namespace felixyin
  7. {
  8. public partial class RegisterForm : Form
  9. {
  10. public RegisterForm()
  11. {
  12. InitializeComponent();
  13. SoftReg sr = new SoftReg();
  14. string rnum = sr.getRNum();
  15. this.keyTextBox.Text = rnum;
  16. }
  17. private void copyKeyBtn_Click(object sender, EventArgs e)
  18. {
  19. Clipboard.SetDataObject(this.keyTextBox.Text.Trim());
  20. MessageBox.Show("复制成功");
  21. }
  22. private void serialTextBox_TextChanged(object sender, EventArgs e)
  23. {
  24. if (this.serialTextBox.Text.Trim() != "")
  25. {
  26. this.registerBtn.Enabled = true;
  27. }
  28. }
  29. private void registerBtn_Click(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. this.registerBtn.Enabled = false;
  34. SoftReg sr = new SoftReg();
  35. string auth_code_by_textbox = this.serialTextBox.Text.Trim();
  36. string auth_code = sr.MD5Encrypt(sr.getRNum());
  37. if(auth_code_by_textbox == "")
  38. {
  39. DialogResult result = MessageBox.Show("请输入序列号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  40. if (result == DialogResult.OK)
  41. {
  42. }
  43. this.registerBtn.Enabled = true;
  44. return;
  45. }
  46. if(auth_code_by_textbox == auth_code)
  47. {
  48. string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
  49. Environment.OSVersion.Platform == PlatformID.MacOSX)
  50. ? Environment.GetEnvironmentVariable("HOME")
  51. : Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
  52. FileStream saveFile = new FileStream(homePath + "/.ap_serial", FileMode.Create, FileAccess.ReadWrite);
  53. string write_str = sr.MD5Encrypt(auth_code_by_textbox);
  54. IFormatter serializer = new BinaryFormatter();
  55. serializer.Serialize(saveFile, write_str);
  56. saveFile.Close();
  57. DialogResult result = MessageBox.Show("激活成功,请重新打开应用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  58. if (result == DialogResult.OK)
  59. {
  60. this.Close();
  61. System.Environment.Exit(0);
  62. }
  63. }
  64. else
  65. {
  66. DialogResult result = MessageBox.Show("激活失败,请重新输入序列号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  67. if (result == DialogResult.OK)
  68. {
  69. this.serialTextBox.Text = "";
  70. this.registerBtn.Enabled = true;
  71. }
  72. }
  73. }
  74. catch (IOException ee)
  75. {
  76. throw ee;
  77. DialogResult result = MessageBox.Show("激活时发生严重错误,请重启电脑后,重新激活!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  78. if (result == DialogResult.OK)
  79. {
  80. this.Close();
  81. System.Environment.Exit(0);
  82. }
  83. }
  84. }
  85. }
  86. }