protected override async void Execute(object parameter) { try { var location = parameter as string; var viewModel = _serviceLocator.ResolveType <ProjectWizardViewModel>(); var r = await _uIVisualizerService.ShowAsync(viewModel, (sender, args) => { if (args.DataContext is not ProjectWizardViewModel res) { return; } var result = args.Result; if (!result.HasValue || !result.Value) { return; } location = Path.Combine(res.ProjectPath, res.ProjectName); var type = res.ProjectType.First(); if (type.Equals(ProjectWizardViewModel.WitcherGameName)) { location += ".w3modproj"; } else if (type.Equals(ProjectWizardViewModel.CyberpunkGameName)) { location += ".cpmodproj"; } }); if (string.IsNullOrWhiteSpace(location)) { return; } RibbonViewModel.GlobalRibbonVM.StartScreenShown = false; RibbonViewModel.GlobalRibbonVM.BackstageIsOpen = false; using (_pleaseWaitService.PushInScope()) { switch (Path.GetExtension(location)) { case ".w3modproj": { var np = new Tw3Project(location) { Name = Path.GetFileNameWithoutExtension(location), Author = "WolvenKit", Email = "", Version = "1.0" }; _projectManager.ActiveProject = np; await _projectManager.SaveAsync(); np.CreateDefaultDirectories(); //saveProjectImg(location); break; } case ".cpmodproj": { var np = new Cp77Project(location) { Name = Path.GetFileNameWithoutExtension(location), Author = "WolvenKit", Email = "", Version = "1.0" }; _projectManager.ActiveProject = np; await _projectManager.SaveAsync(); np.CreateDefaultDirectories(); //saveProjectImg(location); break; } default: _loggerService.LogString("Invalid project path!", Logtype.Error); break; } } await _projectManager.LoadAsync(location); switch (Path.GetExtension(location)) { case ".w3modproj": await _tw3Controller.HandleStartup().ContinueWith(t => { _notificationService.Success( "Project " + Path.GetFileNameWithoutExtension(location) + " loaded!"); }, TaskContinuationOptions.OnlyOnRanToCompletion); break; case ".cpmodproj": await _cp77Controller.HandleStartup().ContinueWith( t => { _notificationService.Success("Project " + Path.GetFileNameWithoutExtension(location) + " loaded!"); }, TaskContinuationOptions.OnlyOnRanToCompletion); break; default: break; } }
protected override async Task ExecuteAsync(object parameter) { var location = parameter as string; // switch from one active project to another if (_projectManager.ActiveProject != null && !string.IsNullOrEmpty(location)) { if (_projectManager.ActiveProject.Location == location) { return; } } try { if (string.IsNullOrWhiteSpace(location) || !File.Exists(location)) { // file was moved or deleted if (_recentlyUsedItemsService.Items.Items.Any(_ => _.Name == location)) { // would you like to locate it? location = await ProjectHelpers.LocateMissingProjectAsync(location); if (string.IsNullOrEmpty(location)) { // user canceled locating a project return; } } // open an existing project else { var result = await _openFileService.DetermineFileAsync(new DetermineOpenFileContext { Filter = "Cyberpunk 2077 Project | *.cpmodproj|Witcher 3 Project (*.w3modproj)|*.w3modproj", IsMultiSelect = false, Title = "Please select the WolvenKit project you would like to open." }); if (!result.Result) { // user canceled locating a project return; } location = result.FileName; } } // one last check if (!File.Exists(location)) { return; } RibbonViewModel.GlobalRibbonVM.StartScreenShown = false; RibbonViewModel.GlobalRibbonVM.BackstageIsOpen = false; // if a valid location has been set //using (_pleaseWaitService.PushInScope()) { await _projectManager.LoadAsync(location); switch (Path.GetExtension(location)) { case ".w3modproj": await _tw3Controller.HandleStartup().ContinueWith(t => { _notificationService.Success( "Project " + Path.GetFileNameWithoutExtension(location) + " loaded!"); }, TaskContinuationOptions.OnlyOnRanToCompletion); break; case ".cpmodproj": await _cp77Controller.HandleStartup().ContinueWith( t => { _notificationService.Success("Project " + Path.GetFileNameWithoutExtension(location) + " loaded!"); }, TaskContinuationOptions.OnlyOnRanToCompletion); break; default: break; } //TODO:ORC //if (StaticReferences.GlobalShell != null) //{ // StaticReferences.GlobalShell.SetCurrentValue(System.Windows.Window.TitleProperty, Path.GetFileNameWithoutExtension(location)); //} StaticReferencesVM.GlobalStatusBar.CurrentProject = Path.GetFileNameWithoutExtension(location); } } catch (Exception) { // TODO: Are we intentionally swallowing this? //Log.Error(ex, "Failed to open file"); } }