private void writeFiles(GDF src, CBinaryWriter bw, GDFDirTable table) { uint fileCount = src.FileCount; foreach (GDFDirEntry entry in table) { if (!entry.IsDirectory) { bw.Seek((long)(entry.Sector * src.VolDesc.SectorSize), SeekOrigin.Begin); string path = ""; this.calcPath(table, entry, ref path); if (path.StartsWith(@"\")) { path = path.Remove(0, 1); } this.progress += ((1f / ((float)fileCount)) * 0.45f) * 100f; base.ReportProgress((int)this.progress, "Writing '" + path + "' at Sector 0x" + entry.Sector.ToString("X02") + "..."); src.WriteFileToStream(path, bw); } } foreach (GDFDirEntry entry2 in table) { if (entry2.IsDirectory && (entry2.SubDir != null)) { this.writeFiles(src, bw, entry2.SubDir); } } }
private void writeFiles(GDF src, CBinaryWriter bw, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (!entry.IsDirectory) { bw.Seek(entry.Sector * src.VolDesc.SectorSize, SeekOrigin.Begin); string path = ""; calcPath(table, entry, ref path); if (path.StartsWith(@"\")) { path = path.Remove(0, 1); } Console.WriteLine("+ Writing '" + path + "' at Sector 0x" + entry.Sector.ToString("X02") + "..."); src.WriteFileToStream(path, bw); } } foreach (GDFDirEntry entry2 in table) { if (entry2.IsDirectory && (entry2.SubDir != null)) { writeFiles(src, bw, entry2.SubDir); } } }
private void writeGDFtable(GDF src, CBinaryWriter bw, GDFDirTable table) { bw.Seek(table.Sector * src.VolDesc.SectorSize, SeekOrigin.Begin); byte[] buffer = table.ToByteArray(); bw.Write(buffer); foreach (GDFDirEntry entry in table) { if (entry.IsDirectory && (entry.SubDir != null)) { writeGDFtable(src, bw, entry.SubDir); } } }
public GDF(FileStream File) { this.file = File; this.fr = new CBinaryReader(EndianType.LittleEndian, this.file); this.readVolume(); try { this.rootDir = new GDFDirTable(this.fr, this.volDesc, this.volDesc.RootDirSector, this.volDesc.RootDirSize); } catch (Exception exception) { this.Exceptions.Add(exception); } }
private void Iso2God_Full(object sender, DoWorkEventArgs e) { FileStream stream; FileStream stream2; base.ReportProgress((int)this.progress, "Preparing to rebuild ISO image..."); IsoEntry argument = (IsoEntry)e.Argument; try { stream = new FileStream(argument.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } catch (Exception exception) { base.ReportProgress(0, "Error! " + exception.Message); return; } using (GDF gdf = new GDF(stream)) { uint lastSector = 0; gdf.ParseDirectory(gdf.RootDir, true, ref lastSector); base.ReportProgress((int)this.progress, "Generating new GDFS structures..."); try { stream2 = File.OpenWrite(argument.Padding.IsoPath + argument.Path.Substring(argument.Path.LastIndexOf(Path.DirectorySeparatorChar) + 1) + "_rebuilt.iso"); } catch (Exception exception2) { base.ReportProgress(0, "Error rebuilding GDF! " + exception2.Message); return; } this.rootDir = (GDFDirTable)gdf.RootDir.Clone(); this.RemapSectors(gdf); this.WriteGDF(gdf, stream2); this.WriteFiles(gdf, stream2); } if (stream2.Length > 0L) { base.ReportProgress((int)this.progress, "ISO image rebuilt."); argument.Path = stream2.Name; argument.Size = stream2.Length; stream2.Close(); stream.Close(); this.Iso2God_Partial(sender, e, false, argument); } else { base.ReportProgress(100, "Failed to rebuild ISO. Aborting."); } }
private void remapFiles(GDF src, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (!entry.IsDirectory) { entry.Sector = freeSector; freeSector += sizeToSectors(src, entry.Size); } } foreach (GDFDirEntry entry2 in table) { if (entry2.IsDirectory && (entry2.SubDir != null)) { remapFiles(src, entry2.SubDir); } } }
private void calcPath(GDFDirTable t, GDFDirEntry e, ref string path) { if (e != null) { path = path.Insert(0, @"\" + e.Name); if (e.Parent != null) { calcPath(e.Parent, null, ref path); } } else if (t.Parent != null) { path = path.Insert(0, @"\" + t.Parent.Name); if (t.Parent.Parent != null) { calcPath(t.Parent.Parent, null, ref path); } } }
private void remapDirs(GDF src, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (entry.IsDirectory) { if (entry.SubDir == null) { entry.Sector = 0; entry.Size = 0; } else { entry.Sector = freeSector; entry.SubDir.Sector = freeSector; entry.SubDir.Parent = entry; freeSector += sizeToSectors(src, entry.Size); Console.WriteLine("+ Remapped '" + entry.Name + "' (" + sizeToSectors(src, entry.Size) + " sectors) to Sector 0x" + entry.Sector.ToString("X02")); remapDirs(src, entry.SubDir); } } } }
private void remapDirs(GDF src, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (entry.IsDirectory) { if (entry.SubDir == null) { entry.Sector = 0; entry.Size = 0; } else { entry.Sector = this.freeSector; entry.SubDir.Sector = this.freeSector; entry.SubDir.Parent = entry; this.freeSector += this.sizeToSectors(src, entry.Size); base.ReportProgress(0, "Remapped '" + entry.Name + "' (" + this.sizeToSectors(src, entry.Size).ToString() + " sectors) to Sector 0x" + entry.Sector.ToString("X02")); this.remapDirs(src, entry.SubDir); } } } }
private void calcSectors(GDFDirTable table, GDFStats stats) { stats.UsedDirSectors += (uint) Math.Ceiling((double) (((double) table.Size) / ((double) stats.SectorSize))); stats.TotalDirs++; foreach (GDFDirEntry entry in table) { if (entry.IsDirectory) { if (entry.SubDir == null) { entry.SubDir = new GDFDirTable(this.fr, this.volDesc, entry.Sector, entry.Size); entry.SubDir.Parent = entry; } this.calcSectors(entry.SubDir, stats); } else { uint num = (uint) Math.Ceiling((double) (((double) entry.Size) / ((double) stats.SectorSize))); stats.TotalFiles++; stats.UsedDataSectors += num; stats.DataBytes += entry.Size; } } }
private void writeFiles(GDF src, CBinaryWriter bw, GDFDirTable table) { uint fileCount = src.FileCount; foreach (GDFDirEntry entry in table) { if (!entry.IsDirectory) { bw.Seek((long) (entry.Sector * src.VolDesc.SectorSize), SeekOrigin.Begin); string path = ""; this.calcPath(table, entry, ref path); if (path.StartsWith(@"\")) { path = path.Remove(0, 1); } this.progress += ((1f / ((float) fileCount)) * 0.45f) * 100f; base.ReportProgress((int) this.progress, "Writing '" + path + "' at Sector 0x" + entry.Sector.ToString("X02") + "..."); src.WriteFileToStream(path, bw); } } foreach (GDFDirEntry entry2 in table) { if (entry2.IsDirectory && (entry2.SubDir != null)) { this.writeFiles(src, bw, entry2.SubDir); } } }
public GDFDirTable GetFolder(GDFDirTable Table, string Path) { try { if (Path.Length == 0) { return Table; } string[] strArray = new string[1]; if (Path.Contains(@"\")) { strArray = Path.Split(new char[] { '\\' }); } else { strArray[0] = Path; } foreach (GDFDirEntry entry in Table) { if (entry.Name.ToLower() == strArray[0].ToLower()) { if (!entry.IsDirectory) { return Table; } if (entry.SubDir == null) { entry.SubDir = new GDFDirTable(this.fr, this.volDesc, entry.Sector, entry.Size); } if (strArray.Length == 1) { return entry.SubDir; } return this.GetFolder(entry.SubDir, Path.Substring(strArray[0].Length + 1)); } } } catch (Exception exception) { this.Exceptions.Add(exception); } return null; }
public void ParseDirectory(GDFDirTable table, bool recursive, ref uint lastSector) { try { foreach (GDFDirEntry entry in table) { if (entry.Sector >= lastSector) { lastSector = entry.Sector + ((uint) Math.Ceiling((double) (((double) entry.Size) / ((double) this.volDesc.SectorSize)))); } if (entry.IsDirectory) { this.dirs++; entry.SubDir = new GDFDirTable(this.fr, this.volDesc, entry.Sector, entry.Size); entry.SubDir.Parent = entry; if (recursive) { this.ParseDirectory(entry.SubDir, true, ref lastSector); } } else { this.files++; } } } catch (Exception exception) { this.Exceptions.Add(exception); } }
public Queue<GDFStreamEntry> GetFileSystem(GDFDirTable Root) { Queue<GDFStreamEntry> fs = new Queue<GDFStreamEntry>(); this.getFileSystem(ref fs, Root, "*"); return fs; }
public void Dispose() { this.src = null; this.root = null; this.tables.Clear(); GC.Collect(); }
private void buildTables(ref GDFDirTable t, string dir) { string[] directories = Directory.GetDirectories(dir); string[] files = Directory.GetFiles(dir); t.Size = (uint) ((directories.Length + files.Length) * 0x90); if (t.Parent != null) { t.Parent.Size = t.Size; } foreach (string str in directories) { GDFDirEntry entry; entry = new GDFDirEntry { Name = str.Substring(str.LastIndexOf(@"\") + 1), NameLength = (byte) entry.Name.Length, Attributes = GDFDirEntryAttrib.Directory, SubDir = new GDFDirTable() }; entry.SubDir.Parent = entry; entry.Parent = t; t.Add(entry); this.buildTables(ref entry.SubDir, str); } foreach (string str2 in files) { if (!str2.EndsWith("i2g.iso")) { GDFDirEntry entry2; entry2 = new GDFDirEntry { Name = str2.Substring(str2.LastIndexOf(@"\") + 1), NameLength = (byte) entry2.Name.Length, Attributes = GDFDirEntryAttrib.Normal, SubDir = null, Parent = t }; try { uint.TryParse(File.ReadAllText(str2, Encoding.ASCII), out entry2.Size); } catch (Exception) { entry2.Size = 0; Console.WriteLine("Exception occured when reading file size from disk for {0}", entry2.Name); } t.Add(entry2); } } this.tables.Add(t); }
private void remapFiles(GDF src, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (!entry.IsDirectory) { entry.Sector = this.freeSector; this.freeSector += this.sizeToSectors(src, entry.Size); } } foreach (GDFDirEntry entry2 in table) { if (entry2.IsDirectory && (entry2.SubDir != null)) { this.remapFiles(src, entry2.SubDir); } } }
private void Iso2God_Full(object sender, DoWorkEventArgs e) { FileStream stream; FileStream stream2; base.ReportProgress((int) this.progress, "Preparing to rebuild ISO image..."); IsoEntry argument = (IsoEntry) e.Argument; try { stream = new FileStream(argument.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } catch (Exception exception) { base.ReportProgress(0, "Error! " + exception.Message); return; } using (GDF gdf = new GDF(stream)) { uint lastSector = 0; gdf.ParseDirectory(gdf.RootDir, true, ref lastSector); base.ReportProgress((int) this.progress, "Generating new GDFS structures..."); try { stream2 = File.OpenWrite(argument.Padding.IsoPath + argument.Path.Substring(argument.Path.LastIndexOf(Path.DirectorySeparatorChar) + 1) + "_rebuilt.iso"); } catch (Exception exception2) { base.ReportProgress(0, "Error rebuilding GDF! " + exception2.Message); return; } this.rootDir = (GDFDirTable) gdf.RootDir.Clone(); this.RemapSectors(gdf); this.WriteGDF(gdf, stream2); this.WriteFiles(gdf, stream2); } if (stream2.Length > 0L) { base.ReportProgress((int) this.progress, "ISO image rebuilt."); argument.Path = stream2.Name; argument.Size = stream2.Length; stream2.Close(); stream.Close(); this.Iso2God_Partial(sender, e, false, argument); } else { base.ReportProgress(100, "Failed to rebuild ISO. Aborting."); } }
private void saveFileSystemTable(StreamWriter file, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (entry.IsDirectory) { this.saveFileSystemTable(file, entry.SubDir); } else { file.WriteLine(string.Concat(new object[] { entry.Sector, "\t\t", entry.Size, "\t\t", Math.Ceiling((double) (((double) entry.Size) / ((double) this.volDesc.SectorSize))), "\t\t", entry.Name })); } } }
private void calcPath(GDFDirTable t, GDFDirEntry e, ref string path) { if (e != null) { path = path.Insert(0, @"\" + e.Name); if (e.Parent != null) { this.calcPath(e.Parent, null, ref path); } } else if (t.Parent != null) { path = path.Insert(0, @"\" + t.Parent.Name); if (t.Parent.Parent != null) { this.calcPath(t.Parent.Parent, null, ref path); } } }
private void writeGDFtable(GDF src, CBinaryWriter bw, GDFDirTable table) { bw.Seek((long) (table.Sector * src.VolDesc.SectorSize), SeekOrigin.Begin); byte[] buffer = table.ToByteArray(); bw.Write(buffer); foreach (GDFDirEntry entry in table) { if (entry.IsDirectory && (entry.SubDir != null)) { this.writeGDFtable(src, bw, entry.SubDir); } } }
public void GenerateGDF() { this.tables = new List<GDFDirTable>(); this.root = new GDFDirTable(); this.buildTables(ref this.root, this.path); this.updateTableSectors(); }
private void getFileSystem(ref Queue<GDFStreamEntry> fs, GDFDirTable root, string path) { foreach (GDFDirEntry entry in root) { fs.Enqueue(new GDFStreamEntry(entry, path + @"\" + entry.Name)); if (entry.IsDirectory) { this.getFileSystem(ref fs, entry.SubDir, path + @"\" + entry.Name); } } }