private void InvokeRemove(MCVersion v) { Task.Run(async() => { IsUninstalling = true; Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); }); Model.StateChangeInfo = new VersionStateChangeInfo(); Model.StateChangeInfo.IsUninstalling = true; try { await UnregisterPackage(v, Path.GetFullPath(v.GameDirectory)); Directory.Delete(v.GameDirectory, true); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } Model.StateChangeInfo.IsUninstalling = false; IsUninstalling = false; v.UpdateInstallStatus(); Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); }); Model.StateChangeInfo = null; return; }); }
private void InvokeDownload(MCVersion v, bool RunAfterwards = false) { System.Diagnostics.Debug.WriteLine("Download start"); bool wasCanceled = false; Task.Run(async() => { cancelSource = new CancellationTokenSource(); ViewModels.LauncherModel.Default.ShowProgressBar = true; ViewModels.LauncherModel.Default.AllowCancel = true; ViewModels.LauncherModel.Default.CancelCommand = new RelayCommand((o) => InvokeCancel()); try { string dlPath = "Minecraft-" + v.Name + ".Appx"; VersionDownloader downloader = _anonVersionDownloader; downloader = _userVersionDownloader; if (v.IsBeta) { await BetaAuthenticate(); } await DownloadVersion(v, downloader, dlPath, cancelSource); await ExtractPackage(v, dlPath, cancelSource); } catch (TaskCanceledException) { wasCanceled = true; } if (!RunAfterwards || wasCanceled) { ViewModels.LauncherModel.Default.ShowProgressBar = false; } ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None; ViewModels.LauncherModel.Default.AllowCancel = false; ViewModels.LauncherModel.Default.CancelCommand = null; cancelSource = null; v.UpdateInstallStatus(); if (RunAfterwards && !wasCanceled) { InvokeLaunch(v); } }); }
private void InvokeRemove(MCVersion v) { Task.Run(async() => { ViewModels.LauncherModel.Default.ShowProgressBar = true; ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.isUninstalling; try { await UnregisterPackage(v, Path.GetFullPath(v.GameDirectory)); Directory.Delete(v.GameDirectory, true); } catch (Exception ex) { ErrorScreenShow.exceptionmsg(ex); } v.UpdateInstallStatus(); ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None; ViewModels.LauncherModel.Default.ShowProgressBar = false; ConfigManager.OnConfigStateChanged(null, Events.ConfigStateArgs.Empty); return; }); }
private void InvokeDownload(MCVersion v) { CancellationTokenSource cancelSource = new CancellationTokenSource(); Model.StateChangeInfo = new VersionStateChangeInfo(); Model.StateChangeInfo.IsInitializing = true; Model.StateChangeInfo.CancelCommand = new RelayCommand((o) => cancelSource.Cancel()); Program.Log("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(); } Program.Log("Waiting for authentication"); try { await _userVersionDownloaderLoginTask; Program.Log("Authentication complete"); } catch (Exception e) { Model.StateChangeInfo = null; Program.Log("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 (Model.StateChangeInfo.IsInitializing) { Model.StateChangeInfo.IsDownloading = true; IsDownloading = true; Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); }); Program.Log("Actual download started"); Model.StateChangeInfo.IsInitializing = false; if (total.HasValue) { Model.StateChangeInfo.TotalSize_Downloading = total.Value; } } Model.StateChangeInfo.DownloadedBytes_Downloading = current; }, cancelSource.Token); Program.Log("Download complete"); Model.StateChangeInfo.IsDownloading = false; IsDownloading = false; } catch (Exception e) { Program.Log("Download failed:\n" + e.ToString()); if (!(e is TaskCanceledException)) { MessageBox.Show("Download failed:\n" + e.ToString()); } Model.StateChangeInfo = null; Model.StateChangeInfo.IsDownloading = false; IsDownloading = false; return; } await ExtractPackage(v, dlPath); Model.StateChangeInfo = null; v.UpdateInstallStatus(); Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); }); }); }
private void InvokeDownload(MCVersion 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; Application.Current.Dispatcher.Invoke(() => { 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(); Application.Current.Dispatcher.Invoke(() => { OnGameStateChanged(GameStateArgs.Empty); }); }); }