View Single Post
Perfect Scrash
Senior Member
Join Date: Aug 2013
Location: Brazil
Old 07-25-2018 , 22:17   Re: Settings API (load/save data to INI files)
Reply With Quote #26

Change:
Code:
SectionExists(file, setting_section[])
{
	// Seek to setting's section
	new linedata[96], section[64]	
	while (!feof(file))
	{
		// Read one line at a time
		fgets(file, linedata, charsmax(linedata))
		
		// Replace newlines with a null character
		replace(linedata, charsmax(linedata), "^n", "")
		
		// New section starting
		if (linedata[0] == '[')
		{
			// Store section name without braces
			copyc(section, charsmax(section), linedata[1], ']')
			
			// Is this our setting's section?
			if (equal(section, setting_section))
				return true;
		}
	}
	
	return false;
}
To:
Code:
SectionExists(file, setting_section[])
{
	// Seek to setting's section
	new linedata[96], section[64]	
	while (!feof(file))
	{
		// Read one line at a time
		fgets(file, linedata, charsmax(linedata))
		
		// Replace newlines with a null character
		replace(linedata, charsmax(linedata), "^n", "")
		
		// New section starting
		if (linedata[0] == '[')
		{
			// Store Section Name
			formatex(section, charsmax(section), "[%s]", setting_section)

			// Is this our setting's section?
			if(equal(linedata, section, strlen(section)))
				return true;
		}
	}
	return false;
}
For Fix this bug when save/load section with [ or ] chars:
https://imgur.com/u28wrhP
__________________
Perfect Scrash is offline
Send a message via Skype™ to Perfect Scrash