配置区增加RemoveAll,支持删除所有配置

This commit is contained in:
nnhy 2016-04-01 06:17:38 +00:00
parent b5cadce3a3
commit f3506846ad
2 changed files with 41 additions and 0 deletions

View File

@ -259,6 +259,45 @@ bool Config::Remove(const String& name) const
return header.Remove(Device, (uint)cfg);
}
bool Config::RemoveAll() const
{
TS("Config::RemoveAll");
/*int count = 0;
uint addr = Address;
if(!CheckSignature(Device, addr, false)) return count;
// 第一个配置块
auto cfg = (const ConfigBlock*)addr;
// 遍历链表,找到同名块
while(cfg->Valid())
{
count++;
#if CFG_DEBUG
debug_printf("Config::RemoveAll %d %s \r\n", count, cfg->Name);
#endif
auto next = cfg->Next();
// 重新搞一个配置头
ConfigBlock header;
cfg->CopyTo(Buffer(&header, sizeof(header)));
header.Size = 0;
Device.Write(&cfg, Buffer(&Hash, len));
cfg = next;
}*/
#if CFG_DEBUG
debug_printf("Config::RemoveAll (0x%08X, %d) \r\n", Address, Size);
#endif
ByteArray bs((byte)0xFF, Size);
return Device.Write(Address, bs);
}
// 根据名称更新块
const void* Config::Set(const String& name, const Buffer& bs) const
{

View File

@ -24,6 +24,8 @@ public:
const void* New(int size) const;
// 删除。仅清空名称,并不删除数据区
bool Remove(const String& name) const;
// 删除所有配置。
bool RemoveAll() const;
// 设置配置数据
const void* Set(const String& name, const Buffer& bs) const;
// 获取配置数据