private void Read(BinaryReader br, Archive parent) { FileTableOffset = br.ReadUInt32(); FileTableSize = br.ReadUInt32(); Crc = br.ReadUInt64(); FileEntryCount = br.ReadUInt32(); FileSegmentCount = br.ReadUInt32(); ResourceDependencyCount = br.ReadUInt32(); // read tables for (int i = 0; i < FileEntryCount; i++) { var entry = new FileEntry(br, parent); if (!FileEntries.ContainsKey(entry.NameHash64)) { FileEntries.Add(entry.NameHash64, entry); } else { // TODO } } for (int i = 0; i < FileSegmentCount; i++) { FileSegments.Add(new FileSegment(br, i)); } for (int i = 0; i < ResourceDependencyCount; i++) { Dependencies.Add(new Dependency(br, i)); } }
// 1. Gets the file segments and load them. /// <summary> /// Load the segments of the remote file. /// </summary> /// <returns>List of segments are stored</returns> public async Task LoadFileSegmentsAsync() { int Count = 0; foreach (var(Start, End) in SegmentPosition(RemoteFileProperties.Size, Environment.ProcessorCount)) { using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(Start, End); FileSegments.Add(new FileSegment { ID = ++Count, PartialContent = await httpClient.GetStreamAsync(Url), Start = Start, End = End, TotalReadBytes = 0 }); } } }
// 1.2 Load the segments info for resuming /// <summary> /// Load the Segments data from the JsonContent /// </summary> /// <param name="JsonContent">Json Content, which you got from the <see cref="GetBasicSegmentsInfo()"/> </param> /// <returns>reloaded segments to be able to resumed</returns> public async Task LoadFileSegmentsForResumingAsync(string JsonContent) { foreach (var fileSegment in JsonConvert.DeserializeObject <IList <FileSegment> >(JsonContent)) { using (HttpClient httpClient = new HttpClient()) { using (Stream tempfile = new FileStream(fileSegment.TempFile, FileMode.Open, FileAccess.Read)) { httpClient.DefaultRequestHeaders.Range = new RangeHeaderValue(fileSegment.Start + tempfile.Length, fileSegment.End); FileSegments.Add(new FileSegment { ID = fileSegment.ID, Start = fileSegment.Start, End = fileSegment.End, TempFile = fileSegment.TempFile, TotalReadBytes = tempfile.Length, PartialContent = await httpClient.GetStreamAsync(Url) }); } } } }