diff --git a/data/images/pbarcenter.png b/data/images/pbarcenter.png index a5e1b2af..12f15819 100644 Binary files a/data/images/pbarcenter.png and b/data/images/pbarcenter.png differ diff --git a/data/images/pbarcenters.png b/data/images/pbarcenters.png index 535e1949..32a49dff 100644 Binary files a/data/images/pbarcenters.png and b/data/images/pbarcenters.png differ diff --git a/data/images/pbarleft.png b/data/images/pbarleft.png index a4d81cb6..2a4bd377 100644 Binary files a/data/images/pbarleft.png and b/data/images/pbarleft.png differ diff --git a/data/images/pbarlefts.png b/data/images/pbarlefts.png index 27c9d8a0..9fbd6091 100644 Binary files a/data/images/pbarlefts.png and b/data/images/pbarlefts.png differ diff --git a/data/images/pbarright.png b/data/images/pbarright.png index 24e26217..20fbe1c0 100644 Binary files a/data/images/pbarright.png and b/data/images/pbarright.png differ diff --git a/data/images/pbarrights.png b/data/images/pbarrights.png index 3b2f7ebe..b040191f 100644 Binary files a/data/images/pbarrights.png and b/data/images/pbarrights.png differ diff --git a/source/menu/menu_ftp.cpp b/source/menu/menu_ftp.cpp index d66ab3d1..70dfb2be 100644 --- a/source/menu/menu_ftp.cpp +++ b/source/menu/menu_ftp.cpp @@ -21,30 +21,38 @@ #include "network/gcard.h" #include "network/FTP_Dir.hpp" +s16 m_ftpLblTitle; s16 m_ftpBtnBack; s16 m_ftpBtnToggle; +s16 m_ftpLblInfo; +s16 m_ftpLblUser[4]; void CMenu::_updateFTP(void) { + _hideFTP(true); if(m_ftp_inited == true) { in_addr addr; addr.s_addr = net_gethostip(); - m_btnMgr.setText(m_wbfsLblDialog, wfmt(_fmt("dlmsg28", L"Running FTP Server on %s:%d"), inet_ntoa(addr), ftp_server_port)); + m_btnMgr.hide(m_wbfsLblDialog, true); + m_btnMgr.setText(m_ftpLblTitle, wfmt(_t("dlmsg28", L"Running FTP Server on %s:%d"), inet_ntoa(addr), ftp_server_port)); + m_btnMgr.show(m_ftpLblTitle); m_btnMgr.setText(m_ftpBtnToggle, _t("ftp2", L"Stop")); + m_btnMgr.show(m_ftpLblInfo); } else { + m_btnMgr.hide(m_ftpLblTitle, true); m_btnMgr.setText(m_wbfsLblDialog, _t("dlmsg29", L"FTP Server is currently stopped.")); m_btnMgr.setText(m_ftpBtnToggle, _t("ftp1", L"Start")); + m_btnMgr.show(m_wbfsLblDialog); } + _showFTP(); } void CMenu::_FTP(void) { - _showFTP(); _updateFTP(); - m_btnMgr.show(m_wbfsLblDialog); while(!m_exit) { _mainLoopCommon(); @@ -56,13 +64,13 @@ void CMenu::_FTP(void) break; else if(m_btnMgr.selected(m_ftpBtnToggle)) { - gprintf("%d\n", m_ftp_inited); if(m_ftp_inited == true) { ftp_endTread(); m_init_ftp = false; m_ftp_inited = false; init_network = (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_use_wifi_gecko); + ftp_dbg_print_update(); } else { @@ -82,6 +90,11 @@ void CMenu::_FTP(void) _updateFTP(); } } + if(ftp_dbg_print_update()) + { + m_btnMgr.setText(m_ftpLblInfo, wfmt(L"%s%s%s%s%s%s", ftp_get_prints(5), ftp_get_prints(4), + ftp_get_prints(3), ftp_get_prints(2), ftp_get_prints(1), ftp_get_prints(0))); + } } m_btnMgr.hide(m_wbfsLblDialog); _hideFTP(); @@ -91,21 +104,35 @@ void CMenu::_showFTP(void) { m_btnMgr.show(m_ftpBtnToggle); m_btnMgr.show(m_ftpBtnBack); + for(u8 i = 0; i < ARRAY_SIZE(m_ftpLblUser); ++i) + if(m_ftpLblUser[i] != -1) + m_btnMgr.show(m_ftpLblUser[i]); } void CMenu::_hideFTP(bool instant) { + m_btnMgr.hide(m_ftpLblTitle, instant); m_btnMgr.hide(m_ftpBtnToggle, instant); m_btnMgr.hide(m_ftpBtnBack, instant); + m_btnMgr.hide(m_ftpLblInfo, instant); + for(u8 i = 0; i < ARRAY_SIZE(m_ftpLblUser); ++i) + if(m_ftpLblUser[i] != -1) + m_btnMgr.hide(m_ftpLblUser[i], instant); } void CMenu::_initFTP(void) { + _addUserLabels(m_ftpLblUser, ARRAY_SIZE(m_ftpLblUser), "FTP"); + + m_ftpLblTitle = _addTitle("FTP/TITLE", theme.titleFont, L"", 20, 30, 600, 60, theme.titleFontColor, FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE); m_ftpBtnToggle = _addButton("FTP/TOGGLE_BTN", theme.btnFont, L"", 20, 400, 200, 56, theme.btnFontColor); m_ftpBtnBack = _addButton("FTP/BACK_BTN", theme.btnFont, L"", 420, 400, 200, 56, theme.btnFontColor); + m_ftpLblInfo = _addText("FTP/INFO", theme.txtFont, L"", 40, 115, 560, 270, theme.txtFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_TOP); + _setHideAnim(m_ftpLblTitle, "FTP/TITLE", 0, -200, 0.f, 1.f); _setHideAnim(m_ftpBtnToggle, "FTP/TOGGLE_BTN", 0, 0, 1.f, -1.f); _setHideAnim(m_ftpBtnBack, "FTP/BACK_BTN", 0, 0, 1.f, -1.f); + _setHideAnim(m_ftpLblInfo, "FTP/INFO", 0, 100, 0.f, 0.f); _textFTP(); _hideFTP(true); @@ -113,7 +140,9 @@ void CMenu::_initFTP(void) void CMenu::_textFTP(void) { + m_btnMgr.setText(m_ftpLblTitle, L""); m_btnMgr.setText(m_ftpBtnToggle, L""); m_btnMgr.setText(m_ftpBtnBack, _t("cfg10", L"Back")); + m_btnMgr.setText(m_ftpLblInfo, L""); } diff --git a/source/network/FTP_Dir.cpp b/source/network/FTP_Dir.cpp index 5096009a..ef29477e 100644 --- a/source/network/FTP_Dir.cpp +++ b/source/network/FTP_Dir.cpp @@ -33,12 +33,16 @@ char main_path[MAXPATHLEN]; char real_path[MAXPATHLEN]; u8 cur_part = 0; +char dbg_messages[6][128]; + void ftp_init(void) { memset(main_path, 0, MAXPATHLEN); main_path[0] = '/'; memset(real_path, 0, MAXPATHLEN); cur_part = 0; + for(u8 i = 0; i < 6; ++i) + memset(dbg_messages[i], 0, 128); } const char *ftp_getpath(void) @@ -310,6 +314,34 @@ void ftp_endTread(void) cur_server_num = -1; } +bool dbg_msg_change = false; +void ftp_dbg_print(char *dbg_info) +{ + dbg_msg_change = true; + /* for gecko and stuff */ + gprintf(dbg_info); + /* for our gui */ + for(u8 i = 5; i > 0; --i) + memcpy(dbg_messages[i], dbg_messages[i-1], 128); + memcpy(dbg_messages[0], dbg_info, 127); + *(dbg_messages[0]+127) = '\0'; +} + +const char *ftp_get_prints(u8 i) +{ + return dbg_messages[i]; +} + +bool ftp_dbg_print_update(void) +{ + if(dbg_msg_change) + { + dbg_msg_change = false; + return true; + } + return false; +} + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/source/network/FTP_Dir.hpp b/source/network/FTP_Dir.hpp index e819b7f1..b5c662fd 100644 --- a/source/network/FTP_Dir.hpp +++ b/source/network/FTP_Dir.hpp @@ -46,6 +46,10 @@ int ftp_delete(char *path); bool ftp_startThread(void); void ftp_endTread(void); +void ftp_dbg_print(char *dbg_info); +bool ftp_dbg_print_update(void); +const char *ftp_get_prints(u8 i); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/source/network/ftp.c b/source/network/ftp.c index b01a520e..19c2e1d9 100644 --- a/source/network/ftp.c +++ b/source/network/ftp.c @@ -80,7 +80,7 @@ static s32 write_reply(client_t *client, u16 code, char *msg) { char msgbuf[msglen + 1]; if (msgbuf == NULL) return -ENOMEM; strncpy(msgbuf, fmt("%u %s\r\n", code, msg), msglen + 1); - gprintf("Wrote reply: %s", msgbuf); + ftp_dbg_print(fmt("Wrote reply: %s", msgbuf)); return send_exact(client->socket, msgbuf, msglen); } @@ -295,7 +295,7 @@ static s32 ftp_PASV(client_t *client, char *rest __attribute__((unused))) { u32 ip = net_gethostip(); struct in_addr addr; addr.s_addr = ip; - gprintf("Listening for data connections at %s:%u...\n", inet_ntoa(addr), port); + ftp_dbg_print(fmt("Listening for data connections at %s:%u...\n", inet_ntoa(addr), port)); strncpy(reply, fmt("Entering Passive Mode (%u,%u,%u,%u,%u,%u).", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff, (port >> 8) & 0xff, port & 0xff), 49); return write_reply(client, 227, reply); } @@ -318,7 +318,7 @@ static s32 ftp_PORT(client_t *client, char *portspec) { u16 port = ((p1 &0xff) << 8) | (p2 & 0xff); client->address.sin_addr = sin_addr; client->address.sin_port = htons(port); - gprintf("Set client address to %s:%u\n", addr_str, port); + ftp_dbg_print(fmt("Set client address to %s:%u\n", addr_str, port)); return write_reply(client, 200, "PORT command successful."); } @@ -340,13 +340,14 @@ static s32 prepare_data_connection_active(client_t *client) { } client->data_socket = data_socket; - gprintf("Attempting to connect to client at %s:%u\n", inet_ntoa(client->address.sin_addr), ntohs(client->address.sin_port)); + ftp_dbg_print(fmt("Attempting to connect to client at %s:%u\n", + inet_ntoa(client->address.sin_addr), ntohs(client->address.sin_port))); return 0; } static s32 prepare_data_connection_passive(client_t *client) { client->data_socket = client->passive_socket; - gprintf("Waiting for data connections...\n"); + ftp_dbg_print("Waiting for data connections...\n"); return 0; } @@ -554,7 +555,7 @@ static s32 process_command(client_t *client, char *cmd_line) { return 0; } - gprintf("Got command: %s\n", cmd_line); + ftp_dbg_print(fmt("Got command: %s\n", cmd_line)); const char **commands = unauthenticated_commands; const ftp_command_handler *handlers = unauthenticated_handlers; @@ -597,7 +598,7 @@ static void cleanup_client(client_t *client) { num_clients--; if(num_clients == 0) ftp_init(); /* reinit for new clients */ - gprintf("Client disconnected.\n"); + ftp_dbg_print("Client disconnected.\n"); } void cleanup_ftp() { @@ -617,21 +618,21 @@ static bool process_accept_events(s32 server) { socklen_t addrlen = sizeof(client_address); while ((peer = net_accept(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) { if (peer < 0) { - gprintf("Error accepting connection: [%i] %s\n", -peer, strerror(-peer)); + ftp_dbg_print(fmt("Error accepting connection: [%i] %s\n", -peer, strerror(-peer))); return false; } - gprintf("Accepted connection from %s!\n", inet_ntoa(client_address.sin_addr)); + ftp_dbg_print(fmt("Accepted connection from %s!\n", inet_ntoa(client_address.sin_addr))); if (num_clients == MAX_CLIENTS) { - gprintf("Maximum of %u clients reached, not accepting client.\n", MAX_CLIENTS); + ftp_dbg_print(fmt("Maximum of %u clients reached, not accepting client.\n", MAX_CLIENTS)); net_close(peer); return true; } client_t *client = malloc(sizeof(client_t)); if (!client) { - gprintf("Could not allocate memory for client state, not accepting client.\n"); + ftp_dbg_print("Could not allocate memory for client state, not accepting client.\n"); net_close(peer); return true; } @@ -653,7 +654,7 @@ static bool process_accept_events(s32 server) { int client_index; char *welcome = fmt("Welcome to %s (%s-r%s)! This is the ftpii server core.", APP_NAME, APP_VERSION, SVN_REV); if (write_reply(client, 220, welcome) < 0) { - gprintf("Error writing greeting.\n"); + ftp_dbg_print("Error writing greeting.\n"); net_close_blocking(peer); free(client); } else { @@ -682,8 +683,10 @@ static void process_data_events(client_t *client) { } } else if(ftp_allow_active == true) { if ((result = net_connect(client->data_socket, (struct sockaddr *)&client->address, sizeof(client->address))) < 0) { - if (result == -EINPROGRESS || result == -EALREADY) result = -EAGAIN; - if (result != -EAGAIN && result != -EISCONN) gprintf("Unable to connect to client: [%i] %s\n", -result, strerror(-result)); + if(result == -EINPROGRESS || result == -EALREADY) + result = -EAGAIN; + if(result != -EAGAIN && result != -EISCONN) + ftp_dbg_print(fmt("Unable to connect to client: [%i] %s\n", -result, strerror(-result))); } if (result >= 0 || result == -EISCONN) { client->data_connection_connected = true; @@ -691,10 +694,10 @@ static void process_data_events(client_t *client) { } if (client->data_connection_connected) { result = 1; - gprintf("Connected to client! Transferring data...\n"); + ftp_dbg_print("Connected to client! Transferring data...\n"); } else if (gettime() > client->data_connection_timer) { result = -1; - gprintf("Timed out waiting for data connection.\n"); + ftp_dbg_print("Timed out waiting for data connection.\n"); } } else { result = client->data_callback(client->data_socket, client->data_connection_callback_arg); @@ -722,7 +725,7 @@ static void process_control_events(client_t *client) { char *offset_buf = client->buf + client->offset; if ((bytes_read = net_read(client->socket, offset_buf, FTP_BUFFER_SIZE - 1 - client->offset)) < 0) { if (bytes_read != -EAGAIN) { - gprintf("Read error %i occurred, closing client.\n", bytes_read); + ftp_dbg_print(fmt("Read error %i occurred, closing client.\n", bytes_read)); goto recv_loop_end; } return; @@ -733,7 +736,7 @@ static void process_control_events(client_t *client) { client->buf[client->offset] = '\0'; if (strchr(offset_buf, '\0') != (client->buf + client->offset)) { - gprintf("Received a null byte from client, closing connection ;-)\n"); // i have decided this isn't allowed =P + ftp_dbg_print("Received a null byte from client, closing connection ;-)\n"); // i have decided this isn't allowed =P goto recv_loop_end; } @@ -742,7 +745,7 @@ static void process_control_events(client_t *client) { for (next = client->buf; (end = strstr(next, CRLF)) && !client->data_callback; next = end + CRLF_LENGTH) { *end = '\0'; if (strchr(next, '\n')) { - gprintf("Received a line-feed from client without preceding carriage return, closing connection ;-)\n"); // i have decided this isn't allowed =P + ftp_dbg_print("Received a line-feed from client without preceding carriage return, closing connection ;-)\n"); // i have decided this isn't allowed =P goto recv_loop_end; } @@ -750,7 +753,7 @@ static void process_control_events(client_t *client) { s32 result; if ((result = process_command(client, next)) < 0) { if (result != -EQUIT) { - gprintf("Closing connection due to error while processing command: %s\n", next); + ftp_dbg_print(fmt("Closing connection due to error while processing command: %s\n", next)); } goto recv_loop_end; } @@ -765,7 +768,7 @@ static void process_control_events(client_t *client) { memcpy(client->buf, tmp_buf, client->offset); } } - gprintf("Received line longer than %u bytes, closing client.\n", FTP_BUFFER_SIZE - 1); + ftp_dbg_print(fmt("Received line longer than %u bytes, closing client.\n", FTP_BUFFER_SIZE - 1)); recv_loop_end: cleanup_client(client);