コード例 #1
0
 public void RemoveProgressReporter(ProgressReporter reporter)
 {
     if (InvokeRequired)
     {
         Invoke(new Action <ProgressReporter>(RemoveProgressReporter), reporter);
     }
     else
     {
         progressContainer.Controls.Remove(reporter);
     }
 }
コード例 #2
0
ファイル: Patcher.cs プロジェクト: Hyddwn/powerpatcher
        private void downloadFiles(PatchInfo info, List <PatchFileInfo> files)
        {
            Logger.Info("Beginning download of {0} files: [{1}]", files.Count, string.Join(", ", files.Select(f => f.Filename)));

            ui.SetMainProgressDisplay(0, "Downloading files...");

            var tasks = new List <Action>();

            int completed = 0;

            foreach (var file in files)
            {
                string url = PatchInfo.MainFtp;
                if (!url.EndsWith("/"))
                {
                    url += "/";
                }
                url += info.EndVersion + "/" + file.RemoteName;

                var dl       = new FileDownloader(url, Path.Combine(info.PatchName, file.Filename), file.Size, ui.tokenSource.Token);
                var reporter = new ProgressReporter()
                {
                    Reporter = dl
                };

                tasks.Add(() =>
                {
                    ui.AddProgressReporter(reporter);

                    try
                    {
                        dl.Download();

                        ui.SetMainProgressDisplay(progressPercent: (int)((Interlocked.Increment(ref completed) / (double)(files.Count)) * 100), text: "Downloading files... " + completed + " / " + files.Count);
                    }
                    finally
                    {
                        ui.RemoveProgressReporter(reporter);
                    }
                });
            }

            Parallel.Invoke(new ParallelOptions()
            {
                MaxDegreeOfParallelism = 10, CancellationToken = ui.tokenSource.Token
            }, tasks.ToArray());

            Logger.Info("All downloads complete");
        }
コード例 #3
0
 public void AddProgressReporter(ProgressReporter reporter)
 {
     if (InvokeRequired)
     {
         Invoke(new Action <ProgressReporter>(AddProgressReporter), reporter);
     }
     else
     {
         try
         {
             progressContainer.Controls.Add(reporter);
             reporter.Width = progressContainer.Width - 2;
         }
         catch { }
     }
 }
コード例 #4
0
ファイル: Patcher.cs プロジェクト: Hyddwn/powerpatcher
        private void copy(PatchInfo info)
        {
            Logger.Info("Preparing to copy patch files");
            ui.SetMainProgressDisplay(0, "Copying patch files...");

            var dst   = Environment.CurrentDirectory;
            var src   = info.ContentDirectory;
            var files = Directory.GetFiles(src, "*", SearchOption.AllDirectories);

            Logger.Info("Files to copy: [{0}]", string.Join(", ", files.Select(f => Path.GetFileName(f))));

            int completed = 0;

            var tasks = new List <Action>();

            foreach (var file in files)
            {
                FileCopier       copier   = new FileCopier(file, file.Replace(src, dst), ui.tokenSource.Token);
                ProgressReporter reporter = new ProgressReporter()
                {
                    Reporter = copier
                };

                tasks.Add(() =>
                {
                    ui.AddProgressReporter(reporter);

                    try
                    {
                        copier.Copy();

                        ui.SetMainProgressDisplay(progressPercent: (int)((Interlocked.Increment(ref completed) / (double)(files.Length)) * 100), text: "Copying patch files... " + completed + " / " + files.Length);
                    }
                    finally
                    {
                        ui.RemoveProgressReporter(reporter);
                    }
                });
            }

            Parallel.Invoke(new ParallelOptions()
            {
                MaxDegreeOfParallelism = 10, CancellationToken = ui.tokenSource.Token
            }, tasks.ToArray());

            Logger.Info("Copy done");
        }