Example #1
0
 private void InvokeRemove(Version v)
 {
     Task.Run(async() =>
     {
         v.StateChangeInfo = new VersionStateChangeInfo();
         v.StateChangeInfo.IsUninstalling = true;
         await UnregisterPackage(Path.GetFullPath(v.GameDirectory));
         Directory.Delete(v.GameDirectory, true);
         v.StateChangeInfo = null;
         v.UpdateInstallStatus();
     });
 }
Example #2
0
        private void InvokeDownload(Version v)
        {
            CancellationTokenSource cancelSource = new CancellationTokenSource();

            v.StateChangeInfo = new VersionStateChangeInfo();
            v.StateChangeInfo.IsInitializing = true;
            v.StateChangeInfo.CancelCommand  = new RelayCommand((o) => cancelSource.Cancel());

            Debug.WriteLine("Download start");
            Task.Run(async() =>
            {
                string dlPath = "Minecraft-" + v.Name + ".Appx";
                VersionDownloader downloader = _anonVersionDownloader;
                if (v.IsBeta)
                {
                    downloader = _userVersionDownloader;
                    if (Interlocked.CompareExchange(ref _userVersionDownloaderLoginTaskStarted, 1, 0) == 0)
                    {
                        _userVersionDownloaderLoginTask.Start();
                    }
                    Debug.WriteLine("Waiting for authentication");
                    try
                    {
                        await _userVersionDownloaderLoginTask;
                        Debug.WriteLine("Authentication complete");
                    }
                    catch (Exception e)
                    {
                        v.StateChangeInfo = null;
                        Debug.WriteLine("Authentication failed:\n" + e.ToString());
                        MessageBox.Show("Failed to authenticate. Please make sure your account is subscribed to the beta programme.\n\n" + e.ToString(), "Authentication failed");
                        return;
                    }
                }
                try
                {
                    await downloader.Download(v.UUID, "1", dlPath, (current, total) =>
                    {
                        if (v.StateChangeInfo.IsInitializing)
                        {
                            IsDownloading = true;
                            OnGameStateChanged(GameStateArgs.Empty);
                            Debug.WriteLine("Actual download started");
                            v.StateChangeInfo.IsInitializing = false;
                            if (total.HasValue)
                            {
                                v.StateChangeInfo.TotalSize = total.Value;
                            }
                        }
                        v.StateChangeInfo.DownloadedBytes = current;
                    }, cancelSource.Token);
                    Debug.WriteLine("Download complete");
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Download failed:\n" + e.ToString());
                    if (!(e is TaskCanceledException))
                    {
                        MessageBox.Show("Download failed:\n" + e.ToString());
                    }
                    v.StateChangeInfo = null;
                    IsDownloading     = false;
                    return;
                }
                try
                {
                    Debug.WriteLine("Extraction started");
                    v.StateChangeInfo.IsExtracting = true;
                    string dirPath = v.GameDirectory;
                    if (Directory.Exists(dirPath))
                    {
                        Directory.Delete(dirPath, true);
                    }
                    ZipFile.ExtractToDirectory(dlPath, dirPath);
                    v.StateChangeInfo = null;
                    File.Delete(Path.Combine(dirPath, "AppxSignature.p7x"));
                    File.Delete(dlPath);
                    Debug.WriteLine("Extracted successfully");
                    InvokeLaunch(v);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Extraction failed:\n" + e.ToString());
                    MessageBox.Show("Extraction failed:\n" + e.ToString());
                    v.StateChangeInfo = null;
                    IsDownloading     = false;
                    return;
                }
                v.StateChangeInfo = null;
                v.UpdateInstallStatus();
                OnGameStateChanged(GameStateArgs.Empty);
            });
        }
Example #3
0
        private void InvokeLaunch(Version v)
        {
            if (HasLaunchTask)
            {
                OnGameStateChanged(GameStateArgs.Empty);
                return;
            }
            else
            {
                HasLaunchTask = true;
                OnGameStateChanged(GameStateArgs.Empty);
            }

            Task.Run(async() =>
            {
                SetInstallationDataPath();
                v.StateChangeInfo             = new VersionStateChangeInfo();
                v.StateChangeInfo.IsLaunching = true;
                string gameDir = Path.GetFullPath(v.GameDirectory);
                try
                {
                    await ReRegisterPackage(gameDir);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("App re-register failed:\n" + e.ToString());
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ErrorScreenShow.errormsg("appregistererror");
                    });
                    HasLaunchTask = false;
                    OnGameStateChanged(GameStateArgs.Empty);
                    v.StateChangeInfo = null;
                    return;
                }
                try
                {
                    var pkg = await AppDiagnosticInfo.RequestInfoForPackageAsync(MINECRAFT_PACKAGE_FAMILY);
                    if (pkg.Count > 0)
                    {
                        await pkg[0].LaunchAsync();
                    }
                    Debug.WriteLine("App launch finished!");
                    HasLaunchTask = false;
                    OnGameStateChanged(GameStateArgs.Empty);
                    v.StateChangeInfo = null;
                    // close launcher if needed and hide progressbar
                    Application.Current.Dispatcher.Invoke(() => { ConfigManager.MainThread.ProgressBarGrid.Visibility = Visibility.Collapsed; });
                    if (Properties.Settings.Default.KeepLauncherOpen == false)
                    {
                        await Application.Current.Dispatcher.InvokeAsync(() =>
                        {
                            Application.Current.MainWindow.Close();
                        });
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("App launch failed:\n" + e.ToString());
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        ConfigManager.MainThread.ProgressBarGrid.Visibility = Visibility.Collapsed;
                        ErrorScreenShow.errormsg("applauncherror");
                    });
                    HasLaunchTask = false;
                    OnGameStateChanged(GameStateArgs.Empty);
                    v.StateChangeInfo = null;
                    return;
                }
            });
        }