public string CreateConfig(string configName, string inisPath, ConfigOptions configOptions) { var configPath = $"{configsDir}\\{configName}"; Directory.CreateDirectory(configPath); CreateUiFile(configPath, inisPath, configOptions); if (configOptions.Flags.HasFlag(ConfigFlags.CopyVmSettings)) { fileHelpers.CopyWithoutException($"{inisPath}\\{ConfiguratorConstants.VmFileName}", $"{configPath}\\{ConfiguratorConstants.VmFileName}"); } if (configOptions.Flags.HasFlag(ConfigFlags.CopyGsdxSettings)) { fileHelpers.CopyWithoutException($"{inisPath}\\{ConfiguratorConstants.GsdxFileName}", $"{configPath}\\{ConfiguratorConstants.GsdxFileName}"); } if (configOptions.Flags.HasFlag(ConfigFlags.CopySpu2xSettings)) { fileHelpers.CopyWithoutException($"{inisPath}\\{ConfiguratorConstants.Spu2xFileName}", $"{configPath}\\{ConfiguratorConstants.Spu2xFileName}"); } if (configOptions.Flags.HasFlag(ConfigFlags.CopyLilyPadSettings)) { fileHelpers.CopyWithoutException($"{inisPath}\\{ConfiguratorConstants.LilyPadFileName}", $"{configPath}\\{ConfiguratorConstants.LilyPadFileName}"); } SetVmSettings(configPath, configOptions); appSettings.UpdateConfigs(); return(configPath); }
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); }
private void ImportGsdx(string importedConfigPath, string configPath) => fileHelpers.CopyWithoutException($"{configPath}\\{ConfiguratorConstants.GsdxFileName}", $"{importedConfigPath}\\{ConfiguratorConstants.GsdxFileName}");