Sign in to follow this  
Followers 0
AZJIO

_Setting_... Choice of storage options, registry or ini-file

3 posts in this topic

#1 ·  Posted (edited)

Setting.7z

_Setting.au3 (pastebin.com)

Allows you to choose where to save the program settings in the registry or ini file

_Setting_Read

_Setting_Write

_Setting_Delete

_Setting_ReadSection

_Setting_ReadSectionNames

_Setting_WriteSection

_Setting_RenameSection

_Setting_MigrateIniToReg

_Setting_MigrateRegToIni

#include <_Setting.au3>
#include <Array.au3>

$TrReg = 0
$sPath_ini = @ScriptDir&'MySoft.ini'
$sKey = 'HKEY_CURRENT_USERSoftwareMySoft'
Global $setting[4]

If FileExists($sPath_ini) Then
$TrReg = 0
_ReadSet($sPath_ini, $TrReg)
Else
If _Reg_Exists($sKey) Then
$TrReg = 1
_ReadSet($sKey, $TrReg)
Else
If MsgBox(4, 'INI or Registry', 'Save in the INI?') = 6 Then
$TrReg = 0
_DefWriteSet($sPath_ini, $TrReg)
Else
$TrReg = 1
_DefWriteSet($sKey, $TrReg)
EndIf
EndIf
EndIf

_ArrayDisplay($setting, 'Array')

Func _ReadSet($sPath, $TrReg)
$setting[0] = _Setting_Read($sPath, 'section1', 'key1', 'default1', $TrReg)
$setting[1] = _Setting_Read($sPath, 'section1', 'key2', 'default2', $TrReg)
$setting[2] = _Setting_Read($sPath, 'section2', 'key1', 'default3', $TrReg)
$setting[3] = _Setting_Read($sPath, 'section2', 'key2', 'default4', $TrReg)
EndFunc

Func _DefWriteSet($sPath, $TrReg)
_Setting_Write($sPath, 'section1', 'key1', '111', $TrReg)
_Setting_Write($sPath, 'section1', 'key2', '22', $TrReg)
_Setting_Write($sPath, 'section2', 'key1', '3333', $TrReg)
_Setting_Write($sPath, 'section2', 'key2', '4', $TrReg)
$setting[0] = '111'
$setting[1] = '22'
$setting[2] = '3333'
$setting[3] = '4'
EndFunc

Func _Reg_Exists($key)
Local $Err = RunWait('reg query "' & $key & '"', '', @SW_HIDE)
If $Err = 0 Then
Return 1
Else
Return 0
EndIf
EndFunc[/code]

[code='autoit']#include <_Setting.au3>
#include <Array.au3>
$TrReg = 1
$sPath = 'HKEY_CURRENT_USERSoftwareAutoIt v3'
$Array = _Setting_ReadSection($sPath, 'AU3Info', $TrReg)
_ArrayDisplay($Array, 'ReadSection')[/code]

[code='autoit']#include <_Setting.au3>
#include <Array.au3>
$TrReg = 1
$sPath = 'HKEY_CURRENT_USERSoftware7-Zip'
$Array = _Setting_ReadSectionNames($sPath, $TrReg)
_ArrayDisplay($Array, 'SectionNames')[/code]

[code='autoit']#include <_Setting.au3>
$sPath = @ScriptDir & 'MySoft.ini'
$sKey = 'HKEY_CURRENT_USERSoftwareAutoIt v3'
_Setting_MigrateRegToIni($sKey, $sPath)
Edited by AZJIO

Share this post


Link to post
Share on other sites



Update

Added

_Setting_WriteSection

_Setting_RenameSection

Taken into account behavior with quotes

Share this post


Link to post
Share on other sites

Need advice:

Want to make $ iReg = 0 first

_Setting_ReadSection($sPath, $sSection, $iReg = 0)
_Setting_ReadSection($iReg, $sPath, $sSection)

Share this post


Link to post
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
Sign in to follow this  
Followers 0