finish refactor, add docs and CI
CI / Build NRO (push) Failing after 3s
CI / Format check (push) Successful in 34s
CI / Layering check (push) Successful in 1s

This commit is contained in:
2026-04-27 01:49:41 +03:00
parent dc65a4c8a9
commit b4ab3e6463
47 changed files with 1964 additions and 1470 deletions
+20 -21
View File
@@ -28,31 +28,31 @@
#include <map>
#include <string.h>
#include <string>
#include <switch.h>
#include <vector>
#include <switch.h>
#define USER_ICON_SIZE 64
namespace std {
template <>
struct hash<AccountUid> {
size_t operator()(const AccountUid& a) const { return ((hash<u64>()(a.uid[0]) ^ (hash<u64>()(a.uid[1]) << 1)) >> 1); }
};
}
template <> struct hash<AccountUid> {
size_t operator()(const AccountUid& a) const {
return ((hash<u64>()(a.uid[0]) ^ (hash<u64>()(a.uid[1]) << 1)) >> 1);
}
};
} // namespace std
inline bool operator==(const AccountUid& x, const AccountUid& y)
{
inline bool operator==(const AccountUid& x, const AccountUid& y) {
return x.uid[0] == y.uid[0] && x.uid[1] == y.uid[1];
}
inline bool operator==(const AccountUid& x, u64 y)
{
inline bool operator==(const AccountUid& x, u64 y) {
return x.uid[0] == y && x.uid[1] == y;
}
inline bool operator<(const AccountUid& x, const AccountUid& y)
{
if (x.uid[0] != y.uid[0]) return x.uid[0] < y.uid[0];
inline bool operator<(const AccountUid& x, const AccountUid& y) {
if (x.uid[0] != y.uid[0])
return x.uid[0] < y.uid[0];
return x.uid[1] < y.uid[1];
}
@@ -62,12 +62,11 @@ struct User {
};
namespace Account {
Result init(void);
void exit(void);
std::vector<AccountUid> ids(void);
AccountUid selectAccount(void);
std::string username(AccountUid id);
std::string iconPath(AccountUid id);
}
Result init(void);
void exit(void);
std::vector<AccountUid> ids(void);
AccountUid selectAccount(void);
std::string username(AccountUid id);
std::string iconPath(AccountUid id);
} // namespace Account
+13 -14
View File
@@ -42,21 +42,20 @@
#define ATEXIT(func) atexit((void (*)())func)
namespace DateTime {
std::string timeStr(void);
std::string dateTimeStr(void);
std::string logDateTime(void);
}
std::string timeStr(void);
std::string dateTimeStr(void);
std::string logDateTime(void);
} // namespace DateTime
namespace StringUtils {
bool containsInvalidChar(const std::string& str);
std::string escapeJson(const std::string& s);
std::string format(const std::string fmt_str, ...);
std::string removeForbiddenCharacters(std::string src);
std::string UTF16toUTF8(const std::u16string& src);
void ltrim(std::string& s);
void rtrim(std::string& s);
void trim(std::string& s);
}
bool containsInvalidChar(const std::string& str);
std::string escapeJson(const std::string& s);
std::string format(const std::string fmt_str, ...);
std::string removeForbiddenCharacters(std::string src);
std::string UTF16toUTF8(const std::u16string& src);
void ltrim(std::string& s);
void rtrim(std::string& s);
void trim(std::string& s);
} // namespace StringUtils
char* getConsoleIP(void);
+12 -12
View File
@@ -2,16 +2,16 @@
#include <cstdint>
namespace proto {
constexpr uint16_t TCP_PORT = 8080;
constexpr uint16_t MULTICAST_PORT = 8081;
constexpr char MULTICAST_GROUP[] = "239.0.0.1";
constexpr size_t BUF_SIZE = 65536;
constexpr uint32_t MAX_FILENAME = 4096;
constexpr uint32_t EOF_SENTINEL = 0;
constexpr uint16_t TCP_PORT = 8080;
constexpr uint16_t MULTICAST_PORT = 8081;
constexpr char MULTICAST_GROUP[] = "239.0.0.1";
constexpr size_t BUF_SIZE = 65536;
constexpr uint32_t MAX_FILENAME = 4096;
constexpr uint32_t EOF_SENTINEL = 0;
// Wire layout per file:
// [filename_len : uint32_t LE] — 0 == end-of-stream
// [filename : filename_len bytes]
// [file_size : uint64_t LE]
// [file_data : file_size bytes]
}
// Wire layout per file:
// [filename_len : uint32_t LE] — 0 == end-of-stream
// [filename : filename_len bytes]
// [file_size : uint64_t LE]
// [file_data : file_size bytes]
} // namespace proto
+45 -22
View File
@@ -4,14 +4,13 @@
namespace nxst {
template <class T, class E = std::string>
class Result {
template <class T, class E = std::string> class Result {
bool ok;
alignas(T) alignas(E) unsigned char storage[sizeof(T) > sizeof(E) ? sizeof(T) : sizeof(E)];
Result() = default;
public:
public:
static Result success(T val) {
Result res;
res.ok = true;
@@ -27,37 +26,52 @@ public:
}
~Result() {
if (ok) reinterpret_cast<T*>(storage)->~T();
else reinterpret_cast<E*>(storage)->~E();
if (ok)
reinterpret_cast<T*>(storage)->~T();
else
reinterpret_cast<E*>(storage)->~E();
}
Result(const Result& other) : ok(other.ok) {
if (ok) new (storage) T(*reinterpret_cast<const T*>(other.storage));
else new (storage) E(*reinterpret_cast<const E*>(other.storage));
if (ok)
new (storage) T(*reinterpret_cast<const T*>(other.storage));
else
new (storage) E(*reinterpret_cast<const E*>(other.storage));
}
Result(Result&& other) : ok(other.ok) {
if (ok) new (storage) T(std::move(*reinterpret_cast<T*>(other.storage)));
else new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
if (ok)
new (storage) T(std::move(*reinterpret_cast<T*>(other.storage)));
else
new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
}
Result& operator=(const Result&) = delete;
bool isOk() const noexcept { return ok; }
const T& value() const { return *reinterpret_cast<const T*>(storage); }
const E& error() const { return *reinterpret_cast<const E*>(storage); }
bool isOk() const noexcept {
return ok;
}
const T& value() const {
return *reinterpret_cast<const T*>(storage);
}
const E& error() const {
return *reinterpret_cast<const E*>(storage);
}
};
// Specialisation for Result<void>
template <class E>
class Result<void, E> {
template <class E> class Result<void, E> {
bool ok;
alignas(E) unsigned char storage[sizeof(E)];
Result() = default;
public:
static Result success() { Result res; res.ok = true; return res; }
public:
static Result success() {
Result res;
res.ok = true;
return res;
}
static Result failure(E err) {
Result res;
@@ -66,20 +80,29 @@ public:
return res;
}
~Result() { if (!ok) reinterpret_cast<E*>(storage)->~E(); }
~Result() {
if (!ok)
reinterpret_cast<E*>(storage)->~E();
}
Result(const Result& other) : ok(other.ok) {
if (!ok) new (storage) E(*reinterpret_cast<const E*>(other.storage));
if (!ok)
new (storage) E(*reinterpret_cast<const E*>(other.storage));
}
Result(Result&& other) : ok(other.ok) {
if (!ok) new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
if (!ok)
new (storage) E(std::move(*reinterpret_cast<E*>(other.storage)));
}
Result& operator=(const Result&) = delete;
bool isOk() const noexcept { return ok; }
const E& error() const { return *reinterpret_cast<const E*>(storage); }
bool isOk() const noexcept {
return ok;
}
const E& error() const {
return *reinterpret_cast<const E*>(storage);
}
};
} // namespace nxst
} // namespace nxst
+10 -8
View File
@@ -25,20 +25,23 @@
*/
#pragma once
#include <nxst/domain/account.hpp>
#include <nxst/infra/fs/filesystem.hpp>
#include <nxst/infra/fs/io.hpp>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <switch.h>
#include <unordered_map>
#include <utility>
#include <vector>
#include <switch.h>
#include <nxst/domain/account.hpp>
#include <nxst/infra/fs/filesystem.hpp>
#include <nxst/infra/fs/io.hpp>
class Title {
public:
void init(u8 saveDataType, u64 titleid, AccountUid userID, const std::string& name, const std::string& author);
public:
void init(u8 saveDataType, u64 titleid, AccountUid userID, const std::string& name,
const std::string& author);
~Title() = default;
std::string author(void);
@@ -60,7 +63,7 @@ public:
AccountUid userId(void);
std::string userName(void);
private:
private:
u64 mId;
u64 mSaveId;
AccountUid mUserId;
@@ -85,4 +88,3 @@ void sortTitles(void);
void rotateSortMode(void);
void refreshDirectories(u64 id);
std::unordered_map<std::string, std::string> getCompleteTitleList(void);
+9 -9
View File
@@ -4,22 +4,22 @@
#include <string>
struct TransferState {
std::atomic<bool> done{false};
std::atomic<bool> cancelled{false};
std::atomic<bool> connection_failed{false};
std::atomic<bool> done{false};
std::atomic<bool> cancelled{false};
std::atomic<bool> connection_failed{false};
std::atomic<uint64_t> bytes_done{0};
std::atomic<uint64_t> bytes_total{0};
std::string status;
std::string fail_reason;
std::string status;
std::string fail_reason;
mutable std::mutex status_mutex;
void reset() {
done = false;
cancelled = false;
done = false;
cancelled = false;
connection_failed = false;
bytes_done = 0;
bytes_total = 0;
bytes_done = 0;
bytes_total = 0;
fail_reason.clear();
std::lock_guard<std::mutex> lock(status_mutex);
status.clear();
+9 -9
View File
@@ -25,11 +25,13 @@
*/
#pragma once
#include <sys/stat.h>
#include <switch.h>
#include <nxst/domain/account.hpp>
#include <nxst/domain/common.hpp>
#include <nxst/infra/fs/io.hpp>
#include <switch.h>
#include <sys/stat.h>
// debug
#include <arpa/inet.h>
@@ -42,10 +44,8 @@ HidsysNotificationLedPattern blinkLedPattern(u8 times);
void blinkLed(u8 times);
namespace StringUtils {
std::string removeAccents(std::string str);
std::string removeNotAscii(std::string str);
std::u16string UTF8toUTF16(const char* src);
std::string elide(const std::string& s, size_t maxChars);
}
std::string removeAccents(std::string str);
std::string removeNotAscii(std::string str);
std::u16string UTF8toUTF16(const char* src);
std::string elide(const std::string& s, size_t maxChars);
} // namespace StringUtils