/// <summary> /// Saves the file to the specified stream. /// </summary> /// <param name="stream">The stream to save to.</param> public override void Save(Stream stream) { BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR")); writer.Write(BaseVersion); writer.Write(CurrentVersion); writer.Write(FileSystems.Count); long[] fileSystemOffsets = new long[FileSystems.Count]; for (int i = 0; i < FileSystems.Count; i++) { VirtualFileIndexSystem fileSystem = FileSystems[i]; writer.WriteShortString(fileSystem.FileName); fileSystemOffsets[i] = stream.Position; writer.Write(0); } for (int i = 0; i < FileSystems.Count; i++) { VirtualFileIndexSystem fileSystem = FileSystems[i]; long entryOffset = stream.Position; stream.Seek(fileSystemOffsets[i], SeekOrigin.Begin); writer.Write((int)entryOffset); stream.Seek(entryOffset, SeekOrigin.Begin); var deletedFiles = from f in fileSystem.Files where f.IsDeleted select f; var startOffset = from f in fileSystem.Files orderby f.Offset select f.Offset; writer.Write(fileSystem.Files.Count); writer.Write(deletedFiles.Count()); writer.Write(startOffset.First()); fileSystem.Files.ForEach(file => { writer.WriteShortString(file.FilePath); writer.Write(file.Offset); writer.Write(file.Size); writer.Write(file.BlockSize); writer.Write(file.IsDeleted); writer.Write(file.IsCompressed); writer.Write(file.IsEncrypted); writer.Write(file.Version); writer.Write(file.Checksum); }); } }
/// <summary> /// Loads the file from the specified stream. /// </summary> /// <param name="stream">The stream to read from.</param> public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR")); BaseVersion = reader.ReadInt32(); CurrentVersion = reader.ReadInt32(); int fileSystemCount = reader.ReadInt32(); for (int i = 0; i < fileSystemCount; i++) { VirtualFileIndexSystem fileSystem = new VirtualFileIndexSystem(); fileSystem.FileName = reader.ReadShortString(); int offset = reader.ReadInt32(); long nextFileSystem = stream.Position; stream.Seek(offset, SeekOrigin.Begin); int fileCount = reader.ReadInt32(); int deleteCount = reader.ReadInt32(); int startOffset = reader.ReadInt32(); for (int j = 0; j < fileCount; j++) { VirtualFileIndexEntry file = new VirtualFileIndexEntry(); file.FilePath = reader.ReadShortString(); file.Offset = reader.ReadInt32(); file.Size = reader.ReadInt32(); file.BlockSize = reader.ReadInt32(); file.IsDeleted = reader.ReadBoolean(); file.IsCompressed = reader.ReadBoolean(); file.IsEncrypted = reader.ReadBoolean(); file.Version = reader.ReadInt32(); file.Checksum = reader.ReadInt32(); fileSystem.Files.Add(file); } FileSystems.Add(fileSystem); if (i < fileSystemCount - 1) { stream.Seek(nextFileSystem, SeekOrigin.Begin); } } }
/// <summary> /// Loads the file from the specified stream. /// </summary> /// <param name="stream">The stream to read from.</param> public override void Load(Stream stream) { BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("EUC-KR")); BaseVersion = reader.ReadInt32(); CurrentVersion = reader.ReadInt32(); int fileSystemCount = reader.ReadInt32(); for (int i = 0; i < fileSystemCount; i++) { VirtualFileIndexSystem fileSystem = new VirtualFileIndexSystem(); fileSystem.FileName = reader.ReadShortString(); int offset = reader.ReadInt32(); long nextFileSystem = stream.Position; stream.Seek(offset, SeekOrigin.Begin); int fileCount = reader.ReadInt32(); /*int deleteCount = */reader.ReadInt32(); /*int startOffset = */reader.ReadInt32(); for (int j = 0; j < fileCount; j++) { VirtualFileIndexEntry file = new VirtualFileIndexEntry(); file.FilePath = reader.ReadShortString(); file.Offset = reader.ReadInt32(); file.Size = reader.ReadInt32(); file.BlockSize = reader.ReadInt32(); file.IsDeleted = reader.ReadBoolean(); file.IsCompressed = reader.ReadBoolean(); file.IsEncrypted = reader.ReadBoolean(); file.Version = reader.ReadInt32(); file.Checksum = reader.ReadInt32(); fileSystem.Files.Add(file); } FileSystems.Add(fileSystem); if (i < fileSystemCount - 1) { stream.Seek(nextFileSystem, SeekOrigin.Begin); } } }