public static DragonFs CreateFromStream(Stream source) { DragonFs newFs = new DragonFs(); DfsSector sector = new DfsSector(0); source.Read(sector.Buffer, 0, (int)DfsSector.SECTOR_SIZE); DfsDirectoryEntry root = new DfsDirectoryEntry(sector); bool checkValid = true; if ((root.Flags != ROOT_FLAGS) || (root.NextEntry != ROOT_NEXTENTRY)) { checkValid = false; } else { // Check DFS version string if (!root.Path.Equals(DragonFs.ROOT_PATH)) { checkValid = false; } } if (checkValid == false) { throw new ArgumentException("source", "The stream does not contain a valid DFS 2.0 image"); } while (source.Position != source.Length) { sector = newFs.NewSector(); source.Read(sector.Buffer, 0, (int)DfsSector.SECTOR_SIZE); } // The virtual root directory entry needs to point to the first sector // TODO: Can this be done better? newFs._RootDirectory.FilePointer = DfsSector.SECTOR_SIZE; return(newFs); }