Login.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using CCWin;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.SQLite;
  7. using System.IO;
  8. using System.Net;
  9. using System.Net.Security;
  10. using System.Security.Cryptography.X509Certificates;
  11. using System.Text;
  12. using System.Windows.Forms;
  13. namespace MOKA_Factory_Tools
  14. {
  15. public partial class login : Skin_Color
  16. {
  17. public int enable;
  18. string path = AppDomain.CurrentDomain.BaseDirectory;
  19. LoginOutput loginOutput1 = new LoginOutput()
  20. {
  21. factoryname = "",
  22. factorynum = ""
  23. };
  24. string ErrorDBPath = AppDomain.CurrentDomain.BaseDirectory + "\\Error.db";
  25. SQLiteConnection ErrorDB = null;
  26. public login()
  27. {
  28. InitializeComponent();
  29. AccountText.Focus();
  30. CommonMethod.CreateDirectory(path + "\\download");
  31. CommonMethod.CreateDirectory(path + "\\Keys");
  32. CommonMethod.CreateDirectory(path + "\\Keys\\Demo");
  33. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\CIKEY");
  34. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\DeviceID");
  35. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\ESN");
  36. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\HDCPKEY");
  37. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\HDCPKEY22");
  38. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\MAC");
  39. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\Widevine");
  40. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\WiDi");
  41. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\Attestation");
  42. CommonMethod.CreateDirectory(path + "\\Keys\\Demo\\MGK");
  43. if (!File.Exists(ErrorDBPath))
  44. {
  45. if (SQLiteHelper.NewDbFile(ErrorDBPath))
  46. {
  47. SQLiteHelper.NewTable(ErrorDBPath, "ErrorReport", "(ID INTEGER PRIMARY KEY AUTOINCREMENT,url varchar,content varvhar,gener_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),report_date DATETIME)");
  48. SQLiteHelper.NewTable(ErrorDBPath, "CopyDelayReport", "(ID INTEGER PRIMARY KEY AUTOINCREMENT,bid varchar,url varchar,content varvhar,copy_date DATETIME DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime')),report_date DATETIME)");
  49. SQLiteHelper.NewTable(ErrorDBPath, "ProductionCount", "(bid varchar,count varchar)");
  50. }
  51. }
  52. if (ErrorDB == null)
  53. {
  54. ErrorDB = new SQLiteConnection("data source=" + ErrorDBPath);
  55. ErrorDB.Open();
  56. }
  57. getTestModeInfo();
  58. }
  59. private void getTestModeInfo()
  60. {
  61. // 读取win.ini或注册表;
  62. StringBuilder MyString = new StringBuilder(256);
  63. CommonMethod.GetProfileString("MOKAFactoryTools", "TestMode", "0", MyString, 256);
  64. if (MyString.ToString().Equals("1"))
  65. {
  66. TestMode.testMode = true;
  67. TestMode.SetTestMode(true);
  68. // 开启了测试模式;
  69. CommonMethod.GetProfileString("MOKAFactoryTools", "VirMAC", "B0-00-00-00-00-0B", MyString, 256);
  70. if (MyString.ToString().Equals("B0-00-00-00-00-0B"))
  71. {// 惠州工厂;
  72. AccountText.Text = "Huizhou";
  73. PwdText.Text = "admin";
  74. }
  75. else if (MyString.ToString().Equals("A0-00-00-00-00-0A"))
  76. {// 三华工厂;
  77. AccountText.Text = "SanHua";
  78. PwdText.Text = "admin";
  79. }
  80. else if (MyString.ToString().Equals("C0-00-00-00-00-0C"))
  81. {// 泰霖工厂;
  82. AccountText.Text = "Talent";
  83. PwdText.Text = "admin";
  84. }
  85. TestMode.MAC = MyString.ToString();
  86. JObject jObject;
  87. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  88. {
  89. using (JsonTextReader reader = new JsonTextReader(file))
  90. {
  91. jObject = (JObject)JToken.ReadFrom(reader);
  92. reader.Close();
  93. jObject["FactoryName"] = AccountText.Text;
  94. }
  95. }
  96. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  97. {
  98. writer.Write(jObject.ToString());
  99. }
  100. }
  101. else
  102. {
  103. TestMode.testMode = false;
  104. TestMode.SetTestMode();
  105. TestMode.MAC = CommonMethod.GetMacAddress();
  106. }
  107. }
  108. private void OnBtnLogin(object sender, EventArgs e)
  109. {
  110. if (PwdText.Text == "zhangyi" && AccountText.Text == "zhangyi")
  111. enable = 1;
  112. else if (PwdText.Text == "offline" && AccountText.Text == "offline")
  113. enable = 3;
  114. else if (PwdText.Text.Trim().Length > 0 && AccountText.Text.Trim().Length > 0)
  115. {
  116. if (CommonMethod.UserLogin(TestMode.loginUrl, AccountText.Text, PwdText.Text, TestMode.MAC, ErrorDB,out loginOutput1))
  117. {
  118. enable = 0;
  119. JObject jObject;
  120. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  121. {
  122. using (JsonTextReader reader = new JsonTextReader(file))
  123. {
  124. jObject = (JObject)JToken.ReadFrom(reader);
  125. reader.Close();
  126. jObject["FactoryName"] = loginOutput1.factoryname;
  127. jObject["FactoryNum"] = loginOutput1.factorynum;
  128. }
  129. }
  130. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  131. {
  132. writer.Write(jObject.ToString());
  133. }
  134. }
  135. else
  136. {
  137. MessageBox.Show(LResource.LoginFail + "\r\n" + loginOutput1.msg);
  138. return;
  139. }
  140. }
  141. else
  142. {
  143. enable = 2;
  144. }
  145. CommonMethod.FactoryName = loginOutput1.factoryname;
  146. UpgradeMsgList upgradeMsgList = new UpgradeMsgList();
  147. var FactoryNum = loginOutput1.factorynum;
  148. if(FactoryNum.Length>0)
  149. {
  150. try
  151. {
  152. if (CommonMethod.UpgradeCheck(TestMode.upgradeUrl, FactoryNum, ErrorDB, out upgradeMsgList))
  153. {
  154. if (CommonMethod.CompareVersion(upgradeMsgList.upgrade.version, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()))
  155. {
  156. Upgrade upgrade = new Upgrade(ErrorDB, upgradeMsgList.upgrade.fileurl, loginOutput1.factorynum);
  157. upgrade.Show();
  158. }
  159. else
  160. {
  161. ErrorDB.Close();
  162. ErrorDB.Dispose();
  163. Main form1 = new Main(enable);
  164. form1.Show();
  165. this.Hide();
  166. }
  167. }
  168. else
  169. {
  170. MessageBox.Show(LResource.UpgradeCheckFail);
  171. ErrorDB.Close();
  172. ErrorDB.Dispose();
  173. Main form1 = new Main(enable);
  174. form1.Show();
  175. this.Hide();
  176. }
  177. }
  178. catch (Exception ex)
  179. {
  180. MessageBox.Show(ServicePointManager.SecurityProtocol.ToString());
  181. MessageBox.Show(ex.Message);
  182. MessageBox.Show(LResource.UpgradeCheckFail);
  183. ErrorDB.Close();
  184. ErrorDB.Dispose();
  185. Main form1 = new Main(enable);
  186. form1.Show();
  187. this.Hide();
  188. }
  189. }
  190. else
  191. {
  192. ErrorDB.Close();
  193. ErrorDB.Dispose();
  194. MessageBox.Show(LResource.PleaseLogin);
  195. Main form1 = new Main(enable);
  196. form1.Show();
  197. this.Hide();
  198. }
  199. }
  200. public string format(uint data,uint length)
  201. {
  202. return String.Format("{0:D" + length.ToString() + "}", data);
  203. }
  204. private void login_Load(object sender, EventArgs e)
  205. {
  206. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  207. {
  208. using (JsonTextReader reader = new JsonTextReader(file))
  209. {
  210. JObject jObject = (JObject)JToken.ReadFrom(reader);
  211. reader.Close();
  212. AccountText.Text = jObject["FactoryName"] == null ? (!CommonMethod.AddJsonConfig("FactoryName", null) ? "" : "") : jObject["FactoryName"].Value<string>();
  213. loginOutput1.factoryname = jObject["FactoryName"] == null ? "" : jObject["FactoryName"].Value<string>();
  214. loginOutput1.factorynum=jObject["FactoryNum"] == null ? "" : jObject["FactoryNum"].Value<string>();
  215. }
  216. }
  217. System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName("SCBC Factory Tools");//获取指定的进程名
  218. if (myProcesses.Length > 1)
  219. {
  220. MessageBox.Show(LResource.AlreadyRun);
  221. Application.Exit();
  222. }
  223. System.Diagnostics.Process[] myProcesses2 = System.Diagnostics.Process.GetProcessesByName("MOKA Factory Tools");//获取指定的进程名
  224. if (myProcesses2.Length > 1)
  225. {
  226. MessageBox.Show(LResource.AlreadyRun);
  227. Application.Exit();
  228. }
  229. }
  230. }
  231. }