diff --git a/client/preferences.c b/client/preferences.c index 434c5d493..138f38528 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,25 +32,27 @@ static int CmdHelp(const char *Cmd); static int setCmdHelp(const char *Cmd); // Load all settings into memory (struct) -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); +#include +#define GetCurrentDir _getcwd #else - snprintf (Buffer,sizeof(Buffer)-1,"%s/%s",PATH,preferencesFilename); -#endif +#include +#define GetCurrentDir getcwd +#endif - return Buffer; - */ - return preferencesFilename; +static char* prefGetFilename (void) { + char *Path; + + 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; @@ -554,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 e1d6556b6..cebe4529e 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -29,8 +29,16 @@ #include "flash.h" #include "preferences.h" +#ifdef _WIN32 +#include +#define GetCurrentDir _getcwd +#else +#include +#define GetCurrentDir getcwd +#endif + // Used to enable/disable use of preferences json file -// #define USE_PREFERENCE_FILE +#define USE_PREFERENCE_FILE #ifdef _WIN32 @@ -391,16 +399,22 @@ static void set_my_executable_path(void) { } static const char *my_user_directory = NULL; +static char _cwd_Buffer [FILENAME_MAX] = {0}; 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) { + 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] = '/'; + // my_user_directory = "."; + } } static void show_help(bool showFullHelp, char *exec_name) {