Skip to content

Commit

Permalink
Fix theme sound loading, save severalç logs
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Jul 5, 2024
1 parent 79e42a7 commit c470943
Show file tree
Hide file tree
Showing 23 changed files with 178 additions and 74 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ List of not implemented official HOME menu features:

- Application (game) updates

> Note that a lot of features could be considered in principle (savedata support, title removing, user management, activity log stuff...), but uLaunch's philosophy is to mainly avoid considering this features or, more generally, features already provided by existing homebrews or potentially providable by them. uLaunch is a custom HOME menu, whose aim partially is to be extended with mostly HOME-menu-related features.
## Setup

### Installing uLaunch
Expand Down
Binary file modified docs/udesigner.data
Binary file not shown.
12 changes: 6 additions & 6 deletions docs/udesigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (ENVIRONMENT_IS_NODE) {

// --pre-jses are emitted after the Module integration code, so that they can
// refer to Module (if they choose; they can also define Module)
// include: /tmp/tmp42pgm85q.js
// include: /tmp/tmp1069syv8.js

if (!Module.expectedDataFileDownloads) {
Module.expectedDataFileDownloads = 0;
Expand Down Expand Up @@ -220,21 +220,21 @@ Module['FS_createPath']("/", "assets", true, true);

})();

// end include: /tmp/tmp42pgm85q.js
// include: /tmp/tmp_qkie3hp.js
// end include: /tmp/tmp1069syv8.js
// include: /tmp/tmpoa2hxxve.js

// All the pre-js content up to here must remain later on, we need to run
// it.
if (Module['$ww'] || (typeof ENVIRONMENT_IS_PTHREAD != 'undefined' && ENVIRONMENT_IS_PTHREAD)) Module['preRun'] = [];
var necessaryPreJSTasks = Module['preRun'].slice();
// end include: /tmp/tmp_qkie3hp.js
// include: /tmp/tmp9nqciaoh.js
// end include: /tmp/tmpoa2hxxve.js
// include: /tmp/tmpx50pwn30.js

if (!Module['preRun']) throw 'Module.preRun should exist because file support used it; did a pre-js delete it?';
necessaryPreJSTasks.forEach((task) => {
if (Module['preRun'].indexOf(task) < 0) throw 'All preRun tasks that exist before user pre-js code should remain after; did you replace Module or modify Module.preRun?';
});
// end include: /tmp/tmp9nqciaoh.js
// end include: /tmp/tmpx50pwn30.js


// Sometimes an existing Module object exists with properties
Expand Down
73 changes: 43 additions & 30 deletions libs/uCommon/include/ul/fs/fs_Stdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,65 @@
#include <switch.h>
#include <sys/stat.h>
#include <dirent.h>
#include <cstdio>
#include <string>
#include <ul/util/util_String.hpp>

