[MortScript] iniEditor: get a friendly menu out of an .ini file!

Search This thread

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
It's very usefull as a developper to use .ini file to store settings of apps or MortScript scripts.

Unfortunately, you may have so many complicated settings (check IPTWeather for instance ;)), that you or newbies would like to be able to edit those settings without having to open the .ini configuration file.

That's why I've created the iniEditor.mscr script to get a friendly menu out of an .ini file:
attachment.php

This is more a proof of concept, and I would really like some developper can port it to a real .exe app to have a great layout as in the S2U2 settings for instance!

It can be used for any app or MortScript script that uses a .ini configuration file.

In the attachment, checkout the iniEditor.mscr which needs two parameters: the .ini file to edit, and your application name.

I've attached:
- the 'iniEditor.mscr' script which is the generic .ini file parser and configurator.
- the 'sample.ini' file to be edited.
- the 'sample.ini.desc' file that is the description file so you can remove all the comments in the 'sample.ini' file but still have them in the iniEditor menus to improve speed performance of your apps reading the 'sample.ini' file! All values in the 'sample.ini.desc' are the default values that are proposed if you cancel your changes for a field.
- the 'sampleConfig.mscr' script which calls the 'iniEditor.mscr' script with the right arguments.
- the 'calledScript.mscr' script which is called for one of the settings.

For the moment, you can set four types for the different settings:
- list: the setting is in a choice list defined in the .ini file;
- int: the setting is an integer;
- callscript: the setting is set using a MortScript script defined in the .ini file;
- fullfilepath: the setting is the full path of a file, to be set with a specific selection dialog box;
- path: the setting is a path, to be set with a specific selection dialog box;
- default: the setting is any entered string.

You set the type of a setting in the .ini.desc file by adding a comment just after the settings, like that:
Code:
[Some settings]
enableFeatureA=0
;list,0,1

You can also add some comments to be displayed for the user, by adding comments (on several lines if you want), like that:
Code:
[Some settings]
enableFeatureA=0
;list,0,1
;Set 0 to disable Feature A.
;Set 1 to enable Feature A.

And that gives you that:


Sometimes, there are so many things to say on a setting, that you don't want to or can't display all the comments about a setting in the menus of iniEditor.mscr.
Then, just added two semicolons at the beginning of the first "comment" line (after the "type" line"), like that:
Code:
advancedSetting=
;
;;Please check FAQ or sample.ini.desc file for more help on this setting.
;This is an advanved option.
;It is so long to explain how it works.
;I cannot show it in a MortScript message dialog box.
;But your are an advanced user.
;So you can find some tips directly here, but not through the iniEditor.mscr script.
And that gives you that:


If you set a parameter of type int, the user will be able to enter only an integer value:


If you set a parameter of type fullfilepath, you get this:


If you set a parameter of type path, you get this:


Feel free to use or modify my iniEditor.mscr, and if someone could make a real .exe app out of it, that would be great!
 

Attachments

  • EnterNewStringValue.jpg
    EnterNewStringValue.jpg
    33 KB · Views: 251
  • EnterNewIntegerValue.jpg
    EnterNewIntegerValue.jpg
    21.7 KB · Views: 171
  • ChooseValueFromList.jpg
    ChooseValueFromList.jpg
    17.6 KB · Views: 234
  • ChooseValueFromList2.jpg
    ChooseValueFromList2.jpg
    21.8 KB · Views: 91
  • fullfilepath.jpg
    fullfilepath.jpg
    34.4 KB · Views: 177
  • path.jpg
    path.jpg
    42.7 KB · Views: 182
  • iniEditor.gif
    iniEditor.gif
    76.5 KB · Views: 2,368
  • iniEditor_v05.zip
    3.3 KB · Views: 529
Last edited:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Thank you for your support JMHL :D.

I know I'm alone in my ini editor trip, but I've added two types of parameters: fullfilepath and path.
Just check the first post to have more information on these.

Still no one motivated to developp this in CF.Net for instance? ;)
 

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
I've seen that two people have downloaded my second version of iniEditor.
Please find in the first post a new version with a small bug corrected.
 

sv0911

Senior Member
May 1, 2010
681
291
Hi michoob,

A BIG THANKS for your new fantastic MortScript app...!!!!
As usual a great work...!!!!

I will of course use it also in my apps...!!!! :D

Greetings
sv0911
 
