/// <summary> /// Saves the EncodingFile 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, Configs.ConfigContainer configContainer = null) { if (Partial) { throw new NotSupportedException("Writing is not supported for partial EncodingFiles"); } EBlock[] eblocks = new EBlock[_EncodingMap.Length]; CASRecord record; using (var bt = new BlockTableStreamWriter(_EncodingMap[1], 1)) using (var bw = new BinaryWriter(bt)) { // ESpecStringTable 1 bt.Write(string.Join('\0', ESpecStringTable).GetBytes()); EncodingHeader.ESpecTableSize = (uint)bt.Length; // CKeysPageIndices 2, CKeysPageTable 3 WritePage(bw, eblocks, 2, EncodingHeader.CKeyPageSize << 10, _CKeyEntries); // EKeysPageIndices 4, EKeysPageTable 5 WritePage(bw, eblocks, 4, EncodingHeader.EKeyPageSize << 10, _EKeyEntries); // Header 0 bt.AddBlock(_EncodingMap[0], 0); EncodingHeader.Write(bw); // File ESpec 6 bt.AddBlock(_EncodingMap[6], 6); bt.Write(GetFileESpec(bt.SubStreams).GetBytes()); // finalise record = bt.Finalise(); // save string saveLocation = Helpers.GetCDNPath(record.EKey.ToString(), "data", directory, true); using (var fs = File.Create(saveLocation)) { bt.WriteTo(fs); record.BLTEPath = saveLocation; } } // update the build config with the new values if (configContainer?.BuildConfig != null) { configContainer.BuildConfig.SetValue("encoding-size", record.EBlock.DecompressedSize, 0); configContainer.BuildConfig.SetValue("encoding-size", record.EBlock.CompressedSize, 1); configContainer.BuildConfig.SetValue("encoding", record.CKey, 0); configContainer.BuildConfig.SetValue("encoding", record.EKey, 1); } Checksum = record.CKey; return(record); }
/// <summary> /// Saves the DownloadFile to disk and optionally updates the BuildConfig /// </summary> /// <param name="directory">Root Directory</param> /// <param name="configContainer"></param> /// <returns></returns> public override CASRecord Write(string directory, TACTRepo tactRepo = null) { CASRecord record; using (var bt = new BlockTableStreamWriter(_EncodingMap[0])) using (var bw = new BinaryWriter(bt)) { // Header DownloadHeader.EntryCount = (uint)_FileEntries.Count; DownloadHeader.TagCount = (ushort)_TagEntries.Count; DownloadHeader.Write(bw); // File Entries bt.AddBlock(_EncodingMap[1]); foreach (var fileEntry in _FileEntries.Values.OrderBy(x => x.Priority)) { fileEntry.Write(bw, DownloadHeader); } // Tag Entries bt.AddBlock(_EncodingMap[2]); WriteTags(bw, _FileEntries.Count); // finalise record = bt.Finalise(); // save string saveLocation = Helpers.GetCDNPath(record.EKey.ToString(), "data", directory, true); using (var fs = File.Create(saveLocation)) { bt.WriteTo(fs); record.BLTEPath = saveLocation; } } if (tactRepo != null) { // insert the record into the encoding tactRepo.EncodingFile?.AddOrUpdate(record); // update the build config with the new values if (tactRepo.ConfigContainer?.BuildConfig != null) { tactRepo.ConfigContainer.BuildConfig.SetValue("download-size", record.EBlock.DecompressedSize, 0); tactRepo.ConfigContainer.BuildConfig.SetValue("download-size", record.EBlock.CompressedSize, 1); tactRepo.ConfigContainer.BuildConfig.SetValue("download", record.CKey, 0); tactRepo.ConfigContainer.BuildConfig.SetValue("download", record.EKey, 1); } } Checksum = record.CKey; FilePath = record.BLTEPath; return(record); }