public static string ExpandVariables(this GameInfo game, string inputString, bool fixSeparators = false) { if (string.IsNullOrEmpty(inputString) || !inputString.Contains('{')) { return(inputString); } var result = inputString; if (!game.InstallDirectory.IsNullOrWhiteSpace()) { result = result.Replace(ExpandableVariables.InstallationDirectory, game.InstallDirectory); result = result.Replace(ExpandableVariables.InstallationDirName, Path.GetFileName(Path.GetDirectoryName(game.InstallDirectory))); } if (!game.GameImagePath.IsNullOrWhiteSpace()) { result = result.Replace(ExpandableVariables.ImagePath, game.GameImagePath); result = result.Replace(ExpandableVariables.ImageNameNoExtension, Path.GetFileNameWithoutExtension(game.GameImagePath)); result = result.Replace(ExpandableVariables.ImageName, Path.GetFileName(game.GameImagePath)); } result = result.Replace(ExpandableVariables.PlayniteDirectory, PlaynitePaths.ProgramPath); result = result.Replace(ExpandableVariables.Name, game.Name); result = result.Replace(ExpandableVariables.Platform, game.Platform); result = result.Replace(ExpandableVariables.GameId, game.GameId); result = result.Replace(ExpandableVariables.Version, game.Version); return(fixSeparators ? Paths.FixSeparators(result) : result); }
public static string ExpandVariables(this Game game, string inputString, bool fixSeparators = false) { if (string.IsNullOrEmpty(inputString)) { return(inputString); } var result = inputString; result = result.Replace(ExpandableVariables.InstallationDirectory, game.InstallDirectory); result = result.Replace(ExpandableVariables.InstallationDirName, Path.GetFileName(Path.GetDirectoryName(game.InstallDirectory))); result = result.Replace(ExpandableVariables.ImagePath, game.GameImagePath); result = result.Replace(ExpandableVariables.ImageNameNoExtension, Path.GetFileNameWithoutExtension(game.GameImagePath)); result = result.Replace(ExpandableVariables.ImageName, Path.GetFileName(game.GameImagePath)); result = result.Replace(ExpandableVariables.Name, game.Name); return(fixSeparators ? Paths.FixSeparators(result) : result); }
public static string ExpandVariables(this Game game, string inputString, bool fixSeparators = false) { if (string.IsNullOrEmpty(inputString)) { return(inputString); } var result = inputString; result = result.Replace("{InstallDir}", game.InstallDirectory); result = result.Replace("{InstallDirName}", Path.GetFileName(Path.GetDirectoryName(game.InstallDirectory))); result = result.Replace("{ImagePath}", game.GameImagePath); result = result.Replace("{ImageNameNoExt}", Path.GetFileNameWithoutExtension(game.GameImagePath)); result = result.Replace("{ImageName}", Path.GetFileName(game.GameImagePath)); result = result.Replace("{PlayniteDir}", PlaynitePaths.ProgramPath); result = result.Replace("{Name}", game.Name); return(fixSeparators ? Paths.FixSeparators(result) : result); }
// TODO rework this whole mess into something better and more maintainable :| private static string StringExpand(this Game game, string inputString, bool fixSeparators = false, string emulatorDir = null, string romPath = null) { if (string.IsNullOrEmpty(inputString) || !inputString.Contains('{')) { return(inputString); } var result = inputString; if (!game.InstallDirectory.IsNullOrWhiteSpace()) { result = result.Replace(ExpandableVariables.InstallationDirectory, game.InstallDirectory); result = result.Replace(ExpandableVariables.InstallationDirName, Path.GetFileName(Path.GetDirectoryName(game.InstallDirectory))); } if (romPath.IsNullOrEmpty() && game.Roms.HasItems()) { var customPath = game.Roms[0].Path; if (!customPath.IsNullOrEmpty()) { result = result.Replace(ExpandableVariables.ImagePath, customPath); result = result.Replace(ExpandableVariables.ImageNameNoExtension, Path.GetFileNameWithoutExtension(customPath)); result = result.Replace(ExpandableVariables.ImageName, Path.GetFileName(customPath)); } } else if (!romPath.IsNullOrEmpty()) { result = result.Replace(ExpandableVariables.ImagePath, romPath); result = result.Replace(ExpandableVariables.ImageNameNoExtension, Path.GetFileNameWithoutExtension(romPath)); result = result.Replace(ExpandableVariables.ImageName, Path.GetFileName(romPath)); } result = result.Replace(ExpandableVariables.PlayniteDirectory, PlaynitePaths.ProgramPath); result = result.Replace(ExpandableVariables.Name, game.Name); result = result.Replace(ExpandableVariables.Platform, game.Platforms?[0].Name); result = result.Replace(ExpandableVariables.PluginId, game.PluginId.ToString()); result = result.Replace(ExpandableVariables.GameId, game.GameId); result = result.Replace(ExpandableVariables.DatabaseId, game.Id.ToString()); result = result.Replace(ExpandableVariables.Version, game.Version); result = result.Replace(ExpandableVariables.EmulatorDirectory, emulatorDir ?? string.Empty); return(fixSeparators ? Paths.FixSeparators(result) : result); }
private static string StringExpand(this GameMetadata game, string inputString, bool fixSeparators = false) { if (string.IsNullOrEmpty(inputString) || !inputString.Contains('{')) { return(inputString); } var result = inputString; if (!game.InstallDirectory.IsNullOrWhiteSpace()) { result = result.Replace(ExpandableVariables.InstallationDirectory, game.InstallDirectory); result = result.Replace(ExpandableVariables.InstallationDirName, Path.GetFileName(Path.GetDirectoryName(game.InstallDirectory))); } if (game.Roms.HasItems()) { var romPath = game.Roms[0].Path; if (!romPath.IsNullOrEmpty()) { result = result.Replace(ExpandableVariables.ImagePath, romPath); result = result.Replace(ExpandableVariables.ImageNameNoExtension, Path.GetFileNameWithoutExtension(romPath)); result = result.Replace(ExpandableVariables.ImageName, Path.GetFileName(romPath)); } } result = result.Replace(ExpandableVariables.PlayniteDirectory, PlaynitePaths.ProgramPath); result = result.Replace(ExpandableVariables.Name, game.Name); result = result.Replace(ExpandableVariables.GameId, game.GameId); result = result.Replace(ExpandableVariables.Version, game.Version); if (game.Platforms.HasItems() && game.Platforms.First() is MetadataNameProperty prop) { result = result.Replace(ExpandableVariables.Platform, prop.Name); } return(fixSeparators ? Paths.FixSeparators(result) : result); }