static async Task Main(string[] args) { //if (args.Length < 2) //{ // Console.WriteLine("Expected two arguments: username password"); // return; //} SteamCredentials steamCredentials = SteamCredentials.Anonymous; if (args.Length == 2) { steamCredentials = new SteamCredentials(args[0], args[1]); } else { steamCredentials = new SteamCredentials(args[0], args[1], args[2]); } SteamClient steamClient = new SteamClient(steamCredentials, new AuthCodeProvider(), new DirectorySteamAuthenticationFilesProvider(".\\sentries")); SteamContentClient steamContentClient = new SteamContentClient(steamClient, 10); try { await steamClient.ConnectAsync(); } catch (Exception ex) { Console.WriteLine($"Could not connect to Steam: {ex.Message}"); return; } Console.WriteLine("Connected"); try { //var depots = await steamContentClient.GetDepotsAsync(107410); //var publicDepots = await steamContentClient.GetDepotsOfBranchAsync(107410, "public"); //await using var downloadHandler = await steamContentClient.GetAppDataAsync(107410, 228990, null, "public", null, SteamOs.Windows); var downloadHandler = await steamContentClient.GetPublishedFileDataAsync(2539330136); Console.WriteLine("Starting download"); downloadHandler.FileVerified += (sender, args) => Console.WriteLine($"Verified file {args.ManifestFile.FileName}"); downloadHandler.FileDownloaded += (sender, args) => Console.WriteLine($"{downloadHandler.TotalProgress * 100:00.00}% {args.FileName}"); downloadHandler.VerificationCompleted += (sender, args) => Console.WriteLine($"Verification completed, {args.QueuedFiles.Count} files queued for download"); downloadHandler.DownloadComplete += (sender, args) => Console.WriteLine("Download completed"); await downloadHandler.DownloadToFolderAsync(@".\download" /*, new CancellationTokenSource(TimeSpan.FromSeconds(20)).Token*/); } catch (Exception ex) { Console.WriteLine($"Download failed: {ex.Message}"); } steamClient.Shutdown(); Console.WriteLine("Done"); }
static async Task DownloadWorkshopItem(Options opt) { if (string.IsNullOrEmpty(opt.TargetDirectory)) { Console.WriteLine("Error: Please specify a target directory."); Environment.Exit(101); } if (!opt.WorkshopFileId.HasValue) { Console.WriteLine("Error: Please specify a workshop item id."); Environment.Exit(102); } if (string.IsNullOrEmpty(opt.Branch)) { opt.Branch = "public"; //Console.WriteLine($"Warning: No branch was specified, using default branch = {opt.Branch}"); } Stopwatch sw = Stopwatch.StartNew(); try { SteamOs steamOs = new SteamOs(opt.OS); if (opt.SyncTargetDeleteEnabled) { if (!opt.ManifestId.HasValue) { opt.ManifestId = (await _steamContentClient.GetPublishedFileDetailsAsync(opt.WorkshopFileId.Value)).hcontent_file; } Manifest manifest = await _steamContentClient.GetManifestAsync(opt.AppId.Value, opt.AppId.Value, opt.ManifestId.Value); SyncDeleteRemovedFiles(opt, manifest); } Console.Write($"Attempting to start download of item {opt.WorkshopFileId.Value}... "); var downloadHandler = await _steamContentClient.GetPublishedFileDataAsync( opt.WorkshopFileId.Value, opt.ManifestId, opt.Branch, opt.BranchPassword, steamOs); await Download(downloadHandler, opt); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}{(ex.InnerException != null ? $" Inner Exception: {ex.InnerException.Message}" : "")}"); Environment.Exit(110); } sw.Stop(); Console.WriteLine($"Download completed, it took {sw.Elapsed:hh\\:mm\\:ss}"); }
static async Task Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Expected two arguments: username password"); return; } SteamCredentials steamCredentials = null; if (args.Length == 2) { steamCredentials = new SteamCredentials(args[0], args[1]); } else { steamCredentials = new SteamCredentials(args[0], args[1], args[2]); } SteamClient steamClient = new SteamClient(steamCredentials, new AuthCodeProvider(), new DirectorySteamAuthenticationFilesProvider(".\\sentries")); SteamContentClient steamContentClient = new SteamContentClient(steamClient); try { await steamClient.ConnectAsync(); } catch (Exception ex) { Console.WriteLine($"Could not connect to Steam: {ex.Message}"); return; } Console.WriteLine("Connected"); var depots = await steamContentClient.GetDepotsAsync(107410); var publicDepots = await steamContentClient.GetDepotsOfBranchAsync(107410, "public"); try { //var downloadHandler = await steamContentClient.GetAppDataAsync(107410, 107411, null, "public", null, SteamOs.Windows); var downloadHandler = await steamContentClient.GetPublishedFileDataAsync(2242952694); Console.WriteLine("Starting download"); var downloadTask = downloadHandler.DownloadToFolderAsync(@".\download"); while (!downloadTask.IsCompleted) { var delayTask = Task.Delay(100); var t = await Task.WhenAny(delayTask, downloadTask); Console.WriteLine($"Progress {(downloadHandler.TotalProgress * 100).ToString("00.00")}%"); } await downloadTask; } catch (Exception ex) { Console.WriteLine($"Download failed: {ex.Message}"); } steamClient.Shutdown(); Console.WriteLine("Done"); }