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(); cdn.Connect(servers.First()); cdn.AuthenticateDepot(241100, decryptKey.DepotKey); var manifest = cdn.DownloadManifest(241100, itemInfo.ManifestID); manifest.DecryptFilenames(decryptKey.DepotKey); if (manifest.Files.First().TotalSize == 0) { MessageBox.Show("Steam Refused Download Request"); return; } var chunk = cdn.DownloadDepotChunk(241100, manifest.Files.First().Chunks.First()); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (var wc = new WebClient()) { using (var io = saveFileDialog1.OpenFile()) { io.Write(chunk.Data, 0, chunk.Data.Length); MessageBox.Show("Download Done!"); } } } } 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()}"); } }
void HandleQueryFiles(CPublishedFile_QueryFiles_Response response, JobID jobid) { foreach (var item in response.publishedfiledetails) { var info = new ConfigItem { App = item.app_name, Name = item.title, FileName = item.filename.Split('/').Last(), URL = item.file_url, RatesUp = item.vote_data != null ? item.vote_data.votes_up : 0, RatesDown = item.vote_data != null ? item.vote_data.votes_down : 0, Details = item }; foreach (var tag in item.kvtags) { if (tag.key == "app") { uint app = 0; if (!uint.TryParse(tag.value, out app)) { info.App = tag.value; } else { var game = Games.Where(x => x.AppID == app).FirstOrDefault(); if (game != null) { info.App = game.Name; } // We don't know actual name else { info.App = $"AppID {app}"; } } } } Invoke(new MethodInvoker(delegate { items.Add(info); })); } totalPages = (uint)Math.Ceiling(response.total / (double)itemsPerPage); if (totalPages > pageCurrent) { pageCurrent++; sendRequest(); } else { requestOnGoing = false; Invoke(new MethodInvoker(delegate { currentStatus.Text = string.Format("Complete!"); })); } }
/// <summary> /// Sends request for controller configs /// </summary> async Task <bool> sendRequest(bool is_new = true) { requestOnGoing = true; try { uint pageCurrent = 1; uint totalPages = 0; var service = steamClient.GetHandler <SteamUnifiedMessages>().CreateService <IPublishedFile>(); do { if (totalPages > 0) { setStatus("Requesting page {0} of {1}", pageCurrent, totalPages); } else { setStatus("Requesting page {0}", pageCurrent, totalPages); } var query = new CPublishedFile_QueryFiles_Request { return_vote_data = true, return_children = true, return_for_sale_data = true, return_kv_tags = true, return_metadata = true, return_tags = true, return_previews = true, appid = is_new ? 241100 : appidCurrent, page = pageCurrent, numperpage = itemsPerPage, query_type = 11, filetype = (uint)EWorkshopFileType.GameManagedItem, }; if (is_new) { if (appidCurrent > 0) { query.required_kv_tags.Add(new CPublishedFile_QueryFiles_Request.KVTag() { key = "app", value = appidCurrent.ToString() }); } query.required_kv_tags.Add(new CPublishedFile_QueryFiles_Request.KVTag() { key = "visibility", value = "public" }); } var callback = await service.SendMessage(x => x.QueryFiles(query)); var response = callback.GetDeserializedResponse <CPublishedFile_QueryFiles_Response>(); totalPages = (uint)Math.Ceiling(response.total / (double)itemsPerPage); pageCurrent++; foreach (var item in response.publishedfiledetails) { var info = new ConfigItem { App = item.app_name, Name = item.title, FileName = item.filename.Split('/').Last(), URL = item.file_url, RatesUp = item.vote_data != null ? item.vote_data.votes_up : 0, RatesDown = item.vote_data != null ? item.vote_data.votes_down : 0, Details = item }; foreach (var tag in item.kvtags) { if (tag.key == "app" || tag.key == "appid") { uint app = 0; if (!uint.TryParse(tag.value, out app)) { info.App = $"(NON-STEAM) {tag.value}"; } else { var game = Games.Where(x => x.AppID == app).FirstOrDefault(); if (game != null) { info.App = game.Name; } // We don't know actual name else { info.App = $"AppID {app}"; } } } else if (tag.key == "visibility" || tag.key == "deleted" || tag.key == "owner" || tag.key == "autosave") { continue; } else { } } Invoke(new MethodInvoker(delegate { items.Add(info); })); } }while (pageCurrent <= totalPages); } catch (Exception) { return(false); } finally { setStatus("Complete!"); requestOnGoing = false; } return(true); }
void HandleQueryFiles(CPublishedFile_QueryFiles_Response response, JobID jobid) { foreach (var item in response.publishedfiledetails) { var info = new ConfigItem { App = item.app_name, Name = item.title, FileName = item.filename.Split('/').Last(), URL = item.file_url, RatesUp = item.vote_data != null ? item.vote_data.votes_up : 0, RatesDown = item.vote_data != null ? item.vote_data.votes_down : 0, Details = item }; foreach (var tag in item.kvtags) { if (tag.key == "app") { uint app = 0; if (!uint.TryParse(tag.value, out app)) { info.App = tag.value; } else { var game = Games.Where(x => x.AppID == app).FirstOrDefault(); if (game != null) { info.App = game.Name; } // We don't know actual name else { info.App = $"AppID {app}"; } } } } Invoke(new MethodInvoker(delegate { items.Add(info); })); } totalPages = (uint) Math.Ceiling(response.total / (double)itemsPerPage); if (totalPages > pageCurrent) { pageCurrent++; sendRequest(); } else { requestOnGoing = false; Invoke(new MethodInvoker(delegate { currentStatus.Text = string.Format("Complete!"); })); } }