Exemple #1
0
        protected override async void Execute(object parameter)
        {
            try
            {
                var location = parameter as string;
                var filter   = "Witcher 3 Project (*.w3modproj)|*.w3modproj| Cyberpunk 2077 Project (*.cpmodproj)|*.cpmodproj";
                if (location == null && parameter is ProjectWizardModel.TypeAndPath)
                {
                    var res = parameter as ProjectWizardModel.TypeAndPath;
                    location = res.Path;
                    if (res.Type == ProjectWizardModel.WitcherGameName)
                    {
                        filter = "Witcher 3 Project (*.w3modproj)|*.w3modproj";
                    }
                    else if (res.Type == ProjectWizardModel.CyberpunkGameName)
                    {
                        filter = "Cyberpunk 2077 Project (*.cpmodproj)|*.cpmodproj";
                    }
                }

                var result = await _saveFileService.DetermineFileAsync(new DetermineSaveFileContext()
                {
                    Filter           = filter,
                    Title            = "Please select a location to save your WolvenKit project",
                    InitialDirectory = location,
                });

                if (result.Result)
                {
                    location = result.FileName;
                }

                if (!string.IsNullOrWhiteSpace(location) && result.Result)
                {
                    using (_pleaseWaitService.PushInScope())
                    {
                        switch (Path.GetExtension(location))
                        {
                        case ".w3modproj":
                        {
                            var np = new Tw3Project(location)
                            {
                                Name = Path.GetFileNameWithoutExtension(location),
                                Data = new W3Mod()
                                {
                                    FileName = location,
                                    Name     = Path.GetFileNameWithoutExtension(location),
                                    Author   = "WolvenKit",
                                    Email    = "",
                                    Version  = "1.0"
                                }
                            };
                            np.Save(location);
                            np.CreateDefaultDirectories();
                            break;
                        }

                        case ".cpmodproj":
                        {
                            var np = new Cp77Project(location)
                            {
                                Name = Path.GetFileNameWithoutExtension(location),
                                Data = new CP77Mod()
                                {
                                    FileName = location,
                                    Name     = Path.GetFileNameWithoutExtension(location),
                                    Author   = "WolvenKit",
                                    Email    = "",
                                    Version  = "1.0"
                                }
                            };
                            np.Save(location);
                            np.CreateDefaultDirectories();
                            break;
                        }

                        default:
                            _loggerService.LogString("Invalid project path!", Logtype.Error);
                            break;
                        }
                    }
                    await _projectManager.LoadAsync(location);
                }
            }
            catch (Exception ex)
            {
                _loggerService.LogString(ex.Message, Logtype.Error);
                _loggerService.LogString("Failed to create a new project!", Logtype.Error);
            }

            OnCommandCompleted?.Invoke();
        }
        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;
                }
            }
Exemple #3
0
        protected override async void Execute(object parameter)
        {
            try
            {
                var location = parameter as string;

                var result = await _saveFileService.DetermineFileAsync(new DetermineSaveFileContext()
                {
                    Filter = "Witcher 3 Project (*.w3modproj)|*.w3modproj| Cyberpunk 2077 Project (*.cpmodproj)|*.cpmodproj",
                    Title  = "Please select a location to save your WolvenKit project"
                });

                if (result.Result)
                {
                    location = result.FileName;
                }

                if (!string.IsNullOrWhiteSpace(location))
                {
                    using (_pleaseWaitService.PushInScope())
                    {
                        switch (Path.GetExtension(location))
                        {
                        case ".w3modproj":
                        {
                            var np = new Tw3Project(location)
                            {
                                Name = Path.GetFileNameWithoutExtension(location),
                                Data = new W3Mod()
                                {
                                    FileName = location,
                                    Name     = Path.GetFileNameWithoutExtension(location),
                                    Author   = "WolvenKit",
                                    Email    = "",
                                    Version  = "1.0"
                                }
                            };
                            np.Save(location);
                            np.CreateDefaultDirectories();
                            break;
                        }

                        case ".cpmodproj":
                        {
                            var np = new Cp77Project(location)
                            {
                                Name = Path.GetFileNameWithoutExtension(location),
                                Data = new CP77Mod()
                                {
                                    FileName = location,
                                    Name     = Path.GetFileNameWithoutExtension(location),
                                    Author   = "WolvenKit",
                                    Email    = "",
                                    Version  = "1.0"
                                }
                            };
                            np.Save(location);
                            np.CreateDefaultDirectories();
                            break;
                        }

                        default:
                            _loggerService.LogString("Invalid project path!", Logtype.Error);
                            break;
                        }
                    }
                    await _projectManager.LoadAsync(location);
                }
            }
            catch (Exception ex)
            {
                _loggerService.LogString("Failed to create a new project!", Logtype.Error);
            }
        }