mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
Pre Filepath cleanup
This commit is contained in:
parent
3aee4fc5e9
commit
7fdaa51678
5 changed files with 48 additions and 44 deletions
|
@ -136,6 +136,8 @@ static bool is_directory(const char *filename) {
|
||||||
* @param dirname
|
* @param dirname
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
// Not used...
|
||||||
|
/*
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define make_dir(a) _mkdir(a)
|
#define make_dir(a) _mkdir(a)
|
||||||
#else
|
#else
|
||||||
|
@ -189,7 +191,7 @@ bool create_path(const char *dirname) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
bool setDefaultPath (savePaths_t pathIndex,const char *Path) {
|
bool setDefaultPath (savePaths_t pathIndex,const char *Path) {
|
||||||
|
|
||||||
if (pathIndex < spItemCount) {
|
if (pathIndex < spItemCount) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ typedef enum {
|
||||||
} DumpFileType_t;
|
} DumpFileType_t;
|
||||||
|
|
||||||
int fileExists(const char *filename);
|
int fileExists(const char *filename);
|
||||||
bool create_path(const char *dirname);
|
//bool create_path(const char *dirname);
|
||||||
bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths
|
bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,9 @@ static char *prefGetFilename(void) {
|
||||||
|
|
||||||
int preferences_load(void) {
|
int preferences_load(void) {
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Looking for preferences...");
|
|
||||||
|
|
||||||
// Set all defaults
|
// Set all defaults
|
||||||
session.client_debug_level = cdbOFF;
|
session.client_debug_level = cdbOFF;
|
||||||
session.device_debug_level = ddbOFF;
|
// session.device_debug_level = ddbOFF;
|
||||||
session.window_changed = false;
|
session.window_changed = false;
|
||||||
session.plot.x = 10;
|
session.plot.x = 10;
|
||||||
session.plot.y = 30;
|
session.plot.y = 30;
|
||||||
|
@ -67,6 +65,11 @@ int preferences_load(void) {
|
||||||
session.show_hints = false;
|
session.show_hints = false;
|
||||||
session.supports_colors = false;
|
session.supports_colors = false;
|
||||||
|
|
||||||
|
setDefaultPath (spDefault, "");
|
||||||
|
setDefaultPath (spDump, "");
|
||||||
|
setDefaultPath (spTrace, "");
|
||||||
|
|
||||||
|
/*
|
||||||
// default save path
|
// default save path
|
||||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||||
setDefaultPath (spDefault, get_my_user_directory());
|
setDefaultPath (spDefault, get_my_user_directory());
|
||||||
|
@ -84,15 +87,20 @@ int preferences_load(void) {
|
||||||
setDefaultPath (spTrace, get_my_user_directory());
|
setDefaultPath (spTrace, get_my_user_directory());
|
||||||
else
|
else
|
||||||
setDefaultPath (spTrace, ".");
|
setDefaultPath (spTrace, ".");
|
||||||
|
*/
|
||||||
|
|
||||||
// loadFileJson wants these, so pass in place holder values, though not used
|
// loadFileJson wants these, so pass in place holder values, though not used
|
||||||
// in settings load;
|
// in settings load;
|
||||||
uint8_t dummyData = 0x00;
|
uint8_t dummyData = 0x00;
|
||||||
size_t dummyDL = 0x00;
|
size_t dummyDL = 0x00;
|
||||||
|
|
||||||
|
// to better control json cant find file error msg.
|
||||||
|
if (fileExists(prefGetFilename())) {
|
||||||
|
PrintAndLogEx(INFO, "Loading Preferences %s",prefGetFilename());
|
||||||
if (loadFileJSON(prefGetFilename(), &dummyData, sizeof(dummyData), &dummyDL) == PM3_SUCCESS) {
|
if (loadFileJSON(prefGetFilename(), &dummyData, sizeof(dummyData), &dummyDL) == PM3_SUCCESS) {
|
||||||
session.preferences_loaded = true;
|
session.preferences_loaded = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Note, if session.settings_loaded == false then the settings_save
|
// Note, if session.settings_loaded == false then the settings_save
|
||||||
// will be called in main () to save settings as set in defaults and main() checks.
|
// will be called in main () to save settings as set in defaults and main() checks.
|
||||||
|
|
||||||
|
@ -194,7 +202,7 @@ void preferences_save_callback(json_t *root) {
|
||||||
default:
|
default:
|
||||||
JsonSaveStr(root, "logging.level", "NORMAL");
|
JsonSaveStr(root, "logging.level", "NORMAL");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
switch (session.device_debug_level) {
|
switch (session.device_debug_level) {
|
||||||
case ddbOFF:
|
case ddbOFF:
|
||||||
JsonSaveStr(root, "device.debug.level", "off");
|
JsonSaveStr(root, "device.debug.level", "off");
|
||||||
|
@ -214,7 +222,7 @@ void preferences_save_callback(json_t *root) {
|
||||||
default:
|
default:
|
||||||
JsonSaveStr(root, "logging.level", "NORMAL");
|
JsonSaveStr(root, "logging.level", "NORMAL");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void preferences_load_callback(json_t *root) {
|
void preferences_load_callback(json_t *root) {
|
||||||
|
@ -280,7 +288,7 @@ void preferences_load_callback(json_t *root) {
|
||||||
|
|
||||||
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "os.supports.colors", &b1) == 0)
|
if (json_unpack_ex(root, &up_error, 0, "{s:b}", "os.supports.colors", &b1) == 0)
|
||||||
session.supports_colors = b1;
|
session.supports_colors = b1;
|
||||||
|
/*
|
||||||
// Logging Level
|
// Logging Level
|
||||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "device.debug.level", &s1) == 0) {
|
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "device.debug.level", &s1) == 0) {
|
||||||
strncpy(tempStr, s1, sizeof(tempStr) - 1);
|
strncpy(tempStr, s1, sizeof(tempStr) - 1);
|
||||||
|
@ -291,7 +299,7 @@ void preferences_load_callback(json_t *root) {
|
||||||
if (strncmp(tempStr, "debug", 5) == 0) session.device_debug_level = ddbDEBUG;
|
if (strncmp(tempStr, "debug", 5) == 0) session.device_debug_level = ddbDEBUG;
|
||||||
if (strncmp(tempStr, "extended", 8) == 0) session.device_debug_level = ddbEXTENDED;
|
if (strncmp(tempStr, "extended", 8) == 0) session.device_debug_level = ddbEXTENDED;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Help Functions
|
// Help Functions
|
||||||
|
@ -328,7 +336,7 @@ static int usage_set_debug() {
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
static int usage_set_devicedebug() {
|
static int usage_set_devicedebug() {
|
||||||
PrintAndLogEx(NORMAL, "Usage: pref set devicedebug <off | error | info | debug | extended>");
|
PrintAndLogEx(NORMAL, "Usage: pref set devicedebug <off | error | info | debug | extended>");
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
|
@ -341,7 +349,7 @@ static int usage_set_devicedebug() {
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
static int usage_set_hints() {
|
static int usage_set_hints() {
|
||||||
PrintAndLogEx(NORMAL, "Usage: pref set hints <off | on>");
|
PrintAndLogEx(NORMAL, "Usage: pref set hints <off | on>");
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
|
@ -426,7 +434,7 @@ void showClientDebugState(prefShowOpt_t Opt) {
|
||||||
PrintAndLogEx(NORMAL, " %s client debug........... "_RED_("unknown"), prefShowMsg(Opt));
|
PrintAndLogEx(NORMAL, " %s client debug........... "_RED_("unknown"), prefShowMsg(Opt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void showDeviceDebugState(prefShowOpt_t Opt) {
|
void showDeviceDebugState(prefShowOpt_t Opt) {
|
||||||
switch (session.device_debug_level) {
|
switch (session.device_debug_level) {
|
||||||
case ddbOFF:
|
case ddbOFF:
|
||||||
|
@ -448,7 +456,7 @@ void showDeviceDebugState(prefShowOpt_t Opt) {
|
||||||
PrintAndLogEx(NORMAL, " %s device debug........... "_RED_("unknown"), prefShowMsg(Opt));
|
PrintAndLogEx(NORMAL, " %s device debug........... "_RED_("unknown"), prefShowMsg(Opt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) {
|
void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) {
|
||||||
|
|
||||||
char tempStr[50];
|
char tempStr[50];
|
||||||
|
@ -466,16 +474,12 @@ void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) {
|
||||||
default:
|
default:
|
||||||
strcpy (tempStr,_RED_("unknown")" save path......");
|
strcpy (tempStr,_RED_("unknown")" save path......");
|
||||||
}
|
}
|
||||||
|
if ((session.defaultPaths[pathIndex] == NULL) || (strcmp(session.defaultPaths[pathIndex],"") == 0))
|
||||||
|
PrintAndLogEx(NORMAL, " %s %s "_WHITE_("not set"), prefShowMsg(Opt),tempStr);
|
||||||
|
else
|
||||||
PrintAndLogEx(NORMAL, " %s %s "_GREEN_("%s"), prefShowMsg(Opt), tempStr, session.defaultPaths[pathIndex]);
|
PrintAndLogEx(NORMAL, " %s %s "_GREEN_("%s"), prefShowMsg(Opt), tempStr, session.defaultPaths[pathIndex]);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void showDumpPathState(prefShowOpt_t Opt) {
|
|
||||||
PrintAndLogEx(NORMAL, " %s dump save path......... "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spDump]);
|
|
||||||
}
|
|
||||||
void showTracePathState(prefShowOpt_t Opt) {
|
|
||||||
PrintAndLogEx(NORMAL, " %s trace save path........ "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spTrace]);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void showPlotPosState(void){
|
void showPlotPosState(void){
|
||||||
PrintAndLogEx(NORMAL, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
PrintAndLogEx(NORMAL, " Plot window............ X "_GREEN_("%4d")" Y "_GREEN_("%4d")" H "_GREEN_("%4d")" W "_GREEN_("%4d"),
|
||||||
session.plot.x, session.plot.y, session.plot.h, session.plot.w);
|
session.plot.x, session.plot.y, session.plot.h, session.plot.w);
|
||||||
|
@ -643,7 +647,7 @@ static int setCmdDebug(const char *Cmd) {
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
static int setCmdDeviceDebug (const char *Cmd)
|
static int setCmdDeviceDebug (const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
|
@ -709,7 +713,7 @@ static int setCmdDeviceDebug (const char *Cmd)
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
static int setCmdHint (const char *Cmd)
|
static int setCmdHint (const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
|
@ -808,8 +812,8 @@ static int setCmdSavePaths (const char *Cmd) {
|
||||||
PrintAndLogEx(ERR,"path does not exist... "_RED_("%s"),newValue);
|
PrintAndLogEx(ERR,"path does not exist... "_RED_("%s"),newValue);
|
||||||
} else {
|
} else {
|
||||||
// do we need to create it
|
// do we need to create it
|
||||||
if (!fileExists(newValue))
|
// if (!fileExists(newValue))
|
||||||
create_path (newValue); //mkdir (newValue,0x777);
|
// create_path (newValue); //mkdir (newValue,0x777);
|
||||||
|
|
||||||
pathItem = spItemCount;
|
pathItem = spItemCount;
|
||||||
if (strncmp(strOpt, "default", 7) == 0) pathItem = spDefault;
|
if (strncmp(strOpt, "default", 7) == 0) pathItem = spDefault;
|
||||||
|
@ -847,9 +851,9 @@ static command_t setCommandTable[] = {
|
||||||
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
|
{"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"},
|
||||||
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
|
{"hints", setCmdHint, AlwaysAvailable, "Set hint display"},
|
||||||
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
|
{"color", setCmdColor, AlwaysAvailable, "Set color support"},
|
||||||
{"defaultsavepaths", setCmdSavePaths, AlwaysAvailable, "Set default save paths"},
|
{"defaultsavepaths", setCmdSavePaths, AlwaysAvailable, "... to be adjusted next ... "},
|
||||||
{"clientdebug", setCmdDebug, AlwaysAvailable, "Set client debug level"},
|
{"clientdebug", setCmdDebug, AlwaysAvailable, "Set client debug level"},
|
||||||
{"devicedebug", setCmdDeviceDebug, AlwaysAvailable, "Set device debug level"},
|
// {"devicedebug", setCmdDeviceDebug, AlwaysAvailable, "Set device debug level"},
|
||||||
{NULL, NULL, NULL, NULL}
|
{NULL, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -870,24 +874,25 @@ int CmdPrefSet(const char *Cmd) {
|
||||||
static int CmdPrefShow(const char *Cmd) {
|
static int CmdPrefShow(const char *Cmd) {
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, _CYAN_("Preferences"));
|
PrintAndLogEx(NORMAL, _CYAN_("Preferences loaded from %s"),prefGetFilename());
|
||||||
|
|
||||||
if (!session.preferences_loaded) {
|
if (!session.preferences_loaded) {
|
||||||
PrintAndLogEx (ERR, "Preferneces not loaded");
|
PrintAndLogEx (ERR, "Preferneces not loaded");
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, " preference file........ "_GREEN_("%s"), prefGetFilename());
|
// PrintAndLogEx(NORMAL, " preference file........ "_GREEN_("%s"), prefGetFilename());
|
||||||
showEmojiState(prefShowNone);
|
showEmojiState(prefShowNone);
|
||||||
showHintsState(prefShowNone);
|
showHintsState(prefShowNone);
|
||||||
showColorState(prefShowNone);
|
showColorState(prefShowNone);
|
||||||
// showPlotPosState ();
|
// showPlotPosState ();
|
||||||
// showOverlayPosState ();
|
// showOverlayPosState ();
|
||||||
showSavePathState(spDefault, prefShowNone);
|
// showSavePathState(spDefault, prefShowNone);
|
||||||
showSavePathState(spDump, prefShowNone);
|
// showSavePathState(spDump, prefShowNone);
|
||||||
showSavePathState(spTrace, prefShowNone);
|
// showSavePathState(spTrace, prefShowNone);
|
||||||
|
|
||||||
showClientDebugState(prefShowNone);
|
showClientDebugState(prefShowNone);
|
||||||
showDeviceDebugState(prefShowNone);
|
// showDeviceDebugState(prefShowNone);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
|
@ -703,10 +703,6 @@ int main(int argc, char *argv[]) {
|
||||||
// Load Settings and assign
|
// Load Settings and assign
|
||||||
// This will allow the command line to override the settings.json values
|
// This will allow the command line to override the settings.json values
|
||||||
preferences_load();
|
preferences_load();
|
||||||
// Change height/width (Rows,Cols) - Testing
|
|
||||||
// printf ("\e[8;50;100t");
|
|
||||||
// printf ("\e[3;50;50t"); // x,y
|
|
||||||
//printf ("Path : %s \n",my_user_directory);
|
|
||||||
// quick patch for debug level
|
// quick patch for debug level
|
||||||
g_debugMode = session.client_debug_level;
|
g_debugMode = session.client_debug_level;
|
||||||
// settings_save ();
|
// settings_save ();
|
||||||
|
@ -980,9 +976,10 @@ int main(int argc, char *argv[]) {
|
||||||
// Doing this here will ensure other checks and updates are saved to over rule default
|
// Doing this here will ensure other checks and updates are saved to over rule default
|
||||||
// e.g. Linux color use check
|
// e.g. Linux color use check
|
||||||
if (!session.preferences_loaded) {
|
if (!session.preferences_loaded) {
|
||||||
|
PrintAndLogEx (INFO,"Creating initial preferences file"); // json save reports file name, so just info msg here
|
||||||
preferences_save(); // Save defaults
|
preferences_save(); // Save defaults
|
||||||
session.preferences_loaded = true;
|
session.preferences_loaded = true;
|
||||||
} else {
|
} /* else {
|
||||||
// Set device debug level
|
// Set device debug level
|
||||||
PrintAndLogEx(INFO,"setting device debug loglevel");
|
PrintAndLogEx(INFO,"setting device debug loglevel");
|
||||||
if (session.pm3_present) {
|
if (session.pm3_present) {
|
||||||
|
@ -994,7 +991,7 @@ int main(int argc, char *argv[]) {
|
||||||
else
|
else
|
||||||
PrintAndLogEx(WARNING,"Proxmark3 not ready to set debug level");
|
PrintAndLogEx(WARNING,"Proxmark3 not ready to set debug level");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_GUI
|
#ifdef HAVE_GUI
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE, HINT} logLevel_t;
|
typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLACE, HINT} logLevel_t;
|
||||||
typedef enum emojiMode {ALIAS, EMOJI, ALTTEXT, ERASE} emojiMode_t;
|
typedef enum emojiMode {ALIAS, EMOJI, ALTTEXT, ERASE} emojiMode_t;
|
||||||
typedef enum clientdebugLevel {cdbOFF, cdbSIMPLE, cdbFULL} clientdebugLevel_t;
|
typedef enum clientdebugLevel {cdbOFF, cdbSIMPLE, cdbFULL} clientdebugLevel_t;
|
||||||
typedef enum devicedebugLevel {ddbOFF, ddbERROR, ddbINFO, ddbDEBUG, ddbEXTENDED} devicedebugLevel_t;
|
// typedef enum devicedebugLevel {ddbOFF, ddbERROR, ddbINFO, ddbDEBUG, ddbEXTENDED} devicedebugLevel_t;
|
||||||
typedef enum savePaths {spDefault, spDump, spTrace, spItemCount} savePaths_t; // last item spItemCount used to auto map to number of files
|
typedef enum savePaths {spDefault, spDump, spTrace, spItemCount} savePaths_t; // last item spItemCount used to auto map to number of files
|
||||||
typedef struct {int x; int y; int h; int w;} qtWindow_t;
|
typedef struct {int x; int y; int h; int w;} qtWindow_t;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ typedef struct {
|
||||||
qtWindow_t overlay;
|
qtWindow_t overlay;
|
||||||
char *defaultPaths[spItemCount]; // Array should allow loop searching for files
|
char *defaultPaths[spItemCount]; // Array should allow loop searching for files
|
||||||
clientdebugLevel_t client_debug_level;
|
clientdebugLevel_t client_debug_level;
|
||||||
uint8_t device_debug_level;
|
// uint8_t device_debug_level;
|
||||||
} session_arg_t;
|
} session_arg_t;
|
||||||
|
|
||||||
extern session_arg_t session;
|
extern session_arg_t session;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue