EasyINI class omitting comments?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

EasyINI class omitting comments?

05 Jan 2018, 08:54

Hello,

im having an issue with the EasyINI class does not support omit commented text, but includes it into the value and when writing the changed value to ini file, the comments does disappear, which i dont want. The class is huge and written in such a style im not very familiar with. Are there anyone who could figure out how to change the class to omit commenting ; and leave them untouched when saving the digit value only?

The INI:

Code: Select all

output_edl=0             ; Edit decision list output
edl_skip_field=3         ; 0-Cut 1-Mute 2-Scene Marker (if start and end times are specified, the end time is used) 3-Commercial Break (playback skip mode)
The code:

Code: Select all

comskipINI := class_EasyIni(A_ScriptDir . "\comskip\Test.ini")
msgbox % "output_edl=" comskipINI[Section].output_edl "`nedl_skip_field=" comskipINI[Section].edl_skip_field
;comskipINI[Section].output_edl := 1
;comskipINI[Section].edl_skip_field := 0
;comskipINI.Save()
;msgbox % "output_edl=" comskipINI[Section].output_edl "`nedl_skip_field=" comskipINI[Section].edl_skip_field
The EasyINI class:
Spoiler
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

05 Jan 2018, 17:53

Ok, no takers so far. I guess I have to specify a bit. Notice in the Loop, Parse, sIni, how measures are being taken for A_Blank and ; but that consequently fails when retrieving the values. Why are A_Blank used since it is not a member of the built-in variables and is it possible to get this working? If trying to exchange a_blank to A_Space class breaks.

Code: Select all

Loop, Parse, sIni, `n, `r
		{
			sTrimmedLine := Trim(A_LoopField)
			; Comments or newlines within the ini
			if (SubStr(sTrimmedLine, 1, 1) == ";" || sTrimmedLine == A_Blank) { ; A_Blank would be a newline
				; Chr(14) is just the magical char to indicate that this line should only be a newline "`n"
				LoopField := A_LoopField == A_Blank ? Chr(14) : A_LoopField
				if (sCurSec == A_Blank)
					this.EasyIni_ReservedFor_TopComments.Insert(A_Index, LoopField) ; not using sTrimmedLine so as to keep comment formatting
				else {
					if (sPrevKeyForThisSec == A_Blank) ; This happens when there is a comment in the section before the first key, if any
						sPrevKeyForThisSec := "SectionComment"
					if (IsObject(this[sCurSec].EasyIni_ReservedFor_Comments)) {
						if (this[sCurSec].EasyIni_ReservedFor_Comments.HasKey(sPrevKeyForThisSec))
							this[sCurSec].EasyIni_ReservedFor_Comments[sPrevKeyForThisSec] .= "`n" LoopField
						else this[sCurSec].EasyIni_ReservedFor_Comments.Insert(sPrevKeyForThisSec, LoopField)
					}
					else {
						if (IsObject(this[sCurSec]))
							this[sCurSec].EasyIni_ReservedFor_Comments := {(sPrevKeyForThisSec):LoopField}
						else this[sCurSec, "EasyIni_ReservedFor_Comments"] := {(sPrevKeyForThisSec):LoopField}
					}
				}
				continue
			}
			; [Section]
			if (SubStr(sTrimmedLine, 1, 1) = "[" && InStr(sTrimmedLine, "]")) { ; need to be sure that this isn't just a key starting with "["
				if (sCurSec != A_Blank && !this.HasKey(sCurSec))
					this[sCurSec] := EasyIni_CreateBaseObj()
				sCurSec := SubStr(sTrimmedLine, 2, InStr(sTrimmedLine, "]", false, 0) - 2) ; 0 search right to left. We want to trim the *last* occurence of "]"
				sPrevKeyForThisSec := ""
				continue
			}
			; key=val
			iPosOfEquals := InStr(sTrimmedLine, "=")
			if (iPosOfEquals) {
				sPrevKeyForThisSec := SubStr(sTrimmedLine, 1, iPosOfEquals - 1) ; so it's not the previous key yet...but it will be on next iteration :P
				val := SubStr(sTrimmedLine, iPosOfEquals + 1)
				StringReplace, val, val , `%A_ScriptDir`%, %A_ScriptDir%, All
				StringReplace, val, val , `%A_WorkingDir`%, %A_ScriptDir%, All
				this[sCurSec, sPrevKeyForThisSec] := val
			}
			else { ; at this point, we know it isn't a comment, or newline, it isn't a section, and it isn't a conventional key-val pair. Treat this line as a key with no val
				sPrevKeyForThisSec := sTrimmedLine
				this[sCurSec, sPrevKeyForThisSec] := ""
			}
		}
		; if there is a section with no keys and it is at the bottom of the file, then we missed it
		if (sCurSec != A_Blank && !this.HasKey(sCurSec))
			this[sCurSec] := EasyIni_CreateBaseObj()
		return this
	}
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: EasyINI class omitting comments?

