Login.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. CommonMethod.GetProfileString("MOKAFactoryTools", "VirMAC", "B0-00-00-00-00-0B", MyString, 256);
  75. if (MyString.ToString().Equals("B0-00-00-00-00-0B"))
  76. {// 惠州工厂;
  77. AccountText.Text = "Huizhou";
  78. PwdText.Text = "admin";
  79. }
  80. else if (MyString.ToString().Equals("A0-00-00-00-00-0A"))
  81. {// 三华工厂;
  82. AccountText.Text = "SanHua";
  83. PwdText.Text = "admin";
  84. }
  85. else if (MyString.ToString().Equals("C0-00-00-00-00-0C"))
  86. {// 泰霖工厂;
  87. AccountText.Text = "Talent";
  88. PwdText.Text = "admin";
  89. }
  90. TestMode.MAC = MyString.ToString();
  91. JObject jObject;
  92. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  93. {
  94. using (JsonTextReader reader = new JsonTextReader(file))
  95. {
  96. jObject = (JObject)JToken.ReadFrom(reader);
  97. reader.Close();
  98. jObject["FactoryName"] = AccountText.Text;
  99. }
  100. }
  101. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  102. {
  103. writer.Write(jObject.ToString());
  104. }
  105. }
  106. else
  107. {
  108. TestMode.testMode = false;
  109. TestMode.SetTestMode();
  110. TestMode.MAC = CommonMethod.GetMacAddress();
  111. }
  112. }
  113. private void OnBtnLogin(object sender, EventArgs e)
  114. {
  115. if (PwdText.Text == "zhangyi" && AccountText.Text == "zhangyi")
  116. enable = 1;
  117. else if (PwdText.Text == "offline" && AccountText.Text == "offline")
  118. enable = 3;
  119. else if (PwdText.Text.Trim().Length > 0 && AccountText.Text.Trim().Length > 0)
  120. {
  121. #region G客户NTF功能开启;
  122. if ( IsNTF )
  123. {
  124. if ( LineText.Text.Length == 0 )
  125. {
  126. MessageBox.Show("Line should not be empty!");
  127. return;
  128. }
  129. }
  130. #endregion
  131. if (CommonMethod.UserLogin(TestMode.loginUrl, AccountText.Text, PwdText.Text, TestMode.MAC, ErrorDB,out loginOutput1))
  132. {
  133. enable = 0;
  134. JObject jObject;
  135. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  136. {
  137. using (JsonTextReader reader = new JsonTextReader(file))
  138. {
  139. jObject = (JObject)JToken.ReadFrom(reader);
  140. reader.Close();
  141. jObject["FactoryName"] = loginOutput1.factoryname;
  142. jObject["FactoryNum"] = loginOutput1.factorynum;
  143. jObject["Line"] = LineText.Text;
  144. }
  145. }
  146. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  147. {
  148. writer.Write(jObject.ToString());
  149. }
  150. }
  151. else
  152. {
  153. MessageBox.Show(LResource.LoginFail + "\r\n" + loginOutput1.msg);
  154. return;
  155. }
  156. }
  157. else
  158. {
  159. enable = 2;
  160. }
  161. CommonMethod.FactoryName = loginOutput1.factoryname;
  162. UpgradeMsgList upgradeMsgList = new UpgradeMsgList();
  163. var FactoryNum = loginOutput1.factorynum;
  164. if(FactoryNum.Length>0)
  165. {
  166. try
  167. {
  168. if (CommonMethod.UpgradeCheck(TestMode.upgradeUrl, FactoryNum, ErrorDB, out upgradeMsgList))
  169. {
  170. if (CommonMethod.CompareVersion(upgradeMsgList.upgrade.version, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()))
  171. {
  172. Upgrade upgrade = new Upgrade(ErrorDB, upgradeMsgList.upgrade.fileurl, loginOutput1.factorynum);
  173. upgrade.Show();
  174. }
  175. else
  176. {
  177. ErrorDB.Close();
  178. ErrorDB.Dispose();
  179. Main form1 = new Main(enable);
  180. form1.Show();
  181. this.Hide();
  182. }
  183. }
  184. else
  185. {
  186. MessageBox.Show(LResource.UpgradeCheckFail);
  187. ErrorDB.Close();
  188. ErrorDB.Dispose();
  189. Main form1 = new Main(enable);
  190. form1.Show();
  191. this.Hide();
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. MessageBox.Show(ServicePointManager.SecurityProtocol.ToString());
  197. MessageBox.Show(ex.Message);
  198. MessageBox.Show(LResource.UpgradeCheckFail);
  199. ErrorDB.Close();
  200. ErrorDB.Dispose();
  201. Main form1 = new Main(enable);
  202. form1.Show();
  203. this.Hide();
  204. }
  205. }
  206. else
  207. {
  208. ErrorDB.Close();
  209. ErrorDB.Dispose();
  210. MessageBox.Show(LResource.PleaseLogin);
  211. Main form1 = new Main(enable);
  212. form1.Show();
  213. this.Hide();
  214. }
  215. }
  216. public string format(uint data,uint length)
  217. {
  218. return String.Format("{0:D" + length.ToString() + "}", data);
  219. }
  220. private void login_Load(object sender, EventArgs e)
  221. {
  222. using (StreamReader file = File.OpenText(LocalPath.localpath + "\\Config.json"))
  223. {
  224. using (JsonTextReader reader = new JsonTextReader(file))
  225. {
  226. JObject jObject = (JObject)JToken.ReadFrom(reader);
  227. reader.Close();
  228. AccountText.Text = jObject["FactoryName"] == null ? (!CommonMethod.AddJsonConfig("FactoryName", null) ? "" : "") : jObject["FactoryName"].Value<string>();
  229. loginOutput1.factoryname = jObject["FactoryName"] == null ? "" : jObject["FactoryName"].Value<string>();
  230. loginOutput1.factorynum=jObject["FactoryNum"] == null ? "" : jObject["FactoryNum"].Value<string>();
  231. HttpHelper.Tracert = jObject["Tracert"] == null ? false : jObject["Tracert"].Value<bool>();
  232. #region G客户NTF功能开启;
  233. if (jObject["NTF"] != null)
  234. {
  235. IsNTF = jObject["NTF"].Value<bool>();
  236. if (IsNTF)
  237. {
  238. skinLabel3.Visible = true;
  239. LineText.Visible = true;
  240. BtnLogin.Location = new System.Drawing.Point(70, 152);
  241. BtnLogin.Size = new System.Drawing.Size(90, 33);
  242. this.Size = new System.Drawing.Size(230, 200);
  243. }
  244. if (jObject["Line"] != null)
  245. {
  246. string Line = jObject["Line"].Value<string>();
  247. LineText.Text = Line;
  248. }
  249. }
  250. #endregion
  251. }
  252. }
  253. System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName("SCBC Factory Tools");//获取指定的进程名
  254. if (myProcesses.Length > 1)
  255. {
  256. MessageBox.Show(LResource.AlreadyRun);
  257. Application.Exit();
  258. }
  259. System.Diagnostics.Process[] myProcesses2 = System.Diagnostics.Process.GetProcessesByName("MOKA Factory Tools");//获取指定的进程名
  260. if (myProcesses2.Length > 1)
  261. {
  262. MessageBox.Show(LResource.AlreadyRun);
  263. Application.Exit();
  264. }
  265. }
  266. }
  267. }