From ffd22a52ff5814d2aee76057d10cdf9f1913f8e9 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Fri, 6 Nov 2020 19:23:14 -0700 Subject: [PATCH] Use C# 7.0 tuples --- DepotDownloader/CDNClientPool.cs | 16 ++++++++-------- DepotDownloader/ContentDownloader.cs | 20 ++++++++++---------- DepotDownloader/Program.cs | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/DepotDownloader/CDNClientPool.cs b/DepotDownloader/CDNClientPool.cs index 8147563d..c468cdd0 100644 --- a/DepotDownloader/CDNClientPool.cs +++ b/DepotDownloader/CDNClientPool.cs @@ -106,22 +106,22 @@ namespace DepotDownloader #endif var weightedCdnServers = servers - .Where(x => + .Where(server => { #if STEAMKIT_UNRELEASED - var isEligibleForApp = x.AllowedAppIds == null || x.AllowedAppIds.Contains(appId); - return isEligibleForApp && (x.Type == "SteamCache" || x.Type == "CDN"); + var isEligibleForApp = server.AllowedAppIds == null || server.AllowedAppIds.Contains(appId); + return isEligibleForApp && (server.Type == "SteamCache" || server.Type == "CDN"); #else - return x.Type == "SteamCache" || x.Type == "CDN"; + return server.Type == "SteamCache" || server.Type == "CDN"; #endif }) - .Select(x => + .Select(server => { - AccountSettingsStore.Instance.ContentServerPenalty.TryGetValue(x.Host, out var penalty); + AccountSettingsStore.Instance.ContentServerPenalty.TryGetValue(server.Host, out var penalty); - return Tuple.Create(x, penalty); + return (server, penalty); }) - .OrderBy(x => x.Item2).ThenBy(x => x.Item1.WeightedLoad); + .OrderBy(pair => pair.penalty).ThenBy(pair => pair.server.WeightedLoad); foreach (var (server, weight) in weightedCdnServers) { diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index b4590015..07884279 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -391,7 +391,7 @@ namespace DepotDownloader } else if ( details?.hcontent_file > 0 ) { - await DownloadAppAsync( appId, new List>() { Tuple.Create( appId, details.hcontent_file ) }, DEFAULT_BRANCH, null, null, null, false, true ); + await DownloadAppAsync( appId, new List<(uint, ulong)>() { ( appId, details.hcontent_file ) }, DEFAULT_BRANCH, null, null, null, false, true ); } else { @@ -418,7 +418,7 @@ namespace DepotDownloader } else { - await DownloadAppAsync( appId, new List>() { Tuple.Create( appId, ugcId ) }, DEFAULT_BRANCH, null, null, null, false, true ); + await DownloadAppAsync( appId, new List<(uint, ulong)>() { ( appId, ugcId ) }, DEFAULT_BRANCH, null, null, null, false, true ); } } @@ -454,7 +454,7 @@ namespace DepotDownloader File.Move( fileStagingPath, fileFinalPath ); } - public static async Task DownloadAppAsync( uint appId, List> depotManifestIds, string branch, string os, string arch, string language, bool lv, bool isUgc ) + public static async Task DownloadAppAsync( uint appId, List<(uint depotId, ulong manifestId)> depotManifestIds, string branch, string os, string arch, string language, bool lv, bool isUgc ) { cdnPool = new CDNClientPool(steam3, appId); @@ -498,7 +498,7 @@ namespace DepotDownloader if ( workshopDepot != 0 && !depotIdsExpected.Contains( workshopDepot ) ) { depotIdsExpected.Add( workshopDepot ); - depotManifestIds = depotManifestIds.Select( pair => Tuple.Create( workshopDepot, pair.Item2 ) ).ToList(); + depotManifestIds = depotManifestIds.Select( pair => ( workshopDepot, pair.manifestId ) ).ToList(); } depotIdsFound.AddRange( depotIdsExpected ); @@ -562,7 +562,7 @@ namespace DepotDownloader depotIdsFound.Add( id ); if ( !hasSpecificDepots ) - depotManifestIds.Add( Tuple.Create( id, ContentDownloader.INVALID_MANIFEST_ID ) ); + depotManifestIds.Add( ( id, ContentDownloader.INVALID_MANIFEST_ID ) ); } } if ( depotManifestIds.Count == 0 && !hasSpecificDepots ) @@ -966,7 +966,7 @@ namespace DepotDownloader Console.WriteLine("Downloading depot {0} - {1}", depot.id, depot.contentName); var files = depotFilesData.filteredFiles.Where(f => !f.Flags.HasFlag(EDepotFileFlag.Directory)).ToArray(); - var networkChunkQueue = new ConcurrentQueue>(); + var networkChunkQueue = new ConcurrentQueue<(FileStreamData fileStreamData, ProtoManifest.FileData fileData, ProtoManifest.ChunkData chunk)>(); await Util.InvokeAsync( files.Select(file => new Func(async () => @@ -975,9 +975,9 @@ namespace DepotDownloader ); await Util.InvokeAsync( - networkChunkQueue.Select((x) => new Func(async () => + networkChunkQueue.Select(q => new Func(async () => await Task.Run(() => DownloadSteam3AsyncDepotFileChunk(cts, appId, downloadCounter, depotFilesData, - x.Item2, x.Item1, x.Item3)))), + q.fileData, q.fileStreamData, q.chunk)))), maxDegreeOfParallelism: Config.MaxDownloads ); @@ -1020,7 +1020,7 @@ namespace DepotDownloader CancellationTokenSource cts, DepotFilesData depotFilesData, ProtoManifest.FileData file, - ConcurrentQueue> networkChunkQueue) + ConcurrentQueue<(FileStreamData, ProtoManifest.FileData, ProtoManifest.ChunkData)> networkChunkQueue) { cts.Token.ThrowIfCancellationRequested(); @@ -1163,7 +1163,7 @@ namespace DepotDownloader foreach (var chunk in neededChunks) { - networkChunkQueue.Enqueue(Tuple.Create(fileStreamData, file, chunk)); + networkChunkQueue.Enqueue((fileStreamData, file, chunk)); } } diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 230cf4e9..bd2006b4 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -224,7 +224,7 @@ namespace DepotDownloader bool lv = HasParameter( args, "-lowviolence" ); - List> depotManifestIds = new List>(); + List<(uint, ulong)> depotManifestIds = new List<(uint, ulong)>(); bool isUGC = false; List depotIdList = GetParameterList( args, "-depot" ); @@ -237,11 +237,11 @@ namespace DepotDownloader return 1; } - depotManifestIds.Add( Tuple.Create( depotIdList[0], manifestId ) ); + depotManifestIds.Add( ( depotIdList[0], manifestId ) ); } else { - depotManifestIds.AddRange( depotIdList.Select( depotId => Tuple.Create( depotId, ContentDownloader.INVALID_MANIFEST_ID ) ) ); + depotManifestIds.AddRange( depotIdList.Select( depotId => ( depotId, ContentDownloader.INVALID_MANIFEST_ID ) ) ); } if ( InitializeSteam( username, password ) )