Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Let a move to a disconnected drive be canceled

Leonardo Lobato7e1cdb65c379
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cpp
index bdced6e..93f6172 100644
--- a/src/homebrew/controller.cpp
+++ b/src/homebrew/controller.cpp
@@ -2057,6 +2057,20 @@ void Controller::TickInstalls() {
if (job.kind == steam::InstallJobKind::kUpdate) updating.insert(job.id);
if (job.kind == steam::InstallJobKind::kMove) moving.insert(job.id);
}
+ // A move whose destination went away while Playden was closed stays locked until the game's PS5 title record
+ // says it starts the game from the folder it is listed in, with nothing pending that could still name the
+ // copy: then it can be canceled. A game without a record stays locked too, as a lost record can't be told
+ // from no title; connecting the drive again lets the move go on or be canceled.
+ if (runtime_)
+ if (const auto runtime = runtime_->Shared();
+ runtime->status == RuntimeHostStatus::kReady && runtime->installs_known)
+ for (const auto& job : snapshot.jobs) {
+ if (job.kind != steam::InstallJobKind::kMove || !job.locked || job.state != steam::InstallJobState::kFailed) continue;
+ const auto view = std::find_if(runtime->installs.begin(), runtime->installs.end(),
+ [&job](const RuntimeInstallView& candidate) { return candidate.game == job.id; });
+ if (view != runtime->installs.end() && !view->moving && !view->recovery_pending && !view->republish_pending)
+ installs_->ReleaseUnreachableMove(job.id, view->install_path);
+ }
for (const auto id : downloading_) {
if (downloading.count(id) || !game_roots_.count(id)) continue;
// A move that ended leaves the game prepared as it was: its title followed the copy (RuntimeHost::Relocate).
diff --git a/src/homebrew/runtime_host.cpp b/src/homebrew/runtime_host.cpp
index e51cfec..9e143e3 100644
--- a/src/homebrew/runtime_host.cpp
+++ b/src/homebrew/runtime_host.cpp
@@ -1485,6 +1485,7 @@ void RuntimeHost::PublishInstalls(const Composition& composition, const std::str
view.game = GameOf(record.game, record.runtime_number);
view.install_path = record.install_path;
view.moving = record.journal && record.journal->operation == "remove-move";
+ view.republish_pending = !record.moved_from.empty();
if (!record.data_root.empty()) view.prefix_root = record.data_root + "/library/prefixes/game";
view.state = record.state;
if (record.journal) view.step = record.journal->step;
diff --git a/src/homebrew/runtime_host.hpp b/src/homebrew/runtime_host.hpp
index 2645a2b..95b4457 100644
--- a/src/homebrew/runtime_host.hpp
+++ b/src/homebrew/runtime_host.hpp
@@ -173,6 +173,9 @@ struct RuntimeInstallView {
std::string install_path;
// Its title is being removed to follow the game to another drive; Prepare finishes that.
bool moving = false;
+ // The title moved to another folder and its publication there isn't done yet: what Home starts may still
+ // name the old folder (the record's moved_from).
+ bool republish_pending = false;
// The game's private bottle (console path); Cloud saves under Windows
// folders live here.
std::string prefix_root;
diff --git a/src/homebrew/simulation.cpp b/src/homebrew/simulation.cpp
index fd3d3b0..c8d93f7 100644
--- a/src/homebrew/simulation.cpp
+++ b/src/homebrew/simulation.cpp
@@ -583,7 +583,12 @@ ModalEntry cancel_job_confirmation(const State& state, const Job* job, std::stri
return found == state.volumes.end() ? std::string("the other drive") : found->label;
};
ModalEntry confirmation{"confirmation", "Cancel the move?", std::move(opener), {"cancel", "confirm-destructive"}, 0, true};
- confirmation.body = "The copy on " + label(job->volume_id) + " is deleted. The game stays on " + label(job->from_volume_id) + ".";
+ // A destination that isn't connected keeps its partial copy: nothing can delete it there.
+ const auto to = std::find_if(state.volumes.begin(), state.volumes.end(), [job](const Volume& volume) { return volume.id == job->volume_id; });
+ confirmation.body = to != state.volumes.end() && to->available
+ ? "The copy on " + label(job->volume_id) + " is deleted. The game stays on " + label(job->from_volume_id) + "."
+ : (to == state.volumes.end() ? std::string("The other drive") : to->label) +
+ " isn't connected, so the part copied there stays. The game stays on " + label(job->from_volume_id) + ".";
return confirmation;
}
ModalEntry confirmation{"confirmation", "Cancel download?", std::move(opener), {"cancel", "confirm-destructive"}, 0, true};
diff --git a/src/installs/install_service.cpp b/src/installs/install_service.cpp
index e1a95f8..d3b4167 100644
--- a/src/installs/install_service.cpp
+++ b/src/installs/install_service.cpp
@@ -399,7 +399,8 @@ void InstallService::Scan() {
// delete: the folder it names is the game's.
if (job.view.from_volume_id == job.view.volume_id) return;
// A destination that isn't there can't show whether the title already names the copy: the move stays
- // locked until the drive is back and the job has run again.
+ // locked until the drive is back and the job has run again, or until the caller has checked the title
+ // (ReleaseUnreachableMove).
const auto* to = FindVolume(entry.move_to);
job.view.locked = entry.volume_id == entry.move_to || !to || !to->available ||
Exists(RootOn(entry.move_to, entry.id) + "/" + kMoveSwitchName);
@@ -889,6 +890,22 @@ void InstallService::MoveQueued(GameId id, bool up) {
}
}
+void InstallService::ReleaseUnreachableMove(GameId id, const std::string& title_folder) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ auto* job = Find(id);
+ if (!job || job->dropped || job->view.kind != InstallJobKind::kMove || !job->view.locked ||
+ job->view.state != InstallJobState::kFailed)
+ return;
+ const auto* to = FindVolume(job->view.volume_id);
+ if (to && to->available) return;
+ // Still listed where it came from, its folder there: only then does the game play from it.
+ const auto game = std::find_if(installed_.begin(), installed_.end(), [id](const InstalledGame& entry) { return entry.id == id; });
+ if (game == installed_.end() || game->volume_id != job->view.from_volume_id || !game->available) return;
+ if (!title_folder.empty() && title_folder != game->root) return;
+ job->view.locked = false;
+ Publish();
+}
+
void InstallService::Cancel(GameId id) {
std::lock_guard<std::mutex> lock(mutex_);
auto* job = Find(id);
diff --git a/src/installs/install_service.h b/src/installs/install_service.h
index 0f1dc43..c2a0540 100644
--- a/src/installs/install_service.h
+++ b/src/installs/install_service.h
@@ -296,6 +296,12 @@ class InstallService {
// Swaps with the previous/next queued download, preserving the running download.
void MoveQueued(GameId id, bool up);
void Cancel(GameId id);
+ // A failed move whose destination isn't connected stays locked: its copy's switch marker can't be read, so
+ // the game's PS5 title may name the copy. The caller has read the title's record: `title_folder` is the game
+ // folder it starts, empty when the title names no folder yet, with no relocation, republish or recovery
+ // pending. When that is the folder the game is listed in on the move's source, the move unlocks
+ // and can be canceled (its partial copy stays on the drive that isn't there). Otherwise nothing changes.
+ void ReleaseUnreachableMove(GameId id, const std::string& title_folder);
void Uninstall(GameId id);
// Uninstalls whose files could not be deleted since the last call.
std::vector<RemovalFailure> TakeRemovalFailures();
diff --git a/tests/game_move_test.cpp b/tests/game_move_test.cpp
index 519c4e2..dcde38a 100644
--- a/tests/game_move_test.cpp
+++ b/tests/game_move_test.cpp
@@ -703,18 +703,51 @@ void AMovedGamePlaysWithoutItsOldDrive() {
CHECK(f.Installed()->volume_id == "internal" && fs::exists(f.internal / "730/data/level1.pak"));
}
-void AMoveToAnAbsentDriveStaysLocked() {
+void AMoveToAnAbsentDriveCanBeCanceledOnceItsTitleIsChecked() {
Fixture f;
- // The title may already name the copy on the USB drive, which isn't there to show its switch marker.
+ // Playden stopped part way through a move to the USB drive, which isn't there at the next start. The copy's
+ // switch marker can't be read, so the move fails locked: the title might name the copy.
+ {
+ std::atomic<bool> cancel{false};
+ f.options.checkpoint = [](MoveCheckpoint point) { return point != MoveCheckpoint::kCopied; };
+ f.CopyUntil(cancel);
+ f.options.checkpoint = nullptr;
+ }
f.RegistryMoving();
f.usb_available = false;
f.Start();
CHECK(f.WaitFor([&] { const auto job = f.Job(); return job && job->state == InstallJobState::kFailed; }));
CHECK(f.Job()->locked && f.service->Locked(kGame));
+ CHECK(f.Job()->failure == "The game's storage is not available.");
+ f.service->Cancel(kGame);
+ CHECK(f.Job() && f.Job()->kind == InstallJobKind::kMove);
+ // A title that names the copy keeps it locked.
+ f.service->ReleaseUnreachableMove(kGame, (f.usb / "730").string());
+ CHECK(f.Job()->locked);
+ // One that names the game's folder on console storage lets it go: Cancel drops the move.
+ f.service->ReleaseUnreachableMove(kGame, (f.internal / "730").string());
+ CHECK(!f.Job()->locked && !f.service->Locked(kGame));
+ f.service->Cancel(kGame);
+ CHECK(f.WaitFor([&] { return !f.Job(); }));
+ CHECK(f.Installed()->volume_id == "internal" && fs::exists(f.internal / "730/data/level1.pak"));
+ CHECK(Read(f.internal / ".playden-games").find("move=") == std::string::npos);
+ // The copy on the drive that was away is left as it was; the next start doesn't bring the move back.
+ f.usb_available = true;
+ f.Restart();
+ CHECK(!f.Job() && f.Installed()->volume_id == "internal" && fs::exists(f.usb / "730/data/level1.pak"));
+}
+
+void AMoveToAnAbsentDriveCarriesOnWhenItIsBack() {
+ Fixture f;
+ f.RegistryMoving();
+ f.usb_available = false;
+ f.Start();
+ CHECK(f.WaitFor([&] { const auto job = f.Job(); return job && job->state == InstallJobState::kFailed; }));
+ CHECK(f.Job()->locked && f.Installed()->volume_id == "internal");
f.service->Cancel(kGame);
f.service->Pause(kGame);
CHECK(f.Job() && f.Job()->kind == InstallJobKind::kMove);
- // With the drive back it can be canceled again, or resumed.
+ // With the drive back the move can be resumed, and finishes.
f.usb_available = true;
f.Restart();
CHECK(f.Job() && !f.Job()->locked);
@@ -722,6 +755,24 @@ void AMoveToAnAbsentDriveStaysLocked() {
f.CheckMoved();
}
+void AMoveWhoseCopyIsMarkedStaysLocked() {
+ Fixture f;
+ // The switch marker on a connected destination: the title may name the copy, so the move only finishes.
+ {
+ std::atomic<bool> cancel{false};
+ f.options.checkpoint = [](MoveCheckpoint point) { return point != MoveCheckpoint::kSwitchMarked; };
+ f.CopyUntil(cancel);
+ f.options.checkpoint = nullptr;
+ }
+ CHECK(fs::exists(f.usb / "730" / kMoveSwitchName));
+ f.RegistryMoving();
+ f.gate = ApplyAnswer::kGameRunning;
+ f.Start();
+ CHECK(f.WaitFor([&] { const auto job = f.Job(); return job && job->locked; }));
+ f.service->Cancel(kGame);
+ CHECK(f.Job() && f.Job()->kind == InstallJobKind::kMove);
+}
+
void AMovedGameIsNotANewDownload() {
Fixture f;
// Installed long ago: Completed doesn't list it, and the copy's newer record doesn't make it list it.
@@ -787,7 +838,9 @@ int main() {
AMovedGameKeepsItsInstallTime();
CancelWhileTheGateIsAskedDropsTheMove();
AMovedGamePlaysWithoutItsOldDrive();
- AMoveToAnAbsentDriveStaysLocked();
+ AMoveToAnAbsentDriveCanBeCanceledOnceItsTitleIsChecked();
+ AMoveToAnAbsentDriveCarriesOnWhenItIsBack();
+ AMoveWhoseCopyIsMarkedStaysLocked();
std::puts("game_move tests passed");
return 0;
}
diff --git a/tests/homebrew_library_model_test.cpp b/tests/homebrew_library_model_test.cpp
index a83b608..beecd59 100644
--- a/tests/homebrew_library_model_test.cpp
+++ b/tests/homebrew_library_model_test.cpp
@@ -2590,6 +2590,29 @@ void live_move_job_actions_say_move() {
"move job: Cancel says the copy goes and the game stays");
activate(model, "cancel");
activate(model, "cancel");
+ // A failed move to a drive that isn't connected: Cancel says its part copy stays there.
+ model.UpdateVolumes({{"internal", "Console storage", true, 2'000'000'000, 1'000'000'000},
+ {"usb", "USB Drive", false, 2'000'000'000, 1'000'000'000}}, "internal");
+ job.state = JobState::Failed;
+ model.UpdateInstalls({job}, {{SteamId(42), 100, "internal", true}});
+ activate(model, "job-42");
+ activate(model, "job-cancel-42");
+ check(model.state().navigation.modals.back().body ==
+ "USB Drive isn't connected, so the part copied there stays. The game stays on Console storage.",
+ "move job: Cancel to a disconnected drive says the copy stays there");
+ activate(model, "cancel");
+ activate(model, "cancel");
+ // A drive that isn't listed at all starts the sentence with a capital.
+ model.UpdateVolumes({{"internal", "Console storage", true, 2'000'000'000, 1'000'000'000}}, "internal");
+ activate(model, "job-42");
+ activate(model, "job-cancel-42");
+ check(model.state().navigation.modals.back().body ==
+ "The other drive isn't connected, so the part copied there stays. The game stays on Console storage.",
+ "move job: an unlisted drive is named in a full sentence");
+ activate(model, "cancel");
+ activate(model, "cancel");
+ model.UpdateVolumes({{"internal", "Console storage", true, 2'000'000'000, 1'000'000'000},
+ {"usb", "USB Drive", true, 2'000'000'000, 1'000'000'000}}, "internal");
job.state = JobState::Paused;
model.UpdateInstalls({job}, {{SteamId(42), 100, "internal", true}});
activate(model, "job-42");