D

Deleted member 1890170

Guest
Thanks, thanks and again thanks

michoob,

a really great job you did! Extremely user friendly and tremendously fast!
 
D

Deleted member 1890170

Guest
Feel free to use or modify my iniEditor.mscr

I followed your invitation. These are the 2 changes I mainly made in my copy of your iniEditor.mscr

Code:
[COLOR="Red"][B]Copy(fileName, fileName & ".bak", 1)
iniChanged = 0[/B][/COLOR]
choosenSection = 1
While (choosenSection <> 0)
	choosenSection = Choice(appName & " settings", "Please choose a settings section:", 0,0, sectionList)
	If (choosenSection <> 0)
		Call("IPTWkeys")
	EndIf
EndWhile
[COLOR="Red"][B]If(not iniChanged)
	Delete(fileName & ".bak")
EndIf[/B][/COLOR]


If (confirmation)
	valueList[choosenKey] = newValue
	keyValueList[choosenKey] = keyList[choosenKey] & "=" & newValue
	IniWrite(fileName, sectionList[choosenSection], keyList[choosenKey], newValue)
	[COLOR="Red"][B]iniChanged += 1[/B][/COLOR]
EndIf
 
Last edited by a moderator:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
I've just updated the iniEditor.mscr script with a new feature really usefull when you have huge .ini files to improve reading performance of your .ini file and have your MortScript apps run faster!
This new feature is the use of the .ini.desc file that contains all default values and all the comment structure of iniEditor. Now, the .ini file can be comment free and still you'll have all the information while editing your .ini file through iniEditor!

As usual, you can test this new version with IPTWeather.

Feedbacks welcomed!
 
D

Deleted member 1890170

Guest
I've just updated the iniEditor.mscr script with a new feature really usefull when you have huge .ini files to improve reading performance of your .ini file and have your MortScript apps run faster!
This new feature is the use of the .ini.desc file that contains all default values and all the comment structure of iniEditor. Now, the .ini file can be comment free and still you'll have all the information while editing your .ini file through iniEditor!

Tried v04. Simply an ingenious improvement. Thanks.
 

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Thanks jwoegerbauer :D! I just thought about XML description files and said: why not the same with .ini file! :D

I just discovered the Configuration tool for Mortscripter that is an exe, but unfortunately, it doesn't right to nor from ini files, so it is a bit more complicated to use with .ini files, even though it can be done using some mortscript...

But I must admit that I like now the idea of a full MortScript "app" to read .ini files used by other MortScript "apps"... It is a bit like the meaning of GNU... :p
 

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Will you developp an iniEditor in C++ for me? :p

Honestly, I won't have time to learn developping on Windows Mobile, but thank you for the information. Maybe someone will be motivated to work on this, but I doubt it because of WP7... :(
 
D

Deleted member 1890170

Guest
Will you developp an iniEditor in C++ for me?
Of course NOT!

BTW: Here I small routine I made to prepare using iniEditor v0.4, may be others are interested in

Code:
Sub IniToIniDesc(ini)
Local(inicontent,idx,line,trimline,newini,desc,newdesc,fpos,feature)
desc=ini&".desc"
Copy(ini,desc,1)
inicontent=Split(ReadFile(ini)&"^NL^","^NL^")
#
#pass ONE
newini=Array()
idx=0
ForEach line In Array(inicontent)
	If(Find(line,";"))
		Continue
	EndIf
	trimline=Replace(line," ","")
	If(Length(trimline)=0)
		Continue
	EndIf
	idx+=1
	newini[idx]=line
EndForEach
WriteFile(ini,Join(newini,"^NL^"),0)
Clear(newini)
#
#pass TWO
newdesc=Array()
idx=0
ForEach line In Array(inicontent)
	trimline=Replace(line," ","")
	If(Length(trimline)=0)
		Continue
	EndIf
	idx+=1
	newdesc[idx]=line
	fpos=Find(trimline,"=0")
	If(NOT fpos)
		fpos=Find(trimline,"=1")
	EndIf
	If(fpos)
		#test whether 0 and/or 1 is the only character here
		If((fpos+2)>Length(trimline))
			feature=Substr(trimline,1,(fpos-1))
			idx+=1
			newdesc[idx]=";Set 0 to disable "&feature&".^NL^;Set 1 to enable "&feature&"."
		EndIf
	EndIf
