Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
 public SegmentRepository(BotContext botContext, FileSegments segments, IDiscordClient client, IUserRepository userRepository, IUniverseRepository universeRepository)
 {
     _botContext         = botContext;
     _segments           = segments;
     _client             = client;
     _userRepository     = userRepository;
     _universeRepository = universeRepository;
 }
Exemplo n.º 3
0
        // 3. Reconstracut the segments
        /// <summary>
        /// Reconstract the segments from the temp files that got created.
        /// </summary>
        /// <returns>A complete file in the directory that you specified in the constructor.</returns>
        public async Task ReconstructSegmentsAsync()
        {
            using (Stream localFileStream = new FileStream(LocalFileFullPath, FileMode.Create, FileAccess.ReadWrite))
            {
                foreach (var Segment in FileSegments.OrderBy(x => x.ID))
                {
                    localFileStream.Seek(Segment.Start, SeekOrigin.Begin);

                    using (Stream tempStream = new FileStream(Segment.TempFile, FileMode.Open, FileAccess.Read))
                    {
                        await tempStream.CopyToAsync(localFileStream);
                    }
                }
            }
            // Delete all the Temp files, after the reconstraction process.
            foreach (var Segment in FileSegments)
            {
                File.Delete(Segment.TempFile);
            }
        }
Exemplo n.º 4
0
        // 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
                    });
                }
            }
        }
Exemplo n.º 5
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)
                        });
                    }
                }
            }
        }