mirror of
https://github.com/SteamRE/DepotDownloader.git
synced 2026-10-19 15:51:50 +00:00
Await steam jobs instead of WaitUntilCallback
This commit is contained in:
1 parent
e7d637ace6
commit
9f64bd0439
2 files changed
+91
-165
No files matched your search
@@ -106,7 +106,7 @@ namespace DepotDownloader
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool AccountHasAccess(uint depotId)
|
||||
static async Task<bool> AccountHasAccess(uint depotId)
|
||||
{
|
||||
if (steam3 == null || steam3.steamUser.SteamID == null || (steam3.Licenses == null && steam3.steamUser.SteamID.AccountType != EAccountType.AnonUser))
|
||||
return false;
|
||||
@@ -121,7 +121,7 @@ namespace DepotDownloader
|
||||
licenseQuery = steam3.Licenses.Select(x => x.PackageID).Distinct();
|
||||
}
|
||||
|
||||
steam3.RequestPackageInfo(licenseQuery);
|
||||
await steam3.RequestPackageInfo(licenseQuery);
|
||||
|
||||
foreach (var license in licenseQuery)
|
||||
{
|
||||
@@ -184,7 +184,7 @@ namespace DepotDownloader
|
||||
return uint.Parse(buildid.Value);
|
||||
}
|
||||
|
||||
static ulong GetSteam3DepotManifest(uint depotId, uint appId, string branch)
|
||||
static async Task<ulong> GetSteam3DepotManifest(uint depotId, uint appId, string branch)
|
||||
{
|
||||
var depots = GetSteam3AppSection(appId, EAppInfoSection.Depots);
|
||||
var depotChild = depots[depotId.ToString()];
|
||||
@@ -206,9 +206,9 @@ namespace DepotDownloader
|
||||
return INVALID_MANIFEST_ID;
|
||||
}
|
||||
|
||||
steam3.RequestAppInfo(otherAppId);
|
||||
await steam3.RequestAppInfo(otherAppId);
|
||||
|
||||
return GetSteam3DepotManifest(depotId, otherAppId, branch);
|
||||
return await GetSteam3DepotManifest(depotId, otherAppId, branch);
|
||||
}
|
||||
|
||||
var manifests = depotChild["manifests"];
|
||||
@@ -236,7 +236,7 @@ namespace DepotDownloader
|
||||
if (encrypted_gid != KeyValue.Invalid)
|
||||
{
|
||||
// Submit the password to Steam now to get encryption keys
|
||||
steam3.CheckAppBetaPassword(appId, Config.BetaPassword);
|
||||
await steam3.CheckAppBetaPassword(appId, Config.BetaPassword);
|
||||
|
||||
if (!steam3.AppBetaPasswords.TryGetValue(branch, out var appBetaPassword))
|
||||
{
|
||||
@@ -326,7 +326,7 @@ namespace DepotDownloader
|
||||
|
||||
public static async Task DownloadPubfileAsync(uint appId, ulong publishedFileId)
|
||||
{
|
||||
var details = steam3.GetPublishedFileDetails(appId, publishedFileId);
|
||||
var details = await steam3.GetPublishedFileDetails(appId, publishedFileId);
|
||||
|
||||
if (!string.IsNullOrEmpty(details?.file_url))
|
||||
{
|
||||
@@ -348,7 +348,7 @@ namespace DepotDownloader
|
||||
|
||||
if (steam3.steamUser.SteamID.AccountType != EAccountType.AnonUser)
|
||||
{
|
||||
details = steam3.GetUGCDetails(ugcId);
|
||||
details = await steam3.GetUGCDetails(ugcId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -410,16 +410,16 @@ namespace DepotDownloader
|
||||
Directory.CreateDirectory(Path.Combine(configPath, CONFIG_DIR));
|
||||
DepotConfigStore.LoadFromFile(Path.Combine(configPath, CONFIG_DIR, "depot.config"));
|
||||
|
||||
steam3?.RequestAppInfo(appId);
|
||||
await steam3?.RequestAppInfo(appId);
|
||||
|
||||
if (!AccountHasAccess(appId))
|
||||
if (!await AccountHasAccess(appId))
|
||||
{
|
||||
if (steam3.RequestFreeAppLicense(appId))
|
||||
if (await steam3.RequestFreeAppLicense(appId))
|
||||
{
|
||||
Console.WriteLine("Obtained FreeOnDemand license for app {0}", appId);
|
||||
|
||||
// Fetch app info again in case we didn't get it fully without a license.
|
||||
steam3.RequestAppInfo(appId, true);
|
||||
await steam3.RequestAppInfo(appId, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -523,7 +523,7 @@ namespace DepotDownloader
|
||||
|
||||
foreach (var (depotId, manifestId) in depotManifestIds)
|
||||
{
|
||||
var info = GetDepotInfo(depotId, appId, manifestId, branch);
|
||||
var info = await GetDepotInfo(depotId, appId, manifestId, branch);
|
||||
if (info != null)
|
||||
{
|
||||
infos.Add(info);
|
||||
@@ -541,12 +541,14 @@ namespace DepotDownloader
|
||||
}
|
||||
}
|
||||
|
||||
static DepotDownloadInfo GetDepotInfo(uint depotId, uint appId, ulong manifestId, string branch)
|
||||
static async Task<DepotDownloadInfo> GetDepotInfo(uint depotId, uint appId, ulong manifestId, string branch)
|
||||
{
|
||||
if (steam3 != null && appId != INVALID_APP_ID)
|
||||
steam3.RequestAppInfo(appId);
|
||||
{
|
||||
await steam3.RequestAppInfo(appId);
|
||||
}
|
||||
|
||||
if (!AccountHasAccess(depotId))
|
||||
if (!await AccountHasAccess(depotId))
|
||||
{
|
||||
Console.WriteLine("Depot {0} is not available from this account.", depotId);
|
||||
|
||||
@@ -555,12 +557,12 @@ namespace DepotDownloader
|
||||
|
||||
if (manifestId == INVALID_MANIFEST_ID)
|
||||
{
|
||||
manifestId = GetSteam3DepotManifest(depotId, appId, branch);
|
||||
manifestId = await GetSteam3DepotManifest(depotId, appId, branch);
|
||||
if (manifestId == INVALID_MANIFEST_ID && !string.Equals(branch, DEFAULT_BRANCH, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Console.WriteLine("Warning: Depot {0} does not have branch named \"{1}\". Trying {2} branch.", depotId, branch, DEFAULT_BRANCH);
|
||||
branch = DEFAULT_BRANCH;
|
||||
manifestId = GetSteam3DepotManifest(depotId, appId, branch);
|
||||
manifestId = await GetSteam3DepotManifest(depotId, appId, branch);
|
||||
}
|
||||
|
||||
if (manifestId == INVALID_MANIFEST_ID)
|
||||
@@ -570,7 +572,7 @@ namespace DepotDownloader
|
||||
}
|
||||
}
|
||||
|
||||
steam3.RequestDepotKey(depotId, appId);
|
||||
await steam3.RequestDepotKey(depotId, appId);
|
||||
if (!steam3.DepotKeys.TryGetValue(depotId, out var depotKey))
|
||||
{
|
||||
Console.WriteLine("No valid depot key for {0}, unable to download.", depotId);
|
||||
|
||||
@@ -127,36 +127,34 @@ namespace DepotDownloader
|
||||
return IsLoggedOn;
|
||||
}
|
||||
|
||||
public void RequestAppInfo(uint appId, bool bForce = false)
|
||||
public async Task RequestAppInfo(uint appId, bool bForce = false)
|
||||
{
|
||||
if ((AppInfo.ContainsKey(appId) && !bForce) || bAborted)
|
||||
return;
|
||||
|
||||
var completed = false;
|
||||
Action<SteamApps.PICSTokensCallback> cbMethodTokens = appTokens =>
|
||||
var appTokens = await steamApps.PICSGetAccessTokens([appId], []);
|
||||
|
||||
if (appTokens.AppTokensDenied.Contains(appId))
|
||||
{
|
||||
completed = true;
|
||||
if (appTokens.AppTokensDenied.Contains(appId))
|
||||
{
|
||||
Console.WriteLine("Insufficient privileges to get access token for app {0}", appId);
|
||||
}
|
||||
Console.WriteLine("Insufficient privileges to get access token for app {0}", appId);
|
||||
}
|
||||
|
||||
foreach (var token_dict in appTokens.AppTokens)
|
||||
{
|
||||
this.AppTokens[token_dict.Key] = token_dict.Value;
|
||||
}
|
||||
};
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
foreach (var token_dict in appTokens.AppTokens)
|
||||
{
|
||||
callbacks.Subscribe(steamApps.PICSGetAccessTokens(new List<uint> { appId }, new List<uint>()), cbMethodTokens);
|
||||
}, () => { return completed; });
|
||||
this.AppTokens[token_dict.Key] = token_dict.Value;
|
||||
}
|
||||
|
||||
completed = false;
|
||||
Action<SteamApps.PICSProductInfoCallback> cbMethod = appInfo =>
|
||||
var request = new SteamApps.PICSRequest(appId);
|
||||
|
||||
if (AppTokens.TryGetValue(appId, out var token))
|
||||
{
|
||||
completed = !appInfo.ResponsePending;
|
||||
request.AccessToken = token;
|
||||
}
|
||||
|
||||
var appInfoMultiple = await steamApps.PICSGetProductInfo([request], []);
|
||||
|
||||
foreach (var appInfo in appInfoMultiple.Results)
|
||||
{
|
||||
foreach (var app_value in appInfo.Apps)
|
||||
{
|
||||
var app = app_value.Value;
|
||||
@@ -169,45 +167,17 @@ namespace DepotDownloader
|
||||
{
|
||||
AppInfo[app] = null;
|
||||
}
|
||||
};
|
||||
|
||||
var request = new SteamApps.PICSRequest(appId);
|
||||
if (AppTokens.TryGetValue(appId, out var token))
|
||||
{
|
||||
request.AccessToken = token;
|
||||
}
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
{
|
||||
callbacks.Subscribe(steamApps.PICSGetProductInfo(new List<SteamApps.PICSRequest> { request }, new List<SteamApps.PICSRequest>()), cbMethod);
|
||||
}, () => { return completed; });
|
||||
}
|
||||
|
||||
public void RequestPackageInfo(IEnumerable<uint> packageIds)
|
||||
public async Task RequestPackageInfo(IEnumerable<uint> packageIds)
|
||||
{
|
||||
var packages = packageIds.ToList();
|
||||
packages.RemoveAll(pid => PackageInfo.ContainsKey(pid));
|
||||
packages.RemoveAll(PackageInfo.ContainsKey);
|
||||
|
||||
if (packages.Count == 0 || bAborted)
|
||||
return;
|
||||
|
||||
var completed = false;
|
||||
Action<SteamApps.PICSProductInfoCallback> cbMethod = packageInfo =>
|
||||
{
|
||||
completed = !packageInfo.ResponsePending;
|
||||
|
||||
foreach (var package_value in packageInfo.Packages)
|
||||
{
|
||||
var package = package_value.Value;
|
||||
PackageInfo[package.ID] = package;
|
||||
}
|
||||
|
||||
foreach (var package in packageInfo.UnknownPackages)
|
||||
{
|
||||
PackageInfo[package] = null;
|
||||
}
|
||||
};
|
||||
|
||||
var packageRequests = new List<SteamApps.PICSRequest>();
|
||||
|
||||
foreach (var package in packages)
|
||||
@@ -222,55 +192,46 @@ namespace DepotDownloader
|
||||
packageRequests.Add(request);
|
||||
}
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
var packageInfoMultiple = await steamApps.PICSGetProductInfo([], packageRequests);
|
||||
|
||||
foreach (var packageInfo in packageInfoMultiple.Results)
|
||||
{
|
||||
callbacks.Subscribe(steamApps.PICSGetProductInfo(new List<SteamApps.PICSRequest>(), packageRequests), cbMethod);
|
||||
}, () => { return completed; });
|
||||
foreach (var package_value in packageInfo.Packages)
|
||||
{
|
||||
var package = package_value.Value;
|
||||
PackageInfo[package.ID] = package;
|
||||
}
|
||||
|
||||
foreach (var package in packageInfo.UnknownPackages)
|
||||
{
|
||||
PackageInfo[package] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RequestFreeAppLicense(uint appId)
|
||||
public async Task<bool> RequestFreeAppLicense(uint appId)
|
||||
{
|
||||
var success = false;
|
||||
var completed = false;
|
||||
Action<SteamApps.FreeLicenseCallback> cbMethod = resultInfo =>
|
||||
{
|
||||
completed = true;
|
||||
success = resultInfo.GrantedApps.Contains(appId);
|
||||
};
|
||||
var resultInfo = await steamApps.RequestFreeLicense(appId);
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
{
|
||||
callbacks.Subscribe(steamApps.RequestFreeLicense(appId), cbMethod);
|
||||
}, () => { return completed; });
|
||||
|
||||
return success;
|
||||
return resultInfo.GrantedApps.Contains(appId);
|
||||
}
|
||||
|
||||
public void RequestDepotKey(uint depotId, uint appid = 0)
|
||||
public async Task RequestDepotKey(uint depotId, uint appid = 0)
|
||||
{
|
||||
if (DepotKeys.ContainsKey(depotId) || bAborted)
|
||||
return;
|
||||
|
||||
var completed = false;
|
||||
var depotKey = await steamApps.GetDepotDecryptionKey(depotId, appid);
|
||||
|
||||
Action<SteamApps.DepotKeyCallback> cbMethod = depotKey =>
|
||||
Console.WriteLine("Got depot key for {0} result: {1}", depotKey.DepotID, depotKey.Result);
|
||||
|
||||
if (depotKey.Result != EResult.OK)
|
||||
{
|
||||
completed = true;
|
||||
Console.WriteLine("Got depot key for {0} result: {1}", depotKey.DepotID, depotKey.Result);
|
||||
Abort();
|
||||
return;
|
||||
}
|
||||
|
||||
if (depotKey.Result != EResult.OK)
|
||||
{
|
||||
Abort();
|
||||
return;
|
||||
}
|
||||
|
||||
DepotKeys[depotKey.DepotID] = depotKey.DepotKey;
|
||||
};
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
{
|
||||
callbacks.Subscribe(steamApps.GetDepotDecryptionKey(depotId, appid), cbMethod);
|
||||
}, () => { return completed; });
|
||||
DepotKeys[depotKey.DepotID] = depotKey.DepotKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,86 +273,49 @@ namespace DepotDownloader
|
||||
completion.TrySetResult(cdnAuth);
|
||||
}
|
||||
|
||||
public void CheckAppBetaPassword(uint appid, string password)
|
||||
public async Task CheckAppBetaPassword(uint appid, string password)
|
||||
{
|
||||
var completed = false;
|
||||
Action<SteamApps.CheckAppBetaPasswordCallback> cbMethod = appPassword =>
|
||||
var appPassword = await steamApps.CheckAppBetaPassword(appid, password);
|
||||
|
||||
Console.WriteLine("Retrieved {0} beta keys with result: {1}", appPassword.BetaPasswords.Count, appPassword.Result);
|
||||
|
||||
foreach (var entry in appPassword.BetaPasswords)
|
||||
{
|
||||
completed = true;
|
||||
|
||||
Console.WriteLine("Retrieved {0} beta keys with result: {1}", appPassword.BetaPasswords.Count, appPassword.Result);
|
||||
|
||||
foreach (var entry in appPassword.BetaPasswords)
|
||||
{
|
||||
AppBetaPasswords[entry.Key] = entry.Value;
|
||||
}
|
||||
};
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
{
|
||||
callbacks.Subscribe(steamApps.CheckAppBetaPassword(appid, password), cbMethod);
|
||||
}, () => { return completed; });
|
||||
AppBetaPasswords[entry.Key] = entry.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public PublishedFileDetails GetPublishedFileDetails(uint appId, PublishedFileID pubFile)
|
||||
public async Task<PublishedFileDetails> GetPublishedFileDetails(uint appId, PublishedFileID pubFile)
|
||||
{
|
||||
var pubFileRequest = new CPublishedFile_GetDetails_Request { appid = appId };
|
||||
pubFileRequest.publishedfileids.Add(pubFile);
|
||||
|
||||
var completed = false;
|
||||
PublishedFileDetails details = null;
|
||||
var callback = await steamPublishedFile.SendMessage(api => api.GetDetails(pubFileRequest));
|
||||
|
||||
Action<SteamUnifiedMessages.ServiceMethodResponse> cbMethod = callback =>
|
||||
if (callback.Result == EResult.OK)
|
||||
{
|
||||
completed = true;
|
||||
if (callback.Result == EResult.OK)
|
||||
{
|
||||
var response = callback.GetDeserializedResponse<CPublishedFile_GetDetails_Response>();
|
||||
details = response.publishedfiledetails.FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving file details for pubfile {pubFile}.");
|
||||
}
|
||||
};
|
||||
var response = callback.GetDeserializedResponse<CPublishedFile_GetDetails_Response>();
|
||||
return response.publishedfiledetails.FirstOrDefault();
|
||||
}
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
{
|
||||
callbacks.Subscribe(steamPublishedFile.SendMessage(api => api.GetDetails(pubFileRequest)), cbMethod);
|
||||
}, () => { return completed; });
|
||||
|
||||
return details;
|
||||
throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving file details for pubfile {pubFile}.");
|
||||
}
|
||||
|
||||
|
||||
public SteamCloud.UGCDetailsCallback GetUGCDetails(UGCHandle ugcHandle)
|
||||
public async Task<SteamCloud.UGCDetailsCallback> GetUGCDetails(UGCHandle ugcHandle)
|
||||
{
|
||||
var completed = false;
|
||||
SteamCloud.UGCDetailsCallback details = null;
|
||||
var callback = await steamCloud.RequestUGCDetails(ugcHandle);
|
||||
|
||||
Action<SteamCloud.UGCDetailsCallback> cbMethod = callback =>
|
||||
if (callback.Result == EResult.OK)
|
||||
{
|
||||
completed = true;
|
||||
if (callback.Result == EResult.OK)
|
||||
{
|
||||
details = callback;
|
||||
}
|
||||
else if (callback.Result == EResult.FileNotFound)
|
||||
{
|
||||
details = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving UGC details for {ugcHandle}.");
|
||||
}
|
||||
};
|
||||
|
||||
WaitUntilCallback(() =>
|
||||
return callback;
|
||||
}
|
||||
else if (callback.Result == EResult.FileNotFound)
|
||||
{
|
||||
callbacks.Subscribe(steamCloud.RequestUGCDetails(ugcHandle), cbMethod);
|
||||
}, () => { return completed; });
|
||||
return null;
|
||||
}
|
||||
|
||||
return details;
|
||||
throw new Exception($"EResult {(int)callback.Result} ({callback.Result}) while retrieving UGC details for {ugcHandle}.");
|
||||
}
|
||||
|
||||
private void ResetConnectionFlags()
|
||||
|
||||
Reference in new issue
Block a user