Jump to content

Udf : Iniread Udf's


Busti
 Share

Recommended Posts

my own method of inireading :think: and writing^^

not everything is working fine yet, but im working on it^^

simply copy script and run it you will se :(

€Dit:

added :

-InideleteSektion

Bugs :

dont use in the ini names double like :

ButBut_1 = LOL

ButBut_2 = LOL

becouse its not casesense yet :/

working on it^^

$delval = _IniDelete( "test.txt" )
ToolTip( '_IniDelete( "test.txt" )' ,0,0)
Sleep(1000)
MsgBox(0, "", $delval)

$creval = _IniCreate("test.txt", ";Createt ini"); $StartLine , Multiline with @CRLF
ToolTip( '_IniCreate("test.txt", ";Createt ini")' ,0,0)
Sleep(1000)
MsgBox(0, "", $creval)

$inireturn = _IniWrite("test.txt", "DiabloIIAccount", "MyAccount")
ToolTip( '_IniWrite("test.txt", "DiabloIIAccount", "MyAccount")' ,0,0)
Sleep(1000)
MsgBox(0, "", $inireturn)

$readnewentry = _IniRead( "test.txt", "DiabloIIAccount", 2)
ToolTip( '_IniRead( "test.txt", "DiabloIIAccount", 2)' ,0,0)
Sleep(1000)
MsgBox(0, "", $readnewentry)

$Changeinireturn = _IniWriteSektion("test.txt", "DiabloIIAccount" , "Ne nich My Account, sondern TEST! :D")
ToolTip( '_IniWriteSektion("test.txt", "DiabloIIAccount" , "Ne nich My Account, sondern TEST! :D")' ,0,0)
Sleep(1000)
MsgBox(0, "", $Changeinireturn)

$readinireturn = _IniRead( "test.txt", "DiabloIIAccount", 2)
ToolTip( '_IniRead( "test.txt", "DiabloIIAccount", 2)' ,0,0)
Sleep(1000)
MsgBox(0, "", $readinireturn)

$delsection = _IniDeleteSektion("test.txt", "DiabloIIAccount")
ToolTip( '_IniDeleteSektion("test.txt", "DiabloIIAccount")' ,0,0)
Sleep(1000)
MsgBox(0, "", $delsection)

$readinireturn = _IniRead( "test.txt", "DiabloIIAccount", 2)
ToolTip( '_IniRead( "test.txt", "DiabloIIAccount", 2)' ,0,0)
Sleep(1000)
MsgBox(0, "", $readinireturn)

_IniDelete( "test.txt" )

Func _IniRead($FileName, $SektionName, $Method = 2, $DefaultReturn = 0)
    If Not FileExists($FileName) Then
        _IniCreate($FileName,";Ini was not Found, so it was Createt to prevent errors;)")
        Else
    Dim $SaveArray[FileGetSize($FileName) ]
    For $i = 1 To FileGetSize($FileName)
        $SaveArray[$i] = FileReadLine($FileName, $i)
        If @error = 1 Then
            ReDim $SaveArray[1]
            Return $DefaultReturn
        ElseIf @error = -1 Then
            $MaxCount = $i
            ExitLoop
        EndIf
    Next
    For $i = 1 To $MaxCount
    ;If FindOccuranceUntil($SaveArray[$i], "=") = 1 Then
        If StringInStr($SaveArray[$i], $SektionName, 0, 1) Then
            $NewStringOne = StringTrimLeft($SaveArray[$i], StringLen($SektionName))
            If StringLeft($NewStringOne, 1) = "=" Then
                $NewStringOne = StringTrimLeft($NewStringOne, 1)
                ReDim $SaveArray[1]
                Return $NewStringOne
            ElseIf StringLeft($NewStringOne, 1) = " " Then
                Do
                    $NewStringOne = StringTrimLeft($NewStringOne, 1)
                Until StringLeft($NewStringOne, 1) = "="
                $NewStringOne = StringTrimLeft($NewStringOne, 1)
                If $Method = 2 Then
                    If StringLeft($NewStringOne, 1) = " " Then
                        Do
                            $NewStringOne = StringTrimLeft($NewStringOne, 1)
                        Until StringLeft($NewStringOne, 1) <> " "
                    EndIf
                EndIf
            EndIf
            Return $NewStringOne
        EndIf
    ;EndIf
    Next
    ReDim $SaveArray[1]
    Return $DefaultReturn
    EndIf
EndFunc  ;==>_IniRead


; ==> _IniWriteSektion()
; ==>   Params :
;           - $Filename - "FileName" 
;           - $Sektion  - "Your Sektion to Write in"
;           - $NewInput - "Replace the old shit with :D"
; ==>   Return Values :
;           - -1        - Sektor does not exist.
;           - 1         - Every thing was Succesfull.
;           - -2        - Sektion does not exist.
; (C) Busti

Func _IniWriteSektion($FileName, $Sektion,$NewInput)
;If _IniRead($FileName, $Sektion, 2, 0) <> 0 Then

    If Not FileExists($FileName) Then
        _IniCreate($FileName,";Ini was not Found, so it was Createt to prevent errors;)")
        Else
        If _IniRead($FileName, $Sektion) = "0" Then
            Return -2; does not exists , w00t^^
        EndIf
        Dim $SaveArray[FileGetSize($FileName) ]
        For $i = 1 To FileGetSize($FileName)
            $SaveArray[$i] = FileReadLine($FileName, $i)
            If @error = -1 Then
                $MaxCount = $i
                ExitLoop
            EndIf
        Next
        For $i = 1 To $MaxCount
            If StringInStr($SaveArray[$i], $Sektion, 0, 1) Then
                $BearString = StringTrimLeft($SaveArray[$i], StringLen($Sektion))
                $SaveString = StringLeft($SaveArray[$i], StringLen($Sektion) + 1)
                If StringLeft($BearString, 1) = "=" Then
                    $BearString = StringTrimLeft($BearString, 1)
                ;$NewString = StringLeft($BearString, StringLen($BearString))
                    $SaveArray[$i] = $SaveString & "= " & $NewInput
                    Local $i_Write = 0
                    If FileExists($FileName)=1 Then FileDelete($FileName)
                    Do
                        $i_Write += 1
                        FileWriteLine($FileName, $SaveArray[$i_Write])
                    Until $i_Write = $MaxCount
                    Return 1
                ElseIf StringLeft($BearString, 1) = " " Then
                    Do
                        $BearString = StringTrimLeft($BearString, 1)
                    Until StringLeft($BearString, 1) = "="
                ;$NewString = StringLeft($BearString, StringLen($BearString))
                    $SaveArray[$i] = $SaveString & "= " & $NewInput
                    Local $i_Write = 0
                    If FileExists($FileName)=1 Then FileDelete($FileName)
                    Do
                        $i_Write += 1
                        FileWriteLine($FileName, $SaveArray[$i_Write])
                    Until $i_Write = $MaxCount
                    Return 1
                EndIf
            EndIf
        ;EndIf
        Next
        ReDim $SaveArray[1]
        Return -1
    EndIf
EndFunc  ;==>_IniWriteSektion

; ==> _IniDeleteSektion()
; ==>   Params :
;           - $Filename - "FileName" 
;           - $Sektion  - "Your Sektion to replace"
; ==>   Return Values :
;           - -1        - Sektor does not exist.
;           - 1         - Every thing was Succesfull.
;           - -2        - Sektion or File does not exist.
; (C) Busti
Func _IniDeleteSektion($FileName, $Sektion)
    If Not FileExists($FileName) Then
        Return -2
        Else
        If _IniRead($FileName, $Sektion) = "0" Then
            Return -2
        EndIf
        Dim $SaveArray[FileGetSize($FileName) ]
        For $i = 1 To FileGetSize($FileName)
            $SaveArray[$i] = FileReadLine($FileName, $i)
            If @error = -1 Then
                $MaxCount = $i
                ExitLoop
            EndIf
        Next
        For $i = 1 To $MaxCount
            If StringInStr($SaveArray[$i], $Sektion, 0, 1) Then
                    $SaveArray[$i] = ""
                    Local $i_Write = 0
                    If FileExists($FileName)=1 Then FileDelete($FileName)
                    Do
                        $i_Write += 1
                        FileWriteLine($FileName, $SaveArray[$i_Write])
                    Until $i_Write = $MaxCount
                    Return 1
            EndIf
        Next
        ReDim $SaveArray[1]
        Return -1
    EndIf
EndFunc  ;==>_IniDeleteSektion
Func _IniCreate($FileName, $StartLine=""); $StartLine , Multiline with @CRLF
    If Not FileExists($FileName) = 1 Then
        FileWrite($FileName, $StartLine)
    Else
        Return 0
    EndIf
EndFunc  ;==>_IniCreate
Func _IniDelete($FileName)
    If FileExists($FileName) = 1 Then 
        Return FileDelete($FileName)
    Else
        Return -1
    EndIf
EndFunc  ;==>_IniDelete
Func _IniWrite($FileName, $Sektion, $Text)
    If FileExists($FileName) = 1 Then
    If _IniRead($FileName, $Sektion) = "0" Then
        Return FileWriteLine($FileName, @CRLF & $Sektion & " = " & $Text)
    Else
        Return 0
    EndIf
Else
    Return -1
EndIf

EndFunc  ;==>_IniWrite
Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

what is the point of this? The built in Ini functions work fine. Although i'm sure you have learnt a lot from doing it. Well done

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

you dont need an extra option in my funcs^^

IniRead( "Filename" , "Section", "key" [ , "Default")]

_IniRead( "FileName" , "key" [ , "Option" , "Default" )]

^^

i created this basicly becouse i did not want the Section xD

Edited by Busti
My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

ahh i get you now.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

I got an error at EnnIf

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Why are you calling these INI functions? The output produced is definitely not an INI file. You've just created a bunch of functions for manipulating a flat file into some bastardization of the INI format. You shouldn't mislead people by implying that these are functions for manipulating a standard INI file.

Link to comment
Share on other sites

But it's not an INI file. The format of the file is not the same as that of an INI file, therefore, it's not an INI file. You can't just modify a standard file format to remove something (sections) and then turn around and call it the same thing. It's not the same thing, calling it the same thing is confusing.

Link to comment
Share on other sites

Very easy. Call it a format loosely based on the INI format. That's what it is.

Edit: Fixed typo.

i know better thing, i wont release my crap here anymore, so better for all and i can call it whatever i want. kay

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

i know better thing, i wont release my crap here anymore, so better for all and i can call it whatever i want. kay

I'll try one more time to get this through to you.

The INI format is pretty standard. It basically says that the file contains one or more sections and each section contains key/value pairs.

You have created a new format based on the INI format which strips out the section. Your file format is no longer INI, you've changed it. You can't call it INI, either, because it's not INI. If your format was really INI, I could use the built-in INI functions on it. However, I can't do that, you've removed sections so standard INI functions can't find the keys.

You can't just take something, strip things out or add things in and then try to pass it off as the original thing. What you have created is not an INI file. I can not use an INI file with your functions. I can not use the standard INI functions with a file created by your functions. The two formats are not interchangeable. They may look in some areas but they are not the same. Calling these functions INI functions is just flat out lying to any user that makes the mistake of assuming these functions work on standard INI files.

Link to comment
Share on other sites

I'll try one more time to get this through to you.

The INI format is pretty standard. It basically says that the file contains one or more sections and each section contains key/value pairs.

You have created a new format based on the INI format which strips out the section. Your file format is no longer INI, you've changed it. You can't call it INI, either, because it's not INI. If your format was really INI, I could use the built-in INI functions on it. However, I can't do that, you've removed sections so standard INI functions can't find the keys.

You can't just take something, strip things out or add things in and then try to pass it off as the original thing. What you have created is not an INI file. I can not use an INI file with your functions. I can not use the standard INI functions with a file created by your functions. The two formats are not interchangeable. They may look in some areas but they are not the same. Calling these functions INI functions is just flat out lying to any user that makes the mistake of assuming these functions work on standard INI files.

but im using it for inireads, thats why i called it _iniread

i cant answer you becouse my english is not good enoguh, sorry m8, i let you win , but please forget my thread and my function , i won't change it, do it if you want, no matter but i call my funcs like i want, and i cant call my function something like :

FileReadForString,

i wouldnt call it this becouse its again not same hes not searching a string , the idea based on iniread, it reads key in a file, only without the section , yes the old iniread would not work, BUT I MADE IT FOR THIS!!...shit why you cant be german i could answer you better sorry m8, pls stop posting something about this, change your mind , or change my thread, or do whatever you want , but let me -.- i wont change the name -

My UDF's : Startet on : 06.06.2006_CaseSearchOrReplaceStr();~> Searches OR Replaces a String,;~> With or Without Casesensivity
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...