From f3506846ad570bbee8f908b76f16de8ccf89928a Mon Sep 17 00:00:00 2001 From: nnhy Date: Fri, 1 Apr 2016 06:17:38 +0000 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8C=BA=E5=A2=9E=E5=8A=A0Re?= =?UTF-8?q?moveAll=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=A0=E9=99=A4=E6=89=80?= =?UTF-8?q?=E6=9C=89=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Config.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/Config.cpp b/Config.cpp index 24f7ea28..769ec53b 100644 --- a/Config.cpp +++ b/Config.cpp @@ -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 { diff --git a/Config.h b/Config.h index 9412eccb..215a1805 100644 --- a/Config.h +++ b/Config.h @@ -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; // 获取配置数据