From d00eff7137c28286e1ebc3cca68ba7ab8b1ddf3f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 6 Oct 2019 12:40:00 -0700 Subject: [PATCH] UI: Allow pinning remote ISO paths. --- UI/MainScreen.cpp | 36 +++++++++++++++--------------------- UI/MainScreen.h | 26 +++++++++++++++++++++++--- UI/RemoteISOScreen.cpp | 36 +++++++++++++++++------------------- UI/RemoteISOScreen.h | 4 +++- ext/native/file/path.cpp | 2 ++ 5 files changed, 60 insertions(+), 44 deletions(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 364e552f9d..bc2884a3c0 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -365,11 +365,6 @@ void GameButton::Draw(UIContext &dc) { dc.RebindTexture(); } -enum GameBrowserFlags { - FLAG_HOMEBREWSTOREBUTTON = 1 -}; - - class DirButton : public UI::Button { public: DirButton(const std::string &path, UI::LayoutParams *layoutParams) @@ -440,8 +435,8 @@ void DirButton::Draw(UIContext &dc) { } } -GameBrowser::GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle, std::string lastText, std::string lastLink, int flags, UI::LayoutParams *layoutParams) - : LinearLayout(UI::ORIENT_VERTICAL, layoutParams), path_(path), gridStyle_(gridStyle), allowBrowsing_(allowBrowsing), lastText_(lastText), lastLink_(lastLink), flags_(flags) { +GameBrowser::GameBrowser(std::string path, BrowseFlags browseFlags, bool *gridStyle, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams) + : LinearLayout(UI::ORIENT_VERTICAL, layoutParams), path_(path), gridStyle_(gridStyle), browseFlags_(browseFlags), lastText_(lastText), lastLink_(lastLink) { using namespace UI; Refresh(); } @@ -530,7 +525,7 @@ void GameBrowser::Refresh() { // No topbar on recent screen if (DisplayTopBar()) { LinearLayout *topBar = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); - if (allowBrowsing_) { + if (browseFlags_ & BrowseFlags::NAVIGATE) { topBar->Add(new Spacer(2.0f)); topBar->Add(new TextView(path_.GetFriendlyPath().c_str(), ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f))); if (System_GetPropertyBool(SYSPROP_HAS_FILE_BROWSER)) { @@ -585,7 +580,7 @@ void GameBrowser::Refresh() { isSaveData = true; if (!isGame && !isSaveData) { - if (allowBrowsing_) { + if (browseFlags_ & BrowseFlags::NAVIGATE) { dirButtons.push_back(new DirButton(fileInfo[i].fullName, fileInfo[i].name, new UI::LinearLayoutParams(UI::FILL_PARENT, UI::FILL_PARENT))); } } else { @@ -595,7 +590,7 @@ void GameBrowser::Refresh() { // Put RAR/ZIP files at the end to get them out of the way. They're only shown so that people // can click them and get an explanation that they need to unpack them. This is necessary due // to a flood of support email... - if (allowBrowsing_) { + if (browseFlags_ & BrowseFlags::ARCHIVES) { fileInfo.clear(); path_.GetListing(fileInfo, "zip:rar:r01:7z:"); if (!fileInfo.empty()) { @@ -613,7 +608,7 @@ void GameBrowser::Refresh() { } } - if (allowBrowsing_) { + if (browseFlags_ & BrowseFlags::NAVIGATE) { gameList_->Add(new DirButton("..", new UI::LinearLayoutParams(UI::FILL_PARENT, UI::FILL_PARENT)))-> OnClick.Handle(this, &GameBrowser::NavigateClick); @@ -645,7 +640,7 @@ void GameBrowser::Refresh() { } // Show a button to toggle pinning at the very end. - if (allowBrowsing_) { + if (browseFlags_ & BrowseFlags::PIN) { std::string caption = IsCurrentPathPinned() ? "-" : "+"; if (!*gridStyle_) { caption = IsCurrentPathPinned() ? mm->T("UnpinPath", "Unpin") : mm->T("PinPath", "Pin"); @@ -654,7 +649,7 @@ void GameBrowser::Refresh() { OnClick.Handle(this, &GameBrowser::PinToggleClick); } - if (flags_ & FLAG_HOMEBREWSTOREBUTTON) { + if (browseFlags_ & BrowseFlags::HOMEBREW_STORE) { Add(new Spacer()); homebrewStoreButton_ = Add(new Choice(mm->T("DownloadFromStore", "Download from the PPSSPP Homebrew Store"), new UI::LinearLayoutParams(UI::WRAP_CONTENT, UI::WRAP_CONTENT))); } else { @@ -801,7 +796,7 @@ void MainScreen::CreateViews() { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollRecentGames->SetTag("MainScreenRecentGames"); GameBrowser *tabRecentGames = new GameBrowser( - "!RECENT", false, &g_Config.bGridView1, "", "", 0, + "!RECENT", BrowseFlags::NONE, &g_Config.bGridView1, "", "", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); scrollRecentGames->Add(tabRecentGames); gameBrowsers_.push_back(tabRecentGames); @@ -819,12 +814,11 @@ void MainScreen::CreateViews() { ScrollView *scrollHomebrew = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollHomebrew->SetTag("MainScreenHomebrew"); - GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2, - mm->T("How to get games"), "https://www.ppsspp.org/getgames.html", 0, + GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, BrowseFlags::STANDARD, &g_Config.bGridView2, + mm->T("How to get games"), "https://www.ppsspp.org/getgames.html", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); - GameBrowser *tabHomebrew = new GameBrowser(GetSysDirectory(DIRECTORY_GAME), false, &g_Config.bGridView3, + GameBrowser *tabHomebrew = new GameBrowser(GetSysDirectory(DIRECTORY_GAME), BrowseFlags::HOMEBREW_STORE, &g_Config.bGridView3, mm->T("How to get homebrew & demos", "How to get homebrew && demos"), "https://www.ppsspp.org/gethomebrew.html", - FLAG_HOMEBREWSTOREBUTTON, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); Choice *hbStore = tabHomebrew->HomebrewStoreButton(); @@ -1274,7 +1268,7 @@ void UmdReplaceScreen::CreateViews() { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollRecentGames->SetTag("UmdReplaceRecentGames"); GameBrowser *tabRecentGames = new GameBrowser( - "!RECENT", false, &g_Config.bGridView1, "", "", 0, + "!RECENT", BrowseFlags::NONE, &g_Config.bGridView1, "", "", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); scrollRecentGames->Add(tabRecentGames); leftColumn->AddTab(mm->T("Recent"), scrollRecentGames); @@ -1284,8 +1278,8 @@ void UmdReplaceScreen::CreateViews() { ScrollView *scrollAllGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollAllGames->SetTag("UmdReplaceAllGames"); - GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2, - mm->T("How to get games"), "https://www.ppsspp.org/getgames.html", 0, + GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, BrowseFlags::STANDARD, &g_Config.bGridView2, + mm->T("How to get games"), "https://www.ppsspp.org/getgames.html", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); scrollAllGames->Add(tabAllGames); diff --git a/UI/MainScreen.h b/UI/MainScreen.h index 199c379187..eb15bd0f22 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -24,9 +24,30 @@ #include "ui/viewgroup.h" #include "UI/MiscScreens.h" +enum GameBrowserFlags { + FLAG_HOMEBREWSTOREBUTTON = 1 +}; + +enum class BrowseFlags { + NONE = 0, + NAVIGATE = 1, + ARCHIVES = 2, + PIN = 4, + HOMEBREW_STORE = 8, + STANDARD = 1 | 2 | 4, +}; + +static inline BrowseFlags operator |(const BrowseFlags &lhs, const BrowseFlags &rhs) { + return BrowseFlags((int)lhs | (int)rhs); +} + +static inline bool operator &(const BrowseFlags &lhs, const BrowseFlags &rhs) { + return ((int)lhs & (int)rhs) != 0; +} + class GameBrowser : public UI::LinearLayout { public: - GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle, std::string lastText, std::string lastLink, int flags = 0, UI::LayoutParams *layoutParams = nullptr); + GameBrowser(std::string path, BrowseFlags browseFlags, bool *gridStyle, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = nullptr); UI::Event OnChoice; UI::Event OnHoldChoice; @@ -62,10 +83,9 @@ private: UI::ViewGroup *gameList_ = nullptr; PathBrowser path_; bool *gridStyle_; - bool allowBrowsing_; + BrowseFlags browseFlags_; std::string lastText_; std::string lastLink_; - int flags_; UI::Choice *homebrewStoreButton_ = nullptr; std::string focusGamePath_; bool listingPending_ = false; diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index f853e49e22..396d9bfa36 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -147,13 +147,8 @@ static bool FindServer(std::string &resultHost, int &resultPort) { return false; } -static bool LoadGameList(const std::string &host, int port, std::vector &games) { - std::string subdir = RemoteSubdir(); - - char temp[1024]; - snprintf(temp, sizeof(temp) - 1, "http://%s:%d%s", host.c_str(), port, subdir.c_str()); - - PathBrowser browser(temp); +static bool LoadGameList(const std::string &url, std::vector &games) { + PathBrowser browser(url); std::vector files; browser.GetListing(files, "iso:cso:pbp:elf:prx:ppdmp:", &scanCancelled); if (scanCancelled) { @@ -165,12 +160,6 @@ static bool LoadGameList(const std::string &host, int port, std::vectorpush(new RemoteISOBrowseScreen(games_)); + screenManager()->push(new RemoteISOBrowseScreen(url_, games_)); break; } } @@ -373,19 +362,26 @@ ScanStatus RemoteISOConnectScreen::GetStatus() { } void RemoteISOConnectScreen::ExecuteLoad() { - bool result = LoadGameList(host_, port_, games_); + std::string subdir = RemoteSubdir(); + url_ = StringFromFormat("http://%s:%d%s", host_.c_str(), port_, subdir.c_str()); + bool result = LoadGameList(url_, games_); if (scanAborted) { return; } + if (result && !games_.empty() && !g_Config.bRemoteISOManual) { + g_Config.sLastRemoteISOServer = host_; + g_Config.iLastRemoteISOPort = port_; + } + std::lock_guard guard(statusLock_); status_ = result ? ScanStatus::LOADED : ScanStatus::FAILED; } class RemoteGameBrowser : public GameBrowser { public: - RemoteGameBrowser(const std::vector &games, bool allowBrowsing, bool *gridStyle_, std::string lastText, std::string lastLink, int flags = 0, UI::LayoutParams *layoutParams = 0) - : GameBrowser("!REMOTE", allowBrowsing, gridStyle_, lastText, lastLink, flags, layoutParams) { + RemoteGameBrowser(const std::string &url, const std::vector &games, BrowseFlags browseFlags, bool *gridStyle_, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = nullptr) + : GameBrowser(url, browseFlags, gridStyle_, lastText, lastLink, layoutParams) { games_ = games; Refresh(); } @@ -397,6 +393,7 @@ protected: bool HasSpecialFiles(std::vector &filenames) override; + std::string url_; std::vector games_; }; @@ -405,7 +402,8 @@ bool RemoteGameBrowser::HasSpecialFiles(std::vector &filenames) { return true; } -RemoteISOBrowseScreen::RemoteISOBrowseScreen(const std::vector &games) : games_(games) { +RemoteISOBrowseScreen::RemoteISOBrowseScreen(const std::string &url, const std::vector &games) + : url_(url), games_(games) { } void RemoteISOBrowseScreen::CreateViews() { @@ -426,7 +424,7 @@ void RemoteISOBrowseScreen::CreateViews() { ScrollView *scrollRecentGames = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)); scrollRecentGames->SetTag("RemoteGamesTab"); RemoteGameBrowser *tabRemoteGames = new RemoteGameBrowser( - games_, false, &g_Config.bGridView1, "", "", 0, + url_, games_, BrowseFlags::PIN, &g_Config.bGridView1, "", "", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); scrollRecentGames->Add(tabRemoteGames); gameBrowsers_.push_back(tabRemoteGames); diff --git a/UI/RemoteISOScreen.h b/UI/RemoteISOScreen.h index b7f7ff0f5c..06f7889a1c 100644 --- a/UI/RemoteISOScreen.h +++ b/UI/RemoteISOScreen.h @@ -72,16 +72,18 @@ protected: std::mutex statusLock_; std::string host_; int port_; + std::string url_; std::vector games_; }; class RemoteISOBrowseScreen : public MainScreen { public: - RemoteISOBrowseScreen(const std::vector &games); + RemoteISOBrowseScreen(const std::string &url, const std::vector &games); protected: void CreateViews() override; + std::string url_; std::vector games_; }; diff --git a/ext/native/file/path.cpp b/ext/native/file/path.cpp index d37eba5a76..ec62c179b5 100644 --- a/ext/native/file/path.cpp +++ b/ext/native/file/path.cpp @@ -66,6 +66,8 @@ bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector