AutoHotkey Community

It is currently May 26th, 2012, 1:31 pm

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 51 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: September 3rd, 2008, 12:40 pm 
Offline

Joined: May 21st, 2007, 3:44 pm
Posts: 176
Location: USA
haichen wrote:
May be a Bracket Error in YOUR Code.


haichen,
Good guess, but removing the "]" from the "*.ini]" did not resolve the problem, I still get the same error.

toralf,
Don't you know that as soon as the doc it written it becomes obsolete? The code reads "ini_MoveKey(ByRef var, from, to, key, copy = false) {"

_________________
-------------
Scott Mattes
Image
My small, and slowly growing, collection of scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2008, 1:03 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Hi scottmattes, I think I found the problem:

Code:
; test ini library

FileSelectFile, my_ini_name, , , Prompt, *.ini]

rc := ini_Load(my_ini_contents, my_ini_name)
if rc = 0
{
  msgbox, my_ini_name=%my_ini_name% contents`n`n%my_ini_contents%
}
else
  msgbox, failed to load
} <-- this shouldn't be here (else block doesn't have opening {)

Maybe this was what haichen was referring to ;)

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2008, 1:35 pm 
Offline

Joined: May 21st, 2007, 3:44 pm
Posts: 176
Location: USA
Titan,
Right you are! I saw the ] and focused on that.

Is it just me, or does the error reported seem 'wrong'? Like, I guess that I am wondering why ahk didn't raise an error before getting to the ini.ahk code.

O well, thank you for finding my error for me.

_________________
-------------
Scott Mattes
Image
My small, and slowly growing, collection of scripts.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 3rd, 2008, 3:46 pm 
Offline

Joined: February 5th, 2007, 12:19 pm
Posts: 192
Location: Osnabrück, Germany
Quote:
Maybe this was what haichen was referring to Wink

I often make such mistakes when I work with Includes. Sorry of being a bit short.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2008, 8:42 pm 
Offline

Joined: December 1st, 2008, 7:55 pm
Posts: 1
Ran into a problem with _ini_(un)escape. One of my values contained \r, which resulted in it being converted to a carriage return. A simple fix would be to modify the escaped version of "`r" and "`n" to something like "{INI_CARRIAGE_RETURN}" and "{INI_NEWLINE}".

It also looks like ini_Save isn't escaping properly.

