Jump to content

Ini file storage capacity


WiseGuy
 Share

Recommended Posts

Hi all,

To store data for the functioning of my application, I wish to use the ini-file format but, having experience in other programming languages, I know there's a cap on how much an ini-file can store. So my question is: does AutoIt use the normal Windows ini-format with it's 32kB limit or does it have it's own custom implementation allowing for larger filesizes?

If it does use the default 32kB limit, what would you guys do when you want to store a truckload of information? I'm thinking in that case of using a regular textdoc but not quite sure how to implement that in AutoIt so could you in that case point me in the right direction?

EDIT: In most cases the file won't be extremely large, just containing a set of clicks and settings but since the way I want to implement it (where users can add clicks at will) it can get very large and I want to take that into acount.

Thanks in advance,

WiseGuy

Edited by WiseGuy
Link to comment
Share on other sites

Maybe you search this? :huh:

IniWrite ( "filename", "section", "key", "value" )

Don't have such limitations like 32kB.

[center][font=courier new,courier,monospace]Die die die my darling[/font][/center][center][font=courier new,courier,monospace]Don't utter a single word[/font][/center][center][font=courier new,courier,monospace]Die die die my darling[/font][/center][center][font=courier new,courier,monospace]Just shut your pretty mouth[/font][/center][center][font=courier new,courier,monospace]I'll be seeing you again[/font][/center][center][font=courier new,courier,monospace]I'll be seeing you[/font][/center][center][font=courier new,courier,monospace]In hell[/font][/center]

Link to comment
Share on other sites

To bypass the limitation :

Func _IniReadSectionEx($v_file, $s_section)

If Not $v_file Then Return SetError(-1, 0, 0)

Local $f_exists = FileExists($v_file)

Local $i_size, $a_secread

If $f_exists Then
$i_size = FileGetSize($v_file) / 1024

; if the file is smaller than 32kb, no need for regex
If $i_size <= 31 Then
$a_secread = IniReadSection($v_file, $s_section)
If @error Then Return SetError(@error, 0, 0)
If Not IsArray($a_secread) Then Return SetError(-2, 0, 0)
Return $a_secread
EndIf
EndIf

Local $s_fread
If Not $f_exists Then
; string of data was passed
$s_fread = $v_file
Else
$s_fread = FileRead($v_file)
EndIf

; data between sections or till end of file
Local $s_datapatt = "(?is)(?:^|v)(?!;|#)h*[h*Q"
$s_datapatt &= $s_section
$s_datapatt &= "Eh*]h*v+(.*?)(?:z|vh*[)"
Local $a_data = StringRegExp($s_fread, $s_datapatt, 1)
If @error Then Return SetError(-3, 0, 0)

; sanity check for inf people
If Not StringInStr($a_data[0], "=", 1, 1) Then
Return SetError(-4, 0, 0)
EndIf

; since we stop at cr/lf then lets just split
Local $a_lines
If StringInStr($a_data[0], @CRLF, 1, 1) Then
$a_lines = StringSplit(StringStripCR($a_data[0]), @LF)
ElseIf StringInStr($a_data[0], @LF, 1, 1) Then
$a_lines = StringSplit($a_data[0], @LF)
Else
$a_lines = StringSplit($a_data[0], @CR)
EndIf

; prevent capturing commented keys
Local $a_key, $a_value
Local $s_keypatt = "h*(?!;|#)(.*?)h*="
Local $s_valpatt = "h*=h*(.*)"
Local $a_secs[$a_lines[0] + 1][2], $i_add = 0

For $iline = 1 To $a_lines[0]

$a_key = StringRegExp($a_lines[$iline], $s_keypatt, 1)
If @error Then ContinueLoop

$s_valpatt = "h*=h*(.*)"

$a_value = StringRegExp($a_lines[$iline], $s_valpatt, 1)
If @error Then ContinueLoop

