示例#1
0
        public static BarEntry Load(BinaryReader binaryReader, uint version, string rootPath)
        {
            BarEntry barEntry = new BarEntry();

            if (version > 3)
            {
                barEntry.Offset = binaryReader.ReadInt64();
            }
            else
            {
                barEntry.Offset = binaryReader.ReadInt32();
            }

            barEntry.FileSize  = binaryReader.ReadInt32();
            barEntry.FileSize2 = binaryReader.ReadInt32();

            if (version == 5)
            {
                barEntry.FileSize3 = binaryReader.ReadInt32();
            }

            barEntry.LastWriteTime = new BarEntryLastWriteTime(binaryReader);
            var length = binaryReader.ReadUInt32();

            barEntry.FileName         = Encoding.Unicode.GetString(binaryReader.ReadBytes((int)length * 2));
            barEntry.FileNameWithRoot = Path.Combine(rootPath, barEntry.FileName);
            if (version > 3)
            {
                barEntry.isCompressed = Convert.ToBoolean(binaryReader.ReadUInt32());
            }

            // MessageBox.Show(barEntry.FileName);
            return(barEntry);
        }
示例#2
0
        public async static Task <BarFile> Load(string filename, bool doCRC32)
        {
            BarFile barFile = new BarFile();

            if (!File.Exists(filename))
            {
                throw new Exception("BAR file does not exist!");
            }
            using var file = File.OpenRead(filename);
            var reader = new BinaryReader(file);

            barFile.barFileHeader = new BarFileHeader(reader);
            file.Seek(barFile.barFileHeader.FilesTableOffset, SeekOrigin.Begin);
            var rootNameLength = reader.ReadUInt32();

            barFile.RootPath          = Encoding.Unicode.GetString(reader.ReadBytes((int)rootNameLength * 2));
            barFile.NumberOfRootFiles = reader.ReadUInt32();

            var barFileEntrys = new List <BarEntry>();

            for (uint i = 0; i < barFile.NumberOfRootFiles; i++)
            {
                barFileEntrys.Add(BarEntry.Load(reader, barFile.barFileHeader.Version, barFile.RootPath));
            }

            // TODO: Look for new date fields in BAR version 6


            if (doCRC32)
            {
                foreach (var barEntry in barFileEntrys)
                {
                    reader.BaseStream.Seek(barEntry.Offset, SeekOrigin.Begin);
                    byte[] data = reader.ReadBytes(barEntry.FileSize2);
                    await Task.Run(() =>
                    {
                        barEntry.CRC32 = Crc32Algorithm.Compute(data);
                    }
                                   );
                }
            }

            barFile.BarFileEntrys = new ReadOnlyCollection <BarEntry>(barFileEntrys);
            return(barFile);
        }
示例#3
0
        public static async Task <BarEntry> Create(string rootPath, FileInfo fileInfo, long offset, uint version)
        {
            BarEntry barEntry = new BarEntry();

            barEntry.FileNameWithRoot = Path.GetFileName(rootPath);
            rootPath = rootPath.EndsWith(Path.DirectorySeparatorChar.ToString())
                ? rootPath
                : rootPath + Path.DirectorySeparatorChar;


            barEntry.FileName         = fileInfo.FullName.Replace(rootPath, string.Empty);
            barEntry.FileNameWithRoot = Path.Combine(barEntry.FileNameWithRoot, barEntry.FileName);
            barEntry.Offset           = offset;

            if (version > 3)
            {
                barEntry.FileSize2    = (int)fileInfo.Length;
                barEntry.isCompressed = Alz4Utils.IsAlz4File(fileInfo.FullName);
                if (barEntry.isCompressed)
                {
                    barEntry.FileSize = (await Alz4Utils.ReadCompressedSizeAlz4Async(fileInfo.FullName));
                }
                else
                {
                    barEntry.FileSize = barEntry.FileSize2;
                }
                barEntry.FileSize3 = barEntry.FileSize2;
            }
            else
            {
                barEntry.FileSize  = (int)fileInfo.Length;
                barEntry.FileSize2 = barEntry.FileSize;
            }



            barEntry.LastWriteTime = new BarEntryLastWriteTime(fileInfo.LastWriteTimeUtc);

            return(barEntry);
        }