mirror of https://github.com/OpenTTD/OpenTTD
(svn r14167) -Fix: items in some ini-groups got duplicated on save.
parent
262ddecfc5
commit
621a9b647a
14
src/ini.cpp
14
src/ini.cpp
|
@ -19,14 +19,6 @@ IniItem::IniItem(IniGroup *parent, const char *name, size_t len) : next(NULL), v
|
||||||
parent->last_item = &this->next;
|
parent->last_item = &this->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
IniItem::IniItem(IniGroup *parent, const char *name, const char *value) : next(NULL), comment(NULL)
|
|
||||||
{
|
|
||||||
this->name = strdup(name);
|
|
||||||
this->value = strdup(value);
|
|
||||||
*parent->last_item = this;
|
|
||||||
parent->last_item = &this->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
IniItem::~IniItem()
|
IniItem::~IniItem()
|
||||||
{
|
{
|
||||||
free(this->name);
|
free(this->name);
|
||||||
|
@ -36,6 +28,12 @@ IniItem::~IniItem()
|
||||||
delete this->next;
|
delete this->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IniItem::SetValue(const char *value)
|
||||||
|
{
|
||||||
|
free(this->value);
|
||||||
|
this->value = strdup(value);
|
||||||
|
}
|
||||||
|
|
||||||
IniGroup::IniGroup(IniFile *parent, const char *name, size_t len) : next(NULL), type(IGT_VARIABLES), item(NULL), comment(NULL)
|
IniGroup::IniGroup(IniFile *parent, const char *name, size_t len) : next(NULL), type(IGT_VARIABLES), item(NULL), comment(NULL)
|
||||||
{
|
{
|
||||||
if (len == 0) len = strlen(name);
|
if (len == 0) len = strlen(name);
|
||||||
|
|
|
@ -26,14 +26,6 @@ struct IniItem {
|
||||||
*/
|
*/
|
||||||
IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
|
IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new in-memory item of an Ini file.
|
|
||||||
* @param parent the group we belong to
|
|
||||||
* @param name the name of the item
|
|
||||||
* @param value the value to immediatelly assign
|
|
||||||
*/
|
|
||||||
IniItem(IniGroup *parent, const char *name, const char *value);
|
|
||||||
|
|
||||||
/** Free everything we loaded. */
|
/** Free everything we loaded. */
|
||||||
~IniItem();
|
~IniItem();
|
||||||
|
|
||||||
|
|
|
@ -640,7 +640,7 @@ static void ini_save_setting_list(IniFile *ini, const char *grpname, char **list
|
||||||
|
|
||||||
if (entry == NULL || *entry == '\0') continue;
|
if (entry == NULL || *entry == '\0') continue;
|
||||||
|
|
||||||
new IniItem(group, entry, "");
|
group->GetItem(entry, true)->SetValue("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1687,7 +1687,7 @@ static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname)
|
||||||
|
|
||||||
value = (v == ND_OFF ? "off" : (v == ND_SUMMARY ? "summarized" : "full"));
|
value = (v == ND_OFF ? "off" : (v == ND_SUMMARY ? "summarized" : "full"));
|
||||||
|
|
||||||
new IniItem(group, _news_type_data[i].name, value);
|
group->GetItem(_news_type_data[i].name, true)->SetValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1708,7 +1708,7 @@ static void SaveVersionInConfig(IniFile *ini)
|
||||||
};
|
};
|
||||||
|
|
||||||
for (uint i = 0; i < lengthof(versions); i++) {
|
for (uint i = 0; i < lengthof(versions); i++) {
|
||||||
new IniItem(group, versions[i][0], versions[i][1]);
|
group->GetItem(versions[i][0], true)->SetValue(versions[i][1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1722,7 +1722,7 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li
|
||||||
char params[512];
|
char params[512];
|
||||||
GRFBuildParamList(params, c, lastof(params));
|
GRFBuildParamList(params, c, lastof(params));
|
||||||
|
|
||||||
new IniItem(group, c->filename, params);
|
group->GetItem(c->filename, true)->SetValue(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue