Skip to content

Commit

Permalink
Code fixes, finish Japanese and Portuguese support
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Jun 7, 2021
1 parent 8ceb04f commit 4c05592
Show file tree
Hide file tree
Showing 24 changed files with 246 additions and 156 deletions.
9 changes: 2 additions & 7 deletions Goldleaf/Include/Types.hpp
Expand Up @@ -80,20 +80,15 @@ enum class LaunchMode {
Application
};

enum class Storage {
GameCart = 2,
NANDSystem,
NANDUser,
SdCard,
};

enum class Language {
English,
Spanish,
German,
French,
Italian,
Dutch,
Japanese,
Portuguese
};

std::string LanguageToString(Language lang);
Expand Down
3 changes: 2 additions & 1 deletion Goldleaf/Include/cfg/cfg_Settings.hpp
Expand Up @@ -44,7 +44,8 @@ namespace cfg {
std::vector<WebBookmark> bookmarks;

void Save();
std::string PathForResource(const std::string &path);
std::string PathForResource(const std::string &res_path);
JSON ReadJSONResource(const std::string &res_path);
void ApplyScrollBarColor(pu::ui::elm::Menu::Ref &menu);
void ApplyProgressBarColor(pu::ui::elm::ProgressBar::Ref &p_bar);
};
Expand Down
7 changes: 7 additions & 0 deletions Goldleaf/Include/fs/fs_Explorer.hpp
Expand Up @@ -118,6 +118,13 @@ namespace fs {
void CopyDirectoryProgress(String dir, String new_dir, std::function<void(double Done, double Total)> cb_fn);
bool IsFileBinary(String path);
std::vector<u8> ReadFile(String path);
JSON ReadJSON(String path);

inline void WriteJSON(const JSON &json, String path) {
const auto json_str = json.dump(4);
this->WriteFile(path, json_str.c_str(), json_str.length());
}

std::vector<String> ReadFileLines(String path, u32 line_offset, u32 line_count);
std::vector<String> ReadFileFormatHex(String path, u32 line_offset, u32 line_count);
u64 GetDirectorySize(String path);
Expand Down
9 changes: 5 additions & 4 deletions Goldleaf/Include/hos/hos_Titles.hpp
Expand Up @@ -58,7 +58,7 @@ namespace hos {
struct ContentId {
NcmContentType type;
NcmContentId id;
Storage location;
NcmStorageId storage_id;
bool is_empty;
u64 size;

Expand Down Expand Up @@ -88,7 +88,7 @@ namespace hos {
NcmContentMetaType type;
u32 version;
NcmContentMetaKey meta_key;
Storage location;
NcmStorageId storage_id;

NacpStruct TryGetNACP() const;
u8 *TryGetIcon() const;
Expand Down Expand Up @@ -162,12 +162,13 @@ namespace hos {
constexpr u32 MaxTitleCount = 64000;

std::string FormatApplicationId(u64 app_id);
std::vector<Title> SearchTitles(NcmContentMetaType type, Storage location);
std::vector<Title> SearchTitles(NcmContentMetaType type, NcmStorageId storage_id);
Title Locate(u64 app_id);
bool ExistsTitle(NcmContentMetaType type, Storage Location, u64 app_id);
bool ExistsTitle(NcmContentMetaType type, NcmStorageId storage_id, u64 app_id);
std::vector<Ticket> GetAllTickets();
Result RemoveTitle(const Title &title);
Result RemoveTicket(const Ticket &tik);
Result UpdateTitleVersion(const Title &title);
std::string GetExportedIconPath(u64 app_id);
String GetExportedNACPPath(u64 app_id);

Expand Down
2 changes: 1 addition & 1 deletion Goldleaf/Include/nsp/nsp_Installer.hpp
Expand Up @@ -51,7 +51,7 @@ namespace nsp {
String icon;

public:
Installer(String path, fs::Explorer *exp, Storage location) : pfs0_file(exp, path), storage_id(static_cast<NcmStorageId>(location)) {}
Installer(String path, fs::Explorer *exp, NcmStorageId st_id) : pfs0_file(exp, path), storage_id(st_id) {}
~Installer();

Result PrepareInstallation();
Expand Down
2 changes: 1 addition & 1 deletion Goldleaf/Include/ui/ui_InstallLayout.hpp
Expand Up @@ -32,7 +32,7 @@ namespace ui {
InstallLayout();
PU_SMART_CTOR(InstallLayout)

void StartInstall(String path, fs::Explorer *exp, Storage location, bool omit_confirmation = false);
void StartInstall(String path, fs::Explorer *exp, NcmStorageId storage_id, bool omit_confirmation = false);
};

}
2 changes: 1 addition & 1 deletion Goldleaf/Include/ui/ui_StorageContentsLayout.hpp
Expand Up @@ -34,7 +34,7 @@ namespace ui {
PU_SMART_CTOR(StorageContentsLayout)

void contents_Click();
void LoadFromStorage(Storage location);
void LoadFromStorage(NcmStorageId storage_id);

inline std::vector<hos::Title> &GetContents() {
return this->contents;
Expand Down
11 changes: 11 additions & 0 deletions Goldleaf/Source/Types.cpp
Expand Up @@ -54,6 +54,12 @@ std::string LanguageToString(Language lang) {
case Language::Dutch: {
return "nl";
}
case Language::Japanese: {
return "ja";
}
case Language::Portuguese: {
return "pt";
}
case Language::English:
default: {
return "en";
Expand All @@ -77,6 +83,9 @@ Language StringToLanguage(std::string str) {
else if(str == "nl") {
return Language::Dutch;
}
else if(str == "ja") {
return Language::Japanese;
}
else {
return Language::English;
}
Expand Down Expand Up @@ -182,6 +191,7 @@ Result Initialize() {

R_TRY(accountInitialize(AccountServiceType_Administrator));
R_TRY(ncmInitialize());
R_TRY(avmInitialize());
R_TRY(nsInitialize());
R_TRY(es::Initialize());
R_TRY(psmInitialize());
Expand Down Expand Up @@ -233,6 +243,7 @@ void Exit(Result rc) {
es::Exit();
nsExit();
accountExit();
avmExit();
ncmExit();
nifmExit();
pdmqryExit();
Expand Down
181 changes: 100 additions & 81 deletions Goldleaf/Source/cfg/cfg_Settings.cpp
Expand Up @@ -71,23 +71,37 @@ namespace cfg {
json["web"]["bookmarks"][i]["name"] = bmk.name;
json["web"]["bookmarks"][i]["url"] = bmk.url;
}

auto sd_exp = fs::GetSdCardExplorer();
sd_exp->DeleteFile(consts::Settings);

const auto settings_data = json.dump(4);
sd_exp->WriteFile(consts::Settings, settings_data.c_str(), settings_data.length());
sd_exp->WriteJSON(json, consts::Settings);
}

std::string Settings::PathForResource(const std::string &Path) {
auto outres = "romfs:" + Path;
std::string Settings::PathForResource(const std::string &res_path) {
auto sd_exp = fs::GetSdCardExplorer();
auto romfs_exp = fs::GetRomFsExplorer();

if(this->has_external_romfs) {
const auto &tmpres = this->external_romfs + "/" + Path;
const auto &ext_path = this->external_romfs + "/" + res_path;
auto sd_exp = fs::GetSdCardExplorer();
if(sd_exp->IsFile(tmpres)) {
outres = tmpres;
if(sd_exp->IsFile(ext_path)) {
return ext_path;
}
}
return romfs_exp->MakeAbsolute(res_path).AsUTF8();
}

JSON Settings::ReadJSONResource(const std::string &res_path) {
auto sd_exp = fs::GetSdCardExplorer();
auto romfs_exp = fs::GetRomFsExplorer();

if(this->has_external_romfs) {
const auto &ext_path = this->external_romfs + "/" + res_path;
if(sd_exp->IsFile(ext_path)) {
return sd_exp->ReadJSON(ext_path);
}
}
return outres;
return romfs_exp->ReadJSON(romfs_exp->MakeAbsolute(res_path));
}

void Settings::ApplyScrollBarColor(pu::ui::elm::Menu::Ref &menu) {
Expand Down Expand Up @@ -138,6 +152,15 @@ namespace cfg {
settings.custom_lang = Language::Dutch;
break;
}
case SetLanguage_JA: {
settings.custom_lang = Language::Japanese;
break;
}
case SetLanguage_PT:
case SetLanguage_PTBR: {
settings.custom_lang = Language::Portuguese;
break;
}
default: {
settings.custom_lang = Language::English;
break;
Expand All @@ -156,87 +179,83 @@ namespace cfg {

settings.custom_scheme = ui::GenerateRandomScheme();

// TODO: read with sdexp?
std::ifstream ifs("sdmc:/" + consts::Settings);
if(ifs.good()) {
const auto &settings_json = JSON::parse(ifs);
if(settings_json.count("general")) {
const auto &lang = settings_json["general"].value("customLanguage", "");
if(!lang.empty()) {
auto clang = StringToLanguage(lang);
settings.has_custom_lang = true;
settings.custom_lang = clang;
}
auto sd_exp = fs::GetSdCardExplorer();
const auto &settings_json = sd_exp->ReadJSON(consts::Settings);
if(settings_json.count("general")) {
const auto &lang = settings_json["general"].value("customLanguage", "");
if(!lang.empty()) {
auto clang = StringToLanguage(lang);
settings.has_custom_lang = true;
settings.custom_lang = clang;
}

const auto &extrom = settings_json["general"].value("externalRomFs", "");
if(!extrom.empty()) {
settings.has_external_romfs = true;
if(extrom.substr(0, 6) == "sdmc:/") {
settings.external_romfs = extrom;
}
else {
settings.external_romfs = "sdmc:";
if(extrom[0] != '/') {
settings.external_romfs += "/";
}
settings.external_romfs += extrom;
const auto &extrom = settings_json["general"].value("externalRomFs", "");
if(!extrom.empty()) {
settings.has_external_romfs = true;
if(extrom.substr(0, 6) == "sdmc:/") {
settings.external_romfs = extrom;
}
else {
settings.external_romfs = "sdmc:";
if(extrom[0] != '/') {
settings.external_romfs += "/";
}
settings.external_romfs += extrom;
}
}
}

if(settings_json.count("ui")) {
const auto itemsize = settings_json["ui"].value("menuItemSize", 0);
if(itemsize > 0) {
settings.has_menu_item_size = true;
settings.menu_item_size = itemsize;
}
const auto &background_clr = settings_json["ui"].value("background", "");
if(!background_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.Background = pu::ui::Color::FromHex(background_clr);
}
const auto &base_clr = settings_json["ui"].value("base", "");
if(!base_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.Base = pu::ui::Color::FromHex(base_clr);
}
const auto &base_focus_clr = settings_json["ui"].value("baseFocus", "");
if(!base_focus_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.BaseFocus = pu::ui::Color::FromHex(base_focus_clr);
}
const auto &text_clr = settings_json["ui"].value("text", "");
if(!text_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.Text = pu::ui::Color::FromHex(text_clr);
}
const auto &scrollbar_clr = settings_json["ui"].value("scrollBar", "");
if(!scrollbar_clr.empty()) {
settings.has_scrollbar_color = true;
settings.scrollbar_color = pu::ui::Color::FromHex(scrollbar_clr);
}
const auto &pbar_clr = settings_json["ui"].value("progressBar", "");
if(!pbar_clr.empty()) {
settings.has_progressbar_color = true;
settings.progressbar_color = pu::ui::Color::FromHex(pbar_clr);
}
if(settings_json.count("ui")) {
const auto itemsize = settings_json["ui"].value("menuItemSize", 0);
if(itemsize > 0) {
settings.has_menu_item_size = true;
settings.menu_item_size = itemsize;
}
const auto &background_clr = settings_json["ui"].value("background", "");
if(!background_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.Background = pu::ui::Color::FromHex(background_clr);
}
const auto &base_clr = settings_json["ui"].value("base", "");
if(!base_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.Base = pu::ui::Color::FromHex(base_clr);
}
const auto &base_focus_clr = settings_json["ui"].value("baseFocus", "");
if(!base_focus_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.BaseFocus = pu::ui::Color::FromHex(base_focus_clr);
}
const auto &text_clr = settings_json["ui"].value("text", "");
if(!text_clr.empty()) {
settings.has_custom_scheme = true;
settings.custom_scheme.Text = pu::ui::Color::FromHex(text_clr);
}
if(settings_json.count("installs")) {
settings.ignore_required_fw_ver = settings_json["installs"].value("ignoreRequiredFwVersion", true);
}
if(settings_json.count("web")) {
if(settings_json["web"].count("bookmarks")) {
for(u32 i = 0; i < settings_json["web"]["bookmarks"].size(); i++) {
WebBookmark bmk = {};
bmk.name = settings_json["web"]["bookmarks"][i].value("name", "");
bmk.url = settings_json["web"]["bookmarks"][i].value("url", "");
if(!bmk.url.empty() && !bmk.name.empty()) {
settings.bookmarks.push_back(bmk);
}
const auto &scrollbar_clr = settings_json["ui"].value("scrollBar", "");
if(!scrollbar_clr.empty()) {
settings.has_scrollbar_color = true;
settings.scrollbar_color = pu::ui::Color::FromHex(scrollbar_clr);
}
const auto &pbar_clr = settings_json["ui"].value("progressBar", "");
if(!pbar_clr.empty()) {
settings.has_progressbar_color = true;
settings.progressbar_color = pu::ui::Color::FromHex(pbar_clr);
}
}
if(settings_json.count("installs")) {
settings.ignore_required_fw_ver = settings_json["installs"].value("ignoreRequiredFwVersion", true);
}
if(settings_json.count("web")) {
if(settings_json["web"].count("bookmarks")) {
for(u32 i = 0; i < settings_json["web"]["bookmarks"].size(); i++) {
WebBookmark bmk = {};
bmk.name = settings_json["web"]["bookmarks"][i].value("name", "");
bmk.url = settings_json["web"]["bookmarks"][i].value("url", "");
if(!bmk.url.empty() && !bmk.name.empty()) {
settings.bookmarks.push_back(bmk);
}
}
}
ifs.close();
}
return settings;
}
Expand Down
8 changes: 1 addition & 7 deletions Goldleaf/Source/cfg/cfg_Strings.cpp
Expand Up @@ -41,15 +41,9 @@ namespace cfg {
return this->json[idx].get<std::string>();
}

// TODO: load with sdexp?

#define _CFG_PROCESS_STRINGS(strs, json_name) { \
strings::strs.language = g_Settings.custom_lang; \
std::ifstream ifs(g_Settings.PathForResource(std::string("/Strings/") + #strs + "/" + json_name)); \
if(ifs.good()) { \
try { strings::strs.json = JSON::parse(ifs); } catch(std::exception&) {} \
ifs.close(); \
} \
strings::strs.json = g_Settings.ReadJSONResource(std::string("/Strings/") + #strs + "/" + json_name); \
}

void LoadStrings() {
Expand Down

0 comments on commit 4c05592

Please sign in to comment.