Changeset - r10752:370d8332151c
[Not reviewed]
master
0 3 0
peter1138 - 15 years ago 2009-01-14 20:23:45
peter1138@openttd.org
(svn r15085) -Fix (r14164): Clearing a settings group did not delete old items nor reset the last_item pointer, causing lists to not be saved unless they started blank.
3 files changed with 16 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/ini.cpp
Show inline comments
 
@@ -77,6 +77,13 @@ IniItem *IniGroup::GetItem(const char *n
 
	return new IniItem(this, name, len);
 
}
 

	
 
void IniGroup::Clear()
 
{
 
	delete this->item;
 
	this->item = NULL;
 
	this->last_item = &this->item;
 
}
 

	
 
IniFile::IniFile(const char **list_group_names) : group(NULL), comment(NULL), list_group_names(list_group_names)
 
{
 
	this->last_group = &this->group;
src/ini_type.h
Show inline comments
 
@@ -64,6 +64,11 @@ struct IniGroup {
 
	 * @return the requested item or NULL if not found.
 
	 */
 
	IniItem *GetItem(const char *name, bool create);
 

	
 
	/**
 
	 * Clear all items in the group
 
	 */
 
	void Clear();
 
};
 

	
 
/** The complete ini file. */
src/settings.cpp
Show inline comments
 
@@ -639,7 +639,7 @@ static void ini_save_setting_list(IniFil
 

	
 
	if (proc == NULL && list == NULL) return;
 
	if (group == NULL) return;
 
	group->item = NULL;
 
	group->Clear();
 

	
 
	for (i = 0; i != len; i++) {
 
		entry = (proc != NULL) ? proc(NULL, i) : list[i];
 
@@ -1720,11 +1720,9 @@ static void NewsDisplaySaveConfig(IniFil
 
static void AISaveConfig(IniFile *ini, const char *grpname)
 
{
 
	IniGroup *group = ini->GetGroup(grpname);
 
	IniItem **item;
 

	
 
	if (group == NULL) return;
 
	group->item = NULL;
 
	item = &group->item;
 
	group->Clear();
 

	
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		AIConfig *config = AIConfig::GetConfig(c, true);
 
@@ -1739,9 +1737,8 @@ static void AISaveConfig(IniFile *ini, c
 
			name = "none";
 
		}
 

	
 
		*item = new IniItem(group, name);
 
		(*item)->value = strdup(value);
 
		item = &(*item)->next;
 
		IniItem *item = new IniItem(group, name, strlen(name));
 
		item->SetValue(value);
 
	}
 
}
 

	
0 comments (0 inline, 0 general)