Beispiel #1
0
 public void Dispose()
 {
     _src  = null;
     _root = null;
     _tables.Clear();
     GC.Collect();
 }
Beispiel #2
0
 public void Dispose()
 {
     this.src  = null;
     this.root = null;
     this.tables.Clear();
     GC.Collect();
 }
Beispiel #3
0
        public Queue <GDFStreamEntry> GetFileSystem(GDFDirTable Root)
        {
            Queue <GDFStreamEntry> fs = new Queue <GDFStreamEntry>();

            this.getFileSystem(ref fs, Root, "*");
            return(fs);
        }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
 public void GenerateGDF()
 {
     _tables = new List <GDFDirTable>();
     _root   = new GDFDirTable();
     BuildTables(ref _root, _path);
     updateTableSectors();
 }
Beispiel #6
0
 public void GenerateGDF()
 {
     this.tables = new List <GDFDirTable>();
     this.root   = new GDFDirTable();
     this.buildTables(ref this.root, this.path);
     this.updateTableSectors();
 }
Beispiel #7
0
 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);
         }
     }
 }
Beispiel #8
0
 public GDF(FileStream File)
 {
     file = File;
     fr   = new CBinaryReader(EndianType.LittleEndian, file);
     readVolume();
     try
     {
         rootDir = new GDFDirTable(fr, volDesc, volDesc.RootDirSector, volDesc.RootDirSize);
     }
     catch (Exception exception)
     {
         Exceptions.Add(exception);
     }
 }
Beispiel #9
0
 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);
     }
 }
Beispiel #10
0
 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 }));
         }
     }
 }
Beispiel #11
0
 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);
 }
Beispiel #12
0
        public object Clone()
        {
            GDFDirTable table = new GDFDirTable {
                Sector = this.Sector,
                Size   = this.Size
            };

            foreach (GDFDirEntry entry in this)
            {
                GDFDirEntry item = (GDFDirEntry)entry.Clone();
                item.Parent = table;
                table.Add(item);
            }
            return(table);
        }
Beispiel #13
0
 public long WriteFileToStream(string Path, CBinaryWriter Writer)
 {
     try
     {
         GDFDirTable folder = this.GetFolder(this.rootDir, Path);
         string      str    = Path.Contains(@"\") ? Path.Substring(Path.LastIndexOf(@"\") + 1) : Path;
         foreach (GDFDirEntry entry in folder)
         {
             if (entry.Name.ToLower() == str.ToLower())
             {
                 this.fr.Seek((long)(this.volDesc.RootOffset + (entry.Sector * this.volDesc.SectorSize)), SeekOrigin.Begin);
                 uint num  = (uint)Math.Ceiling((double)(((double)entry.Size) / ((double)this.volDesc.SectorSize)));
                 long num2 = 0L;
                 for (uint i = 0; i < num; i++)
                 {
                     byte[] buffer;
                     if ((num2 + this.volDesc.SectorSize) > entry.Size)
                     {
                         buffer = this.fr.ReadBytes((int)(entry.Size - num2));
                         Writer.Write(buffer);
                         int num4 = ((int)this.volDesc.SectorSize) - buffer.Length;
                         for (int j = 0; j < num4; j++)
                         {
                             Writer.Write((byte)0);
                         }
                     }
                     else
                     {
                         buffer = this.fr.ReadBytes((int)this.volDesc.SectorSize);
                         Writer.Write(buffer);
                     }
                     num2 += this.volDesc.SectorSize;
                 }
                 return((long)entry.Size);
             }
         }
     }
     catch (Exception exception)
     {
         this.Exceptions.Add(exception);
     }
     return(-1L);
 }
Beispiel #14
0
 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);
 }
Beispiel #15
0
 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);
         }
     }
 }
Beispiel #16
0
 public bool Exists(string Path)
 {
     try
     {
         GDFDirTable folder = this.GetFolder(this.rootDir, Path);
         string      str    = Path.Contains(@"\") ? Path.Substring(Path.LastIndexOf(@"\") + 1) : Path;
         foreach (GDFDirEntry entry in folder)
         {
             if (entry.Name.ToLower() == str.ToLower())
             {
                 return(true);
             }
         }
     }
     catch (Exception exception)
     {
         this.Exceptions.Add(exception);
     }
     return(false);
 }
Beispiel #17
0
 public byte[] GetFile(string Path)
 {
     try
     {
         GDFDirTable folder = this.GetFolder(this.rootDir, Path);
         string      str    = Path.Contains(@"\") ? Path.Substring(Path.LastIndexOf(@"\") + 1) : Path;
         foreach (GDFDirEntry entry in folder)
         {
             if (entry.Name.ToLower() == str.ToLower())
             {
                 this.fr.Seek((long)(this.volDesc.RootOffset + (entry.Sector * this.volDesc.SectorSize)), SeekOrigin.Begin);
                 return(this.fr.ReadBytes((int)entry.Size));
             }
         }
     }
     catch (Exception exception)
     {
         this.Exceptions.Add(exception);
     }
     return(new byte[0]);
 }
Beispiel #18
0
        public List <GDFDirEntry> GetDirContents(string Path)
        {
            List <GDFDirEntry> list = new List <GDFDirEntry>();

            try
            {
                GDFDirTable folder = this.GetFolder(this.rootDir, Path);
                if (folder == null)
                {
                    return(list);
                }
                foreach (GDFDirEntry entry in folder)
                {
                    list.Add(entry);
                }
            }
            catch (Exception exception)
            {
                this.Exceptions.Add(exception);
            }
            return(list);
        }
Beispiel #19
0
 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;
         }
     }
 }