namespace ul::fs {

template<mode_t Mode>
inline bool ExistsBase(const std::string &path) {
template<typename S, mode_t Mode>
inline bool ExistsBase(const S &path) {
struct stat st;
if(stat(path.c_str(), &st) == 0) {
if(stat(util::GetCString(path), &st) == 0) {
return st.st_mode & Mode;
}
else {
return false;
}
}

inline bool ExistsFile(const std::string &path) {
return ExistsBase<S_IFREG>(path);
template<typename S>
inline bool ExistsFile(const S &path) {
return ExistsBase<S, S_IFREG>(path);
}

inline bool ExistsDirectory(const std::string &path) {
return ExistsBase<S_IFDIR>(path);
template<typename S>
inline bool ExistsDirectory(const S &path) {
return ExistsBase<S, S_IFDIR>(path);
}

inline void CreateDirectory(const std::string &path) {
mkdir(path.c_str(), 777);
template<typename S>
inline void CreateDirectory(const S &path) {
mkdir(util::GetCString(path), 777);
}

inline void CreateFile(const std::string &path) {
fsdevCreateFile(path.c_str(), 0, 0);
template<typename S>
inline void CreateFile(const S &path) {
fsdevCreateFile(util::GetCString(path), 0, 0);
}

inline void DeleteDirectory(const std::string &path) {
fsdevDeleteDirectoryRecursively(path.c_str());
template<typename S>
inline void DeleteDirectory(const S &path) {
fsdevDeleteDirectoryRecursively(util::GetCString(path));
}

inline void DeleteFile(const std::string &path) {
remove(path.c_str());
template<typename S>
inline void DeleteFile(const S &path) {
remove(util::GetCString(path));
}

inline void CleanDirectory(const std::string &path) {
template<typename S>
inline void CleanDirectory(const S &path) {
DeleteDirectory(path);
CreateDirectory(path);
}

inline bool RenameFile(const std::string &old_path, const std::string &new_path) {
return rename(old_path.c_str(), new_path.c_str()) == 0;
template<typename S>
inline bool RenameFile(const S &old_path, const S &new_path) {
return rename(util::GetCString(old_path), util::GetCString(new_path)) == 0;
}

inline bool WriteFile(const std::string &path, const void *data, const size_t size, const bool overwrite) {
auto f = fopen(path.c_str(), overwrite ? "wb" : "ab+");
template<typename S>
inline bool WriteFile(const S &path, const void *data, const size_t size, const bool overwrite) {
auto f = fopen(util::GetCString(path), overwrite ? "wb" : "ab+");
if(f) {
fwrite(data, size, 1, f);
fclose(f);
Expand All @@ -64,8 +72,9 @@ namespace ul::fs {
}
}

inline bool ReadFile(const std::string &path, void *data, const size_t size) {
auto f = fopen(path.c_str(), "rb");
template<typename S>
inline bool ReadFile(const S &path, void *data, const size_t size) {
auto f = fopen(util::GetCString(path), "rb");
if(f) {
const auto ok = fread(data, size, 1, f) == 1;
fclose(f);
Expand All @@ -76,8 +85,9 @@ namespace ul::fs {
}
}

inline bool ReadFileAtOffset(const std::string &path, const size_t offset, void *data, const size_t size) {
auto f = fopen(path.c_str(), "rb");
template<typename S>
inline bool ReadFileAtOffset(const S &path, const size_t offset, void *data, const size_t size) {
auto f = fopen(util::GetCString(path), "rb");
if(f) {
fseek(f, offset, SEEK_SET);
const auto ok = fread(data, size, 1, f) == 1;
Expand All @@ -89,17 +99,19 @@ namespace ul::fs {
}
}

inline size_t GetFileSize(const std::string &path) {
template<typename S>
inline size_t GetFileSize(const S &path) {
struct stat st;
if(stat(path.c_str(), &st) == 0) {
if(stat(util::GetCString(path), &st) == 0) {
return st.st_size;
}
else {
return 0;
}
}

inline bool ReadFileString(const std::string &path, std::string &out) {
template<typename S>
inline bool ReadFileString(const S &path, std::string &out) {
const auto f_size = GetFileSize(path);
if(f_size == 0) {
return false;
Expand All @@ -114,7 +126,8 @@ namespace ul::fs {
return ok;
}

inline bool WriteFileString(const std::string &path, const std::string &str, const bool overwrite) {
template<typename S>
inline bool WriteFileString(const S &path, const std::string &str, const bool overwrite) {
return WriteFile(path, str.c_str(), str.length(), overwrite);
}

Expand Down
4 changes: 3 additions & 1 deletion libs/uCommon/include/ul/smi/smi_Protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ namespace ul::smi {
OpenUserPage,
OpenMiiEdit,
OpenAddUser,
OpenNetConnect
OpenNetConnect,
ReloadThemeCache
};

struct SystemStatus {
Expand All @@ -64,6 +65,7 @@ namespace ul::smi {
char last_menu_fs_path[FS_MAX_PATH];
char last_menu_path[FS_MAX_PATH];
u32 last_menu_index;
bool reload_theme_cache;
};

using CommandFunction = Result(*)(void*, const size_t, const bool);
Expand Down
12 changes: 7 additions & 5 deletions libs/uCommon/include/ul/ul_Result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace ul {

void InitializeLogging(const char *proc_name);
void LogImpl(const LogKind kind, const char *log_fmt, ...);
void NX_NORETURN AbortImpl(const Result rc);

#define UL_LOG_INFO(log_fmt, ...) ::ul::LogImpl(::ul::LogKind::Information, log_fmt, ##__VA_ARGS__)

Expand All @@ -53,23 +54,25 @@ namespace ul {
inline void NX_NORETURN OnAssertionFailed(const Result rc, const char *log_fmt, Args &&...args) {
LogImpl(LogKind::Critical, log_fmt, args...);

svcBreak(0, reinterpret_cast<uintptr_t>(&rc), sizeof(rc));
AbortImpl(rc);
__builtin_unreachable();
}

#define UL_RC_ASSERT(expr) ({ \
#define UL_RC_LOG_ASSERT(log, expr) ({ \
const auto _tmp_rc = ::ul::res::TransformIntoResult(expr); \
if(R_FAILED(_tmp_rc)) { \
const char *mod_name; \
const char *rc_name; \
if(rc::GetResultNameAny(_tmp_rc, mod_name, rc_name)) { \
::ul::OnAssertionFailed(_tmp_rc, #expr " asserted %04d-%04d/0x%X/%s::%s...\n", R_MODULE(_tmp_rc) + 2000, R_DESCRIPTION(_tmp_rc), R_VALUE(_tmp_rc), mod_name, rc_name); \
::ul::OnAssertionFailed(_tmp_rc, log " asserted %04d-%04d/0x%X/%s::%s...\n", R_MODULE(_tmp_rc) + 2000, R_DESCRIPTION(_tmp_rc), R_VALUE(_tmp_rc), mod_name, rc_name); \
} \
else { \
::ul::OnAssertionFailed(_tmp_rc, #expr " asserted %04d-%04d/0x%X...\n", R_MODULE(_tmp_rc) + 2000, R_DESCRIPTION(_tmp_rc), R_VALUE(_tmp_rc)); \
::ul::OnAssertionFailed(_tmp_rc, log " asserted %04d-%04d/0x%X...\n", R_MODULE(_tmp_rc) + 2000, R_DESCRIPTION(_tmp_rc), R_VALUE(_tmp_rc)); \
} \
} \
})

#define UL_RC_ASSERT(expr) UL_RC_LOG_ASSERT(#expr, expr)

#define UL_ASSERT_TRUE(expr) ({ \
const auto _tmp_expr = (expr); \
Expand All @@ -78,5 +81,4 @@ namespace ul {
} \
})


}
10 changes: 10 additions & 0 deletions libs/uCommon/include/ul/util/util_String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

namespace ul::util {

template<typename S>
inline const char *GetCString(const S &s) {
return s;
}

template<>
inline const char *GetCString<std::string>(const std::string &s) {
return s.c_str();
}

inline bool StringEndsWith(const std::string &value, const std::string &ending) {
if(ending.size() > value.size()) {
return false;
Expand Down
5 changes: 1 addition & 4 deletions libs/uCommon/source/ul/cfg/cfg_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ namespace ul::cfg {

const auto entry_path = fs::JoinPath(ActiveThemeCachePath, zip_entry_name(zip_file));
const auto is_dir = zip_entry_isdir(zip_file);
if(is_dir) {
fs::CreateDirectory(entry_path);
}
else {
if(!is_dir) {
void *read_buf;
size_t read_buf_size;
const auto read_size = zip_entry_read(zip_file, &read_buf, &read_buf_size);
Expand Down
48 changes: 46 additions & 2 deletions libs/uCommon/source/ul/ul_Result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
#include <ul/fs/fs_Stdio.hpp>
#include <cstdarg>

extern "C" {

void diagAbortWithResult(Result rc) {
UL_RC_LOG_ASSERT("diagAbortWithResult", rc);
__builtin_unreachable();
}

}

namespace ul {

namespace {
Expand All @@ -26,6 +35,17 @@ namespace ul {
}
}

constexpr auto MaxLogFileCount = 10;

inline void FormatLogPath(char *out_path, const char *proc_name, const u32 log_idx) {
if(log_idx == 0) {
snprintf(out_path, FS_MAX_PATH, "%s/log_%s.log", RootPath, proc_name);
}
else {
snprintf(out_path, FS_MAX_PATH, "%s/log_%s_%d.log", RootPath, proc_name, log_idx);
}
}

}

// Doing this since the process may not even have these initialized (looking at you, uLoader...)
Expand All @@ -52,10 +72,29 @@ namespace ul {
})

void InitializeLogging(const char *proc_name) {
snprintf(g_LogPath, sizeof(g_LogPath), "%s/log_%s.log", RootPath, proc_name);
char tmp_log_path[FS_MAX_PATH] = {};

_UL_DO_WITH_FSDEV({
remove(g_LogPath);
u32 i = MaxLogFileCount - 1;
while(true) {
FormatLogPath(g_LogPath, proc_name, i);
if(fs::ExistsFile(g_LogPath)) {
if(i == MaxLogFileCount - 1) {
fs::DeleteFile(g_LogPath);
}
else {
FormatLogPath(tmp_log_path, proc_name, i + 1);
fs::RenameFile(g_LogPath, tmp_log_path);
}
}

if(i == 0) {
break;
}
i--;
}

// Loop ends with idx 0 formatted, which is what we want
});
}

Expand All @@ -82,4 +121,9 @@ namespace ul {
va_end(args);
}

void AbortImpl(const Result rc) {
svcBreak(BreakReason_Panic, reinterpret_cast<uintptr_t>(&rc), sizeof(rc));
__builtin_unreachable();
}

}
3 changes: 2 additions & 1 deletion projects/uMenu/include/ul/menu/smi/smi_Commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ namespace ul::menu::smi {
);
}

inline Result RestartMenu() {
inline Result RestartMenu(const bool reload_theme_cache) {
return SendCommand(SystemMessage::RestartMenu,
[&](ScopedStorageWriter &writer) {
writer.Push(reload_theme_cache);
return ResultSuccess;
},
[](ScopedStorageReader &reader) {
Expand Down
1 change: 1 addition & 0 deletions projects/uMenu/include/ul/menu/ui/ui_IMenuLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace ul::menu::ui {
void NotifyMessageContext(const smi::MenuMessageContext msg_ctx);
virtual void OnMenuInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const pu::ui::TouchPoint touch_pos) = 0;
virtual bool OnHomeButtonPress() = 0;
virtual void DisposeAudio() = 0;
};

}
2 changes: 1 addition & 1 deletion projects/uMenu/include/ul/menu/ui/ui_MainMenuLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ namespace ul::menu::ui {
public:
MainMenuLayout(const u8 *captured_screen_buf, const u8 min_alpha);
PU_SMART_CTOR(MainMenuLayout)
~MainMenuLayout();

void OnMenuInput(const u64 keys_down, const u64 keys_up, const u64 keys_held, const pu::ui::TouchPoint touch_pos) override;
bool OnHomeButtonPress() override;
void DisposeAudio() override;

void MoveTo(const std::string &new_path, const bool fade, std::function<void()> action = nullptr);

Expand Down
Loading

0 comments on commit c470943

Please sign in to comment.