Beispiel #1
0
        protected override async Task DownloadImplementation()
        {
            string[] roots = Directory.GetDirectories(Directory.GetCurrentDirectory() + "\\" + Properties.Settings.Default.GameDirectory);
            if (roots.Length > 1)
            {
                throw new DirectoryNotFoundException(message: string.Format("Multiple roots:\n{0}", string.Join("\n", roots)));
            }
            if (roots.Length == 0)
            {
                ShowError("There are no files inside your installation directory.");
                throw new DirectoryNotFoundException();
            }
            string root = roots[0];

            foreach (string file in oldPath)
            {
                var fileInfo = new FileInfo(root + "\\" + file);
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }
            }
            double n_file     = newPath.Count;
            int    downloaded = 0;

            using (var webClient = new WebClient())
            {
                foreach (string file in newPath)
                {
                    string url = this.url + file;
                    System.Diagnostics.Debug.WriteLine(file);
                    System.Diagnostics.Debug.WriteLine(root + "\\" + file.Replace("/", "\\"));
                    System.Diagnostics.Debug.WriteLine(url);
                    var fileInfo = new FileInfo(root + "\\" + file.Replace("/", "\\"));
                    if (fileInfo.Exists)
                    {
                        fileInfo.Delete();
                    }
                    if (fileInfo.Directory.Exists == false)
                    {
                        fileInfo.Directory.Create();
                    }
                    try
                    {
                        await webClient.DownloadFileTaskAsync(url, root + "\\" + file.Replace("/", "\\"));
                    }
                    catch (WebException)
                    {
                        // The file is in newPath but it has been mooved or deleted in a future commit, so it cannot be downloaded, just do nothing
                    }
                    downloaded++;
                    ShowProgress(downloaded / n_file * 100);
                }
            }
            Properties.Settings.Default.Version       = (await handler.GetLatestRelease()).Tag;
            Properties.Settings.Default.CurrentCommit = (await handler.GetLatestRelease()).Commit;
            Properties.Settings.Default.Save();
            PhpManager.UpdateVersion((await handler.GetLatestRelease()).Tag);
        }
Beispiel #2
0
        private async Task MainLogic(bool isToUpdate, bool isServerReachable, string myVer)
        {
            if (IsGameInstalled())
            {
                // Yes, it is installed. There is an update available?
                if (isToUpdate)
                {
                    // Yes, there is an update. So get info about the last release, and change the button into an Update Button.
                    (string url, string commit, string tag) = await updateHandler.GetLatestRelease();

                    GradientStopCollection c = new GradientStopCollection
                    {
                        new GradientStop(Color.FromArgb(255, 27, 134, 255), 0),
                        new GradientStop(Color.FromArgb(255, 55, 170, 255), 0.3),
                        new GradientStop(Color.FromArgb(255, 55, 170, 255), 0.7),
                        new GradientStop(Color.FromArgb(255, 27, 134, 255), 1.0)
                    };
                    LinearGradientBrush b = new LinearGradientBrush(c)
                    {
                        StartPoint = new Point(0.5, 0),
                        EndPoint   = new Point(0.5, 1)
                    };
                    this.button.Background = b;
                    this.button.Content    = Properties.Langs.Lang.update;
                    RemoveRoutedEventHandlers(this.button, Button.ClickEvent);
                    this.button.Click += async(s, ee) =>
                    {
                        (List <string> oldPath, List <string> newPath) = await updateHandler.Compare(commit);

                        await new UpdateDownloader(this, String.Format(Properties.Resources.UpdateUrl, tag), oldPath, newPath, updateHandler).Download();
                        InitPlayButton();
                    };
                    this.infoLabel.Content = String.Format(Properties.Langs.Lang.version_available, tag);
                }
                else
                // No, the game is installed but there are not any updates. So initialise the Play Button.
                {
                    this.infoLabel.Content = String.Format(Properties.Langs.Lang.version, myVer);
                    InitPlayButton();
                    if (isServerReachable)
                    {
                        this.infoLabel.Content += Properties.Langs.Lang.last_version_av;
                    }
                    else
                    {
                        this.infoLabel.Content += Properties.Langs.Lang.update_not_possible;
                    }
                }
            }
            // No, the game is not installed. Is it possible to connect to the repository?
            else if (isServerReachable)
            {
                // Yes, it is possible to connect to the repository. So, initialize Download Button.
                RemoveRoutedEventHandlers(this.button, Button.ClickEvent);
                this.button.Click     += DownloadAndInstall;
                this.infoLabel.Content = "";
                GradientStopCollection c = new GradientStopCollection
                {
                    new GradientStop(Color.FromArgb(255, 27, 134, 255), 0),
                    new GradientStop(Color.FromArgb(255, 55, 170, 255), 0.3),
                    new GradientStop(Color.FromArgb(255, 55, 170, 255), 0.7),
                    new GradientStop(Color.FromArgb(255, 27, 134, 255), 1.0)
                };
                LinearGradientBrush b = new LinearGradientBrush(c)
                {
                    StartPoint = new Point(0.5, 0),
                    EndPoint   = new Point(0.5, 1)
                };
                this.button.Background = b;
                //delete eventually corrupeted archive
                if (File.Exists(Directory.GetCurrentDirectory() + "\\" + FILE_NAME + ".zip"))
                {
                    File.Delete(Directory.GetCurrentDirectory() + "\\" + FILE_NAME + ".zip");
                }
            }
            else
            {
                // No. The game is not installed and it is not possible to install it. Nothing can be done at the moment.
                this.BarGrid.Visibility = Visibility.Collapsed;
                this.button.Visibility  = Visibility.Collapsed;
                this.infoLabel.Content  = Properties.Langs.Lang.download_not_possible;
            }
        }