From 1debcaeeccd42701f11f9ff1f2170bad1a10c165 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Mon, 14 Mar 2016 23:58:25 +0100 Subject: [PATCH] Added ability to create folders --- source/fs.c | 6 ++++++ source/fs.h | 3 +++ source/godmode.c | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/source/fs.c b/source/fs.c index d1fe654..a2c9a54 100644 --- a/source/fs.c +++ b/source/fs.c @@ -298,6 +298,12 @@ bool PathRename(const char* path, const char* newname) { return (f_rename(path, npath) == FR_OK); } +bool DirCreate(const char* cpath, const char* dirname) { + char npath[256]; // 256 is the maximum length of a full path + snprintf(npath, 255, "%s/%s", cpath, dirname); + return (f_mkdir(npath) == FR_OK); +} + void CreateScreenshot() { const u8 bmp_header[54] = { 0x42, 0x4D, 0x36, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, diff --git a/source/fs.h b/source/fs.h index f0cd179..2fb456f 100644 --- a/source/fs.h +++ b/source/fs.h @@ -52,6 +52,9 @@ bool PathDelete(const char* path); /** Rename file / folder in path to new name **/ bool PathRename(const char* path, const char* newname); +/** Create a new directory in cpath **/ +bool DirCreate(const char* cpath, const char* dirname); + /** Create a screenshot of the current framebuffer **/ void CreateScreenshot(); diff --git a/source/godmode.c b/source/godmode.c index 1f3ec1b..0f8abcc 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -283,7 +283,13 @@ u32 GodMode() { } else if (pad_state & BUTTON_Y) { // create a folder char dirname[256]; snprintf(dirname, 255, "newdir"); - ShowInputPrompt(dirname, 256, "Create a new folder here?\nEnter name below."); + if (ShowInputPrompt(dirname, 256, "Create a new folder here?\nEnter name below.")) { + if (!DirCreate(current_path, dirname)) { + char namestr[20+1]; + TruncateString(namestr, current_dir->entry[cursor].name, 20, 12); + ShowPrompt(false, "Failed creating dir:\n%s", namestr); + } else GetDirContents(current_dir, current_path); + } } }