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

Search This thread

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Originally Posted by RoryB
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 ;).
What I mean is for one example when I went to set name and pressed cancel it would become blank even though Michoob was in the text box.
 

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Ah, ok, then you are really working on an old version :p.

In the version 4, it will prompt if you really want to set it to blank or not, and if not, it will prompt if you want to set back to the default value which is the value in the .ini.desc file! :)

But still I like your idea of skiping the section part in you only have one section :).

I'll compile this idea with the change of jwoegerbauer in a new version so everyone can have these features in one version :).

I'm so glad to see other people using iniEditor.
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Ah, ok, then you are really working on an old version :p.

In the version 4, it will prompt if you really want to set it to blank or not, and if not, it will prompt if you want to set back to the default value which is the value in the .ini.desc file! :)

But still I like your idea of skiping the section part in you only have one section :).

I'll compile this idea with the change of jwoegerbauer in a new version so everyone can have these features in one version :).

I'm so glad to see other people using iniEditor.
I'll look at your latest when you release. Another thing I did was remove the confirmation. Could you add a flag check to not ask for confirmation of changes?
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
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)
 

Attachments

  • iniEditor.mscr.txt
    7.3 KB · Views: 9
Last edited:
  • Like
Reactions: michoob

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
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?
 

Attachments

  • iniEditor_v04.zip
    2.8 KB · Views: 2
  • iniEditor_v05.zip
    3.3 KB · Views: 5
Last edited:
  • Like
Reactions: RoryB

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
I'll look at it some more later, but it appears you require a description file. I have a simple ini file that has no descriptions and iniEditor works fine if I allow it to not require a descr file as in the version I sent.

I agree we should avoid different versions. Let me know how I could help. I have not published my version anywhere, but I do have it included in my CHT Widget. I can move my code into my other script so there will not be another version of iniEditor floating around.

I have noticed if you accept a change to an item, but then cancel the main page it does not go back to the original settings.
 
Last edited:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Actually, it is not that I don't want to have several different versions floating around.
But still, we can indeed try to have a single version with the requirements of everybody.
My idea is also that the new version should be able to behave the same way as previous versions if no parameters are given.
Please note that in v05, I've also added a check not to display the section choice if you have only one or no section at all ;).

Maybe iniEditor could just check the existence of the .ini.desc file instead of retrieving a parameter for the filetype?
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
My concern of several versions is if someone overwrites a one version with a different based one that causes failure. Like in my widget versus someone else's work.

It would be easy to take argv[1] and add .desc to it and check fileexists.

If(fileexists(filename & ".desc"))
Descfile = filename & ".desc"
Else
Descfile = filename
endif
 
Last edited:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
@RoryB: totally, you're right actually. If I have time tonight, I'll create a Google Code Project for iniEditor. And I could then also add you as a contributor (PM a Google Code login of your own) so you can commit any change whenever you want :). I'll also add your change for the .desc file to iniEditor.
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
Great. I could not wait to think of something else. If they forget to put ".ini" at the end of argv[1] or they put ".desc" instead or if we want to let people leave it out.
Code:
if(substr(filename, -4) NE ".ini")
  if(substr(filename, -5) NE ".desc")
    iniFileName= filename & ".ini"
  else
    iniFileName= part(filename, ".", 1, FALSE ) & ".ini"
  endif
else
  iniFileName = filename
endif
Also, if we leave out the SystemPath("ScriptPath") we could allow iniEditor.mscr to exist in a different folder. The user would have to make sure SampleConfig.mscr included paths in the arguments as in
CallScript("\programs\script\iniEditor.mscr", "\programs\sample\sample.ini", "Dummy", TRUE, FALSE)
 
Last edited:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Great. I could not wait to think of something else. If they forget to put ".ini" at the end of argv[1] or they put ".desc" instead or if we want to let people leave it out.
Code:
if(substr(filename, -4) NE ".ini")
  if(substr(filename, -5) NE ".desc")
    iniFileName= filename & ".ini"
  else
    iniFileName= part(filename, ".", 1, FALSE ) & ".ini"
  endif
else
  iniFileName = filename
endif
=> me no like :(
You might want to use a different extension than .ini for ini files...
I would rather do a FileExists test, and if the file doesn't exist, then do the check and append the .ini extension ;).

Also, if we leave out the SystemPath("ScriptPath") we could allow iniEditor.mscr to exist in a different folder.
=> me like :)
But again, with a FileExists test, we could keep the old behaviour together with this suggestion ;).
 

RoryB

Inactive Recognized Developer
Sep 4, 2008
2,921
766
Lexington
=> me no like :(
You might want to use a different extension than .ini for ini files...
I would rather do a FileExists test, and if the file doesn't exist, then do the check and append the .ini extension ;).

=> me like :)
But again, with a FileExists test, we could keep the old behaviour together with this suggestion ;).
I see. So you could have sample.cfg and sample.cfg.desc

Definitely, we could add an error message of "file filename or filename.ini was not found".
 

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Also, if we leave out the SystemPath("ScriptPath") we could allow iniEditor.mscr to exist in a different folder. The user would have to make sure SampleConfig.mscr included paths in the arguments as in
CallScript("\programs\script\iniEditor.mscr", "\programs\sample\sample.ini", "Dummy", TRUE, FALSE)

Actually, I just checked again, and the SystemPath("ScriptPath") is used only if no path has been given to the .ini file.
So calling CallScript("\programs\script\iniEditor.mscr", "\programs\sample\sample.ini", "Dummy", TRUE, FALSE) works perfectly well with v05 :).
Nothing to do here. :D
 

howdykeith

Senior Member
Oct 8, 2009
876
2
East Greenwich, RI
Added to the Compendium

Hiya Michoob.

Happy New years...

I added your script to the compendium.

I also wrote routines to delete a [Section] or key of an ini file:

Code:
Sub IniSectionDelete (Section)
INIline = "start"
NewIni = ""
While( NOT IsEmpty( INIline ) )
	INIline = ReadLine( iniFile  )
	If (CharAt( INIline, 1 ) eq "[")
		Skipper = (INIline eq "[" & Section & "]") ? True : False
	EndIf
	If (NOT Skipper)
		NewIni &= INIline & "^NL^"
	EndIf
EndWhile
WriteFile( iniFile, NewIni )
EndSub

This should delete a Key from a certain [Section] of an ini file:

Code:
Sub IniKeyDelete (Section, Value)
	IniLoaded = ReadFile( iniFile )
Skipper = False
ForEach line in split ( IniLoaded, "^LF^", TRUE )
	If (Find (Line, "[" & Section & "]") )
		SkipSection = True
		WriteLine( iniFile, line, True )
	EndIf
	#Skip the "Value=" line
	If (SkipSection AND (Substr ( Line, 1, (Length(Value) + 1)) eq ( Value & "=")))
	Else
		WriteLine( iniFile, line, True )
	EndIf
	#Next [Section] or done
	If (CharAt( line, 1 ) eq "[")
		SkipSection = False
	EndIf
	
EndForEach

EndSub

Thanks much,
HowdyKeith
 
Last edited:

michoob

Retired Recognized Developer
Dec 19, 2008
1,270
65
Brussels
Hi howdykeith, thanks for the info, even though I will not add this section or key deletion features into iniEditor, because this is not the purpose of iniEditor.
Actually, I have perhaps not chosen the best name for iniEditor, as the idea is to easily edit the values for end users, and only the values.
I should have better called it iniValueEditor :p.

Anyway, thanks for your interest in my work, and thanks for your great work in the MortScript world :).
 

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?