From 0b43252a020919d8c669b2091f73e75a109db617 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Tue, 14 Apr 2020 19:17:00 +1000 Subject: [PATCH 1/2] Test code for full path --- client/preferences.c | 30 ++++++++++++++++++++++++++++-- client/proxmark3.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/client/preferences.c b/client/preferences.c index 434c5d493..f1f2d7e50 100644 --- a/client/preferences.c +++ b/client/preferences.c @@ -23,7 +23,8 @@ #include #include "cmdparser.h" #include -#include +// #include +#include //#include "proxgui.h" //extern void SetWindowsPosition (void); @@ -31,6 +32,14 @@ static int CmdHelp(const char *Cmd); static int setCmdHelp(const char *Cmd); // Load all settings into memory (struct) +#ifdef _WIN32 +#include +#define GetCurrentDir _getcwd +#else +#include +#define GetCurrentDir getcwd +#endif + static char* prefGetFilename (void) { /* static char Buffer[FILENAME_MAX+sizeof(preferencesFilename)+2] = {0}; @@ -45,7 +54,24 @@ static char* prefGetFilename (void) { return Buffer; */ - return preferencesFilename; + static char Buffer [FILENAME_MAX] = {0}; + char *Path; + + // int searchHomeFilePath(char **foundpath, const char *filename, bool create_home); + if (searchHomeFilePath(&Path,preferencesFilename,false) == PM3_SUCCESS) { + snprintf(Buffer,sizeof(Buffer)-1,"%s",Path); + } else { + snprintf(Buffer,sizeof(Buffer)-1,"%s",preferencesFilename); + } + + + //printf ("%s [%s]\n",Buffer,get_my_user_directory() ); + + // GetCurrentDir (Buffer,sizeof(Buffer)); + // printf ("%s\n",Buffer, ); + + return Buffer; + //return preferencesFilename; } int preferences_load (void) { diff --git a/client/proxmark3.c b/client/proxmark3.c index e1d6556b6..559741bfa 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -29,8 +29,20 @@ #include "flash.h" #include "preferences.h" +// mwalker33 test code + +#ifdef _WIN32 +#include +#define GetCurrentDir _getcwd +#else +#include +#define GetCurrentDir getcwd +#endif + +// end test code + // Used to enable/disable use of preferences json file -// #define USE_PREFERENCE_FILE +#define USE_PREFERENCE_FILE #ifdef _WIN32 @@ -392,15 +404,25 @@ static void set_my_executable_path(void) { static const char *my_user_directory = NULL; +// mwalker33 test code +static char _cwd_Buffer [FILENAME_MAX] = {0}; +// end test code + const char *get_my_user_directory(void) { return my_user_directory; } - static void set_my_user_directory(void) { my_user_directory = getenv("HOME"); // if not found, default to current directory - if (my_user_directory == NULL) - my_user_directory = "."; + if (my_user_directory == NULL) { +// mwalker33 test code + my_user_directory = GetCurrentDir ( _cwd_Buffer,sizeof( _cwd_Buffer)); + // change all slashs to / (windows should not care... + for (int i = 0; i < strlen(_cwd_Buffer); i++) + if (_cwd_Buffer[i] == '\\') _cwd_Buffer[i] = '/'; +// end + // my_user_directory = "."; + } } static void show_help(bool showFullHelp, char *exec_name) { From 5545219f824a3197fd8a5630ba5e0905afd5e632 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Wed, 15 Apr 2020 16:40:28 +1000 Subject: [PATCH 2/2] Update Full Path --- client/preferences.c | 38 ++++++++------------------------------ client/proxmark3.c | 10 +--------- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/client/preferences.c b/client/preferences.c index f1f2d7e50..138f38528 100644 --- a/client/preferences.c +++ b/client/preferences.c @@ -41,41 +41,18 @@ static int setCmdHelp(const char *Cmd); #endif static char* prefGetFilename (void) { - /* - static char Buffer[FILENAME_MAX+sizeof(preferencesFilename)+2] = {0}; - char PATH[FILENAME_MAX] = {0}; - - getcwd(PATH, sizeof(PATH)); -#ifdef _WIN32 - snprintf (Buffer,sizeof(Buffer)-1,"%s\\%s",PATH,preferencesFilename); -#else - snprintf (Buffer,sizeof(Buffer)-1,"%s/%s",PATH,preferencesFilename); -#endif - - return Buffer; - */ - static char Buffer [FILENAME_MAX] = {0}; char *Path; - - // int searchHomeFilePath(char **foundpath, const char *filename, bool create_home); - if (searchHomeFilePath(&Path,preferencesFilename,false) == PM3_SUCCESS) { - snprintf(Buffer,sizeof(Buffer)-1,"%s",Path); - } else { - snprintf(Buffer,sizeof(Buffer)-1,"%s",preferencesFilename); - } - - - //printf ("%s [%s]\n",Buffer,get_my_user_directory() ); - - // GetCurrentDir (Buffer,sizeof(Buffer)); - // printf ("%s\n",Buffer, ); - - return Buffer; - //return preferencesFilename; + + if (searchHomeFilePath(&Path,preferencesFilename,false) == PM3_SUCCESS) + return Path; + else + return preferencesFilename; } int preferences_load (void) { + PrintAndLogEx(INFO,"Looking for preferences..."); + // Set all defaults session.client_debug_level = OFF; session.window_changed = false; @@ -580,6 +557,7 @@ static int CmdPrefShow (const char *Cmd) { return PM3_ESOFT; } + PrintAndLogEx(NORMAL," Preference file........ "_GREEN_("%s"),prefGetFilename()); showEmojiState (prefShowNone); showColorState (prefShowNone); // showPlotPosState (); diff --git a/client/proxmark3.c b/client/proxmark3.c index 559741bfa..cebe4529e 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -29,8 +29,6 @@ #include "flash.h" #include "preferences.h" -// mwalker33 test code - #ifdef _WIN32 #include #define GetCurrentDir _getcwd @@ -39,8 +37,6 @@ #define GetCurrentDir getcwd #endif -// end test code - // Used to enable/disable use of preferences json file #define USE_PREFERENCE_FILE @@ -403,24 +399,20 @@ static void set_my_executable_path(void) { } static const char *my_user_directory = NULL; - -// mwalker33 test code static char _cwd_Buffer [FILENAME_MAX] = {0}; -// end test code const char *get_my_user_directory(void) { return my_user_directory; } static void set_my_user_directory(void) { my_user_directory = getenv("HOME"); + // if not found, default to current directory if (my_user_directory == NULL) { -// mwalker33 test code my_user_directory = GetCurrentDir ( _cwd_Buffer,sizeof( _cwd_Buffer)); // change all slashs to / (windows should not care... for (int i = 0; i < strlen(_cwd_Buffer); i++) if (_cwd_Buffer[i] == '\\') _cwd_Buffer[i] = '/'; -// end // my_user_directory = "."; } }