mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-24 16:14:59 +08:00
Update preferences.c
Error msg and show help if invalid option detected
This commit is contained in:
parent
82bbea3874
commit
0cc2bda952
1 changed files with 111 additions and 46 deletions
|
@ -317,6 +317,7 @@ void showHintsState (prefShowOpt_t Opt){
|
||||||
static int setCmdEmoji (const char *Cmd) {
|
static int setCmdEmoji (const char *Cmd) {
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
|
bool validValue = false;
|
||||||
char strOpt[50];
|
char strOpt[50];
|
||||||
emojiMode_t newValue = session.emoji_mode;
|
emojiMode_t newValue = session.emoji_mode;
|
||||||
|
|
||||||
|
@ -328,19 +329,38 @@ static int setCmdEmoji (const char *Cmd) {
|
||||||
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
||||||
str_lower(strOpt); // convert to lowercase
|
str_lower(strOpt); // convert to lowercase
|
||||||
|
|
||||||
if (strncmp (strOpt,"help",4) == 0) usage_set_emoji();
|
if (strncmp (strOpt,"help",4) == 0)
|
||||||
if (strncmp (strOpt,"alias",5) == 0) newValue = ALIAS;
|
return usage_set_emoji();
|
||||||
if (strncmp (strOpt,"emoji",5) == 0) newValue = EMOJI;
|
if (strncmp (strOpt,"alias",5) == 0) {
|
||||||
if (strncmp (strOpt,"alttext",7) == 0) newValue = ALTTEXT;
|
validValue = true;
|
||||||
if (strncmp (strOpt,"erase",5) == 0) newValue = ERASE;
|
newValue = ALIAS;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"emoji",5) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = EMOJI;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"alttext",7) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = ALTTEXT;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"erase",5) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = ERASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validValue) {
|
||||||
if (session.emoji_mode != newValue) {// changed
|
if (session.emoji_mode != newValue) {// changed
|
||||||
showEmojiState (prefShowOLD);
|
showEmojiState (prefShowOLD);
|
||||||
session.emoji_mode = newValue;
|
session.emoji_mode = newValue;
|
||||||
showEmojiState (prefShowNEW);
|
showEmojiState (prefShowNEW);
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO,"nothing changed");
|
||||||
|
showEmojiState (prefShowNone);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error
|
PrintAndLogEx(ERR,"invalid option");
|
||||||
|
return usage_set_emoji();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,6 +371,7 @@ static int setCmdColor (const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
|
bool validValue = false;
|
||||||
char strOpt[50];
|
char strOpt[50];
|
||||||
bool newValue = session.supports_colors;
|
bool newValue = session.supports_colors;
|
||||||
|
|
||||||
|
@ -362,17 +383,30 @@ static int setCmdColor (const char *Cmd)
|
||||||
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
||||||
str_lower(strOpt); // convert to lowercase
|
str_lower(strOpt); // convert to lowercase
|
||||||
|
|
||||||
if (strncmp (strOpt,"help",4) == 0) usage_set_color();
|
if (strncmp (strOpt,"help",4) == 0)
|
||||||
if (strncmp (strOpt,"off",3) == 0) newValue = false;
|
return usage_set_color();
|
||||||
if (strncmp (strOpt,"ansi",4) == 0) newValue = true;
|
if (strncmp (strOpt,"off",3) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = false;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"ansi",4) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validValue) {
|
||||||
if (session.supports_colors != newValue) {// changed
|
if (session.supports_colors != newValue) {// changed
|
||||||
showColorState (prefShowOLD);
|
showColorState (prefShowOLD);
|
||||||
session.supports_colors = newValue;
|
session.supports_colors = newValue;
|
||||||
showColorState (prefShowNEW);
|
showColorState (prefShowNEW);
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO,"nothing changed");
|
||||||
|
showColorState (prefShowNone);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error
|
PrintAndLogEx(ERR,"invalid option");
|
||||||
|
return usage_set_color();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,6 +417,7 @@ static int setCmdDebug (const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
|
bool validValue = false;
|
||||||
char strOpt[50];
|
char strOpt[50];
|
||||||
clientdebugLevel_t newValue = session.client_debug_level;
|
clientdebugLevel_t newValue = session.client_debug_level;
|
||||||
|
|
||||||
|
@ -394,19 +429,35 @@ static int setCmdDebug (const char *Cmd)
|
||||||
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
||||||
str_lower(strOpt); // convert to lowercase
|
str_lower(strOpt); // convert to lowercase
|
||||||
|
|
||||||
if (strncmp (strOpt,"help",4) == 0) usage_set_debug();
|
if (strncmp (strOpt,"help",4) == 0)
|
||||||
if (strncmp (strOpt,"off",3) == 0) newValue = OFF;
|
return usage_set_debug();
|
||||||
if (strncmp (strOpt,"simple",6) == 0) newValue = SIMPLE;
|
if (strncmp (strOpt,"off",3) == 0) {
|
||||||
if (strncmp (strOpt,"full",4) == 0) newValue = FULL;
|
validValue = true;
|
||||||
|
newValue = OFF;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"simple",6) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = SIMPLE;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"full",4) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = FULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validValue) {
|
||||||
if (session.client_debug_level != newValue) {// changed
|
if (session.client_debug_level != newValue) {// changed
|
||||||
showClientDebugState (prefShowOLD);
|
showClientDebugState (prefShowOLD);
|
||||||
session.client_debug_level = newValue;
|
session.client_debug_level = newValue;
|
||||||
g_debugMode = newValue;
|
g_debugMode = newValue;
|
||||||
showClientDebugState (prefShowNEW);
|
showClientDebugState (prefShowNEW);
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO,"nothing changed");
|
||||||
|
showClientDebugState (prefShowNone);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error
|
PrintAndLogEx(ERR,"invalid option");
|
||||||
|
return usage_set_debug();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +468,7 @@ static int setCmdHint (const char *Cmd)
|
||||||
{
|
{
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
bool errors = false;
|
bool errors = false;
|
||||||
|
bool validValue = false;
|
||||||
char strOpt[50];
|
char strOpt[50];
|
||||||
bool newValue = session.show_hints;
|
bool newValue = session.show_hints;
|
||||||
|
|
||||||
|
@ -428,17 +480,30 @@ static int setCmdHint (const char *Cmd)
|
||||||
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
if (param_getstr(Cmd, cmdp++, strOpt, sizeof(strOpt)) != 0) {
|
||||||
str_lower(strOpt); // convert to lowercase
|
str_lower(strOpt); // convert to lowercase
|
||||||
|
|
||||||
if (strncmp (strOpt,"help",4) == 0) usage_set_hints();
|
if (strncmp (strOpt,"help",4) == 0)
|
||||||
if (strncmp (strOpt,"off",3) == 0) newValue = false;
|
return usage_set_hints();
|
||||||
if (strncmp (strOpt,"on",2) == 0) newValue = true;
|
if (strncmp (strOpt,"off",3) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = false;
|
||||||
|
}
|
||||||
|
if (strncmp (strOpt,"on",2) == 0) {
|
||||||
|
validValue = true;
|
||||||
|
newValue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validValue) {
|
||||||
if (session.show_hints != newValue) {// changed
|
if (session.show_hints != newValue) {// changed
|
||||||
showHintsState (prefShowOLD);
|
showHintsState (prefShowOLD);
|
||||||
session.show_hints = newValue;
|
session.show_hints = newValue;
|
||||||
showHintsState (prefShowNEW);
|
showHintsState (prefShowNEW);
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(INFO,"nothing changed");
|
||||||
|
showHintsState (prefShowNone);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// error
|
PrintAndLogEx(ERR,"invalid option");
|
||||||
|
return usage_set_hints();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue