コード例 #1
0
        private static async Task <bool> DownloadChunk(DepotProcessor.ManifestJob job, DepotManifest.ChunkData chunk, FileInfo downloadPath)
        {
            for (var i = 0; i <= 5; i++)
            {
                try
                {
                    var chunkData = await CDNClient.DownloadDepotChunkAsync(job.DepotID, chunk, job.Server, job.CDNToken, job.DepotKey);

                    using (var fs = downloadPath.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                    {
                        fs.Seek((long)chunk.Offset, SeekOrigin.Begin);
                        await fs.WriteAsync(chunkData.Data, 0, chunkData.Data.Length);
                    }

                    return(true);
                }
                catch (Exception e)
                {
                    Log.WriteWarn("FileDownloader", "{0} exception: {1}", job.DepotID, e.Message);
                }

                await Task.Delay(Utils.ExponentionalBackoff(i));
            }

            return(false);
        }
コード例 #2
0
        private static async Task <bool> DownloadChunk(DepotProcessor.ManifestJob job, DepotManifest.ChunkData chunk, FileInfo downloadPath, CancellationTokenSource chunkCancellation)
        {
            const int TRIES = 3;

            for (var i = 0; i <= TRIES; i++)
            {
                chunkCancellation.Token.ThrowIfCancellationRequested();

                try
                {
                    var chunkData = await CDNClient.DownloadDepotChunkAsync(job.DepotID, chunk, job.Server, string.Empty, job.DepotKey);

                    await using var fs = downloadPath.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                    fs.Seek((long)chunk.Offset, SeekOrigin.Begin);
                    await fs.WriteAsync(chunkData.Data);

                    return(true);
                }
                catch (Exception e)
                {
                    Log.WriteWarn($"FileDownloader {job.DepotID}", $"Exception: {e}");
                }

                if (i < TRIES)
                {
                    await Task.Delay(Utils.ExponentionalBackoff(i + 1));
                }
            }

            return(false);
        }
コード例 #3
0
        private static async Task <bool> DownloadChunk(DepotProcessor.ManifestJob job, DepotManifest.ChunkData chunk, FileInfo downloadPath)
        {
            for (var i = 0; i <= 5; i++)
            {
                try
                {
                    var chunkData = await CDNClient.DownloadDepotChunkAsync(job.DepotID, chunk, job.Server, string.Empty, job.DepotKey);

                    await using var fs = downloadPath.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                    fs.Seek((long)chunk.Offset, SeekOrigin.Begin);
                    await fs.WriteAsync(chunkData.Data, 0, chunkData.Data.Length);

                    return(true);
                }
                catch (Exception e)
                {
                    Log.WriteWarn($"FileDownloader {job.DepotID}", $"Exception: {e}");
                }

                if (i < 5)
                {
                    await Task.Delay(Utils.ExponentionalBackoff(i + 1));
                }
            }

            return(false);
        }
コード例 #4
0
        async private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            try
            {
                ConfigItem item = datagridConfigs.Rows[e.RowIndex].DataBoundItem as ConfigItem;

                if (item != null)
                {
                    if (item.URL == "")
                    {
                        var callback = await steamWorkshop.RequestInfo(241100, item.Details.publishedfileid);

                        var itemInfo = callback.Items.FirstOrDefault();
                        var ticket   = await steamClient.GetHandler <SteamApps>().GetAppOwnershipTicket(241100);

                        var decryptKey = await steamClient.GetHandler <SteamApps>().GetDepotDecryptionKey(241100, 241100);

                        var cdn = new CDNClient(steamClient, ticket.Ticket);
                        // var servers = cdn.FetchServerList();
                        var servers = await cdn.FetchServerListAsync();

                        int i = 0;
                        foreach (CDNClient.Server server in servers)
                        {
                            Log.w($"Server{i}: {server}");
                            ++i;
                        }
                        await cdn.ConnectAsync(servers.First());

                        await cdn.AuthenticateDepotAsync(241100, decryptKey.DepotKey);

                        var manifest = await cdn.DownloadManifestAsync(241100, itemInfo.ManifestID);

                        manifest.DecryptFilenames(decryptKey.DepotKey);
                        if (manifest.Files.Count == 0)
                        {
                            MessageBox.Show("Steam Refused Download Request");
                            return;
                        }
                        var chunk = cdn.DownloadDepotChunkAsync(241100, manifest.Files.First().Chunks.First());
                        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            using (var wc = new WebClient())
                            {
                                using (var io = saveFileDialog1.OpenFile())
                                {
                                    io.Write(chunk.Result.Data, 0, chunk.Result.Data.Length);
                                    MessageBox.Show($"Download Done!\nSaved {saveFileDialog1.FileName}");
                                    Log.w($"Downloaded {saveFileDialog1.FileName}");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            using (var wc = new WebClient())
                            {
                                wc.DownloadFile(new Uri(item.URL), saveFileDialog1.FileName);
                                MessageBox.Show("Download Done!");
                            }
                        }
                    }
                }
            }
            catch (TaskCanceledException)
            {
                MessageBox.Show("Timeout! This can happen if you're using anonymous account and trying to download.");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error Downloading Config: {ex.ToString()}");
            }
        }