Jump to content
Jefrey

storage.au3 - localStorage and sessionStorage

Recommended Posts

Needed a way to store global temporary & permanent information and came up with this.

This is inspired by NodeJS's store and store2 packages, as well as W3 specs' localStorage and sessionStorage, offering multiple ways of usage.

This is not related to any browser's storage, nor will allow you to access or modify browsers storage - although this is possible and not a hard task, this is not what this UDF is intended to do.

This UDF offers functions for temporary storage (that gets cleaned up once the application is shutdown) that is kept on memory using ScriptingDictionary, as well as for permanent storage, that is saved on the harddisk as an encrypted file.

sessionStorage (temporary storage)

It's useful to keep application state and temporary settings accessible by any part of your script (although it could also be done with a global variable, I still prefer this method).

You have multiple ways, at your choice, to:

; add or modify a key
sessionStorage("foo", "bar")
store("foo", "bar")
sessionStorage_set("foo", "bar")
sessionStorage_setItem("foo", "bar")

; read a key (returns false if key does not exist)
$read = sessionStorage("foo")
$read = store("foo")
$read = sessionStorage_get("foo")
$read = sessionStorage_getItem("foo")

; delete a key
sessionStorage_remove("foo")

; delete all keys
sessionStorage_clear()
sessionStorage_clearAll()

localStorage (permanent storage)

It's useful to store user-defined settings.

; initialize
; this is optional, but allows you to control
; how things are going to be saved
localStorage_startup([file where you want the settings to be saved], [crypt password])
; by default, if not supplied, if supplied the "Default" keyword (or if you dont initialize),
; the file will be a random-named file (based on @ScriptFullPath) at user's %APPDATA%
; and the password will also be based on @ScriptFullPath
; you can set only the crypt password if you want:
; localStorage_startup(Default, "mypassword")

; the usage is the same as sessionStorage

; add or modify a key
localStorage("foo", "bar")
store2("foo", "bar") ; notice the '2'
localStorage_set("foo", "bar")
localStorage_setItem("foo", "bar")

; read a key (returns false if key does not exist)
$read = localStorage("foo")
$read = store2("foo")
$read = localStorage_get("foo")
$read = localStorage_getItem("foo")

; delete a key
localStorage_remove("foo")

; delete all keys
localStorage_clear()
localStorage_clearAll()

Download

Edited by Jefrey

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path Random stuff Super Mario beep sound your ears will hurt

 

Share this post


Link to post
Share on other sites

Interesting Idea have you done any speed comparisons between global variables and using your method (once initialized)?

I like the Idea of being able to save / load the whole shebang  encrypted in one shot

Edited by Bilgus

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

    • By vargheseg
      I am new to AutoIT but I do use Sikuli.  Decided to use AutoIT for  this project as all  the required can be created in an .exe file, does not  need Java like Sikuli.
      Also  which can be pushed to tool bar of Windows 10 desktop.
      Our users will interact with a client/server application and normally work on dual screen. The script needs to detect the c/s application from the dual screen,  needs to do three mouse clicks based of image/pixel comparison, will need to wait till the  click object is available and then finally take screen capture  of the top 40 rows  and save the .jpeg file to  windows file share location.
      once the file save is completed,  pop up message - the screen capture is completed. Then the users can do their regular work.
      Potentially  other factor that will play are the screen resolution.
      Can anyone guide me to some relevant scripts already in the forum. In the meantime I am learning  the basics of the  tool.
       
      Appreciate feedback and any help
      George V
       
       
    • By Rhidlor
      I don't have any experience compiling AutoIt scripts or know of any best practices regarding said scripts so I was wondering, what are some of the options for passing data to complied scripts? Here's an example of what I mean by "option": Writing data to a text file, then running a script which reads the data from that text file.
      Thanks!
      I apologize if this topic is a little lackluster
    • By smud
      Currently, I'm working on a program that will display Dialog boxes with either Yes or No.
      For each dialog, I reward the user with X amount of Credits.
      I'm hoping to output the amount of credits to a cell in a column (there will be 20 different columns).
      It will only post to a row that is equal to today's date (first column). If no row exists yet with the current date, it will start a new row.
      Any suggestions?
      Thank you
    • By natedog102
      This small UDF helps you save any text to speech to a .wav file. 
      UDF:
      #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #include-once ; #INDEX# ======================================================================================================================= ; Title .........: _TTStoWav() ; AutoIt Version : 3.3.14.2 ; Language ......: English ; Author(s) .....: natedog102 ; Modifiers .....: ; Forum link ....: https://www.autoitscript.com/forum/topic/191573-tts-text-to-speech-to-wav-file-using-sapi/ ; Description ...: TTS to .wav file using SAPI ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: _TTStoWav ; Description ...: TTS to .wav file using SAPI ; Syntax.........: _TTStoWav($sText, $sLocation[, $iRate = 1[, $iVolume = 100]]) ; Parameters ....: $sText - String you want converted to a .wav ; $sLocation - Save location + file name, example: "C:\folder\sample.wav" ; $iRate - TTS speak rate between -10 and 10 ; $iVolume - Volume of the TTS between 0 and 100 ; Return values .: Success - Returns one ; Failure - Returns zero ; Author ........: natedog102 ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TTStoWav($sText, $sLocation, $iRate = 1, $iVolume = 100) $oFileStream = ObjCreate("SAPI.SpFileStream") If @error Then Return 0 EndIf $oFileStream.Format.Type = 39 $oFileStream.Open($sLocation, 3) $oSpeech = ObjCreate('SAPI.SpVoice') If @error Then Return 0 EndIf $oSpeech.AudioOutputStream = $oFileStream $oSpeech.Rate = $iRate $oSpeech.Volume = $iVolume $oSpeech.Speak($sText, 3) $oSpeech.WaitUntilDone(10000) $oFileStream.Close() Return 1 EndFunc ;==>_TTStoWav And here's example usage:
      _TTStoWav("This is a test", "C:\folder-must-exist\sample2.wav") I have never made a UDF before so I don't know if I coded it correctly or if I followed all the recommended guidelines. Apologies if I haven't.
      DOWNLOAD:
       _TTStoWav.au3
    • By Shirdish_chakravarthi
      in need the path/text present int above shown input box to be copied or retrieved into a variable .. how can i do that?
       
      Thanks
       
×
×
  • Create New...