Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When ini.remove(section) is used, ini file breaks #36

Closed
Meridiano opened this issue Jul 25, 2024 · 4 comments
Closed

When ini.remove(section) is used, ini file breaks #36

Meridiano opened this issue Jul 25, 2024 · 4 comments

Comments

@Meridiano
Copy link

Input ini file

[CustomSectionDestroy]
DESTROY_A=WYZ
DESTROY_B=KID

[CustomSectionGet]
iA=123
iB=456
iC=Example String A

[TestPull]
bBool=true
iInt=333
fFloat=135.248
sString=Example String B

[CustomSectionClear]
CLEAR_VALUE_A=ABCD
CLEAR_VALUE_B=EFGH

Output ini file

[CustomSectionGet]
iA=WYZ
iB=KID
iC=123
destroy_a=WYZ
destroy_b=KID

[TestPull]
bBool=123
iInt=456
fFloat=Example String A
sString=true
ia=123
ib=456
ic=Example String A

[CustomSectionClear]
CLEAR_VALUE_A=true
CLEAR_VALUE_B=333
bbool=true
iint=333
ffloat=135.248
sstring=Example String B

Used code snippet > DestroyIniData(1, "mini-test.ini", "CustomSectionDestroy", "") is called

bool DestroyIniData(std::int32_t level, std::string path, std::string section, std::string key) {
	mINI::INIFile file(path);
	mINI::INIStructure ini;
	if (file.read(ini)) {
		if (level == 0) {
			fs::path target = path;
			return std::filesystem::remove(target);
		} else if ((level == 1) && ini.has(section)) {
			ini.remove(section);
			return file.write(ini, usePrettyPrint);
		} else if ((level == 2) && ini.has(section) && ini.get(section).has(key)) {
			ini[section].remove(key);
			return file.write(ini, usePrettyPrint);
		}
		return false;
	}
	return false;
}

I also attach the whole solution (VS 2022), just in case.
mini-test.zip

@Meridiano
Copy link
Author

Version 0.9.14 works as expected, the issue appears only in 0.9.15.

@metayeti
Copy link
Owner

Thanks for reporting this, I'll look into it when I have some time on my hands.

@metayeti
Copy link
Owner

Yeah this is very very bad. Apparently the assignment operator introduced in 0.9.15 is the cause for this, I will publish a new version with a fix soon. Thanks again for reporting this.

@metayeti
Copy link
Owner

Fixed in 0.9.16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants