Ejemplo n.º 1
0
        private bool Download(PatchInformation file)
        {
            string webFileName = file.FileName.Replace("\\", "-") + ".gz";

            try
            {
                using (WebClient client = new WebClient())
                {
                    if (Config.UseLogin)
                    {
                        client.Credentials = new NetworkCredential(Config.Username, Config.Password);
                    }

                    bool downloading = true;
                    client.DownloadProgressChanged += (o, e) => CurrentProgress = e.BytesReceived;
                    client.DownloadFileCompleted   += (o, e) => downloading = false;

                    if (!Directory.Exists(ClientPath + "Patch\\"))
                    {
                        Directory.CreateDirectory(ClientPath + "Patch\\");
                    }

                    client.DownloadFileAsync(new Uri(Config.Host + webFileName), $"{ClientPath}Patch\\{webFileName}");

                    while (downloading)
                    {
                        Thread.Sleep(1);
                    }

                    CurrentProgress = 0;
                    TotalProgress  += file.CompressedLength;
                }

                return(true);
            }
            catch (Exception)
            {
                file.CheckSum = new byte[8];
            }

            return(false);
        }
Ejemplo n.º 2
0
        private List <PatchInformation> CalculatePatch(IReadOnlyList <PatchInformation> list, List <PatchInformation> current, IProgress <string> progress)
        {
            List <PatchInformation> patch = new List <PatchInformation>();

            if (list == null)
            {
                return(patch);
            }

            for (int i = 0; i < list.Count; i++)
            {
                progress.Report($"Files Checked: {i + 1} of {list.Count}");

                PatchInformation file = list[i];
                if (current != null && current.Any(x => x.FileName == file.FileName && IsMatch(x.CheckSum, file.CheckSum)))
                {
                    continue;
                }

                if (File.Exists(ClientPath + file.FileName))
                {
                    byte[] CheckSum;
                    using (MD5 md5 = MD5.Create())
                    {
                        using (FileStream stream = File.OpenRead(ClientPath + file.FileName))
                            CheckSum = md5.ComputeHash(stream);
                    }

                    if (IsMatch(CheckSum, file.CheckSum))
                    {
                        continue;
                    }
                }

                patch.Add(file);
                TotalDownload += file.CompressedLength;
            }

            return(patch);
        }
Ejemplo n.º 3
0
        private void Extract(PatchInformation file)
        {
            string webFileName = file.FileName.Replace("\\", "-") + ".gz";

            try
            {
                string toPath = ClientPath + file.FileName;

                if (Application.ExecutablePath.EndsWith(file.FileName, StringComparison.OrdinalIgnoreCase))
                {
                    toPath    += ".tmp";
                    NeedUpdate = true;
                }


                if (File.Exists(toPath))
                {
                    File.Delete(toPath);
                }

                Decompress($"{ClientPath}Patch\\{webFileName}", toPath);
            }
            catch (UnauthorizedAccessException ex)
            {
                file.CheckSum = new byte[8];

                if (HasError)
                {
                    return;
                }
                HasError = true;
                MessageBox.Show(ex.Message + "\n\nFile might be in use, please make sure the game is closed.", "File Error", MessageBoxButtons.OK);
            }
            catch
            {
                file.CheckSum = new byte[8];
            }
        }