Login.cs 13 KB

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