summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-21 21:08:20 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-21 21:17:31 +0300
commit4a4681e6994e3489d2ab0f32d2cb19d97a8b496e (patch)
treefd342a89f8db4982ac7004d4ba6036c5da8050a9
parentc2d8a6fbeba27a125cf3e2581d762c8c58a8e6d1 (diff)
downloadmv-4a4681e6994e3489d2ab0f32d2cb19d97a8b496e.tar.gz
mv-4a4681e6994e3489d2ab0f32d2cb19d97a8b496e.tar.bz2
mv-4a4681e6994e3489d2ab0f32d2cb19d97a8b496e.tar.xz
mv-4a4681e6994e3489d2ab0f32d2cb19d97a8b496e.zip
Add ability to remove old unused keys from configuration file.
-rw-r--r--src/client.cpp10
-rw-r--r--src/configuration.cpp203
-rw-r--r--src/configuration.h15
-rw-r--r--src/localconsts.h2
-rw-r--r--src/test/testmain.cpp2
5 files changed, 229 insertions, 3 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 3d4e2a37d..77625c924 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -803,6 +803,10 @@ void Client::gameClear()
if (logger)
logger->log1("Quitting10");
+#ifdef DEBUG_CONFIG
+ config.enableKeyLogging();
+#endif
+ config.removeOldKeys();
config.write();
serverConfig.write();
@@ -1765,6 +1769,10 @@ void Client::initServerConfig(std::string serverName)
*/
void Client::initConfiguration()
{
+#ifdef DEBUG_CONFIG
+ config.setIsMain(true);
+#endif
+
// Fill configuration with defaults
config.setValue("hwaccel", false);
#if (defined __APPLE__) && defined USE_OPENGL
@@ -1777,7 +1785,7 @@ void Client::initConfiguration()
config.setValue("screen", false);
config.setValue("sound", true);
config.setValue("guialpha", 0.8f);
- config.setValue("remember", true);
+// config.setValue("remember", true);
config.setValue("sfxVolume", 100);
config.setValue("musicVolume", 60);
config.setValue("fpslimit", 60);
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 624cf7865..e4a1702de 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -33,11 +33,175 @@
#include "debug.h"
#ifdef DEBUG_CONFIG
-#define GETLOG() if (logger) {logger->log("config get: " + key); }
+std::map<std::string, int> optionsCount;
+#define GETLOG() if (logger) {logger->log("config get: " + key); \
+ if (mIsMain) optionsCount[key] = 1; }
#else
#define GETLOG()
#endif
+const std::string unusedKeys[] =
+{
+ "AttackRange",
+ "emoteshortcut0",
+ "AttackRangeBorder",
+ "AttackRangeBorderDelay",
+ "AttackRangeBorderGradient",
+ "AttackRangeDelay",
+ "AttackRangeGradient",
+ "Being",
+ "BeingDelay",
+ "BeingGradient",
+ "BeingPopupSkin",
+ "BotCheckerWindowSkin",
+ "BuySellSkin",
+ "BuySkin",
+ "ChatSkin",
+ "CollisionHighlight",
+ "CollisionHighlightDelay",
+ "CollisionHighlightGradient",
+ "ColorCross",
+ "ColorCrossDelay",
+ "ColorCrossGradient",
+ "ColorExperience",
+ "ColorExperienceGradient",
+ "ColorPickup",
+ "ColorPickupGradient",
+ "DebugSkin",
+ "DropShortcutSkin",
+ "EmoteShortcutSkin",
+ "EquipmentSkin",
+ "ExpInfo",
+ "ExpInfoDelay",
+ "ExpInfoGradient",
+ "Experience",
+ "ExperienceGradient",
+ "GM",
+ "GMDelay",
+ "GMGradient",
+ "Guild",
+ "GuildDelay",
+ "GuildGradient",
+ "GuildSkin",
+ "HelpSkin",
+ "Hit CriticalDelay",
+ "Hit CriticalGradient",
+ "Hit Monster Player",
+ "Hit Monster PlayerGradient",
+ "Hit Player Monster",
+ "Hit Player MonsterGradient",
+ "HitCriticalDelay",
+ "HitCriticalGradient",
+ "HitLocalPlayerCriticalDelay",
+ "HitLocalPlayerCriticalGradient",
+ "HitLocalPlayerMiss",
+ "HitLocalPlayerMissDelay",
+ "HitLocalPlayerMissGradient",
+ "HitLocalPlayerMonster",
+ "HitLocalPlayerMonsterDelay",
+ "HitLocalPlayerMonsterGradient",
+ "HitMonsterPlayer",
+ "HitMonsterPlayerDelay",
+ "HitMonsterPlayerGradient",
+ "HitPlayerMonster",
+ "HitPlayerMonsterDelay",
+ "HitPlayerMonsterGradient",
+ "HomePlace",
+ "HomePlaceBorder",
+ "HomePlaceBorderDelay",
+ "HomePlaceBorderGradient",
+ "HomePlaceDelay",
+ "HomePlaceGradient",
+ "InventorySkin",
+ "ItemPopupSkin",
+ "ItemShortcutSkin",
+ "Kill statsSkin",
+ "MiniStatusSkin",
+ "MinimapSkin",
+ "Miss",
+ "MissDelay",
+ "MissGradient",
+ "Monster",
+ "MonsterAttackRange",
+ "MonsterAttackRangeDelay",
+ "MonsterAttackRangeGradient",
+ "MonsterDelay",
+ "MonsterGradient",
+ "NPC",
+ "NPCDelay",
+ "NPCGradient",
+ "NpcTextSkin",
+ "OutfitsSkin",
+ "Particle",
+ "ParticleDelay",
+ "ParticleGradient",
+ "PartyDelay",
+ "PartyGradient",
+ "PartySkin",
+ "Personal ShopSkin",
+ "Pickup",
+ "PickupGradient",
+ "Player",
+ "PlayerDelay",
+ "PlayerGradient",
+ "PopupMenuSkin",
+ "PortalHighlight",
+ "PortalHighlightDelay",
+ "PortalHighlightGradient",
+ "RecorderSkin",
+ "RecorderWinX",
+ "RecorderWinY",
+ "RoadPoint",
+ "RoadPointDelay",
+ "RoadPointGradient",
+ "Self",
+ "SelfDelay",
+ "SelfGradient",
+ "SellSkin",
+ "ServerDialogSkin",
+ "ShopSkin",
+ "SkillsSkin",
+ "SocialCreatePopupSkin",
+ "SocialSkin",
+ "SpecialsSkin",
+ "SpeechSkin",
+ "SpellPopupSkin",
+ "SpellShortcutSkin",
+ "StatusPopupSkin",
+ "StatusSkin",
+ "StorageSkin",
+ "TextCommandEditorSkin",
+ "TextPopupSkin",
+ "TradeSkin",
+ "WhoIsOnlineSkin",
+ "emoteshortcut1",
+ "emoteshortcut2",
+ "emoteshortcut3",
+ "emoteshortcut4",
+ "emoteshortcut5",
+ "emoteshortcut6",
+ "emoteshortcut7",
+ "emoteshortcut8",
+ "emoteshortcut9",
+ "emoteshortcut10",
+ "emoteshortcut11",
+ "emoteshortcut12",
+ "emoteshortcut13",
+ "fastOpenGL",
+ "keyAutoCompleteChat",
+ "keyDeActivateChat",
+ "keyTargetClosest",
+ "keyWindowParty",
+ "mapalpha",
+ "port",
+ "shopBuyList",
+ "shopSellList",
+ "OutfitAwayIndex",
+ "playerHomes",
+ "remember",
+ ""
+};
+
void ConfigurationObject::setValue(const std::string &key,
const std::string &value)
{
@@ -152,6 +316,10 @@ Configuration::Configuration() :
mDefaultsData(nullptr),
mDirectory("")
{
+#ifdef DEBUG_CONFIG
+ mLogKeys = false;
+ mIsMain = false;
+#endif
}
void Configuration::cleanDefaults()
@@ -470,6 +638,7 @@ bool Configuration::resetBoolValue(const std::string &key)
return defaultValue;
}
+
void ConfigurationObject::initFromXML(XmlNodePtr parent_node)
{
clear();
@@ -549,6 +718,13 @@ void ConfigurationObject::writeToXML(XmlTextWriterPtr writer)
for (Options::const_iterator i = mOptions.begin(), i_end = mOptions.end();
i != i_end; ++i)
{
+#ifdef DEBUG_CONFIG
+ if (mLogKeys)
+ {
+ if (optionsCount.find(i->first) == optionsCount.end())
+ logger->log("unused configuration option: " + i->first);
+ }
+#endif
xmlTextWriterStartElement(writer, BAD_CAST "option");
xmlTextWriterWriteAttribute(writer,
BAD_CAST "name", BAD_CAST i->first.c_str());
@@ -636,3 +812,28 @@ void Configuration::removeListeners(ConfigListener *listener)
for (; it != it_end; ++ it)
(it->second).remove(listener);
}
+
+void Configuration::removeOldKeys()
+{
+ if (mOptions.find(unusedKeys[0]) != mOptions.end()
+ || mOptions.find(unusedKeys[1]) != mOptions.end())
+ {
+ int f = 0;
+ while (unusedKeys[f] != "")
+ {
+ deleteKey(unusedKeys[f]);
+ logger->log("remove unused key: " + unusedKeys[f]);
+ f ++;
+ }
+ for (f = 0; f < 80; f ++)
+ {
+ deleteKey("Outfit" + toString(f));
+ deleteKey("OutfitUnequip" + toString(f));
+ deleteKey("commandShortcutCmd" + toString(f));
+ deleteKey("commandShortcutFlags" + toString(f));
+ deleteKey("commandShortcutSymbol" + toString(f));
+ deleteKey("drop" + toString(f));
+ deleteKey("shortcut" + toString(f));
+ }
+ }
+}
diff --git a/src/configuration.h b/src/configuration.h
index 696ddcf3a..79fa9b5ba 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -192,6 +192,14 @@ class ConfigurationObject
return container;
}
+#ifdef DEBUG_CONFIG
+ void enableKeyLogging()
+ { mLogKeys = true; }
+
+ void setIsMain(bool b)
+ { mIsMain = b; }
+#endif
+
protected:
virtual void initFromXML(XmlNodePtr node);
virtual void writeToXML(XmlTextWriterPtr writer);
@@ -203,6 +211,11 @@ class ConfigurationObject
typedef std::list<ConfigurationObject *> ConfigurationList;
std::map<std::string, ConfigurationList> mContainerOptions;
+
+#ifdef DEBUG_CONFIG
+ bool mLogKeys;
+ bool mIsMain;
+#endif
};
/**
@@ -301,6 +314,8 @@ class Configuration : public ConfigurationObject
std::string getDirectory() const
{ return mDirectory; }
+ void removeOldKeys();
+
private:
/**
* Clean up the default values member.
diff --git a/src/localconsts.h b/src/localconsts.h
index de67c3850..4fbbbda2e 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -31,3 +31,5 @@
#else
#define A_UNUSED
#endif
+
+//#define DEBUG_CONFIG 1
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
index 70fcfc346..f5bdc5711 100644
--- a/src/test/testmain.cpp
+++ b/src/test/testmain.cpp
@@ -62,7 +62,7 @@ void TestMain::initConfig()
config.setValue("screen", false);
config.setValue("sound", false);
config.setValue("guialpha", 0.8f);
- config.setValue("remember", true);
+// config.setValue("remember", true);
config.setValue("sfxVolume", 50);
config.setValue("musicVolume", 60);
config.setValue("fpslimit", 0);