UI: Show warning when in a temporary dir.

In case PPSSPP is opened from a compressed folder, or otherwise from a
temporary dir, warn users that the saves won't be permanent.
This commit is contained in:
Unknown W. Brackets committed 2018-06-07 14:14:20 -07:00
1 parent 40c7f5ddfd
commit 640eadb0f7
2 files changed
+70 -5

No files matched your search

+69 -5
View File
@@ -29,6 +29,7 @@
#include "ui/ui_context.h"
#include "ui/view.h"
#include "ui/viewgroup.h"
#include "util/text/utf8.h"
#include "Common/FileUtil.h"
#include "Core/System.h"
@@ -76,6 +77,47 @@
bool MainScreen::showHomebrewTab = false;
static bool IsTempPath(const std::string &str) {
std::string item = str;
const auto testPath = [&](std::string temp) {
#ifdef _WIN32
temp = ReplaceAll(temp, "/", "\\");
if (!temp.empty() && temp[temp.size() - 1] != '\\')
temp += "\\";
#else
if (!temp.empty() && temp[temp.size() - 1] != '/')
temp += "/";
#endif
return startsWith(item, temp);
};
const auto testCPath = [&](const char *temp) {
if (temp && temp[0])
return testPath(temp);
return false;
};
#ifdef _WIN32
// Normalize slashes.
item = ReplaceAll(str, "/", "\\");
wchar_t tempPath[MAX_PATH];
GetTempPath(MAX_PATH, tempPath);
if (testPath(ConvertWStringToUTF8(tempPath)))
return true;
#endif
if (testCPath(getenv("TMPDIR")))
return true;
if (testCPath(getenv("TMP")))
return true;
if (testCPath(getenv("TEMP")))
return true;
return false;
}
class GameButton : public UI::Clickable {
public:
GameButton(const std::string &gamePath, bool gridStyle, UI::LayoutParams *layoutParams = 0)
@@ -743,6 +785,7 @@ void MainScreen::CreateViews() {
bool showRecent = g_Config.iMaxRecent > 0;
bool hasStorageAccess = System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE) == PERMISSION_STATUS_GRANTED;
bool storageIsTemporary = IsTempPath(GetSysDirectory(DIRECTORY_SAVEDATA)) && !confirmedTemporary_;
if (showRecent && !hasStorageAccess) {
showRecent = !g_Config.recentIsos.empty();
}
@@ -762,7 +805,7 @@ void MainScreen::CreateViews() {
tabRecentGames->OnHighlight.Handle(this, &MainScreen::OnGameHighlight);
}
Button *grantStorageButton = nullptr;
Button *focusButton = nullptr;
if (hasStorageAccess) {
ScrollView *scrollAllGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
scrollAllGames->SetTag("MainScreenAllGames");
@@ -810,6 +853,26 @@ void MainScreen::CreateViews() {
backFromStore_ = false;
showHomebrewTab = false;
}
if (storageIsTemporary) {
LinearLayout *buttonHolder = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
buttonHolder->Add(new Spacer(new LinearLayoutParams(1.0f)));
focusButton = new Button(mm->T("SavesAreTemporaryIgnore", "Ignore warning"), new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
focusButton->SetPadding(32, 16);
buttonHolder->Add(focusButton)->OnClick.Add([this](UI::EventParams &e) {
confirmedTemporary_ = true;
RecreateViews();
return UI::EVENT_DONE;
});
buttonHolder->Add(new Spacer(new LinearLayoutParams(1.0f)));
leftColumn->Add(new Spacer(new LinearLayoutParams(0.1f)));
leftColumn->Add(new TextView(mm->T("SavesAreTemporary", "PPSSPP saving in temporary storage"), ALIGN_HCENTER, false));
leftColumn->Add(new TextView(mm->T("SavesAreTemporaryGuidance", "Extract PPSSPP somewhere to save permanently"), ALIGN_HCENTER, false));
leftColumn->Add(new Spacer(10.0f));
leftColumn->Add(buttonHolder);
leftColumn->Add(new Spacer(new LinearLayoutParams(0.1f)));
}
} else {
if (!showRecent) {
leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f));
@@ -820,8 +883,9 @@ void MainScreen::CreateViews() {
LinearLayout *buttonHolder = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
buttonHolder->Add(new Spacer(new LinearLayoutParams(1.0f)));
grantStorageButton = new Button(mm->T("Give PPSSPP permission to access storage"), new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
buttonHolder->Add(grantStorageButton)->OnClick.Handle(this, &MainScreen::OnAllowStorage);
focusButton = new Button(mm->T("Give PPSSPP permission to access storage"), new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT));
focusButton->SetPadding(32, 16);
buttonHolder->Add(focusButton)->OnClick.Handle(this, &MainScreen::OnAllowStorage);
buttonHolder->Add(new Spacer(new LinearLayoutParams(1.0f)));
leftColumn->Add(new Spacer(new LinearLayoutParams(0.1f)));
@@ -880,8 +944,8 @@ void MainScreen::CreateViews() {
root_->Add(rightColumn);
}
if (grantStorageButton) {
root_->SetDefaultFocusView(grantStorageButton);
if (focusButton) {
root_->SetDefaultFocusView(focusButton);
} else if (tabHolder_->GetVisibility() != V_GONE) {
root_->SetDefaultFocusView(tabHolder_);
}