/// <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);
        }
Exemple #2
0
        public void Download(string folder)
        {
            folder = folder.ToLower();

            var tasks = new List <Task>();

            for (int i = 0; i < Environment.ProcessorCount; i++)
            {
                var task = Task.Run(async() =>
                {
                    while (_queue.TryDequeue(out var item))
                    {
                        string url      = Helpers.GetCDNUrl(item, folder);
                        string filepath = Helpers.GetCDNPath(item, folder, _directory, true);

                        if (!File.Exists(filepath))
                        {
                            await _client.DownloadFile(url, filepath);
                        }
                    }
                });

                tasks.Add(task);
            }

            Task.WhenAll(tasks).Wait();
        }
Exemple #3
0
        private async Task <bool> DownloadFile(string hash, string filename)
        {
            if (File.Exists(filename))
            {
                return(true);
            }

            return(await Client.DownloadFile(Helpers.GetCDNUrl(hash, "data"), filename));
        }