Skip to content

Commit

Permalink
Implement update support, fixes on lang support, add simplified Chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Sep 7, 2023
1 parent 1c9b0d0 commit f1749f7
Show file tree
Hide file tree
Showing 21 changed files with 590 additions and 53 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ uloader:
umenu: pu
@$(MAKE) -C projects/uMenu
@mkdir -p SdOut/ulaunch/bin/uMenu
@mkdir -p SdOut/ulaunch/lang/uMenu
@cp projects/uMenu/uMenu.nso SdOut/ulaunch/bin/uMenu/main
@cp projects/uMenu/uMenu.npdm SdOut/ulaunch/bin/uMenu/main.npdm
@build_romfs projects/uMenu/romfs SdOut/ulaunch/bin/uMenu/romfs.bin

umanager: pu
@$(MAKE) -C projects/uManager
@mkdir -p SdOut/ulaunch/lang/uManager
@mkdir -p SdOut/switch
@cp projects/uManager/uManager.nro SdOut/switch/uManager.nro

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Table of contents

- Browse the Internet (via the normally hidden web-applet) directly from the main menu!

- Toggle between uLaunch and the original HOME menu (no permanent removal) using our `uManager` homebrew tool!
- Toggle between uLaunch and the original HOME menu (no permanent removal) and/or easily update uLaunch using our `uManager` homebrew tool!

- Stream the screen via USB (although at low speeds, about ~9 FPS) via `uScreen`! (can be useful for taking quick screenshots, specially since uLaunch is able to capture more than SysDVR or usual game capture)

