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"); }
public override string GetTwoFactorAuthenticationCode(SteamCredentials steamCredentials) { Console.Write("Please enter your 2FA code: "); string input = Console.ReadLine(); Console.Write("Retrying... "); return(input); }
/// <inheritdoc cref="ISteamClient" /> /// <param name="settings">Settings containing steam user, password and mods directory.</param> /// <param name="logger">Logger</param> /// TODO: Handle no Steam User/Password public SteamClient( ISettings settings, ILogger <SteamClient> logger) { var steamCredentials = new SteamCredentials(settings.SteamUser, settings.SteamPassword); _bytexSteamClient = new BytexSteamClient(steamCredentials); ContentClient = new SteamContentClient(_bytexSteamClient); _logger = logger; }
public override string GetTwoFactorAuthenticationCode(SteamCredentials steamCredentials) { MainWindow.Instance.SteamUpdaterViewModel.Parameters.Output += "\nPlease enter your 2FA code: "; var input = MainWindow.Instance.SteamUpdaterViewModel.SteamGuardInput().Result; MainWindow.Instance.SteamUpdaterViewModel.Parameters.Output += "\nRetrying... "; return(input); }
static async Task RunOptions(Options opt) { SteamAuthenticationFilesProvider sentryFileProvider = default; if (!string.IsNullOrEmpty(opt.SentryDirectory)) { sentryFileProvider = new DirectorySteamAuthenticationFilesProvider(opt.SentryDirectory); } if (opt.Username == Options.ANONYMOUS_USERNAME) { _steamCredentials = SteamCredentials.Anonymous; } else { _steamCredentials = new SteamCredentials(opt.Username, opt.Password); } _steamClient = new SteamClient(_steamCredentials, new AuthCodeProvider(), sentryFileProvider); _steamContentClient = new SteamContentClient(_steamClient, null, opt.WorkerCount, opt.ChunkBufferSizeBytes, opt.ChunkBufferUsageThreshold); if (string.IsNullOrEmpty(opt.OS)) { opt.OS = _steamClient.GetSteamOs().Identifier; } Console.Write($"Connecting to Steam as \"{opt.Username}\"... "); try { await _steamClient.ConnectAsync(); } catch (Exception ex) { Console.WriteLine($"Failed! Error: {ex.Message}"); if (ex is SteamLogonException logonEx) { if (logonEx.Result == SteamKit2.EResult.InvalidPassword) { Console.WriteLine($"Warning: The logon may have failed due to expired sentry-data. " + $"If you are sure that the provided username and password are correct, consider deleting the .bin and .key file for the user \"{_steamClient.Credentials.Username}\" in the sentries directory."); } } Environment.Exit(3); } Console.WriteLine("OK."); if (opt.DownloadApp) { await DownloadApp(opt); } else if (opt.DownloadWorkshopItem) { await DownloadWorkshopItem(opt); } else { Console.WriteLine("No action to run specified, exiting."); } _steamClient.Shutdown(); }
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"); }