Example #1
0
        /// <summary>
        /// Parses all Index files from a remote CDN
        /// </summary>
        /// <param name="manifestContainer"></param>
        /// <param name="useParallelism"></param>
        public void OpenRemote(Configs.ConfigContainer configContainer, Configs.ManifestContainer manifestContainer, bool useParallelism = false)
        {
            IsRemote = true;

            _indices.Clear();
            _useParallelism = useParallelism;
            _client         = new CDNClient(manifestContainer);

            ParallelOptions options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = useParallelism ? -1 : 1
            };

            // stream data archive indicies
            var archives = configContainer.CDNConfig.GetValues("archives");

            if (archives != null && archives.Count > 0)
            {
                Parallel.ForEach(archives, options, index => _indices.Add(new IndexFile(_client, index, IndexType.Data)));
            }

            // stream patch archive indices
            var patcharchives = configContainer.CDNConfig.GetValues("patch-archives");

            if (patcharchives != null && patcharchives.Count > 0)
            {
                Parallel.ForEach(patcharchives, options, index => _indices.Add(new IndexFile(_client, index, IndexType.Patch)));
            }

            // stream loose file index
            var fileIndex = configContainer.CDNConfig.GetValue("file-index");

            if (fileIndex != null)
            {
                _indices.Add(new IndexFile(_client, fileIndex, IndexType.Loose | IndexType.Data));
            }

            // stream loose patch file index
            var patchIndex = configContainer.CDNConfig.GetValue("patch-file-index");

            if (patchIndex != null)
            {
                _indices.Add(new IndexFile(_client, patchIndex, IndexType.Loose | IndexType.Patch));
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new CDN Client and loads the hosts from the CDNs file
        /// </summary>
        /// <param name="configContainer"></param>
        /// <param name="applyDecryption"></param>
        public CDNClient(Configs.ManifestContainer manifestContainer, bool applyDecryption = false) : this(applyDecryption)
        {
            if (manifestContainer?.CDNsFile == null)
            {
                throw new ArgumentException("Unable to load CDNs file");
            }

            string[] hosts = manifestContainer.CDNsFile.GetValue("Hosts", manifestContainer.Locale)?.Split(' ');
            foreach (var host in hosts)
            {
                Hosts.Add(host.Split('?')[0]);
            }

            if (Hosts.Count == 0)
            {
                throw new FormatException("No hosts found");
            }
        }
Example #3
0
        /// <summary>
        /// Downloads all Index and Archive files from a remote CDN
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="configContainer"></param>
        public void DownloadRemote(string directory, Configs.ConfigContainer configContainer, Configs.ManifestContainer manifestContainer)
        {
            _client = new CDNClient(manifestContainer);

            var queuedDownloader = new QueuedDownloader(directory, _client);

            // download data archives
            var archives = configContainer.CDNConfig.GetValues("archives");

            if (archives != null && archives.Count > 0)
            {
                queuedDownloader.Enqueue(archives);
                queuedDownloader.Enqueue(archives, (x) => x + ".index");
                queuedDownloader.Download("data");
            }

            // download patch archives
            var patcharchives = configContainer.CDNConfig.GetValues("patch-archives");

            if (patcharchives != null && patcharchives.Count > 0)
            {
                queuedDownloader.Enqueue(patcharchives);
                queuedDownloader.Enqueue(patcharchives, (x) => x + ".index");
                queuedDownloader.Download("patch");
            }

            // download loose file index
            var fileIndex = configContainer.CDNConfig.GetValue("file-index");

            if (fileIndex != null)
            {
                string url  = Helpers.GetCDNUrl(fileIndex, "data");
                string path = Helpers.GetCDNPath(fileIndex, "data", directory, true);
                _client.DownloadFile(url, path).Wait();

                // download loose files
                var index = new IndexFile(path);
                queuedDownloader.Enqueue(index.Entries, (x) => x.Key.ToString());
                queuedDownloader.Download("data");
            }

            // download loose patch file index
            var patchIndex = configContainer.CDNConfig.GetValue("patch-file-index");

            if (patchIndex != null)
            {
                string url  = Helpers.GetCDNUrl(patchIndex, "patch");
                string path = Helpers.GetCDNPath(patchIndex, "patch", directory, true);
                _client.DownloadFile(url, path).Wait();

                // download loose patches
                var index = new IndexFile(path);
                queuedDownloader.Enqueue(index.Entries, (x) => x.Key.ToString());
                queuedDownloader.Download("patch");
            }

            Open(directory);
        }