public void SingleFile() { MemoryStream fsImage = new MemoryStream(); SquashFileSystemBuilder builder = new SquashFileSystemBuilder(); builder.AddFile("file", new MemoryStream(new byte[] { 1, 2, 3, 4 })); builder.Build(fsImage); SquashFileSystemReader reader = new SquashFileSystemReader(fsImage); Assert.Equal(1, reader.GetFileSystemEntries("\\").Length); Assert.Equal(4, reader.GetFileLength("file")); Assert.True(reader.FileExists("file")); Assert.False(reader.DirectoryExists("file")); Assert.False(reader.FileExists("otherfile")); }
public void CreateDirs() { MemoryStream fsImage = new MemoryStream(); SquashFileSystemBuilder builder = new SquashFileSystemBuilder(); builder.AddFile(@"\adir\anotherdir\file", new MemoryStream(new byte[] { 1, 2, 3, 4 })); builder.Build(fsImage); SquashFileSystemReader reader = new SquashFileSystemReader(fsImage); Assert.True(reader.DirectoryExists(@"adir")); Assert.True(reader.DirectoryExists(@"adir\anotherdir")); Assert.True(reader.FileExists(@"adir\anotherdir\file")); }
/// <summary>Explodes the UCE file and places individual files in repsective directories (coverart, bezelart, etc.).</summary> /// <param name="fileName">Name of the file.</param> /// <param name="overwrite">if set to <c>true</c> [overwrite].</param> /// <returns></returns> internal static VaultRecordCSV_ViewModel ExplodeUCE(string fileName, string defaultGenre = "Unknown", bool overwrite = false) { var vCart = new VaultRecordCSV_ViewModel(); string boxArtFileName = ""; string bezelArtFileName = ""; string emulatorFileName = ""; string romFileName = ""; vCart.Genre = defaultGenre; using (FileStream isoStream = File.OpenRead(fileName)) { SquashFileSystemReader readCart = new SquashFileSystemReader(isoStream); if (readCart.FileExists($"cartridge.xml")) { using (Stream entryFs = readCart.OpenFile("cartridge.xml", FileMode.Open)) { byte[] bytes = new byte[entryFs.Length]; entryFs.Position = 0; entryFs.Read(bytes, 0, (int)entryFs.Length); string data = Encoding.ASCII.GetString(bytes); Match m = Regex.Match(data, @"<title>\s*(.+?)\s*</title>"); vCart.Title = m.Success ? m.Groups[1].Value : "No Title Found"; m = Regex.Match(data, @"<desc>\s*(.+?)\s*</desc>"); vCart.Description = m.Success ? m.Groups[1].Value : "No Desc Found"; } if (readCart.FileExists($"exec.sh")) { using (Stream entryFs = readCart.OpenFile("exec.sh", FileMode.Open)) { byte[] bytes = new byte[entryFs.Length]; entryFs.Position = 0; entryFs.Read(bytes, 0, (int)entryFs.Length); string data = Encoding.ASCII.GetString(bytes); //Parse out Bezel FileName var bezelArtData = data.Split(new string[] { " /tmp" }, StringSplitOptions.None)[0]; var indexOfBoxArt = bezelArtData.kIndexOf("./boxart/", System.Globalization.CompareOptions.IgnoreCase); bezelArtFileName = bezelArtData.Substring(indexOfBoxArt + 9).TrimEnd(new char[] { ' ', '\"' }); // /emulator/retroplayer ./emu/fceumm_libretro.so "./roms/Top gun.nes" var emulatorData = data.Split(new string[] { "./roms" }, StringSplitOptions.None); var indexOfEmulator = emulatorData[0].kIndexOf(" ./emu/", System.Globalization.CompareOptions.IgnoreCase); emulatorFileName = emulatorData[0].Substring(indexOfEmulator + 7).TrimEnd(new char[] { ' ', '\"' }); vCart.EmulatorCoreFile = emulatorFileName; var indexOfROM = emulatorData[1].kIndexOf("\n", System.Globalization.CompareOptions.IgnoreCase); romFileName = emulatorData[1].Substring(1, indexOfROM - 1).TrimEnd(new char[] { ' ', '\"' }); vCart.ROMFile = romFileName; } //Cover Art (Boxart) if (readCart.FileExists($"title.png")) { vCart.CoverArtFile = $"{_Settings.DefaultFolder_BoxArt}\\{vCart.Title.Replace(" ", "_")}_cover.png"; if (!File.Exists(vCart.CoverArtFile) || overwrite) { using (Stream bxArtFile = readCart.OpenFile($"title.png", FileMode.Open)) { Image.FromStream(bxArtFile).Save(vCart.CoverArtFile); } } else { throw new Exception($"File {vCart.CoverArtFile} already exists in Vault"); } } //Bezel Art if (readCart.FileExists($"boxart\\{bezelArtFileName}")) { vCart.BezelArtFile = $"{_Settings.DefaultFolder_BezelArt}\\{vCart.Title.Replace(" ", "_")}_bezel.png"; if (!File.Exists(vCart.BezelArtFile) || overwrite) { using (Stream bzArtFile = readCart.OpenFile($"boxart\\{bezelArtFileName}", FileMode.Open)) { Image.FromStream(bzArtFile).Save(vCart.BezelArtFile); } } else { throw new Exception($"File {vCart.BezelArtFile} already exists in Vault"); } } //Emulator if (readCart.FileExists($"emu\\{emulatorFileName}")) { using (Stream emuFile = readCart.OpenFile($"emu\\{emulatorFileName}", FileMode.Open)) { vCart.EmulatorCoreFile = $"{_Settings.DefaultFolder_Cores}\\{emulatorFileName}"; if (!File.Exists(vCart.EmulatorCoreFile)) { using (var fileStream = File.Create(vCart.EmulatorCoreFile)) { emuFile.Seek(0, SeekOrigin.Begin); emuFile.CopyTo(fileStream); } } } } //ROM if (readCart.FileExists($"roms\\{romFileName}")) { using (Stream romFile = readCart.OpenFile($"roms\\{romFileName}", FileMode.Open)) { vCart.ROMFile = $"{_Settings.DefaultFolder_ROMS}\\{romFileName.Replace(" ", "_")}"; if (!File.Exists(vCart.ROMFile) || overwrite) { using (var fileStream = File.Create(vCart.ROMFile)) { romFile.Seek(0, SeekOrigin.Begin); romFile.CopyTo(fileStream); } } else { throw new Exception($"File {vCart.BezelArtFile} already exists in Vault"); } } } } // end if exec.sh exists } // end if cartridge.xml exists } vCart.Index = -1; return(vCart); }