diff --git a/.gitignore b/.gitignore index df7df74..25b812d 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,5 @@ eboot2.bin param.sfo param2.sfo PSVita_Debug -PSVita_Release \ No newline at end of file +PSVita_Release +build \ No newline at end of file diff --git a/BGFTP/main.c b/BGFTP/main.c index 4ad155e..807d65d 100644 --- a/BGFTP/main.c +++ b/BGFTP/main.c @@ -62,5 +62,7 @@ int main() sceSysmoduleLoadModule(SCE_SYSMODULE_BG_APP_UTIL); sceBgAppUtilStartBgApp(0); + common_exit(0); + return 0; } diff --git a/BGFTP/param.sfx b/BGFTP/param.sfx index 54ff9a4..6c1d5f9 100644 --- a/BGFTP/param.sfx +++ b/BGFTP/param.sfx @@ -1,6 +1,6 @@ - 03.23 + 03.24 16814080 17 0 diff --git a/BGFTP_bgapp/ftpvita.c b/BGFTP_bgapp/ftpvita.c index 3d1a920..75c2530 100644 --- a/BGFTP_bgapp/ftpvita.c +++ b/BGFTP_bgapp/ftpvita.c @@ -14,6 +14,7 @@ #include #define UNUSED(x) (void)(x) +#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1)) #define NET_CTL_ERROR_NOT_TERMINATED 0x80412102 @@ -52,6 +53,7 @@ static struct { static void *net_memory = NULL; static int ftp_initialized = 0; static unsigned int file_buf_size = DEFAULT_FILE_BUF_SIZE; +static unsigned int active_op_count = 0; static SceNetInAddr vita_addr; static SceUID server_thid; static int server_sockfd; @@ -510,6 +512,11 @@ static void send_file(ftpvita_client_info_t *client, const char *path) unsigned char *buffer; SceUID fd; unsigned int bytes_read; + unsigned int op_buf_size; + + active_op_count++; + + op_buf_size = ALIGN(file_buf_size / active_op_count, 4 * 1024); DEBUG("Opening: %s\n", path); @@ -517,16 +524,17 @@ static void send_file(ftpvita_client_info_t *client, const char *path) sceIoLseek32(fd, client->restore_point, SCE_SEEK_SET); - buffer = malloc(file_buf_size); + buffer = malloc(op_buf_size); if (buffer == NULL) { client_send_ctrl_msg(client, "550 Could not allocate memory." FTPVITA_EOL); + active_op_count--; return; } client_open_data_connection(client); client_send_ctrl_msg(client, "150 Opening Image mode data transfer." FTPVITA_EOL); - while ((bytes_read = sceIoRead (fd, buffer, file_buf_size)) > 0) { + while ((bytes_read = sceIoRead (fd, buffer, op_buf_size)) > 0) { client_send_data_raw(client, buffer, bytes_read); } @@ -540,6 +548,8 @@ static void send_file(ftpvita_client_info_t *client, const char *path) } else { client_send_ctrl_msg(client, "550 File not found." FTPVITA_EOL); } + + active_op_count--; } /* This function generates an FTP full-path with the input path (relative or absolute) @@ -576,6 +586,11 @@ static void receive_file(ftpvita_client_info_t *client, const char *path) unsigned char *buffer; SceUID fd; int bytes_recv; + unsigned int op_buf_size; + + active_op_count++; + + op_buf_size = ALIGN(file_buf_size / active_op_count, 4 * 1024); DEBUG("Opening: %s\n", path); @@ -591,16 +606,17 @@ static void receive_file(ftpvita_client_info_t *client, const char *path) if ((fd = sceIoOpen(path, mode, 0777)) >= 0) { - buffer = malloc(file_buf_size); + buffer = malloc(op_buf_size); if (buffer == NULL) { client_send_ctrl_msg(client, "550 Could not allocate memory." FTPVITA_EOL); + active_op_count--; return; } client_open_data_connection(client); client_send_ctrl_msg(client, "150 Opening Image mode data transfer." FTPVITA_EOL); - while ((bytes_recv = client_recv_data_raw(client, buffer, file_buf_size)) > 0) { + while ((bytes_recv = client_recv_data_raw(client, buffer, op_buf_size)) > 0) { sceIoWrite(fd, buffer, bytes_recv); } @@ -620,6 +636,8 @@ static void receive_file(ftpvita_client_info_t *client, const char *path) } else { client_send_ctrl_msg(client, "550 File not found." FTPVITA_EOL); } + + active_op_count--; } static void cmd_STOR_func(ftpvita_client_info_t *client) @@ -1067,7 +1085,7 @@ static int server_thread(SceSize args, void *argp) return 0; } -int ftpvita_init(char *vita_ip, unsigned short int *vita_port) +int ftpvita_init(char *vita_ip, unsigned short *vita_port) { int ret; int i; @@ -1105,6 +1123,13 @@ int ftpvita_init(char *vita_ip, unsigned short int *vita_port) if (netctl_init < 0 && netctl_init != NET_CTL_ERROR_NOT_TERMINATED) goto error_netctlinit; + sceNetCtlInetGetState(&ret); + + while (ret != SCE_NET_CTL_STATE_IPOBTAINED) { + sceNetCtlInetGetState(&ret); + sceKernelDelayThread(10000); + } + /* Get IP address */ ret = sceNetCtlInetGetInfo(SCE_NET_CTL_INFO_IP_ADDRESS, &info); DEBUG("sceNetCtlInetGetInfo(): 0x%08X\n", ret); @@ -1143,22 +1168,23 @@ int ftpvita_init(char *vita_ip, unsigned short int *vita_port) return 0; -error_netctlgetinfo: - if (netctl_init == 0) { - sceNetCtlTerm(); - netctl_init = -1; - } error_netctlinit: +error_netctlgetinfo: +error_netinit: +error_netstat: if (net_init == 0) { sceNetTerm(); net_init = -1; } -error_netinit: + if (netctl_init == 0) { + sceNetCtlTerm(); + netctl_init = -1; + } if (net_memory) { free(net_memory); net_memory = NULL; } -error_netstat: + return ret; } diff --git a/BGFTP_bgapp/ftpvita.h b/BGFTP_bgapp/ftpvita.h index 540a83b..089944e 100644 --- a/BGFTP_bgapp/ftpvita.h +++ b/BGFTP_bgapp/ftpvita.h @@ -15,7 +15,7 @@ typedef void (*ftpvita_log_cb_t)(const char *); /* Returns PSVita's IP and FTP port. 0 on success */ -int ftpvita_init(char *vita_ip, unsigned short int *vita_port); +int ftpvita_init(char *vita_ip, unsigned short *vita_port); void ftpvita_fini(); int ftpvita_is_initialized(); int ftpvita_add_device(const char *devname); diff --git a/BGFTP_bgapp/main.c b/BGFTP_bgapp/main.c index 0b0815d..497a21c 100644 --- a/BGFTP_bgapp/main.c +++ b/BGFTP_bgapp/main.c @@ -27,15 +27,6 @@ extern unsigned int sce_process_preload_disabled = (SCE_PROCESS_PRELOAD_DISABLED // Libc parameters unsigned int sceLibcHeapSize = 14 * 1024 * 1024; -typedef struct SceAppMgrEvent { - int event; /* Event ID */ - SceUID appId; /* Application ID. Added when required by the event */ - char param[56]; /* Parameters to pass with the event */ -} SceAppMgrEvent; - -/* appmgr */ -extern int sceAppMgrReceiveEvent(SceAppMgrEvent *appEvent); - void sendNotification(const char *text, ...) { SceNotificationUtilSendParam param; @@ -67,7 +58,7 @@ void ftpvita_init_app() { char vita_ip[16]; int state; - unsigned short int vita_port; + unsigned short vita_port; ftpvita_set_file_buf_size(6 * 1024 * 1024); @@ -97,61 +88,6 @@ void ftpvita_init_app() int main() { - /* network check */ - - SceAppMgrEvent appEvent; - int plane, wifi, dialogShown; - uint32_t inSize, outSize; - dialogShown = 0; - - sceRegMgrGetKeyInt("/CONFIG/NET", "wifi_flag", &wifi); - sceRegMgrGetKeyInt("/CONFIG/SYSTEM", "flight_mode", &plane); - - if (!wifi || plane) { - - sceSysmoduleLoadModule(SCE_SYSMODULE_INCOMING_DIALOG); - - sceIncomingDialogInit(0); - - SceIncomingDialogParam params; - sceIncomingDialogParamInit(¶ms); - sceClibStrncpy((char *)params.titleId, "GRVA00002", sizeof(params.titleId)); - params.timeout = 0x7FFFFFF0; - - SceCesUcsContext context; - - sceCesUcsContextInit(&context); - sceCesUtf8StrToUtf16Str( - &context, - "OK", - 6, - &inSize, - (uint16_t *)params.acceptText, - 0x20, - &outSize); - - sceCesUcsContextInit(&context); - sceCesUtf8StrToUtf16Str( - &context, - "Wi-Fi is disabled or system is in airplane mode.", - 95, - &inSize, - (uint16_t *)params.dialogText, - 0x40, - &outSize); - - sceIncomingDialogOpen(¶ms); - - while (1) { - sceAppMgrReceiveEvent(&appEvent); - if (appEvent.event == 0x20000004 && dialogShown) - sceAppMgrDestroyAppByAppId(-2); - else if (appEvent.event == 0x20000004) - dialogShown = 1; - sceKernelDelayThread(10000); - } - } - /* BG application*/ sceSysmoduleLoadModule(SCE_SYSMODULE_NOTIFICATION_UTIL); diff --git a/BGFTP_bgapp/param.sfx b/BGFTP_bgapp/param.sfx index c37dcbf..a826bae 100644 --- a/BGFTP_bgapp/param.sfx +++ b/BGFTP_bgapp/param.sfx @@ -1,6 +1,6 @@ - 03.23 + 03.24 528384 0 gdd