public static Ark GetHarmonixArk(this PlatformData data, string path) { DirectoryNode dir = null; try { dir = data.GetDirectoryStructure(path); } catch { if (File.Exists(path)) { path = Path.GetDirectoryName(path); } if (!Directory.Exists(path)) { throw new FormatException(); } dir = DirectoryNode.FromPath(path, data.Cache); } try { Ark ark = GetHarmonixArk(dir); data.Session["ark"] = ark; return(ark); } catch (Exception exception) { Exceptions.Error(exception, "Unable to open the ark file at " + path); } return(null); }
public static DirectoryNode GetDirectoryStructure(this PlatformData platform, string path) { platform.Session["path"] = path; if (Directory.Exists(path)) { DirectoryNode root = DirectoryNode.FromPath(path, platform.Cache, FileAccess.Read, FileShare.Read); platform.Session["rootdirnode"] = root; return(root); } else if (File.Exists(path)) { Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); platform.Cache.AddStream(stream); try { stream.Position = 0; Iso9660 iso = new Iso9660(stream); platform.Session["iso"] = iso; platform.Session["rootdirnode"] = iso.Root; return(iso.Root); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as ISO: " + path); } try { stream.Position = 0; Disc disc = new Disc(stream); platform.Session["wiidisc"] = disc; Partition partition = disc.DataPartition; if (partition == null) { throw new FormatException(); } platform.Session["rootdirnode"] = partition.Root.Root; return(partition.Root.Root); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as Wiidisc: " + path); } try { stream.Position = 0; U8 u8 = new U8(stream); platform.Session["u8"] = u8; platform.Session["rootdirnode"] = u8.Root; return(u8.Root); } catch (FormatException) { } catch (Exception exception) { Exceptions.Warning(exception, "Trying to open as U8: " + path); } } Exceptions.Error("Could not find a proper file type handler for " + path); throw new NotSupportedException(); }
static void PlatformDetection_DetectDirectory(string path, PlatformList platforms) { if (DetectDirectoryNode != null) { DelayedStreamCache cache = new DelayedStreamCache(); DirectoryNode root = DirectoryNode.FromPath(path, cache, FileAccess.Read, FileShare.Read); DetectDirectoryNode(path, root, platforms); cache.Dispose(); } }
public override PlatformData Create(string path, Game game, ProgressIndicator progress) { PlatformData data = new PlatformData(this, game); DirectoryNode maindir = DirectoryNode.FromPath(path, data.Cache, FileAccess.Read); char[] regions = new char[] { 'E', 'P' }; DirectoryNode dir = maindir.Navigate("private/wii/data", false, true) as DirectoryNode; if (dir == null) dir = maindir; for (char letter = 'A'; letter <= 'Z'; letter++) { foreach (char region in regions) { DirectoryNode subdir = dir.Find("SZ" + letter + region, true) as DirectoryNode; if (subdir == null) continue; foreach (FileNode file in subdir.Files) { if (String.Compare(Path.GetExtension(file.Name), ".bin", true) != 0) continue; try { file.Data.Position = 0; DlcBin bin = new DlcBin(file.Data); U8 u8; try { u8 = new U8(bin.Data); } catch (FormatException) { file.Data.Close(); continue; } FileNode songsdta = u8.Root.Find("songs.dta", SearchOption.AllDirectories) as FileNode; if (songsdta == null) { file.Data.Close(); continue; } DTB.NodeTree dtb = DTA.Create(songsdta.Data); SongsDTA dta = SongsDTA.Create(dtb); file.Data.Close(); SongData song = HarmonixMetadata.GetSongData(data, dtb); string contentbin = dta.Song.Name.Substring(9, 3); // Example, "dlc/sZAE/023/content/songs/simpleman/simpleman" FileNode contentfile = subdir.Find(contentbin + ".bin", true) as FileNode; if (contentfile == null) continue; FormatData formatdata = new TemporaryFormatData(song, data); Create(formatdata, file.Data, contentfile.Data); data.AddSong(formatdata); contentfile.Data.Close(); } catch (FormatException) { } // Not a DLC bin we care about } } } return data; }
static void Main(string[] args) { string dir = string.Empty; if (args.Length == 2) { dir = args[1]; } else if (args.Length == 1) { dir = args[0] + ".ext"; } else { Console.WriteLine("Usage: wiidiscextractor /path/to/disc.iso /extract/path"); return; } Directory.CreateDirectory(dir); try { if (!Directory.Exists(args[0])) { throw new FormatException(); } DelayedStreamCache cache = new DelayedStreamCache(); DirectoryNode dirn = DirectoryNode.FromPath(args[0], cache, FileAccess.Read, FileShare.Read); DirectoryNode gen = dirn.Navigate("gen", false, true) as DirectoryNode; if (gen == null) // Just in case we're given the "wrong" directory that directly contains the ark { gen = dirn; } List <Pair <int, Stream> > arkfiles = new List <Pair <int, Stream> >(); Stream hdrfile = null; foreach (FileNode file in gen.Files) { if (file.Name.ToLower().EndsWith(".hdr")) { hdrfile = file.Data; } else if (file.Name.ToLower().EndsWith(".ark")) { Match match = Regex.Match(file.Name.ToLower(), @"_(\d+).ark"); if (match.Success) { arkfiles.Add(new Pair <int, Stream>(int.Parse(match.Groups[1].Value), file.Data)); } else { arkfiles.Add(new Pair <int, Stream>(0, file.Data)); } } } // FreQuency/Amplitude where the header is the ark if (hdrfile == null) { if (arkfiles.Count == 1) { hdrfile = arkfiles[0].Value; arkfiles.Clear(); } else { throw new FormatException(); } } Ark ark = new Ark(new EndianReader(hdrfile, Endianness.LittleEndian), arkfiles.OrderBy(f => f.Key).Select(f => f.Value).ToArray()); ark.Root.Extract(dir); cache.Dispose(); } catch (FormatException) { Stream stream = new FileStream(args[0], FileMode.Open, FileAccess.Read); try { Iso9660 iso = new Iso9660(stream); iso.Root.Extract(dir); } catch (Exception) { try { stream.Position = 0; Disc disc = new Disc(stream); File.WriteAllText(Path.Combine(dir, "title"), disc.Title); foreach (var partition in disc.Partitions) { string path = Path.Combine(dir, "partition" + disc.Partitions.IndexOf(partition).ToString()); Directory.CreateDirectory(path); partition.Root.Root.Extract(Path.Combine(path, "data")); FileStream file = new FileStream(Path.Combine(path, "partition.tik"), FileMode.Create, FileAccess.Write); partition.Ticket.Save(file); file.Close(); file = new FileStream(Path.Combine(path, "partition.tmd"), FileMode.Create, FileAccess.Write); partition.TMD.Save(file); file.Close(); file = new FileStream(Path.Combine(path, "partition.certs"), FileMode.Create, FileAccess.Write); file.Write(partition.CertificateChain); file.Close(); } } catch { try { stream.Position = 0; DlcBin bin = new DlcBin(stream); U8 u8 = new U8(bin.Data); u8.Root.Extract(dir); } catch { try { stream.Position = 0; U8 u8 = new U8(stream); u8.Root.Extract(dir); } catch { stream.Position = 0; Rarc rarc = new Rarc(stream); rarc.Root.Extract(dir); } } } } stream.Close(); } }