Skip to content

Homebrew Store: Minor update adding license and website links #19425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Homebrew Store: Fetch license and website URL. Add buttons to go to w…
…ebsite and look up license info.
  • Loading branch information
hrydgard committed Sep 1, 2024
commit d0ab095b1d61a91452d4619f80d246cd9aad53f6
8 changes: 8 additions & 0 deletions Common/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ std::string IndentString(const std::string &str, const std::string &sep, bool sk
return output.str();
}

std::string_view StripPrefix(std::string_view prefix, std::string_view s) {
if (startsWith(s, prefix)) {
return s.substr(prefix.size(), s.size() - prefix.size());
} else {
return s;
}
}

void SkipSpace(const char **ptr) {
while (**ptr && isspace(**ptr)) {
(*ptr)++;
Expand Down
2 changes: 2 additions & 0 deletions Common/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ std::string StripQuotes(const std::string &s);
std::string_view StripSpaces(std::string_view s);
std::string_view StripQuotes(std::string_view s);

std::string_view StripPrefix(std::string_view prefix, std::string_view s);

// NOTE: str must live at least as long as all uses of output.
void SplitString(std::string_view str, const char delim, std::vector<std::string_view> &output);
// Try to avoid this when possible, in favor of the string_view version.
Expand Down
37 changes: 34 additions & 3 deletions UI/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ void HttpImageFileView::Draw(UIContext &dc) {
}
}



// This is the entry in a list. Does not have install buttons and so on.
class ProductItemView : public UI::StickyChoice {
public:
Expand Down Expand Up @@ -333,6 +331,37 @@ void ProductView::CreateViews() {

float size = entry_.size / (1024.f * 1024.f);
Add(new TextView(StringFromFormat("%s: %.2f %s", st->T_cstr("Size"), size, st->T_cstr("MB"))));

if (!entry_.license.empty()) {
LinearLayout *horiz = Add(new LinearLayout(ORIENT_HORIZONTAL));
horiz->Add(new TextView(StringFromFormat("%s: %s", st->T_cstr("License"), entry_.license.c_str())));
horiz->Add(new Button(st->T("Details")))->OnClick.Add([this](UI::EventParams) {
std::string url = StringFromFormat("https://www.ppsspp.org/docs/reference/homebrew-store-distribution/#%s", entry_.file.c_str());
System_LaunchUrl(LaunchUrlType::BROWSER_URL, url.c_str());
return UI::EVENT_DONE;
});
}
if (!entry_.websiteURL.empty()) {
// Display in a few different ways depending on the URL
size_t slashes = std::count(entry_.websiteURL.begin(), entry_.websiteURL.end(), '/');
std::string buttonText;
if (slashes == 2) {
// Just strip https and show the URL.
std::string_view name = StripPrefix("https://", entry_.websiteURL);
name = StripPrefix("http://", name);
if (name.size() < entry_.websiteURL.size()) {
buttonText = name;
}
}
if (buttonText.empty()) {
// Fall back
buttonText = st->T("Website");
}
Add(new Button(buttonText))->OnClick.Add([this](UI::EventParams) {
System_LaunchUrl(LaunchUrlType::BROWSER_URL, entry_.websiteURL.c_str());
return UI::EVENT_DONE;
});
}
}

void ProductView::Update() {
Expand Down Expand Up @@ -460,11 +489,13 @@ void StoreScreen::ParseListing(const std::string &json) {
e.type = ENTRY_PBPZIP;
e.name = GetTranslatedString(game, "name");
e.description = GetTranslatedString(game, "description", "");
e.author = game.getStringOr("author", "?");
e.author = ReplaceAll(game.getStringOr("author", "?"), "&&", "&"); // Can't remove && in the JSON source data due to old app versions
e.size = game.getInt("size");
e.downloadURL = game.getStringOr("download-url", "");
e.iconURL = game.getStringOr("icon-url", "");
e.contentRating = game.getInt("content-rating", 0);
e.websiteURL = game.getStringOr("website-url", "");
e.license = game.getStringOr("license", "");
#if PPSSPP_PLATFORM(IOS_APP_STORE)
if (e.contentRating >= 100) {
continue;
Expand Down
4 changes: 3 additions & 1 deletion UI/Store.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ struct StoreEntry {
std::string description;
std::string author;
std::string iconURL;
std::string file; // This is the folder name of the installed one too, and hence a "unique-ish" identifier.
std::string file; // This is the folder name of the installed one too, and hence a "unique-ish" identifier. Also used as a-link on the license website, if !license.empty().
std::string category;
std::string downloadURL; // Only set for games that are not hosted on store.ppsspp.org
std::string websiteURL;
std::string license;
bool hidden;
int contentRating; // 100 means to hide it on iOS. No other values defined yet.
u64 size;
Expand Down