 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 4114 Location: Belgrade
|
Posted: Fri Dec 28, 2007 9:23 am Post subject: |
|
|
| Quote: | | (when makesection works) would this be faster than doing a ReplaceSection for each section? |
Yes, you got it. That kind of behavior is exactly what I wanted with Ini module - ability to use functions in any manner. The code you posted is definitely the way to go for larger ini files when you have to update all sections. ReplaceSection is more for single section manipulation like MRU lists, history items that are saved per user action etc... _________________
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 4114 Location: Belgrade
|
Posted: Fri Dec 28, 2007 4:10 pm Post subject: |
|
|
Ok, I had time to check your problem bmc
You used Ini incorrectly. Ini_LoadKeys automaticaly appends section name on user prefix. As you used | Quote: | | "cfg_" . A_LoopField . "_" |
as a prefix, u doubled the prefix (well, maybe this is a bit of design isue which I will check later). Instead, your entire work is one line of code:
| Code: | | Ini_LoadKeys(ConfigFile, "", 0, "cfg_") ;notice the "" as section name |
This will create global vars cfg_SectionName_Key.
This also caused problem with MakeSection, as your globals where created as cfg_SectionName_SectionName_KeyName as both you and LoadKeys added SectionName. That made MakeSection to work improperly as later only first part of the prefix was removed.
I don't know why Dock variables poped up ... that doesn't happen here, and everything works normaly.
I made you a test script so you can see what is going on, with your own ini.
When you start it, it will open listvars and show you your globals. After that press F12 to iterate over sections and see all of them.
Using this example I noticed that LoadKeys should also return sections so
| Code: | configSections := Ini_GetSectionNames(ConfigFile)
Ini_LoadKeys(ConfigFile, "", 0, "cfg_") |
will be probably replaced with
| Code: | | configSections := Ini_LoadKeys(ConfigFile, "", 0, "cfg_") |
Now LoadKeys returns number of variables created.
I will eventualy make Ini_MakeIni(prefix) that will scan for the global variable name patterns with 2 undrscores taking middle as a section name so you don't have to iterate over sections.
I am interested to know why Dock variables bumped up in your sections. If you catch it, let me know.
This is the sample for you.
Again, keep in mind that MakeSection uses realy nasty hack to get list of globals you created which is proved to not work correctly with more then around 2000 variables. Lets hope Chris will fix this, or update ListVars. _________________
 |
|
| Back to top |
|
 |
bmcclure
Joined: 24 Nov 2007 Posts: 766
|
Posted: Sat Dec 29, 2007 12:52 am Post subject: |
|
|
On the contrary, Ini_LoadKeys doesn't seem to return the section names:
| Quote: | pInfo=0 or pInfo=”” number of variables created (default).
pInfo=1 or pInfo=”keys” function returns key names separated by prefix string (by default `n)
pInfo>1 or pInfo=”vals” function returns key values separated by prefix string (by default `n) |
But other than that, you're right about my code problem.
Funny thing is, I fixed it last night, but just didn't try it since I fixed it. This code seems to work great:
| Code: | ReadConfig:
FileCopy,res\default\config.ini.default,%ConfigFile%,0
configSections := Ini_GetSectionNames(ConfigFile)
Ini_LoadKeys(ConfigFile, "", 0, "cfg_")
If Not cfgSteamLab_LastRun
GoSub,ShowSettings
Return
WriteConfig:
configFileNew := ""
Loop, Parse, configSections, `n
configFileNew .= "[" . A_LoopField . "]`n" . Ini_MakeSection("cfg_" . A_LoopField . "_") . "`n`n"
FileDelete, %ConfigFile%
FileAppend, %configFileNew%, %ConfigFile%
Return |
Ugly hack or time/code-saving masterpiece; is there necessarily a difference?
It's amazing.
If I feel like creating a new config value now, and I already have a section in the Ini for it, all I need to do is set cfg_SectionName_ValueName to whatever I'd like, and the value is written and read from the ini file from then on out. It's pure genius! Thanks majkinetor  _________________ Ben
My Trac projects
My Wiki
[Broken] - My music |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|