refactor: phase 0 & 1

This commit is contained in:
2026-04-26 20:02:15 +03:00
parent 844093e3e7
commit b5c506cf03
36 changed files with 690 additions and 137 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
#endif
#include <protocol.hpp>
#include <TransferState.hpp>
#include <transfer_state.hpp>
namespace fs = std::filesystem;
using path = fs::path;
+3 -3
View File
@@ -116,7 +116,7 @@ Result io::copyDirectory(const std::string& srcPath, const std::string& dstPath)
Result io::createDirectory(const std::string& path)
{
mkdir(path.c_str(), 777);
mkdir(path.c_str(), 0777);
return 0;
}
@@ -228,8 +228,8 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, AccountUid uid,
Logger::getInstance().log(Logger::INFO, "Started restore of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(), title.id(),
title.userId().uid[1], title.userId().uid[0]);
// Если сейв ещё не существует (игра не запускалась) — создаём его через NACP.
// fsCreateSaveDataFileSystem возвращает ошибку если сейв уже есть — это нормально.
// If save data does not yet exist (game was never launched), create it via NACP.
// fsCreateSaveDataFileSystem returns an error if the save already exists — this is expected.
{
NsApplicationControlData* nsacd = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
if (nsacd != NULL) {
+64
View File
@@ -0,0 +1,64 @@
#include <logger.hpp>
#include <cstdarg>
#include <cstdio>
#include <ctime>
#include <mutex>
namespace {
std::mutex g_log_mutex;
#if defined(__SWITCH__)
constexpr const char* kLogPath = "/switch/NXST/log.log";
#else
constexpr const char* kLogPath = "nxst.log";
#endif
void writeEntry(const char* tag, const char* fmt, va_list args)
{
char msg[2048];
vsnprintf(msg, sizeof(msg), fmt, args);
time_t now = time(nullptr);
struct tm tm_buf;
localtime_r(&now, &tm_buf);
char time_str[16];
strftime(time_str, sizeof(time_str), "%H:%M:%S", &tm_buf);
std::lock_guard<std::mutex> lock(g_log_mutex);
fprintf(stderr, "[%s]%s %s\n", time_str, tag, msg);
FILE* log_file = fopen(kLogPath, "a");
if (log_file != nullptr) {
fprintf(log_file, "[%s]%s %s\n", time_str, tag, msg);
fclose(log_file);
}
}
} // namespace
namespace nxst::log {
void write(Level level, const char* fmt, ...)
{
const char* tag = "[INFO] ";
switch (level) {
case Level::Debug: tag = "[DEBUG]"; break;
case Level::Info: tag = "[INFO] "; break;
case Level::Warn: tag = "[WARN] "; break;
case Level::Error: tag = "[ERROR]"; break;
}
va_list args;
va_start(args, fmt);
writeEntry(tag, fmt, args);
va_end(args);
}
void debug(const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[DEBUG]", fmt, args); va_end(args); }
void info (const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[INFO] ", fmt, args); va_end(args); }
void warn (const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[WARN] ", fmt, args); va_end(args); }
void error(const char* fmt, ...) { va_list args; va_start(args, fmt); writeEntry("[ERROR]", fmt, args); va_end(args); }
} // namespace nxst::log
+1 -1
View File
@@ -1,4 +1,4 @@
#include <MainApplication.hpp>
#include <main_application.hpp>
#include "util.hpp"
#include "main.hpp"
#include <server.hpp>
@@ -2,7 +2,7 @@
#include <switch.h>
#include <switch/services/hid.h>
#include <vector>
#include <MainApplication.hpp>
#include <main_application.hpp>
namespace ui {
MainApplication *mainApp;
+2 -2
View File
@@ -19,8 +19,8 @@
#endif
#include <protocol.hpp>
#include <TransferState.hpp>
#include <net/Socket.hpp>
#include <transfer_state.hpp>
#include <net/socket.hpp>
static TransferState g_server_state;
static std::atomic<int> g_server_client_sock{-1};
@@ -1,10 +1,10 @@
#include <MainApplication.hpp>
#include <main_application.hpp>
#include <stdio.h>
#include <main.hpp>
#include <const.h>
#include <client.hpp>
#include <server.hpp>
#include <TransferOverlay.hpp>
#include <transfer_overlay.hpp>
namespace ui {
extern MainApplication *mainApp;
@@ -1,5 +1,5 @@
#include <cstdio>
#include <MainApplication.hpp>
#include <main_application.hpp>
#include "main.hpp"
namespace ui {
+1 -11
View File
@@ -26,7 +26,7 @@
#include "util.hpp"
#include <logger.hpp>
#include <MainApplication.hpp>
#include <main_application.hpp>
#include "main.hpp"
void servicesExit(void)
@@ -47,16 +47,6 @@ Result servicesInit(void)
Logger::getInstance().log(Logger::WARN, "Please do not run NXST in applet mode.");
}
// Result socinit = 0;
// if ((socinit = socketInitializeDefault()) == 0) {
// nxlinkStdio();
// }
// else {
// Logger::getInstance().log(Logger::INFO, "Unable to initialize socket. Result code 0x%08lX.", socinit);
// }
// g_shouldExitNetworkLoop = R_FAILED(socinit);
Result res = 0;
romfsInit();