private void CompileTweakFiles(Cp77Project cp77Proj)
        {
            try
            {
                Directory.Delete(cp77Proj.PackedTweakDirectory, true);
            }
            catch (Exception e)
            {
                _loggerService.Error(e);
            }

            var tweakFiles = Directory.GetFiles(cp77Proj.TweakDirectory, "*.tweak", SearchOption.AllDirectories);

            foreach (var f in tweakFiles)
            {
                var text         = File.ReadAllText(f);
                var folder       = Path.GetDirectoryName(Path.GetRelativePath(cp77Proj.TweakDirectory, f));
                var outDirectory = Path.Combine(cp77Proj.PackedTweakDirectory, folder);
                if (!Directory.Exists(outDirectory))
                {
                    Directory.CreateDirectory(outDirectory);
                }
                var filename = Path.GetFileNameWithoutExtension(f) + ".bin";
                var outPath  = Path.Combine(outDirectory, filename);

                try
                {
                    if (!Serialization.Deserialize(text, out var dict))
                    {
                        continue;
                    }
                    var db = new TweakDB();
                    //flats
                    foreach (var(key, value) in dict.Flats)
                    {
                        db.Add(key, value);
                    }
                    //groups
                    foreach (var(key, value) in dict.Groups)
                    {
                        db.Add(key, value);
                    }

                    db.Save(outPath);
                }
                catch (Exception e)
                {
                    _loggerService.Error(e);
                    continue;
                }
            }
        }
Example #2
0
        protected override async Task <IProject> ReadFromLocationAsync(string location)
        {
            try
            {
                var fi = new FileInfo(location);
                if (!fi.Exists)
                {
                    return(null);
                }

                EditorProject project = null;
                switch (fi.Extension)
                {
                case ".w3modproj":
                {
                    project = new Tw3Project(location);
                    MainController.Get().ActiveMod = project.Data;
                    await MainController.SetGame(new Tw3Controller()).ContinueWith(t => _notificationService.Success("Project " + Path.GetFileNameWithoutExtension(location) +
                                                                                                                     " loaded!"), TaskContinuationOptions.OnlyOnRanToCompletion);

                    break;
                }

                case ".cpmodproj":
                {
                    project = new Cp77Project(location);
                    MainController.Get().ActiveMod = project.Data;
                    await MainController.SetGame(new Cp77Controller()).ContinueWith(t => _notificationService.Success("Project " + Path.GetFileNameWithoutExtension(location) + " loaded!"), TaskContinuationOptions.OnlyOnRanToCompletion);

                    break;
                }
                }

                return(await Task.FromResult <IProject>(project));
            }
            catch (IOException ex)
            {
                _notificationService.Error(ex.Message);
            }

            return(null);
        }
Example #3
0
        protected override Task <IProject> ReadFromLocationAsync(string location)
        {
            try
            {
                var fi = new FileInfo(location);
                if (!fi.Exists)
                {
                    return(null);
                }

                EditorProject project = null;
                switch (fi.Extension)
                {
                case ".w3modproj":
                {
                    project = new Tw3Project(location);
                    MainController.Get().ActiveMod = project.Data;
                    MainController.Get().SetGame(new Tw3Controller());
                    break;
                }

                case ".cpmodproj":
                {
                    project = new Cp77Project(location);
                    MainController.Get().ActiveMod = project.Data;
                    MainController.Get().SetGame(new Cp77Controller());
                    break;
                }
                }
                _notificationService.ShowNotification("Success", "Project " + Path.GetFileNameWithoutExtension(location) +
                                                      " loaded!");
                return(Task.FromResult <IProject>(project));
            } catch (IOException ex)
            {
                _notificationService.ShowNotification("Could not open file", ex.Message);
            }

            return(null);
        }
Example #4
0
        private async Task NewProjectTask(ProjectWizardViewModel project)
        {
            try
            {
                var projectLocation = Path.Combine(project.ProjectPath, project.ProjectName, project.ProjectName + ".cpmodproj");
                var np = new Cp77Project(projectLocation)
                {
                    Name    = project.ProjectName,
                    Author  = project.Author,
                    Email   = project.Email,
                    Version = project.Version
                };
                _projectManager.ActiveProject = np;
                await _projectManager.SaveAsync();

                np.CreateDefaultDirectories();

                await _projectManager.LoadAsync(projectLocation);

                DispatcherHelper.RunOnMainThread(() =>
                {
                    ActiveProject = _projectManager.ActiveProject;
                });

                await _gameControllerFactory.GetController().HandleStartup().ContinueWith(_ =>
                {
                    UpdateTitle();
                    _notificationService.Success("Project " + project.ProjectName + " loaded!");
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
            }
            catch (Exception ex)
            {
                _loggerService.Error(ex.Message);
                _loggerService.Error("Failed to create a new project!");
            }
        }
Example #5
0
        private async Task <Unit> NewProjectAsync()
        {
            try
            {
                var location = await Interactions.NewProjectInteraction.Handle(Unit.Default);

                if (string.IsNullOrWhiteSpace(location))
                {
                    return(Unit.Default);
                }

                var ribbon = Locator.Current.GetService <RibbonViewModel>();
                ribbon.StartScreenShown = false;
                ribbon.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.Error("Invalid project path!");
                        break;
                    }
                }

                await _projectManager.LoadAsync(location);

                switch (Path.GetExtension(location))
                {
                case ".w3modproj":
                    await _gameControllerFactory.GetController().HandleStartup().ContinueWith(_ =>
                    {
                        _notificationService.Success(
                            "Project " + Path.GetFileNameWithoutExtension(location) +
                            " loaded!");
                    }, TaskContinuationOptions.OnlyOnRanToCompletion);

                    break;

                case ".cpmodproj":
                    await _gameControllerFactory.GetController().HandleStartup().ContinueWith(
                        _ =>
                    {
                        _notificationService.Success("Project " +
                                                     Path.GetFileNameWithoutExtension(location) +
                                                     " loaded!");
                    },
                        TaskContinuationOptions.OnlyOnRanToCompletion);

                    break;
                }
            }
            catch (Exception ex)
            {
                _loggerService.Error(ex.Message);
                _loggerService.Error("Failed to create a new project!");
            }

            return(Unit.Default);
        }
        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;
                }
            }
Example #7
0
        /// <summary>
        /// Scoops up the packed files and packs it into a zip in a hierarchy that can be easily unzipped
        /// even if the user is not using our manager
        /// Package.wkp (zip)
        /// |---archive\pc\*.archive
        /// |
        /// |---wkpmeta\<modname>\<modname>.wkmeta (json) + icon
        /// |
        /// |---r6\cache\tweakdbpatches\<modname>.tweakdbpatch
        ///
        /// </summary>
        /// <param name="project">Project to pack</param>
        public void CyberpunkPublishStrategy(Cp77Project project) =>
        //TODO: I am not sure how to do this until we have packing

        Logger.Write("Packing Cyberpunk 2077 mod complete.", LogLevel.Info);
Example #8
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();
        }
Example #9
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);
            }
        }