public static string RomAbsolutePath(this PathEntryCollection collection, string systemId = null) { if (string.IsNullOrWhiteSpace(systemId)) { return(collection.AbsolutePathFor(collection["Global_NULL", "ROM"].Path, "Global_NULL")); } if (collection.UseRecentForRoms) { return(Environment.SpecialFolder.Recent.ToString()); } var path = collection[systemId, "ROM"]; if (!path.Path.PathIsSet()) { path = collection["Global", "ROM"]; if (path.Path.PathIsSet()) { return(collection.AbsolutePathFor(path.Path, null)); } } return(collection.AbsolutePathFor(path.Path, systemId)); }
public static string ScreenshotAbsolutePathFor(this PathEntryCollection collection, string systemId) { var entry = collection[systemId, "Screenshots"] ?? collection[systemId, "Base"]; return(collection.AbsolutePathFor(entry.Path, systemId)); }
/// <summary> /// Takes an absolute path and attempts to convert it to a relative, based on the system, /// or global base if no system is supplied, if it is not a subfolder of the base, it will return the path unaltered /// </summary> public static string TryMakeRelative(this PathEntryCollection collection, string absolutePath, string system = null) { var parentPath = string.IsNullOrWhiteSpace(system) ? collection.GlobalBaseAbsolutePath() : collection.AbsolutePathFor(collection.BaseFor(system), system); #if true if (!absolutePath.IsSubfolderOf(parentPath)) { return(absolutePath); } return(OSTailoredCode.IsUnixHost ? "./" + OSTailoredCode.SimpleSubshell("realpath", $"--relative-to=\"{parentPath}\" \"{absolutePath}\"", $"invalid path {absolutePath} or missing realpath binary") : absolutePath.Replace(parentPath, ".")); #else // written for Unix port but may be useful for .NET Core if (!IsSubfolder(parentPath, absolutePath)) { return(OSTailoredCode.IsUnixHost && parentPath.TrimEnd('.') == $"{absolutePath}/" ? "." : absolutePath); } return(OSTailoredCode.IsUnixHost ? absolutePath.Replace(parentPath.TrimEnd('.'), "./") : absolutePath.Replace(parentPath, ".")); #endif }
public static string SaveStateAbsolutePath(this PathEntryCollection collection, string systemId) { var pathEntry = collection[systemId, "Savestates"] ?? collection[systemId, "Base"]; return(collection.AbsolutePathFor(pathEntry.Path, systemId)); }
/// <summary> /// Puts the currently configured temp path into the environment for use as actual temp directory /// </summary> public static void RefreshTempPath(this PathEntryCollection collection) { if (string.IsNullOrWhiteSpace(collection.TempFilesFragment)) { return; } var path = collection.AbsolutePathFor(collection.TempFilesFragment, null); TempFileManager.HelperSetTempPath(path); }
public static string SaveRamAbsolutePath(this PathEntryCollection collection, IGameInfo game, IMovie movie) { var name = game.FilesystemSafeName(); if (movie.IsActive()) { name += $".{Path.GetFileNameWithoutExtension(movie.Filename)}"; } var pathEntry = collection[game.System, "Save RAM"] ?? collection[game.System, "Base"]; return($"{Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name)}.SaveRAM"); }
// Shenanigans public static string RetroSystemAbsolutePath(this PathEntryCollection collection, IGameInfo game) { var name = game.FilesystemSafeName(); name = Path.GetDirectoryName(name); if (string.IsNullOrEmpty(name)) { name = game.FilesystemSafeName(); } var pathEntry = collection[game.System, "System"] ?? collection[game.System, "Base"]; return(Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name)); }
// Shenanigans public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, IGameInfo game) { var name = game.FilesystemSafeName(); name = Path.GetDirectoryName(name); if (name == "") { name = game.FilesystemSafeName(); } name ??= ""; var pathEntry = collection[game.System, "Save RAM"] ?? collection[game.System, "Base"]; return(Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name)); }
// Shenanigans public static string RetroSaveRamAbsolutePath(this PathEntryCollection collection, GameInfo game, bool movieIsActive, string movieFilename) { var name = game.FilesystemSafeName(); name = Path.GetDirectoryName(name); if (name == "") { name = game.FilesystemSafeName(); } if (movieIsActive) { name = Path.Combine(name, $"movie-{Path.GetFileNameWithoutExtension(movieFilename)}"); } var pathEntry = collection[game.System, "Save RAM"] ?? collection[game.System, "Base"]; return(Path.Combine(collection.AbsolutePathFor(pathEntry.Path, game.System), name)); }
public static string ToolsAbsolutePath(this PathEntryCollection collection) { var path = collection["Global", "Tools"].Path; return(collection.AbsolutePathFor(path, null)); }
public static string LuaAbsolutePath(this PathEntryCollection collection) { var path = collection[PathEntryCollection.GLOBAL, "Lua"].Path; return(collection.AbsolutePathFor(path, null)); }
public void DoScanAndResolve(PathEntryCollection pathEntries, IDictionary<string, string> userSpecifications) { // build a list of file sizes. Only those will be checked during scanning var sizes = new HashSet<long>(); foreach (var ff in FirmwareDatabase.FirmwareFiles) { sizes.Add(ff.Size); } using var reader = new RealFirmwareReader(); // build a list of files under the global firmwares path, and build a hash for each of them while we're at it var todo = new Queue<DirectoryInfo>(); todo.Enqueue(new DirectoryInfo(pathEntries.AbsolutePathFor(pathEntries.FirmwaresPathFragment, null))); while (todo.Count != 0) { var di = todo.Dequeue(); if (!di.Exists) { continue; } // we're going to allow recursing into subdirectories, now. its been verified to work OK foreach (var subDir in di.GetDirectories()) { todo.Enqueue(subDir); } foreach (var fi in di.GetFiles()) { if (sizes.Contains(fi.Length)) { reader.Read(fi); } } } // now, for each firmware record, try to resolve it foreach (var fr in FirmwareDatabase.FirmwareRecords) { // clear previous resolution results _resolutionDictionary.Remove(fr); // get all options for this firmware (in order) var fr1 = fr; var options = FirmwareDatabase.FirmwareOptions .Where(fo => fo.SystemId == fr1.SystemId && fo.FirmwareId == fr1.FirmwareId && fo.IsAcceptableOrIdeal); // try each option foreach (var fo in options) { var hash = fo.Hash; // did we find this firmware? if (reader.Dict.ContainsKey(hash)) { // rad! then we can use it var ri = new ResolutionInfo { FilePath = reader.Dict[hash].FileInfo.FullName, KnownFirmwareFile = FirmwareDatabase.FirmwareFilesByHash[hash], Hash = hash, Size = fo.Size }; _resolutionDictionary[fr] = ri; goto DONE_FIRMWARE; } } DONE_FIRMWARE: ; } // apply user overrides foreach (var fr in FirmwareDatabase.FirmwareRecords) { // do we have a user specification for this firmware record? if (userSpecifications.TryGetValue(fr.ConfigKey, out var userSpec)) { // flag it as user specified if (!_resolutionDictionary.TryGetValue(fr, out ResolutionInfo ri)) { ri = new ResolutionInfo(); _resolutionDictionary[fr] = ri; } ri.UserSpecified = true; ri.KnownFirmwareFile = null; ri.FilePath = userSpec; ri.Hash = null; // check whether it exists var fi = new FileInfo(userSpec); if (!fi.Exists) { ri.Missing = true; continue; } // compute its hash RealFirmwareFile rff; // NDS's firmware file contains user settings; these are over-written by sync settings, so we shouldn't allow them to impact the hash if (fr.SystemId == "NDS" && fr.FirmwareId == "firmware") rff = reader.Read(new FileInfo(Emulation.Cores.Consoles.Nintendo.NDS.MelonDS.CreateModifiedFirmware(userSpec))); else rff = reader.Read(fi); ri.Size = fi.Length; ri.Hash = rff.Hash; // check whether it was a known file anyway, and go ahead and bind to the known file, as a perk (the firmwares config doesn't really use this information right now) if (FirmwareDatabase.FirmwareFilesByHash.TryGetValue(rff.Hash, out var ff)) { ri.KnownFirmwareFile = ff; // if the known firmware file is for a different firmware, flag it so we can show a warning var option = FirmwareDatabase.FirmwareOptions .FirstOrDefault(fo => fo.Hash == rff.Hash && fo.ConfigKey != fr.ConfigKey); if (option != null) { ri.KnownMismatching = true; } } } } // foreach(firmware record) } // DoScanAndResolve()
public static string PalettesAbsolutePathFor(this PathEntryCollection collection, string systemId) { return(collection.AbsolutePathFor(collection[systemId, "Palettes"].Path, systemId)); }
public static string WatchAbsolutePath(this PathEntryCollection collection) { var path = collection.ResolveToolsPath(collection["Global", "Watch (.wch)"].Path); return(collection.AbsolutePathFor(path, null)); }
public static string LogAbsolutePath(this PathEntryCollection collection) { var path = collection.ResolveToolsPath(collection["Global", "Debug Logs"].Path); return(collection.AbsolutePathFor(path, null)); }
public static string FirmwareAbsolutePath(this PathEntryCollection collection) { return(collection.AbsolutePathFor(collection.FirmwaresPathFragment, null)); }
public static string MovieBackupsAbsolutePath(this PathEntryCollection collection) { var path = collection["Global", "Movie backups"].Path; return(collection.AbsolutePathFor(path, null)); }
/// <summary> /// Takes an absolute path and attempts to convert it to a relative, based on the system, /// or global base if no system is supplied, if it is not a subfolder of the base, it will return the path unaltered /// </summary> public static string TryMakeRelative(this PathEntryCollection collection, string absolutePath, string system = null) => absolutePath.MakeRelativeTo( string.IsNullOrWhiteSpace(system) ? collection.GlobalBaseAbsolutePath() : collection.AbsolutePathFor(collection.BaseFor(system), system) );
public static string TastudioStatesAbsolutePath(this PathEntryCollection collection) { var path = collection["Global", "TAStudio states"].Path; return(collection.AbsolutePathFor(path, null)); }
public static string AbsolutePathForType(this PathEntryCollection collection, string systemId, string type) { var path = collection.EntryWithFallback(type, systemId).Path; return(collection.AbsolutePathFor(path, systemId)); }
public static string MultiDiskAbsolutePath(this PathEntryCollection collection) { var path = collection.ResolveToolsPath(collection["Global", "Multi-Disk Bundles"].Path); return(collection.AbsolutePathFor(path, null)); }