Skip to content

Commit 0a5cbbc

Browse files
committed
Minor improvements to recursive copy and
- Also use smaller sizes when calling malloc. I'm pretty sure we didn't need to allocate 1024 bytes. - Also 33 characters are the most that can be viewed on the top screen's CWD display.
1 parent 75763e2 commit 0a5cbbc

6 files changed

Lines changed: 47 additions & 15 deletions

File tree

include/file/dirlist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct File
1818
int isDir; // Folder flag
1919
int isReadOnly; // Read-only flag
2020
int isHidden; // Hidden file flag
21-
char name[256]; // File name
21+
u8 name[256]; // File name
2222
char ext[4]; // File extension
2323
u64 size; // File size
2424
} File;

source/file/dirlist.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Result updateList(int clearindex)
115115
if (R_SUCCEEDED(ret = FSDIR_Read(dirHandle, &entryCount, MAX_FILES, entries)))
116116
{
117117
qsort(entries, entryCount, sizeof(FS_DirectoryEntry), cmpstringp);
118-
char name[255] = {'\0'};
118+
u8 name[255] = {'\0'};
119119

120120
for (u32 i = 0; i < entryCount; i++)
121121
{

source/file/file_operations.c

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ Result copy_folder_recursive(char * src, char * dst)
304304

305305
if (R_SUCCEEDED(ret = FSDIR_Read(dirHandle, &entryCount, MAX_FILES, entries)))
306306
{
307-
char name[255] = {'\0'};
307+
u8 name[255] = {'\0'};
308308
for (u32 i = 0; i < entryCount; i++)
309309
{
310310
u16_to_u8(&name[0], entries[i].name, 254);
@@ -335,8 +335,41 @@ Result copy_folder_recursive(char * src, char * dst)
335335
copy_folder_recursive(inbuffer, outbuffer); // Copy folder (via recursion)
336336

337337
else
338-
copy_file(inbuffer, outbuffer, false); // Copy file
339-
338+
{
339+
if (copyFromNand)
340+
{
341+
FS_Archive sd, nand;
342+
openArchive(&sd, ARCHIVE_SDMC);
343+
openArchive(&nand, ARCHIVE_NAND_CTR_FS);
344+
345+
ret = copy_file_archive(nand, sd, ARCHIVE_NAND_CTR_FS, ARCHIVE_SDMC, inbuffer, outbuffer);
346+
347+
closeArchive(sd);
348+
closeArchive(nand);
349+
350+
if (R_FAILED(ret))
351+
return ret;
352+
}
353+
else if ((copyFromSD) && (BROWSE_STATE == STATE_NAND))
354+
{
355+
FS_Archive sd, nand;
356+
openArchive(&sd, ARCHIVE_SDMC);
357+
openArchive(&nand, ARCHIVE_NAND_CTR_FS);
358+
359+
ret = copy_file_archive(sd, nand, ARCHIVE_SDMC, ARCHIVE_NAND_CTR_FS, inbuffer, outbuffer);
360+
361+
closeArchive(sd);
362+
closeArchive(nand);
363+
364+
if (R_FAILED(ret))
365+
return ret;
366+
}
367+
else
368+
{
369+
if (R_FAILED(ret = ret = copy_file(inbuffer, outbuffer, false))) // Copy file
370+
return ret;
371+
}
372+
}
340373

341374
if (!isMovingToBin)
342375
drawProgress(copymode == 1? "Moving" : "Copying", basename(name), i, entryCount);

source/menus/menu_main.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ void menu_displayMainMenu(void)
8181
{
8282
screen_draw_string(170, 109, 0.45f, 0.45f, RGBA8(Options_text_colour.r, Options_text_colour.g, Options_text_colour.b, 255), lang_options[language][4]);
8383
screen_draw_string(170, 146, 0.45f, 0.45f, RGBA8(Options_text_colour.r, Options_text_colour.g, Options_text_colour.b, 255), lang_options[language][6]);
84-
}
85-
84+
}
8685
}
8786
else
8887
screen_draw_texture(TEXTURE_OPTIONS_ICON, 25, 0);
@@ -182,7 +181,7 @@ void menu_displayMainMenu(void)
182181

183182
screen_draw_texture(TEXTURE_BACKGROUND, 0, 0);
184183

185-
screen_draw_stringf(84, 28, 0.45f, 0.45f, RGBA8(TopScreen_bar_colour.r, TopScreen_bar_colour.g, TopScreen_bar_colour.b, 255), "%.35s", cwd); // Display current path
184+
screen_draw_stringf(84, 28, 0.45f, 0.45f, RGBA8(TopScreen_bar_colour.r, TopScreen_bar_colour.g, TopScreen_bar_colour.b, 255), "%.33s", cwd); // Display current path
186185

187186
drawStatusBar();
188187

source/theme.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Result saveThemeConfig(char * themePath, char * coloursPath)
4747
{
4848
Result ret = 0;
4949

50-
char * buf = (char *)malloc(1024);
51-
snprintf(buf, 1024, themeConfig, themePath, coloursPath);
50+
char * buf = (char *)malloc(512);
51+
snprintf(buf, 512, themeConfig, themePath, coloursPath);
5252

5353
if (R_FAILED(ret = fsWrite(fsArchive, "/3ds/3DShell/theme.cfg", buf)))
5454
return ret;
@@ -87,8 +87,8 @@ static Result createFontColours(void)
8787
{
8888
Result ret = 0;
8989

90-
char * buf = (char *)malloc(1024);
91-
snprintf(buf, 1024, coloursConfig, 48, 174, 222,
90+
char * buf = (char *)malloc(512);
91+
snprintf(buf, 512, coloursConfig, 48, 174, 222,
9292
255, 255, 255,
9393
0, 0, 0,
9494
95, 95, 95,

source/utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Result saveConfig(int sortBy, bool recycleBin, bool protection, bool hidden)
1616
{
1717
Result ret = 0;
1818

19-
char * buf = (char *)malloc(1024);
20-
snprintf(buf, 1024, configFile, sortBy, recycleBin, protection, hidden);
19+
char * buf = (char *)malloc(256);
20+
snprintf(buf, 256, configFile, sortBy, recycleBin, protection, hidden);
2121

2222
if (R_FAILED(ret = fsWrite(fsArchive, "/3ds/3DShell/config.cfg", buf)))
2323
return ret;
@@ -83,7 +83,7 @@ Result getLastDirectory(void)
8383

8484
buf[size] = '\0';
8585

86-
char tempPath[250];
86+
char tempPath[256];
8787
sscanf(buf, "%[^\n]s", tempPath);
8888

8989
if (dirExists(fsArchive, tempPath)) // Incase a directory previously visited had been deleted, set start path to sdmc:/ to avoid errors.

0 commit comments

Comments
 (0)