private async Task DownloadVersion(BLVersion v, VersionDownloader downloader, string dlPath, CancellationTokenSource cancelSource)
 {
     try
     {
         ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.isInitializing;
         await downloader.Download(v.DisplayName, v.UUID, 1, dlPath, (current, total) =>
         {
             if (ViewModels.LauncherModel.Default.CurrentState == ViewModels.LauncherModel.StateChange.isInitializing)
             {
                 ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.isDownloading;
                 System.Diagnostics.Debug.WriteLine("Actual download started");
                 if (total.HasValue) ViewModels.LauncherModel.Default.TotalProgress = total.Value;
             }
             ViewModels.LauncherModel.Default.CurrentProgress = current;
         }, cancelSource.Token);
         System.Diagnostics.Debug.WriteLine("Download complete");
         ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None;
     }
     catch (TaskCanceledException e)
     {
         ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None;
         throw e;
     }
     catch (Exception e)
     {
         ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None;
         System.Diagnostics.Debug.WriteLine("Download failed:\n" + e.ToString());
         ErrorScreenShow.errormsg("Error_AppDownloadFailed_Title", "Error_AppDownloadFailed", e);
         throw e;
     }
 }
Example #2
0
        private void GetManualComboBoxEntries()
        {
            BLVersion latest_release = new BLVersion("latest_release", Application.Current.Resources["EditInstallationScreen_LatestRelease"].ToString(), false);
            BLVersion latest_beta    = new BLVersion("latest_beta", Application.Current.Resources["EditInstallationScreen_LatestSnapshot"].ToString(), true);

            Versions.InsertRange(0, new List <BLVersion>()
            {
                latest_release, latest_beta
            });
        }
Example #3
0
        private void UpdateVersionsComboBox()
        {
            Versions.Clear();
            InstallationVersionSelect.ItemsSource = null;
            foreach (var entry in LauncherModel.Default.Versions)
            {
                Versions.Add(BLVersion.Convert(entry));
            }
            GetManualComboBoxEntries();
            InstallationVersionSelect.ItemsSource = Versions;
            var view = CollectionViewSource.GetDefaultView(InstallationVersionSelect.ItemsSource) as CollectionView;

            view.Filter = Filter_VersionList;
            InstallationVersionSelect.SelectedIndex = 0;
        }
        private async Task ExtractPackage(BLVersion v, string dlPath, CancellationTokenSource cancelSource)
        {
            Stream zipReadingStream = null;
            try
            {
                System.Diagnostics.Debug.WriteLine("Extraction started");
                ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.isExtracting;
                ViewModels.LauncherModel.Default.CurrentProgress = 0;
                string dirPath = v.GameDirectory;
                if (Directory.Exists(dirPath))
                    Directory.Delete(dirPath, true);

                zipReadingStream = File.OpenRead(dlPath);
                ZipArchive zip = new ZipArchive(zipReadingStream);
                var progress = new Progress<ZipProgress>();
                progress.ProgressChanged += (s, z) =>
                {
                    ViewModels.LauncherModel.Default.CurrentProgress = z.Processed;
                    ViewModels.LauncherModel.Default.TotalProgress = z.Total;
                };
                await Task.Run(() => zip.ExtractToDirectory(dirPath, progress, cancelSource));

                zipReadingStream.Close();

                File.Delete(Path.Combine(dirPath, "AppxSignature.p7x"));
                File.Delete(dlPath);
                System.Diagnostics.Debug.WriteLine("Extracted successfully");
            }
            catch (TaskCanceledException e)
            {
                if (zipReadingStream != null) zipReadingStream.Close();
                Directory.Delete(v.GameDirectory, true);
                throw e;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Extraction failed:\n" + e.ToString());
                ErrorScreenShow.errormsg("Error_AppExtractionFailed_Title", "Error_AppExtractionFailed", e);
                if (zipReadingStream != null) zipReadingStream.Close();
                ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.None;
                throw new TaskCanceledException();
            }
        }
        public async void Remove(BLVersion v)
        {
            ViewModels.LauncherModel.Default.ShowProgressBar = true;
            ViewModels.LauncherModel.Default.CurrentState = ViewModels.LauncherModel.StateChange.isUninstalling;

            try
            {
                await UnregisterPackage(v, Path.GetFullPath(v.GameDirectory), false);
                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;
            return;
        }
        private async Task<bool> Download(BLVersion v, bool RunAfterwards)
        {
            System.Diagnostics.Debug.WriteLine("Download start");
            bool wasCanceled = false;

            cancelSource = new CancellationTokenSource();
            ViewModels.LauncherModel.Default.ShowProgressBar = true;
            ViewModels.LauncherModel.Default.AllowCancel = true;
            ViewModels.LauncherModel.Default.CancelCommand = new RelayCommand((o) => Cancel());

            try
            {
                string dlPath = "Minecraft-" + v.Name + ".Appx";
                VersionDownloader downloader = LauncherModel.Default.VersionDownloader;
                if (v.IsBeta) await BetaAuthenticate();
                await DownloadVersion(v, downloader, dlPath, cancelSource);
                await ExtractPackage(v, dlPath, cancelSource);
            }
            catch (TaskCanceledException)
            {
                wasCanceled = true;
            }
            catch (Exception ex)
            {
                ErrorScreenShow.exceptionmsg(ex);
                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();

            return wasCanceled;


        }
        public bool Filter_VersionList(object obj)
        {
            BLVersion v = BLVersion.Convert(obj as MCVersion);

            if (v != null && v.IsInstalled)
            {
                if (!Properties.LauncherSettings.Default.ShowBetas && v.IsBeta)
                {
                    return(false);
                }
                else if (!Properties.LauncherSettings.Default.ShowReleases && !v.IsBeta)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
 public async void Repair(BLVersion v)
 {
     await Download(v, false);
 }