Code:
ini_Load(LoadedINI, "[Section]`nKey = \\\\We\Shall\Rock\N\Roll\All\Night\!\\\\")
MsgBox % "Key value is """ . ini_Read(LoadedINI, "Section", "Key") . """."
ini_Write(LoadedINI, "Section", "Key", "\\We\Shall\Rock\N\Roll\All\Night\!\\")
MsgBox % "Key value is """ . ini_Read(LoadedINI, "Section", "Key") . """ after ini_Write."
MsgBox % "INI will be saved as """ . ini_Save(LoadedINI) . """."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 28th, 2009, 10:09 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I can't get ini_Save to work, and I've found some issues (some of which have already been stated).

Line 442:
Code:
_at = %A_LoopField%


Should be:
Code:
_at = %A_AutoTrim%


Line 451:
Code:
StringReplace, ls, ls, %s%`n


%s% is a blank variable at the start of the loop, so you're removing all newlines of the section list on loop pass 1 and doing nothing for the other passes, as far as I can tell. I think this line should be moved up above 451:
Code:
s := SubStr(l, 2, -2), x := InStr(ls, s . "`n"), z := ini_GetKeys(var, s)


Finally, as another user stated, %file% is not defined when you use it at the end of the function. %src% used to contain the filename, but was overwritten at the beginning with the file contents. Before it's overwritten, you need to add:
Code:
file := src


Testing to see if additional changes are needed to get it working...

Update: Definitely still not working. The Save function looks like a mess! I hope the other functions are sound, as I hope to be able to use this library when I figure out the save function.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 28th, 2009, 6:03 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Titan wrote:
Best of all the script is performance enhanced with only string functions used for parsing content (no regex!), unlike all the other similar scripts you can find on the forum.


Is that RegEx really so slow compare to string functions ?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 28th, 2009, 11:16 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Smurth wrote:
Is that RegEx really so slow compare to string functions ?


In general, no. Compared to string functions, generally yes. Kind of a speed vs. convenience trade-off.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject: ini_Save is not working
PostPosted: March 10th, 2009, 6:26 pm 
I also found that the ini_Save functionality is not working.

When someone (maybe even me) fixes this problem, please post the code. The ini library is really fast and I would like to be able to write to file.

Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2009, 6:32 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
I don't know exactly how the speed compares, but if you can't figure this out,
you might want to try my IniFile class also in these forums which I created because
this library had some unresolved issues. Initial reports indicate it's pretty fast and
all functions work.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Found the problem
PostPosted: March 10th, 2009, 6:51 pm 
The ini_Save works fine. You will notice that at the bottom Titan uses
%file% . This is empty. So you just need to create a copy of the file uptop before any changes happen. Viola you got a working program.

:D

And it is much faster than other routines purely because it stores the ini file in memory. So unless you're ini file is really small it wont be worth using it.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 11th, 2009, 12:38 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Ini_save doesn't work for me in Vista 64-bit, even when populating the %file% variable properly in the function. You'll notice in my posts above there are several other code errors I found, but even when I fixed them it still did not work for me.

My IniFile class is object-oriented, and also stores the Ini file in memory for ultra-fast access, FYI. It parses the whole file into sections and fields (separated by key, value, and comment) when opening it, so it doesn't have to parse the file when you actually run your operations on it. And the save function works, and I don't believe there are errors or omissions in the current code.

So if you can't get this to work, as I couldn't, and because this doesn't seem to be supported anymore (or currently, at least), feel free to give my library a try here.

I even created function aliases in my library so that you can use almost the exact same syntax you use with the Ini_ library, but with IniFile_ before it.

You can also use both at the same time, because I changed the name to IniFile for mine. So feel free to compare and share your results. I've tried to cater to fans of this library, since I'm a fan of this library.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Found the problem
PostPosted: April 26th, 2009, 9:21 pm 
Offline

Joined: April 15th, 2009, 12:05 am
Posts: 75
Location: Italy
Boontjie wrote:
The ini_Save works fine. You will notice that at the bottom Titan uses
%file% . This is empty.

....


I still dont get it why it works like this

Code:
   c := ini_Save(AppParms)
   FileDelete %MainIniFile%
   FileAppend, %c%, %MainIniFile%


while it doesn't like this (even though I guess that's the intended most common usage):

Code:
   c := ini_Save(AppParms,MainIniFile)


although the last lines in the invoked function look exactly like those in the working example

Code:
   If src_file = 1
   {
      FileDelete, %file%
      FileAppend, %d%, %file%
      Return, !ErrorLevel
   }


src_file is = 1, %file% contains exactly the same value as per the working example (that is a correctly placed existing ini file, it aint empty Boontjie...).
testing ErrorLevel (via OutputDebugger) both after the attempted deletion and file append show a failure on both commands

Code:
   If src_file = 1
   {
      FileDelete, %file%
      OD_Err1 = ErrorLevel
      FileAppend, %d%, %file%
      OD_Err2 = ErrorLevel
      OutputDebug %OD_Err1% %OD_Err2%

      Return, !ErrorLevel

   }


:?:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2009, 7:02 pm 
Offline

Joined: April 15th, 2009, 12:05 am
Posts: 75
Location: Italy
Unfortunately this library doesnt work.
Or at least I cant make it working
Aside the objections above:

you cant have a key containing C:\remainder or C:\nicholas as value because \r and \n will be escaped/unescaped with funny results.

I found also:

if my code tries to write an empty string in a key, the key and values of the immedialy subsequent one will be deleted and lost

If a section gets vacated of keys the entire section is deleted...

I gave up and switched to the old fashioned ahk directives
It was nice (and fast, veeery fas!!) to handle INI in memory with no disk access.
I doubt that this should still be included in the Wiki catalogue.

_________________
Intel Centrino @ 2.8GHz
4 GB RAM
WIN XP SP3


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2009, 5:46 pm 
Offline

Joined: April 15th, 2009, 12:05 am
Posts: 75
Location: Italy
Found the bug in ini_Write function
Line 95 and 97 (contained in ini_Write) are:
Code:
95   p += StrLen(f) + 1
97   StringLeft, d1, var, p - 1

if one passes an empty string to write in the key that "+1" at the end of the line 95 gets the following StringGetPos call to set the string trimming right at the end of the following key
so a section like this
[SOMESECTION]
Key1=somevalues1
key2=somevalues2

after a manipulation like
Code:
ini_Write(MyIniRef, "SOMESECTION", "Key1", newVal)

where newVal is an empty string (I want to keep the key but with no value set) becomes:
[SOMESECTION]
Key1=

WHAT?!! IVE LOST Key2 WHICH WASNT EVEN MEANT TO BE TOUCHED!!
yep.
Ive changed the above lines into
Code:
95   p += StrLen(f)
97   StringLeft, d1, var, p

and now it looks like it's working fine, at least for my usage.
I've also made (see bmcclure and Coryf88 posts above) these other changes in the Titan's original code:
Code:
431b   file := src                                    ;line added in ini_Save
440   _at = %A_AutoTrim%                              ;line changed in ini_Save
;##############
571   StringReplace, val, val, `r, {I_C_R}, All       ;lines changed in
572   StringReplace, val, val, `n, {I_L_F}, All       ;_ini_escape
;##############
578   StringReplace, val, val, {I_C_R}, `r, All       ;lines changed in
579   StringReplace, val, val, {I_L_F}, `n, All       ;_ini_unescape

again it works for my own usage wich is limited to load, read, write, delete and save. dunno abt the rest.

_________________
Intel Centrino @ 2.8GHz
4 GB RAM
WIN XP SP3


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 51 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Google Feedfetcher, maraskan_user, Yahoo [Bot] and 14 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