메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

Autoit ini파일 memory 캐시

데브카페

Autoit ini파일 memory 캐시

  • AutoIt에서 .ini 파일을 메모리에 로드해두고 필요할 때마다 읽어오는 방법은 IniRead 또는 IniReadSection 함수를 활용하여 파일의 내용을 변수에 저장하는 것임.
  • .ini 파일 전체를 메모리에 올려두려면 IniReadSectionNames와 IniReadSection 함수 사용
  • ini 파일의 내용을 메모리에 저장해두면, 파일을 매번 다시 읽지 않고도 데이터를 손쉽게 접근.

.ini 파일을 메모리에 로드한 후 필요할 때마다 데이터를 불러오는 방법

.ini 파일 예시

  • 예를 들어 config.ini 파일이라고 가정
[Settings]
username=admin
password=1234

[Network]
ip=192.168.1.1
port=8080

.ini 파일을 메모리에 로드하고 읽기

#include <Array.au3>
#include <MsgBoxConstants.au3>

Global $g_Config = _ReadIniToMemory("config.ini")

; 예시 조회
MsgBox(0, "MYKEY", _GetConfig("username", "username"))
MsgBox(0, "FONT_NAME", _GetConfig("Network", "ip"))

; ============================
; INI 읽고 메모리에 저장하는 함수
Func _ReadIniToMemory($sFilePath)
    Local $config = ObjCreate("Scripting.Dictionary")
    If Not FileExists($sFilePath) Then
        MsgBox(16, "오류", "INI 파일을 찾을 수 없습니다: " & $sFilePath)
        Exit
    EndIf

    Local $sections = IniReadSectionNames($sFilePath)
    If @error Then Return $config

    For $i = 1 To $sections[0]
        Local $section = $sections[$i]
        Local $keyValues = IniReadSection($sFilePath, $section)
        If @error Then ContinueLoop

        Local $innerDict = ObjCreate("Scripting.Dictionary")
        For $j = 1 To $keyValues[0][0]
            $innerDict.Add($keyValues[$j][0], $keyValues[$j][1])
        Next
        $config.Add($section, $innerDict)
    Next

    Return $config
EndFunc

; 설정값을 조회하는 함수
Func _GetConfig($sSection, $sKey)
    If Not $g_Config.Exists($sSection) Then Return ""
    Local $sectionDict = $g_Config.Item($sSection)
    If Not $sectionDict.Exists($sKey) Then Return ""
    Return $sectionDict.Item($sKey)
EndFunc

Comments