Skip to content

Commit

Permalink
- Re-add fs and sdmc init, check configuration early on.
Browse files Browse the repository at this point in the history
  • Loading branch information
Koi-3088 committed Apr 10, 2022
1 parent a56f9a6 commit ef4da85
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions sys-botbase/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void sub_key(void *arg);
void sub_click(void *arg);
void usbMainLoop();
void wifiMainLoop();
bool isUSB();

// locks for thread
Mutex freezeMutex, touchMutex, keyMutex, clickMutex;
Expand Down Expand Up @@ -116,12 +117,27 @@ void __appInit(void)
rc = pminfoInitialize();
if (R_FAILED(rc))
fatalThrow(rc);
rc = usbCommsInitialize();
rc = fsInitialize();
if (R_FAILED(rc))
fatalThrow(rc);
rc = socketInitializeDefault();
rc = fsdevMountSdmc();
if (R_FAILED(rc))
fatalThrow(rc);

usb = isUSB();
if (usb)
{
rc = usbCommsInitialize();
if (R_FAILED(rc))
fatalThrow(rc);
}
else
{
rc = socketInitializeDefault();
if (R_FAILED(rc))
fatalThrow(rc);
}

rc = capsscInitialize();
if (R_FAILED(rc))
fatalThrow(rc);
Expand All @@ -132,12 +148,15 @@ void __appInit(void)

void __appExit(void)
{
fsdevUnmountAll();
fsExit();
smExit();
audoutExit();
timeExit();
socketExit();
viExit();
usbCommsExit();
if (usb)
usbCommsExit();
else socketExit();
}

u64 mainLoopSleepTime = 50;
Expand Down Expand Up @@ -1048,16 +1067,6 @@ void del_from_pfds(struct pollfd pfds[], int i, int *fd_count)

int main()
{
char str[4];
FILE* config = fopen("sdmc:/atmosphere/contents/430000000000000B/config.cfg", "r");
if (config)
{
fscanf(config, "%[^\n]", str);
fclose(config);
if (strcmp(strlwr(str), "wifi") == 0)
usb = false;
}

Result rc;
initFreezes();

Expand Down Expand Up @@ -1386,3 +1395,17 @@ void sub_click(void *arg)
svcSleepThread(1e+6L);
}
}

bool isUSB()
{
char str[4];
FILE* config = fopen("sdmc:/atmosphere/contents/430000000000000B/config.cfg", "r");
if (config)
{
fscanf(config, "%[^\n]", str);
fclose(config);
if (strcmp(strlwr(str), "wifi") == 0)
return false;
}
return true;
}

0 comments on commit ef4da85

Please sign in to comment.