EndForEach
WriteFile(desc,Join(newdesc,"^NL^"),0)
EndSub

As one will notice, this script 1) trims the original ini - thus the goal to gain speed when processing it will definitly be reached, and 2) only adds some ;Set lines to the desc, hence one of course have to edit the desc after having run this script.
 
Last edited by a moderator:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
It just prepares it for 0 or 1 values ini fields, doesn't it?
Then, to use iniEditor as a switch for 0 or 1 values to disable or enable a feature, it would be better to use a list with a choice between 0 or 1 ;).
I wonder which scripts do you use iniEditor with.
 
D

Deleted member 1890170

Guest
1) To satisfy your curiosity, the ini is attached

2) Only a suggestion:

If (endNextLinePos > 0)
valueTypeList[keyIndex] = ToLower(SubStr(iniDescFile, endLinePos + 2, endNextLinePos - endLinePos - 3))
endLinePos = endNextLinePos
Else
valueTypeList[keyIndex] = ToLower(SubStr(iniDescFile, endLinePos + 2, Length(iniDescFile) - endLinePos - 1))
endLinePos = endLinePos +1
EndIf
 

Attachments

  • MioPocket.ini.txt
    7 KB · Views: 10
D

Deleted member 1890170

Guest
Don't know this useful for others too: I added to v0.4 valueTypes as follows:

alpha
num
alphanum
hex
range

The modified version v0.4-p1 is attached.
 
Last edited by a moderator:

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
@michoob I have made some tweaks to an older version that I wanted to share. It skips the choose [settings] group if there is only one setting group. Also it updates the array with the latest saved changes so if you go to another setting group and then go back to a previously edited one the updates show. And I think lastly I added some code to keep the original settings if you cancel the change since some of them went blank.
 
  • Like
Reactions: michoob

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
@michoob I have made some tweaks to an older version that I wanted to share.
Thanks, I'll have a look at this. :)

]It skips the choose [settings] group if there is only one setting group.
Good idea! :D

Also it updates the array with the latest saved changes so if you go to another setting group and then go back to a previously edited one the updates show.
Hum... the latest version already does that. Maybe because you edited an older version :p.

And I think lastly I added some code to keep the original settings if you cancel the change since some of them went blank
I don't get it. But I'll have a look at this ;).
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    @michoob I have made some tweaks to an older version that I wanted to share. It skips the choose [settings] group if there is only one setting group. Also it updates the array with the latest saved changes so if you go to another setting group and then go back to a previously edited one the updates show. And I think lastly I added some code to keep the original settings if you cancel the change since some of them went blank.
    1
    Why not a flag, I was also thinking of a flag to enable the .bkp copy ;).
    Great, that would be helpful.

    -------------------------------------

    I played with version 4 from 1st post. Added switches to allow description file or not. Call is CallScript("iniEditor.mscr", "sample", "Dummy", TRUE, TRUE) where old calls without the last two TRUEs will work as calling the desc file and requiring confirmation. Please give me your feedback if I missed something.

    Just added another flag for the size of the selection boxes in choice so now CallScript("iniEditor.mscr", "sample", "Dummy", TRUE, TRUE, 30)
    1
    Ok, I have one suggestion: do not edit your post if you make a change several days later in the latest post of a thread :D.
    Because I'm subscribed to this thread and I'm seeing your work only now :(.
    ;).

    Other than that, your changes are interesting.
    But personnally, I don't want to have all these options in iniEditor.
    So it seems like we will have different branches of iniEditor :).
    I wonder if I should'nt start a new Google Code project for iniEditor. It would be way easier to merge the changes of each contributor :).

    Anyway, my version v05 that I'm just publishing comes with two additionnal parameters that are optional (if empty, you'll have the behaviour of v04).
    Here is the list of v05 parameters:
    # Parameters:
    # 1 - string: name of the .ini file to edit
    # 2 - string: name of the application that uses the .ini file (just for display purpose)
    # 3 - boolean (optional, default is FALSE): if 1 or TRUE, create a .ini.bkp backup file if changes are made
    # 4 - boolean (optional, default is TRUE): if 0 or FALSE, do not prompt for change confirmation. If FALSE, the cancel button will just cancel the change

    I took some of your ideas, and some of jwoegerbauer ideas.

    EDIT: I'm attaching here versions v04 and v05 for history purpose ;)

    So, what do you think?