-
Notifications
You must be signed in to change notification settings - Fork 107
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
Fixed a bug where saving an empty item, makes a new line in the INI file. #2
Conversation
I said I would help people out with learning the YSI internals for a little bit to help the transition. That code will fix the general case, but y_ini supports comments, and the naming of "e_INI_LINE_TYPE_BLANK" is a bit bad, it should maybe be "e_INI_LINE_TYPE_DATALESS". A "blank" line has no tags or key/value pairs, but that doesn't actually mean it is totally empty, as a comment on its own line counts as "blank":
With that fix (I think), your file will end up like this after a save:
You've lost the comments. |
A better fix would possibly be: if (!deleted && p2s != p2e) fwrite(buffer, sLine); There are several returns from |
About POST 1: But now it only creates one empty line. (I don't really use comments if you are saying that it will remove the comments there.) And about POST 2: Thanks for the info, I will give it a try. |
Yup, I read through writing.inc and came to same conclusion e_INI_LINE_TYPE_BLANK naming is misleading. @johnymac: You want to update your PR to reflect that? |
Ok, It made the same result as mine. And yes I will commit it now. |
It is better because even if you don't use comments, that doesn't mean no-one does. So either fix will work for you, because you have no comments to preserve, but anyone with comments will loose them. |
The best solution would be if there wasn't a duplicate new line created (I've tried additional conditions around line 923), but it get's really weird when the value is empty, but there is a comment in the same line. We'll stick to this fix for foreseeable future. |
Fix duplicate new lines, when key has empty value.
Change lines 918-920 to: fwrite(buffer, YSI_g_sINIWriteBuffer[curSlot][E_INI_KV_ENTRY_NAME]),
fwrite(buffer, " = "),
fwrite(buffer, YSI_g_sINIWriteBuffer[curSlot][E_INI_KV_ENTRY_TEXT]); The old version (I think, I've not tested any of this), printed the old version of the line, ending at the start of the value ( |
If I'm right about that fix, it should never write the extra blank line in the first place, so the old fix can be reverted. With that other fix, explicit blank lines are also consumed, so a neatly laid out INI file like:
Will become:
Which IMHO is unlikely to be what is wanted. |
Ok, I did some fast testing and the old version didn't add spaces between tags also.. So I think using the second solution would be better. |
Ok, almost perfect. Currently when comment is after empty value the ";" get's copied ad infinitum. For some reason p2s is at |
I'm not saying it ADDED spaces, I'm saying it didn't REMOVE them. If you have a hand written/edited INI file that has spaces anywhere (that example was just between the tags), then they are preserved in the old version to match the user's style as closely as possible. That's why the old write line code used |
That comment location bug is interesting - |
I was doing some more tests and that bug isn't happening to me :/ |
Hah, this is quite peculiar one:
Gets rewritten as
So, when empty value is written we have two padding spaces - one from " = ", other one from INI_WriteComments, and this shakes stuff up a little bit. |
Misiur@a447167 fixes comment duplication as well. |
I was literally typing that line 599 fix as you posted that. You may also want to change fwrite(buffer, ";"), \ To avoid all the extra spaces. |
Merge code (half of which I wrote anyway).
More INFO: http://forum.sa-mp.com/showpost.php?p=3433253&postcount=13
And also I removed a useless copy of writing.inc file.