12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190 |
- using Client;
- using Client.MirNetwork;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.IO.Compression;
- using System.Net;
- using System.Net.Sockets;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace Launcher
- {
- public partial class AMain : Form
- {
- long _totalBytes, _completedBytes, _currentBytes;
- private int _fileCount, _currentCount;
- private FileInformation _currentFile;
- public bool Completed, Checked, CleanFiles, LabelSwitch, ErrorFound;
- public List<FileInformation> OldList;
- public Queue<FileInformation> DownloadList;
- private Stopwatch _stopwatch = Stopwatch.StartNew();
- public Thread _workThread;
- private bool dragging = false;
- private Point dragCursorPoint;
- private Point dragFormPoint;
- private Point mouseLocation;//表示鼠标对于窗口左上角的坐标的负数
- private bool isDragging;//标识鼠标是否按下
- // private string oldClientName = "OldMir3.exe"; //"OldClient.exe";
- // private string tempIPAddress;
- // private string xcopyname = "xcopy.exe";
- private bool Restart = false;
- // private string html;
- private static byte[] Keys = { 0x14, 0x36, 0xE6, 0xF8, 0xD0, 0xAB, 0xCD, 0xEF };
- private static string[] ipgourp = new string[5];
- public AMain()
- {
- InitializeComponent();
- int a = DateTime.Now.Second % 6;
- if (a == 2) panel2.BackgroundImage = Client.Properties.Resources.back2;
- else if (a == 3) panel2.BackgroundImage = Client.Properties.Resources.back3;
- else if (a == 4) panel2.BackgroundImage = Client.Properties.Resources.back4;
- else if (a == 5) panel2.BackgroundImage = Client.Properties.Resources.back5;
- else panel2.BackgroundImage = Client.Properties.Resources.back6;
- BackColor = Color.FromArgb(1, 0, 0);
- TransparencyKey = Color.FromArgb(1, 0, 0);
- linkLabel1.Links.Add(0, 4, @"http://52773mir.com");
- linkLabel2.Links.Add(0, 16, @"http://52773mir.com/News/NewArea20240501.html");
- linkLabel3.Links.Add(0, 8, @"http://52773mir.com/DXIntorduce.html");
- linkLabel4.Links.Add(0, 6, @"http://52773mir.com/News/UpdateInfo.html");
- linkLabel5.Links.Add(0, 6, @"http://52773mir.com/News/AccountExchange.html");
- linkLabel6.Links.Add(0, 6, @"http://52773mir.com/News/AccountSeasonQuest.html");
- }
- public static void SaveError(string ex)
- {
- try
- {
- if (Settings.RemainingErrorLogs-- > 0)
- {
- File.AppendAllText(@".\Error.txt",
- string.Format("[{0}] {1}{2}", DateTime.Now, ex, Environment.NewLine));
- }
- }
- catch
- {
- }
- }
- public bool isMustCheck = false;
- public void Start()
- {
- if (Debugger.IsAttached)
- {
- //MessageBox.Show("未能获得补丁信息.");
- Completed = true;
- return;
- }
- try
- {
- OldList = new List<FileInformation>();
- DownloadList = new Queue<FileInformation>();
- if (!File.Exists("PListFirst.gz")||!File.Exists("./Data/Mir3monster/MonS-46.Lib"))
- {
- Network.SetFirstUpdate();
- Restart = true;
- Settings.P_Host = Settings.update["IP"].Value<string>();
- if (!Settings.P_Host.EndsWith("/")) Settings.P_Host += "/";
- Download(Settings.update["PatchFile"].Value<string>(), Settings.update["PatchFile"].Value<string>());
- if (File.Exists(Settings.update["PatchFile"].Value<string>()))
- {
- using (FileStream stream = new FileStream(Settings.update["PatchFile"].Value<string>(), FileMode.Open, FileAccess.Read))
- using (BinaryReader reader = new BinaryReader(stream))
- ParseOld(reader);
- _fileCount = OldList.Count;
- //StringBuilder strbuilder=new StringBuilder();
- for (int i = 0; i < OldList.Count; i++)
- {
- CheckFile(OldList[i]);
- //strbuilder.AppendLine(@"http://52773mir.com/path/" + OldList[i].FileName.Replace("\","")+".gz" );
- }
- //File.WriteAllText("urls.txt",strbuilder.ToString());
- }
- else
- {
- MessageBox.Show("未能获得补丁信息.");
- Completed = true;
- return;
- }
- Checked = true;
- _fileCount = 0;
- _currentCount = 0;
- _fileCount = DownloadList.Count;
- BeginDownload();
- }
- else
- {
- Settings.P_Host = Settings.update["IP"].Value<string>();
- if (!Settings.P_Host.EndsWith("/")) Settings.P_Host += "/";
- //
- //byte[] data = Download("PList.gz");
- // byte[] data = null;
- //byte[] data = Download(Settings.update["PatchFile"].Value<string>());
- //if (data != null)
- //{
- // using (MemoryStream stream = new MemoryStream(data))
- // using (BinaryReader reader = new BinaryReader(stream))
- // ParseOld(reader);
- //}
- //else
- //{
- // MessageBox.Show("未能获得补丁信息.");
- // Completed = true;
- // return;
- //}
- bool isNeedCheckFile = true;
- if ( File.Exists("PListC.gz")&&!Settings.isMustUpdate)
- {
- byte[] oldMd5;
- using (FileStream fs = File.OpenRead("PListC.gz"))
- {
- using (var crypto = MD5.Create())
- {
- oldMd5 = crypto.ComputeHash(fs);
- }
- }
- Download(Settings.update["PatchFile"].Value<string>(), Settings.update["PatchFile"].Value<string>());
- using (FileStream fs = File.OpenRead(Settings.update["PatchFile"].Value<string>()))
- {
- byte[] newMd5;
- using (var crypto = MD5.Create())
- {
- newMd5 = crypto.ComputeHash(fs);
- }
- if (oldMd5.Length == newMd5.Length)
- {
- int i = 0;
- for (i = 0; i < Math.Max(oldMd5.Length, newMd5.Length); i++)
- {
- if (oldMd5[i] != newMd5[i])
- {
- break;
- }
- }
- if (i == Math.Max(oldMd5.Length, newMd5.Length))
- {
- isNeedCheckFile = false;
- }
- }
- }
- }
- else
- {
- Download(Settings.update["PatchFile"].Value<string>(), Settings.update["PatchFile"].Value<string>());
- }
- if (isNeedCheckFile)
- {
- using (FileStream stream = new FileStream(Settings.update["PatchFile"].Value<string>(), FileMode.Open, FileAccess.Read))
- using (BinaryReader reader = new BinaryReader(stream))
- ParseOld(reader);
- _fileCount = OldList.Count;
- for (int i = 0; i < OldList.Count; i++)
- CheckFile(OldList[i]);
- }
- Checked = true;
- _fileCount = 0;
- _currentCount = 0;
- _fileCount = DownloadList.Count;
- BeginDownload();
- }
- }
- catch (EndOfStreamException ex)
- {
- MessageBox.Show("补丁程序遇到了异常流结束");
- Completed = true;
- SaveError(ex.ToString());
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString(), "Error");
- Completed = true;
- SaveError(ex.ToString());
- }
- }
- private void BeginDownload()
- {
- if (DownloadList == null) return;
- if (DownloadList.Count == 0)
- {
- DownloadList = null;
- _currentFile = null;
- Completed = true;
- if (File.Exists("PList.gz"))
- {
- if (File.Exists("PListFirst.gz"))
- {
- if (File.Exists("PListC.gz"))
- {
- File.Delete("PListC.gz");
- }
- File.Move("PList.gz", "PListC.gz");
- }
- else
- {
- File.Move("PList.gz", "PListFirst.gz");
- }
- }
- CleanUp();
- return;
- }
- _currentFile = DownloadList.Dequeue();
- if (_currentFile.FileName == "\\Mir3AU.exe")
- {
- Download(_currentFile, "path");
- }
- else
- Download(_currentFile);
- }
- private void CleanUp()
- {
- if (!CleanFiles) return;
- string[] fileNames = Directory.GetFiles(@".\", "*.*", SearchOption.AllDirectories);
- string fileName;
- for (int i = 0; i < fileNames.Length; i++)
- {
- if (fileNames[i].StartsWith(".\\Screenshots\\")) continue;
- fileName = Path.GetFileName(fileNames[i]);
- if (fileName == "Mir3Config.ini" || fileName == System.AppDomain.CurrentDomain.FriendlyName) continue;
- try
- {
- if (!NeedFile(fileNames[i]))
- File.Delete(fileNames[i]);
- }
- catch (Exception ex) { Console.WriteLine(ex.StackTrace); }
- }
- }
- public bool NeedFile(string fileName)
- {
- for (int i = 0; i < OldList.Count; i++)
- {
- if (fileName.EndsWith(OldList[i].FileName))
- return true;
- }
- return false;
- }
- public void ParseOld(BinaryReader reader)
- {
- int count = reader.ReadInt32();
- for (int i = 0; i < count; i++)
- OldList.Add(new FileInformation(reader));
- }
- public void CheckFile(FileInformation old)
- {
- FileInformation info = GetFileInformation(Settings.P_Client + old.FileName);
- _currentCount++;
- // MessageBox.Show(info.MD5);
- if (info == null || old.MD5 != info.MD5 || old.Length != info.Length) // || old.Creation != info.Creation
- {
- if ((old.FileName.Contains("Mir3AU.exe")))
- {
- // MessageBox.Show("212121212");
- // File.Move(Settings.P_Client + System.AppDomain.CurrentDomain.FriendlyName, Settings.P_Client + oldClientName);
- Restart = true;
- }
- DownloadList.Enqueue(old);
- _totalBytes += old.Compressed;
- }
- }
- public class MD5Code
- {
- /// <summary>
- /// Get 文件的MD5校验码
- /// </summary>
- /// <param name="fileName">文件名称</param>
- /// <returns></returns>
- public static string GetMD5HashFromFile(string fileName)
- {
- var file = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);
- var md5 = new MD5CryptoServiceProvider();
- var bytes = md5.ComputeHash(file);
- file.Close();
- var sb = new StringBuilder();
- for (int i = 0; i < bytes.Length; i++)
- {
- sb.Append(bytes[i].ToString("x2"));
- }
- return sb.ToString();
- }
- }
- public static void webClientMethod1(string biaoshi)
- {
- try
- {
- WebClient MyWebClient = new WebClient();
- MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
- Byte[] pageData = MyWebClient.DownloadData("https://mp.weixin.qq.com/s/xqbnmyf42EJvbugSdeJFBg"); //从指定网站下载数据
- string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句
- int temp = pageHtml.IndexOf(biaoshi);
- string pageHtml1 = pageHtml.Substring(temp + 4, 24);
- string pageHtml2 = pageHtml.Substring(temp + 30, 24);
- string pageHtml3 = pageHtml.Substring(temp + 56, 24);
- ipgourp[0] = DecryptDES(pageHtml1, "plk05207");
- ipgourp[1] = DecryptDES(pageHtml2, "plk05207");
- ipgourp[2] = DecryptDES(pageHtml3, "plk05207");
- // MessageBox.Show(ipgourp[0] + ipgourp[1] + ipgourp[2]);
- }
- catch (WebException webEx)
- {
- Console.WriteLine(webEx.Message.ToString());
- }
- }
- /// <summary>
- /// DES加密字符串
- /// </summary>
- /// <param name="encryptString">待加密的字符串</param>
- /// <param name="encryptKey">加密密钥,要求为8位</param>
- /// <returns>加密成功返回加密后的字符串,失败返回源串 </returns>
- //public static string EncryptDES(string encryptString, string encryptKey)
- //{
- // try
- // {
- // byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));//转换为字节
- // byte[] rgbIV = Keys;
- // byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
- // DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();//实例化数据加密标准
- // MemoryStream mStream = new MemoryStream();//实例化内存流
- // //将数据流链接到加密转换的流
- // CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
- // cStream.Write(inputByteArray, 0, inputByteArray.Length);
- // cStream.FlushFinalBlock();
- // return Convert.ToBase64String(mStream.ToArray());
- // }
- // catch
- // {
- // return encryptString;
- // }
- //}
- /// <summary>
- /// DES解密字符串
- /// </summary>
- /// <param name="decryptString">待解密的字符串</param>
- /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param>
- /// <returns>解密成功返回解密后的字符串,失败返源串</returns>
- public static string DecryptDES(string decryptString, string decryptKey)
- {
- try
- {
- byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
- byte[] rgbIV = Keys;
- byte[] inputByteArray = Convert.FromBase64String(decryptString);
- DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
- MemoryStream mStream = new MemoryStream();
- CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
- cStream.Write(inputByteArray, 0, inputByteArray.Length);
- cStream.FlushFinalBlock();
- return Encoding.UTF8.GetString(mStream.ToArray());
- }
- catch
- {
- return decryptString;
- }
- }
- public void Download(FileInformation info, string path = null)
- {
- string fileName = info.FileName.Replace(@"\", "/");
- if (fileName != "PList.gz")
- fileName += ".gz";
- try
- {
- using (WebClient client = new WebClient())
- {
- client.DownloadProgressChanged += (o, e) =>
- {
- _currentBytes = e.BytesReceived;
- };
- client.DownloadDataCompleted += (o, e) =>
- {
- if (e.Error != null)
- {
- File.AppendAllText(@".\Error.txt",
- string.Format("[{0}] {1}{2}", DateTime.Now, info.FileName + " 不能下载. (" + e.Error.Message + ")", Environment.NewLine));
- ErrorFound = true;
- }
- else
- {
- _currentCount++;
- _completedBytes += _currentBytes;
- _currentBytes = 0;
- _stopwatch.Stop();
- if (!Directory.Exists(Settings.P_Client + "\\" + Path.GetDirectoryName(info.FileName)))
- Directory.CreateDirectory(Settings.P_Client + "\\" + Path.GetDirectoryName(info.FileName));
- try
- {
- File.WriteAllBytes(Settings.P_Client + "\\" + info.FileName, e.Result);
- File.SetLastWriteTime(Settings.P_Client + "\\" + info.FileName, info.Creation);
- }
- catch (System.IO.IOException ex)
- {
- Restart = true;
- File.WriteAllBytes(Settings.P_Client + "\\" + info.FileName + ".bak", e.Result);
- File.SetLastWriteTime(Settings.P_Client + "\\" + info.FileName + ".bak", info.Creation);
- File.AppendAllText(".\\updates_rename.log", Settings.P_Client + "\\" + info.FileName + "\n");
- }
- }
- BeginDownload();
- };
- if (Settings.update["NeedLogin"].Value<bool>()) client.Credentials = new NetworkCredential(Settings.update["Login"].Value<string>(), Settings.update["PassWord"].Value<string>());
- _stopwatch = Stopwatch.StartNew();
- //MessageBox.Show(Settings.update["IP"] + fileName);
- client.DownloadDataAsync(new Uri(Settings.update["IP"] + fileName));
- }
- }
- catch
- {
- MessageBox.Show(string.Format("无法下载文件: {0}", fileName));
- }
- }
- public void Download(string fileName, string filePath)
- {
- // 加上using
- using (WebClient client = new WebClient())
- {
- //MessageBox.Show(Settings.P_Host + fileName, filePath);
- // 填下载链接,和本地地址,下载完检查文件夹即可
- client.DownloadFile(Settings.P_Host + fileName, filePath);
- }
- }
- public byte[] Download(string fileName)
- {
- fileName = fileName.Replace(@"\", "/");
- if (fileName != "PList.gz")
- fileName += Path.GetExtension(fileName);
- try
- {
- using (WebClient client = new WebClient())
- {
- if (Settings.P_NeedLogin)
- client.Credentials = new NetworkCredential(Settings.P_Login, Settings.Password);
- else
- client.Credentials = new NetworkCredential("", "");
- return client.DownloadData(Settings.P_Host + Path.ChangeExtension(fileName, ".gz"));
- }
- }
- catch
- {
- return null;
- }
- }
- public static byte[] Decompress(byte[] raw)
- {
- using (GZipStream gStream = new GZipStream(new MemoryStream(raw), CompressionMode.Decompress))
- {
- const int size = 4096; //4kb
- byte[] buffer = new byte[size];
- using (MemoryStream mStream = new MemoryStream())
- {
- int count;
- do
- {
- count = gStream.Read(buffer, 0, size);
- if (count > 0)
- {
- mStream.Write(buffer, 0, count);
- }
- } while (count > 0);
- return mStream.ToArray();
- }
- }
- }
- public static byte[] Compress(byte[] raw)
- {
- using (MemoryStream mStream = new MemoryStream())
- {
- using (GZipStream gStream = new GZipStream(mStream, CompressionMode.Compress, true))
- gStream.Write(raw, 0, raw.Length);
- return mStream.ToArray();
- }
- }
- public FileInformation GetFileInformation(string fileName)
- {
- if (!File.Exists(fileName)) return null;
- FileInfo info = new FileInfo(fileName);
- return new FileInformation
- {
- FileName = fileName.Remove(0, Settings.P_Client.Length),
- Length = (int)info.Length,
- Creation = info.LastWriteTime,
- MD5 = MD5Code.GetMD5HashFromFile(fileName)
- };
- }
- private void AMain_Load(object sender, EventArgs e)
- {
- //if (Settings.P_BrowserAddress != "") Main_browser.Navigate(new Uri(Settings.P_BrowserAddress));
- webClientMethod1("列表OK");
- panel1.BackColor=Color.FromArgb(120,0, 0, 0);
- //panel1.BringToFront();
- //panel1.Top = 100;
- //panel2.BackColor = Color.FromArgb(120, 0, 0, 0);
- //webBrowser1.Navigate("file:///D:/网页/WEB/newFrame.html");
- // mir3lib.ReadMir3Stat();
- // mir3lib.Findstat(1);
- // MessageBox.Show(mir3lib.Findstat(1).Name);
- // if (File.Exists(Settings.P_Client + oldClientName)) File.Delete(Settings.P_Client + oldClientName);
- //Launch_pb.Enabled = false;
- ProgressCurrent_pb.Width = 5;
- TotalProg_pb.Width = 5;
- Version_label.Text = "Version " + Application.ProductVersion;
- if (Settings.P_ServerName != String.Empty)
- {
- Name_label.Visible = true;
- Name_label.Text = Settings.P_ServerName;
- }
- //string[] temp = { "牛转乾坤登录点一", "牛转乾坤登录点二", "牛转乾坤登录点三", "牛转乾坤登录点四", "牛转乾坤登录点五", "测试登录点", "备用登录点" };
- //serverlistbox.Items.AddRange(temp);
- //serverlistbox.Text = "牛转乾坤登录点一";
- foreach (JObject game in Settings.games)
- {
- serverlistbox.Items.Add(game["ServerName"].Value<string>());
- }
- serverlistbox.Text = Settings.games[0]["ServerName"].Value<string>();
- Settings.ServerID = Settings.games[0]["ServerID"].Value<string>();
- Settings.ServerName = Settings.games[0]["ServerName"].Value<string>();
- ResolutionComboBox.Items.Clear();
- ResolutionComboBox.Items.AddRange(Settings.Resolutions);
- ResolutionComboBox.SelectedIndex = Settings.ResolutionId;
- FullScreen_CheckBox.Checked = Settings.FullScreen;
- Windowed_CheckBox.Checked = Settings.AlwaysOnTop;
- FPSLimit_CheckBox.Checked = Settings.FPSCap;
- _workThread = new Thread(Start) { IsBackground = true };
- _workThread.Start();
- }
- private void Launch_pb_Click(object sender, EventArgs e)
- {
- Launch();
- }
- private void Launch()
- {
- if (Network.CheckIP())
- {
- //Settings.Save();
- // Settings.Load();
- //if (serverlistbox.SelectedIndex == 5)
- //{
- // Settings.partnum = 3;
- //}
- //else
- //if (serverlistbox.SelectedIndex == 6)
- //{
- // Settings.IPAddress = Settings.IPAddress5;
- //}
- //else
- //{
- // Settings.partnum = 5;
- //}
- Program.Form = new CMain();
- Program.Form.Closed += (s, args) => this.Close();
- Program.Form.Show();
- Program.PForm.Hide();
- }
- else
- {
- MessageBox.Show("服务器链接失败!");
- }
- }
- private void Movement_panel_MouseUp(object sender, MouseEventArgs e)
- {
- dragging = false;
- }
- private void Movement_panel_MouseMove(object sender, MouseEventArgs e)
- {
- if (dragging)
- {
- Location = new Point(dragFormPoint.X + MousePosition.X - dragCursorPoint.X, dragFormPoint.Y + MousePosition.Y - dragCursorPoint.Y);
- }
- }
- private void Launch_pb_MouseEnter(object sender, EventArgs e)
- {
- Launch_pb.Image = Client.Properties.Resources.Launch_Hover;
- }
- private void Launch_pb_MouseLeave(object sender, EventArgs e)
- {
- Launch_pb.Image = Client.Properties.Resources.Launch_Base1;
- }
- private void Close_pb_MouseEnter(object sender, EventArgs e)
- {
- Close_pb.Image = Client.Properties.Resources.Cross_Hover;
- }
- private void Close_pb_MouseLeave(object sender, EventArgs e)
- {
- Close_pb.Image = Client.Properties.Resources.Cross_Base;
- }
- private void Launch_pb_MouseDown(object sender, MouseEventArgs e)
- {
- Launch_pb.Image = Client.Properties.Resources.Launch_Pressed;
- }
- private void Launch_pb_MouseUp(object sender, MouseEventArgs e)
- {
- Launch_pb.Image = Client.Properties.Resources.Launch_Base1;
- }
- private void Close_pb_MouseDown(object sender, MouseEventArgs e)
- {
- Close_pb.Image = Client.Properties.Resources.Cross_Pressed;
- }
- private void Close_pb_MouseUp(object sender, MouseEventArgs e)
- {
- Close_pb.Image = Client.Properties.Resources.Cross_Base;
- }
- private void ProgressCurrent_pb_SizeChanged(object sender, EventArgs e)
- {
- ProgEnd_pb.Location = new Point((ProgressCurrent_pb.Location.X + ProgressCurrent_pb.Width), 490);
- if (ProgressCurrent_pb.Width == 0) ProgEnd_pb.Visible = false;
- else ProgEnd_pb.Visible = true;
- }
- private void Config_pb_MouseDown(object sender, MouseEventArgs e)
- {
- Config_pb.Image = Client.Properties.Resources.Config_Pressed;
- }
- private void Config_pb_MouseEnter(object sender, EventArgs e)
- {
- Config_pb.Image = Client.Properties.Resources.Config_Hover;
- }
- private void Config_pb_MouseLeave(object sender, EventArgs e)
- {
- Config_pb.Image = Client.Properties.Resources.Config_Base;
- }
- private void Config_pb_MouseUp(object sender, MouseEventArgs e)
- {
- Config_pb.Image = Client.Properties.Resources.Config_Base;
- }
- private void TotalProg_pb_SizeChanged(object sender, EventArgs e)
- {
- ProgTotalEnd_pb.Location = new Point((TotalProg_pb.Location.X + TotalProg_pb.Width), 508);
- if (TotalProg_pb.Width == 0) ProgTotalEnd_pb.Visible = false;
- else ProgTotalEnd_pb.Visible = true;
- }
- private void serverlistbox_SelectedIndexChanged(object sender, EventArgs e)
- {
- string temp = serverlistbox.SelectedItem.ToString();
- // switch (temp)
- // {
- //case "备用登录点":
- // // tempIPAddress = ipgourp[4];
- // tempIPAddress = Settings.IPAddress5;
- // break;
- //default:
- // tempIPAddress = ipgourp[0];
- // break;
- // }
- // MessageBox.Show(IPAddress, IPAddress);
- foreach (JObject game in Settings.games)
- {
- if (game["ServerName"].ToString() == temp)
- {
- Settings.ServerID = game["ServerID"].Value<string>();
- Settings.ServerName = game["ServerName"].Value<string>();
- Settings.shields = JArray.Parse(game["shields"].ToString());
- break;
- }
- }
- }
- private void Name_label_Click(object sender, EventArgs e)
- {
- if (File.Exists("PListC.gz"))
- {
- File.Delete("PListC.gz");
- }
- if (File.Exists("PListFirst.gz"))
- {
- File.Delete("PListFirst.gz");
- }
- Process.Start("Start.exe");
- Environment.Exit(0);
- }
- //private void Res1_pb_Click(object sender, EventArgs e)
- //{
- // resolutionChoice(800);
- //}
- //public void resolutionChoice(int res)
- //{
- // Res1_pb.Image = Client.Properties.Resources.Radio_Unactive;
- // Res2_pb.Image = Client.Properties.Resources.Radio_Unactive;
- // // Res3_pb.Image = Client.Properties.Resources.Radio_Unactive;
- // // Res4_pb.Image = Client.Properties.Resources.Radio_Unactive;
- // if (res == 800) Res1_pb.Image = Client.Properties.Resources.Config_Radio_On;
- // if (res == 1024) Res2_pb.Image = Client.Properties.Resources.Config_Radio_On;
- // // else if (res == 1366) Res3_pb.Image = Client.Properties.Resources.Config_Radio_On;
- // // else if (res == 1280) Res4_pb.Image = Client.Properties.Resources.Config_Radio_On;
- //}
- //private void Res2_pb_Click(object sender, EventArgs e)
- //{
- // resolutionChoice(1024);
- //}
- private void Main_browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- // if (Main_browser.Url.AbsolutePath != "blank") Main_browser.Visible = true;
- }
- private void Name_label_DoubleClick(object sender, EventArgs e)
- {
- }
- private void label10_DoubleClick(object sender, EventArgs e)
- {
- //FormResourceEditor form = new FormResourceEditor();
- //form.Show();
- }
- private void ResolutionComboBox_TextChanged(object sender, EventArgs e)
- {
- Settings.ResolutionId = ResolutionComboBox.SelectedIndex;
- }
- private void FullScreen_CheckBox_CheckedChanged(object sender, EventArgs e)
- {
- Settings.FullScreen=FullScreen_CheckBox.Checked;
- }
- private void FPSLimit_CheckBox_CheckedChanged(object sender, EventArgs e)
- {
- Settings.FPSCap = FPSLimit_CheckBox.Checked;
- }
- private void Close_pb_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- this.linkLabel1.Links[this.linkLabel1.Links.IndexOf(e.Link)].Visited = true;
- string targetUrl = e.Link.LinkData as string;
- if (string.IsNullOrEmpty(targetUrl))
- MessageBox.Show("没有链接地址!");
- else
- System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
- }
- private void Movement_panel_MouseDown(object sender, MouseEventArgs e)
- {
- dragging = true;
- dragCursorPoint =MousePosition;
- dragFormPoint = new Point(Location.X, Location.Y);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (DownloadList!=null&& DownloadList.Count<1)
- {
- Start();
- }
- }
- private void Button_CheckUpdate_Click(object sender, EventArgs e)
- {
- if (File.Exists("PListC.gz"))
- {
- File.Delete("PListC.gz");
- }
- Process.Start("Start.exe");
- Environment.Exit(0 );
- }
- private void Config_pb_Click(object sender, EventArgs e)
- {
- panel1.Visible = !panel1.Visible;
- }
- private void Name_label_MouseEnter(object sender, EventArgs e)
- {
- Name_label.ForeColor = Color.Lime;
- }
- private void Name_label_MouseLeave(object sender, EventArgs e)
- {
- Name_label.ForeColor = Color.White;
- }
- private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- this.linkLabel2.Links[this.linkLabel2.Links.IndexOf(e.Link)].Visited = true;
- string targetUrl = e.Link.LinkData as string;
- if (string.IsNullOrEmpty(targetUrl))
- MessageBox.Show("没有链接地址!");
- else
- System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
- }
- private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- this.linkLabel3.Links[this.linkLabel3.Links.IndexOf(e.Link)].Visited = true;
- string targetUrl = e.Link.LinkData as string;
- if (string.IsNullOrEmpty(targetUrl))
- MessageBox.Show("没有链接地址!");
- else
- System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
- }
- private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- this.linkLabel4.Links[this.linkLabel4.Links.IndexOf(e.Link)].Visited = true;
- string targetUrl = e.Link.LinkData as string;
- if (string.IsNullOrEmpty(targetUrl))
- MessageBox.Show("没有链接地址!");
- else
- System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
- }
- private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- this.linkLabel5.Links[this.linkLabel5.Links.IndexOf(e.Link)].Visited = true;
- string targetUrl = e.Link.LinkData as string;
- if (string.IsNullOrEmpty(targetUrl))
- MessageBox.Show("没有链接地址!");
- else
- System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
- }
- private void linkLabel6_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- this.linkLabel6.Links[this.linkLabel6.Links.IndexOf(e.Link)].Visited = true;
- string targetUrl = e.Link.LinkData as string;
- if (string.IsNullOrEmpty(targetUrl))
- MessageBox.Show("没有链接地址!");
- else
- System.Diagnostics.Process.Start("iexplore.exe", targetUrl);
- }
- private void Windowed_CheckBox_CheckedChanged(object sender, EventArgs e)
- {
- Settings.AlwaysOnTop = Windowed_CheckBox.Checked;
- }
- private void label10_Click(object sender, EventArgs e)
- {
- }
- private void InterfaceTimer_Tick(object sender, EventArgs e)
- {
- try
- {
- if (Completed)
- {
- ActionLabel.Text = "";
- CurrentFile_label.Text = "更新完毕.";
- SpeedLabel.Text = "";
- ProgressCurrent_pb.Width = 550;
- TotalProg_pb.Width = 550;
- CurrentFile_label.Visible = true;
- CurrentPercent_label.Visible = true;
- TotalPercent_label.Visible = true;
- CurrentPercent_label.Text = "100%";
- TotalPercent_label.Text = "100%";
- InterfaceTimer.Enabled = false;
- Launch_pb.Enabled = true;
- // Settings.Load();
- // Settings.Save();
- if (ErrorFound) MessageBox.Show("一个或多个文件下载失败, 请检查 Error.txt 中的错误.", "未能下载.");
- ErrorFound = false;
- if (CleanFiles)
- {
- CleanFiles = false;
- MessageBox.Show("你的文件已经被清理干净.", "清理文件");
- }
- if (Restart)
- {
- Program.Restart = true;
- // MoveOldClientToCurrent();
- // Close();
- Process.Start("Start.exe");
- System.Environment.Exit(0);
- }
- //if (Settings.P_AutoStart)
- //{
- // Launch();
- //}
- return;
- }
- ActionLabel.Visible = true;
- SpeedLabel.Visible = true;
- CurrentFile_label.Visible = true;
- CurrentPercent_label.Visible = true;
- TotalPercent_label.Visible = true;
- if (LabelSwitch) ActionLabel.Text = string.Format("{0} 剩余文件", _fileCount - _currentCount);
- else ActionLabel.Text = string.Format("{0:#,##0}MB 剩余文件", ((_totalBytes) - (_completedBytes + _currentBytes)) / 1024 / 1024);
- //ActionLabel.Text = string.Format("{0:#,##0}MB / {1:#,##0}MB", (_completedBytes + _currentBytes) / 1024 / 1024, _totalBytes / 1024 / 1024);
- if (_currentFile != null)
- {
- //FileLabel.Text = string.Format("{0}, ({1:#,##0} MB) / ({2:#,##0} MB)", _currentFile.FileName, _currentBytes / 1024 / 1024, _currentFile.Compressed / 1024 / 1024);
- CurrentFile_label.Text = string.Format("{0}", _currentFile.FileName);
- SpeedLabel.Text = (_currentBytes / 1024F / _stopwatch.Elapsed.TotalSeconds).ToString("#,##0.##") + "KB/s";
- CurrentPercent_label.Text = ((int)(100 * _currentBytes / _currentFile.Compressed)).ToString() + "%";
- ProgressCurrent_pb.Width = (int)(5.5 * (100 * _currentBytes / _currentFile.Compressed));
- }
- if (_totalBytes > 0)
- {
- TotalPercent_label.Text = ((int)(100 * (_completedBytes + _currentBytes) / _totalBytes)).ToString() + "%";
- TotalProg_pb.Width = (int)(5.5 * (100 * (_completedBytes + _currentBytes) / _totalBytes));
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.StackTrace);
- }
- }
- private void ActionLabel_Click(object sender, EventArgs e)
- {
- LabelSwitch = !LabelSwitch;
- }
- private void Credit_label_Click(object sender, EventArgs e)
- {
- if (Credit_label.Text == "www.mir3.com") Credit_label.Text = "QQ:暂不开放";
- else Credit_label.Text = "www.mir3.com";
- }
- private void AMain_FormClosed(object sender, FormClosedEventArgs e)
- {
- // MoveOldClientToCurrent();
- }
- //private void MoveOldClientToCurrent()
- //{
- // string oldClient = Settings.P_Client + oldClientName;
- // string currentClient = Settings.P_Client + System.AppDomain.CurrentDomain.FriendlyName;
- // if (!File.Exists(currentClient) && File.Exists(oldClient))
- // File.Move(oldClient, currentClient);
- //}
- private bool checkonline(string ipstring, int prot)
- {
- IPAddress ip = IPAddress.Parse(ipstring);
- // IPEndPoint point = new IPEndPoint(ip, prot);
- // bool success = ar.AsyncWaitHandle.WaitOne(1000);
- // if (!success)
- // throw new Exception("超时时间已到,未连接到指定服务器");
- // try
- //{
- TcpClient tcp = new TcpClient();
- IAsyncResult ar = tcp.BeginConnect(ip, Settings.Port, null, null);
- bool success = ar.AsyncWaitHandle.WaitOne(200);
- // tcp.Connect(point);
- //tcp.Close();
- // temp= true;
- // }
- //catch (Exception)
- // {
- // }
- return success;
- }
- }
- public class FileInformation
- {
- public string FileName; //Relative. 文件名
- public int Length, Compressed;
- public DateTime Creation;
- public string MD5;
- public FileInformation()
- {
- }
- public FileInformation(BinaryReader reader)
- {
- FileName = reader.ReadString();
- MD5 = reader.ReadString();
- Length = reader.ReadInt32();
- Compressed = reader.ReadInt32();
- Creation = DateTime.FromBinary(reader.ReadInt64());
- }
- public void Save(BinaryWriter writer)
- {
- writer.Write(FileName);
- writer.Write(MD5);
- writer.Write(Length);
- writer.Write(Compressed);
- writer.Write(Creation.ToBinary());
- }
- }
- }
|