예제 #1
0
        public Package(PackageCollection parent, string fileLocation, ushort version = ushort.MinValue, bool?isImg = null)
        {
            Collection    = parent;
            FilePath      = fileLocation;
            FileName      = Path.GetFileNameWithoutExtension(FilePath).Replace(".rebuilt", "");
            streamFactory = new StreamFactory(() => File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
            isImg         = isImg ?? fileLocation.EndsWith(".img");

            using (WZReader file = GetRawReader()) {
                if (!isImg.Value)
                {
                    if (!file.ReadString(4).Equals("PKG1", StringComparison.CurrentCultureIgnoreCase))
                    {
                        throw new InvalidOperationException("Can not run on non-PKG1 files.");
                    }
                    FileSize = file.ReadInt64();
                    ContentsStartLocation = file.ReadUInt32();
                    FileDescription       = file.ReadNULTerminatedString(100);
                    Logging($"Loaded package {this.FileName} ({this.FileSize}, {this.ContentsStartLocation}) with Description: {this.FileDescription}");
                }
                MainDirectory = new WZProperty(FileName, FileName, this, isImg.Value ? PropertyType.Image : PropertyType.Directory, null, (uint)FileSize, -1, (uint)ContentsStartLocation + (uint)(isImg.Value ? 0 : 2));

                file.BaseStream.Seek(ContentsStartLocation, SeekOrigin.Begin);

                if (!isImg.Value)
                {
                    this.VersionHash = (byte)file.ReadUInt16();
                    Logging($"{this.FileName} - Version Hash: {this.VersionHash}");
                    if (!UpdateVersion(version))
                    {
                        Logging("Warning: Version is not wrong, expect corrupted / malformed data.");
                    }
                }
            }
        }