Example #1
0
        /// <summary>
        /// Iterates through the pack file and records the offsets and headers of each record found
        /// </summary>
        /// <param name="pathToGgpk">Path to pack file to read</param>
        /// <param name="output">Output function</param>
        private void ReadRecordOffsets(string pathToGgpk, Action <string> output)
        {
            float previousPercentComplete = 0.0f;

            using (FileStream fs = Utils.OpenFile(pathToGgpk, out isReadOnly))
            {
                BinaryReader br           = new BinaryReader(fs);
                long         streamLength = br.BaseStream.Length;

                while (br.BaseStream.Position < streamLength)
                {
                    long       currentOffset = br.BaseStream.Position;
                    BaseRecord record        = RecordFactory.ReadRecord(br);
                    RecordOffsets.Add(currentOffset, record);
                    float percentComplete = currentOffset / (float)streamLength;
                    if (!(percentComplete - previousPercentComplete >= 0.10f))
                    {
                        continue;
                    }
                    output?.Invoke($"{100.0 * percentComplete:00.00}%{Environment.NewLine}");
                    previousPercentComplete = percentComplete;
                }
                output?.Invoke($"{100.0f * br.BaseStream.Position / br.BaseStream.Length:00.00}%{Environment.NewLine}");
            }
        }