fix bug when restore to default value at initializing

This commit is contained in:
gb 2023-12-26 13:50:23 +08:00
parent 13e06217fe
commit 225efeff9d
4 changed files with 30 additions and 1 deletions

View File

@ -486,7 +486,7 @@ file_reader::~file_reader()
if (map_)
map_->release();
notify_progress(len_, len_, 0); // ensure 100%
utils::to_log(LOG_LEVEL_DEBUG, "Read over of file(%s) at(%p/%p).\n", path_.c_str(), consume_, len_);
utils::to_log(LOG_LEVEL_DEBUG, "Read over of file(%s) at(%llu/%llu).\n", path_.c_str(), consume_, len_);
}
int file_reader::open(const char* file, bool in_mem, size_t off)

View File

@ -31,6 +31,31 @@ std::string sane_opt_provider::sane_value_2_text(const char* type, void* value)
else
return "";
}
void sane_opt_provider::set_opt_value(gb_json* opt, void* value, const char* key)
{
std::string type("");
opt->get_value("type", type);
if (!key || *key == 0)
key = "cur";
if (type == JSON_SANE_TYPE_BOOL)
{
opt->set_value(key, *(bool*)value);
}
else if (type == JSON_SANE_TYPE_INT)
{
opt->set_value(key, *(int*)value);
}
else if (type == JSON_SANE_TYPE_FIXED)
{
opt->set_value(key, *(double*)value);
}
else if (type == JSON_SANE_TYPE_STRING)
{
opt->set_value(key, (char*)value);
}
}
bool sane_opt_provider::set_opt_json_text(char* txt)
{

View File

@ -9,6 +9,8 @@
#include <map>
#include <base/utils.h> // for refer
class gb_json;
class sane_opt_provider : public refer
{
bool is_in_another_module_;
@ -23,6 +25,7 @@ public:
sane_opt_provider();
static std::string sane_value_2_text(const char* type, void* value); // convert to readable text. e.g. bool to "true" or "false", ...
static void set_opt_value(gb_json* opt, void* value, const char* key = "cur");
protected:
virtual ~sane_opt_provider();

View File

@ -1213,6 +1213,7 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c
type = sane_opt_provider::sane_value_2_text(type.c_str(), &val[0]);
utils::to_log(LOG_LEVEL_ALL, "Set option '%s' to default value: '%s'\n", opt->key().c_str(), type.c_str());
from->set_value(opt->key().c_str(), &val[0]);
sane_opt_provider::set_opt_value(opt, &val[0]);
}
}
}