AutoHotkey Community

It is currently May 26th, 2012, 1:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: December 28th, 2007, 10:23 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2007, 5:10 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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 isthe 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.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2007, 1:52 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group