06 Jan 2018, 03:29

A_Blank should be read as A_Empty. It's an uninitialized local variable 'containing' an empty string ("").

INI files don't support same-line comments.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

06 Jan 2018, 04:43

just me wrote:A_Blank should be read as A_Empty. It's an uninitialized local variable 'containing' an empty string ("").
Aha, thanks for the clarification.
just me wrote:INI files don't support same-line comments.
I suppose you mean that Chris/lexikos didnt/dont want it to be supported for AHK, but its of course more dependent on the software that should read the INI. In this case Comskip which has absolutely no problem reading the key value and omit same-line comments. It does not write to the INI though. Well, I just cannot accept "not supported", to me this is complete nonsense. I will try to get same-line commenting detection/omitting working anyways, excuse my hardheadedness :oops:
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: EasyINI class omitting comments?

06 Jan 2018, 06:37

INI files are plain text files, so you can do whatever you want. But if you use the appropriate Windows API functions to read an INI, same line comments will be treated as part of the value. Each application which strips this kind of comments must do it internally, because it's not standard.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: EasyINI class omitting comments?

06 Jan 2018, 07:25

zcooler wrote:Well, I just cannot accept "not supported", to me this is complete nonsense.
It would be complete monsense if AHK didn’t follow the Microsoft standard. If my value was supposed to include a “;” but AHK stopped reading it at that point because they decided to treat that as an inline comment that doesn’t exist in the standard, that would be nonsense.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

06 Jan 2018, 07:49

boiler wrote:
zcooler wrote:Well, I just cannot accept "not supported", to me this is complete nonsense.
It would be complete monsense if AHK didn’t follow the Microsoft standard. If my value was supposed to include a “;” but AHK stopped reading it at that point because they decided to treat that as an inline comment that doesn’t exist in the standard, that would be nonsense.
MS are using OS reserved chars all the time (file names) (xml dom has reserved chars), why would that be any different from reserving ";" for INIs?
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: EasyINI class omitting comments?

06 Jan 2018, 08:08

Because that's what they decided. If you have an issue with it, take it up with them.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

06 Jan 2018, 08:11

boiler wrote:Because that's what they decided.
Yes...and therein lies the nonsense ;) But I do understand in such a case, ultimately a bunch of chars has to be reserved, cuz every language and script engine probably uses their own comment char.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: EasyINI class omitting comments?

06 Jan 2018, 08:58

It is reserved in the sense that it can’t be in a key name since it is the comment character (the comment character for a language using the ini file should have nothing to do with the ini file, and indeed it doesn’t). But comments must be on their own line. It makes sense to have fewer restrictions on the value.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

06 Jan 2018, 09:35

Ok, fine, you are right and sorry for the "nonsense" statement ;) Do you have anything to add solving the topic issue? Yes, that EasyINI version will not be used with any Windows API functions! I really wanna keep those same-line comments, cuz the ini file is huge with many commands and adding own-line comments would make it even more immense (twice as long) compared to what it is now and im not sure if Comskip understands own-line comments, probably not. Additionally this has to work with a standard comskip.ini which have same-line comments and no sections (a couple of empty section square brackets are left in the INI when saving).
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: EasyINI class omitting comments?

06 Jan 2018, 10:29

You would need to add an additional array for the same line comments to store them after stripping them from the read key/value line while reading the INI. When writing the INI, you could add the comment from this array, then.
zcooler wrote:In this case Comskip which has absolutely no problem reading the key value and omit same-line comments. It does not write to the INI though.
Which application actually needs the comments?

Edit: I didn't read your last post carefully enough.
Additionally this has to work with a standard comskip.ini which have same-line comments and no sections (a couple of empty section square brackets are left in the INI when saving).
This means it isn't a standard INI file.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

06 Jan 2018, 10:40

