 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Tue Jul 25, 2006 10:49 pm Post subject: |
|
|
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 |
|
 |
Camarade_Tux
Joined: 05 Jun 2006 Posts: 38 Location: Paris
|
Posted: Sat Dec 16, 2006 4:48 pm Post subject: |
|
|
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.
Thanks a lot.
edit: btw the listview containing the sections is incredibly large!  |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5382 Location: /b/
|
Posted: Sat Dec 16, 2006 6:01 pm Post subject: |
|
|
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 |
|
 |
Camarade_Tux
Joined: 05 Jun 2006 Posts: 38 Location: Paris
|
Posted: Sat Dec 16, 2006 11:04 pm Post subject: |
|
|
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.
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.  |
|
| Back to top |
|
 |
Camarade_Tux
Joined: 05 Jun 2006 Posts: 38 Location: Paris
|
Posted: Sun Dec 17, 2006 10:41 am Post subject: |
|
|
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.
: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".  |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Sun Dec 17, 2006 4:07 pm Post subject: |
|
|
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
|
Posted: Tue Nov 06, 2007 10:20 am Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|