Code Clean

This commit is contained in:
mwalker33 2020-04-06 16:20:57 +10:00
commit 7b14fd7212
5 changed files with 24 additions and 21 deletions

View file

@ -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) {
return JsonSaveJsonObject(root, path, json_boolean(value));
}
int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) {
char *msg = sprint_hex_inrow(data, datalen);
if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ')

View file

@ -38,6 +38,8 @@
// this define is needed for scandir/alphasort to work
#define _GNU_SOURCE
#include "fileutils.h"
#include "settings.h"
#include <dirent.h>
#include <ctype.h>
@ -52,9 +54,6 @@
#define PATH_MAX_LENGTH 200
extern void JsonLoadSettingsCallback (json_t *root);
extern void JsonSaveSettingsCallback (json_t *root);
struct wave_info_t {
char signature[4];
uint32_t filesize;
@ -429,7 +428,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s
}
break;
case jsfSettings:
JsonSaveSettingsCallback (root);
settings_save_callback (root);
break;
default:
break;
@ -870,7 +869,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_
*datalen = sptr;
}
if (!strcmp(ctype,"settings")) {
JsonLoadSettingsCallback (root);
settings_load_callback (root);
}
PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName);
out:

View file

@ -558,7 +558,6 @@ int main(int argc, char *argv[]) {
/* initialize history */
using_history();
#ifdef RL_STATE_READCMD
rl_extend_line_buffer(1024);
@ -583,9 +582,9 @@ int main(int argc, char *argv[]) {
set_my_executable_path();
set_my_user_directory();
// Settings
settingsLoad ();
settingsSave ();
// Settings Load and Test
settings_load ();
settings_save ();
printf ("Ver : %s\n",mySettings.version);
// End Settings

View file

@ -43,10 +43,8 @@
#include "comms.h"
#include "emv/emvjson.h"
// settings_t mySettings;
// 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
// in settings load;
@ -79,17 +77,17 @@ void settingsLoad (void)
printf (" window_hsize (int) : [%d]\n",mySettings.window_hsize);
printf (" window_wsize (int) : [%d]\n",mySettings.window_wsize);
return PM3_SUCCESS;
}
// Save all settings from memory (struct) to file
int settingsSave (void)
int settings_save (void)
{
// Note sure if backup has value ?
char backupFilename[500];
// if (mySettings.loaded)
snprintf (backupFilename,sizeof(backupFilename),"%s.bak",settingsFilename);
if (fileExists (backupFilename)) {
if (remove (backupFilename) != 0) {
PrintAndLogEx (FAILED, "Error - could not delete old settings backup file \"%s\"",backupFilename);
@ -115,7 +113,7 @@ int settingsSave (void)
return PM3_SUCCESS;
}
void JsonSaveSettingsCallback (json_t *root)
void settings_save_callback (json_t *root)
{
// extern settings_t mySettings;
@ -141,7 +139,7 @@ void JsonSaveSettingsCallback (json_t *root)
JsonSaveInt (root,"window.wsize",mySettings.window_wsize);
}
void JsonLoadSettingsCallback (json_t *root)
void settings_load_callback (json_t *root)
{
// extern settings_t mySettings;
json_error_t up_error = {0};

View file

@ -8,10 +8,13 @@
//-----------------------------------------------------------------------------
// Settings Functions
//-----------------------------------------------------------------------------
#ifndef settings_h
#define settings_h
#include "fileutils.h"
#define settingsFilename "settings.json"
typedef struct {
bool loaded;
char version[20];
@ -23,10 +26,13 @@ typedef struct {
int window_wsize;
} settings_t;
// Settings struct so as to be available to other modules by including settings.h
settings_t mySettings;
void settingsLoad (void);
int settingsSave (void);
int settings_load (void);
int settings_save (void);
void JsonSaveCallback ( json_t *root);
void JsonLoadCallback ( json_t *root);
void settings_save_callback (json_t *root);
void settings_load_callback (json_t *root);
#endif