Exemplo n.º 1
0
        private List <PatchInformation> CreateVersion(IProgress <string> progress)
        {
            try
            {
                string[] files = Directory.GetFiles(Config.CleanClient, "*.*", SearchOption.AllDirectories);

                PatchInformation[] list = new PatchInformation[files.Length];
                ParallelOptions    po   = new ParallelOptions {
                    MaxDegreeOfParallelism = 8
                };
                int count = 0;
                Parallel.For(0, files.Length, po, i =>
                {
                    list[i] = new PatchInformation(files[i]);
                    progress.Report($"Version Created: File {Interlocked.Increment(ref count)} of {files.Length}");
                });

                return(list.ToList());
            }
            catch (Exception ex)
            {
                progress.Report(ex.Message);
            }

            return(null);
        }
Exemplo n.º 2
0
        private void UploadPatch(List <PatchInformation> patch, IProgress <string> progress)
        {
            for (int i = 0; i < patch.Count; i++)
            {
                PatchInformation file = patch[i];

                if (!Upload(file, progress))
                {
                    Error = true;
                    return;
                }

                progress.Report($"Files Uploaded: {i + 1} of {patch.Count}");
            }
        }
Exemplo n.º 3
0
        private bool Upload(PatchInformation file, IProgress <string> progress)
        {
            string webFileName = file.FileName.Replace("\\", "-") + ".gz";

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

                    bool uploading = true;
                    client.UploadProgressChanged += (o, e) => CurrentProgress = e.BytesSent;
                    client.UploadFileCompleted   += (o, e) =>
                    {
                        File.Delete($".\\Patch\\{webFileName}");
                        uploading = false;
                    };

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

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

                    while (uploading)
                    {
                        Task.Delay(TimeSpan.FromMilliseconds(1));
                    }

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

                return(true);
            }
            catch (Exception ex)
            {
                progress.Report(ex.Message);
            }

            return(false);
        }
Exemplo n.º 4
0
        private List <PatchInformation> CalculatePatch(List <PatchInformation> current, List <PatchInformation> live, IProgress <string> progress)
        {
            List <PatchInformation> patch = new List <PatchInformation>();

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

            int count = 0;

            Parallel.For(0, current.Count, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, i =>
            {
                PatchInformation file  = current[i];
                PatchInformation lFile = live?.FirstOrDefault(x => x.FileName == file.FileName);

                if (lFile != null && IsMatch(lFile.CheckSum, file.CheckSum))
                {
                    file.CompressedLength = lFile.CompressedLength;
                    return;
                }

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

                string webFileName = file.FileName.Replace("\\", "-") + ".gz";

                file.UploadFileName = ".\\Patch\\" + webFileName;
                file.PatchFileName  = Path.Combine(Directory.GetCurrentDirectory(), $"Patch\\{webFileName}");

                file.CompressedLength = Compress(Config.CleanClient + file.FileName, file.PatchFileName);
                Interlocked.Add(ref TotalUpload, file.CompressedLength);

                lock (patch)
                    patch.Add(file);

                progress.Report($"File Created: {Interlocked.Increment(ref count)} of {current.Count}");
            });

            return(patch);
        }