Login.cs 12 KB

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