Exemplo n.º 1
0
        private void Read(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (!stream.CanRead || stream.Length <= 1)
            {
                throw new NotSupportedException($"Unable to read InstallFile stream");
            }

            using (var br = new BinaryReader(stream))
            {
                InstallHeader.Read(br);

                // Tags
                ReadTags(br, InstallHeader.TagCount, InstallHeader.EntryCount);

                // Files
                for (int i = 0; i < InstallHeader.EntryCount; i++)
                {
                    var fileEntry = new InstallFileEntry();
                    fileEntry.Read(br, InstallHeader);
                    _FileEntries.TryAdd(fileEntry.FilePath, fileEntry);
                }

                Checksum = stream.MD5Hash();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new InstallFile
        /// </summary>
        public InstallFile()
        {
            InstallHeader = new InstallHeader();
            _FileEntries  = new Dictionary <string, InstallFileEntry>(StringComparer.OrdinalIgnoreCase);

            _EncodingMap = new[]
            {
                new EMap(EType.ZLib, 9),
                new EMap(EType.None, 6),
            };
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the InstallFile to disk and optionally updates the BuildConfig
        /// </summary>
        /// <param name="directory">Root Directory</param>
        /// <param name="configContainer"></param>
        /// <returns></returns>
        public CASRecord Write(string directory, TACTRepo tactRepo = null)
        {
            CASRecord record;

            using (var bt = new BlockTableStreamWriter(_EncodingMap[0]))
                using (var bw = new BinaryWriter(bt))
                {
                    // Header and Tag block
                    InstallHeader.EntryCount = (uint)_FileEntries.Count;
                    InstallHeader.TagCount   = (ushort)_TagEntries.Count;
                    InstallHeader.Write(bw);
                    WriteTags(bw, _FileEntries.Count);

                    // File Entry block
                    bt.AddBlock(_EncodingMap[1]);
                    foreach (var fileEntry in _FileEntries.Values)
                    {
                        fileEntry.Write(bw);
                    }

                    // finalise
                    record = bt.Finalise();
                    record.DownloadPriority = -1;

                    // save
                    string saveLocation = Helpers.GetCDNPath(record.EKey.ToString(), "data", directory, true);
                    using (var fs = File.Create(saveLocation))
                    {
                        bt.WriteTo(fs);
                        record.BLTEPath = saveLocation;
                    }
                }

            // insert the record into the encoding and the download files
            if (tactRepo != null)
            {
                tactRepo.EncodingFile?.AddOrUpdate(record, tactRepo);

                // update the build config with the new values
                if (tactRepo.ConfigContainer?.BuildConfig != null)
                {
                    tactRepo.ConfigContainer.BuildConfig.SetValue("install-size", record.EBlock.DecompressedSize, 0);
                    tactRepo.ConfigContainer.BuildConfig.SetValue("install-size", record.EBlock.CompressedSize, 1);
                    tactRepo.ConfigContainer.BuildConfig.SetValue("install", record.CKey, 0);
                    tactRepo.ConfigContainer.BuildConfig.SetValue("install", record.EKey, 1);
                }
            }

            Checksum = record.CKey;
            FilePath = record.BLTEPath;
            return(record);
        }
Exemplo n.º 4
0
 public void Read(BinaryReader br, InstallHeader header)
 {
     FilePath         = br.ReadCString();
     CKey             = new MD5Hash(br.ReadBytes(header.CKeySize));
     DecompressedSize = br.ReadUInt32BE();
 }