public WZDirectory(string Name, WZFile file, int baseOffset, WZDirectory parent, int Size) { this.Name = Name; this.baseOffset = baseOffset; this.file = file; this.Size = Size; this.parent = parent; }
public IMGFile(string Name, File file, int baseOffset, WZDirectory parent, int Size, int checksum) { loaded = false; this.Name = Name; this.baseOffset = baseOffset; this.file = file; this.Size = Size; this.Directory = parent; this.Checksum = checksum; }
public void Open(WZDirectory other, List <WZPatchOperation> operations, string Base) { int count = file.ReadValue(); List <string> names = new List <string>(); for (int i = 0; i < count; i++) { string Name = ""; int size, checksum, offset; byte type = file.ReadByte(); switch (type) { case 0x02: Name = file.ReadStringAt(true); break; case 0x03: case 0x04: Name = file.ReadString(); break; } size = file.ReadValue(); checksum = file.ReadValue(); offset = file.ReadOffset(); switch (type) { case 0x02: case 0x04: { IMGFile img = other.GetIMG(Base + ((Base == "") ? "" : "/") + Name); if (img == null || img.Checksum != checksum) { operations.Add(new Add(file, offset + file.FileStart, size)); } else { operations.Add(new Copy(other.file, img.baseOffset + other.file.FileStart, img.Size)); } break; } case 0x03: { names.Add(Name); break; } } } foreach (string name in names) { Open(other, operations, Base + ((Base == "") ? "" : "/") + name); } }
public void WriteIMGs(BinaryWriter file) { foreach (DictionaryEntry entry in IMGs) { IMGFile img = (IMGFile)entry.Value; img.Write(file); } foreach (DictionaryEntry entry in Directories) { WZDirectory directory = (WZDirectory)entry.Value; directory.WriteIMGs(file); } }
private int CalculateIMGsSize() { int size = 0; foreach (DictionaryEntry entry in Directories) { WZDirectory directory = (WZDirectory)entry.Value; size += directory.CalculateIMGsSize(); } foreach (DictionaryEntry entry in IMGs) { IMGFile img = (IMGFile)entry.Value; size += img.Size; } return(size); }
public void CreateTempIMGs() { foreach (DictionaryEntry entry in Directories) { WZDirectory directory = (WZDirectory)entry.Value; directory.CreateTempIMGs(); } foreach (DictionaryEntry entry in IMGs) { IMGFile img = (IMGFile)entry.Value; if (img.ToSave) { img.CreateTemp(); } } }
public void Open(WZDirectory other, List <WZPatchOperation> operations) { long soffset = file.file.BaseStream.Position; List <WZPatchOperation> ops = new List <WZPatchOperation>(); file.file.BaseStream.Seek(baseOffset + file.FileStart, SeekOrigin.Begin); Open(other, ops, ""); int size = (int)file.file.BaseStream.Position; operations.Add(new Add(file, 0, size)); operations.AddRange(ops); file.file.BaseStream.Seek(soffset, SeekOrigin.Begin); }
public override void Write(BinaryWriter file) { if (dirOffsets.Contains(this)) { WriteOffsetAt(file, (int)dirOffsets[this], (int)file.BaseStream.Position); } WritePackedInt(file, Directories.Count + IMGs.Count); foreach (DictionaryEntry entry in Directories) { WZDirectory directory = (WZDirectory)entry.Value; WriteString(file, directory.Name, 3, 1, true); WritePackedInt(file, directory.CalculateIMGsSize()); WritePackedInt(file, 0); // checksum dirOffsets[directory] = (int)file.BaseStream.Position; file.Write((int)0); // keep place for the offset } foreach (DictionaryEntry entry in IMGs) { IMGFile img = (IMGFile)entry.Value; img.CalculateChecksum(); WriteString(file, img.Name, 4, 2, true); WritePackedInt(file, img.Size); WritePackedInt(file, img.Checksum); imgOffsets[img] = (int)file.BaseStream.Position; file.Write((int)0); // keep place for the offset } foreach (DictionaryEntry entry in Directories) { WZDirectory directory = (WZDirectory)entry.Value; directory.Write(file); } /*foreach (DictionaryEntry entry in IMGs) * { * IMGFile img = (IMGFile)entry.Value; * img.Write(file); * }*/ }
public void Open() { if (!loaded) { file.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); Header = ReadString(4); FileSize = ReadLong(); FileStart = ReadInt(); Copyright = ReadString(FileStart - (int)Position()); byte EncodedVersion = ReadByte(); if (EncodeVersion() != EncodedVersion) { throw new Exception("Incorrect version error"); } ReadByte(); // null Directory = new WZDirectory(Name, this, 2); loaded = true; } }
private static void Clean(WZDirectory directory, object locker) { foreach(IMGFile img in directory.IMGs.Values) { lock (img) { if (img.IsLoaded()) { if (!img.ToSave && !imgs.Contains(img)) { lock(locker) img.Close(); } } } } foreach (WZDirectory dir in directory.Directories.Values) { Clean(dir, locker); } }
public void Open(WZDirectory other, List<WZPatchOperation> operations, string Base) { int count = file.ReadValue(); List<string> names = new List<string>(); for (int i = 0; i < count; i++) { string Name = ""; int size, checksum, offset; byte type = file.ReadByte(); switch (type) { case 0x02: Name = file.ReadStringAt(true); break; case 0x03: case 0x04: Name = file.ReadString(); break; } size = file.ReadValue(); checksum = file.ReadValue(); offset = file.ReadOffset(); switch (type) { case 0x02: case 0x04: { IMGFile img = other.GetIMG(Base + ((Base == "") ? "" : "/") + Name); if (img == null || img.Checksum != checksum) { operations.Add(new Add(file, offset + file.FileStart, size)); } else { operations.Add(new Copy(other.file, img.baseOffset + other.file.FileStart, img.Size)); } break; } case 0x03: { names.Add(Name); break; } } } foreach (string name in names) { Open(other, operations, Base + ((Base == "") ? "" : "/") + name); } }
public void Open(WZDirectory other, List<WZPatchOperation> operations) { long soffset = file.file.BaseStream.Position; List<WZPatchOperation> ops = new List<WZPatchOperation>(); file.file.BaseStream.Seek(baseOffset + file.FileStart, SeekOrigin.Begin); Open(other, ops, ""); int size = (int)file.file.BaseStream.Position; operations.Add(new Add(file, 0, size)); operations.AddRange(ops); file.file.BaseStream.Seek(soffset, SeekOrigin.Begin); }
private void LoadNames(WZDirectory dir, IMGFile strings, Hashtable names) { foreach (IMGFile life in dir.IMGs.Values) { string id = int.Parse(life.Name.Substring(0, 7)).ToString(); names.Add(id, strings.GetString(id + "/name")); } }
public void Open() { if (!loaded) { file.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); Header = ReadString(4); FileSize = ReadLong(); FileStart = ReadInt(); Copyright = ReadString(FileStart - (int)Position()); byte EncodedVersion = ReadByte(); if (EncodeVersion() != EncodedVersion) throw new Exception("Incorrect version error"); ReadByte(); // null Directory = new WZDirectory(Name, this, 2); loaded = true; } }