Example #1
0
        public Task DownloadPackagesAsync(List <DatabasePackage> packagesToDownload)
        {
            if (string.IsNullOrEmpty(UrlBase))
            {
                throw new BadMemeException("UrlBase is empty/null");
            }

            if (string.IsNullOrEmpty(DownloadLocationBase))
            {
                throw new BadMemeException("DownloadLocationBase is empty/null");
            }

            if (Progress == null)
            {
                Logging.Warning("Progress is null, no progress will be reported for this download operation");
            }

            if (CancellationToken == null)
            {
                Logging.Warning("CancellationToken is null, no cancellations will be acknowledged for this download operation");
            }

            downloadProgress = new RelhaxDownloadProgress()
            {
                ParrentTotal = packagesToDownload.Count
            };

            return(Task.Run(() => {
                //load md5 database manager before downloading packages
                if (!databaseManager.DatabaseLoaded)
                {
                    databaseManager.LoadMd5Database(ApplicationConstants.MD5HashDatabaseXmlFile);
                }

                for (int i = 0; i < packagesToDownload.Count; i++)
                {
                    DatabasePackage package = packagesToDownload[i];
                    Logging.Info(LogOptions.ClassName, "Download {0} of {1}, package {2} start", i + 1, packagesToDownload.Count, package.PackageName);
                    Logging.Debug(LogOptions.ClassName, "Download of package {0} from formed URL {1}", package.PackageName, UrlBase + package.ZipFile);
                    DownloadPackage(package);
                    Logging.Info(LogOptions.ClassName, "Download {0} of {1}, package {2} finish", i + 1, packagesToDownload.Count, package.PackageName);
                }
            }));
        }
Example #2
0
        public void OnReportDownload(RelhaxDownloadProgress progress)
        {
            if (lastRelhaxInstallerProgressExtraction.WaitingOnDownloadsOfAThread == null)
            {
                return;
            }

            int indexWaitingOnDownload = 0;

            foreach (bool b in lastRelhaxInstallerProgressExtraction.WaitingOnDownloadsOfAThread)
            {
                if (b)
                {
                    break;
                }
                indexWaitingOnDownload++;
            }
            if (indexWaitingOnDownload >= lastRelhaxInstallerProgressExtraction.WaitingOnDownloadsOfAThread.Length)
            {
                return;
            }

            ExtractionModsReporters[indexWaitingOnDownload].TaskMinimum = 0;
            ExtractionModsReporters[indexWaitingOnDownload].TaskMaximum = progress.ChildTotal;
            ExtractionModsReporters[indexWaitingOnDownload].TaskValue   = progress.ChildCurrent;

            //break it up into lines cause it's hard to read
            //"downloading package_name"
            string line1 = string.Format("{0} {1}", Translations.GetTranslatedString("Downloading"), progress.DatabasePackage.PackageName);

            //"zip_file_name"
            string line2 = progress.DatabasePackage.ZipFile;

            //https://stackoverflow.com/questions/9869346/double-string-format
            //"2MB of 8MB"
            string line3 = string.Format("{0} {1} {2}", FileUtils.SizeSuffix((ulong)progress.ChildCurrent, 1, true), Translations.GetTranslatedString("of"), FileUtils.SizeSuffix((ulong)progress.ChildTotal, 1, true));

            //also report to the download message process
            ExtractionModsReporters[indexWaitingOnDownload].TaskText = string.Format("{0}\n{1}\n{2}", line1, line2, line3);
        }