Ejemplo n.º 1
0
        private void DownloadNextFile()
        {
            string dir = Directory.GetCurrentDirectory() + "\\UpdateFiles";

            if (filesDownloaded == filesToDownload.Count)
            {
                progressBar.Visible    = false;
                downloadButton.Visible = false;
                //updateInfoBox.Visible = false;

                updateInfoText.Text = "Installing update...";

                try
                {
                    UpdaterUtil.InstallUpdatedFiles(dir);
                }

                catch (Exception e)
                {
                    updateInfoText.Text = "Update failed";
                    ShowError("Error while installing the update", e.Message);

                    launchButton.Enabled = true;
                    return;
                }

                settings.WasGameUpdated = true;

                UpdaterUtil.CleanUnnecessaryFiles(latestVersionFiles);

                updateInfoText.Text  = "The game was updated succesfully!";
                launchButton.Enabled = true;

                //MessageBox.Show("Download completed!");
                return;
            }

            updateInfoText.Text = "Downloading file " + filesDownloaded + "/" + filesToDownloadCount;

            GUITextBlock textBlock = new GUITextBlock(
                new Rectangle(0, 0, 0, 17),
                "Downloading " + filesToDownload[filesDownloaded] + "...", "",
                Alignment.TopLeft, Alignment.TopLeft,
                updateInfoBox, false, GUI.SmallFont);

            textBlock.CanBeFocused = false;

            updateInfoBox.BarScroll = 1.0f;

            WebClient webClient = new WebClient();

            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string fileDir = dir + "\\" + Path.GetDirectoryName(filesToDownload[filesDownloaded]);

            if (!string.IsNullOrWhiteSpace(fileDir) && !Directory.Exists(fileDir))
            {
                Directory.CreateDirectory(fileDir);
            }

            webClient.DownloadFileAsync(new Uri(latestVersionFolder + filesToDownload[filesDownloaded]), @dir + "\\" + filesToDownload[filesDownloaded]);
        }