mirror of
https://github.com/cathery/sys-con.git
synced 2024-12-25 09:14:35 +00:00
Reimplement WirteToLog to grealy reduce filesize
This commit is contained in:
parent
ac6eff74bc
commit
cdc8ed5d51
@ -126,7 +126,7 @@ Result XboxOneAdapter::SendInitBytes()
|
||||
ControlWrite(m_interface, MT_FCE_PDMA_GLOBAL_CONF, 0x44);
|
||||
ControlWrite(m_interface, MT_FCE_SKIP_FS, 0x03);
|
||||
|
||||
WriteToLog("firmware path: ", firmwarePath);
|
||||
WriteToLog("firmware path: %s", firmwarePath);
|
||||
if (!firmwarePath || *firmwarePath == '\0')
|
||||
{
|
||||
WriteToLog("But the string is empty!");
|
||||
@ -145,7 +145,7 @@ Result XboxOneAdapter::SendInitBytes()
|
||||
|
||||
fs.close();
|
||||
|
||||
WriteToLog("writing ", firmware.size(), " bytes...");
|
||||
WriteToLog("writing %lu bytes...", firmware.size());
|
||||
|
||||
FwHeader *header = reinterpret_cast<FwHeader *>(firmware.data());
|
||||
|
||||
|
@ -203,7 +203,7 @@ Result XboxOneController::SendInitBytes()
|
||||
if (R_FAILED(rc))
|
||||
break;
|
||||
else
|
||||
WriteToLog("Send a specific init packet ", i, " for controller v", vendor, " p", product);
|
||||
WriteToLog("Sent a specific init packet %i for controller v%u p%u", i, vendor, product);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
49
source/log.c
Normal file
49
source/log.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include "switch.h"
|
||||
#include "log.h"
|
||||
#include "configFile.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
static Mutex g_PrintMutex = 0;
|
||||
|
||||
void WriteToLog(const char *fmt, ...)
|
||||
{
|
||||
mutexLock(&g_PrintMutex);
|
||||
|
||||
#ifdef __APPLET__
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vprintf(fmt, va);
|
||||
printf("\n");
|
||||
va_end(va);
|
||||
|
||||
#else
|
||||
|
||||
time_t unixTime = time(NULL);
|
||||
struct tm *tStruct = localtime((const time_t *)&unixTime);
|
||||
|
||||
FILE *fp = fopen(CONFIG_PATH "log.txt", "a");
|
||||
|
||||
//Print time
|
||||
fprintf(fp, "%04i-%02i-%02i %02i:%02i:%02i: ", (tStruct->tm_year + 1900), tStruct->tm_mon, tStruct->tm_mday, tStruct->tm_hour, tStruct->tm_min, tStruct->tm_sec);
|
||||
|
||||
//Print the actual text
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vfprintf(fp, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
fprintf(fp, "\n");
|
||||
fclose(fp);
|
||||
#endif
|
||||
|
||||
mutexUnlock(&g_PrintMutex);
|
||||
}
|
||||
|
||||
void LockedUpdateConsole()
|
||||
{
|
||||
mutexLock(&g_PrintMutex);
|
||||
consoleUpdate(NULL);
|
||||
mutexUnlock(&g_PrintMutex);
|
||||
}
|
45
source/log.h
45
source/log.h
@ -1,41 +1,14 @@
|
||||
#pragma once
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "configFile.h"
|
||||
|
||||
template <typename... T>
|
||||
void WriteToLog(T &&... text)
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#ifdef __APPLET__
|
||||
|
||||
std::stringstream ss;
|
||||
((ss << text), ...);
|
||||
printf(ss.str().c_str());
|
||||
printf("\n");
|
||||
|
||||
#else
|
||||
|
||||
using namespace std;
|
||||
|
||||
time_t unixTime = time(NULL);
|
||||
struct tm *time = localtime((const time_t *)&unixTime);
|
||||
|
||||
fstream fs;
|
||||
fs.open(CONFIG_PATH "log.txt", fstream::app);
|
||||
|
||||
//Print time
|
||||
fs << setfill('0');
|
||||
fs << setw(4) << (time->tm_year + 1900)
|
||||
<< "-" << setw(2) << time->tm_mon
|
||||
<< "-" << setw(2) << time->tm_mday
|
||||
<< " " << setw(2) << time->tm_hour
|
||||
<< ":" << setw(2) << time->tm_min
|
||||
<< ":" << setw(2) << time->tm_sec << ": ";
|
||||
//Print the actual text
|
||||
((fs << text), ...);
|
||||
fs << "\n";
|
||||
fs.close();
|
||||
|
||||
#endif
|
||||
|
||||
void WriteToLog(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
|
||||
void LockedUpdateConsole();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -90,7 +90,8 @@ extern "C"
|
||||
|
||||
void __libnx_exception_handler(ThreadExceptionDump *ctx)
|
||||
{
|
||||
WriteToLog("Sysmodule crashed with error 0x", std::hex, ctx->error_desc);
|
||||
WriteToLog("Sysmodule crashed with error 0x%x", ctx->error_desc);
|
||||
LockedUpdateConsole();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ Result CallInitHandler(std::unique_ptr<IController> &controllerPtr)
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToLog("Error creating interface with error ", rc);
|
||||
WriteToLog("Error creating interface with error 0x%x", rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@ -192,8 +192,7 @@ Result mainLoop()
|
||||
const uint16_t dependencies[] = {PscPmModuleId_Usb};
|
||||
|
||||
rc = pscmGetPmModule(&pscModule, static_cast<PscPmModuleId>(126), dependencies, sizeof(dependencies) / sizeof(uint16_t), true);
|
||||
WriteToLog("Get module result: 0x", std::hex, rc);
|
||||
//Waiter pscModuleWaiter = waiterForEvent(&pscModule.event);
|
||||
WriteToLog("Get module result: 0x%x", rc);
|
||||
|
||||
bool pscLoopRunning = true;
|
||||
bool shouldSleep = false;
|
||||
@ -210,8 +209,7 @@ Result mainLoop()
|
||||
|
||||
rc = OpenEvents();
|
||||
if (R_FAILED(rc))
|
||||
WriteToLog("Failed to open events: ", rc);
|
||||
|
||||
WriteToLog("Failed to open events: 0x%x", rc);
|
||||
controllerInterfaces.reserve(10);
|
||||
|
||||
while (appletMainLoop())
|
||||
@ -227,7 +225,7 @@ Result mainLoop()
|
||||
{
|
||||
u64 kHeld = hidKeysDown(static_cast<HidControllerID>(i));
|
||||
if (kHeld != 0)
|
||||
WriteToLog("Player ", i + 1, ": ", kHeld);
|
||||
WriteToLog("Player %i: %lu", i + 1, kHeld);
|
||||
}
|
||||
|
||||
if (kDown & KEY_B)
|
||||
@ -350,7 +348,7 @@ Result mainLoop()
|
||||
|
||||
if (!found_flag)
|
||||
{
|
||||
WriteToLog("Erasing controller! ", (*it)->GetController()->GetType());
|
||||
WriteToLog("Erasing controller! %i", (*it)->GetController()->GetType());
|
||||
controllerInterfaces.erase(it--);
|
||||
WriteToLog("Controller erased!");
|
||||
}
|
||||
@ -377,7 +375,7 @@ Result mainLoop()
|
||||
controllerInterfaces.clear();
|
||||
}
|
||||
#ifdef __APPLET__
|
||||
consoleUpdate(nullptr);
|
||||
LockedUpdateConsole();
|
||||
#else
|
||||
svcSleepThread(1e+7L);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user