public void CreateDownloadTask(string DownloadName, DownloadConfig Dc, bool AdvancedConfig, bool IsRestore) { DownloadProgressBar Dpb = new DownloadProgressBar(); Dc.OnReportProgressEvent += Dpb.OnDownloadProgress; Dc.OnDownloadFinishedEvent += Dpb.OnDownloadFinished; Dc.OnStateChangedEvent += Dpb.OnStateChanged; var TargetDownloader = new ContentDownloader(); Program.DownloaderInstances.Add(TargetDownloader); Dpb.RestartDownload += TargetDownloader.RestartDownload; Dpb.StopDownload += TargetDownloader.StopDownload; Dpb.CancelDownload += this.CancelDownload; Dpb.OnDownloadFinishedReport += this.OnDownloadFinished; Dpb.InitDownloading(DownloadName, Dc.AppID, Dc.DepotID, Dc.Branch); this.panelDownloading.Controls.Add(Dpb); RegroupDownloadProgressControl(); if (!IsRestore) { DownloadRecord Dr = new DownloadRecord(); Dr.AppID = Dc.AppID; Dr.DepotID = Dc.DepotID; Dr.BranchName = Dc.Branch; Dr.FileToDownload = AllowFileList; Dr.InstallDir = InstallDir; Dr.NoForceDepot = !Dc.ForceDepot; Dr.DownloadName = DownloadName; Dr.MaxDownload = Dc.MaxDownloads; Dr.MaxServer = Dc.MaxServers; Dr.AllPlatforms = Dc.DownloadAllPlatforms; Dr.AdvancedConfig = AdvancedConfig; Dr.ManifestID = Dc.ManifestId; if (Dc.FilesToDownloadRegex != null) { Dr.FileRegex = new List <string>(); foreach (System.Text.RegularExpressions.Regex Fileregex in Dc.FilesToDownloadRegex) { Dr.FileRegex.Add(Fileregex.ToString()); } } ConfigStore.TheConfig.DownloadRecord.Add(Dr); ConfigStore.Save(); } TargetDownloader.Config = Dc; if (!IsRestore) { TargetDownloader.RestartDownload(); } else { Dpb.Downloading = false; } }