Skip to content
Permalink
Browse files

UI: Allow pinning remote ISO paths.

  • Loading branch information...
unknownbrackets committed Oct 6, 2019
1 parent e5eb849 commit d00eff7137c28286e1ebc3cca68ba7ab8b1ddf3f
Showing with 60 additions and 44 deletions.
  1. +15 −21 UI/MainScreen.cpp
  2. +23 −3 UI/MainScreen.h
  3. +17 −19 UI/RemoteISOScreen.cpp
  4. +3 −1 UI/RemoteISOScreen.h
  5. +2 −0 ext/native/file/path.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);
@@ -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 @@ class GameBrowser : public UI::LinearLayout {
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;
@@ -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<std::string> &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<std::string> &games) {
PathBrowser browser(url);
std::vector<FileInfo> 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::vector<std::str
}
}

// Save for next time unless manual is true
if (!games.empty() && !g_Config.bRemoteISOManual) {
g_Config.sLastRemoteISOServer = host;
g_Config.iLastRemoteISOPort = port;
}

return !games.empty();
}

@@ -352,7 +341,7 @@ void RemoteISOConnectScreen::update() {

case ScanStatus::LOADED:
TriggerFinish(DR_OK);
screenManager()->push(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<std::mutex> guard(statusLock_);
status_ = result ? ScanStatus::LOADED : ScanStatus::FAILED;
}

class RemoteGameBrowser : public GameBrowser {
public:
RemoteGameBrowser(const std::vector<std::string> &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<std::string> &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 @@ class RemoteGameBrowser : public GameBrowser {

bool HasSpecialFiles(std::vector<std::string> &filenames) override;

std::string url_;
std::vector<std::string> games_;
};

@@ -405,7 +402,8 @@ bool RemoteGameBrowser::HasSpecialFiles(std::vector<std::string> &filenames) {
return true;
}

RemoteISOBrowseScreen::RemoteISOBrowseScreen(const std::vector<std::string> &games) : games_(games) {
RemoteISOBrowseScreen::RemoteISOBrowseScreen(const std::string &url, const std::vector<std::string> &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);
@@ -72,16 +72,18 @@ class RemoteISOConnectScreen : public UIScreenWithBackground {
std::mutex statusLock_;
std::string host_;
int port_;
std::string url_;
std::vector<std::string> games_;
};

class RemoteISOBrowseScreen : public MainScreen {
public:
RemoteISOBrowseScreen(const std::vector<std::string> &games);
RemoteISOBrowseScreen(const std::string &url, const std::vector<std::string> &games);

protected:
void CreateViews() override;

std::string url_;
std::vector<std::string> games_;
};

@@ -66,6 +66,8 @@ bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector<FileIn
continue;
if (item.back() == '\r')
item.pop_back();
if (item == baseURL.Resource())
continue;

FileInfo info;
info.name = item;

0 comments on commit d00eff7

Please sign in to comment.
You can’t perform that action at this time.