AMain.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. using Client;
  2. using Client.MirNetwork;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.IO.Compression;
  10. using System.Net;
  11. using System.Net.Sockets;
  12. using System.Security.Cryptography;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Windows.Forms;
  16. namespace Launcher
  17. {
  18. public partial class AMain : Form
  19. {
  20. long _totalBytes, _completedBytes, _currentBytes;
  21. private int _fileCount, _currentCount;
  22. private FileInformation _currentFile;
  23. public bool Completed, Checked, CleanFiles, LabelSwitch, ErrorFound;
  24. public List<FileInformation> OldList;
  25. public Queue<FileInformation> DownloadList;
  26. private Stopwatch _stopwatch = Stopwatch.StartNew();
  27. public Thread _workThread;
  28. private bool dragging = false;
  29. private Point dragCursorPoint;
  30. private Point dragFormPoint;
  31. private Point mouseLocation;//表示鼠标对于窗口左上角的坐标的负数
  32. private bool isDragging;//标识鼠标是否按下
  33. // private string oldClientName = "OldMir3.exe"; //"OldClient.exe";
  34. // private string tempIPAddress;
  35. // private string xcopyname = "xcopy.exe";
  36. private bool Restart = false;
  37. // private string html;
  38. private static byte[] Keys = { 0x14, 0x36, 0xE6, 0xF8, 0xD0, 0xAB, 0xCD, 0xEF };
  39. private static string[] ipgourp = new string[5];
  40. public AMain()
  41. {
  42. InitializeComponent();
  43. int a = DateTime.Now.Second % 6;
  44. if (a == 2) panel2.BackgroundImage = Client.Properties.Resources.back2;
  45. else if (a == 3) panel2.BackgroundImage = Client.Properties.Resources.back3;
  46. else if (a == 4) panel2.BackgroundImage = Client.Properties.Resources.back4;
  47. else if (a == 5) panel2.BackgroundImage = Client.Properties.Resources.back5;
  48. else panel2.BackgroundImage = Client.Properties.Resources.back6;
  49. BackColor = Color.FromArgb(1, 0, 0);
  50. TransparencyKey = Color.FromArgb(1, 0, 0);
  51. linkLabel1.Links.Add(0, 4, @"http://52773mir.com");
  52. linkLabel2.Links.Add(0, 16, @"http://52773mir.com/News/NewArea20240501.html");
  53. linkLabel3.Links.Add(0, 8, @"http://52773mir.com/DXIntorduce.html");
  54. linkLabel4.Links.Add(0, 6, @"http://52773mir.com/News/UpdateInfo.html");
  55. linkLabel5.Links.Add(0, 6, @"http://52773mir.com/News/AccountExchange.html");
  56. linkLabel6.Links.Add(0, 6, @"http://52773mir.com/News/AccountSeasonQuest.html");
  57. }
  58. public static void SaveError(string ex)
  59. {
  60. try
  61. {
  62. if (Settings.RemainingErrorLogs-- > 0)
  63. {
  64. File.AppendAllText(@".\Error.txt",
  65. string.Format("[{0}] {1}{2}", DateTime.Now, ex, Environment.NewLine));
  66. }
  67. }
  68. catch
  69. {
  70. }
  71. }
  72. public bool isMustCheck = false;
  73. public void Start()
  74. {
  75. if (Debugger.IsAttached)
  76. {
  77. //MessageBox.Show("未能获得补丁信息.");
  78. Completed = true;
  79. return;
  80. }
  81. try
  82. {
  83. OldList = new List<FileInformation>();
  84. DownloadList = new Queue<FileInformation>();
  85. if (!File.Exists("PListFirst.gz")||!File.Exists("./Data/Mir3monster/MonS-46.Lib"))
  86. {
  87. Network.SetFirstUpdate();
  88. Restart = true;
  89. Settings.P_Host = Settings.update["IP"].Value<string>();
  90. if (!Settings.P_Host.EndsWith("/")) Settings.P_Host += "/";
  91. Download(Settings.update["PatchFile"].Value<string>(), Settings.update["PatchFile"].Value<string>());
  92. if (File.Exists(Settings.update["PatchFile"].Value<string>()))
  93. {
  94. using (FileStream stream = new FileStream(Settings.update["PatchFile"].Value<string>(), FileMode.Open, FileAccess.Read))
  95. using (BinaryReader reader = new BinaryReader(stream))
  96. ParseOld(reader);
  97. _fileCount = OldList.Count;
  98. //StringBuilder strbuilder=new StringBuilder();
  99. for (int i = 0; i < OldList.Count; i++)
  100. {
  101. CheckFile(OldList[i]);
  102. //strbuilder.AppendLine(@"http://52773mir.com/path/" + OldList[i].FileName.Replace("\","")+".gz" );
  103. }
  104. //File.WriteAllText("urls.txt",strbuilder.ToString());
  105. }
  106. else
  107. {
  108. MessageBox.Show("未能获得补丁信息.");
  109. Completed = true;
  110. return;
  111. }
  112. Checked = true;
  113. _fileCount = 0;
  114. _currentCount = 0;
  115. _fileCount = DownloadList.Count;
  116. BeginDownload();
  117. }
  118. else
  119. {
  120. Settings.P_Host = Settings.update["IP"].Value<string>();
  121. if (!Settings.P_Host.EndsWith("/")) Settings.P_Host += "/";
  122. //
  123. //byte[] data = Download("PList.gz");
  124. // byte[] data = null;
  125. //byte[] data = Download(Settings.update["PatchFile"].Value<string>());
  126. //if (data != null)
  127. //{
  128. // using (MemoryStream stream = new MemoryStream(data))
  129. // using (BinaryReader reader = new BinaryReader(stream))
  130. // ParseOld(reader);
  131. //}
  132. //else
  133. //{
  134. // MessageBox.Show("未能获得补丁信息.");
  135. // Completed = true;
  136. // return;
  137. //}
  138. bool isNeedCheckFile = true;
  139. if ( File.Exists("PListC.gz")&&!Settings.isMustUpdate)
  140. {
  141. byte[] oldMd5;
  142. using (FileStream fs = File.OpenRead("PListC.gz"))
  143. {
  144. using (var crypto = MD5.Create())
  145. {
  146. oldMd5 = crypto.ComputeHash(fs);
  147. }
  148. }
  149. Download(Settings.update["PatchFile"].Value<string>(), Settings.update["PatchFile"].Value<string>());
  150. using (FileStream fs = File.OpenRead(Settings.update["PatchFile"].Value<string>()))
  151. {
  152. byte[] newMd5;
  153. using (var crypto = MD5.Create())
  154. {
  155. newMd5 = crypto.ComputeHash(fs);
  156. }
  157. if (oldMd5.Length == newMd5.Length)
  158. {
  159. int i = 0;
  160. for (i = 0; i < Math.Max(oldMd5.Length, newMd5.Length); i++)
  161. {
  162. if (oldMd5[i] != newMd5[i])
  163. {
  164. break;
  165. }
  166. }
  167. if (i == Math.Max(oldMd5.Length, newMd5.Length))
  168. {
  169. isNeedCheckFile = false;
  170. }
  171. }
  172. }
  173. }
  174. else
  175. {
  176. Download(Settings.update["PatchFile"].Value<string>(), Settings.update["PatchFile"].Value<string>());
  177. }
  178. if (isNeedCheckFile)
  179. {
  180. using (FileStream stream = new FileStream(Settings.update["PatchFile"].Value<string>(), FileMode.Open, FileAccess.Read))
  181. using (BinaryReader reader = new BinaryReader(stream))
  182. ParseOld(reader);
  183. _fileCount = OldList.Count;
  184. for (int i = 0; i < OldList.Count; i++)
  185. CheckFile(OldList[i]);
  186. }
  187. Checked = true;
  188. _fileCount = 0;
  189. _currentCount = 0;
  190. _fileCount = DownloadList.Count;
  191. BeginDownload();
  192. }
  193. }
  194. catch (EndOfStreamException ex)
  195. {
  196. MessageBox.Show("补丁程序遇到了异常流结束");
  197. Completed = true;
  198. SaveError(ex.ToString());
  199. }
  200. catch (Exception ex)
  201. {
  202. MessageBox.Show(ex.ToString(), "Error");
  203. Completed = true;
  204. SaveError(ex.ToString());
  205. }
  206. }
  207. private void BeginDownload()
  208. {
  209. if (DownloadList == null) return;
  210. if (DownloadList.Count == 0)
  211. {
  212. DownloadList = null;
  213. _currentFile = null;
  214. Completed = true;
  215. if (File.Exists("PList.gz"))
  216. {
  217. if (File.Exists("PListFirst.gz"))
  218. {
  219. if (File.Exists("PListC.gz"))
  220. {
  221. File.Delete("PListC.gz");
  222. }
  223. File.Move("PList.gz", "PListC.gz");
  224. }
  225. else
  226. {
  227. File.Move("PList.gz", "PListFirst.gz");
  228. }
  229. }
  230. CleanUp();
  231. return;
  232. }
  233. _currentFile = DownloadList.Dequeue();
  234. if (_currentFile.FileName == "\\Mir3AU.exe")
  235. {
  236. Download(_currentFile, "path");
  237. }
  238. else
  239. Download(_currentFile);
  240. }
  241. private void CleanUp()
  242. {
  243. if (!CleanFiles) return;
  244. string[] fileNames = Directory.GetFiles(@".\", "*.*", SearchOption.AllDirectories);
  245. string fileName;
  246. for (int i = 0; i < fileNames.Length; i++)
  247. {
  248. if (fileNames[i].StartsWith(".\\Screenshots\\")) continue;
  249. fileName = Path.GetFileName(fileNames[i]);
  250. if (fileName == "Mir3Config.ini" || fileName == System.AppDomain.CurrentDomain.FriendlyName) continue;
  251. try
  252. {
  253. if (!NeedFile(fileNames[i]))
  254. File.Delete(fileNames[i]);
  255. }
  256. catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
  257. }
  258. }
  259. public bool NeedFile(string fileName)
  260. {
  261. for (int i = 0; i < OldList.Count; i++)
  262. {
  263. if (fileName.EndsWith(OldList[i].FileName))
  264. return true;
  265. }
  266. return false;
  267. }
  268. public void ParseOld(BinaryReader reader)
  269. {
  270. int count = reader.ReadInt32();
  271. for (int i = 0; i < count; i++)
  272. OldList.Add(new FileInformation(reader));
  273. }
  274. public void CheckFile(FileInformation old)
  275. {
  276. FileInformation info = GetFileInformation(Settings.P_Client + old.FileName);
  277. _currentCount++;
  278. // MessageBox.Show(info.MD5);
  279. if (info == null || old.MD5 != info.MD5 || old.Length != info.Length) // || old.Creation != info.Creation
  280. {
  281. if ((old.FileName.Contains("Mir3AU.exe")))
  282. {
  283. // MessageBox.Show("212121212");
  284. // File.Move(Settings.P_Client + System.AppDomain.CurrentDomain.FriendlyName, Settings.P_Client + oldClientName);
  285. Restart = true;
  286. }
  287. DownloadList.Enqueue(old);
  288. _totalBytes += old.Compressed;
  289. }
  290. }
  291. public class MD5Code
  292. {
  293. /// <summary>
  294. /// Get 文件的MD5校验码
  295. /// </summary>
  296. /// <param name="fileName">文件名称</param>
  297. /// <returns></returns>
  298. public static string GetMD5HashFromFile(string fileName)
  299. {
  300. var file = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);
  301. var md5 = new MD5CryptoServiceProvider();
  302. var bytes = md5.ComputeHash(file);
  303. file.Close();
  304. var sb = new StringBuilder();
  305. for (int i = 0; i < bytes.Length; i++)
  306. {
  307. sb.Append(bytes[i].ToString("x2"));
  308. }
  309. return sb.ToString();
  310. }
  311. }
  312. public static void webClientMethod1(string biaoshi)
  313. {
  314. try
  315. {
  316. WebClient MyWebClient = new WebClient();
  317. MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
  318. Byte[] pageData = MyWebClient.DownloadData("https://mp.weixin.qq.com/s/xqbnmyf42EJvbugSdeJFBg"); //从指定网站下载数据
  319. string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句
  320. int temp = pageHtml.IndexOf(biaoshi);
  321. string pageHtml1 = pageHtml.Substring(temp + 4, 24);
  322. string pageHtml2 = pageHtml.Substring(temp + 30, 24);
  323. string pageHtml3 = pageHtml.Substring(temp + 56, 24);
  324. ipgourp[0] = DecryptDES(pageHtml1, "plk05207");
  325. ipgourp[1] = DecryptDES(pageHtml2, "plk05207");
  326. ipgourp[2] = DecryptDES(pageHtml3, "plk05207");
  327. // MessageBox.Show(ipgourp[0] + ipgourp[1] + ipgourp[2]);
  328. }
  329. catch (WebException webEx)
  330. {
  331. Console.WriteLine(webEx.Message.ToString());
  332. }
  333. }
  334. /// <summary>
  335. /// DES加密字符串
  336. /// </summary>
  337. /// <param name="encryptString">待加密的字符串</param>
  338. /// <param name="encryptKey">加密密钥,要求为8位</param>
  339. /// <returns>加密成功返回加密后的字符串,失败返回源串 </returns>
  340. //public static string EncryptDES(string encryptString, string encryptKey)
  341. //{
  342. // try
  343. // {
  344. // byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));//转换为字节
  345. // byte[] rgbIV = Keys;
  346. // byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
  347. // DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();//实例化数据加密标准
  348. // MemoryStream mStream = new MemoryStream();//实例化内存流
  349. // //将数据流链接到加密转换的流
  350. // CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
  351. // cStream.Write(inputByteArray, 0, inputByteArray.Length);
  352. // cStream.FlushFinalBlock();
  353. // return Convert.ToBase64String(mStream.ToArray());
  354. // }
  355. // catch
  356. // {
  357. // return encryptString;
  358. // }
  359. //}
  360. /// <summary>
  361. /// DES解密字符串
  362. /// </summary>
  363. /// <param name="decryptString">待解密的字符串</param>
  364. /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param>
  365. /// <returns>解密成功返回解密后的字符串,失败返源串</returns>
  366. public static string DecryptDES(string decryptString, string decryptKey)
  367. {
  368. try
  369. {
  370. byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
  371. byte[] rgbIV = Keys;
  372. byte[] inputByteArray = Convert.FromBase64String(decryptString);
  373. DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
  374. MemoryStream mStream = new MemoryStream();
  375. CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
  376. cStream.Write(inputByteArray, 0, inputByteArray.Length);
  377. cStream.FlushFinalBlock();
  378. return Encoding.UTF8.GetString(mStream.ToArray());
  379. }
  380. catch
  381. {
  382. return decryptString;
  383. }
  384. }
  385. public void Download(FileInformation info, string path = null)
  386. {
  387. string fileName = info.FileName.Replace(@"\", "/");
  388. if (fileName != "PList.gz")
  389. fileName += ".gz";
  390. try
  391. {
  392. using (WebClient client = new WebClient())
  393. {
  394. client.DownloadProgressChanged += (o, e) =>
  395. {
  396. _currentBytes = e.BytesReceived;
  397. };
  398. client.DownloadDataCompleted += (o, e) =>
  399. {
  400. if (e.Error != null)
  401. {
  402. File.AppendAllText(@".\Error.txt",
  403. string.Format("[{0}] {1}{2}", DateTime.Now, info.FileName + " 不能下载. (" + e.Error.Message + ")", Environment.NewLine));
  404. ErrorFound = true;
  405. }
  406. else
  407. {
  408. _currentCount++;
  409. _completedBytes += _currentBytes;
  410. _currentBytes = 0;
  411. _stopwatch.Stop();
  412. if (!Directory.Exists(Settings.P_Client + "\\" + Path.GetDirectoryName(info.FileName)))
  413. Directory.CreateDirectory(Settings.P_Client + "\\" + Path.GetDirectoryName(info.FileName));
  414. try
  415. {
  416. File.WriteAllBytes(Settings.P_Client + "\\" + info.FileName, e.Result);
  417. File.SetLastWriteTime(Settings.P_Client + "\\" + info.FileName, info.Creation);
  418. }
  419. catch (System.IO.IOException ex)
  420. {
  421. Restart = true;
  422. File.WriteAllBytes(Settings.P_Client + "\\" + info.FileName + ".bak", e.Result);
  423. File.SetLastWriteTime(Settings.P_Client + "\\" + info.FileName + ".bak", info.Creation);
  424. File.AppendAllText(".\\updates_rename.log", Settings.P_Client + "\\" + info.FileName + "\n");
  425. }
  426. }
  427. BeginDownload();
  428. };
  429. if (Settings.update["NeedLogin"].Value<bool>()) client.Credentials = new NetworkCredential(Settings.update["Login"].Value<string>(), Settings.update["PassWord"].Value<string>());
  430. _stopwatch = Stopwatch.StartNew();
  431. //MessageBox.Show(Settings.update["IP"] + fileName);
  432. client.DownloadDataAsync(new Uri(Settings.update["IP"] + fileName));
  433. }
  434. }
  435. catch
  436. {
  437. MessageBox.Show(string.Format("无法下载文件: {0}", fileName));
  438. }
  439. }
  440. public void Download(string fileName, string filePath)
  441. {
  442. // 加上using
  443. using (WebClient client = new WebClient())
  444. {
  445. //MessageBox.Show(Settings.P_Host + fileName, filePath);
  446. // 填下载链接,和本地地址,下载完检查文件夹即可
  447. client.DownloadFile(Settings.P_Host + fileName, filePath);
  448. }
  449. }
  450. public byte[] Download(string fileName)
  451. {
  452. fileName = fileName.Replace(@"\", "/");
  453. if (fileName != "PList.gz")
  454. fileName += Path.GetExtension(fileName);
  455. try
  456. {
  457. using (WebClient client = new WebClient())
  458. {
  459. if (Settings.P_NeedLogin)
  460. client.Credentials = new NetworkCredential(Settings.P_Login, Settings.Password);
  461. else
  462. client.Credentials = new NetworkCredential("", "");
  463. return client.DownloadData(Settings.P_Host + Path.ChangeExtension(fileName, ".gz"));
  464. }
  465. }
  466. catch
  467. {
  468. return null;
  469. }
  470. }
  471. public static byte[] Decompress(byte[] raw)
  472. {
  473. using (GZipStream gStream = new GZipStream(new MemoryStream(raw), CompressionMode.Decompress))
  474. {
  475. const int size = 4096; //4kb
  476. byte[] buffer = new byte[size];
  477. using (MemoryStream mStream = new MemoryStream())
  478. {
  479. int count;
  480. do
  481. {
  482. count = gStream.Read(buffer, 0, size);
  483. if (count > 0)
  484. {
  485. mStream.Write(buffer, 0, count);
  486. }
  487. } while (count > 0);
  488. return mStream.ToArray();
  489. }
  490. }
  491. }
  492. public static byte[] Compress(byte[] raw)
  493. {
  494. using (MemoryStream mStream = new MemoryStream())
  495. {
  496. using (GZipStream gStream = new GZipStream(mStream, CompressionMode.Compress, true))
  497. gStream.Write(raw, 0, raw.Length);
  498. return mStream.ToArray();
  499. }
  500. }
  501. public FileInformation GetFileInformation(string fileName)
  502. {
  503. if (!File.Exists(fileName)) return null;
  504. FileInfo info = new FileInfo(fileName);
  505. return new FileInformation
  506. {
  507. FileName = fileName.Remove(0, Settings.P_Client.Length),
  508. Length = (int)info.Length,
  509. Creation = info.LastWriteTime,
  510. MD5 = MD5Code.GetMD5HashFromFile(fileName)
  511. };
  512. }
  513. private void AMain_Load(object sender, EventArgs e)
  514. {
  515. //if (Settings.P_BrowserAddress != "") Main_browser.Navigate(new Uri(Settings.P_BrowserAddress));
  516. webClientMethod1("列表OK");
  517. panel1.BackColor=Color.FromArgb(120,0, 0, 0);
  518. //panel1.BringToFront();
  519. //panel1.Top = 100;
  520. //panel2.BackColor = Color.FromArgb(120, 0, 0, 0);
  521. //webBrowser1.Navigate("file:///D:/网页/WEB/newFrame.html");
  522. // mir3lib.ReadMir3Stat();
  523. // mir3lib.Findstat(1);
  524. // MessageBox.Show(mir3lib.Findstat(1).Name);
  525. // if (File.Exists(Settings.P_Client + oldClientName)) File.Delete(Settings.P_Client + oldClientName);
  526. //Launch_pb.Enabled = false;
  527. ProgressCurrent_pb.Width = 5;
  528. TotalProg_pb.Width = 5;
  529. Version_label.Text = "Version " + Application.ProductVersion;
  530. if (Settings.P_ServerName != String.Empty)
  531. {
  532. Name_label.Visible = true;
  533. Name_label.Text = Settings.P_ServerName;
  534. }
  535. //string[] temp = { "牛转乾坤登录点一", "牛转乾坤登录点二", "牛转乾坤登录点三", "牛转乾坤登录点四", "牛转乾坤登录点五", "测试登录点", "备用登录点" };
  536. //serverlistbox.Items.AddRange(temp);
  537. //serverlistbox.Text = "牛转乾坤登录点一";
  538. foreach (JObject game in Settings.games)
  539. {
  540. serverlistbox.Items.Add(game["ServerName"].Value<string>());
  541. }
  542. serverlistbox.Text = Settings.games[0]["ServerName"].Value<string>();
  543. Settings.ServerID = Settings.games[0]["ServerID"].Value<string>();
  544. Settings.ServerName = Settings.games[0]["ServerName"].Value<string>();
  545. ResolutionComboBox.Items.Clear();
  546. ResolutionComboBox.Items.AddRange(Settings.Resolutions);
  547. ResolutionComboBox.SelectedIndex = Settings.ResolutionId;
  548. FullScreen_CheckBox.Checked = Settings.FullScreen;
  549. Windowed_CheckBox.Checked = Settings.AlwaysOnTop;
  550. FPSLimit_CheckBox.Checked = Settings.FPSCap;
  551. _workThread = new Thread(Start) { IsBackground = true };
  552. _workThread.Start();
  553. }
  554. private void Launch_pb_Click(object sender, EventArgs e)
  555. {
  556. Launch();
  557. }
  558. private void Launch()
  559. {
  560. if (Network.CheckIP())
  561. {
  562. //Settings.Save();
  563. // Settings.Load();
  564. //if (serverlistbox.SelectedIndex == 5)
  565. //{
  566. // Settings.partnum = 3;
  567. //}
  568. //else
  569. //if (serverlistbox.SelectedIndex == 6)
  570. //{
  571. // Settings.IPAddress = Settings.IPAddress5;
  572. //}
  573. //else
  574. //{
  575. // Settings.partnum = 5;
  576. //}
  577. Program.Form = new CMain();
  578. Program.Form.Closed += (s, args) => this.Close();
  579. Program.Form.Show();
  580. Program.PForm.Hide();
  581. }
  582. else
  583. {
  584. MessageBox.Show("服务器链接失败!");
  585. }
  586. }
  587. private void Movement_panel_MouseUp(object sender, MouseEventArgs e)
  588. {
  589. dragging = false;
  590. }
  591. private void Movement_panel_MouseMove(object sender, MouseEventArgs e)
  592. {
  593. if (dragging)
  594. {
  595. Location = new Point(dragFormPoint.X + MousePosition.X - dragCursorPoint.X, dragFormPoint.Y + MousePosition.Y - dragCursorPoint.Y);
  596. }
  597. }
  598. private void Launch_pb_MouseEnter(object sender, EventArgs e)
  599. {
  600. Launch_pb.Image = Client.Properties.Resources.Launch_Hover;
  601. }
  602. private void Launch_pb_MouseLeave(object sender, EventArgs e)
  603. {
  604. Launch_pb.Image = Client.Properties.Resources.Launch_Base1;
  605. }
  606. private void Close_pb_MouseEnter(object sender, EventArgs e)
  607. {
  608. Close_pb.Image = Client.Properties.Resources.Cross_Hover;
  609. }
  610. private void Close_pb_MouseLeave(object sender, EventArgs e)
  611. {
  612. Close_pb.Image = Client.Properties.Resources.Cross_Base;
  613. }
  614. private void Launch_pb_MouseDown(object sender, MouseEventArgs e)
  615. {
  616. Launch_pb.Image = Client.Properties.Resources.Launch_Pressed;
  617. }
  618. private void Launch_pb_MouseUp(object sender, MouseEventArgs e)
  619. {
  620. Launch_pb.Image = Client.Properties.Resources.Launch_Base1;
  621. }
  622. private void Close_pb_MouseDown(object sender, MouseEventArgs e)
  623. {
  624. Close_pb.Image = Client.Properties.Resources.Cross_Pressed;
  625. }
  626. private void Close_pb_MouseUp(object sender, MouseEventArgs e)
  627. {
  628. Close_pb.Image = Client.Properties.Resources.Cross_Base;
  629. }
  630. private void ProgressCurrent_pb_SizeChanged(object sender, EventArgs e)
  631. {
  632. ProgEnd_pb.Location = new Point((ProgressCurrent_pb.Location.X + ProgressCurrent_pb.Width), 490);
  633. if (ProgressCurrent_pb.Width == 0) ProgEnd_pb.Visible = false;
  634. else ProgEnd_pb.Visible = true;
  635. }
  636. private void Config_pb_MouseDown(object sender, MouseEventArgs e)
  637. {
  638. Config_pb.Image = Client.Properties.Resources.Config_Pressed;
  639. }
  640. private void Config_pb_MouseEnter(object sender, EventArgs e)
  641. {
  642. Config_pb.Image = Client.Properties.Resources.Config_Hover;
  643. }
  644. private void Config_pb_MouseLeave(object sender, EventArgs e)
  645. {
  646. Config_pb.Image = Client.Properties.Resources.Config_Base;
  647. }
  648. private void Config_pb_MouseUp(object sender, MouseEventArgs e)
  649. {
  650. Config_pb.Image = Client.Properties.Resources.Config_Base;
  651. }
  652. private void TotalProg_pb_SizeChanged(object sender, EventArgs e)
  653. {
  654. ProgTotalEnd_pb.Location = new Point((TotalProg_pb.Location.X + TotalProg_pb.Width), 508);
  655. if (TotalProg_pb.Width == 0) ProgTotalEnd_pb.Visible = false;
  656. else ProgTotalEnd_pb.Visible = true;
  657. }
  658. private void serverlistbox_SelectedIndexChanged(object sender, EventArgs e)
  659. {
  660. string temp = serverlistbox.SelectedItem.ToString();
  661. // switch (temp)
  662. // {
  663. //case "备用登录点":
  664. // // tempIPAddress = ipgourp[4];
  665. // tempIPAddress = Settings.IPAddress5;
  666. // break;
  667. //default:
  668. // tempIPAddress = ipgourp[0];
  669. // break;
  670. // }
  671. // MessageBox.Show(IPAddress, IPAddress);
  672. foreach (JObject game in Settings.games)
  673. {
  674. if (game["ServerName"].ToString() == temp)
  675. {
  676. Settings.ServerID = game["ServerID"].Value<string>();
  677. Settings.ServerName = game["ServerName"].Value<string>();
  678. Settings.shields = JArray.Parse(game["shields"].ToString());
  679. break;
  680. }
  681. }
  682. }
  683. private void Name_label_Click(object sender, EventArgs e)
  684. {
  685. if (File.Exists("PListC.gz"))
  686. {
  687. File.Delete("PListC.gz");
  688. }
  689. if (File.Exists("PListFirst.gz"))
  690. {
  691. File.Delete("PListFirst.gz");
  692. }
  693. Process.Start("Start.exe");
  694. Environment.Exit(0);
  695. }
  696. //private void Res1_pb_Click(object sender, EventArgs e)
  697. //{
  698. // resolutionChoice(800);
  699. //}
  700. //public void resolutionChoice(int res)
  701. //{
  702. // Res1_pb.Image = Client.Properties.Resources.Radio_Unactive;
  703. // Res2_pb.Image = Client.Properties.Resources.Radio_Unactive;
  704. // // Res3_pb.Image = Client.Properties.Resources.Radio_Unactive;
  705. // // Res4_pb.Image = Client.Properties.Resources.Radio_Unactive;
  706. // if (res == 800) Res1_pb.Image = Client.Properties.Resources.Config_Radio_On;
  707. // if (res == 1024) Res2_pb.Image = Client.Properties.Resources.Config_Radio_On;
  708. // // else if (res == 1366) Res3_pb.Image = Client.Properties.Resources.Config_Radio_On;
  709. // // else if (res == 1280) Res4_pb.Image = Client.Properties.Resources.Config_Radio_On;
  710. //}
  711. //private void Res2_pb_Click(object sender, EventArgs e)
  712. //{
  713. // resolutionChoice(1024);
  714. //}
  715. private void Main_browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  716. {
  717. // if (Main_browser.Url.AbsolutePath != "blank") Main_browser.Visible = true;
  718. }
  719. private void Name_label_DoubleClick(object sender, EventArgs e)
  720. {
  721. }
  722. private void label10_DoubleClick(object sender, EventArgs e)
  723. {
  724. //FormResourceEditor form = new FormResourceEditor();
  725. //form.Show();
  726. }
  727. private void ResolutionComboBox_TextChanged(object sender, EventArgs e)
  728. {
  729. Settings.ResolutionId = ResolutionComboBox.SelectedIndex;
  730. }
  731. private void FullScreen_CheckBox_CheckedChanged(object sender, EventArgs e)
  732. {
  733. Settings.FullScreen=FullScreen_CheckBox.Checked;
  734. }
  735. private void FPSLimit_CheckBox_CheckedChanged(object sender, EventArgs e)
  736. {
  737. Settings.FPSCap = FPSLimit_CheckBox.Checked;
  738. }
  739. private void Close_pb_Click(object sender, EventArgs e)
  740. {
  741. Application.Exit();
  742. }
  743. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  744. {
  745. this.linkLabel1.Links[this.linkLabel1.Links.IndexOf(e.Link)].Visited = true;
  746. string targetUrl = e.Link.LinkData as string;
  747. if (string.IsNullOrEmpty(targetUrl))
  748. MessageBox.Show("没有链接地址!");
  749. else
  750. System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
  751. }
  752. private void Movement_panel_MouseDown(object sender, MouseEventArgs e)
  753. {
  754. dragging = true;
  755. dragCursorPoint =MousePosition;
  756. dragFormPoint = new Point(Location.X, Location.Y);
  757. }
  758. private void button1_Click(object sender, EventArgs e)
  759. {
  760. if (DownloadList!=null&& DownloadList.Count<1)
  761. {
  762. Start();
  763. }
  764. }
  765. private void Button_CheckUpdate_Click(object sender, EventArgs e)
  766. {
  767. if (File.Exists("PListC.gz"))
  768. {
  769. File.Delete("PListC.gz");
  770. }
  771. Process.Start("Start.exe");
  772. Environment.Exit(0 );
  773. }
  774. private void Config_pb_Click(object sender, EventArgs e)
  775. {
  776. panel1.Visible = !panel1.Visible;
  777. }
  778. private void Name_label_MouseEnter(object sender, EventArgs e)
  779. {
  780. Name_label.ForeColor = Color.Lime;
  781. }
  782. private void Name_label_MouseLeave(object sender, EventArgs e)
  783. {
  784. Name_label.ForeColor = Color.White;
  785. }
  786. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  787. {
  788. this.linkLabel2.Links[this.linkLabel2.Links.IndexOf(e.Link)].Visited = true;
  789. string targetUrl = e.Link.LinkData as string;
  790. if (string.IsNullOrEmpty(targetUrl))
  791. MessageBox.Show("没有链接地址!");
  792. else
  793. System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
  794. }
  795. private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  796. {
  797. this.linkLabel3.Links[this.linkLabel3.Links.IndexOf(e.Link)].Visited = true;
  798. string targetUrl = e.Link.LinkData as string;
  799. if (string.IsNullOrEmpty(targetUrl))
  800. MessageBox.Show("没有链接地址!");
  801. else
  802. System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
  803. }
  804. private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  805. {
  806. this.linkLabel4.Links[this.linkLabel4.Links.IndexOf(e.Link)].Visited = true;
  807. string targetUrl = e.Link.LinkData as string;
  808. if (string.IsNullOrEmpty(targetUrl))
  809. MessageBox.Show("没有链接地址!");
  810. else
  811. System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
  812. }
  813. private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  814. {
  815. this.linkLabel5.Links[this.linkLabel5.Links.IndexOf(e.Link)].Visited = true;
  816. string targetUrl = e.Link.LinkData as string;
  817. if (string.IsNullOrEmpty(targetUrl))
  818. MessageBox.Show("没有链接地址!");
  819. else
  820. System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
  821. }
  822. private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  823. {
  824. this.linkLabel6.Links[this.linkLabel6.Links.IndexOf(e.Link)].Visited = true;
  825. string targetUrl = e.Link.LinkData as string;
  826. if (string.IsNullOrEmpty(targetUrl))
  827. MessageBox.Show("没有链接地址!");
  828. else
  829. System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
  830. }
  831. private void Windowed_CheckBox_CheckedChanged(object sender, EventArgs e)
  832. {
  833. Settings.AlwaysOnTop = Windowed_CheckBox.Checked;
  834. }
  835. private void label10_Click(object sender, EventArgs e)
  836. {
  837. }
  838. private void InterfaceTimer_Tick(object sender, EventArgs e)
  839. {
  840. try
  841. {
  842. if (Completed)
  843. {
  844. ActionLabel.Text = "";
  845. CurrentFile_label.Text = "更新完毕.";
  846. SpeedLabel.Text = "";
  847. ProgressCurrent_pb.Width = 550;
  848. TotalProg_pb.Width = 550;
  849. CurrentFile_label.Visible = true;
  850. CurrentPercent_label.Visible = true;
  851. TotalPercent_label.Visible = true;
  852. CurrentPercent_label.Text = "100%";
  853. TotalPercent_label.Text = "100%";
  854. InterfaceTimer.Enabled = false;
  855. Launch_pb.Enabled = true;
  856. // Settings.Load();
  857. // Settings.Save();
  858. if (ErrorFound) MessageBox.Show("一个或多个文件下载失败, 请检查 Error.txt 中的错误.", "未能下载.");
  859. ErrorFound = false;
  860. if (CleanFiles)
  861. {
  862. CleanFiles = false;
  863. MessageBox.Show("你的文件已经被清理干净.", "清理文件");
  864. }
  865. if (Restart)
  866. {
  867. Program.Restart = true;
  868. // MoveOldClientToCurrent();
  869. // Close();
  870. Process.Start("Start.exe");
  871. System.Environment.Exit(0);
  872. }
  873. //if (Settings.P_AutoStart)
  874. //{
  875. // Launch();
  876. //}
  877. return;
  878. }
  879. ActionLabel.Visible = true;
  880. SpeedLabel.Visible = true;
  881. CurrentFile_label.Visible = true;
  882. CurrentPercent_label.Visible = true;
  883. TotalPercent_label.Visible = true;
  884. if (LabelSwitch) ActionLabel.Text = string.Format("{0} 剩余文件", _fileCount - _currentCount);
  885. else ActionLabel.Text = string.Format("{0:#,##0}MB 剩余文件", ((_totalBytes) - (_completedBytes + _currentBytes)) / 1024 / 1024);
  886. //ActionLabel.Text = string.Format("{0:#,##0}MB / {1:#,##0}MB", (_completedBytes + _currentBytes) / 1024 / 1024, _totalBytes / 1024 / 1024);
  887. if (_currentFile != null)
  888. {
  889. //FileLabel.Text = string.Format("{0}, ({1:#,##0} MB) / ({2:#,##0} MB)", _currentFile.FileName, _currentBytes / 1024 / 1024, _currentFile.Compressed / 1024 / 1024);
  890. CurrentFile_label.Text = string.Format("{0}", _currentFile.FileName);
  891. SpeedLabel.Text = (_currentBytes / 1024F / _stopwatch.Elapsed.TotalSeconds).ToString("#,##0.##") + "KB/s";
  892. CurrentPercent_label.Text = ((int)(100 * _currentBytes / _currentFile.Compressed)).ToString() + "%";
  893. ProgressCurrent_pb.Width = (int)(5.5 * (100 * _currentBytes / _currentFile.Compressed));
  894. }
  895. if (_totalBytes > 0)
  896. {
  897. TotalPercent_label.Text = ((int)(100 * (_completedBytes + _currentBytes) / _totalBytes)).ToString() + "%";
  898. TotalProg_pb.Width = (int)(5.5 * (100 * (_completedBytes + _currentBytes) / _totalBytes));
  899. }
  900. }
  901. catch (Exception ex)
  902. {
  903. Console.WriteLine(ex.StackTrace);
  904. }
  905. }
  906. private void ActionLabel_Click(object sender, EventArgs e)
  907. {
  908. LabelSwitch = !LabelSwitch;
  909. }
  910. private void Credit_label_Click(object sender, EventArgs e)
  911. {
  912. if (Credit_label.Text == "www.mir3.com") Credit_label.Text = "QQ:暂不开放";
  913. else Credit_label.Text = "www.mir3.com";
  914. }
  915. private void AMain_FormClosed(object sender, FormClosedEventArgs e)
  916. {
  917. // MoveOldClientToCurrent();
  918. }
  919. //private void MoveOldClientToCurrent()
  920. //{
  921. // string oldClient = Settings.P_Client + oldClientName;
  922. // string currentClient = Settings.P_Client + System.AppDomain.CurrentDomain.FriendlyName;
  923. // if (!File.Exists(currentClient) && File.Exists(oldClient))
  924. // File.Move(oldClient, currentClient);
  925. //}
  926. private bool checkonline(string ipstring, int prot)
  927. {
  928. IPAddress ip = IPAddress.Parse(ipstring);
  929. // IPEndPoint point = new IPEndPoint(ip, prot);
  930. // bool success = ar.AsyncWaitHandle.WaitOne(1000);
  931. // if (!success)
  932. // throw new Exception("超时时间已到,未连接到指定服务器");
  933. // try
  934. //{
  935. TcpClient tcp = new TcpClient();
  936. IAsyncResult ar = tcp.BeginConnect(ip, Settings.Port, null, null);
  937. bool success = ar.AsyncWaitHandle.WaitOne(200);
  938. // tcp.Connect(point);
  939. //tcp.Close();
  940. // temp= true;
  941. // }
  942. //catch (Exception)
  943. // {
  944. // }
  945. return success;
  946. }
  947. }
  948. public class FileInformation
  949. {
  950. public string FileName; //Relative. 文件名
  951. public int Length, Compressed;
  952. public DateTime Creation;
  953. public string MD5;
  954. public FileInformation()
  955. {
  956. }
  957. public FileInformation(BinaryReader reader)
  958. {
  959. FileName = reader.ReadString();
  960. MD5 = reader.ReadString();
  961. Length = reader.ReadInt32();
  962. Compressed = reader.ReadInt32();
  963. Creation = DateTime.FromBinary(reader.ReadInt64());
  964. }
  965. public void Save(BinaryWriter writer)
  966. {
  967. writer.Write(FileName);
  968. writer.Write(MD5);
  969. writer.Write(Length);
  970. writer.Write(Compressed);
  971. writer.Write(Creation.ToBinary());
  972. }
  973. }
  974. }