From b9ac6b2b3101cf40d7851d72b57b2e3d2a5a191d Mon Sep 17 00:00:00 2001 From: p-sam Date: Thu, 14 Mar 2019 00:06:43 +0000 Subject: [PATCH] nx: set config and temp file paths (next to NRO) --- platforms/nx/nxhooks/include/nxhooks/init.h | 1 + platforms/nx/nxhooks/src/init.c | 18 +++++++++++++++--- src/ppui/osinterface/posix/PPSystem_POSIX.cpp | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/platforms/nx/nxhooks/include/nxhooks/init.h b/platforms/nx/nxhooks/include/nxhooks/init.h index 14d481eb..2b27444d 100644 --- a/platforms/nx/nxhooks/include/nxhooks/init.h +++ b/platforms/nx/nxhooks/include/nxhooks/init.h @@ -6,6 +6,7 @@ extern "C" { void nxHooksInit(); void nxHooksExit(); +char* nxHooksGetInitialDirectoryName(); #ifdef __cplusplus } diff --git a/platforms/nx/nxhooks/src/init.c b/platforms/nx/nxhooks/src/init.c index e3ee9b2a..ed2741b0 100644 --- a/platforms/nx/nxhooks/src/init.c +++ b/platforms/nx/nxhooks/src/init.c @@ -1,8 +1,12 @@ #include #include #include +#include +#include static FILE* g_logfile = NULL; +static char g_initial_directory_name[PATH_MAX+1]; + void nxHooksInit() { Result rc = socketInitializeDefault(); int stdioRes = -1; @@ -19,18 +23,22 @@ void nxHooksInit() { fflush(stderr); dup2(fileno(g_logfile), STDERR_FILENO); } - printf("nxhooks: nxlink failed with res: %d\n", stdioRes); + printf("[nxhooks] nxlink failed with res: %d\n", stdioRes); } if(R_FAILED(rc)) { - printf("nxhooks: socketInitialize failed with rc: %x\n", rc); + printf("[nxhooks] socketInitialize failed with rc: %x\n", rc); } rc = appletInitializeGamePlayRecording(); if(R_FAILED(rc)) { - printf("nxhooks: appletInitializeGamePlayRecording failed with rc: %x\n", rc); + printf("[nxhooks] appletInitializeGamePlayRecording failed with rc: %x\n", rc); } appletSetGamePlayRecordingState(1); + + memset(g_initial_directory_name, 0, sizeof(g_initial_directory_name)); + getcwd(g_initial_directory_name, sizeof(g_initial_directory_name)); + printf("[nxhooks] initial_directory_name: %s\n", g_initial_directory_name); } void nxHooksExit() { @@ -38,4 +46,8 @@ void nxHooksExit() { if(g_logfile != NULL) { fclose(g_logfile); } +} + +char* nxHooksGetInitialDirectoryName() { + return g_initial_directory_name; } \ No newline at end of file diff --git a/src/ppui/osinterface/posix/PPSystem_POSIX.cpp b/src/ppui/osinterface/posix/PPSystem_POSIX.cpp index 78b91945..bfb7526d 100644 --- a/src/ppui/osinterface/posix/PPSystem_POSIX.cpp +++ b/src/ppui/osinterface/posix/PPSystem_POSIX.cpp @@ -53,10 +53,19 @@ #include #endif +#ifdef __SWITCH__ +#include +#endif + SYSCHAR System::buffer[PATH_MAX+1]; const SYSCHAR* System::getTempFileName() { +#ifdef __SWITCH__ + strcpy(buffer, nxHooksGetInitialDirectoryName()); + strcat(buffer, "/milkytracker_temp"); + return buffer; +#endif // Suppressed warning: "'tmpnam' is deprecated: This function is provided for // compatibility reasons only. Due to security concerns inherent in the // design of tmpnam(3), it is highly recommended that you use mkstemp(3) @@ -102,6 +111,13 @@ const SYSCHAR* System::getConfigFileName() strcpy(buffer, path.Path()); return buffer; #endif + +#ifdef __SWITCH__ + strcpy(buffer, nxHooksGetInitialDirectoryName()); + strcat(buffer, "/milkytracker_config"); + return buffer; +#endif + char *home = getenv("HOME"); if(!home) {