Use C# 7.0 tuples

pull/151/head
Ryan Kistner 5 years ago
parent f146251555
commit ffd22a52ff

@ -106,22 +106,22 @@ namespace DepotDownloader
#endif #endif
var weightedCdnServers = servers var weightedCdnServers = servers
.Where(x => .Where(server =>
{ {
#if STEAMKIT_UNRELEASED #if STEAMKIT_UNRELEASED
var isEligibleForApp = x.AllowedAppIds == null || x.AllowedAppIds.Contains(appId); var isEligibleForApp = server.AllowedAppIds == null || server.AllowedAppIds.Contains(appId);
return isEligibleForApp && (x.Type == "SteamCache" || x.Type == "CDN"); return isEligibleForApp && (server.Type == "SteamCache" || server.Type == "CDN");
#else #else
return x.Type == "SteamCache" || x.Type == "CDN"; return server.Type == "SteamCache" || server.Type == "CDN";
#endif #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) foreach (var (server, weight) in weightedCdnServers)
{ {

@ -391,7 +391,7 @@ namespace DepotDownloader
} }
else if ( details?.hcontent_file > 0 ) else if ( details?.hcontent_file > 0 )
{ {
await DownloadAppAsync( appId, new List<Tuple<uint, ulong>>() { 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 else
{ {
@ -418,7 +418,7 @@ namespace DepotDownloader
} }
else else
{ {
await DownloadAppAsync( appId, new List<Tuple<uint, ulong>>() { 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 ); File.Move( fileStagingPath, fileFinalPath );
} }
public static async Task DownloadAppAsync( uint appId, List<Tuple<uint, ulong>> 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); cdnPool = new CDNClientPool(steam3, appId);
@ -498,7 +498,7 @@ namespace DepotDownloader
if ( workshopDepot != 0 && !depotIdsExpected.Contains( workshopDepot ) ) if ( workshopDepot != 0 && !depotIdsExpected.Contains( workshopDepot ) )
{ {
depotIdsExpected.Add( 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 ); depotIdsFound.AddRange( depotIdsExpected );
@ -562,7 +562,7 @@ namespace DepotDownloader
depotIdsFound.Add( id ); depotIdsFound.Add( id );
if ( !hasSpecificDepots ) if ( !hasSpecificDepots )
depotManifestIds.Add( Tuple.Create( id, ContentDownloader.INVALID_MANIFEST_ID ) ); depotManifestIds.Add( ( id, ContentDownloader.INVALID_MANIFEST_ID ) );
} }
} }
if ( depotManifestIds.Count == 0 && !hasSpecificDepots ) if ( depotManifestIds.Count == 0 && !hasSpecificDepots )
@ -966,7 +966,7 @@ namespace DepotDownloader
Console.WriteLine("Downloading depot {0} - {1}", depot.id, depot.contentName); Console.WriteLine("Downloading depot {0} - {1}", depot.id, depot.contentName);
var files = depotFilesData.filteredFiles.Where(f => !f.Flags.HasFlag(EDepotFileFlag.Directory)).ToArray(); var files = depotFilesData.filteredFiles.Where(f => !f.Flags.HasFlag(EDepotFileFlag.Directory)).ToArray();
var networkChunkQueue = new ConcurrentQueue<Tuple<FileStreamData, ProtoManifest.FileData, ProtoManifest.ChunkData>>(); var networkChunkQueue = new ConcurrentQueue<(FileStreamData fileStreamData, ProtoManifest.FileData fileData, ProtoManifest.ChunkData chunk)>();
await Util.InvokeAsync( await Util.InvokeAsync(
files.Select(file => new Func<Task>(async () => files.Select(file => new Func<Task>(async () =>
@ -975,9 +975,9 @@ namespace DepotDownloader
); );
await Util.InvokeAsync( await Util.InvokeAsync(
networkChunkQueue.Select((x) => new Func<Task>(async () => networkChunkQueue.Select(q => new Func<Task>(async () =>
await Task.Run(() => DownloadSteam3AsyncDepotFileChunk(cts, appId, downloadCounter, depotFilesData, await Task.Run(() => DownloadSteam3AsyncDepotFileChunk(cts, appId, downloadCounter, depotFilesData,
x.Item2, x.Item1, x.Item3)))), q.fileData, q.fileStreamData, q.chunk)))),
maxDegreeOfParallelism: Config.MaxDownloads maxDegreeOfParallelism: Config.MaxDownloads
); );
@ -1020,7 +1020,7 @@ namespace DepotDownloader
CancellationTokenSource cts, CancellationTokenSource cts,
DepotFilesData depotFilesData, DepotFilesData depotFilesData,
ProtoManifest.FileData file, ProtoManifest.FileData file,
ConcurrentQueue<Tuple<FileStreamData, ProtoManifest.FileData, ProtoManifest.ChunkData>> networkChunkQueue) ConcurrentQueue<(FileStreamData, ProtoManifest.FileData, ProtoManifest.ChunkData)> networkChunkQueue)
{ {
cts.Token.ThrowIfCancellationRequested(); cts.Token.ThrowIfCancellationRequested();
@ -1163,7 +1163,7 @@ namespace DepotDownloader
foreach (var chunk in neededChunks) foreach (var chunk in neededChunks)
{ {
networkChunkQueue.Enqueue(Tuple.Create(fileStreamData, file, chunk)); networkChunkQueue.Enqueue((fileStreamData, file, chunk));
} }
} }

@ -224,7 +224,7 @@ namespace DepotDownloader
bool lv = HasParameter( args, "-lowviolence" ); bool lv = HasParameter( args, "-lowviolence" );
List<Tuple<uint, ulong>> depotManifestIds = new List<Tuple<uint, ulong>>(); List<(uint, ulong)> depotManifestIds = new List<(uint, ulong)>();
bool isUGC = false; bool isUGC = false;
List<uint> depotIdList = GetParameterList<uint>( args, "-depot" ); List<uint> depotIdList = GetParameterList<uint>( args, "-depot" );
@ -237,11 +237,11 @@ namespace DepotDownloader
return 1; return 1;
} }
depotManifestIds.Add( Tuple.Create( depotIdList[0], manifestId ) ); depotManifestIds.Add( ( depotIdList[0], manifestId ) );
} }
else 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 ) ) if ( InitializeSteam( username, password ) )

Loading…
Cancel
Save