public Index2(PackIdentifier packId, Stream stream)
        {
            this.PackId = packId;

            using (var reader = new BinaryReader(stream, Encoding.Default, true))
                Build(reader);
        }
Beispiel #2
0
        public Index2(PackIdentifier packId, Stream stream)
        {
            this.PackId = packId;

            using (BinaryReader reader = new BinaryReader(stream, Encoding.Default, true))
                Build(reader);
        }
Beispiel #3
0
        public Pack(PackCollection collection, DirectoryInfo dataDirectory, PackIdentifier id)
        {
            if (dataDirectory == null)
            {
                throw new ArgumentNullException("dataDirectory");
            }
            if (!dataDirectory.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            Collection    = collection;
            DataDirectory = dataDirectory;
            this.Id       = id;

            var indexPath  = Path.Combine(DataDirectory.FullName, id.Expansion, string.Format(IndexFileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number));
            var index2Path = Path.Combine(DataDirectory.FullName, id.Expansion, string.Format(Index2FileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number));

            if (IOFile.Exists(indexPath))
            {
                Source = new IndexSource(this, new Index(id, indexPath));
            }
            else if (IOFile.Exists(index2Path))
            {
                Source = new Index2Source(this, new Index2(id, index2Path));
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
Beispiel #4
0
        public IndexDirectory(PackIdentifier packId, BinaryReader reader) {
            PackId = packId;

            ReadMeta(reader);
            var pos = reader.BaseStream.Position;
            ReadFiles(reader);
            reader.BaseStream.Position = pos;
        }
        public Index2File(PackIdentifier packId, BinaryReader reader)
        {
            PackId = packId;
            FileKey = reader.ReadUInt32();

            var baseOffset = reader.ReadInt32();
            DatFile = (byte)((baseOffset & 0x7) >> 1);
            Offset = (int)((baseOffset & 0xFFFFFFF8) << 3);
        }
Beispiel #6
0
        public Index(PackIdentifier packId, string path)
        {
            PackId = packId;

            using (var file = IOFile.OpenRead(path)) {
                using (var reader = new BinaryReader(file))
                    Build(reader);
            }
        }
        public IndexDirectory(PackIdentifier packId, BinaryReader reader)
        {
            PackId = packId;

            ReadMeta(reader);
            var pos = reader.BaseStream.Position;
            ReadFiles(reader);
            reader.BaseStream.Position = pos;
        }
        public Pack GetPack(PackIdentifier id)
        {
            Pack pack;
            if (_Packs.TryGetValue(id, out pack)) return pack;

            pack = new Pack(this, DataDirectory, id);
            _Packs.Add(id, pack);
            return pack;
        }
Beispiel #9
0
        public Index2(PackIdentifier packId, string path)
        {
            this.PackId = packId;

            using (FileStream file = IOFile.OpenRead(path)) {
                using (BinaryReader reader = new BinaryReader(file))
                    Build(reader);
            }
        }
        public Index2(PackIdentifier packId, string path)
        {
            this.PackId = packId;

            using (var file = IOFile.OpenRead(path)) {
                using (var reader = new BinaryReader(file))
                    Build(reader);
            }
        }
Beispiel #11
0
        public Index2File(PackIdentifier packId, BinaryReader reader)
        {
            PackId  = packId;
            FileKey = reader.ReadUInt32();

            int baseOffset = reader.ReadInt32();

            DatFile = (byte)((baseOffset & 0x7) >> 1);
            Offset  = (int)((baseOffset & 0xFFFFFFF8) << 3);
        }
Beispiel #12
0
        public Pack GetPack(PackIdentifier id)
        {
            if (_Packs.TryGetValue(id, out var pack))
            {
                return(pack);
            }

            pack = new Pack(this, DataDirectory, id);
            _Packs.Add(id, pack);
            return(pack);
        }
        public bool TryGetPack(string path, out Pack pack)
        {
            pack = null;

            if (!PackIdentifier.TryGet(path, out var id))
            {
                return(false);
            }

            pack = _Packs.GetOrAdd(id, i => new Pack(this, DataDirectory, id));
            return(true);
        }
Beispiel #14
0
        public Pack GetPack(string path)
        {
            var id = PackIdentifier.Get(path);

            if (_Packs.TryGetValue(id, out var pack))
            {
                return(pack);
            }

            pack = new Pack(this, DataDirectory, id);
            _Packs.Add(id, pack);
            return(pack);
        }
Beispiel #15
0
        public IndexFile(PackIdentifier packId, BinaryReader reader)
        {
            PackId       = packId;
            FileKey      = reader.ReadUInt32();
            DirectoryKey = reader.ReadUInt32();

            var baseOffset = reader.ReadInt32();

            DatFile = (byte)((baseOffset & 0x000F) / 2);
            Offset  = (baseOffset - (baseOffset & 0x000F)) * 0x08;

            reader.ReadInt32(); // Zero
        }
Beispiel #16
0
        public IndexFile(PackIdentifier packId, BinaryReader reader)
        {
            PackId       = packId;
            FileKey      = reader.ReadUInt32();
            DirectoryKey = reader.ReadUInt32();

            var baseOffset = reader.ReadInt32();

            DatFile = (byte)((baseOffset & 0x7) >> 1);
            Offset  = (int)((baseOffset & 0xFFFFFFF8) << 3);

            reader.ReadInt32(); // Zero
        }
Beispiel #17
0
        public static bool TryGet(string fullPath, out PackIdentifier value)
        {
            value = default(PackIdentifier);

            int typeSep = fullPath.IndexOf('/');

            if (typeSep <= 0)
            {
                return(false);
            }
            string type = fullPath.Substring(0, typeSep);

            if (!TypeToKeyMap.ContainsKey(type))
            {
                return(false);
            }

            int expSep = fullPath.IndexOf('/', typeSep + 1);

            string expansion = null;
            byte   number    = 0;

            if (expSep > typeSep)
            {
                expansion = fullPath.Substring(typeSep + 1, expSep - typeSep - 1);
                int numberEnd = fullPath.IndexOf('_', expSep);
                if (numberEnd - expSep == 3)
                {
                    if (!byte.TryParse(
                            fullPath.Substring(expSep + 1, 2),
                            System.Globalization.NumberStyles.HexNumber | System.Globalization.NumberStyles.AllowHexSpecifier,
                            System.Globalization.CultureInfo.CurrentCulture,
                            out number))
                    {
                        number = 0;
                    }
                }
            }

            if (expansion == null || !ExpansionToKeyMap.ContainsKey(expansion))
            {
                expansion = DefaultExpansion;
            }

            value = new PackIdentifier(type, expansion, number);
            return(true);
        }
Beispiel #18
0
        public bool TryGetPack(string path, out Pack pack)
        {
            pack = null;

            if (!PackIdentifier.TryGet(path, out var id))
            {
                return(false);
            }

            if (_Packs.TryGetValue(id, out pack))
            {
                return(true);
            }

            pack = new Pack(this, DataDirectory, id);
            _Packs.Add(id, pack);
            return(true);
        }
        public static bool TryGet(string fullPath, out PackIdentifier value)
        {
            value = default(PackIdentifier);

            var typeSep = fullPath.IndexOf('/');
            if (typeSep <= 0)
                return false;
            var type = fullPath.Substring(0, typeSep);
            if (!TypeToKeyMap.ContainsKey(type))
                return false;

            var expSep = fullPath.IndexOf('/', typeSep + 1);

            string expansion = null;
            byte number = 0;
            if (expSep > typeSep) {
                expansion = fullPath.Substring(typeSep + 1, expSep - typeSep - 1);
                var numberEnd = fullPath.IndexOf('_', expSep);
                if (numberEnd - expSep == 3) {
                    if (!byte.TryParse(
                        fullPath.Substring(expSep + 1, 2),
                        System.Globalization.NumberStyles.HexNumber | System.Globalization.NumberStyles.AllowHexSpecifier,
                        System.Globalization.CultureInfo.CurrentCulture,
                        out number))
                        number = 0;
                }
            }

            if (expansion == null || !ExpansionToKeyMap.ContainsKey(expansion))
                expansion = DefaultExpansion;

            value = new PackIdentifier(type, expansion, number);
            return true;
        }
Beispiel #20
0
 public Pack(PackCollection collection, string dataPath, PackIdentifier id)
     : this(collection, new DirectoryInfo(dataPath), id)
 {
 }
Beispiel #21
0
 public Pack(DirectoryInfo dataDirectory, PackIdentifier id) : this(null, dataDirectory, id)
 {
 }
Beispiel #22
0
 public Pack(string dataPath, PackIdentifier id) : this(null, new DirectoryInfo(dataPath), id)
 {
 }
 public Pack GetPack(PackIdentifier id)
 {
     return(_Packs.GetOrAdd(id, i => new Pack(this, DataDirectory, id)));
 }
        public Pack GetPack(string path)
        {
            var id = PackIdentifier.Get(path);

            return(GetPack(id));
        }
        public Index2(PackIdentifier packId, BinaryReader reader)
        {
            this.PackId = packId;

            Build(reader);
        }
        /// <summary>
        ///     Update to the current version.
        /// </summary>
        /// <param name="detectDataChanges">Boolean indicating whether the update should also look for changes in data.</param>
        /// <param name="progress">Optional object to which update progress is reported.</param>
        /// <returns>Returns the <see cref="UpdateReport" /> containing all changes.</returns>
        /// <exception cref="InvalidOperationException">Definition is up-to-date.</exception>
        public UpdateReport Update(bool detectDataChanges, IProgress<UpdateProgress> progress = null)
        {
            if (DefinitionVersion == GameVersion)
                throw new InvalidOperationException();

            var previousVersion = DefinitionVersion;

            var exdPackId = new PackIdentifier("exd", PackIdentifier.DefaultExpansion, 0);
            var exdPack = Packs.GetPack(exdPackId);
            var exdOldKeepInMemory = exdPack.KeepInMemory;
            exdPack.KeepInMemory = true;

            string tempPath = null;
            UpdateReport report;
            try {
                using (var zip = new ZipFile(StateFile.FullName, ZipEncoding)) {
                    tempPath = ExtractPacks(zip, previousVersion);
                    var previousPack = new PackCollection(Path.Combine(tempPath, previousVersion));
                    previousPack.GetPack(exdPackId).KeepInMemory = true;
                    var previousDefinition = ReadDefinition(zip);

                    var updater = new RelationUpdater(previousPack, previousDefinition, Packs, GameVersion, progress);

                    var changes = updater.Update(detectDataChanges);
                    report = new UpdateReport(previousVersion, GameVersion, changes);

                    var definition = updater.Updated;

                    StorePacks(zip);
                    StoreDefinition(zip, definition, DefinitionFile);
                    StoreDefinition(zip, definition, string.Format("{0}/{1}", definition.Version, DefinitionFile));
                    StoreReport(zip, report);
                    zip.Save();

                    GameData.Definition = definition;
                    GameData.Definition.Compile();
                }
            } finally {
                if (exdPack != null)
                    exdPack.KeepInMemory = exdOldKeepInMemory;
                if (tempPath != null) {
                    try {
                        Directory.Delete(tempPath, true);
                    } catch {
                        Console.Error.WriteLine("Failed to delete temporary directory {0}.", tempPath);
                    }
                }
            }
            return report;
        }
Beispiel #27
0
 public bool Equals(PackIdentifier other)
 {
     return(other.TypeKey == this.TypeKey && other.ExpansionKey == this.ExpansionKey && other.Number == this.Number);
 }
 public bool Equals(PackIdentifier other)
 {
     return other.TypeKey == this.TypeKey && other.ExpansionKey == this.ExpansionKey && other.Number == this.Number;
 }
Beispiel #29
0
        public Index2(PackIdentifier packId, BinaryReader reader)
        {
            this.PackId = packId;

            Build(reader);
        }