Beispiel #1
0
        public void Download()
        {
            Logger.Info("Beginning download of {0} to {1}", url, localFile);

            using (FileStream output = new FileStream(localFile, FileMode.Create))
            {
                using (var wc = new WebClient())
                {
                    using (var input = wc.OpenRead(url))
                    {
                        s.Start();
                        byte[] buffer = new byte[4096];
                        int    read;
                        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            tok.ThrowIfCancellationRequested();

                            output.Write(buffer, 0, read);
                            totalRead += read;
                        }

                        s.Stop();
                    }
                }
            }

            Logger.Info("Download of {0} complete, average speed {1}/s", localFile, ByteSizeHelper.ToString(fSize / s.Elapsed.TotalSeconds));
        }
Beispiel #2
0
        public void Copy()
        {
            Directory.CreateDirectory(Path.GetDirectoryName(dst));

            Logger.Info("Copying from {0} to {1}", src, dst);

            using (var output = new FileStream(dst, FileMode.Create))
            {
                using (var input = new FileStream(src, FileMode.Open))
                {
                    fSize = input.Length;
                    s.Start();
                    byte[] buffer = new byte[4096];
                    int    read;
                    while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        tok.ThrowIfCancellationRequested();

                        output.Write(buffer, 0, read);
                        totalRead += read;
                    }

                    s.Stop();
                }
            }

            Logger.Info("Finished copying to {0}. Speed: {1}/s", dst, ByteSizeHelper.ToString(fSize / s.Elapsed.TotalSeconds));
        }
Beispiel #3
0
 public override string ToString()
 {
     return(string.Format("{0}, {1} files, {2}", PatchName, Files.Count, ByteSizeHelper.ToString(PatchSize)));
 }
Beispiel #4
0
 public override string ToString()
 {
     return(string.Format("Sequence from {0} to {1}. {2} files. Total size: {3}", StartVersion, EndVersion, Patches.Sum(p => p.Files.Count), ByteSizeHelper.ToString(Size)));
 }
Beispiel #5
0
        private void downloadAndExtractLanguage(PatchInfo info)
        {
            Logger.Info("Beginning download of language pack to {0}", info.LanguageFilePath);

            string message = "Downloading language pack at {0}/s";

            ui.SetMainProgressDisplay(0, string.Format(message, 0, info.Files.Count, "0b"), true);

            var stopwatch = new System.Diagnostics.Stopwatch();

            byte[] buffer = new byte[4096];
            int    read, totalRead = 0;

            string url = PatchInfo.MainFtp;

            if (!url.EndsWith("/"))
            {
                url += "/";
            }
            url += info.EndVersion + "/" + info.EndVersion + "_language.p_";


            using (var output = new FileStream(info.LanguageFilePath, FileMode.Create))
            {
                using (var wc = new WebClient())
                {
                    using (var input = wc.OpenRead(url))
                    {
                        stopwatch.Start();

                        System.Threading.Timer t = new System.Threading.Timer((o) =>
                                                                              { ui.SetMainProgressDisplay(text: string.Format(message, ByteSizeHelper.ToString(totalRead / stopwatch.Elapsed.TotalSeconds)), indeterminate: true); },
                                                                              null, 200, 200);

                        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            ui.tokenSource.Token.ThrowIfCancellationRequested();

                            output.Write(buffer, 0, read);
                            totalRead += read;
                        }

                        stopwatch.Stop();

                        t.Change(Timeout.Infinite, Timeout.Infinite);
                        t.Dispose();
                    }
                }
            }

            Logger.Info("Download complete. Speed: {0}/s", ByteSizeHelper.ToString(totalRead / stopwatch.Elapsed.TotalSeconds));

            Logger.Info("Extracting language pack to {0}", info.LanguageContentDir);
            ui.SetMainProgressDisplay(0, "Extracting language pack");

            using (var zip = ZipFile.Read(info.LanguageFilePath))
            {
                zip.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
                zip.ExtractAll(info.LanguageContentDir);
            }

            ui.tokenSource.Token.ThrowIfCancellationRequested();

            Logger.Info("Extraction complete");
        }
Beispiel #6
0
        private void combineFiles(PatchInfo info)
        {
            Logger.Info("Beginning file combine");

            string message = "Combining patch files... {0} out of {1} at {2}/s";

            ui.SetMainProgressDisplay(0, string.Format(message, 0, info.Files.Count, "0b"));

            var stopwatch = new System.Diagnostics.Stopwatch();

            byte[] buffer = new byte[4096];
            int    read, completed = 0;
            long   totalRead = 0;

            Logger.Info("Opening {0} for output", info.ZipFilePath);

            using (FileStream output = new FileStream(info.ZipFilePath, FileMode.Create))
            {
                stopwatch.Start();
                System.Threading.Timer t = new System.Threading.Timer((o) =>
                                                                      { ui.SetMainProgressDisplay((int)((completed / (double)info.Files.Count) * 100), string.Format(message, completed, info.Files.Count, ByteSizeHelper.ToString(totalRead / stopwatch.Elapsed.TotalSeconds))); },
                                                                      null, 200, 200);

                foreach (var file in info.Files)
                {
                    Logger.Info("Adding {0}", file.Filename);
                    using (FileStream input = new FileStream(Path.Combine(info.PatchName, file.Filename), FileMode.Open))
                    {
                        while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            ui.tokenSource.Token.ThrowIfCancellationRequested();

                            output.Write(buffer, 0, read);
                            totalRead += read;
                        }
                    }
                    completed++;
                }

                t.Change(Timeout.Infinite, Timeout.Infinite);
                t.Dispose();
            }

            Logger.Info("Patch combine success");

            ui.SetMainProgressDisplay(100, string.Format(message, info.Files.Count, info.Files.Count, ""));
        }