Exemplo n.º 1
0
        /// <summary>
        /// Main download method.
        /// </summary>
        public void Download()
        {
            try {
                finished = true;
                foreach (IDownloadable download in downloadQueue)
                {
                    string source      = download.Location;
                    string destination = Path.Combine(Config.InstallPath, "Versions", download.ToString());
                    currentFilepath = $"{destination}.zip";

                    Program.Launcher.UpdateStatus($"Downloading {download}");
                    Directory.CreateDirectory(destination);

                    // Download
                    HttpWebResponse fileresp = GetResponse(download.Location);
                    if (fileresp.ContentLength <= 0)
                    {
                        MessageBox.Show($"Could not access file {download}. Package skipped.");
                        continue;
                    }

                    if (!StreamFile(fileresp, download))
                    {
                        finished = false;
                        MessageBox.Show("The download couldn't be completed. Check your internet connection. If you think this is a program error, please report this to the Launcher's GitHub page.");
                        break;
                    }

                    // Extraction
                    if (!ExtractDownload(download, destination))
                    {
                        continue;
                    }

                    // Patching
                    if (!PatchDownload(download, destination))
                    {
                        continue;
                    }
                }

                if (finished)
                {
                    QueueComplete?.Invoke(this, new EventArgs());
                }
            } catch (ThreadAbortException) { } catch (ThreadInterruptedException) { } catch (Exception e) {
                new ErrorCatcher(e).ShowDialog();
                Aborted?.Invoke(this, new EventArgs());
            }
        }
 private void OnQueueComplete()
 {
     QueueComplete?.Invoke(this, EventArgs.Empty);
 }