If StringLeft($a_key[0], 1) = '"' And StringRight($a_key[0], 1) = '"' Then
$a_key[0] = StringTrimLeft(StringTrimRight($a_key[0], 1), 1)
EndIf
If StringLeft($a_value[0], 1) = '"' And StringRight($a_value[0], 1) = '"' Then
$a_value[0] = StringTrimLeft(StringTrimRight($a_value[0], 1), 1)
EndIf

$i_add += 1
$a_secs[$i_add][0] = $a_key[0]
$a_secs[$i_add][1] = $a_value[0]
Next

If Not $i_add Then Return SetError(-5, 0, 0)

; cleanup return array
ReDim $a_secs[$i_add + 1][2]
$a_secs[0][0] = $i_add

Return $a_secs
EndFunc   ;==>_IniReadSectionEx

Func _IniReadEx($v_file, $s_section, $s_key, $v_default = -1)

If Not $v_file Then Return SetError(-1, 0, 0)

If $v_default = -1 Or $v_default = Default Then
$v_default = ""
EndIf

Local $f_exists = FileExists($v_file)

Local $i_size, $s_read

If $f_exists Then
$i_size = FileGetSize($v_file) / 1024

; if the file is smaller than 32kb, no need for regex
If $i_size <= 31 Then
$s_read = _IniReadEx($v_file, $s_section, $s_key, $v_default)
Return $s_read
EndIf
EndIf

Local $s_fread
If Not $f_exists Then
; string of data was passed
$s_fread = $v_file
Else
$s_fread = FileRead($v_file)
EndIf

; data between sections or till end of file
Local $s_datapatt = "(?is)(?:^|v)(?!;|#)h*[h*Q"
$s_datapatt &= $s_section
$s_datapatt &= "Eh*]h*v+(.*?)(?:z|vh*[)"
Local $a_data = StringRegExp($s_fread, $s_datapatt, 1)
If @error Then Return SetError(-2, 0, 0)

; sanity check for inf people
If Not StringInStr($a_data[0], "=", 1, 1) Then
Return SetError(-3, 0, 0)
EndIf

; since we stop at cr/lf then lets just split
Local $a_lines
If StringInStr($a_data[0], @CRLF, 1, 1) Then
$a_lines = StringSplit(StringStripCR($a_data[0]), @LF)
ElseIf StringInStr($a_data[0], @LF, 1, 1) Then
$a_lines = StringSplit($a_data[0], @LF)
Else
$a_lines = StringSplit($a_data[0], @CR)
EndIf

; prevent capturing commented keys
Local $a_key, $a_value, $s_ret
Local $s_keypatt = "h*(?!;|#)(.*?)h*="
Local $s_valpatt = "h*=h*(.*)"

For $iline = 1 To $a_lines[0]

$a_key = StringRegExp($a_lines[$iline], $s_keypatt, 1)
If @error Then ContinueLoop

If StringLeft($a_key[0], 1) = '"' And StringRight($a_key[0], 1) = '"' Then
$a_key[0] = StringTrimLeft(StringTrimRight($a_key[0], 1), 1)
EndIf

If $a_key[0] <> $s_key Then ContinueLoop

$s_valpatt = "h*=h*(.*)"

$a_value = StringRegExp($a_lines[$iline], $s_valpatt, 1)
If @error Then ContinueLoop

If StringLeft($a_value[0], 1) = '"' And StringRight($a_value[0], 1) = '"' Then
$a_value[0] = StringTrimLeft(StringTrimRight($a_value[0], 1), 1)
EndIf

$s_ret = $a_value[0]
ExitLoop
Next

If Not $s_ret Then Return $v_default

Return $s_ret
EndFunc   ;==>_IniReadEx
Edited by Jayson
Link to comment
Share on other sites

Jayson,

Did you create that yourself? If not then please link to the UDF instead of duplicating code. Thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

The only 32K limit that applies to INI files is reading a section, the ini file itself can be much larger.

Although, if you have a 32Kb section, it might be a better idea to split it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Another not-as-complicated-as-it-sounds way is to use a database. The easiest to setup and use is SQLite, which enjoys standard UDF support.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

SmOke_N wrote a UDF replacement for the inifile functions which does not have the 32k limit.

You can find it in

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...