66#include " g2d.h"
77#include " gui.h"
88#include " kernel_functions.h"
9+ #include " log.h"
910#include " textures.h"
1011#include " utils.h"
1112
1213static int row = 0 , column = 0 ;
13- static bool copy = false , move = false , options_more = false ;
14+ static bool copy = false , move = false , moreOptions = false ;
1415
1516namespace Options {
1617 static void ResetSelector (void ) {
1718 row = 0 ;
1819 column = 0 ;
1920 }
21+
22+ static void RefreshDirectory (MenuItem &item) {
23+ FS::GetDirList (cfg.cwd , item.entries );
24+ GUI::ResetCheckbox (item);
25+ }
2026
2127 static void HandleMultipleCopy (MenuItem &item, int (*func)()) {
2228 int ret = 0 ;
2329 std::vector<SceIoDirent> entries;
2430
25- if (R_FAILED (ret = FS::GetDirList (item.checked_cwd .data (), entries)))
31+ if (R_FAILED (ret = FS::GetDirList (item.checked_cwd .data (), entries))) {
2632 return ;
33+ }
2734
2835 for (u32 i = 0 ; i < item.checked_copy .size (); i++) {
29- if (item.checked_copy . at (i) ) {
36+ if (item.checked_copy [i] ) {
3037 FS::Copy (entries[i], item.checked_cwd );
38+
3139 if (R_FAILED ((*func)())) {
32- FS::GetDirList (cfg.cwd , item.entries );
33- GUI::ResetCheckbox (item);
40+ Options::RefreshDirectory (item);
3441 break ;
3542 }
3643 }
3744 }
3845
39- FS::GetDirList (cfg.cwd , item.entries );
40- GUI::ResetCheckbox (item);
41- entries.clear ();
46+ Options::RefreshDirectory (item);
4247 }
4348
4449 static void CreateFolder (MenuItem &item) {
4550 std::string name = G2D::KeyboardGetText (" Enter folder name" , " New folder" );
4651 std::string path = FS::BuildPath (cfg.cwd , name);
4752
4853 if (R_SUCCEEDED (FS::MakeDir (path.c_str ()))) {
49- FS::GetDirList (cfg.cwd , item.entries );
50- GUI::ResetCheckbox (item);
54+ Options::RefreshDirectory (item);
5155 }
5256 }
5357
@@ -56,8 +60,7 @@ namespace Options {
5660 std::string path = FS::BuildPath (cfg.cwd , name);
5761
5862 if (R_SUCCEEDED (FS::CreateFile (path.c_str ()))) {
59- FS::GetDirList (cfg.cwd , item.entries );
60- GUI::ResetCheckbox (item);
63+ Options::RefreshDirectory (item);
6164 }
6265 }
6366
@@ -73,28 +76,33 @@ namespace Options {
7376#endif
7477 FS::GetDirList (cfg.cwd , item.entries );
7578 Options::ResetSelector ();
76- options_more = false ;
79+ moreOptions = false ;
7780 item.state = MENU_STATE_FILEBROWSER;
7881 }
7982 }
8083
8184 static void Copy (MenuItem &item) {
8285 if (!copy) {
83- if ((item.checked_count >= 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 ))
86+ if ((item.checked_count >= 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 )) {
8487 GUI::ResetCheckbox (item);
85- if (item.checked_count <= 1 )
88+ }
89+ if (item.checked_count <= 1 ) {
8690 FS::Copy (item.entries [item.selected ], cfg.cwd );
91+ }
8792
8893 copy = !copy;
8994 item.state = MENU_STATE_FILEBROWSER;
9095 }
9196 else {
92- if ((item.checked_count > 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 ))
97+ Log::Error (" In !copy\n " );
98+ if ((item.checked_count > 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 )) {
99+ Log::Error (" In !copy IF\n " );
93100 Options::HandleMultipleCopy (item, &FS::Paste);
101+ }
94102 else {
103+ Log::Error (" In !copy ELSE\n " );
95104 if (R_SUCCEEDED (FS::Paste ())) {
96- FS::GetDirList (cfg.cwd , item.entries );
97- GUI::ResetCheckbox (item);
105+ Options::RefreshDirectory (item);
98106 }
99107 }
100108
@@ -106,18 +114,20 @@ namespace Options {
106114
107115 static void Move (MenuItem &item) {
108116 if (!move) {
109- if ((item.checked_count >= 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 ))
117+ if ((item.checked_count >= 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 )) {
110118 GUI::ResetCheckbox (item);
119+ }
111120
112- if (item.checked_count <= 1 )
121+ if (item.checked_count <= 1 ) {
113122 FS::Copy (item.entries [item.selected ], cfg.cwd );
123+ }
114124 }
115125 else {
116- if ((item.checked_count > 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 ))
126+ if ((item.checked_count > 1 ) && (item.checked_cwd .compare (cfg.cwd ) != 0 )) {
117127 Options::HandleMultipleCopy (item, &FS::Move);
128+ }
118129 else if (R_SUCCEEDED (FS::Move ())) {
119- FS::GetDirList (cfg.cwd , item.entries );
120- GUI::ResetCheckbox (item);
130+ Options::RefreshDirectory (item);
121131 }
122132 }
123133
@@ -128,34 +138,44 @@ namespace Options {
128138
129139namespace GUI {
130140 void DisplayFileOptions (MenuItem &item) {
141+ int cancelWidth = intraFontMeasureText (font, " CANCEL" );
142+
131143 G2D::DrawRect (0 , 18 , 480 , 254 , G2D_RGBA (0 , 0 , 0 , cfg.dark_theme ? 50 : 80 ));
132144 G2D::DrawImage (options_dialog[cfg.dark_theme ], (480 - options_dialog[0 ]->w ) / 2 , (272 - options_dialog[0 ]->h ) / 2 );
133145 G2D::FontSetStyle (1 .f , TITLE_COLOUR, INTRAFONT_ALIGN_LEFT);
134146 G2D::DrawText (140 , 52 , " Actions" );
135147
136- if (row == 0 && column == 0 )
148+ if (row == 0 && column == 0 ) {
137149 G2D::DrawRect (132 , 71 , 107 , 38 , SELECTOR_COLOUR);
138- else if (row == 1 && column == 0 )
150+ }
151+ else if (row == 1 && column == 0 ) {
139152 G2D::DrawRect (241 , 71 , 107 , 38 , SELECTOR_COLOUR);
140- else if (row == 0 && column == 1 )
153+ }
154+ else if (row == 0 && column == 1 ) {
141155 G2D::DrawRect (132 , 110 , 107 , 38 , SELECTOR_COLOUR);
142- else if (row == 1 && column == 1 )
156+ }
157+ else if (row == 1 && column == 1 ) {
143158 G2D::DrawRect (241 , 110 , 107 , 38 , SELECTOR_COLOUR);
144- else if (row == 0 && column == 2 && !options_more)
159+ }
160+ else if (row == 0 && column == 2 && !moreOptions) {
145161 G2D::DrawRect (132 , 148 , 107 , 38 , SELECTOR_COLOUR);
146- else if (row == 1 && column == 2 && !options_more)
162+ }
163+ else if (row == 1 && column == 2 && !moreOptions) {
147164 G2D::DrawRect (241 , 148 , 107 , 38 , SELECTOR_COLOUR);
148- else if (column == 3 && !options_more)
149- G2D::DrawRect ((340 - intraFontMeasureText (font, " CANCEL" )) - 5 , (230 - (font->texYSize - 6 )) - 5 , intraFontMeasureText (font, " CANCEL" ) + 10 ,
165+ }
166+ else if (column == 3 && !moreOptions) {
167+ G2D::DrawRect ((340 - cancelWidth) - 5 , (230 - (font->texYSize - 6 )) - 5 , cancelWidth + 10 ,
150168 (font->texYSize - 6 ) + 10 , SELECTOR_COLOUR);
151- else if (column == 2 && options_more)
152- G2D::DrawRect ((340 - intraFontMeasureText (font, " CANCEL" )) - 5 , (230 - (font->texYSize - 6 )) - 5 , intraFontMeasureText (font, " CANCEL" ) + 10 ,
169+ }
170+ else if (column == 2 && moreOptions) {
171+ G2D::DrawRect ((340 - cancelWidth) - 5 , (230 - (font->texYSize - 6 )) - 5 , cancelWidth + 10 ,
153172 (font->texYSize - 6 ) + 10 , SELECTOR_COLOUR);
173+ }
154174
155- G2D::DrawText (340 - intraFontMeasureText (font, " CANCEL " ) , 230 - (font->texYSize - 15 ), " CANCEL" );
175+ G2D::DrawText (340 - cancelWidth , 230 - (font->texYSize - 15 ), " CANCEL" );
156176 G2D::FontSetStyle (1 .f , TEXT_COLOUR, INTRAFONT_ALIGN_LEFT);
157177
158- if (!options_more ) {
178+ if (!moreOptions ) {
159179 G2D::DrawText (143 , 95 , " Properties" );
160180 G2D::DrawText (143 , 133 , copy? " Paste" : " Copy" );
161181 G2D::DrawText (143 , 171 , " Delete" );
@@ -171,84 +191,97 @@ namespace GUI {
171191 }
172192
173193 void ControlFileOptions (MenuItem &item, int &ctrl) {
174- if (ctrl & PSP_CTRL_RIGHT)
194+ if (ctrl & PSP_CTRL_RIGHT) {
175195 row++;
176- else if (ctrl & PSP_CTRL_LEFT)
196+ }
197+ else if (ctrl & PSP_CTRL_LEFT) {
177198 row--;
199+ }
178200
179- if (ctrl & PSP_CTRL_DOWN)
201+ if (ctrl & PSP_CTRL_DOWN) {
180202 column++;
181- else if (ctrl & PSP_CTRL_UP)
203+ }
204+ else if (ctrl & PSP_CTRL_UP) {
182205 column--;
206+ }
183207
184- if (!options_more ) {
208+ if (!moreOptions ) {
185209 Utils::SetBounds (row, 0 , 1 );
186210 Utils::SetBounds (column, 0 , 3 );
187211 }
188212 else {
189213 Utils::SetBounds (column, 0 , 2 );
190214
191- if (column == 1 )
215+ if (column == 1 ) {
192216 Utils::SetBounds (row, 0 , 0 );
193- else
217+ }
218+ else {
194219 Utils::SetBounds (row, 0 , 1 );
220+ }
195221 }
196222
197223 if (Utils::IsButtonPressed (PSP_CTRL_ENTER)) {
198- const std::string filename = item.entries [item.selected ].d_name ;
199-
200224 if (row == 0 ) {
201- if (!options_more ) {
202- if (column == 0 )
225+ if (!moreOptions ) {
226+ if (column == 0 ) {
203227 item.state = MENU_STATE_PROPERTIES;
204- else if (column == 1 )
228+ }
229+ else if (column == 1 ) {
205230 Options::Copy (item);
206- else if (column == 2 )
231+ }
232+ else if (column == 2 ) {
207233 item.state = MENU_STATE_DELETE;
234+ }
208235 }
209236 else {
210- if (column == 0 )
237+ if (column == 0 ) {
211238 Options::CreateFolder (item);
212- else if (column == 1 )
213- Options::Rename (item, filename);
239+ }
240+ else if (column == 1 ) {
241+ Options::Rename (item, item.entries [item.selected ].d_name );
242+ }
214243 }
215244 }
216245 else if (row == 1 ) {
217- if (!options_more ) {
246+ if (!moreOptions ) {
218247 if (column == 0 ) {
219248 FS::GetDirList (cfg.cwd , item.entries );
220249 Options::ResetSelector ();
221- options_more = false ;
250+ moreOptions = false ;
222251 item.selected = 0 ;
223252 item.state = MENU_STATE_FILEBROWSER;
224253 }
225- else if (column == 1 )
254+ else if (column == 1 ) {
226255 Options::Move (item);
256+ }
227257 else if (column == 2 ) {
228258 Options::ResetSelector ();
229- options_more = true ;
259+ moreOptions = true ;
230260 }
231261 }
232262 else {
233- if (column == 0 )
263+ if (column == 0 ) {
234264 Options::CreateFile (item);
265+ }
235266 }
236267 }
237268 if (column == 3 ) {
238269 copy = false ;
239270 move = false ;
240271 Options::ResetSelector ();
241- options_more = false ;
272+ moreOptions = false ;
242273 item.state = MENU_STATE_FILEBROWSER;
243274 }
244275 }
245276 if (Utils::IsButtonPressed (PSP_CTRL_CANCEL)) {
246277 Options::ResetSelector ();
247278
248- if (!options_more)
279+ if (!moreOptions) {
249280 item.state = MENU_STATE_FILEBROWSER;
250- else
251- options_more = false ;
281+ }
282+ else {
283+ moreOptions = false ;
284+ }
252285 }
253286 }
254287}
0 commit comments