ftpiiu_plugin/source/main.c

121 lines
1.9 KiB
C
Raw Normal View History

2014-11-23 23:39:00 +01:00
#include <malloc.h>
#include <stdarg.h>
#include <stdio.h>
#ifdef _3DS
#include <3ds.h>
#endif
#include "console.h"
#include "ftp.h"
/*! looping mechanism
*
* @param[in] callback function to call during each iteration
2016-01-16 07:38:58 +01:00
*
* @returns loop status
2014-11-23 23:39:00 +01:00
*/
2016-01-16 07:38:58 +01:00
static loop_status_t
loop(loop_status_t (*callback)(void))
2014-11-23 23:39:00 +01:00
{
2016-01-16 07:38:58 +01:00
loop_status_t status = LOOP_CONTINUE;
2014-11-23 23:39:00 +01:00
#ifdef _3DS
2014-11-25 20:26:37 +01:00
while(aptMainLoop())
2014-11-23 23:39:00 +01:00
{
2016-01-16 07:38:58 +01:00
status = callback();
console_render();
if(status != LOOP_CONTINUE)
return status;
2014-11-23 23:39:00 +01:00
}
2016-01-16 07:38:58 +01:00
return LOOP_EXIT;
2014-11-23 23:39:00 +01:00
#else
2016-01-16 07:41:49 +01:00
while(status == LOOP_CONTINUE)
status = callback();
return status;
2014-11-23 23:39:00 +01:00
#endif
}
2016-08-11 06:08:08 +02:00
#ifdef _3DS
2014-11-23 23:39:00 +01:00
/*! wait until the B button is pressed
*
2016-01-16 07:38:58 +01:00
* @returns loop status
2014-11-23 23:39:00 +01:00
*/
2016-01-16 07:38:58 +01:00
static loop_status_t
2014-11-23 23:39:00 +01:00
wait_for_b(void)
{
/* update button state */
hidScanInput();
/* check if B was pressed */
if(hidKeysDown() & KEY_B)
2016-01-16 07:38:58 +01:00
return LOOP_EXIT;
2014-11-23 23:39:00 +01:00
/* B was not pressed */
2016-01-16 07:38:58 +01:00
return LOOP_CONTINUE;
2014-11-23 23:39:00 +01:00
}
2016-08-11 06:08:08 +02:00
#endif
2014-11-23 23:39:00 +01:00
/*! entry point
*
* @param[in] argc unused
* @param[in] argv unused
*
* returns exit status
*/
int
main(int argc,
char *argv[])
{
2016-01-16 07:38:58 +01:00
loop_status_t status = LOOP_RESTART;
2014-11-23 23:39:00 +01:00
#ifdef _3DS
/* initialize needed 3DS services */
2016-01-16 07:22:26 +01:00
acInit();
2015-01-08 15:01:33 +01:00
gfxInitDefault();
2014-11-23 23:39:00 +01:00
gfxSet3D(false);
2016-01-12 23:24:01 +01:00
sdmcWriteSafe(false);
2014-11-23 23:39:00 +01:00
#endif
/* initialize console subsystem */
console_init();
console_set_status("\n" GREEN STATUS_STRING RESET);
2014-11-23 23:39:00 +01:00
2016-01-16 07:38:58 +01:00
while(status == LOOP_RESTART)
2014-11-23 23:39:00 +01:00
{
2016-01-16 07:38:58 +01:00
/* initialize ftp subsystem */
if(ftp_init() == 0)
{
/* ftp loop */
status = loop(ftp_loop);
2014-11-23 23:39:00 +01:00
2016-01-16 07:38:58 +01:00
/* done with ftp */
ftp_exit();
}
else
status = LOOP_EXIT;
2014-11-23 23:39:00 +01:00
}
#ifdef _3DS
2016-08-11 06:08:08 +02:00
u64 id;
APT_GetProgramID(&id);
if(id != 0x000400000BEEF500)
{
console_print("Press B to exit\n");
loop(wait_for_b);
}
else
{
console_print("Press the Home Button to exit\n");
while(aptMainLoop())
console_render();
}
2014-11-23 23:39:00 +01:00
/* deinitialize 3DS services */
gfxExit();
2016-01-16 07:22:26 +01:00
acExit();
2014-11-23 23:39:00 +01:00
#endif
return 0;
}