MemstickScreen: Cleanly cancel instead of blocking the back button if space calculation is underway

This commit is contained in:
Henrik Rydgård committed 2025-05-28 15:27:00 +02:00
1 parent a0ba0d2f7d
commit 6b987fa4ac
7 files changed
+95 -31

No files matched your search

+24 -16
View File
@@ -460,24 +460,36 @@ ConfirmMemstickMoveScreen::ConfirmMemstickMoveScreen(const Path &newMemstickFold
: newMemstickFolder_(newMemstickFolder), initialSetup_(initialSetup), progressReporter_() {
const Path &oldMemstickFolder = g_Config.memStickDirectory;
existingFilesInNewFolder_ = FolderSeemsToBeUsed(newMemstickFolder);
folderConflict_ = newMemstickFolder.StartsWithGlobal(oldMemstickFolder);
if (!oldMemstickFolder.empty()) {
folderConflict_ = newMemstickFolder != oldMemstickFolder && newMemstickFolder.StartsWithGlobalAndNotEqual(oldMemstickFolder);
} else {
folderConflict_ = false;
}
INFO_LOG(Log::System, "Old: '%s'", oldMemstickFolder.c_str());
INFO_LOG(Log::System, "New: '%s'", newMemstickFolder.c_str());
// TODO: If you reinstall the app and start by selecting a subfolder of the PSP folder, we don't detect and warn about that -
// we can only warn if there's a known previous folder :(
if (initialSetup_) {
moveData_ = false;
}
}
ConfirmMemstickMoveScreen::~ConfirmMemstickMoveScreen() {
// We should no longer end up blocking here since the back button is disabled until the tasks are done.
if (moveDataTask_) {
INFO_LOG(Log::System, "Move Data task still running, blocking on it");
moveDataTask_->BlockUntilReady();
delete moveDataTask_;
}
// These we just cancel / leak.
if (oldSpaceTask_) {
oldSpaceTask_->BlockUntilReady();
oldSpaceTask_->Cancel();
delete oldSpaceTask_;
}
if (newSpaceTask_) {
newSpaceTask_->BlockUntilReady();
newSpaceTask_->Cancel();
delete newSpaceTask_;
}
}
@@ -504,11 +516,14 @@ void ConfirmMemstickMoveScreen::CreateViews() {
}
leftColumn->Add(new TextView(newMemstickFolder_.ToVisualString(), ALIGN_LEFT, false));
newFreeSpaceView_ = leftColumn->Add(new TextView(ms->T("Free space"), ALIGN_LEFT, false));
// TODO: Add spinner
newFreeSpaceView_ = leftColumn->Add(new TextView(ApplySafeSubstitutions("%1: ...", ms->T("Free space")), ALIGN_LEFT, false));
newSpaceTask_ = Promise<SpaceResult *>::Spawn(&g_threadManager, [&]() -> SpaceResult * {
Path newMemstickFolder = newMemstickFolder_;
newSpaceTask_ = Promise<SpaceResult *>::Spawn(&g_threadManager, [newMemstickFolder]() -> SpaceResult * {
int64_t freeSpaceNew;
free_disk_space(newMemstickFolder_, freeSpaceNew);
INFO_LOG(Log::System, "Computing free space in %s", newMemstickFolder.c_str());
free_disk_space(newMemstickFolder, freeSpaceNew);
return new SpaceResult{ freeSpaceNew };
}, TaskType::IO_BLOCKING, TaskPriority::HIGH);
@@ -528,15 +543,16 @@ void ConfirmMemstickMoveScreen::CreateViews() {
}
if (!oldMemstickFolder.empty()) {
oldSpaceTask_ = Promise<SpaceResult *>::Spawn(&g_threadManager, [&]() -> SpaceResult * {
oldSpaceTask_ = Promise<SpaceResult *>::Spawn(&g_threadManager, [oldMemstickFolder]() -> SpaceResult * {
int64_t freeSpaceOld;
INFO_LOG(Log::System, "Computing free space in %s", oldMemstickFolder.c_str());
free_disk_space(oldMemstickFolder, freeSpaceOld);
return new SpaceResult{ freeSpaceOld };
}, TaskType::IO_BLOCKING, TaskPriority::HIGH);
rightColumn->Add(new TextView(std::string(ms->T("Current")) + ":", ALIGN_LEFT, false));
rightColumn->Add(new TextView(oldMemstickFolder.ToVisualString(), ALIGN_LEFT, false));
oldFreeSpaceView_ = rightColumn->Add(new TextView(ms->T("Free space"), ALIGN_LEFT, false));
oldFreeSpaceView_ = rightColumn->Add(new TextView(ApplySafeSubstitutions("%1: ...", ms->T("Free space")), ALIGN_LEFT, false));
}
if (moveDataTask_) {
@@ -556,14 +572,6 @@ void ConfirmMemstickMoveScreen::CreateViews() {
if (moveDataTask_ && !moveDataTask_->Poll()) {
return UI::EVENT_DONE;
}
if (newSpaceTask_ && !newSpaceTask_->Poll()) {
// TODO: we should detach/cancel the task somehow instead..
return UI::EVENT_DONE;
}
if (oldSpaceTask_ && !oldSpaceTask_->Poll()) {
// TODO: we should detach/cancel the task somehow instead..
return UI::EVENT_DONE;
}
return UIScreen::OnBack(params);
});
}