mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2024-11-13 21:27:06 +00:00
Complete logging for the switch version
This commit is contained in:
parent
7457eb7cd4
commit
92e595dd70
8 changed files with 52 additions and 19 deletions
|
@ -37,7 +37,7 @@ CheatManager::CheatManager(void)
|
|||
fclose(in);
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d", errno);
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d.", errno);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -63,7 +63,7 @@ CheatManager::CheatManager(void)
|
|||
fclose(f);
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d", errno);
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d.", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ Result servicesInit(void)
|
|||
|
||||
Handle hbldrHandle;
|
||||
if (R_FAILED(res = svcConnectToPort(&hbldrHandle, "hb:ldr"))) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Error during startup with result %llX. Rosalina not found on this system", res);
|
||||
Logger::getInstance().log(Logger::ERROR, "Error during startup with result %llX. Rosalina not found on this system.", res);
|
||||
return consoleDisplayError("Rosalina not found on this system.\nAn updated CFW is required to launch Checkpoint.", res);
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ Result servicesInit(void)
|
|||
ATEXIT(pxiDevExit);
|
||||
|
||||
if (R_FAILED(res = Archive::init())) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Archive::init failed with result %llX", res);
|
||||
Logger::getInstance().log(Logger::ERROR, "Archive::init failed with result %llX.", res);
|
||||
return consoleDisplayError("Archive::init failed.", res);
|
||||
}
|
||||
ATEXIT(Archive::exit);
|
||||
|
|
|
@ -24,17 +24,17 @@ static FC_Font* getFontFromMap(int size)
|
|||
bool SDLH_Init(void)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
|
||||
Logger::getInstance().log(Logger::ERROR, "SDL_Init: %s\n", SDL_GetError());
|
||||
Logger::getInstance().log(Logger::ERROR, "SDL_Init: %s.", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
s_window = SDL_CreateWindow("Checkpoint", 0, 0, 1280, 720, SDL_WINDOW_FULLSCREEN);
|
||||
if (!s_window) {
|
||||
Logger::getInstance().log(Logger::ERROR, "SDL_CreateWindow: %s\n", SDL_GetError());
|
||||
Logger::getInstance().log(Logger::ERROR, "SDL_CreateWindow: %s.", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
s_renderer = SDL_CreateRenderer(s_window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
if (!s_renderer) {
|
||||
Logger::getInstance().log(Logger::ERROR, "SDL_CreateRenderer: %s\n", SDL_GetError());
|
||||
Logger::getInstance().log(Logger::ERROR, "SDL_CreateRenderer: %s.", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(s_renderer, SDL_BLENDMODE_BLEND);
|
||||
|
@ -42,7 +42,7 @@ bool SDLH_Init(void)
|
|||
|
||||
const int img_flags = IMG_INIT_PNG | IMG_INIT_JPG;
|
||||
if ((IMG_Init(img_flags) & img_flags) != img_flags) {
|
||||
Logger::getInstance().log(Logger::ERROR, "IMG_Init: %s\n", IMG_GetError());
|
||||
Logger::getInstance().log(Logger::ERROR, "IMG_Init: %s.", IMG_GetError());
|
||||
return false;
|
||||
}
|
||||
SDLH_LoadImage(&s_star, "romfs:/star.png");
|
||||
|
|
|
@ -37,7 +37,7 @@ CheatManager::CheatManager(void)
|
|||
fclose(in);
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d", errno);
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d.", errno);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -63,7 +63,7 @@ CheatManager::CheatManager(void)
|
|||
fclose(f);
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d", errno);
|
||||
Logger::getInstance().log(Logger::WARN, "Failed to open " + path + " with errno %d.", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ void CheatManager::save(const std::string& key, const std::vector<std::string>&
|
|||
fclose(f);
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to write " + outPath + " with errno %d", errno);
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to write " + outPath + " with errno %d.", errno);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ static void handle_populate(struct mg_connection* nc, struct http_message* hm)
|
|||
json["title_list"] = map;
|
||||
std::string body = json.dump();
|
||||
mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%.*s", (unsigned long)body.length(), (int)body.length(), body.c_str());
|
||||
Logger::getInstance().log(Logger::INFO, "A new Configuration connection has been handled.");
|
||||
}
|
||||
|
||||
static void handle_save(struct mg_connection* nc, struct http_message* hm)
|
||||
|
@ -49,6 +50,9 @@ static void handle_save(struct mg_connection* nc, struct http_message* hm)
|
|||
if (f != NULL) {
|
||||
fwrite(hm->body.p, 1, hm->body.len, f);
|
||||
fclose(f);
|
||||
Logger::getInstance().log(Logger::INFO, "Configurations have been updated.");
|
||||
} else {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to write to configuration file.");
|
||||
}
|
||||
Configuration::getInstance().load();
|
||||
Configuration::getInstance().parse();
|
||||
|
|
|
@ -36,10 +36,12 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
|
|||
{
|
||||
FILE* src = fopen(srcPath.c_str(), "rb");
|
||||
if (src == NULL) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to open source file " + srcPath + " during copy. Skipping...");
|
||||
return;
|
||||
}
|
||||
FILE* dst = fopen(dstPath.c_str(), "wb");
|
||||
if (dst == NULL) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to open destination file " + dstPath + " during copy. Skipping...");
|
||||
fclose(src);
|
||||
return;
|
||||
}
|
||||
|
@ -62,6 +64,7 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
|
|||
|
||||
// commit each file to the save
|
||||
if (dstPath.rfind("save:/", 0) == 0) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Committing file " + dstPath + " to the save archive.");
|
||||
fsdevCommitDevice("save");
|
||||
}
|
||||
}
|
||||
|
@ -143,16 +146,20 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
|
|||
Title title;
|
||||
getTitle(title, uid, index);
|
||||
|
||||
Logger::getInstance().log(Logger::INFO, "Started backup of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(), title.id(), (u64)(title.userId() >> 8), (u64)(title.userId()));
|
||||
|
||||
FsFileSystem fileSystem;
|
||||
res = FileSystem::mount(&fileSystem, title.id(), title.userId());
|
||||
if (R_SUCCEEDED(res)) {
|
||||
int rc = FileSystem::mount(fileSystem);
|
||||
if (rc == -1) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during backup. Title id: 0x%016lX; User id: 0x%lX%lX.", title.id(), (u64)(title.userId() >> 8), (u64)(title.userId()));
|
||||
return std::make_tuple(false, -2, "Failed to mount save.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during backup with result %X. Title id: 0x%016lX; User id: 0x%lX%lX.", res, title.id(), (u64)(title.userId() >> 8), (u64)(title.userId()));
|
||||
return std::make_tuple(false, res, "Failed to mount save.");
|
||||
}
|
||||
|
||||
|
@ -173,6 +180,7 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
|
|||
}
|
||||
else {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::INFO, "Copy operation aborted by the user through the system keyboard.");
|
||||
return std::make_tuple(false, 0, "Operation aborted by the user.");
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +202,7 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
|
|||
int rc = io::deleteFolderRecursively((dstPath + "/").c_str());
|
||||
if (rc != 0) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to recursively delete directory " + dstPath);
|
||||
return std::make_tuple(false, (Result)rc, "Failed to delete the existing backup\ndirectory recursively.");
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +212,7 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
|
|||
if (R_FAILED(res)) {
|
||||
FileSystem::unmount();
|
||||
io::deleteFolderRecursively((dstPath + "/").c_str());
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to copy directory " + dstPath + ". Skipping...");
|
||||
return std::make_tuple(false, res, "Failed to backup save.");
|
||||
}
|
||||
|
||||
|
@ -213,11 +223,14 @@ std::tuple<bool, Result, std::string> io::backup(size_t index, u128 uid, size_t
|
|||
blinkLed(4);
|
||||
ret = std::make_tuple(true, 0, "Progress correctly saved to disk.");
|
||||
}
|
||||
// TODO: figure out if this code can be accessed at all
|
||||
auto systemKeyboardAvailable = KeyboardManager::get().isSystemKeyboardAvailable();
|
||||
if (!systemKeyboardAvailable.first) {
|
||||
return std::make_tuple(
|
||||
false, systemKeyboardAvailable.second, "System keyboard applet not accessible.\nThe suggested destination folder was used\ninstead.");
|
||||
}
|
||||
|
||||
Logger::getInstance().log(Logger::INFO, "Backup succeeded.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -228,16 +241,20 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, u128 uid, size_t
|
|||
Title title;
|
||||
getTitle(title, uid, index);
|
||||
|
||||
Logger::getInstance().log(Logger::INFO, "Started restore of %s. Title id: 0x%016lX; User id: 0x%lX%lX.", title.name().c_str(), title.id(), (u64)(title.userId() >> 8), (u64)(title.userId()));
|
||||
|
||||
FsFileSystem fileSystem;
|
||||
res = title.systemSave() ? FileSystem::mount(&fileSystem, title.id()) : FileSystem::mount(&fileSystem, title.id(), title.userId());
|
||||
if (R_SUCCEEDED(res)) {
|
||||
int rc = FileSystem::mount(fileSystem);
|
||||
if (rc == -1) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during restore. Title id: 0x%016lX; User id: 0x%lX%lX.", title.id(), (u64)(title.userId() >> 8), (u64)(title.userId()));
|
||||
return std::make_tuple(false, -2, "Failed to mount save.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to mount filesystem during restore with result %X. Title id: 0x%016lX; User id: 0x%lX%lX.", res, title.id(), (u64)(title.userId() >> 8), (u64)(title.userId()));
|
||||
return std::make_tuple(false, res, "Failed to mount save.");
|
||||
}
|
||||
|
||||
|
@ -247,17 +264,20 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, u128 uid, size_t
|
|||
res = io::deleteFolderRecursively(dstPath.c_str());
|
||||
if (R_FAILED(res)) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to recursively delete directory " + dstPath);
|
||||
return std::make_tuple(false, res, "Failed to delete save.");
|
||||
}
|
||||
|
||||
res = io::copyDirectory(srcPath, dstPath);
|
||||
if (R_FAILED(res)) {
|
||||
FileSystem::unmount();
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to copy directory " + srcPath + " to " + dstPath + ". Skipping...");
|
||||
return std::make_tuple(false, res, "Failed to restore save.");
|
||||
}
|
||||
|
||||
res = fsdevCommitDevice("save");
|
||||
if (R_FAILED(res)) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to commit save with result %X.", res);
|
||||
return std::make_tuple(false, res, "Failed to commit to save device.");
|
||||
}
|
||||
else {
|
||||
|
@ -266,5 +286,7 @@ std::tuple<bool, Result, std::string> io::restore(size_t index, u128 uid, size_t
|
|||
}
|
||||
|
||||
FileSystem::unmount();
|
||||
|
||||
Logger::getInstance().log(Logger::INFO, "Restore succeeded.");
|
||||
return ret;
|
||||
}
|
|
@ -116,6 +116,7 @@ std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid,
|
|||
int fd;
|
||||
struct sockaddr_in servaddr;
|
||||
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Socket creation failed.");
|
||||
return std::make_tuple(false, errno, "Socket creation failed.");
|
||||
}
|
||||
|
||||
|
@ -126,10 +127,12 @@ std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid,
|
|||
|
||||
if (bind(fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
|
||||
close(fd);
|
||||
Logger::getInstance().log(Logger::ERROR, "Socket bind failed.");
|
||||
return std::make_tuple(false, errno, "Socket bind failed.");
|
||||
}
|
||||
if (listen(fd, 5) < 0) {
|
||||
close(fd);
|
||||
Logger::getInstance().log(Logger::ERROR, "Socket listen failed.");
|
||||
return std::make_tuple(false, errno, "Socket listen failed.");
|
||||
}
|
||||
|
||||
|
@ -137,6 +140,7 @@ std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid,
|
|||
int addrlen = sizeof(servaddr);
|
||||
if ((fdconn = accept(fd, (struct sockaddr*)&servaddr, (socklen_t*)&addrlen)) < 0) {
|
||||
close(fd);
|
||||
Logger::getInstance().log(Logger::ERROR, "Socket accept failed.");
|
||||
return std::make_tuple(false, errno, "Socket accept failed.");
|
||||
}
|
||||
|
||||
|
@ -148,6 +152,7 @@ std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid,
|
|||
if (save == NULL) {
|
||||
close(fd);
|
||||
close(fdconn);
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to open destination file.");
|
||||
return std::make_tuple(false, errno, "Failed to open destination file.");
|
||||
}
|
||||
|
||||
|
@ -172,11 +177,13 @@ std::tuple<bool, Result, std::string> recvFromPKSMBridge(size_t index, u128 uid,
|
|||
fwrite(data, 1, size, save);
|
||||
fclose(save);
|
||||
delete[] data;
|
||||
Logger::getInstance().log(Logger::INFO, "pksmbridge data received correctly.");
|
||||
return std::make_tuple(true, 0, "Data received correctly.");
|
||||
}
|
||||
else {
|
||||
fclose(save);
|
||||
delete[] data;
|
||||
Logger::getInstance().log(Logger::ERROR, "Failed to receive pksmbridge data.");
|
||||
return std::make_tuple(false, errno, "Failed to receive data.");
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ Result servicesInit(void)
|
|||
|
||||
int appletType = (int)appletGetAppletType();
|
||||
if (appletType != AppletType_Application) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Please run Checkpoint under Atmosphére title takeover. AppletType is %d", appletType);
|
||||
Logger::getInstance().log(Logger::ERROR, "Please run Checkpoint under Atmosphére title takeover. AppletType is %d.", appletType);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ Result servicesInit(void)
|
|||
// nxlinkStdio();
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::INFO, "Unable to initialize socket. Result code %X", socinit);
|
||||
Logger::getInstance().log(Logger::INFO, "Unable to initialize socket. Result code %X.", socinit);
|
||||
}
|
||||
|
||||
g_shouldExitNetworkLoop = R_FAILED(socinit);
|
||||
|
@ -63,25 +63,25 @@ Result servicesInit(void)
|
|||
io::createDirectory("sdmc:/switch/Checkpoint/cheats");
|
||||
|
||||
if (R_FAILED(res = plInitialize())) {
|
||||
Logger::getInstance().log(Logger::ERROR, "plInitialize failed. Result code %X", res);
|
||||
Logger::getInstance().log(Logger::ERROR, "plInitialize failed. Result code %X.", res);
|
||||
return res;
|
||||
}
|
||||
ATEXIT(plExit);
|
||||
|
||||
if (R_FAILED(res = Account::init())) {
|
||||
Logger::getInstance().log(Logger::ERROR, "Account::init failed. Result code %X", res);
|
||||
Logger::getInstance().log(Logger::ERROR, "Account::init failed. Result code %X.", res);
|
||||
return res;
|
||||
}
|
||||
ATEXIT(Account::exit);
|
||||
|
||||
if (R_FAILED(res = nsInitialize())) {
|
||||
Logger::getInstance().log(Logger::ERROR, "nsInitialize failed. Result code %X", res);
|
||||
Logger::getInstance().log(Logger::ERROR, "nsInitialize failed. Result code %X.", res);
|
||||
return res;
|
||||
}
|
||||
ATEXIT(nsExit);
|
||||
|
||||
if (!SDLH_Init()) {
|
||||
Logger::getInstance().log(Logger::ERROR, "SDLH_Init failed. Result code %X", res);
|
||||
Logger::getInstance().log(Logger::ERROR, "SDLH_Init failed. Result code %X.", res);
|
||||
return -1;
|
||||
}
|
||||
ATEXIT(freeIcons);
|
||||
|
@ -91,7 +91,7 @@ Result servicesInit(void)
|
|||
ATEXIT(hidsysExit);
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::INFO, "Notification led not available. Result code %X", res);
|
||||
Logger::getInstance().log(Logger::INFO, "Notification led not available. Result code %X.", res);
|
||||
}
|
||||
|
||||
Configuration::getInstance();
|
||||
|
@ -103,7 +103,7 @@ Result servicesInit(void)
|
|||
Logger::getInstance().log(Logger::INFO, "FTP Server successfully loaded.");
|
||||
}
|
||||
else {
|
||||
Logger::getInstance().log(Logger::INFO, "FTP Server failed to load. Result code %X", res);
|
||||
Logger::getInstance().log(Logger::INFO, "FTP Server failed to load. Result code %X.", res);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue