11#include <stdio.h>
22#include <string.h>
3+ #include <unistd.h>
34
45#include "C2D_helper.h"
56#include "common.h"
67#include "config.h"
78#include "dirbrowse.h"
89#include "fs.h"
9- #include "ftp.h"
10+ //#include "ftp.h"
11+ #include "bftps.h"
1012#include "menu_main.h"
1113#include "status_bar.h"
1214#include "textures.h"
1315#include "touch.h"
1416#include "utils.h"
1517
18+ const char * my_basename (const char * path ) {
19+ const char * pLastSlash = path ;
20+ while (* path != '\0' ) {
21+ if (* path == '/' )
22+ pLastSlash = path + 1 ;
23+ path ++ ;
24+ }
25+ return pLastSlash ;
26+ }
27+
1628void Menu_DisplayFTP (void ) {
17- ftp_init ();
29+
30+ bftps_start ();
1831
1932 Result ret = 0 ;
20- char buf [137 ], hostname [ 128 ];
21- u32 wifi_status = 0 ;
33+ char buf [137 ], buf2 [ 512 ];
34+ u32 wifiStatus = 0 ;
2235
23- int pBar = 0 , xlim = 270 ;
36+ int position = 0 , progress = 0 , xlim = 270 ;
2437
25- ret = gethostname (hostname , sizeof (hostname ));
38+ // ret = gethostname(hostname, sizeof(hostname));
2639
2740 if (R_SUCCEEDED (gspLcdInit ())) {
2841 GSPLCD_PowerOffBacklight (GSPLCD_SCREEN_TOP );
2942 gspLcdExit ();
3043 }
3144
3245 while (MENU_STATE == MENU_STATE_FTP ) {
33- ftp_loop ();
46+ // ftp_loop();
3447
3548 C3D_FrameBegin (C3D_FRAME_SYNCDRAW );
3649 C2D_TargetClear (RENDER_BOTTOM , config .dark_theme ? BLACK_BG : WHITE );
@@ -42,15 +55,56 @@ void Menu_DisplayFTP(void) {
4255
4356 Menu_DrawMenuBar ();
4457
45- if ((wifi_status != 0 ) && R_SUCCEEDED (ret )) {
46- Draw_Text (((320 - Draw_GetTextWidth (0.42f , "FTP initialized" )) / 2 ), 37 , 0.42f , WHITE , "FTP initialized" );
47- snprintf (buf , 137 , "IP: %s:5000" , R_FAILED (ret )? "Failed to get IP" : hostname );
48-
49- if (strlen (ftp_accepted_connection ) != 0 )
50- Draw_Text (((320 - Draw_GetTextWidth (0.42f , ftp_accepted_connection )) / 2 ), 77 , 0.42f , WHITE , ftp_accepted_connection );
51-
52- Draw_Text (((320 - Draw_GetTextWidth (0.42f , "File browser cannot be accesed at this time." )) / 2 ), 97 , 0.42f , WHITE , "File browser cannot be accesed at this time." );
53-
58+ if ((wifiStatus != 0 ) && R_SUCCEEDED (ret )) {
59+ Draw_Text (((320 - Draw_GetTextWidth (0.48f , "FTP initialized" )) / 2 ), 40 , 0.48f , WHITE , "FTP initialized" );
60+ //snprintf(buf, 137, "IP: %s:5000", R_FAILED(ret)? "Failed to get IP" : hostname);
61+ snprintf (buf , 137 , "%s" , bftps_name ());
62+
63+ /* for now I still don't have a list of conected clients
64+ if (strlen(ftp_accepted_connection) != 0)
65+ Draw_Text(((320 - Draw_GetTextWidth(0.48f, ftp_accepted_connection)) / 2), 80, 0.48f, WHITE, ftp_accepted_connection);
66+ */
67+
68+ Draw_Text (((320 - Draw_GetTextWidth (0.48f , "File browser cannot be accessed at this time." )) / 2 ), 100 , 0.48f , WHITE , "File browser cannot be accesed at this time." );
69+
70+ const bftps_file_transfer_t * transfersInfo = bftps_file_transfer_retrieve ();
71+ if (transfersInfo ) {
72+ const bftps_file_transfer_t * file = transfersInfo ;
73+ // while (file) { for now only show the first file on the list
74+ if (file -> mode == FILE_SENDING ) {
75+ float fraction = ((float ) file -> filePosition / (float ) file -> fileSize );
76+ snprintf (buf2 , 512 , "Sending %.2f%%" , fraction * (float ) 100 );
77+ //file name should have an elipsis when is to longer
78+ Draw_Text (((320 - Draw_GetTextWidth (0.45f , buf2 )) / 2 ), 150 , 0.45f , WHITE , buf2 );
79+ Draw_Text (((320 - Draw_GetTextWidth (0.35f , my_basename (file -> name ))) / 2 ), 170 , 0.35f , WHITE , my_basename (file -> name ));
80+ position = 0 ;
81+ progress = round (fraction * (float )xlim );
82+ }
83+ else {
84+ snprintf (buf2 , 512 , "Receiving %.2fMB" ,
85+ ((float ) file -> filePosition / ((float ) 1024 * (float ) 1024 )));
86+ //file name should have an elipsis when is to longer
87+ Draw_Text (((320 - Draw_GetTextWidth (0.45f , buf2 )) / 2 ), 150 , 0.45f , WHITE , buf2 );
88+ Draw_Text (((320 - Draw_GetTextWidth (0.35f , my_basename (file -> name ))) / 2 ), 170 , 0.35f , WHITE , my_basename (file -> name ));
89+ progress = 40 ;
90+ position += 4 ;
91+ if (position >= xlim )
92+ position = 34 ;
93+ }
94+ //aux = aux->next;
95+ //}
96+ bftps_file_transfer_cleanup (transfersInfo );
97+
98+ Draw_Rect (50 , 140 , 220 , 3 , config .dark_theme ? STATUS_BAR_DARK : STATUS_BAR_LIGHT );
99+ Draw_Rect (position , 140 , progress , 3 , WHITE );
100+
101+ // Boundary stuff
102+ Draw_Rect (0 , 140 , 50 , 3 , config .dark_theme ? MENU_BAR_DARK : MENU_BAR_LIGHT );
103+ Draw_Rect (270 , 140 , 50 , 3 , config .dark_theme ? MENU_BAR_DARK : MENU_BAR_LIGHT );
104+
105+ }
106+
107+ /*
54108 if (strlen(ftp_file_transfer) != 0)
55109 Draw_Text(((320 - Draw_GetTextWidth(0.42f, ftp_file_transfer)) / 2), 147, 0.42f, WHITE, ftp_file_transfer);
56110
@@ -66,6 +120,7 @@ void Menu_DisplayFTP(void) {
66120 if (pBar >= xlim)
67121 pBar = 34;
68122 }
123+ */
69124 }
70125 else {
71126 Draw_Text (((320 - Draw_GetTextWidth (0.42f , "Failed to initialize FTP." )) / 2 ), 37 , 0.42f , WHITE , "Failed to initialize FTP." );
@@ -82,11 +137,14 @@ void Menu_DisplayFTP(void) {
82137
83138 if (((kDown & KEY_TOUCH ) && (TouchInRect (73 , 0 , 97 , 20 ))) || (kDown & KEY_SELECT ))
84139 break ;
140+ // so CPU is not doing unneeded extra work, 100ms should made the UI responsive enough, probably we could increase this to 150 mss
141+ usleep (100000 );
85142 }
86143
87- memset (ftp_accepted_connection , 0 , 20 ); // Empty accepted connection address
88- memset (ftp_file_transfer , 0 , 50 ); // Empty transfer status
89- ftp_exit ();
144+ //memset(ftp_accepted_connection, 0, 20); // Empty accepted connection address
145+ //memset(ftp_file_transfer, 0, 50); // Empty transfer status
146+ //ftp_exit();
147+ bftps_stop ();
90148
91149 if (R_SUCCEEDED (gspLcdInit ())) {
92150 GSPLCD_PowerOnBacklight (GSPLCD_SCREEN_TOP );
0 commit comments