Play your Steam library's Windows games on a jailbroken PS5.
C++
Log which Cloud save failed and why
Leonardo Lobato01ce99554a66
diff --git a/src/steam/backend/cloud_sync.cpp b/src/steam/backend/cloud_sync.cppindex 737f2af..7ffdaf3 100644--- a/src/steam/backend/cloud_sync.cpp+++ b/src/steam/backend/cloud_sync.cpp@@ -16,6 +16,7 @@#include <mbedtls/sha256.h>#include <algorithm>+#include <cerrno>#include <chrono>#include <cstdio>#include <cstring>@@ -684,9 +685,10 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatiResolution resolution, bool confirm_account, const std::atomic<bool>& cancel,const ApplyProgress& progress) {CloudOutcome outcome;- const auto fail = [&](std::string message) {+ const auto fail = [&](std::string message, std::string detail = {}) {outcome.ok = false;outcome.message = std::move(message);+ outcome.detail = std::move(detail);return outcome;};if (plan.status == PlanStatus::kFailed || plan.status == PlanStatus::kUnsupported) return fail(plan.message);@@ -737,6 +739,7 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocati};std::string failure;+ std::string detail; // for the log: which file and what failed (never a URL path or header: they carry tokens)std::optional<RemoteFileList> final_list;const auto result = hooks_.session(session, kSessionDeadlineMs, cancel,[&](const CmClient::ServiceCall& call, std::uint64_t steam_id) {@@ -765,14 +768,23 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocaticonst auto fetch = [&](const Decision& decision) -> std::optional<std::vector<std::uint8_t>> {PLAYDEN_CLOUD_TRACE("download");reply.clear();- if (call(kClientFileDownload, EncodeFileDownloadRequest(location.app_id, decision.remote_name), &reply, nullptr) !=+ const auto named = "file=" + decision.remote_name;+ int eresult = 0;+ if (call(kClientFileDownload, EncodeFileDownloadRequest(location.app_id, decision.remote_name), &reply, &eresult) !=CmError::kNone) {failure = "Steam refused a Cloud save download.";+ detail = named + " download-request eresult=" + std::to_string(eresult);return std::nullopt;}const auto ticket = DecodeFileDownloadResponse(reply);if (!ticket || ticket->encrypted || ticket->explicit_delete || ticket->sha1 != decision.remote_fact.sha1 ||ticket->raw_file_size != decision.remote_fact.size || ticket->file_size > kMaxHttpResponseBytes) {+ detail = !ticket ? named + " ticket=undecodable"+ : named + " ticket encrypted=" + std::to_string(ticket->encrypted) ++ " deleted=" + std::to_string(ticket->explicit_delete) ++ " sha1_match=" + std::to_string(ticket->sha1 == decision.remote_fact.sha1) ++ " raw_size=" + std::to_string(ticket->raw_file_size) + " listed_size=" ++ std::to_string(decision.remote_fact.size) + " file_size=" + std::to_string(ticket->file_size);failure = ticket && ticket->file_size > kMaxHttpResponseBytes ? "A Cloud save is too large to download yet.": "Steam described a Cloud save Playden cannot use.";return std::nullopt;@@ -780,6 +792,7 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocaticonst auto url = TransferUrl(ticket->use_https, ticket->host, ticket->path);if (!url) {failure = "Steam described a Cloud save Playden cannot use.";+ detail = named + " transfer-url refused host=" + ticket->host;return std::nullopt;}HttpRequest request;@@ -790,6 +803,9 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocaticonst auto response = hooks_.http(request, cancel);if (!response.ok() || response.status_code != 200) {failure = "A Cloud save could not be downloaded. Try again.";+ detail = named + " http error=" + HttpErrorName(response.error) + " status=" + std::to_string(response.status_code) ++ " host=" + ticket->host + " file_size=" + std::to_string(ticket->file_size) ++ " raw_size=" + std::to_string(ticket->raw_file_size) + " body=" + std::to_string(response.body.size());return std::nullopt;}std::vector<std::uint8_t> data = response.body;@@ -797,12 +813,15 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatistd::vector<std::uint8_t> unpacked;if (!UnzipFirstEntry(response.body, InflateRaw, &unpacked)) {failure = "A downloaded Cloud save was damaged.";+ detail = named + " unzip failed body=" + std::to_string(response.body.size());return std::nullopt;}data = std::move(unpacked);}if (data.size() != decision.remote_fact.size || Sha1(data) != decision.remote_fact.sha1) {failure = "A downloaded Cloud save was damaged.";+ detail = named + " content size=" + std::to_string(data.size()) + " listed_size=" ++ std::to_string(decision.remote_fact.size) + " sha1_match=0";return std::nullopt;}return data;@@ -815,6 +834,7 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocaticonst auto target = Absolute(location, decision.local);if (!backup(decision) || !WriteFileAtomic(target, data)) {failure = "A Cloud save could not be written on this device.";+ detail = "file=" + decision.remote_name + " write failed errno=" + std::to_string(errno);return CmError::kProtocol;}SetModified(target, decision.remote_fact.time);@@ -892,8 +912,10 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatiif (call(kClientBeginFileUpload,EncodeBeginFileUploadRequest(location.app_id, data.size(), decision.local_fact.sha1, time_stamp,decision.remote_name, batch->batch_id),- &reply, &eresult) != CmError::kNone)+ &reply, &eresult) != CmError::kNone) {+ detail = "file=" + decision.remote_name + " upload-request eresult=" + std::to_string(eresult);return abort_batch("Steam refused a Cloud save upload (" + std::to_string(eresult) + ").", CmError::kRejected);+ }const auto upload = DecodeBeginFileUploadResponse(reply);if (!upload || upload->encrypt_file) return abort_batch("Steam asked for an upload Playden cannot make.", CmError::kProtocol);bool transferred = true;@@ -901,6 +923,8 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocaticonst auto url = TransferUrl(block.use_https, block.host, block.path);if (!url || (block.http_method != 3 && block.http_method != 4) ||(!block.explicit_body && block.offset + block.length > data.size())) {+ detail = "file=" + decision.remote_name + " upload block refused method=" + std::to_string(block.http_method) ++ " host=" + block.host;transferred = false;break;}@@ -914,6 +938,9 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatidata.begin() + static_cast<std::ptrdiff_t>(block.offset + block.length));const auto response = hooks_.http(request, cancel);if (!response.ok() || response.status_code < 200 || response.status_code >= 300) {+ detail = "file=" + decision.remote_name + " upload http error=" + HttpErrorName(response.error) ++ " status=" + std::to_string(response.status_code) + " host=" + block.host ++ " bytes=" + std::to_string(request.body.size());transferred = false;break;}@@ -924,8 +951,12 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatidecision.remote_name),&reply, nullptr);const auto committed_ok = committed == CmError::kNone ? DecodeCommitFileUploadResponse(reply) : std::nullopt;- if (!transferred || !committed_ok || !*committed_ok)+ if (!transferred || !committed_ok || !*committed_ok) {+ if (transferred)+ detail = "file=" + decision.remote_name + " commit " ++ (committed != CmError::kNone ? "request failed" : !committed_ok ? "reply undecodable" : "refused");return abort_batch("A Cloud save could not be uploaded. Try again.", CmError::kNetwork);+ }++outcome.uploaded;count_bytes(decision.local_fact.size);}@@ -953,7 +984,7 @@ CloudOutcome CloudSync::Apply(const StoredSession& session, const GameSaveLocatireturn CmError::kNone;});if (backed_up) PruneBackups(location.state_root);- if (result != CmError::kNone) return fail(failure.empty() ? "Steam is not reachable. Try again." : failure);+ if (result != CmError::kNone) return fail(failure.empty() ? "Steam is not reachable. Try again." : failure, detail);// The verified common state becomes the next baseline: every Cloud file that maps locally and// now matches its local copy.diff --git a/src/steam/backend/cloud_sync.h b/src/steam/backend/cloud_sync.hindex 9b53604..b240622 100644--- a/src/steam/backend/cloud_sync.h+++ b/src/steam/backend/cloud_sync.h@@ -90,6 +90,7 @@ using ApplyProgress = std::function<void(std::uint64_t done, std::uint64_t totalstruct CloudOutcome {bool ok = false;std::string message; // short, user-facing+ std::string detail; // for the log only: the file and what failedstd::size_t downloaded = 0, uploaded = 0, removed_local = 0, removed_remote = 0;// Both sides once the transfers are done (when ok).std::size_t local_files = 0, remote_files = 0;diff --git a/src/steam/backend/steam_cloud_runner.cpp b/src/steam/backend/steam_cloud_runner.cppindex 2acf283..dfdfd5d 100644--- a/src/steam/backend/steam_cloud_runner.cpp+++ b/src/steam/backend/steam_cloud_runner.cpp@@ -114,7 +114,9 @@ CloudReport SteamCloudRunner::Apply(const StoredSession& session, const CloudLocreport.local_latest = outcome.local_latest;report.remote_latest = outcome.remote_latest;}- if (log_) log_(App(location), outcome.ok ? "apply-ok" : "apply-failed", outcome.message);+ if (log_)+ log_(App(location), outcome.ok ? "apply-ok" : "apply-failed",+ outcome.detail.empty() ? outcome.message : outcome.message + " (" + outcome.detail + ")");report.first_sync = false;report.first_overwrite = false;return report;diff --git a/tests/steam_cloud_test.cpp b/tests/steam_cloud_test.cppindex 66d888f..249be2d 100644--- a/tests/steam_cloud_test.cpp+++ b/tests/steam_cloud_test.cpp@@ -142,6 +142,7 @@ struct FakeCloud {std::uint64_t steam_id = kSteamId;bool declares_ufs = true;bool corrupt_downloads = false;+ long download_status = 200; // another status refuses every downloadstd::uint64_t next_batch = 700;std::map<std::string, std::vector<std::uint8_t>> pending; // uploads in the open batchstd::vector<std::string> pending_deletes;@@ -253,6 +254,10 @@ struct FakeCloud {const auto& file = files.at(path.substr(4));response.body = file.zipped ? StoredZip("f", file.data) : file.data;if (corrupt_downloads && !response.body.empty()) response.body.back() ^= 0xff;+ if (download_status != 200) {+ response.status_code = download_status;+ response.body.clear();+ }} else if (path.rfind("/up/", 0) == 0) {CHECK(request.method == HttpMethod::kPut);pending[path.substr(4)] = request.body;@@ -514,9 +519,20 @@ void SyncEndToEnd() {cloud.corrupt_downloads = true;outcome = sync.Apply(session, location, plan, Resolution::kUseCloud, true, cancel);CHECK(!outcome.ok && outcome.message.find("damaged") != std::string::npos);+ CHECK(outcome.detail.find("file=%WinMyDocuments%My Games/Cloud Game/slot3.sav") != std::string::npos &&+ outcome.detail.find("sha1_match=0") != std::string::npos);CHECK(!std::filesystem::exists(docs / "slot3.sav"));cloud.corrupt_downloads = false;+ // A download the server refuses: the player reads a short message, the log gets the file and the HTTP status.+ plan = sync.Check(session, location, cancel);+ cloud.download_status = 403;+ outcome = sync.Apply(session, location, plan, Resolution::kUseCloud, true, cancel);+ CHECK(!outcome.ok && outcome.message == "A Cloud save could not be downloaded. Try again.");+ CHECK(outcome.detail.find("file=%WinMyDocuments%My Games/Cloud Game/slot3.sav http error=") != std::string::npos &&+ outcome.detail.find(" status=403 ") != std::string::npos && outcome.detail.find("x-test-signature") == std::string::npos);+ cloud.download_status = 200;+// A game without Steam Cloud says so.cloud.declares_ufs = false;plan = sync.Check(session, location, cancel);