just me wrote:This means it isn't a standard INI file.
Correctomundo, just me! Its far from it and the comments contain very useful information about every tuning parameter comskip has. With "standard comskip.ini" I mean "default" (which comes with the comskip app) not standard ini in MS sense. Everyone who have tried tuning an comskip.ini for a TV channel to detect commercial breaks to perfection, knows how vital the comment info are :) Without it you are lost.
just me wrote:You would need to add an additional array for the same line comments to store them after stripping them from the read key/value line while reading the INI. When writing the INI, you could add the comment from this array, then.
Ok, I will try to see what I can do. Many thanks :wave:
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

07 Jan 2018, 12:39

Arrg... :headwall: A complete nightmare working with this class. Not even simple arrays works or using objects...WTF! Im giving up :( Have been written two simple classes on my own before, but this one is something else and its above my intermediate amateur level.

EasyINI class
Spoiler
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: EasyINI class omitting comments?

08 Jan 2018, 04:03

As for as I can see you want to automatically edit one special file called ComSkip.ini which isn't standard INI format. So why do you want to use EasyINI.ahk at all?
Do you only need to change some values or do you need to add new key/value pairs?
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

08 Jan 2018, 11:50

just me wrote:As for as I can see you want to automatically edit one special file called ComSkip.ini which isn't standard INI format. So why do you want to use EasyINI.ahk at all?
EasyINI is a bliss to use and handles all settings and available languages for the ML. Since this Comskip tuning tool Im developing was planned to be a part of it, I figured why not using the awesome EasyINI. Didnt know at that point how xtreamly advanced it was with the ordered arrays and how difficult it was going to be using ;, a_space and `n characters in array keys. I thought a grand challenge for me trying to get better at AHK, but the only thing i did was discovering, first hand, there is a very good reason why same-line comments are not supported and avoided like the plague ;) So i will scrap the idea and focus on something else.
just me wrote:Do you only need to change some values or do you need to add new key/value pairs?
Unfortunately Yes, on both accounts. There are many comskip tuning parameters (key/value pairs) that does not exist in the default INI, that I wanna have the possibility to add and I also thought about having the possibilty to retrieve same-line comments exclusively (since storing them in a separate array) in order to use them inside the GUI, but continuing this is just too far fetched.

just me, thanks anyway for your support and reasoning :wave:

Regards
zcooler
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: EasyINI class omitting comments?

08 Jan 2018, 12:18

I might be wrong, but from what I read on the ComSkip site, the order of the settings in the INI doesn't matter. If you want to edit the file manually with a GUI, all you need is an Edit control. Otherwise, which kind of controls shall your GUI contain?
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

08 Jan 2018, 13:22

That is correct the order of the settings does not matter.

Before doing any of the GUI stuff I have to work out some alternate core functionality replacing the EasyINI plan. There actually already are a Comskip tuning application if you are interested to see how it looks like (download the free Comskip and start the ComskipINIEditor.exe) and my thoughts was to improve upon that one. Perhaps using the Pic Buttons GUIs you helped me with earlier and maybe tooltips. Tune by read and click...as little manual typing as possible ;) Oh and also include your awesome comskip output trim script somehow, if you remember it :D
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: EasyINI class omitting comments?

09 Jan 2018, 04:17

After a look at the ComskipINIEditor.exe I think it will be a real challenge to add features. Apparently, the comskip.txt file is used in combination with comskip.ini to display the information.

If you restrict your program to supply only predefined changes, there might be an 'easy' way (without EasyINI).
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: EasyINI class omitting comments?

09 Jan 2018, 13:53

just me wrote:After a look at the ComskipINIEditor.exe I think it will be a real challenge to add features. Apparently, the comskip.txt file is used in combination with comskip.ini to display the information.
Yes, the ComskipINIEditor.exe is too cool as is to leave out. Nontheless I want my own touch on it so Im gonna try to replicate it and then add/change a few things I am regarding as improvements (such as language translations...a few german guys i know, do want it in deutsch for example) :) The comskip.txt has been added by the editor author (support file to the editor) and not by the comskip author erik and yes it does read from the .TXT and write to the .INI with kept same-line comments.
just me wrote:If you restrict your program to supply only predefined changes, there might be an 'easy' way (without EasyINI).
Yes, I will look into it eventually. These troubles kind of took the fun right out of it and its priority got low. I need to focus on ML...getting the settings GUIs working and finished. Thanks for your support and attention...hopefully I didnt waste your time :wave:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mmflume, peter_ahk, ShatterCoder and 138 guests