1. Dashboard
  2. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team
    4. Mitgliedersuche
  3. Forenregeln
  4. Forum
    1. Unerledigte Themen
  • Anmelden
  • Registrieren
  • Suche
Alles
  • Alles
  • Artikel
  • Seiten
  • Forum
  • Erweiterte Suche
  1. AutoIt.de - Das deutschsprachige Forum.
  2. Mitglieder
  3. BugFix

Beiträge von BugFix

  • Problem mit #AutoIt3Wrapper_Res_ProductVersion=

    • BugFix
    • 28. November 2019 um 13:44

    Alternativ (mit vermutlich etwas Aufwand) müsstest du dir einen "Ressource-Cleaner" schreiben.

    Dazu sollte _WinAPI_UpdateResource() geeignet sein.

  • Problem mit #AutoIt3Wrapper_Res_ProductVersion=

    • BugFix
    • 28. November 2019 um 09:57
    Zitat von fee

    Daher wäre es schön und nett, wenn jemand, der im Gegensatz zu mir aus dem Stegreif gutes Englisch von sich geben kann, den (Chef-)Programmierer von AutoIt darauf aufmerksam machen könnte, damit er die Möglichkeit bekommt, diesen bestimmt nicht allzugroßen Fehler im AutoIt3Wrapper zu beheben.

    Ich habe mal probiert: Das Problem ist nicht der Wrapper. Den benötigt man ja auch grundsätzlich nicht, ist nur ein Tool zur Vereinfachung.

    Wenn man selbst kompiliert ist das Feld "Produktversion" enthalten. Das wird beim Kompilieren über die "Aut2exe.exe" erstellt.

    zum Testen ein beliebiges Skript (hier "msgbox.au3") direkt kompilieren:

    AutoIt
    Local $sInFile = "C:\CODE\AutoIt\TEST\msgbox.au3"
    Local $Aut2Exe = StringReplace(@AutoItExe, "AutoIt3.exe", "Aut2Exe\Aut2exe.exe")
    
    ; "Aut2exe.exe / In < infile.au3 >[/out < outfile.exe >][/icon < iconfile.ico >][/comp 0 - 4][/nopack][/x64][/bin < binfile.bin >] "
    Local $sCmd = StringFormat("%s /in %s", $Aut2Exe, $sInFile)
    
    Run($sCmd)

    Eigenschaften Datei:

    eigenschaften.JPG

    Somit sind Änderungen nur in der fertigen exe mittels Ressource-Hacker möglich.

  • Problem mit #AutoIt3Wrapper_Res_ProductVersion=

    • BugFix
    • 27. November 2019 um 22:56
    Zitat

    Würde mich ehrlich gesagt auch wundern, wenn das was bringen würde, denn dafür müsste ich die AutoIt3Wrapper.au3 doch kompilieren, oder nicht? Bei mir wurde die jedenfalls so "nackt" installiert und wird über die Registry passend aufgerufen, wenn auch über einen Pfadumweg: "c:\programme\autoit3\scite\..\autoit3.exe" "c:\programme\autoit3\scite\autoit3wrapper\autoit3wrapper.au3" /showgui /in "%l".

    Das ist kein Umweg, sondern der normale Weg eine *. au3 ausführen zu lassen, indem man sie als Parameter der autoit3.exe übergibt.

    Kompilieren ist also nicht erforderlich.

  • Listview & Multiauswahl

    • BugFix
    • 27. November 2019 um 12:52

    Das Array gibt dir an [0] die Anzahl der gewählten Einträge. An [1] bis [n] findest du den 0-basierten Item Index.

    Den übergibst du dann zum Auswerten an die Funktion

    _GUICtrlListView_GetItemText ( $hWnd, $iIndex [, $iSubItem = 0] ) (mit entsprechendem SpaltenIndex).

    Alternativ kannst du jedes Item mit SubItem in ein Array auslesen:_GUICtrlListView_GetItemTextArray ( $hWnd [, $iItem = -1] )

  • Problem mit #AutoIt3Wrapper_Res_ProductVersion=

    • BugFix
    • 27. November 2019 um 11:59

    Kommentiere doch mal in der "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" die Zeile 14

    #AutoIt3Wrapper_Res_ProductVersion=2.2

    aus. Vielleicht ist damit schon dein Problem gelöst.

    ..und in der "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\Directives.au3" die Zeile 40 ebenfalls auskommentieren

    #AutoIt3Wrapper_Res_ProductVersion= ;Product Version

  • Wörter finden in String

    • BugFix
    • 27. November 2019 um 11:04

    Da der TS nicht explizit kyrillsche, japanische, etc. Texte angeführt hat, sollte man Unicode eher vermeiden. In unserem Sprachraum ist mit Windows-1252 alles abgedeckt (Textdateien sind standardmäßig meist in dieser Kodierung) und wenn ich multilingual arbeiten wollte, hätte ich eh das Problem, dass ich mit Dateien unterschiedlicher Kodierung arbeiten müsste. Wiederum ist das Ermitteln der Kodierung (wenn nicht im Text extra hinterlegt) nur unsicher möglich.


    Persönlich wäre ich ja eher dafür, dass Hersteller von Editoren gezwungen werden Textdateien ausschließlich in Unicode zu speichern. Das würde viel Frust beim Programmieren ersparen. ;)

  • Urlaubsplanung

    • BugFix
    • 25. November 2019 um 11:19

    Ich kann dir nur empfehlen das Projekt komplett in VBA zu lösen. AutoIt hierfür zu verwenden ist wenig sinnvoll.

    Du kannst alles mit den Excel-Bordmitteln lösen. Farbgebung geht über bedingte Formatierung, Feiertage kannst du in extra Tabellen hinterlegen und über Verweise heranziehen, ebenso Schulferien etc. pp.

    Grafische Oberfläche (Menü zur Eingabe, Comboboxen zur Auswahl, ...) bietet alles VBA. Also knie dich lieber etwas in die Excel Programmierung rein, kannst ja auch eine der massenhaft im Netz verfügbaren Vorlagen als Anregung nehmen.

  • Huawei Mate 20 lite: Speicher voll - wovon?

    • BugFix
    • 24. November 2019 um 22:49

    Dieses hier als Hilfe für alle, die mal vor demselben Problem stehen.

    Meine Frau hat ein Huawei Mate 20 lite. Das Gerät hat 64GB Speicher, für den Nutzer verfügbar: 58GB.

    Nach einem Jahr Nutzung kam nun die Meldung "Speicher voll". Naja, meine Frau tauscht viele Fotos aus und WhatsApp't auch intensiv, da dachte ich mir: Holst du erst mal einen Schwung Videos und Fotos runter, dann hast du erst mal Ruhe. Etwa 10GB Daten runter geladen - aber nach einer Woche dasselbe wieder.

    Aber 10GB in einer Woche - das schafft selbst meine Frau nicht.

    Also habe ich gesucht. Mit dem normalen Datenbrowser war nichts zu finden. Ich habe dann den Cx-Datei Explorer installiert und mir versteckte Dateien anzeigen lassen. Da bin ich dann fündig geworden: .photoShare ist der Bösewicht. In den Unterordnern befanden sich knapp 150.000! IMG-Dateien (thumb), etwa 30GB.

    Warum soviel thumbs gespeichert wurden, ist mir nicht ganz klar. Ich vermute, dass die fehlerhafte Erkennung der Speicherkarte (bekannter Fehler für das Modell, sollte man nicht mit SD-Karte betreiben) zu Synchronisationsfehlern geführt hat und deshalb thumbs mehrfach gespeichert wurden.

    Also die Unterordner von .photoShare/thumb löschen und alles ist wieder im Lot. :thumbup:

    Aber Zeit mitbringen - schafft max. 6GB/Stunde.

  • config.au3 - Alternative zur INI, ohne deren Größenbeschränkung

    • BugFix
    • 21. November 2019 um 13:40

    Das Thema wurde in diesem Post behandelt.

    Ich habe die dort gepostete Version meiner UDF jetzt noch etwas verfeinert.

    AutoIt
    ;-- TIME_STAMP   2019-11-21 12:56:14   v 0.3
    
    
    Opt('MustDeclareVars', 1)
    
    #cs
    Struktur Config-Datei (*.cfg)
    
    == Sektion mit Inhalt ==
    SECTION;Key=Value;Key=;Key=Value;Key=Value...
    
    Schlüssel ohne Wert MÜSSEN mit einem "=" abgeschlossen werden!
    
    == leere Sektion ==
    SECTION
    
    Kommentarzeilen beginnen mit "#"
    
    == Funktionen ==
    
    _CfgRead()
    Reads a value from a key in a section
    
    _CfgWrite()
    Writes a value for a key in a section
    
    _CfgKeyDelete()
    Deletes a key in a section
    
    _CfgSectionDelete()
    Deletes a section
    
    _CfgKeyList()
    Returns all keys in a section (as array or delimited string)
    
    _CfgSectionList()
    Returns all sections (as array or delimited string)
    
    _CfgSectionGetArray()
    Returns an 2D array with all key-value-pairs of a section
    
    _CfgSectionWriteArray()
    Replaces (or adds) a section from a 2D array with all key-value-pairs
    
    
    
    == Hilfsfunktionen ==
    
    __CfgKeyWrite
    __CfgSectionRead
    __CfgSectionWrite
    __CfgSectionDelete
    __FileWriteToLine (modified version of _FileWriteToLine)
    #ce
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgRead
    ; Description ...: Reads the value from a key in a section.
    ; Syntax ........: _CfgRead($_sCfg, $_sSection, $_sKey[, $_sDefault = ''])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section with the searched key
    ;                  $_sKey               - The searched key
    ;                  $_sDefault           - [optional] The default return value. Default is ''.
    ; Return values .: Success              The value of the passed key or if not set, the default value
    ;                  Failure              The default value, set @error  1 - config file does'nt exist
    ;                                       The default value, set @error  2 - config file is empty
    ;                                       The default value, set @error  3 - section does'nt exist
    ;                                       The default value, set @error  4 - none key-value-pairs in this section
    ;                                       The default value, set @error  5 - key does'nt exist in this section
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgRead($_sCfg, $_sSection, $_sKey, $_sDefault='')
        Local $aSec = __CfgSectionRead($_sCfg, $_sSection)
        If $aSec[0] = 0 Then Return SetError(@error,0,0)
        Local $aSectionLine = StringSplit($aSec[1], ';', 2)           ; $STR_NOCOUNT (2)
        If @error Then Return SetError(4,0,0)                         ; none key-value-pairs in this line
        Local $aKeyVal, $sSectionContent = $_sSection
        For $i = 1 To UBound($aSectionLine) -1
            $aKeyVal = StringSplit($aSectionLine[$i], '=', 2)         ; $STR_NOCOUNT (2)
            If $aKeyVal[0] = $_sKey Then
                If UBound($aKeyVal) = 2 Then
                    Return $aKeyVal[1]
                Else
                    Return $_sDefault
                EndIf
            EndIf
        Next
        Return SetError(5,0,$_sDefault)
    EndFunc  ;==>_CfgRead
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgWrite
    ; Description ...: Writes the value of a key in a section.
    ; Syntax ........: _CfgWrite($_sCfg, $_sSection, $_sKey, $_sValue)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - The section
    ;                  $_sKey               - The key
    ;                  $_sValue             - The value to store
    ; Return values .: Success              1
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgWrite($_sCfg, $_sSection, $_sKey, $_sValue)
        Local $fH, $aSec = __CfgSectionRead($_sCfg, $_sSection)
        Switch @error
            Case 1 ; file does'nt exist
                Return FileWrite($_sCfg, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
            Case 2 ; file is empty
                $fH = FileOpen($_sCfg, 2)                             ; $FO_OVERWRITE (2)
                FileWrite($fH, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
                Return FileClose($fH)
            Case 3 ; section does'nt exist
                Return __CfgSectionWrite($_sCfg, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue), $aSec[0])
        EndSwitch
        ; otherwise: section exists
        Local $sSectionContent = __CfgKeyWrite($_sSection, $aSec[1], $_sKey, $_sValue)
        Return __CfgSectionWrite($_sCfg, $sSectionContent, $aSec[0])
    EndFunc  ;==>_CfgWrite
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgKeyDelete
    ; Description ...: Deletes a key-value-pair in a section
    ; Syntax ........: _CfgKeyDelete($_sCfg, $_sSection, $_sKey)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section with the searched key
    ;                  $_sKey               - The key to delete
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - section does'nt exist
    ;                                       0, set @error  4 - none key-value-pairs in this section
    ;                                       0, set @error  5 - key does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgKeyDelete($_sCfg, $_sSection, $_sKey)
        Local $aSec = __CfgSectionRead($_sCfg, $_sSection)
        If $aSec[0] = 0 Then Return SetError(@error,0,0)
        Local $aSectionLine = StringSplit($aSec[1], ';', 2)           ; $STR_NOCOUNT (2)
        If @error Then Return SetError(4,0,0)                         ; none key-value-pairs in this line
        Local $aKeyVal, $sSectionContent = $_sSection, $bDeleted = False
        For $i = 1 To UBound($aSectionLine) -1
            $aKeyVal = StringSplit($aSectionLine[$i], '=', 2)         ; $STR_NOCOUNT (2)
            If $aKeyVal[0] = $_sKey Then
                ; do nothing, will not write again
                $bDeleted = True
            Else
                $sSectionContent &= StringFormat(';%s=%s', $aKeyVal[0], $aKeyVal[1])
            EndIf
        Next
        If Not $bDeleted Then Return SetError(5,0,0)
        Return __CfgSectionWrite($_sCfg, $sSectionContent, $aSec[0])
    EndFunc  ;==>_CfgKeyDelete
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionDelete
    ; Description ...: Deletes a section
    ; Syntax ........: _CfgSectionDelete($_sCfg, $_sSection)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - The Section to delete
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionDelete($_sCfg, $_sSection)
        Local $aSec = __CfgSectionRead($_sCfg, $_sSection)
        If $aSec[0] = 0 Then Return SetError(@error,0,0)
        Return __CfgSectionDelete($_sCfg, $aSec[0])
    EndFunc  ;==>_CfgSectionDelete
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionList
    ; Description ...: Returns a  array or string of all section names
    ; Syntax ........: _CfgSectionList($_sCfg[, $_bRetArray=True])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_bRetArray          - [optional] Return as array or delimited string, Default is True - Array
    ; Return values .: Success              Array with all section names, count of sections on index [0]
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionList($_sCfg, $_bRetArray=True)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aSectionLine, $aKeyVal, $sRet = ''
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $sRet &= $aSectionLine[0] & ';'
        Next
        $sRet = StringTrimRight($sRet, 1)
        Return ($_bRetArray ? StringSplit($sRet, ';') : $sRet)
    EndFunc  ;==>_CfgSectionList
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgKeyList
    ; Description ...: Returns a  array or string of all key names in a section
    ; Syntax ........: _CfgKeyList($_sCfg, $_sSection[, $_bRetArray=True])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section to get the keys from
    ;                  $_bRetArray          - [optional] Return as array or delimited string, Default is True - Array
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - section does'nt exist
    ;                                       0, set @error  4 - none key-value-pairs in this section
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgKeyList($_sCfg, $_sSection, $_bRetArray=True)
        Local $sRet = '', $aRet[1]
        Local $aSec = __CfgSectionRead($_sCfg, $_sSection)
        If $aSec[0] = 0 Then Return SetError(@error,0,($_bRetArray ? $aRet : $sRet))
        Local $aKeys = StringRegExp($aSec[1], "([^=;]+)=", 3)
        If Not IsArray($aKeys) Then Return SetError(4,0,($_bRetArray ? $aRet : $sRet))
        If $_bRetArray Then Return $aKeys
        For $i = 0 To UBound($aKeys) -1
            $sRet &= $aKeys[$i] & ';'
        Next
        Return StringTrimRight($sRet, 1)
    EndFunc  ;==>_CfgKeyList
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionGetArray
    ; Description ...: Returns a  2D array of all key-value-pairs in a section
    ; Syntax ........: _CfgSectionGetArray($_sCfg, $_sSection)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section to get the key-value-pairs from
    ; Return values .: Success              2D array: [[count_keys,section_name],[key_1,value],[key_2,value], .. [key_n,value]]
    ;                  Failure              [[0,"error"]], set @error  1 - config file does'nt exist
    ;                                       [[0,"error"]], set @error  2 - config file is empty
    ;                                       [[0,"error"]], set @error  3 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionGetArray($_sCfg, $_sSection)
        Local $aRet[1][2] = [[0,"error"]]
        Local $aSec = __CfgSectionRead($_sCfg, $_sSection)
        If $aSec[0] = 0 Then Return SetError(@error,0,$aRet)
        Local $aSectionLine = StringSplit($aSec[1], ';', 2)           ; $STR_NOCOUNT (2)
        If @error Then                                                ; none key-value-pairs in this line
            $aRet[0][1] = $_sSection
            Return $aRet
        EndIf
        Local $aKeyVal, $iCnt = UBound($aSectionLine)
        ReDim $aRet[$iCnt][2]
        $aRet[0][0] = $iCnt -1
        $aRet[0][1] = $_sSection
        For $i = 1 To UBound($aSectionLine) -1
            $aKeyVal = StringSplit($aSectionLine[$i], '=', 2)         ; $STR_NOCOUNT (2)
            $aRet[$i][0] = $aKeyVal[0]
            $aRet[$i][1] = (UBound($aKeyVal) = 2 ? $aKeyVal[1] : '')
        Next
    EndFunc  ;==>_CfgSectionGetArray
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionWriteArray
    ; Description ...: Writes the whole section at once from a passed 2D array with all key-value-pairs
    ; Syntax ........: _CfgSectionWriteArray($_sCfg, $_sSection, $_aKeyVal)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section to write the key-value-pairs
    ;                  $_aKeyVal            - 2D array Default: [[count_keys,section_name],[key_1,val],[key_2,val],...[key_n,val]]
    ;                                         or [[key_1,val],[key_2,val],...[key_n,val]] - $_1stIndex must set to "0" in this case!
    ;                  $_1stIndex           - [optional] The first index with data of the passed array. Default=1, like returned from _CfgSectionGetArray()
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - $_aKeyVal is'nt a array
    ;                                       0, set @error  2 - $_aKeyVal is'nt a 2D array
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionWriteArray($_sCfg, $_sSection, $_aKeyVal, $_1stIndex=1)
        Local $fH, $aSec = __CfgSectionRead($_sCfg, $_sSection)
        Local $iErr = @error
        If Not IsArray($_aKeyVal) Then Return SetError(1,0,0)
        If UBound($_aKeyVal, 0) <> 2 Then Return SetError(2,0,0)
        Local $sSectionContent = $_sSection
        For $i = $_1stIndex To UBound($_aKeyVal) -1
            $sSectionContent &= StringFormat(';%s=%s', $_aKeyVal[$i][0], $_aKeyVal[$i][1])
        Next
        Switch $iErr
            Case 0 ; section exists
                Return __CfgSectionWrite($_sCfg, $sSectionContent, $aSec[0])
            Case 1 ; file does'nt exist
                Return FileWrite($_sCfg, $sSectionContent & @CRLF)
            Case 2 ; file is empty
                $fH = FileOpen($_sCfg, 2)                             ; $FO_OVERWRITE (2)
                FileWrite($fH, $sSectionContent & @CRLF)
                Return FileClose($fH)
            Case 3 ; section does'nt exist
                Return __CfgSectionWrite($_sCfg, $sSectionContent & @CRLF, $aSec[0])
        EndSwitch
    EndFunc  ;==>_CfgSectionWriteArray
    
    
    
    #region - Helper functions
    
    ; Builds the new section content
    Func __CfgKeyWrite($_sSection, $_sSectionContent, $_sKey, $_sValue)
        Local $aSectionLine = StringSplit($_sSectionContent, ';', 2)  ; $STR_NOCOUNT (2)
        If @error = 1 Then                                            ; none key-value-pairs in this line
            $_sSectionContent = StringFormat('%s;%s=%s', $_sSection, $_sKey, $_sValue)
        EndIf
        $_sSectionContent = $_sSection
        Local $aKeyVal, $bReplaced = False
        For $i = 1 To UBound($aSectionLine) -1
            $aKeyVal = StringSplit($aSectionLine[$i], '=', 2)         ; $STR_NOCOUNT (2)
            If $aKeyVal[0] = $_sKey Then
                $_sSectionContent &= StringFormat(';%s=%s', $aKeyVal[0], $_sValue)
                $bReplaced = True
            Else
                $_sSectionContent &= StringFormat(';%s=%s', $aKeyVal[0], $aKeyVal[1])
            EndIf
        Next
        ; the key is new:
        If Not $bReplaced Then $_sSectionContent &= StringFormat(';%s=%s', $_sKey, $_sValue)
        Return $_sSectionContent
    EndFunc  ;==>__CfgKeyWrite
    
    ; Returns an array: [line_number_in_file,line_content]
    Func __CfgSectionRead($_sCfg, $_sSection)
        Local $aRet[] = [0,'']                                        ; if not found: line number is 0
        If Not FileExists($_sCfg) Then Return SetError(1,0,$aRet)
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,$aRet)                 ; empty file
        Local $aMatch
        For $i = 0 To UBound($aCfg) -1
            $aMatch = StringRegExp($aCfg[$i], "^([^;]+)", 1)
            If $aMatch[0] = $_sSection Then
                $aRet[0] = $i+1
                $aRet[1] = $aCfg[$i]
                Return $aRet
            EndIf
        Next
        Return SetError(3,0,$aRet)                                    ; section does'nt exist
    EndFunc  ;==>__CfgSectionRead
    
    ; Writes the full section in the passed line (overwriting). Line number 0 for append.
    Func __CfgSectionWrite($_sCfg, $_sSectionContent, $_iSectionLine=0)
        If $_iSectionLine = 0 Then                                    ; section does'nt exist
            Local $fH = FileOpen($_sCfg, 1)                           ; $FO_APPEND (1)
            FileWrite($fH, $_sSectionContent)
            Return FileClose($fH)
        EndIf
        Return __FileWriteToLine($_sCfg, $_iSectionLine, $_sSectionContent, True)
    EndFunc  ;==>__CfgSectionWrite
    
    ; Deletes the passed line
    Func __CfgSectionDelete($_sCfg, $_iSectionLine)
        Return __FileWriteToLine($_sCfg, $_iSectionLine, '', True)
    EndFunc  ;==>__CfgSectionDelete
    
    ; #FUNCTION# ====================================================================================================================
    ; Author ........: cdkid
    ; Modified.......: partypooper, MrCreatoR
    ;                  BugFix: The last line needs normally also a CRLF. So here is a new parameter to define this.
    ; ===============================================================================================================================
    Func __FileWriteToLine($sFilePath, $iLine, $sText, $bOverWrite = False, $bLastLineCRLF = True)
        If $iLine <= 0 Then Return SetError(4, 0, 0)
        If Not IsString($sText) Then
            $sText = String($sText)
            If $sText = "" Then Return SetError(6, 0, 0)
        EndIf
        If $bOverWrite = Default Then $bOverWrite = False
        If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) ; For old versions.
        If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
    
        Local $aArray = FileReadToArray($sFilePath)
        Local $iUBound = UBound($aArray) - 1
        If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0)
    
        Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) +2) ; $FO_OVERWRITE (2)
        If $hFileOpen = -1 Then Return SetError(3, 0, 0)
    
        Local $sData = ""
        $iLine -= 1 ; Now the array is 0-based, so reduce the line number by 1.
        For $i = 0 To $iUBound
            If $i = $iLine Then
                If $bOverWrite Then
                    If $sText Then $sData &= $sText & @CRLF
                Else
                    $sData &= $sText & @CRLF & $aArray[$i] & @CRLF
                EndIf
            ElseIf $i < $iUBound Then
                $sData &= $aArray[$i] & @CRLF
            ElseIf $i = $iUBound Then
                $sData &= $aArray[$i] & ($bLastLineCRLF ? @CRLF : '')
            EndIf
        Next
    
        FileWrite($hFileOpen, $sData)
        FileClose($hFileOpen)
        Return 1
    EndFunc  ;==>__FileWriteToLine
    
    #endregion
    Alles anzeigen

    Dateien

    config[0.3].au3 18,73 kB – 324 Downloads
  • _FileWriteToLine() - löscht letzten Zeilenumbruch

    • BugFix
    • 21. November 2019 um 13:28
    Zitat von Musashi

    Ist wohl wieder mal eine Frage des Standpunktes

    Eigentlich nicht.

    Wenn ich den Inhalt einer Zeile ändere erwarte ich NICHT, dass die ganze Datei verändert wird. Das ist definitiv ein Bug - auch wenn Melba das in den nächsten 7 Leben nicht einsehen wird. :rofl:

  • _FileWriteToLine() - löscht letzten Zeilenumbruch

    • BugFix
    • 21. November 2019 um 12:30

    Hier ein kleines Testskript, das alles erklärt:

    AutoIt
    #include <File.au3>
    
    Local $File = 'test_write.txt'
    Local $sContent = _
    'Easy to learn BASIC-like syntax' & @CRLF & _
    'Simulate keystrokes and mouse movements' & @CRLF & _
    'Manipulate windows and processes' & @CRLF & _
    'Interact with all standard windows controls' & @CRLF & _
    'Scripts can be compiled into standalone executables' & @CRLF & _
    'Create Graphical User Interfaces (GUIs)' & @CRLF & _
    'COM support' & @CRLF & _
    'Regular expressions' & @CRLF & _
    'Directly call external DLL and Windows API functions' & @CRLF & _
    'Scriptable RunAs functions' & @CRLF & _
    'Detailed helpfile and large community-based support forums' & @CRLF & _
    'Compatible with Windows XP / Server 2003 / Vista / Server 2008 / Windows 7 / Windows 8 / Windows 10' & @CRLF & _
    'Unicode and x64 support' & @CRLF & _
    'Digitally signed for peace of mind' & @CRLF & _
    'Works with the User Account Control (UAC) found in Windows beginning with Vista' & @CRLF
    FileWrite($File, $sContent)
    
    ; wenn man die Datei im Editor betrachtet, endet sie - wie gewollt - mit einem Zeilenumbruch
    ; Ändere ich jetzt aber den Inhalt einer Zeile wie folgt:
    _FileWriteToLine($File, 2, 'Bla-Bla', True)
    
    ; dann wird der letzte Zeilenumbruch in der Datei "verschluckt"
    Alles anzeigen

    Könnt ihr dieses Verhalten nachvollziehen?

    Wenn ja ist das wohl ein Bug. Denn wenn ich nun im AppendMode auf die Datei zugreife, landet neuer Inhalt statt in einer neuen Zeile, am letzten Wort der letzten Zeile. :Face:

    EDIT:

    Ja, ist (m.M.) ein Bug. Habe die Funktion mal entsprechend erweitert. Standardmäßig wird nun auch das abschliessende CRLF geschrieben, kann optional abgewählt werden:

    AutoIt
    ; #FUNCTION# ====================================================================================================================
    ; Author ........: cdkid
    ; Modified.......: partypooper, MrCreatoR
    ;                  BugFix: The last line needs normally also a CRLF. So here is a new parameter to define this.
    ; ===============================================================================================================================
    Func __FileWriteToLine($sFilePath, $iLine, $sText, $bOverWrite = False, $bLastLineCRLF = True)
        If $iLine <= 0 Then Return SetError(4, 0, 0)
        If Not IsString($sText) Then
            $sText = String($sText)
            If $sText = "" Then Return SetError(6, 0, 0)
        EndIf
        If $bOverWrite = Default Then $bOverWrite = False
        If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) ; For old versions.
        If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
    
        Local $aArray = FileReadToArray($sFilePath)
        Local $iUBound = UBound($aArray) - 1
        If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0)
    
        Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_OVERWRITE)
        If $hFileOpen = -1 Then Return SetError(3, 0, 0)
    
        Local $sData = ""
        $iLine -= 1 ; Now the array is 0-based, so reduce the line number by 1.
        For $i = 0 To $iUBound
            If $i = $iLine Then
                If $bOverWrite Then
                    If $sText Then $sData &= $sText & @CRLF
                Else
                    $sData &= $sText & @CRLF & $aArray[$i] & @CRLF
                EndIf
            ElseIf $i < $iUBound Then
                $sData &= $aArray[$i] & @CRLF
            ElseIf $i = $iUBound Then
                $sData &= $aArray[$i] & ($bLastLineCRLF ? @CRLF : '')
            EndIf
        Next
    
        FileWrite($hFileOpen, $sData)
        FileClose($hFileOpen)
        Return 1
    EndFunc   ;==>__FileWriteToLine
    Alles anzeigen
  • IniReadSectionNames Grenze

    • BugFix
    • 20. November 2019 um 21:01

    Ich habe mal noch eine weitere Funktion hinzugefügt: _CfgSectionGetArray() - liest alle Schlüssel-Wert-Paare einer Sektion in ein 2D-Array.

    config.au3 v0.2
    AutoIt
    ;-- TIME_STAMP   2019-11-20 20:58:33   v 0.2
    
    #include-once
    #include <File.au3>
    
    Opt('MustDeclareVars', 1)
    
    #cs
    Struktur Config-Datei (*.cfg)
    
    == Sektion mit Inhalt ==
    SECTION;Key=Value;Key=;Key=Value;Key=Value...
    
    Schlüssel ohne Wert MÜSSEN mit einem "=" abgeschlossen werden!
    
    == leere Sektion ==
    SECTION
    
    Kommentarzeilen beginnen mit "#"
    
    Funktionen:
    
    _CfgRead()
    _CfgWrite()
    _CfgKeyDelete()
    _CfgSectionDelete()
    _CfgKeyList()
    _CfgSectionList()
    _CfgSectionGetArray()
    
    #ce
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgRead
    ; Description ...: Reads the value of a key in a section.
    ; Syntax ........: _CfgRead($_sCfg, $_sSection, $_sKey[, $_sDefault = ''])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section with the searched key
    ;                  $_sKey               - The searched key
    ;                  $_sDefault           - [optional] The default return value. Default is ''.
    ; Return values .: Success              The value of the passed key or if not set, the default value
    ;                  Failure              The default value, set @error  1 - config file does'nt exist
    ;                                       The default value, set @error  2 - config file is empty
    ;                                       The default value, set @error  3 - none key-value-pairs in this section
    ;                                       The default value, set @error  4 - key does'nt exist in this section
    ;                                       The default value, set @error  5 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgRead($_sCfg, $_sSection, $_sKey, $_sDefault='')
        If Not FileExists($_sCfg) Then Return SetError(1,0,$_sDefault)
        Local $aSectionLine, $aKeyVal, $iErr
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,$_sDefault)            ; empty file
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then Return SetError(3,0,$_sDefault)     ; none key-value-pairs in this line
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    If $aKeyVal[0] = $_sKey Then
                        If UBound($aKeyVal) = 2 Then
                            Return $aKeyVal[1]
                        Else
                            Return $_sDefault
                        EndIf
                    EndIf
                Next
                Return SetError(4,0,$_sDefault)
            EndIf
        Next
        Return SetError(5,0,$_sDefault)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgWrite
    ; Description ...: Writes the value of a key in a section.
    ; Syntax ........: _CfgWrite($_sCfg, $_sSection, $_sKey, $_sValue)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - The section
    ;                  $_sKey               - The key
    ;                  $_sValue             - The value to store
    ; Return values .: Success              1
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgWrite($_sCfg, $_sSection, $_sKey, $_sValue)
        If Not FileExists($_sCfg) Then
            Return FileWrite($_sCfg, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
        EndIf
        Local $aSectionLine, $aKeyVal, $fH, $sLine, $iErr, $bReplaced
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then                                            ; empty file
            $fH = FileOpen($_sCfg, 2)                                 ; $FO_OVERWRITE (2)
            FileWrite($fH, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
            Return FileClose($fH)
        EndIf
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then                                     ; none key-value-pairs in this line
                    Return _FileWriteToLine($_sCfg, $i+1, StringFormat('%s;%s=%s', $_sSection, $_sKey, $_sValue), True)
                EndIf
                $sLine = $aSectionLine[0]
                $bReplaced = False
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    If $aKeyVal[0] = $_sKey Then
                        $sLine &= StringFormat(';%s=%s', $aKeyVal[0], $_sValue)
                        $bReplaced = True
                    Else
                        $sLine &= StringFormat(';%s=%s', $aKeyVal[0], $aKeyVal[1])
                    EndIf
                Next
                If Not $bReplaced Then $sLine &= StringFormat(';%s=%s', $_sKey, $_sValue)
                Return _FileWriteToLine($_sCfg, $i+1, $sLine, True)
            EndIf
        Next
        ; section not found
        $fH = FileOpen($_sCfg, 1)                                     ; $FO_APPEND (1)
        FileWrite($fH, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
        Return FileClose($fH)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgKeyDelete
    ; Description ...: Deletes a key-value-pair in a section
    ; Syntax ........: _CfgKeyDelete($_sCfg, $_sSection, $_sKey)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section with the searched key
    ;                  $_sKey               - The key to delete
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - none key-value-pairs in this section
    ;                                       0, set @error  4 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgKeyDelete($_sCfg, $_sSection, $_sKey)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aSectionLine, $aKeyVal, $fH, $sLine, $iErr
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then Return SetError(3,0,0)              ; none key-value-pairs in this line
                $sLine = $aSectionLine[0]
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    If $aKeyVal[0] = $_sKey Then
                        ; do nothing, will not write again
                    Else
                        $sLine &= StringFormat(';%s=%s', $aKeyVal[0], $aKeyVal[1])
                    EndIf
                Next
                Return _FileWriteToLine($_sCfg, $i+1, $sLine, True)
            EndIf
        Next
        ; section not found
        Return SetError(4,0,0)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionDelete
    ; Description ...: Deletes a section
    ; Syntax ........: _CfgSectionDelete($_sCfg, $_sSection)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - The Section to delete
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionDelete($_sCfg, $_sSection)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aSectionLine
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            If $aSectionLine[0] = $_sSection Then
                Return _FileWriteToLine($_sCfg, $i+1, '', True)
            EndIf
        Next
        ; section not found
        Return SetError(3,0,0)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionList
    ; Description ...: Returns a  array or string of all section names
    ; Syntax ........: _CfgSectionList($_sCfg[, $_bRetArray=True])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_bRetArray          - [optional] Return as array or delimited string, Default is True - Array
    ; Return values .: Success              Array with all section names, count of sections on index [0]
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionList($_sCfg, $_bRetArray=True)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aSectionLine, $aKeyVal, $sRet = ''
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $sRet &= $aSectionLine[0] & ';'
        Next
        $sRet = StringTrimRight($sRet, 1)
        Return ($_bRetArray ? StringSplit($sRet, ';') : $sRet)
    EndFunc
    
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgKeyList
    ; Description ...: Returns a  array or string of all key names in a section
    ; Syntax ........: _CfgKeyList($_sCfg, $_sSection[, $_bRetArray=True])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section to get the keys from
    ;                  $_bRetArray          - [optional] Return as array or delimited string, Default is True - Array
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - none key-value-pairs in this section
    ;                                       0, set @error  4 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgKeyList($_sCfg, $_sSection, $_bRetArray=True)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aSectionLine, $aKeyVal, $iErr, $sRet = ''
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then Return SetError(3,0,0)              ; none key-value-pairs in this line
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    $sRet &= $aKeyVal[0] & ';'
                Next
                $sRet = StringTrimRight($sRet, 1)
                Return ($_bRetArray ? StringSplit($sRet, ';') : $sRet)
            EndIf
        Next
        ; section not found
        Return SetError(4,0,0)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionGetArray
    ; Description ...: Returns a  2D array of all key-value-pairs in a section
    ; Syntax ........: _CfgSectionGetArray($_sCfg, $_sSection)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section to get the key-value-pairs from
    ; Return values .: Success              2D array: [[count_keys,section_name],[key_1,value],[key_2,value], .. [key_n,value]]
    ;                  Failure              [[0,"error"]], set @error  1 - config file does'nt exist
    ;                                       [[0,"error"]], set @error  2 - config file is empty
    ;                                       [[0,"error"]], set @error  3 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionGetArray($_sCfg, $_sSection)
        Local $aSectionLine, $aKeyVal, $iErr, $iCnt, $aRet[1][2] = [[0,"error"]]
        If Not FileExists($_sCfg) Then Return SetError(1,0,$aRet)
        Local $aCfg = FileReadToArray($_sCfg)
        If @error = 2 Then Return SetError(2,0,$aRet)                 ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            $iCnt = UBound($aSectionLine)
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then
                    $aRet[0][1] = ''                                  ; none key-value-pairs in this line
                    Return $aRet
                EndIf
                ReDim $aRet[$iCnt][2]
                $aRet[0][0] = $iCnt -1
                $aRet[0][1] = $_sSection
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    $aRet[$j][0] = $aKeyVal[0]
                    $aRet[$j][1] = (UBound($aKeyVal) = 2 ? $aKeyVal[1] : '')
                Next
                Return $aRet
            EndIf
        Next
        ; section not found
        Return SetError(3,0,$aRet)
    EndFunc
    Alles anzeigen

    Dateien

    config[0.2].au3 14,41 kB – 293 Downloads
  • IniReadSectionNames Grenze

    • BugFix
    • 20. November 2019 um 14:52

    Ich habe mal auf die Schnelle das von mir angesprochene cfg-Modell in eine UDF gegossen:

    config.au3
    AutoIt
    ;-- TIME_STAMP   2019-11-20 14:49:31   v 0.1
    
    #include-once
    #include <File.au3>
    
    Opt('MustDeclareVars', 1)
    
    #cs
    Struktur Config-Datei (*.cfg)
    
    == Sektion mit Inhalt ==
    SECTION;Key=Value;Key=;Key=Value;Key=Value...
    
    Schlüssel ohne Wert MÜSSEN mit einem "=" abgeschlossen werden!
    
    == leere Sektion ==
    SECTION
    
    Kommentarzeilen beginnen mit "#"
    
    Funktionen:
    
    _CfgRead()
    _CfgWrite()
    _CfgKeyDelete()
    _CfgSectionDelete()
    _CfgKeyList()
    _CfgSectionList()
    
    #ce
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgRead
    ; Description ...: Reads the value of a key in a section.
    ; Syntax ........: _CfgRead($_sCfg, $_sSection, $_sKey[, $_sDefault = ''])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section with the searched key
    ;                  $_sKey               - The searched key
    ;                  $_sDefault           - [optional] The default return value. Default is ''.
    ; Return values .: Success              The value of the passed key or if not set, the default value
    ;                  Failure              The default value, set @error  1 - config file does'nt exist
    ;                                       The default value, set @error  2 - config file is empty
    ;                                       The default value, set @error  3 - none key-value-pairs in this section
    ;                                       The default value, set @error  4 - key does'nt exist in this section
    ;                                       The default value, set @error  5 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgRead($_sCfg, $_sSection, $_sKey, $_sDefault='')
        If Not FileExists($_sCfg) Then Return SetError(1,0,$_sDefault)
        Local $aCfg = FileReadToArray($_sCfg), $aSectionLine, $aKeyVal, $iErr
        If @error = 2 Then Return SetError(2,0,$_sDefault)            ; empty file
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then Return SetError(3,0,$_sDefault)     ; none key-value-pairs in this line
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    If $aKeyVal[0] = $_sKey Then
                        If UBound($aKeyVal) = 2 Then
                            Return $aKeyVal[1]
                        Else
                            Return $_sDefault
                        EndIf
                    EndIf
                Next
                Return SetError(4,0,$_sDefault)
            EndIf
        Next
        Return SetError(5,0,$_sDefault)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgWrite
    ; Description ...: Writes the value of a key in a section.
    ; Syntax ........: _CfgWrite($_sCfg, $_sSection, $_sKey, $_sValue)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - The section
    ;                  $_sKey               - The key
    ;                  $_sValue             - The value to store
    ; Return values .: Success              1
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgWrite($_sCfg, $_sSection, $_sKey, $_sValue)
        If Not FileExists($_sCfg) Then
            Return FileWrite($_sCfg, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
        EndIf
        Local $aCfg = FileReadToArray($_sCfg), $aSectionLine, $aKeyVal, $fH, $sLine, $iErr, $bReplaced
        If @error = 2 Then                                            ; empty file
            $fH = FileOpen($_sCfg, 2)                                 ; $FO_OVERWRITE (2)
            FileWrite($fH, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
            Return FileClose($fH)
        EndIf
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then                                     ; none key-value-pairs in this line
                    Return _FileWriteToLine($_sCfg, $i+1, StringFormat('%s;%s=%s', $_sSection, $_sKey, $_sValue), True)
                EndIf
                $sLine = $aSectionLine[0]
                $bReplaced = False
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    If $aKeyVal[0] = $_sKey Then
                        $sLine &= StringFormat(';%s=%s', $aKeyVal[0], $_sValue)
                        $bReplaced = True
                    Else
                        $sLine &= StringFormat(';%s=%s', $aKeyVal[0], $aKeyVal[1])
                    EndIf
                Next
                If Not $bReplaced Then $sLine &= StringFormat(';%s=%s', $_sKey, $_sValue)
                Return _FileWriteToLine($_sCfg, $i+1, $sLine, True)
            EndIf
        Next
        ; section not found
        $fH = FileOpen($_sCfg, 1)                                     ; $FO_APPEND (1)
        FileWrite($fH, StringFormat('%s;%s=%s\n', $_sSection, $_sKey, $_sValue))
        Return FileClose($fH)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgKeyDelete
    ; Description ...: Deletes a key-value-pair in a section
    ; Syntax ........: _CfgKeyDelete($_sCfg, $_sSection, $_sKey)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section with the searched key
    ;                  $_sKey               - The key to delete
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - none key-value-pairs in this section
    ;                                       0, set @error  4 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgKeyDelete($_sCfg, $_sSection, $_sKey)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aCfg = FileReadToArray($_sCfg), $aSectionLine, $aKeyVal, $fH, $sLine, $iErr
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then Return SetError(3,0,0)              ; none key-value-pairs in this line
                $sLine = $aSectionLine[0]
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    If $aKeyVal[0] = $_sKey Then
                        ; do nothing, will not write again
                    Else
                        $sLine &= StringFormat(';%s=%s', $aKeyVal[0], $aKeyVal[1])
                    EndIf
                Next
                Return _FileWriteToLine($_sCfg, $i+1, $sLine, True)
            EndIf
        Next
        ; section not found
        Return SetError(4,0,0)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionDelete
    ; Description ...: Deletes a section
    ; Syntax ........: _CfgSectionDelete($_sCfg, $_sSection)
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - The Section to delete
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionDelete($_sCfg, $_sSection)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aCfg = FileReadToArray($_sCfg), $aSectionLine
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            If $aSectionLine[0] = $_sSection Then
                Return _FileWriteToLine($_sCfg, $i+1, '', True)
            EndIf
        Next
        ; section not found
        Return SetError(3,0,0)
    EndFunc
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgSectionList
    ; Description ...: Returns a  array or string of all section names
    ; Syntax ........: _CfgSectionList($_sCfg[, $_bRetArray=True])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_bRetArray          - [optional] Return as array or delimited string, Default is True - Array
    ; Return values .: Success              Array with all section names, count of sections on index [0]
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgSectionList($_sCfg, $_bRetArray=True)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aCfg = FileReadToArray($_sCfg), $aSectionLine, $aKeyVal, $sRet = ''
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $sRet &= $aSectionLine[0] & ';'
        Next
        $sRet = StringTrimRight($sRet, 1)
        Return ($_bRetArray ? StringSplit($sRet, ';') : $sRet)
    EndFunc
    
    
    
    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _CfgKeyList
    ; Description ...: Returns a  array or string of all key names in a section
    ; Syntax ........: _CfgKeyList($_sCfg, $_sSection[, $_bRetArray=True])
    ; Parameters ....: $_sCfg               - Path of the config file
    ;                  $_sSection           - Section to get the keys from
    ;                  $_bRetArray          - [optional] Return as array or delimited string, Default is True - Array
    ; Return values .: Success              1
    ;                  Failure              0, set @error  1 - config file does'nt exist
    ;                                       0, set @error  2 - config file is empty
    ;                                       0, set @error  3 - none key-value-pairs in this section
    ;                                       0, set @error  4 - section does'nt exist
    ; Author ........: BugFix
    ; ===============================================================================================================================
    Func _CfgKeyList($_sCfg, $_sSection, $_bRetArray=True)
        If Not FileExists($_sCfg) Then Return SetError(1,0,0)
        Local $aCfg = FileReadToArray($_sCfg), $aSectionLine, $aKeyVal, $iErr, $sRet = ''
        If @error = 2 Then Return SetError(2,0,0)                     ; empty file
    
        For $i = 0 To UBound($aCfg) -1
            If StringLeft($aCfg[$i], 1) = '#' Then ContinueLoop       ; its a comment line - skip
            $aSectionLine = StringSplit($aCfg[$i], ';', 2)            ; $STR_NOCOUNT (2)
            $iErr = @error
            If $aSectionLine[0] = $_sSection Then
                If $iErr = 1 Then Return SetError(3,0,0)              ; none key-value-pairs in this line
                For $j = 1 To UBound($aSectionLine) -1
                    $aKeyVal = StringSplit($aSectionLine[$j], '=', 2) ; $STR_NOCOUNT (2)
                    $sRet &= $aKeyVal[0] & ';'
                Next
                $sRet = StringTrimRight($sRet, 1)
                Return ($_bRetArray ? StringSplit($sRet, ';') : $sRet)
            EndIf
        Next
        ; section not found
        Return SetError(4,0,0)
    EndFunc
    Alles anzeigen
    Zitat von Superdau

    An diese Möglichkeit hab ich auch schon gedacht.

    Ist halt nur n großer Umbau

    Der Umbau ist ein simples Replace-Skript für deine INI:P, dass die Aufgabe in wenigen ms erledigt.

    Dateien

    config.au3 12,24 kB – 274 Downloads
  • IniReadSectionNames Grenze

    • BugFix
    • 20. November 2019 um 09:29

    Dafür verwende ich normale Textdateien als Config-Dateien (*.cfg).

    Struktur je Zeile:

    sektion;Schlüssel=Wert;Schlüssel=Wert;Schlüssel=Wert;Schlüssel=Wert

    Ist easy mit FileReadLine, FileWriteLine, StringSplit zu handeln.

  • Hab ich was verpasst? also bitte....

    • BugFix
    • 20. November 2019 um 09:23
    Zitat von Kev

    find ich halt schon lächerlich, kann ich gleich in die tonne treten wenn sowas einfaches schon als virus von ALLEM erkannt wird.

    Beschwer dich bei den hirnbefreiten Skriptkiddies, die AutoIt für Virenbastelei etc. pp. missbrauchen! Dadurch werden AutoIt-Exe'n pro Forma als gefährlich eingestuft.

    Ich umgehe das, indem ich meine Skripte nicht kompiliere, sondern mit der AutoIt3.exe aufrufe (diese wird von Virenprogrammen als sauber betrachtet).

    Running Scripts: AutoIt3.exe [/ErrorStdOut] [/AutoIt3ExecuteScript] filename [params ...]

  • Analog-Digital Wandler mit USB Anschluss

    • BugFix
    • 19. November 2019 um 18:07
    Zitat von Oscar

    Darauf ein ganz klares: Jein!

    Ich habe ein JA gefunden! Guckst du. ;)

    Edit:

    Habs mal getestet

    Spoiler anzeigen
    C
    long readVcc() {
      // Read 1.1V reference against AVcc
      // set the reference to Vcc and the measurement to the internal 1.1V reference
      #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
        ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
      #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
        ADMUX = _BV(MUX5) | _BV(MUX0);
      #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
        ADMUX = _BV(MUX3) | _BV(MUX2);
      #else
        ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
      #endif  
    
      delay(2); // Wait for Vref to settle
      ADCSRA |= _BV(ADSC); // Start conversion
      while (bit_is_set(ADCSRA,ADSC)); // measuring
    
      uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
      uint8_t high = ADCH; // unlocks both
    
      long result = (high<<8) | low;
    
      result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
      return result; // Vcc in millivolts
    }
    
    long valVcc = 0; 
    
    void setup() {
      //Serielle Uebertragung 
      Serial.begin(9600); 
    }
    
    void loop() {
      if (Serial.available()) {
        // Vcc messen
        valVcc = readVcc();
        // Wert ausgeben 
        Serial.print("Vcc (mV): "); 
        Serial.println(valVcc);             
      }
      delay(1000);
    }
    Alles anzeigen

    Aber das mochte mein Nano gar nicht. Keinerlei Ausgabe und neue Sketche nimmt er nicht mehr entgegen

    avrdude: stk500_recv(): programmer is not responding

    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x8c

    :rolleyes:

  • Analog-Digital Wandler mit USB Anschluss

    • BugFix
    • 19. November 2019 um 15:58
    Zitat von Oscar

    Nun kommt aber ein Trick des ATmega ins Spiel. Es gibt nämlich durchaus eine interne Referenzspannung (1.1 Volt). Kann man aktivieren mit analogReference(INTERNAL);.

    Aber: Vorsicht!

    Dann darf die Spannung an den analogen Anschlüssen nicht größer als die Referenzspannung werden.

    Du brauchst dann also immer einen Spannungsteiler pro Eingang.

    Gilt das auch für externe Referenzspannung? Habe im Buch noch keinen Verweis darauf gefunden.

  • IniReadSectionNames Grenze

    • BugFix
    • 19. November 2019 um 14:28

    Willst du nur eine bestimmte Anzahl lesen?

    Oder

    Willst du wissen ob es eine Obergrenze an Sektionen gibt?

  • Analog-Digital Wandler mit USB Anschluss

    • BugFix
    • 19. November 2019 um 13:38
    Zitat von Oscar

    Bei analogRead bekommst Du nicht die Spannungswerte, sondern den Sample-Wert (10 Bit, also: 0...1023).

    Wissen ist Macht! :thumbup: (Jetzt bin ich in meinem Arduino-Buch an genau der Stelle angekommen ^^)

    Zitat von Oscar

    Um die Genauigkeit noch zu erhöhen, musst Du die Größe der Versorgungsspannung messen.

    Ich nutze ja den USB-Port zur Spannungsversorgung, je nach Spezifikation also zwischen 4,40V und 5,25V.

    Wenn der Arduino das messen könnte, kann ich die Berechnung ja dort gleich ausführen. - Kann er das?

    Ansonsten bleibt nur manuell messen - das wäre aber sehr nutzerunfreundlich. X/

    Edit:

    Ich habe die Berechnung in die Messreihe eingefügt um durch Anpassen der Versorgungsspannung Übereinstimmung mit meinen Vorgabewerten zu erlangen. Das passt einigermaßen bei 4,48V. Bei gefilterten Messwerten und somit dann auch vollständiger Linearität sollte das OK sein.

    Allerdings kann ich auch mit Ungenauigkeiten leben. Der Prüflauf soll ja nur Deltas finden. Insofern müssen die absoluten Werte nicht zu 100% real sein, es ist wichtig zu sehen, ob über längere Zeit diese Werte sich plötzlich ändern.

    Edit2:

    Hab noch weitergelesen: Referenzspannung ist die Lösung, Da kommt einfach eine CR2032 dran und gut ist. :thumbup:

  • Analog-Digital Wandler mit USB Anschluss

    • BugFix
    • 19. November 2019 um 12:28

    Ich habe jetzt mal zum Testen einen Sensor ausgelötet und mit dem Arduino verbunden. Mit dem folgenden Sketch habe ich mir den Messwert alle 500 ms auf dem Seriellen Monitor ausgeben lassen:

    Sketch
    C
    int analogPin = 7;  // AnaogPin deklarieren  
                           
    float val = 0;   
    int wait = 500;       
    
    void setup()
    {
      //Serielle Uebertragung 
      Serial.begin(9600);         
    }
    
    void loop()
    {
      // AnalogPIN auslesen
      val = analogRead(analogPin);
      // Wert des AnalogPin ausgeben  
      Serial.println(val);             
      delay(wait);
    }
    Alles anzeigen

    Pin 7 habe ich deshalb genommen, weil er direkt neben +5V und GND liegt und somit mit einem 4-PIN Steckverbinder am Einfachsten anzuschliessen war.

    Ich habe testweise in 0,5 mbar Schritten Druck von 4 bis 20 mbar (0,4 bis 0,2 kPa) angelegt. Laut Datenblatt habe ich jetzt Ausgangsspannung von 1,4V bis 3,0V erwartet.

    Übertragen werden aber folgende Werte:

    sensor_output.JPG

    Die Werte sind nahezu linear (ich habe ohne Filterung gemessen, daher sind Schwankungen OK), das passt. Aber woher kommen diese Werte?

Spenden

Jeder Euro hilft uns, Euch zu helfen.

Download

AutoIt Tutorial
AutoIt Buch
Onlinehilfe
AutoIt Entwickler
  1. Datenschutzerklärung
  2. Impressum
  3. Shoutbox-Archiv
Community-Software: WoltLab Suite™