配置区名称使用0结尾字符串,也就是最大智能7个字符
This commit is contained in:
parent
0794facec5
commit
fcfe40aa09
10
Config.cpp
10
Config.cpp
|
@ -20,7 +20,7 @@ struct ConfigBlock
|
||||||
{
|
{
|
||||||
ushort Hash;
|
ushort Hash;
|
||||||
ushort Size;
|
ushort Size;
|
||||||
char Name[8];
|
char Name[8]; // 零结尾字符串
|
||||||
|
|
||||||
ushort GetHash() const;
|
ushort GetHash() const;
|
||||||
bool Valid() const;
|
bool Valid() const;
|
||||||
|
@ -76,11 +76,10 @@ uint ConfigBlock::CopyTo(Buffer& bs) const
|
||||||
bool ConfigBlock::Init(const String& name, const Buffer& bs)
|
bool ConfigBlock::Init(const String& name, const Buffer& bs)
|
||||||
{
|
{
|
||||||
if(!name) return false;
|
if(!name) return false;
|
||||||
|
if(name.Length() >= sizeof(Name)) return false;
|
||||||
|
|
||||||
TS("ConfigBlock::Init");
|
TS("ConfigBlock::Init");
|
||||||
|
|
||||||
if(name.Length() > sizeof(Name)) return false;
|
|
||||||
|
|
||||||
// 配置块的大小,只有第一次能够修改,以后即使废弃也不能修改,仅仅清空名称
|
// 配置块的大小,只有第一次能够修改,以后即使废弃也不能修改,仅仅清空名称
|
||||||
if(bs.Length() > 0)
|
if(bs.Length() > 0)
|
||||||
{
|
{
|
||||||
|
@ -165,14 +164,13 @@ const ConfigBlock* FindBlock(const Storage& st, uint addr, const String& name)
|
||||||
TS("Config::Find");
|
TS("Config::Find");
|
||||||
|
|
||||||
if(!name) return nullptr;
|
if(!name) return nullptr;
|
||||||
|
if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr;
|
||||||
|
|
||||||
if(!CheckSignature(st, addr, false)) return nullptr;
|
if(!CheckSignature(st, addr, false)) return nullptr;
|
||||||
|
|
||||||
// 第一个配置块
|
// 第一个配置块
|
||||||
auto cfg = (const ConfigBlock*)addr;
|
auto cfg = (const ConfigBlock*)addr;
|
||||||
|
|
||||||
if(name.Length() > sizeof(cfg->Name)) return nullptr;
|
|
||||||
|
|
||||||
// 遍历链表,找到同名块
|
// 遍历链表,找到同名块
|
||||||
while(cfg->Valid())
|
while(cfg->Valid())
|
||||||
{
|
{
|
||||||
|
@ -252,6 +250,8 @@ const void* Config::Set(const String& name, const Buffer& bs) const
|
||||||
|
|
||||||
if(!name) return nullptr;
|
if(!name) return nullptr;
|
||||||
|
|
||||||
|
if(name.Length() >= sizeof(ConfigBlock::Name)) return nullptr;
|
||||||
|
|
||||||
auto cfg = FindBlock(Device, Address, name);
|
auto cfg = FindBlock(Device, Address, name);
|
||||||
if(!cfg) cfg = NewBlock(Device, Address, bs.Length());
|
if(!cfg) cfg = NewBlock(Device, Address, bs.Length());
|
||||||
if(!cfg) return nullptr;
|
if(!cfg) return nullptr;
|
||||||
|
|
|
@ -5,7 +5,7 @@ TinyConfig* TinyConfig::Current = nullptr;
|
||||||
|
|
||||||
TinyConfig::TinyConfig() : ConfigBase()
|
TinyConfig::TinyConfig() : ConfigBase()
|
||||||
{
|
{
|
||||||
_Name = "TinyConf";
|
_Name = "TinyCfg";
|
||||||
_Start = &Length;
|
_Start = &Length;
|
||||||
_End = &TagEnd;
|
_End = &TagEnd;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ TokenConfig::TokenConfig() : ConfigBase(),
|
||||||
Server(_Server, ArrayLength(_Server)),
|
Server(_Server, ArrayLength(_Server)),
|
||||||
Vendor(_Vendor, ArrayLength(_Vendor))
|
Vendor(_Vendor, ArrayLength(_Vendor))
|
||||||
{
|
{
|
||||||
_Name = "TokenCfg";
|
_Name = "TokenCf";
|
||||||
_Start = &Length;
|
_Start = &Length;
|
||||||
_End = &TagEnd;
|
_End = &TagEnd;
|
||||||
Init();
|
Init();
|
||||||
|
|
Loading…
Reference in New Issue