/// <summary> /// Reverts the FixRomsForStreaming changes /// </summary> public static RomModel[] RevertRomsFromStreaming(RomModel[] roms) { RomModel[] newRoms = new RomModel[roms.Length]; int i = 0; foreach (var rom in roms) { try { if (rom != null && !string.IsNullOrEmpty(rom.Path) && !string.IsNullOrEmpty(rom.StreamingCompatiblePath)) { rom.Path = rom.StreamingCompatiblePath.Replace(ConfigurationHelper.GetStreamingCompatiblityReplacementName(), " "); if (rom.Path != rom.StreamingCompatiblePath) { File.Move(rom.StreamingCompatiblePath, rom.Path); } rom.UseStreamingCompatiblePath = false; newRoms[i] = rom; } } catch (System.IO.IOException) { i++; continue; // This hits randomly but still works? } i++; } return(newRoms); }
/// <summary> /// Changes the ROM filename to be compatible with streaming over Steam Big Picture /// </summary> public static RomModel[] FixRomsForStreaming(RomModel[] roms) { RomModel[] newRoms = new RomModel[roms.Length]; int i = 0; foreach (var rom in roms) { try { if (rom != null && !string.IsNullOrEmpty(rom.Path) && !string.IsNullOrEmpty(rom.StreamingCompatiblePath)) { if (rom.Path != rom.StreamingCompatiblePath) { File.Move(rom.Path, rom.StreamingCompatiblePath); } rom.UseStreamingCompatiblePath = true; newRoms[i] = rom; } } catch (System.IO.IOException) { i++; continue; // This hits randomly but still works? } i++; } return(newRoms); }
private static string GetRomPath(RomModel rom) { if (rom.UseStreamingCompatiblePath) { return(rom.StreamingCompatiblePath); } return(rom.Path); }
/// <summary> /// Populates a rom model for a given rom file and the console aliases from the config file /// </summary> /// <param name="file">Rom File (with full path)</param> /// <param name="consoleAliases">Console Aliases (from app.config)</param> /// <returns>Rom Model</returns> private static RomModel PopulateRomModelFromRomPathRomFileName(string file, string consoleAliases) { RomModel model = new RomModel(); model.Path = file; model.Name = Path.GetFileNameWithoutExtension(file).Replace(ConfigurationHelper.GetStreamingCompatiblityReplacementName(), " "); string streamingFileName = Path.GetFileName(file); // Rplace space in streamingName streamingFileName = streamingFileName.Replace(" ", ConfigurationHelper.GetStreamingCompatiblityReplacementName()); model.StreamingCompatiblePath = string.Format(@"{0}\{1}", Path.GetDirectoryName(file), streamingFileName); string[] filePathParts = file.Split('\\'); string consoles = ConfigurationManager.AppSettings.Get("Consoles"); // Attempt to find the console based on the rom directory (i.e.: FooConsole/BarRom.ext would set the console to FooConsole) // [length - 1] because the length index would be the file name int length = filePathParts.Length - 1; while (length >= 0) { string testFolder = filePathParts[length]; if (consoles.Contains(testFolder)) { model.Console = testFolder; break; } else if (consoleAliases.Contains(testFolder)) { foreach (string consoleAlias in consoleAliases.Split(';')) { if (consoleAlias.Contains(testFolder)) { model.Console = consoleAlias.Split(':')[1]; break; } } } length--; } return(model); }
/// <summary> /// Builds a RomModel for every rom /// </summary> public static RomModel[] GetRomInformationFromDisk(string rootRomDirectory) { string consoleAliases = ConfigurationManager.AppSettings.Get("ConsoleAliases"); RomModel[] models = null; try { models = new RomModel[EnumerateRomFiles(rootRomDirectory)]; } catch (DirectoryNotFoundException ex) { DebugManager.ShowErrorDialog("An error occured getting the rom directory", ex); return(models); } string[] romExtensions = new EmuManagerModel().RomExtensions.Split(','); //TODO: We probably want to take a look at the nesting here int x = 0; try { foreach (string extension in romExtensions) { string[] files = System.IO.Directory.GetFiles(rootRomDirectory, "*." + extension, SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { models[x] = PopulateRomModelFromRomPathRomFileName(files[i], consoleAliases); x++; } } } catch (NullReferenceException) { // This would mean an improperly formatted emulator association was present if hit } catch (IOException) { // This would mean the rom directory was set incorrectly or unreadable } return(models); }
/// <summary> /// Populates a rom model for a given rom file and the console aliases from the config file /// </summary> /// <param name="file">Rom File (with full path)</param> /// <param name="consoleAliases">Console Aliases (from app.config)</param> /// <returns>Rom Model</returns> private static RomModel PopulateRomModelFromRomPathRomFileName(string file, string consoleAliases) { string[] filePathParts = file.Split('\\'); RomModel model = new RomModel(); model.Path = file; model.Name = filePathParts.Last().Split('.')[0]; model.StreamingCompatibleName = StringHelper.RemoveWhitespace(model.Name); string consoles = ConfigurationManager.AppSettings.Get("Consoles"); // [length - 1] because the length index would be the file name int length = filePathParts.Length - 1; while (length >= 0) { string testFolder = filePathParts[length]; if (consoles.Contains(testFolder)) { model.Console = testFolder; break; } else if (consoleAliases.Contains(testFolder)) { foreach (string consoleAlias in consoleAliases.Split(';')) { if (consoleAlias.Contains(testFolder)) { model.Console = consoleAlias.Split(':')[1]; break; } } } length--; } return(model); }
public static void DownloadRomImage(RomModel rom) { throw new System.NotImplementedException(); }