Skip to content

Commit

Permalink
nx: set config and temp file paths (next to NRO)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sam committed Mar 14, 2019
1 parent 16053bd commit b9ac6b2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions platforms/nx/nxhooks/include/nxhooks/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C" {

void nxHooksInit();
void nxHooksExit();
char* nxHooksGetInitialDirectoryName();

#ifdef __cplusplus
}
Expand Down
18 changes: 15 additions & 3 deletions platforms/nx/nxhooks/src/init.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#include <switch.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>

static FILE* g_logfile = NULL;
static char g_initial_directory_name[PATH_MAX+1];

void nxHooksInit() {
Result rc = socketInitializeDefault();
int stdioRes = -1;
Expand All @@ -19,23 +23,31 @@ 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() {
socketExit();
if(g_logfile != NULL) {
fclose(g_logfile);
}
}

char* nxHooksGetInitialDirectoryName() {
return g_initial_directory_name;
}
16 changes: 16 additions & 0 deletions src/ppui/osinterface/posix/PPSystem_POSIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@
#include <Path.h>
#endif

#ifdef __SWITCH__
#include <nxhooks.h>
#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)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit b9ac6b2

Please sign in to comment.