AutoHotkey Community

It is currently May 27th, 2012, 12:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 63 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject:
PostPosted: December 17th, 2011, 8:54 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Here ya go. This should do what you want.

It will find section/key pairs that contain a value you pass to it. The returned data is *Section*|*Key* for a single entry or *Section*|*Key*`r`n*Section*|*Key* for two or more.

Code:
RIni_FindValues(RVar,Value,Find_FirstOnly = 1)
{
   Global
   Local T_Section, R_Section, R_Key, Found_Data
   
   RVar = %RVar%
   If !RIni_%RVar%_Is_Set
      Return -10
   
   Loop,% RIni_%RVar%_Section_Number
   {
      If (RIni_%RVar%_%A_Index% != ""){
         T_Section := RIni_%RVar%_%A_Index%
         
         If (%RVar%_All_%T_Section%_Keys){
            Loop,Parse,%RVar%_All_%T_Section%_Keys,`n
            {
               If A_LoopField =
                  Continue
               
               If (InStr(%RVar%_%T_Section%_%A_LoopField%_Value,Value)){
                  R_Section := T_Section
                  , R_Key := A_LoopField
                  
                  If InStr(R_Section,"@$S$@")
                     StringReplace,R_Section,R_Section,@$S$@,%A_Space%,A
                  
                  If InStr(R_Key,"@$S$@")
                     StringReplace,R_Key,R_Key,@$S$@,%A_Space%,A
                  
                  If (Find_FirstOnly)
                     Return R_Section . "|" . R_Key
                  Else
                     Found_Data .= Found_Data ? "`r`n" R_Section "|" R_Key : R_Section "|" R_Key
               }
            }
         }
      }
   }
   
   Return Found_Data
}



It's designed for the "Basic" version of the library. If you would like I can write up one for the "Advanced" version.

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Last edited by Rseding91 on December 17th, 2011, 9:05 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2011, 9:03 am 
Offline

Joined: November 14th, 2008, 1:45 am
Posts: 80
Location: USA
rseding91 wrote:
Here ya go. This should do what you want.

It will find section/key pairs that contain a value you pass to it. The returned data is *Section*|*Key* for a single entry or *Section*|*Key*`r`n*Section*|*Key* for two ore more.

It's designed for the "Basic" version of the library. If you would like I can write up one for the "Advanced" version.

Thank you very much :D . I really appreciate your help. You will be given due credit for your help and for your library of awesome functions in the "About" of my program. What I have been using is the Basic version, so that will do nicely.

Thanks again!
-Sam.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Help with RIni_Write
PostPosted: January 12th, 2012, 6:10 pm 
Offline

Joined: October 21st, 2009, 6:55 pm
Posts: 48
Hey guys,

First off let me just say that this is a really nice Ini library. Great work on it, its very thorough.

Anyhow I am having trouble getting the RIni_Write function to work properly.

I am running the Basic version of this and here is the line of code I am using before my app closes:

Code:
RIni_Write(1,A_ScriptDir "\print.forms.ini",Newline="`r`n",Write_Blank_Sections=1,Write_Blank_Keys=1,Space_Sections=1,Space_Keys=0,Remove_Valuewlines=1,Overwrite_If_Exists=1,Addwline_At_End=0)


Hopefully it is something obvious because I can't seem to figure it out. I ran a test to see if the RIni_SetValue function was working and it is but my ini file is not reflecting the changes meaning the RIni_Write function is not.

I was looking through the function in the source file and I see there are numerous error levels that could be triggered but not sure how I can visual these if they are. I noticed that one of the errors writes the ini file to the A_Temp directory. I checked there and saw nothing so that isn't it.

My guess is that it may have to do with Overwrite_If_Exists=1 but the documentation isn't updated with this parameter. I am assuming 1 means yes though.

Any help would be greatly appreciated.

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2012, 10:18 pm 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
It looks like you don't quite understand how optional parameters for a function work :)

Optional paramaters can either be left blank (meaning it will use what ever that paramater is set to by the function) or manually set to what you want them to be.

In this example you can see the function has 2 paramaters and one of them is optional (you don't always have to fill it in).

Code:
Test("Hello")
Test("Hello","Hello again")

Test(Message, Optional_Message = "")
{
If (Optional_Message)
MsgBox % Message "`n" Optional_Message
Else
MsgBox % Message
}


Using that example you can see that the RIni_Write() function has several optional paramters you don't always have to fill in - but it looks like you copied the optional paramaters variables and values.

You will want to use this:

Code:
RIni_Write(1,A_ScriptDir "\print.forms.ini","`r`n",1,1,1,0,1,1,0)


Or, beacuse you don't want to change any of the optional paramaters - you can leave those out.

Code:
RIni_Write(1,A_ScriptDir "\print.forms.ini")



For a better explination on functions and paramaters you can read the help files section on Functions - i'm sure it will explain everything much better then I can.

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 12th, 2012, 10:28 pm 
Offline

Joined: October 21st, 2009, 6:55 pm
Posts: 48
Thanks for the reply.

It works now. Thank you.

You're right I didn't realize they were optional. Thought they had to be declared. Anywho thanks again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 7:26 am 
Offline

Joined: November 14th, 2008, 1:45 am
Posts: 80
Location: USA
What does RIni_GetKeysValues() do? It isn't covered in the documentation and it isn't as obvious as most...

TIA,
Sam.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2012, 7:55 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Sam. wrote:
What does RIni_GetKeysValues() do? It isn't covered in the documentation and it isn't as obvious as most...

TIA,
Sam.


I had to go back and look at it :P

It finds and gets all of the values of a key you specify. So, you could say "get every key with the name "Username" and it would return a comma (or user defined) split list of every key that had the name "username".

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2012, 4:04 am 
Offline

Joined: November 14th, 2008, 1:45 am
Posts: 80
Location: USA
I need to swap a Key=Value with the Key=Value either above it or below it in the same section (reverse their order). I'm using the INI to store information, and the relative order of the keys in the section matters. Can you think of a good way to do this? I couldn't come up with a way that didn't resort to messy hackery...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2012, 6:31 am 
Offline

Joined: November 14th, 2008, 1:45 am
Posts: 80
Location: USA
Code:
RIni_SectionExists(RVar,Sec)
{
   Global
   RVar = %RVar%
   If !RIni_%RVar%_Is_Set
      Return 0
   If InStr(Sec,A_Space)
      StringReplace,Sec,Sec,%A_Space%,@$S$@,A
   Return RIni_%RVar%_%Sec%_Is_Set ? 0 : 1
}

RIni_SectionExists() seems to return 0 for True and 1 for False. Typically it's the other way around, right? I'd think it should be:
Code:
RIni_SectionExists(RVar,Sec)
{
   Global
   RVar = %RVar%
   If !RIni_%RVar%_Is_Set
      Return 0
   If InStr(Sec,A_Space)
      StringReplace,Sec,Sec,%A_Space%,@$S$@,A
   Return RIni_%RVar%_%Sec%_Is_Set ? 1 : 0
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2012, 6:36 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
The only method I can think of would be to loop through the keys one at a time moving them to a new section and when you come across the keys you want - switch them. Then when that's done rename the section to the old section name (if needed).


Regarding the sectionexists function - oops. Yeah I have it wrong. I'll fix that real quick.

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2012, 6:41 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Updated to 1.5

Fixed SectionExists to return 1 for true and 0 for false - it was the oposite before

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 12th, 2012, 9:00 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
Deleted. See post Below.


Last edited by Morpheus on March 18th, 2012, 1:13 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2012, 4:34 pm 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
I don't have a test set for the different functions. I wrote them so fast one after each other that when I got done there was so much to test I never bothered.

Your best best for testing new additions would be to create a ini and then use the RIni_Read() and RIni_Write() functions and check if the input and output are the same.

Those two functions use a lot of the different add/get options and if they both work chances are everything else will work.

_________________
(Statistics script) M&K Counter 2.0
My FAST ini Lib
Minecraft NBT Lib


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 13th, 2012, 7:22 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
Will Do. Thanks!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 18th, 2012, 1:07 pm 
Offline

Joined: July 31st, 2008, 10:27 pm
Posts: 336
Mod for Ini files with illegal chars in section names.
Scripts using the original FAST INI library Basic will work with this modified set of functions. Section names are encoded using Hex() by Laslo.
Most of the RIni_ functions just have one additional line, to encode the section name as passed as a parameter.
I added an extra parameter to the following 4 RIni_ functions for INTERNAL USE ONLY.

RIni_AddSection
RIni_DeleteKey
RIni_DeleteSection
RIni_RenameSection

http://www.autohotkey.net/~Morpheus/Rob ... 0Basic.ahk

I tested this by reading and then writing this ini file.
Code:
;This is a example ini file
[Nam{)es]
Name1=James
Name2=Harry
Name3=Steve
;The above are supposed to all be names.
[Pa\*?sswords] ;Passwords really shouldn't be listed in a ini
Password1=eleventeen
Password2=cmseb3
Password3=password ;Note, this is a bad password


I also ran a benchmark using Lexikos'
T() Function
, reading and writing the ini above.

Without encoding - .000024 seconds
With encoding - .000085 seconds


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], notsoobvious and 11 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