From 67923556da783eb2d764fcae0ff287ee54d84907 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Thu, 8 Dec 2016 22:19:42 +0100 Subject: [PATCH] Show a warning when a file is currently locked (on A button) --- source/common.h | 2 +- source/fs.c | 9 +++++++++ source/fs.h | 3 +++ source/godmode.c | 4 +++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/source/common.h b/source/common.h index 1d03b13..b7b1e85 100644 --- a/source/common.h +++ b/source/common.h @@ -38,7 +38,7 @@ (((v) % (a)) ? ((v) + (a) - ((v) % (a))) : (v)) // GodMode9 version -#define VERSION "0.8.3" +#define VERSION "0.8.4" // input / output paths #define INPUT_PATHS "0:", "0:/files9", "0:/Decrypt9" diff --git a/source/fs.c b/source/fs.c index e446515..fdb1cb9 100644 --- a/source/fs.c +++ b/source/fs.c @@ -402,6 +402,15 @@ u32 GetWritePermissions() { return write_permissions; } +bool FileCheck(const char* path) { + FIL file; + if (PathToNumFSA(path) < 0) return true; + if (f_open(&file, path, FA_READ | FA_OPEN_EXISTING) == FR_OK) { + f_close(&file); + return true; + } else return false; +} + bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset, bool create) { int drvtype = DriveType(path); if (!CheckWritePermissions(path)) return false; diff --git a/source/fs.h b/source/fs.h index e04df08..cc6b352 100644 --- a/source/fs.h +++ b/source/fs.h @@ -64,6 +64,9 @@ bool SetWritePermissions(u32 perm, bool add_perm); /** Get write permissions */ u32 GetWritePermissions(); +/** True if file exists and is not locked, false otherwise **/ +bool FileCheck(const char* path); + /** Create / open file and write the provided data to it **/ bool FileSetData(const char* path, const u8* data, size_t size, size_t foffset, bool create); diff --git a/source/godmode.c b/source/godmode.c index 2d318c0..41e44ba 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -700,7 +700,9 @@ u32 GodMode() { (filetype == GAME_NCCH) ? "Mount as NCCH image" : "???"; if (searchdrv > 0) optionstr[searchdrv-1] = "Open containing folder"; - int user_select = ShowSelectPrompt(n_opt, optionstr, pathstr); + int user_select = 0; + if (!FileCheck(curr_entry->path)) ShowPrompt(false, "%s\nFile is currently locked", pathstr); + else user_select = ShowSelectPrompt(n_opt, optionstr, pathstr); if (user_select == hexviewer) { // -> show in hex viewer HexViewer(curr_entry->path); } else if (user_select == calcsha) { // -> calculate SHA-256