Skip to content

Commit

Permalink
Adding a hidden flag that controls the number of download threads. Th…
Browse files Browse the repository at this point in the history
…is is only meant for debugging and isn't exposed to the user via the cli help text.
  • Loading branch information
tpill90 committed Oct 11, 2024
1 parent 7cf7190 commit 9406cb9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LancachePrefill.Common
16 changes: 15 additions & 1 deletion SteamPrefill/Models/DownloadArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public sealed class DownloadArguments
{
private int _maxConcurrentRequests = 30;

/// <summary>
/// When set to true, always run the download, regardless of if the app has been previously downloaded.
/// </summary>
Expand All @@ -19,7 +21,19 @@ public sealed class DownloadArguments
/// The default of 30 was found to be a good middle ground for maximum throughput. It also minimizes the potential for SteamPrefill to
/// choke out any other downloads on the network, without having to require users setup QoS themselves.
/// </summary>
public int MaxConcurrentRequests { get; set; } = 30;
public int MaxConcurrentRequests
{
get
{
//TODO I don't like how this is using a static variable like this, because nothing else in this class is like this. Consider removing this later once its no longer used for debugging.
if (AppConfig.MaxConcurrencyOverride != null)
{
return AppConfig.MaxConcurrencyOverride.Value;
}
return _maxConcurrentRequests;
}
set => _maxConcurrentRequests = value;
}

/// <summary>
/// Determines which Operating System specific depots should be included in the download.
Expand Down
23 changes: 18 additions & 5 deletions SteamPrefill/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ public static async Task<int> Main()
{
try
{
// Checking to see if the user double clicked the exe in Windows, and display a message on how to use the app
// Checking to see if the user double-clicked the exe in Windows, and display a message on how to use the app
OperatingSystemUtils.DetectDoubleClickOnWindows("SteamPrefill");

var cliArgs = ParseHiddenFlags();
var description = "Automatically fills a Lancache with games from Steam, so that subsequent downloads will be \n" +
" served from the Lancache, improving speeds and reducing load on your internet connection. \n" +
"\n" +
" Start by selecting apps for prefill with the 'select-apps' command, then start the prefill using 'prefill'";
var description = """
Automatically fills a Lancache with games from Steam, so that subsequent downloads will be
served from the Lancache, improving speeds and reducing load on your internet connection.
Start by selecting apps for prefill with the 'select-apps' command, then start the prefill using 'prefill'
""";

return await new CliApplicationBuilder()
.AddCommandsFromThisAssembly()
Expand Down Expand Up @@ -101,6 +103,17 @@ private static List<string> ParseHiddenFlags()
args.Remove(id);
}

if (args.Any(e => e.Contains("--max-threads")))
{
var flagIndex = args.IndexOf("--max-threads");
var count = args[flagIndex + 1];
AppConfig.MaxConcurrencyOverride = int.Parse(count);

AnsiConsole.Console.LogMarkupLine($"Using {LightYellow("--max-threads")} flag. Will download using at most {Magenta(count)} threads");
args.Remove("--max-threads");
args.Remove(count);
}

// Adding some formatting to logging to make it more readable + clear that these flags are enabled
if (AppConfig.DebugLogs || AppConfig.SkipDownloads || AppConfig.NoLocalCache)
{
Expand Down
2 changes: 2 additions & 0 deletions SteamPrefill/Settings/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public static bool DebugLogs

public static uint? CellIdOverride { get; set; }

public static int? MaxConcurrencyOverride { get; set; }

#endregion
}
}

0 comments on commit 9406cb9

Please sign in to comment.