mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 13:00:42 -07:00
Code Clean
This commit is contained in:
parent
8fea6cddf7
commit
7b14fd7212
5 changed files with 24 additions and 21 deletions
|
@ -97,6 +97,7 @@ int JsonSaveStr(json_t *root, const char *path, const char *value) {
|
||||||
int JsonSaveBoolean(json_t *root, const char *path, bool value) {
|
int JsonSaveBoolean(json_t *root, const char *path, bool value) {
|
||||||
return JsonSaveJsonObject(root, path, json_boolean(value));
|
return JsonSaveJsonObject(root, path, json_boolean(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) {
|
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) {
|
||||||
char *msg = sprint_hex_inrow(data, datalen);
|
char *msg = sprint_hex_inrow(data, datalen);
|
||||||
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')
|
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
// this define is needed for scandir/alphasort to work
|
// this define is needed for scandir/alphasort to work
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -52,9 +54,6 @@
|
||||||
|
|
||||||
#define PATH_MAX_LENGTH 200
|
#define PATH_MAX_LENGTH 200
|
||||||
|
|
||||||
extern void JsonLoadSettingsCallback (json_t *root);
|
|
||||||
extern void JsonSaveSettingsCallback (json_t *root);
|
|
||||||
|
|
||||||
struct wave_info_t {
|
struct wave_info_t {
|
||||||
char signature[4];
|
char signature[4];
|
||||||
uint32_t filesize;
|
uint32_t filesize;
|
||||||
|
@ -429,7 +428,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case jsfSettings:
|
case jsfSettings:
|
||||||
JsonSaveSettingsCallback (root);
|
settings_save_callback (root);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -870,7 +869,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_
|
||||||
*datalen = sptr;
|
*datalen = sptr;
|
||||||
}
|
}
|
||||||
if (!strcmp(ctype,"settings")) {
|
if (!strcmp(ctype,"settings")) {
|
||||||
JsonLoadSettingsCallback (root);
|
settings_load_callback (root);
|
||||||
}
|
}
|
||||||
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
|
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
|
||||||
out:
|
out:
|
||||||
|
|
|
@ -558,7 +558,6 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
/* initialize history */
|
/* initialize history */
|
||||||
using_history();
|
using_history();
|
||||||
|
|
||||||
|
|
||||||
#ifdef RL_STATE_READCMD
|
#ifdef RL_STATE_READCMD
|
||||||
rl_extend_line_buffer(1024);
|
rl_extend_line_buffer(1024);
|
||||||
|
@ -583,9 +582,9 @@ int main(int argc, char *argv[]) {
|
||||||
set_my_executable_path();
|
set_my_executable_path();
|
||||||
set_my_user_directory();
|
set_my_user_directory();
|
||||||
|
|
||||||
// Settings
|
// Settings Load and Test
|
||||||
settingsLoad ();
|
settings_load ();
|
||||||
settingsSave ();
|
settings_save ();
|
||||||
printf ("Ver : %s\n",mySettings.version);
|
printf ("Ver : %s\n",mySettings.version);
|
||||||
// End Settings
|
// End Settings
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,8 @@
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
#include "emv/emvjson.h"
|
#include "emv/emvjson.h"
|
||||||
|
|
||||||
// settings_t mySettings;
|
|
||||||
|
|
||||||
// Load all settings into memory (struct)
|
// Load all settings into memory (struct)
|
||||||
void settingsLoad (void)
|
int settings_load (void)
|
||||||
{
|
{
|
||||||
// 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;
|
||||||
|
@ -79,17 +77,17 @@ void settingsLoad (void)
|
||||||
printf (" window_hsize (int) : [%d]\n",mySettings.window_hsize);
|
printf (" window_hsize (int) : [%d]\n",mySettings.window_hsize);
|
||||||
printf (" window_wsize (int) : [%d]\n",mySettings.window_wsize);
|
printf (" window_wsize (int) : [%d]\n",mySettings.window_wsize);
|
||||||
|
|
||||||
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save all settings from memory (struct) to file
|
// Save all settings from memory (struct) to file
|
||||||
int settingsSave (void)
|
int settings_save (void)
|
||||||
{
|
{
|
||||||
// Note sure if backup has value ?
|
// Note sure if backup has value ?
|
||||||
char backupFilename[500];
|
char backupFilename[500];
|
||||||
// if (mySettings.loaded)
|
|
||||||
|
|
||||||
snprintf (backupFilename,sizeof(backupFilename),"%s.bak",settingsFilename);
|
snprintf (backupFilename,sizeof(backupFilename),"%s.bak",settingsFilename);
|
||||||
|
|
||||||
if (fileExists (backupFilename)) {
|
if (fileExists (backupFilename)) {
|
||||||
if (remove (backupFilename) != 0) {
|
if (remove (backupFilename) != 0) {
|
||||||
PrintAndLogEx (FAILED, "Error - could not delete old settings backup file \"%s\"",backupFilename);
|
PrintAndLogEx (FAILED, "Error - could not delete old settings backup file \"%s\"",backupFilename);
|
||||||
|
@ -115,7 +113,7 @@ int settingsSave (void)
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonSaveSettingsCallback (json_t *root)
|
void settings_save_callback (json_t *root)
|
||||||
{
|
{
|
||||||
// extern settings_t mySettings;
|
// extern settings_t mySettings;
|
||||||
|
|
||||||
|
@ -141,7 +139,7 @@ void JsonSaveSettingsCallback (json_t *root)
|
||||||
JsonSaveInt (root,"window.wsize",mySettings.window_wsize);
|
JsonSaveInt (root,"window.wsize",mySettings.window_wsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonLoadSettingsCallback (json_t *root)
|
void settings_load_callback (json_t *root)
|
||||||
{
|
{
|
||||||
// extern settings_t mySettings;
|
// extern settings_t mySettings;
|
||||||
json_error_t up_error = {0};
|
json_error_t up_error = {0};
|
||||||
|
|
|
@ -8,10 +8,13 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Settings Functions
|
// Settings Functions
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
#ifndef settings_h
|
||||||
|
#define settings_h
|
||||||
|
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
|
|
||||||
#define settingsFilename "settings.json"
|
#define settingsFilename "settings.json"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool loaded;
|
bool loaded;
|
||||||
char version[20];
|
char version[20];
|
||||||
|
@ -23,10 +26,13 @@ typedef struct {
|
||||||
int window_wsize;
|
int window_wsize;
|
||||||
} settings_t;
|
} settings_t;
|
||||||
|
|
||||||
|
// Settings struct so as to be available to other modules by including settings.h
|
||||||
settings_t mySettings;
|
settings_t mySettings;
|
||||||
|
|
||||||
void settingsLoad (void);
|
int settings_load (void);
|
||||||
int settingsSave (void);
|
int settings_save (void);
|
||||||
|
|
||||||
void JsonSaveCallback ( json_t *root);
|
void settings_save_callback (json_t *root);
|
||||||
void JsonLoadCallback ( json_t *root);
|
void settings_load_callback (json_t *root);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue