Jump to content
TheSaint

Virtual INI UDF & ASCII Checker

Recommended Posts

TheSaint

I had a need, and so I developed.

Before I did that though, I did a quick search of the forum, and found a few things, but none seemed to suit what I really wanted ... though to be honest, I did not investigate them deeply or search extensively. In any case, I am not very good at modifying the code of others, nor do I enjoy doing so, so in the end I decided it was best to start from scratch ... re-inventing the wheel perhaps, but a wheel I feel a certain degree of comfort with. I also thought about Maps, but don't know enough.

_IniString Functions (was Ini_InMem)

Ini in memory

Settings INI - Read/Write once to the disk

INI File Processing Functions

... sure to be others.

As with all my stuff, feel free to use (no guarantees) or modify ... just give me credit where due.

I always go for the quick & simple approach, as those who know me here, are well aware, so without a doubt, my code could be improved - sped up, RegExp used, etc. So feel free to do that, and convert into a proper UDF, if you want, following best practices etc, as I am sure others will appreciate it.

Quote

Some background.
I have been a long time user and fan of INI files. I realize, they have their issues, and in many cases you are no doubt better off using XML, SQL or other (be assured though, they all have their own issues). But if your needs are simple, and you want quick coding and processing, then INI files are hard to beat.

A few years ago, while trying to perfect the INI elements of a project I was working on, I discovered that quotes (double & single) get stripped if a value is encapsulated in them. That seemed stupid to me, and I wondered if AutoIt was responsible or just some quirk etc of Windows (Microsoft), and why. I don't recall ever getting a satisfactory explanation at the time, after starting a topic about it (in MVP Chat I think), though it was made clear it was a Windows issue. Later, I discovered via Wikipedia, that quotes were used to encapsulate 'escape characters' and then stripped after doing their job. EDIT - By the way, I think it pretty lame of Microsoft to use both Single Quotes (apostrophe) and Double Quotes to do that. One of either would surely have been sufficient, leaving the other as a replacement possibility for the other. I do understand that INI files were initially conceived as settings files, but really that issue should have been fixed at a later date, especially as they themselves started using INI files for other things (i.e. cdplayer.ini), and where text encapsulated by quotes could become quite likely.

INI file (Wikipedia)

Recently, I have come upon a need to extract data from an approximately 50 Mb downloaded Index file, just extracting the few elements I need, and storing them in an INI file. It is quite a time consuming process, especially on my underpowered Netbook, which is where I am using the program I built. I have been considering ways to speed up things. Two good sounding methods, out of several possibles, have come to mind - 1) RAM Disk and 2) Virtual INI processing. That last being a better option, when sharing code (program) with others.

Another method, which I am currently using, that did give me some measurable benefit, was to download the almost 50 Mb Index file in Stages (i.e. 30 x 1.4 Mb roughly), extracting data from each in turn. I have also considered extracting to 10 (or 11) separate INI files, rather than the single large INI file (4~5 Mb), as things noticeably slow up as the INI file increases in size ... obviously due to writing time.

I can't really speed up the extraction process, but that last method may speed up the writing stage.  However, it would require significant program changes, and perhaps not gain me much benefit. To complicate things, there are too many Section names (Index ID's) for the IniReadSectionNames command, so I have had to split them off into their own (read/write) line-by-line index file, and create code to deal with duplicates. When read, Index ID's and Titles populate a Listbox control in a user GUI.

So at this point in time, it seems best to use the Virtual INI approach to gain a significant reduction in time taken. For my own specific use, with my slow Netbook, I may also use a RAM Disk.

Due to the aforementioned INI issues, and lack of available specific data, probably because it is always  program concentric, I have created an ASCII Checker program, which I guess you can say, is AutoIt  concentric. Because others may also find it handy, I am providing it here. NOTE - As yet, I am only aware that Escape characters exist, but have not investigated or catered for them in any way.

ASCII Checker.zip

ASCchecker.png

The Virtual_INI_UDF is still a work in progress, though I have done most of the functions now, with the working but incomplete _Ini_Test function, still requiring changes etc from the information gleaned by the ASCII Checker program.

Here's something to play with meanwhile.

Updated files (24th February 2017)

Virtual_INI_UDF.au3  NEW

Example.au3 (23rd February 2017)

All pretty basic, but managed to load my 4 Mb INI file (seemingly ok, but took a few seconds) ... though I have only worked with much smaller testing ones so far.

P.S. While I have done a fair amount of testing, it has been pretty basic, and mostly limited to the examples provided. Testing has definitely not been extensive.

Spoiler

Previous Downloads

17-02-2017 - UDF (12) + Example (9)
21-02-2017 - UDF (10) + Example (5)
23-02-2017 - UDF (6)

 

Edited by TheSaint
Updates
  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
TheSaint

Well I finally got some time free to do a bit more work on this project. Files at first post, were removed and updated. INI files no longer required, as they get created as they are needed during the order of Examples.

I have rewritten some of it, and finished a few more functions, added one or two, plus pretty much rewritten all the Examples.

I've also been a good boy, and added in lots of short comments.

Current status is as follows.

FUNCTIONS
_Ini_AddUpdate($ini_virtual, $section, $key, $value = "")
_Ini_Close($ini_virtual)
_Ini_Create($section, $key, $value = "")
_Ini_Inform($ini_virtual, $show = "")
_Ini_Open($ini_fle)
_Ini_Read($ini_virtual, $section, $key = "", $report = "")
_Ini_Remove($ini_virtual, $section, $key = "")
_Ini_Rename($ini_virtual, $section, $new, $key = "")
_Ini_Save($ini_virtual, $ini_fle)
_Ini_Show($ini_virtual, $section = "")
_Ini_WriteSection($ini_virtual, $data, $section, $replace = 0)

NOT YET FULLY IMPLEMENTED
_Ini_Test($ini_virtual, $section, $key, $value, $new, $job)

NOT YET IMPLEMENTED
_Ini_CopySection($ini_virtual, $section, $newsect)
_Ini_Sections($ini_virtual)
_Ini_Log (maybe)

 

Edited by TheSaint
  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
TheSaint

Files at first post, were updated.

I have rewritten some of it again, and finished two more functions (one a new one), plus rewritten some aspects of most Examples.

Basically, I rewrote some code, because I felt some aspects should not be solely reliant on square bracket detection, but also include Chr(13) and Chr(10) in the mix, so as not to leave any room for ambiguity.

Current status is as follows.

FUNCTIONS
_Ini_AddUpdate($ini_virtual, $section, $key, $value = "")
_Ini_Close($ini_virtual)
_Ini_Create($section, $key, $value = "")
_Ini_Inform($ini_virtual, $show = "")
_Ini_KeyNames($ini_virtual, $section)  NEW
_Ini_Open($ini_fle)
_Ini_Read($ini_virtual, $section, $key = "", $report = "")
_Ini_Remove($ini_virtual, $section, $key = "")
_Ini_Rename($ini_virtual, $section, $new, $key = "")
_Ini_Save($ini_virtual, $ini_fle)
_Ini_SectionNames($ini_virtual) RENAMED & COMPLETED
_Ini_Show($ini_virtual, $section = "", $title = "") CHANGED - TITLE parameter added
_Ini_WriteSection($ini_virtual, $data, $section, $replace = 0)

NOT YET FULLY COMPLETED (but working)
_Ini_Test($ini_virtual, $section, $key, $value, $new, $job) FURTHER IMPLEMENTATIONS

NOT YET IMPLEMENTED
_Ini_CopySection($ini_virtual, $section, $newsect) (maybe)
_Ini_Log (maybe)

NOTES - It has occurred to me, that being virtual, I could add a switch (flag), that allows for a virtual INI that doesn't conform entirely to the standard file based one. For example, quotes could be allowed ... remembering that any such virtual INI written to file, should really only ever be used in a virtual environment (read & written to that way). I haven't thought too deeply about the benefits etc yet, but I believe you could think of it, as almost another type of database (if extremely similar to INI files). To reduce confusion or problems, another file type could be specified (i.e. .vini or .virt etc).

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
TheSaint

While incorporating this into the program, that essentially inspired me to create the UDF, I decided I really should give most of the parameter variables a more unique name, so I have added 'virtual_' to them (i.e. 'virtual_section, virtual_key, etc'.

So the UDF file has been updated at first post. Example remains unchanged.

As for the benefit I was hoping for with my program, I actually got the opposite in the area that really mattered most. I did gain a 36 second benefit writing to a small INI file (creating virtually then dumping to file), that was around 100 Kb's or so, but as the virtual INI grew in size, the benefit was lost, and before long was worse than using regular INI functions. Especially as the eventual INI file was gonna be around 4~5 Mb's. Most disappointing.

So unless someone else has a great way to speed things up (beyond the limit of my coding experience), then this project, while useful perhaps for some smaller applications, is dead and buried as far as I am concerned. I suspect there are ways to speed things up, but I just don't have that knowledge or skill.

I was hoping to reduce a two hour process on my Netbook (using regular INI functions), to something a bit quicker, but at the two and a half hour mark (with the virtual functions), and not quite a third done, it was clear it was going to extend out to 6 hours plus. And it was obvious that my Netbook had been working too hard, and was running slow and quite hot, even causing the fan to play up a little later, requiring a shutdown and a rest.

So I guess it is Plan B now ... RAM Disk. Or just live with things as they are. Certainly once I upgrade the Netbook to a more powerful PC, the times will be much shorter. The current maximum 2 Gb of RAM is not much.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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

  • Similar Content

    • xtcislove
      By xtcislove
      Hello,
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Title
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 
      -Transparency

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

       
       
      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")  
      ScalingMessageBox.au3
    • Gowrisankar
      By Gowrisankar
      Dear members, 
      I am working on a project where, emails from outlook are to be read and moved to various folders within the mailbox, based on the content of the emails.
      I used the below code for moving mails. It works fine when I run it against individual mail ids. But when I run it on Shared mailbox, the mails are not moved to respective folders.
      _OL_ItemMove($oOutlook, $sEntryId, Default, $sDestinationFolder) The value of $sEntryId is saved in an excel report initially. The current process reads the $sEntryId from the excel and passes it to "_OL_ItemMove" statement.
      Requesting the guidance of the forum members in this issue.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
    • ScriptJunky
      By ScriptJunky
      I noticed a lack of a constants file for _WinAPI_GetSystemMetrics() so I made this for anyone who wants to add it to their library. Enjoy!  (file attached below)
      #include-once ; #INDEX# ======================================================================================================================= ; Title .........: WinAPI GetSystemMetrics Constants ; AutoIt Version : 3.3.14.5 ; Language ......: English ; Description ...: Constants for _WinAPI_GetSystemMetrics(). ; Author(s) .....: ScriptJunky ; =============================================================================================================================== ; #CONSTANTS# =================================================================================================================== ; _WinAPI_GetSystemMetrics() Global Const $ARRANGE = 56 Global Const $CLEANBOOT = 67 Global Const $CMONITORS = 80 Global Const $CMOUSEBUTTONS = 43 Global Const $CONVERTIBLESLATEMODE = 0x2003 Global Const $CXBORDER = 5 Global Const $CXCURSOR = 13 Global Const $CXDLGFRAME = 7 Global Const $CXDOUBLECLK = 36 Global Const $CXDRAG = 68 Global Const $CXEDGE = 45 Global Const $CXFIXEDFRAME = 7 Global Const $CXFOCUSBORDER = 83 Global Const $CXFRAME = 32 Global Const $CXFULLSCREEN = 16 Global Const $CXHSCROLL = 21 Global Const $CXHTHUMB = 10 Global Const $CXICON = 11 Global Const $CXICONSPACING = 38 Global Const $CXMAXIMIZED = 61 Global Const $CXMAXTRACK = 59 Global Const $CXMENUCHECK = 71 Global Const $CXMENUSIZE = 54 Global Const $CXMIN = 28 Global Const $CXMINIMIZED = 57 Global Const $CXMINSPACING = 47 Global Const $CXMINTRACK = 34 Global Const $CXPADDEDBORDER = 92 Global Const $CXSCREEN = 0 Global Const $CXSIZE = 30 Global Const $CXSIZEFRAME = 32 Global Const $CXSMICON = 49 Global Const $CXSMSIZE = 52 Global Const $CXVIRTUALSCREEN = 78 Global Const $CXVSCROLL = 2 Global Const $CYBORDER = 6 Global Const $CYCAPTION = 4 Global Const $CYCURSOR = 14 Global Const $CYDLGFRAME = 8 Global Const $CYDOUBLECLK = 37 Global Const $CYDRAG = 69 Global Const $CYEDGE = 46 Global Const $CYFIXEDFRAME = 8 Global Const $CYFOCUSBORDER = 84 Global Const $CYFRAME = 33 Global Const $CYFULLSCREEN = 17 Global Const $CYHSCROLL = 3 Global Const $CYICON = 12 Global Const $CYICONSPACING = 39 Global Const $CYKANJIWINDOW = 18 Global Const $CYMAXIMIZED = 62 Global Const $CYMAXTRACK = 60 Global Const $CYMENU = 15 Global Const $CYMENUCHECK = 72 Global Const $CYMENUSIZE = 55 Global Const $CYMIN = 29 Global Const $CYMINIMIZED = 58 Global Const $CYMINSPACING = 48 Global Const $CYMINTRACK = 35 Global Const $CYSCREEN = 1 Global Const $CYSIZE = 31 Global Const $CYSIZEFRAME = 33 Global Const $CYSMCAPTION = 51 Global Const $CYSMICON = 50 Global Const $CYSMSIZE = 53 Global Const $CYVIRTUALSCREEN = 79 Global Const $CYVSCROLL = 20 Global Const $CYVTHUMB = 9 Global Const $DBCSENABLED = 42 Global Const $DEBUG = 22 Global Const $DIGITIZER = 94 Global Const $IMMENABLED = 82 Global Const $MAXIMUMTOUCHES = 95 Global Const $MEDIACENTER = 87 Global Const $MENUDROPALIGNMENT = 40 Global Const $MIDEASTENABLED = 74 Global Const $MOUSEPRESENT = 19 Global Const $MOUSEHORIZONTALWHEELPRESENT = 91 Global Const $MOUSEWHEELPRESENT = 75 Global Const $NETWORK = 63 Global Const $PENWINDOWS = 41 Global Const $REMOTECONTROL = 0x2001 Global Const $REMOTESESSION = 0x1000 Global Const $SAMEDISPLAYFORMAT = 81 Global Const $SECURE = 44 Global Const $SERVERR = 289 Global Const $SHOWSOUNDS = 70 Global Const $SHUTTINGDOWN = 0x2000 Global Const $SLOWMACHINE = 73 Global Const $STARTER = 88 Global Const $SWAPBUTTON = 23 Global Const $TABLETPC = 86 Global Const $XVIRTUALSCREEN = 76 Global Const $YVIRTUALSCREEN = 77  
      WinAPISystemMetricsConstants.au3
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management
       
      Notes:
      Fixes WinGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.
×