2022-07-01 07:24:58 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-07-19 01:42:16 +00:00
|
|
|
|
#if defined(WIN32) || defined(_WIN64)
|
2022-07-01 07:24:58 +00:00
|
|
|
|
#include <Windows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// #include "cJSON.h"
|
|
|
|
|
#include "../../code_device/hgsane/cJSON.h"
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
namespace gb
|
|
|
|
|
{
|
|
|
|
|
class json
|
|
|
|
|
{
|
|
|
|
|
cJSON *obj_;
|
|
|
|
|
cJSON* cur_child_;
|
|
|
|
|
bool is_array_;
|
|
|
|
|
|
|
|
|
|
cJSON* find_sibling(cJSON* first, const char* name, cJSON*** addr);
|
|
|
|
|
cJSON* find_child(cJSON *parent, std::vector<std::string>& path, bool create, cJSON*** addr = NULL);
|
|
|
|
|
cJSON* find(const char* path, bool create = false, cJSON*** addr = NULL);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
json(char* json_txt = 0);
|
|
|
|
|
~json();
|
|
|
|
|
|
|
|
|
|
static std::string to_string(cJSON* root, bool formatted);
|
|
|
|
|
static std::string get_value_as_string(cJSON* root, bool integer = false);
|
|
|
|
|
static void free_node_data(cJSON* node);
|
|
|
|
|
static cJSON* create_element_with_name(const char* name);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool attach_text(char* json_txt);
|
|
|
|
|
bool attach_cjson(cJSON* cjson);
|
|
|
|
|
bool create_empty(bool array = false);
|
|
|
|
|
void clear(void);
|
|
|
|
|
std::string to_string(bool formatted);
|
|
|
|
|
|
|
|
|
|
// can be path: child/value ...
|
|
|
|
|
bool get_value(const char* key, bool& val);
|
|
|
|
|
bool get_value(const char* key, int& val);
|
|
|
|
|
bool get_value(const char* key, double& val);
|
|
|
|
|
bool get_value(const char* key, std::string& val);
|
|
|
|
|
bool get_value(const char* key, json*& val); // caller shoud call "delete" to free the returned object !!!
|
|
|
|
|
bool get_value_as_string(const char* key, std::string& val, bool integer);
|
|
|
|
|
bool get_as_array(const char* key, std::vector<std::string>& val);
|
|
|
|
|
|
|
|
|
|
bool first_child(std::string& val, std::string* name = NULL);
|
|
|
|
|
bool next_child(std::string& val, std::string* name = NULL);
|
|
|
|
|
|
|
|
|
|
bool set_value(const char* key, bool val);
|
|
|
|
|
bool set_value(const char* key, int val);
|
|
|
|
|
bool set_value(const char* key, double val);
|
|
|
|
|
bool set_value(const char* key, std::string val);
|
|
|
|
|
bool set_value(const char* key, const char* val);
|
|
|
|
|
bool set_value(const char* key, json* obj);
|
|
|
|
|
|
|
|
|
|
bool remove(const char* key);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class base64
|
|
|
|
|
{
|
|
|
|
|
char base64_ind_[128];
|
|
|
|
|
char base64_char_[80];
|
|
|
|
|
char padding_char_;
|
|
|
|
|
|
|
|
|
|
bool is_valid_base64_table(const char* table);
|
|
|
|
|
bool initialize_base64_table(const char* table);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
base64();
|
|
|
|
|
~base64();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool set_base64_table(const char* table = NULL);
|
|
|
|
|
std::string encode(const char* data, size_t bytes, unsigned int line_bytes = -1, bool need_padding = true);
|
|
|
|
|
std::string decode(const char* data, size_t bytes);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class sane_config
|
|
|
|
|
{
|
2022-09-23 06:17:41 +00:00
|
|
|
|
std::wstring file_;
|
2022-07-01 07:24:58 +00:00
|
|
|
|
json* jsn_;
|
|
|
|
|
json* bkp_;
|
|
|
|
|
json* def_val_;
|
|
|
|
|
bool in_setting_;
|
|
|
|
|
std::map<int, std::string> id_title_;
|
|
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
std::string to_hex_letter(const char* data, size_t bytes);
|
|
|
|
|
std::string from_hex_letter(const char* data, size_t bytes);
|
|
|
|
|
std::string default_value(const char* hex_title);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
sane_config();
|
|
|
|
|
~sane_config();
|
|
|
|
|
|
|
|
|
|
static bool hex(unsigned char ch, unsigned char* val);
|
|
|
|
|
static bool hex_char(const char* data, unsigned char* val);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool load_from_file(const wchar_t* file);
|
|
|
|
|
bool load_from_mem(const char* mem);
|
|
|
|
|
bool save_to(const wchar_t* file);
|
|
|
|
|
void set_default_value(int sn, const char* title, const char* val, size_t bytes);
|
|
|
|
|
bool first_config(std::string& title, std::string& val);
|
|
|
|
|
bool next_config(std::string& title, std::string& val);
|
|
|
|
|
void begin_setting(bool restore = false);
|
|
|
|
|
void config_changed(const char* title, const char* val, size_t bytes);
|
|
|
|
|
void config_changed(int sn, const char* val, size_t bytes);
|
2022-09-27 04:35:37 +00:00
|
|
|
|
void remove_config(const char* title);
|
2022-07-01 07:24:58 +00:00
|
|
|
|
void end_setting(bool cancel);
|
|
|
|
|
int id_from_title(const char* title);
|
|
|
|
|
std::string to_text_stream(void);
|
2022-09-27 01:48:57 +00:00
|
|
|
|
std::string get_version(void);
|
2022-07-01 07:24:58 +00:00
|
|
|
|
};
|
|
|
|
|
}
|