Expand Down
12 changes: 8 additions & 4 deletions libs/uCommon/include/ul/cfg/cfg_Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,15 @@ namespace ul::cfg {
std::vector<Theme> LoadThemes();
std::string GetAssetByTheme(const Theme &base, const std::string &resource_base);

inline std::string GetLanguageJSONPath(const std::string &lang) {
return fs::JoinPath(LanguagesPath, lang + ".json");
}
void LoadLanguageJsons(const std::string &lang_base, util::JSON &lang, util::JSON &def);

std::string GetLanguageString(const util::JSON &lang, const util::JSON &def, const std::string &name);
inline std::string GetLanguageString(const util::JSON &lang, const util::JSON &def, const std::string &name) {
auto str = lang.value(name, "");
if(str.empty()) {
str = def.value(name, "");
}
return str;
}

Config CreateNewAndLoadConfig();
Config LoadConfig();
Expand Down
8 changes: 5 additions & 3 deletions libs/uCommon/include/ul/ul_Include.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
namespace ul {

constexpr const char DefaultThemePath[] = "romfs:/default";
constexpr const char DefaultLanguagePath[] = "romfs:/en.json";
constexpr const char DefaultLanguagePath[] = "romfs:/lang";
constexpr const char DefaultLanguage[] = "en-US";

constexpr const char RootPath[] = "sdmc:/ulaunch";

Expand All @@ -18,14 +19,15 @@ namespace ul {
constexpr const char ThemesPath[] = "sdmc:/ulaunch/themes";

constexpr const char MenuPath[] = "sdmc:/ulaunch/menu";

constexpr const char LanguagesPath[] = "sdmc:/ulaunch/lang";
constexpr const char MenuLanguagesPath[] = "sdmc:/ulaunch/lang/uMenu";

constexpr const char RootCachePath[] = "sdmc:/ulaunch/cache";
constexpr const char ApplicationCachePath[] = "sdmc:/ulaunch/cache/app";
constexpr const char HomebrewCachePath[] = "sdmc:/ulaunch/cache/hb";
constexpr const char AccountCachePath[] = "sdmc:/ulaunch/cache/acc";

constexpr const char ManagerLanguagesPath[] = "sdmc:/ulaunch/lang/uManager";

constexpr const char OldMenuPath[] = "sdmc:/ulaunch/entries";
constexpr const char OldApplicationCachePath[] = "sdmc:/ulaunch/titles";
constexpr const char OldHomebrewCachePath[] = "sdmc:/ulaunch/nro";
Expand Down
18 changes: 13 additions & 5 deletions libs/uCommon/source/ul/cfg/cfg_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ namespace ul::cfg {
return "";
}

std::string GetLanguageString(const util::JSON &lang, const util::JSON &def, const std::string &name) {
auto str = lang.value(name, "");
if(str.empty()) {
str = def.value(name, "");
void LoadLanguageJsons(const std::string &lang_base, util::JSON &lang, util::JSON &def) {
const auto default_lang_file_path = fs::JoinPath(DefaultLanguagePath, DefaultLanguage) + ".json";
UL_RC_ASSERT(ul::util::LoadJSONFromFile(def, default_lang_file_path));

u64 lang_code = 0;
UL_RC_ASSERT(setGetLanguageCode(&lang_code));

const auto ext_lang_path = fs::JoinPath(lang_base, reinterpret_cast<char*>(&lang_code)) + ".json";
if(R_FAILED(util::LoadJSONFromFile(lang, ext_lang_path))) {
const auto lang_path = fs::JoinPath(DefaultLanguagePath, reinterpret_cast<char*>(&lang_code)) + ".json";
if(R_FAILED(util::LoadJSONFromFile(lang, lang_path))) {
lang = def;
}
}
return str;
}

Config CreateNewAndLoadConfig() {
Expand Down
34 changes: 17 additions & 17 deletions libs/uCommon/source/ul/menu/menu_Entries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,9 @@ namespace ul::menu {
void InitializeRemainingEntries(const std::vector<NsApplicationRecord> &remaining_apps) {
const std::vector<std::string> DefaultHomebrewRecordPaths = { HbmenuPath, ManagerPath };

// Reserve for all remaining apps + special homebrews
const auto index_gap = UINT32_MAX / (remaining_apps.size() + DefaultHomebrewRecordPaths.size());

// Add remaining app entries
// Reserve for special homebrews + all remaining apps
const auto index_gap = UINT32_MAX / (DefaultHomebrewRecordPaths.size() + remaining_apps.size());
u32 cur_start_idx = 0;
for(const auto &app_record : remaining_apps) {
Entry app_entry = {
.type = EntryType::Application,
.entry_path = MakeEntryPath(MenuPath, cur_start_idx + index_gap / 2),

.app_info = {
.app_id = app_record.application_id,
.record = app_record
}
};
app_entry.Save();
cur_start_idx += index_gap;
}

// Add special homebrew entries
for(const auto &nro_path : DefaultHomebrewRecordPaths) {
Expand All @@ -143,6 +128,21 @@ namespace ul::menu {
hb_entry.Save();
cur_start_idx += index_gap;
}

// Add remaining app entries
for(const auto &app_record : remaining_apps) {
Entry app_entry = {
.type = EntryType::Application,
.entry_path = MakeEntryPath(MenuPath, cur_start_idx + index_gap / 2),

.app_info = {
.app_id = app_record.application_id,
.record = app_record
}
};
app_entry.Save();
cur_start_idx += index_gap;
}
}

void ConvertOldMenu() {
Expand Down
4 changes: 2 additions & 2 deletions projects/uManager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BUILD := build
SOURCES := source source/ul source/ul/man source/ul/man/ui
INCLUDES := include
DATA := data
# ROMFS := romfs
ROMFS := romfs

VER_MAJOR := 1
VER_MINOR := 0
Expand Down Expand Up @@ -71,7 +71,7 @@ LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*
LIBUCOMMON := $(CURDIR)/../../libs/uCommon
LIBPU := $(CURDIR)/../../libs/Plutonium/Plutonium

LIBS := -lnx -lpu -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -lc -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs`
LIBS := -lpu -lzzip -lcurl -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -lc -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -luCommon -lnx

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
40 changes: 40 additions & 0 deletions projects/uManager/include/ul/man/man_Manager.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#pragma once
#include <ul/ul_Include.hpp>

namespace ul::man {

Expand All @@ -12,4 +13,43 @@ namespace ul::man {
void ActivateSystem();
void DeactivateSystem();

struct Version {
u32 major;
u32 minor;
s32 micro;

std::string AsString() const;

static inline constexpr Version MakeVersion(const u32 major, const u32 minor, const u32 micro) {
return { major, minor, static_cast<s32>(micro) };
}

static Version FromString(const std::string &ver_str);

inline constexpr bool IsLower(const Version &other) const {
if(this->major > other.major) {
return true;
}
else if(this->major == other.major) {
if(this->minor > other.minor) {
return true;
}
else if(this->minor == other.minor) {
if(this->micro > other.micro) {
return true;
}
}
}
return false;
}

inline constexpr bool IsHigher(const Version &other) const {
return !this->IsLower(other) && !this->IsEqual(other);
}

inline constexpr bool IsEqual(const Version &other) const {
return ((this->major == other.major) && (this->minor == other.minor) && (this->micro == other.micro));
}
};

}
16 changes: 16 additions & 0 deletions projects/uManager/include/ul/man/man_Network.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#pragma once
#include <ul/ul_Include.hpp>
#include <functional>

namespace ul::man {

constexpr const char TemporaryReleaseZipPath[] = "sdmc:/ulaunch_tmp.zip";

using RetrieveOnProgressCallback = std::function<void(const double now_downloaded, const double total_to_download)>;

std::string RetrieveContent(const std::string &url, const std::string &mime_type = "");
void RetrieveToFile(const std::string &url, const std::string &path, RetrieveOnProgressCallback on_progress_cb);
bool HasConnection();

}
10 changes: 9 additions & 1 deletion projects/uManager/include/ul/man/ui/ui_MainMenuLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ namespace ul::man::ui {
static constexpr u32 MenuItemCount = 6;

private:
pu::ui::elm::Menu::Ref options_menu;
pu::ui::elm::TextBlock::Ref info_text;

pu::ui::elm::Menu::Ref options_menu;
pu::ui::elm::MenuItem::Ref activate_menu_item;
pu::ui::elm::MenuItem::Ref update_menu_item;

inline void ResetInfoText() {
this->info_text->SetText("uManager v" UL_VERSION " - uLaunch's manager");
}

public:
MainMenuLayout();
PU_SMART_CTOR(MainMenuLayout)

void activate_DefaultKey();
void update_DefaultKey();
};

}
24 changes: 24 additions & 0 deletions projects/uManager/romfs/lang/en-US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"yes": "Yes",
"cancel": "Cancel",
"ok": "Ok",
"reboot": "Reboot",
"status": "Status",
"status_active": "active",
"status_not_active": "not active",
"status_not_present": "not present",
"update_item": "Check for updates",
"activate_changes_title": "Changes",
"activate_changes": "The (de)activation of uLaunch needs a reboot for changes to take effect.",
"activate_continue": "Continue",
"activate_not_present": "uLaunch was not found in the SD card.",
"update_title": "Update check",
"update_error": "Unable to retrieve last update information...",
"update_version": "Last release",
"update_conf": "Would you like to update to the last release?",
"update_equal": "uLaunch is already on the latest release.",
"update_higher": "uLaunch seems to be in a newer version than the latest release...",
"update_success": "uLaunch was successfully updated, now the system must reboot for the update to apply.",
"update_progress_download": "Downloading update...",
"update_progress_install": "Installing update..."
}
3 changes: 3 additions & 0 deletions projects/uManager/source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <ul/man/ui/ui_MainApplication.hpp>
#include <ul/ul_Result.hpp>

ul::man::ui::MainApplication::Ref g_MainApplication;

int main() {
ul::InitializeLogging("uManager");

auto renderer_opts = pu::ui::render::RendererInitOptions(SDL_INIT_EVERYTHING, pu::ui::render::RendererHardwareFlags);
renderer_opts.UseImage(pu::ui::render::IMGAllFlags);
renderer_opts.UseTTF();
Expand Down
42 changes: 42 additions & 0 deletions projects/uManager/source/ul/man/man_Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,46 @@ namespace ul::man {
fsdevDeleteDirectoryRecursively(ActiveSystemPath);
}

std::string Version::AsString() const {
auto as_str = std::to_string(this->major) + "." + std::to_string(this->minor);
if(this->micro > 0) {
as_str += "." + std::to_string(this->micro);
}
return as_str;
}

Version Version::FromString(const std::string &ver_str) {
auto ver_str_cpy = ver_str;
Version v = {};
size_t pos = 0;
std::string token;
u32 c = 0;
std::string delimiter = ".";
while((pos = ver_str_cpy.find(delimiter)) != std::string::npos) {
token = ver_str_cpy.substr(0, pos);
if(c == 0) {
v.major = std::stoi(token);
}
else if(c == 1) {
v.minor = std::stoi(token);
}
else if(c == 2) {
v.micro = std::stoi(token);
}
ver_str_cpy.erase(0, pos + delimiter.length());
c++;
}

if(c == 0) {
v.major = std::stoi(ver_str_cpy);
}
else if(c == 1) {
v.minor = std::stoi(ver_str_cpy);
}
else if(c == 2) {
v.micro = std::stoi(ver_str_cpy);
}
return v;
}

}
Loading

0 comments on commit f1749f7

Please sign in to comment.