mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
streamline works
This commit is contained in:
parent
5060a52b3a
commit
600e5d7d6f
4 changed files with 112 additions and 64 deletions
|
@ -139,7 +139,7 @@ static bool is_directory(const char *filename) {
|
|||
#ifdef _WIN32
|
||||
#define make_dir(a) _mkdir(a)
|
||||
#else
|
||||
#define make_dir(a) mkdir(a,0755)
|
||||
#define make_dir(a) mkdir(a,0755) //note 0755 MUST have leading 0 for octal linux file permissions
|
||||
#endif
|
||||
bool create_path(const char *dirname) {
|
||||
|
||||
|
@ -190,6 +190,24 @@ bool create_path(const char *dirname) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool setDefaultPath (savePaths_t pathIndex,const char *Path) {
|
||||
|
||||
if (pathIndex < spItemCount) {
|
||||
if ((Path == NULL) && (session.defaultPaths[pathIndex] != NULL)) {
|
||||
free (session.defaultPaths[pathIndex]);
|
||||
session.defaultPaths[pathIndex] = NULL;
|
||||
}
|
||||
|
||||
if (Path != NULL) {
|
||||
session.defaultPaths[pathIndex] = (char *)realloc(session.defaultPaths[pathIndex], strlen(Path) + 1);
|
||||
strcpy(session.defaultPaths[pathIndex], Path);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static char *filenamemcopy(const char *preferredName, const char *suffix) {
|
||||
if (preferredName == NULL) return NULL;
|
||||
|
|
|
@ -75,6 +75,8 @@ typedef enum {
|
|||
|
||||
int fileExists(const char *filename);
|
||||
bool create_path(const char *dirname);
|
||||
bool setDefaultPath (savePaths_t pathIndex,const char *Path); // set a path in the path list session.defaultPaths
|
||||
|
||||
|
||||
/**
|
||||
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that
|
||||
|
|
|
@ -67,31 +67,23 @@ int preferences_load(void) {
|
|||
session.show_hints = false;
|
||||
session.supports_colors = false;
|
||||
|
||||
// default save path
|
||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||
setDefaultPath (spDefault, get_my_user_directory());
|
||||
else
|
||||
setDefaultPath (spDefault, ".");
|
||||
|
||||
// default save path
|
||||
if (get_my_user_directory() != NULL) { // should return path to .proxmark3 folder
|
||||
session.defaultPaths[spDefault] = (char *)realloc(session.defaultPaths[spDefault], strlen(get_my_user_directory()) + 1); //, sizeof(uint8_t));
|
||||
strcpy(session.defaultPaths[spDefault], get_my_user_directory());
|
||||
} else {
|
||||
session.defaultPaths[spDefault] = (char *)realloc(session.defaultPaths[spDefault], 2); // 2, sizeof(uint8_t));
|
||||
strcpy(session.defaultPaths[spDefault], ".");
|
||||
}
|
||||
// default dump path
|
||||
if (get_my_user_directory() != NULL) { // should return path to .proxmark3 folder
|
||||
session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], strlen(get_my_user_directory()) + 1); //, sizeof(uint8_t));
|
||||
strcpy(session.defaultPaths[spDump], get_my_user_directory());
|
||||
} else {
|
||||
session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], 2); // 2, sizeof(uint8_t));
|
||||
strcpy(session.defaultPaths[spDump], ".");
|
||||
}
|
||||
// default save path
|
||||
if (get_my_user_directory() != NULL) { // should return path to .proxmark3 folder
|
||||
session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], strlen(get_my_user_directory()) + 1); //, sizeof(uint8_t));
|
||||
strcpy(session.defaultPaths[spTrace], get_my_user_directory());
|
||||
} else {
|
||||
session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], 2); // 2, sizeof(uint8_t));
|
||||
strcpy(session.defaultPaths[spTrace], ".");
|
||||
}
|
||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||
setDefaultPath (spDump, get_my_user_directory());
|
||||
else
|
||||
setDefaultPath (spDump, ".");
|
||||
|
||||
// default dump path
|
||||
if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
|
||||
setDefaultPath (spTrace, get_my_user_directory());
|
||||
else
|
||||
setDefaultPath (spTrace, ".");
|
||||
|
||||
// loadFileJson wants these, so pass in place holder values, though not used
|
||||
// in settings load;
|
||||
|
@ -242,20 +234,16 @@ void preferences_load_callback(json_t *root) {
|
|||
}
|
||||
|
||||
// default save path
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0) {
|
||||
session.defaultPaths[spDefault] = realloc(session.defaultPaths[spDefault], strlen(s1) + 1);
|
||||
strcpy(session.defaultPaths[spDefault], s1);
|
||||
}
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0)
|
||||
setDefaultPath (spDefault,s1);
|
||||
|
||||
// default dump path
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0) {
|
||||
session.defaultPaths[spDump] = realloc(session.defaultPaths[spDump],strlen(s1) + 1);
|
||||
strcpy(session.defaultPaths[spDump],s1);
|
||||
}
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0)
|
||||
setDefaultPath (spDump,s1);
|
||||
|
||||
// default trace path
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0) {
|
||||
session.defaultPaths[spTrace] = realloc(session.defaultPaths[spTrace],strlen(s1) + 1);
|
||||
strcpy(session.defaultPaths[spTrace],s1);
|
||||
}
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0)
|
||||
setDefaultPath (spTrace,s1);
|
||||
|
||||
// window plot
|
||||
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0)
|
||||
|
@ -461,16 +449,33 @@ void showDeviceDebugState(prefShowOpt_t Opt) {
|
|||
}
|
||||
}
|
||||
|
||||
void showSavePathState(prefShowOpt_t Opt) {
|
||||
PrintAndLogEx(NORMAL, " %s default save path...... "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spDefault]);
|
||||
void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) {
|
||||
|
||||
char tempStr[50];
|
||||
|
||||
switch (pathIndex) {
|
||||
case spDefault:
|
||||
strcpy (tempStr,"default save path......");
|
||||
break;
|
||||
case spDump:
|
||||
strcpy (tempStr,"dump save path.........");
|
||||
break;
|
||||
case spTrace:
|
||||
strcpy (tempStr,"trace save path........");
|
||||
break;
|
||||
default:
|
||||
strcpy (tempStr,_RED_("unknown")" save path......");
|
||||
}
|
||||
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){
|
||||
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);
|
||||
|
@ -760,6 +765,8 @@ static int setCmdSavePaths (const char *Cmd) {
|
|||
int optLen = 0;
|
||||
char *newValue = NULL;
|
||||
bool createDir = false;
|
||||
savePaths_t pathItem = spItemCount;
|
||||
|
||||
|
||||
if (param_getchar(Cmd, cmdp) == 0x00)
|
||||
return usage_set_savePaths();
|
||||
|
@ -804,45 +811,67 @@ static int setCmdSavePaths (const char *Cmd) {
|
|||
if (!fileExists(newValue))
|
||||
create_path (newValue); //mkdir (newValue,0x777);
|
||||
|
||||
// Default
|
||||
if (strncmp(strOpt, "default", 7) == 0) {
|
||||
if (strcmp(newValue, session.defaultPaths[spDefault]) != 0) {
|
||||
showSavePathState(prefShowOLD);
|
||||
session.defaultPaths[spDefault] = (char *)realloc(session.defaultPaths[spDefault], strlen(newValue) + 1);
|
||||
strcpy (session.defaultPaths[spDefault],newValue);
|
||||
showSavePathState(prefShowNEW);
|
||||
pathItem = spItemCount;
|
||||
if (strncmp(strOpt, "default", 7) == 0) pathItem = spDefault;
|
||||
if (strncmp(strOpt, "dump", 4) == 0) pathItem = spDump;
|
||||
if (strncmp(strOpt, "trace", 7) == 0) pathItem = spTrace;
|
||||
|
||||
if (pathItem < spItemCount) {
|
||||
if (strcmp(newValue, session.defaultPaths[pathItem]) != 0) {
|
||||
showSavePathState(pathItem, prefShowOLD);
|
||||
setDefaultPath (pathItem, newValue);
|
||||
showSavePathState(pathItem, prefShowNEW);
|
||||
preferences_save();
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "nothing changed");
|
||||
showSavePathState(prefShowNone);
|
||||
showSavePathState(pathItem, prefShowNone);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// Default
|
||||
if (strncmp(strOpt, "default", 7) == 0) {
|
||||
if (strcmp(newValue, session.defaultPaths[spDefault]) != 0) {
|
||||
showSavePathState(spDefault, prefShowOLD);
|
||||
setDefaultPath (spDefault, newValue);
|
||||
// session.defaultPaths[spDefault] = (char *)realloc(session.defaultPaths[spDefault], strlen(newValue) + 1);
|
||||
// strcpy (session.defaultPaths[spDefault],newValue);
|
||||
showSavePathState(spDefault, prefShowNEW);
|
||||
preferences_save();
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "nothing changed");
|
||||
showSavePathState(spDefault, prefShowNone);
|
||||
}
|
||||
}
|
||||
// Dump
|
||||
if (strncmp(strOpt, "dump", 4) == 0) {
|
||||
if (strcmp(newValue, session.defaultPaths[spDump]) != 0) {
|
||||
showDumpPathState(prefShowOLD);
|
||||
session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], strlen(newValue) + 1);
|
||||
strcpy (session.defaultPaths[spDump],newValue);
|
||||
showDumpPathState(prefShowNEW);
|
||||
showSavePathState(spDump, prefShowOLD);
|
||||
setDefaultPath (spDump, newValue);
|
||||
// session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], strlen(newValue) + 1);
|
||||
// strcpy (session.defaultPaths[spDump],newValue);
|
||||
showSavePathState(spDump, prefShowNEW);
|
||||
preferences_save();
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "nothing changed");
|
||||
showDumpPathState(prefShowNone);
|
||||
showSavePathState(spDump, prefShowNone);
|
||||
}
|
||||
}
|
||||
// Trace
|
||||
if (strncmp(strOpt, "trace", 7) == 0) {
|
||||
if (strcmp(newValue, session.defaultPaths[spTrace]) != 0) {
|
||||
showTracePathState(prefShowOLD);
|
||||
session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], strlen(newValue) + 1);
|
||||
strcpy (session.defaultPaths[spTrace],newValue);
|
||||
showTracePathState(prefShowNEW);
|
||||
showSavePathState(spTrace, prefShowOLD);
|
||||
setDefaultPath (spTrace, newValue);
|
||||
// session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], strlen(newValue) + 1);
|
||||
// strcpy (session.defaultPaths[spTrace],newValue);
|
||||
showSavePathState(spTrace,prefShowNEW);
|
||||
preferences_save();
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "nothing changed");
|
||||
showTracePathState(prefShowNone);
|
||||
showSavePathState(spTrace,prefShowNone);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
return usage_set_savePaths();
|
||||
|
@ -899,9 +928,9 @@ static int CmdPrefShow(const char *Cmd) {
|
|||
showColorState(prefShowNone);
|
||||
// showPlotPosState ();
|
||||
// showOverlayPosState ();
|
||||
showSavePathState(prefShowNone);
|
||||
showDumpPathState(prefShowNone);
|
||||
showTracePathState(prefShowNone);
|
||||
showSavePathState(spDefault, prefShowNone);
|
||||
showSavePathState(spDump, prefShowNone);
|
||||
showSavePathState(spTrace, prefShowNone);
|
||||
showClientDebugState(prefShowNone);
|
||||
showDeviceDebugState(prefShowNone);
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
|
|
@ -21,8 +21,7 @@ typedef enum logLevel {NORMAL, SUCCESS, INFO, FAILED, WARNING, ERR, DEBUG, INPLA
|
|||
typedef enum emojiMode {ALIAS, EMOJI, ALTTEXT, ERASE} emojiMode_t;
|
||||
typedef enum clientdebugLevel {cdbOFF,cdbSIMPLE,cdbFULL} clientdebugLevel_t;
|
||||
typedef enum devicedebugLevel {ddbOFF,ddbERROR,ddbINFO,ddbDEBUG,ddbEXTENDED} devicedebugLevel_t;
|
||||
#define savePathCount 3
|
||||
typedef enum savePaths {spDefault, spDump, spTrace} savePaths_t;
|
||||
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 {
|
||||
|
@ -37,7 +36,7 @@ typedef struct {
|
|||
bool window_changed; // track if plot/overlay pos/size changed to save on exit
|
||||
qtWindow_t plot;
|
||||
qtWindow_t overlay;
|
||||
char *defaultPaths[savePathCount]; // Array should allow loop searching for files
|
||||
char *defaultPaths[spItemCount]; // Array should allow loop searching for files
|
||||
clientdebugLevel_t client_debug_level;
|
||||
uint8_t device_debug_level;
|
||||
} session_arg_t;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue