Merge pull request #687 from mwalker33/Settings-2

Settings - full path name
This commit is contained in:
Iceman 2020-04-15 09:34:51 +02:00 committed by GitHub
commit 5c511d35a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 17 deletions

View file

@ -23,7 +23,8 @@
#include <string.h>
#include "cmdparser.h"
#include <ctype.h>
#include <unistd.h>
// #include <unistd.h>
#include <proxmark3.h>
//#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 <direct.h>
#define GetCurrentDir _getcwd
#else
snprintf (Buffer,sizeof(Buffer)-1,"%s/%s",PATH,preferencesFilename);
#include <unistd.h>
#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 ();

View file

@ -29,8 +29,16 @@
#include "flash.h"
#include "preferences.h"
#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#else
#include <unistd.h>
#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) {