Example #1
0
        private void CreateConfig(object sender, RoutedEventArgs e)
        {
            var selectedVersion = version.SelectedItem as string;
            var givenName       = configName.Text;

            if (string.IsNullOrWhiteSpace(givenName) || string.IsNullOrWhiteSpace(selectedVersion))
            {
                var error = string.IsNullOrWhiteSpace(givenName) ? "enter a name" : "choose a version";
                MessageBox.Show("You must " + error, "Error");
                return;
            }
            var inisPath = emulationService.GetInisPath(settings.Versions[selectedVersion]);
            var options  = GetConfigOptions();

            configurationService.CreateConfig(givenName, inisPath, options);
            GameModel.Configs = settings.Configs.Keys;
            gameModel.Version = selectedVersion;
            gameModel.Config  = givenName;
            Close();
        }
        private void ImportConfig(string configName, string emulatorPath, IEnumerable <string> gameIds, XmlElement configElement)
        {
            var configPath = $"{remoteConfigsPath}\\Game Configs\\{configName}";

            configElement ??= remoteIndex.SelectSingleNode($"//Config[contains(@Name, \"{configName}\")]") as XmlElement;
            if (configElement == null)
            {
                return;
            }

            configName = Regex.Replace(configName, "id#\\d+", "").Trim().ToLowerInvariant().Replace(" ", "-");
            var inisPath           = emulationService.GetInisPath(emulatorPath);
            var importedConfigPath = configurationService.CreateConfig(configName, inisPath, ConfigOptions.DefaultForRemote);

            ImportPcsx2Ui(importedConfigPath, configPath);
            ImportPcsx2Vm(importedConfigPath, configPath);
            ImportSpu2x(importedConfigPath, configPath);
            ImportGsdx(importedConfigPath, configPath);
            ImportCheatsAndPatches(configPath, emulatorPath);

            WriteGameIdsForConfig(importedConfigPath, configElement, gameIds);
            WriteRemoteInfoForConfig(importedConfigPath, configElement);
        }
Example #3
0
        public void ImportConfig(string gameId, string emulatorPath)
        {
            if (!(remoteIndex.SelectSingleNode($"//Config[GameIds/GameId = contains(., '{gameId}')]") is XmlElement configElement))
            {
                return;
            }
            var configDirectory = configElement.GetAttribute("Name");
            var configPath      = $"{remoteConfigsPath}\\Game Configs\\{configDirectory}";
            var configName      = Regex.Replace(configDirectory, "id#\\d+", "").Trim().ToLowerInvariant().Replace(" ", "-");
            var inisPath        = emulationService.GetInisPath(emulatorPath);

            var importedConfigPath = configurationService.CreateConfig(configName, inisPath, ConfigOptions.DefaultForRemote);

            // PCSX2_ui.ini
            var targetUiFile   = $"{importedConfigPath}\\{ConfiguratorConstants.UiFileName}";
            var targetUiConfig = iniParser.ReadFile(targetUiFile);
            var sourceUiConfig = new IniData();

            if (File.Exists($"{configPath}\\{ConfiguratorConstants.UiFileName}"))
            {
                MergeUiConfig(sourceUiConfig, iniParser.ReadFile($"{configPath}\\{ConfiguratorConstants.UiFileName}"));
            }
            if (File.Exists($"{configPath}\\pcsx2_ui-tweak.ini"))
            {
                MergeUiConfig(sourceUiConfig, iniParser.ReadFile($"{configPath}\\pcsx2_ui-tweak.ini"));
            }

            targetUiConfig.Merge(sourceUiConfig);
            iniParser.WriteFile(targetUiFile, targetUiConfig, Encoding.UTF8);

            // SPU2-X.ini
            var sourceSpu2xConfigFile = $"{configPath}\\{ConfiguratorConstants.Spu2xFileName}";

            if (File.Exists(sourceSpu2xConfigFile))
            {
                var targetSpu2xFile   = $"{importedConfigPath}\\{ConfiguratorConstants.Spu2xFileName}";
                var targetSpu2xConfig = File.Exists(targetSpu2xFile) ? iniParser.ReadFile(targetSpu2xFile) : new IniData();
                var sourceSpu2xConfig = iniParser.ReadFile(sourceSpu2xConfigFile);

                MergeSpu2xConfig(targetSpu2xConfig, sourceSpu2xConfig);
                iniParser.WriteFile(targetSpu2xFile, targetSpu2xConfig, Encoding.UTF8);
            }

            // PCSX2_vm.ini
            var sourceVmConfigFile = $"{configPath}\\{ConfiguratorConstants.VmFileName}";

            if (File.Exists(sourceVmConfigFile))
            {
                var targetVmFile   = $"{importedConfigPath}\\{ConfiguratorConstants.VmFileName}";
                var targetVmConfig = File.Exists(targetVmFile) ? iniParser.ReadFile(targetVmFile) : new IniData();
                var sourceVmConfig = iniParser.ReadFile(sourceVmConfigFile);

                MergeVmConfig(targetVmConfig, sourceVmConfig);
                iniParser.WriteFile(targetVmFile, targetVmConfig, Encoding.UTF8);
            }

            // GSdx.ini
            fileHelpers.CopyWithoutException($"{configPath}\\{ConfiguratorConstants.GsdxFileName}", $"{importedConfigPath}\\{ConfiguratorConstants.GsdxFileName}");

            // Cheats and Widescreen Patches
            foreach (var file in Directory.GetFiles(configPath, "*.pnach"))
            {
                var fileName    = Path.GetFileName(file);
                var destination = $"{Path.GetDirectoryName(emulatorPath)}\\" + (fileName.EndsWith("_ws.pnach") ? $"cheats_ws\\{fileName.Replace("_ws", "")}" : $"cheats\\{fileName}");
                File.Copy(file, destination, overwrite: true);
            }

            // Game Ids
            var gameIds = configElement.SelectNodes("GameIds/GameId").Cast <XmlNode>().Select(x => Regex.Match(x.InnerText, "[A-Z]{4}-[0-9]{5}").Value);

            if (gameIds.Count() > 0)
            {
                File.WriteAllText($"{importedConfigPath}\\gameids", string.Join(';', gameIds), Encoding.UTF8);
            }

            // Remote File
            var remoteJson = JsonConvert.SerializeObject(new { status = configElement.SelectSingleNode("Status")?.InnerText, notes = configElement.SelectSingleNode("Notes")?.InnerText });

            File.WriteAllText($"{importedConfigPath}\\remote", remoteJson, Encoding.UTF8);
        }