AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

VisualINI v2
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5382
Location: /b/

PostPosted: Tue Jul 25, 2006 10:49 pm    Post subject: Reply with quote

Version 2.0 had a bug where new files could not be made sections couldn't be added/removed/renamed properly. This has all been fixed in v2.1
_________________

Back to top
View user's profile Send private message Visit poster's website
Camarade_Tux



Joined: 05 Jun 2006
Posts: 38
Location: Paris

PostPosted: Sat Dec 16, 2006 4:48 pm    Post subject: Reply with quote

Hi Titan,

could you tell me how you retrieve the list of [sections] from the ini (and the related keys) ?

I tried to find it by myself but it's clear I'm not experienced enough to go trough your code. Crying or Very sad

Thanks a lot. Smile


edit: btw the listview containing the sections is incredibly large! Shocked
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5382
Location: /b/

PostPosted: Sat Dec 16, 2006 6:01 pm    Post subject: Reply with quote

I wouldn't use this code, its very outdated. When RegExMatch has the global modifier it will be much easier to extract sections and keys from INI files. Until then you can use parsing loops and basic regex; if you're stuck post in the Ask for Help section and you should get an answer.
_________________

Back to top
View user's profile Send private message Visit poster's website
Camarade_Tux



Joined: 05 Jun 2006
Posts: 38
Location: Paris

PostPosted: Sat Dec 16, 2006 11:04 pm    Post subject: Reply with quote

I'll try with RegEx then. Thanks.


But your code handled my ini file just perfectly. Maybe that your code is outdated but it's solid. Smile
And a reason I was trying to understand your script was because I thought it was using a dllcall I saw a few months ago but I couldn't find again.

But, I've managed to get my hands over it again:
GetPrivateProfileSectionNames and GetPrivateProfileSection both in kernel32.dll.

I'll see which method is more convenient and which method is faster. Smile
Back to top
View user's profile Send private message
Camarade_Tux



Joined: 05 Jun 2006
Posts: 38
Location: Paris

PostPosted: Sun Dec 17, 2006 10:41 am    Post subject: Reply with quote

I tried the dllcall method and got it to work. ^^

Code:
GrantedCapacity:=VarSetCapacity(test, 10240000)
noms := DllCall("Kernel32.dll\GetPrivateProfileSectionNames", "Str", test, "UInt", GrantedCapacity, "Str", "E:\install_en.ini", "UInt")
MsgBox, % noms ;%
MsgBox, % test ;%
CharReplace(test, 0, 13, noms)
MsgBox, % test ;%


CharReplace(ByRef Buf, Ch1, Ch2, Len=0) {
   m := VarSetCapacity(Buf)
   If (Len < 1 or Len > m)
       Len = %m%
   Loop %Len%
      If (*(&Buf+A_Index-1) = Ch1)
         DllCall("RtlFillMemory", UInt,&Buf+A_Index-1, UInt,1, UInt,Ch2)
}

CharReplace function has been posted by Laszlo here. Thanks a lot. Wink

:woooooooooooooot:

Btw, I think AHK lacks documentation for ByRef, & and *.
I saw ByRef in CharReplace prototype so I tried to call it with "CharReplace(&test, 0, 13, noms)". And of course...
The problem is there is no entry for "address" or "pointer" in the help file and there is little info for "ByRef". Crying or Very sad
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Sun Dec 17, 2006 4:07 pm    Post subject: Reply with quote

Nice, here is the call to get the section:

Code:
/*

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getprivateprofilesectionnames.asp

DWORD GetPrivateProfileSection(
  LPCTSTR lpAppName,
  LPTSTR lpReturnedString,
  DWORD nSize,
  LPCTSTR lpFileName
);

*/

iniFile = path to an ini-file
iniSection = section name

sectionCapacity:=VarSetCapacity(aSection, 2048)
buffCharNr := DllCall("Kernel32.dll\GetPrivateProfileSection"
                              , "Str", iniSection
                              , "Str", aSection
                              , "UInt", sectionCapacity
                              , "Str", iniFile)

CharReplace(aSection, 0, 13, buffCharNr)
MsgBox, % aSection

ExitApp

CharReplace(ByRef Buf, Ch1, Ch2, Len=0) {
   m := VarSetCapacity(Buf)
   If (Len < 1 or Len > m)
       Len = %m%
   Loop %Len%
      If (*(&Buf+A_Index-1) = Ch1)
         DllCall("RtlFillMemory", UInt,&Buf+A_Index-1, UInt,1, UInt,Ch2)
}
Back to top
Hasso



Joined: 23 Mar 2005
Posts: 158
Location: Germany

PostPosted: Tue Nov 06, 2007 10:20 am    Post subject: Reply with quote

Titan,

I like your VisualINI very much! Just found only a small bug: If you try to rename the very first section that doesn't work. I think it's the expression in red as the first section has no preceding line break.
Code:
SecSet(act, file) {
   Critical
   If (act = "Add") {
      Gui, +OwnDialogs
      InputBox, new, New section, Name des neuen Abschnitts:, , , 125
      If new {
         skey = _TODELETE[%A_Now%]
         IniWrite, %A_Now%, %file%, %new%, %skey%
         IniDelete, %file%, %new%, %skey%
         Parse(file)
         SB("Abschnitt hinzugefügt", 67)
      } Else SB("Abgebrochen", 110)
   } Else If (act = "Delete") {
      IniDelete, %file%, % Get("Sec")
      Parse(file)
      SB("Abschnitt gelöscht", 132)
   } Else If (act = "Rename") {
      Gui, +OwnDialogs
      InputBox, new, Abschnitt umbenennen, Abschnitt umbenennen in:, , , 125, , , , , % Get("Sec")
      If new {
         FileRead, c, %file%
         r := InStr(c, "`r")
         StringReplace, c, c, `r, , All
         s := Get("Sec")
         StringReplace, c, c, `n[%s%]`n, `n[%new%]`n
         If r
            StringReplace, c, c, `n, `r`n, All
         FileDelete, %file%
         FileAppend, %c%, %file%
         Parse(file)
         SB("Abschnitt umbenannt", 75)
      }
   }
}

Changing the line into
Code:
StringReplace, c, c, [%s%], [%new%]
did it.
Another thing I would like to change is removing tabs from the file as they show as ugly squares in the list view of keys/values. I wanted to replace all %A_TAB% characters with nothing but didn't yet find the right lines to do so.
_________________
Hasso

Programmers don't die, they GOSUB without RETURN
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group