private async void OpenExecuted(string selected) { if (selected != null) { if (!File.Exists(selected)) { selected = null; } else { previousPath = selected; } } if (selected == null) { if (this.previousPath != null) { var settings = new FileDialogSettings(new DialogFilterBuilder("*" + FileConstants.AppInstallerExtension).BuildFilter(), this.previousPath); if (!this.interactionService.SelectFile(settings, out selected)) { return; } } else if (!this.interactionService.SelectFile(FileDialogSettings.FromFilterString(new DialogFilterBuilder("*" + FileConstants.AppInstallerExtension).BuildFilter()), out selected)) { return; } } this.previousPath = selected; AppInstallerConfig file; try { file = await AppInstallerConfig.FromFile(selected).ConfigureAwait(true); } catch (Exception e) { // ReSharper disable once PossibleNullReferenceException this.interactionService.ShowError("The selected file is not a valid .appinstaller.", e, InteractionResult.OK); return; } var builder = new AppInstallerBuilder(file); this.AllowDowngrades.CurrentValue = builder.AllowDowngrades; this.AppInstallerUpdateCheckingMethod.CurrentValue = builder.CheckForUpdates; this.AppInstallerUri.CurrentValue = builder.RedirectUri.ToString(); if (builder.ShowPrompt) { this.PromptMode.CurrentValue = builder.UpdateBlocksActivation ? ViewModel.PromptMode.Force : ViewModel.PromptMode.Inform; } else { this.PromptMode.CurrentValue = ViewModel.PromptMode.Background; } this.Hours.CurrentValue = builder.HoursBetweenUpdateChecks.ToString(); this.MainPackageUri.CurrentValue = builder.MainPackageUri.ToString(); this.Version.CurrentValue = builder.Version; this.TabPackage.Name.CurrentValue = builder.MainPackageName; this.TabPackage.Version.CurrentValue = builder.MainPackageVersion; this.TabPackage.Publisher.CurrentValue = builder.MainPackagePublisher; this.TabPackage.PackageType.CurrentValue = builder.MainPackageType; this.TabPackage.Architecture.CurrentValue = builder.MainPackageArchitecture; this.TabOptionalPackages.SetPackages(file.Optional); this.TabRelatedPackages.SetPackages(file.Related); this.AllowDowngrades.CurrentValue = builder.AllowDowngrades; this.OnPropertyChanged(nameof(ShowLaunchOptions)); this.OnPropertyChanged(nameof(CompatibleWindows)); }
private void OpenExecuted(string selected) { if (selected != null) { if (!File.Exists(selected)) { selected = null; } else { previousPath = selected; } } if (selected == null) { if (this.previousPath != null) { // ReSharper disable once StringLiteralTypo var settings = new FileDialogSettings(new DialogFilterBuilder("*.appinstaller").BuildFilter(), this.previousPath); if (!this.interactionService.SelectFile(settings, out selected)) { return; } } // ReSharper disable once StringLiteralTypo else if (!this.interactionService.SelectFile(FileDialogSettings.FromFilterString(new DialogFilterBuilder("*.appinstaller").BuildFilter()), out selected)) { return; } } this.previousPath = selected; AppInstallerConfig.FromFile(selected).ContinueWith(t => { if (t.IsFaulted) { // ReSharper disable once PossibleNullReferenceException this.interactionService.ShowError("The selected file is not a valid .appinstaller.", t.Exception.GetBaseException(), InteractionResult.OK); return; } if (t.IsCanceled) { return; } if (!t.IsCompleted) { return; } var builder = new AppInstallerBuilder(t.Result); this.AllowDowngrades.CurrentValue = builder.AllowDowngrades; this.AppInstallerUpdateCheckingMethod.CurrentValue = builder.CheckForUpdates; this.AppInstallerUri.CurrentValue = builder.RedirectUri.ToString(); this.BlockLaunching.CurrentValue = builder.UpdateBlocksActivation; this.Hours.CurrentValue = builder.HoursBetweenUpdateChecks.ToString(); this.MainPackageUri.CurrentValue = builder.MainPackageUri.ToString(); this.Version.CurrentValue = builder.Version; this.ShowPrompt.CurrentValue = builder.ShowPrompt; this.TabPackage.Name.CurrentValue = builder.MainPackageName; this.TabPackage.Version.CurrentValue = builder.MainPackageVersion; this.TabPackage.Publisher.CurrentValue = builder.MainPackagePublisher; this.TabPackage.PackageType.CurrentValue = builder.MainPackageType; this.TabPackage.Architecture.CurrentValue = builder.MainPackageArchitecture; this.AllowDowngrades.CurrentValue = builder.AllowDowngrades; this.OnPropertyChanged(nameof(ShowLaunchOptions)); this.OnPropertyChanged(nameof(CompatibleWindows)); }, CancellationToken.None, TaskContinuationOptions.AttachedToParent | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.FromCurrentSynchronizationContext()); }