Example #1
0
 private async Task NewProject(ProjectWizardViewModel project)
 {
     if (project == null)
     {
         CloseDialogCommand.Execute(null);
         return;
     }
     CloseModalCommand.Execute(null);
     await Task.Run(() => NewProjectTask(project)).ContinueWith((result) =>
     {
     });
 }
Example #2
0
        public async Task OpenFromNewFile(NewFileViewModel file)
        {
            CloseModalCommand.Execute(null);
            if (file == null)
            {
                return;
            }

            _watcherService.IsSuspended = true;
            await Task.Run(() => OpenFromNewFileTask(file)).ContinueWith(async(result) =>
            {
                _watcherService.IsSuspended = false;
                await _watcherService.RefreshAsync(ActiveProject);
                await RequestFileOpen(file.FullPath);
            });
        }
Example #3
0
        private async Task <Unit> OpenProjectAsync(string location)
        {
            // switch from one active project to another

            if (_projectManager.ActiveProject != null && !string.IsNullOrEmpty(location))
            {
                if (_projectManager.ActiveProject.Location == location)
                {
                    return(Unit.Default);
                }
            }

            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?
                        //TODO
                        //location = await ProjectHelpers.LocateMissingProjectAsync(location);
                        //location = "";
                        //if (string.IsNullOrEmpty(location))
                        {
                            // user canceled locating a project
                            DeleteProject(location);
                            return(Unit.Default);
                        }
                    }
                    // open an existing project
                    else
                    {
                        var dlg = new CommonOpenFileDialog
                        {
                            AllowNonFileSystemItems = false,
                            Multiselect             = false,
                            IsFolderPicker          = false,
                            Title = "Locate the WolvenKit project"
                        };
                        dlg.Filters.Add(new CommonFileDialogFilter("Cyberpunk 2077 Project", "*.cpmodproj"));

                        if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                        {
                            return(Unit.Default);
                        }

                        var result = dlg.FileName;
                        if (string.IsNullOrEmpty(result))
                        {
                            return(Unit.Default);
                        }

                        location = result;
                    }
                }

                // one last check
                if (!File.Exists(location))
                {
                    return(Unit.Default);
                }

                CloseModalCommand.Execute(null);

                await _projectManager.LoadAsync(location);

                ActiveProject = _projectManager.ActiveProject;

                await _gameControllerFactory.GetController().HandleStartup().ContinueWith(_ =>
                {
                    UpdateTitle();
                    _notificationService.Success($"Project {Path.GetFileNameWithoutExtension(location)} loaded!");
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
            }
            catch (Exception)
            {
                // TODO: Are we intentionally swallowing this?
                //Log.Error(ex, "Failed to open file");
            }

            return(Unit.Default);
        }