Permalink
Browse files

Merge pull request #11124 from unknownbrackets/temp-warning

Show warning when PPSSPP is saving to a temp directory
  • Loading branch information...
hrydgard committed Jun 16, 2018
2 parents a9eb786 + 640eadb commit c7baed26dbaf8af6e8420064a8b61e6bb8f93b36
Showing with 78 additions and 7 deletions.
  1. +69 −5 UI/MainScreen.cpp
  2. +1 −0 UI/MainScreen.h
  3. +2 −2 ext/native/ui/view.cpp
  4. +6 −0 ext/native/ui/view.h
@@ -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_);
}
@@ -119,6 +119,7 @@ class MainScreen : public UIScreenWithBackground {
bool backFromStore_;
bool lockBackgroundAudio_;
bool lastVertical_;
bool confirmedTemporary_ = false;
friend class RemoteISOBrowseScreen;
};
@@ -733,8 +733,8 @@ void Button::GetContentDimensions(const UIContext &dc, float &w, float &h) const
dc.MeasureText(dc.theme->uiFont, 1.0f, 1.0f, text_.c_str(), &w, &h);
}
// Add some internal padding to not look totally ugly
w += 16;
h += 8;
w += paddingW_;
h += paddingH_;
}
void Button::Draw(UIContext &dc) {
@@ -508,11 +508,17 @@ class Button : public Clickable {
void Draw(UIContext &dc) override;
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
const std::string &GetText() const { return text_; }
void SetPadding(int w, int h) {
paddingW_ = w;
paddingH_ = h;
}
private:
Style style_;
std::string text_;
ImageID imageID_;
int paddingW_ = 16;
int paddingH_ = 8;
};
class Slider : public Clickable {

0 comments on commit c7baed2

Please sign in to comment.