WiseGuy Posted October 26, 2012 Share Posted October 26, 2012 (edited) 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 October 26, 2012 by WiseGuy Link to comment Share on other sites More sharing options...
6105 Posted October 26, 2012 Share Posted October 26, 2012 Maybe you search this? 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 More sharing options...
Jayson Posted October 26, 2012 Share Posted October 26, 2012 (edited) To bypass the limitation : expandcollapse popupFunc _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 October 26, 2012 by Jayson Link to comment Share on other sites More sharing options...
guinness Posted October 26, 2012 Share Posted October 26, 2012 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
BrewManNH Posted October 26, 2012 Share Posted October 26, 2012 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 GudeHow 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 More sharing options...
jchd Posted October 27, 2012 Share Posted October 27, 2012 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
martin Posted October 27, 2012 Share Posted October 27, 2012 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 More sharing options...
Jayson Posted October 28, 2012 Share Posted October 28, 2012 (edited) Jayson,Did you create that yourself? If not then please link to the UDF instead of duplicating code. Thanks.Sorry, I lost the UDF but found it back Edited October 28, 2012 by Jayson Link to comment Share on other sites More sharing options...
WiseGuy Posted October 28, 2012 Author Share Posted October 28, 2012 Thanks all, plenty to read and consider! Much obliged! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now