streamline works

This commit is contained in:
mwalker33 2020-04-19 10:49:09 +10:00 committed by Philippe Teuwen
commit 600e5d7d6f
4 changed files with 112 additions and 64 deletions

View file

@ -139,7 +139,7 @@ static bool is_directory(const char *filename) {
#ifdef _WIN32 #ifdef _WIN32
#define make_dir(a) _mkdir(a) #define make_dir(a) _mkdir(a)
#else #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 #endif
bool create_path(const char *dirname) { bool create_path(const char *dirname) {
@ -190,6 +190,24 @@ bool create_path(const char *dirname) {
return true; 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) { static char *filenamemcopy(const char *preferredName, const char *suffix) {
if (preferredName == NULL) return NULL; if (preferredName == NULL) return NULL;

View file

@ -75,6 +75,8 @@ typedef enum {
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
/** /**
* @brief Utility function to save data to a binary file. This method takes a preferred name, but if that * @brief Utility function to save data to a binary file. This method takes a preferred name, but if that

View file

@ -67,31 +67,23 @@ int preferences_load(void) {
session.show_hints = false; session.show_hints = false;
session.supports_colors = 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 // default dump 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
session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], strlen(get_my_user_directory()) + 1); //, sizeof(uint8_t)); setDefaultPath (spDump, get_my_user_directory());
strcpy(session.defaultPaths[spDump], get_my_user_directory()); else
} else { setDefaultPath (spDump, ".");
session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], 2); // 2, sizeof(uint8_t));
strcpy(session.defaultPaths[spDump], "."); // default dump path
} if (get_my_user_directory() != NULL) // should return path to .proxmark3 folder
// default save path setDefaultPath (spTrace, get_my_user_directory());
if (get_my_user_directory() != NULL) { // should return path to .proxmark3 folder else
session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], strlen(get_my_user_directory()) + 1); //, sizeof(uint8_t)); setDefaultPath (spTrace, ".");
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], ".");
}
// 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;
@ -242,21 +234,17 @@ void preferences_load_callback(json_t *root) {
} }
// default save path // default save path
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.savepath", &s1) == 0) { 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); setDefaultPath (spDefault,s1);
strcpy(session.defaultPaths[spDefault], s1);
}
// default dump path // default dump path
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.dumppath", &s1) == 0) { 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); setDefaultPath (spDump,s1);
strcpy(session.defaultPaths[spDump],s1);
}
// default trace path // default trace path
if (json_unpack_ex(root, &up_error, 0, "{s:s}", "file.default.tracepath", &s1) == 0) { 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); setDefaultPath (spTrace,s1);
strcpy(session.defaultPaths[spTrace],s1);
}
// window plot // window plot
if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0) if (json_unpack_ex(root, &up_error, 0, "{s:i}", "window.plot.xpos", &i1) == 0)
session.plot.x = i1; session.plot.x = i1;
@ -461,16 +449,33 @@ void showDeviceDebugState(prefShowOpt_t Opt) {
} }
} }
void showSavePathState(prefShowOpt_t Opt) { void showSavePathState(savePaths_t pathIndex, prefShowOpt_t Opt) {
PrintAndLogEx(NORMAL, " %s default save path...... "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spDefault]);
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) { void showDumpPathState(prefShowOpt_t Opt) {
PrintAndLogEx(NORMAL, " %s dump save path......... "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spDump]); PrintAndLogEx(NORMAL, " %s dump save path......... "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spDump]);
} }
void showTracePathState(prefShowOpt_t Opt) { void showTracePathState(prefShowOpt_t Opt) {
PrintAndLogEx(NORMAL, " %s trace save path........ "_GREEN_("%s"), prefShowMsg(Opt), session.defaultPaths[spTrace]); 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);
@ -760,6 +765,8 @@ static int setCmdSavePaths (const char *Cmd) {
int optLen = 0; int optLen = 0;
char *newValue = NULL; char *newValue = NULL;
bool createDir = false; bool createDir = false;
savePaths_t pathItem = spItemCount;
if (param_getchar(Cmd, cmdp) == 0x00) if (param_getchar(Cmd, cmdp) == 0x00)
return usage_set_savePaths(); return usage_set_savePaths();
@ -804,45 +811,67 @@ static int setCmdSavePaths (const char *Cmd) {
if (!fileExists(newValue)) if (!fileExists(newValue))
create_path (newValue); //mkdir (newValue,0x777); create_path (newValue); //mkdir (newValue,0x777);
// Default pathItem = spItemCount;
if (strncmp(strOpt, "default", 7) == 0) { if (strncmp(strOpt, "default", 7) == 0) pathItem = spDefault;
if (strcmp(newValue, session.defaultPaths[spDefault]) != 0) { if (strncmp(strOpt, "dump", 4) == 0) pathItem = spDump;
showSavePathState(prefShowOLD); if (strncmp(strOpt, "trace", 7) == 0) pathItem = spTrace;
session.defaultPaths[spDefault] = (char *)realloc(session.defaultPaths[spDefault], strlen(newValue) + 1);
strcpy (session.defaultPaths[spDefault],newValue); if (pathItem < spItemCount) {
showSavePathState(prefShowNEW); if (strcmp(newValue, session.defaultPaths[pathItem]) != 0) {
showSavePathState(pathItem, prefShowOLD);
setDefaultPath (pathItem, newValue);
showSavePathState(pathItem, prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
PrintAndLogEx(INFO, "nothing changed"); 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 // Dump
if (strncmp(strOpt, "dump", 4) == 0) { if (strncmp(strOpt, "dump", 4) == 0) {
if (strcmp(newValue, session.defaultPaths[spDump]) != 0) { if (strcmp(newValue, session.defaultPaths[spDump]) != 0) {
showDumpPathState(prefShowOLD); showSavePathState(spDump, prefShowOLD);
session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], strlen(newValue) + 1); setDefaultPath (spDump, newValue);
strcpy (session.defaultPaths[spDump],newValue); // session.defaultPaths[spDump] = (char *)realloc(session.defaultPaths[spDump], strlen(newValue) + 1);
showDumpPathState(prefShowNEW); // strcpy (session.defaultPaths[spDump],newValue);
showSavePathState(spDump, prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
PrintAndLogEx(INFO, "nothing changed"); PrintAndLogEx(INFO, "nothing changed");
showDumpPathState(prefShowNone); showSavePathState(spDump, prefShowNone);
} }
} }
// Trace // Trace
if (strncmp(strOpt, "trace", 7) == 0) { if (strncmp(strOpt, "trace", 7) == 0) {
if (strcmp(newValue, session.defaultPaths[spTrace]) != 0) { if (strcmp(newValue, session.defaultPaths[spTrace]) != 0) {
showTracePathState(prefShowOLD); showSavePathState(spTrace, prefShowOLD);
session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], strlen(newValue) + 1); setDefaultPath (spTrace, newValue);
strcpy (session.defaultPaths[spTrace],newValue); // session.defaultPaths[spTrace] = (char *)realloc(session.defaultPaths[spTrace], strlen(newValue) + 1);
showTracePathState(prefShowNEW); // strcpy (session.defaultPaths[spTrace],newValue);
showSavePathState(spTrace,prefShowNEW);
preferences_save(); preferences_save();
} else { } else {
PrintAndLogEx(INFO, "nothing changed"); PrintAndLogEx(INFO, "nothing changed");
showTracePathState(prefShowNone); showSavePathState(spTrace,prefShowNone);
} }
} }
*/
} }
} else { } else {
return usage_set_savePaths(); return usage_set_savePaths();
@ -899,9 +928,9 @@ static int CmdPrefShow(const char *Cmd) {
showColorState(prefShowNone); showColorState(prefShowNone);
// showPlotPosState (); // showPlotPosState ();
// showOverlayPosState (); // showOverlayPosState ();
showSavePathState(prefShowNone); showSavePathState(spDefault, prefShowNone);
showDumpPathState(prefShowNone); showSavePathState(spDump, prefShowNone);
showTracePathState(prefShowNone); showSavePathState(spTrace, prefShowNone);
showClientDebugState(prefShowNone); showClientDebugState(prefShowNone);
showDeviceDebugState(prefShowNone); showDeviceDebugState(prefShowNone);
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");

View file

@ -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 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;
#define savePathCount 3 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} savePaths_t;
typedef struct {int x; int y; int h; int w;} qtWindow_t; typedef struct {int x; int y; int h; int w;} qtWindow_t;
typedef struct { typedef struct {
@ -37,7 +36,7 @@ typedef struct {
bool window_changed; // track if plot/overlay pos/size changed to save on exit bool window_changed; // track if plot/overlay pos/size changed to save on exit
qtWindow_t plot; qtWindow_t plot;
qtWindow_t overlay; 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; clientdebugLevel_t client_debug_level;
uint8_t device_debug_level; uint8_t device_debug_level;
} session_arg_t; } session_arg_t;