I have always been using .ini
files to store information generated by my AutoHotkey scripts, hiding them with FileSetAttrib
afterwards..ini
files are great, my only concern is that the user finds the file and alters the information stored in it.
I remember reading something about .dll
files and Data Streams
, but I do not know where or how to start, as there aren't that many "tutorials" or documentation articles.
How would you guys approach this, when trying to store information that the user should not be able to change?
Encrypting settings with AutoHotkey would not have much point too: the effort is not worth it in this case.
I suggest simply encoding the settings into something not too obvious. Keep in mind that if a user wants to change something, assume that they will be able to (depending on how resourceful they are). Something like Base64 should suffice your needs.
Using this library: base64.ahk
;Say you have a `decodefile()` and `encodefile()` function:
#Include base64.ahk
decodefile(filepath) {
FileRead, rawData, %filepath%
decoded := b64Decode(rawData)
; save decoded file first, in case of crash
tempfile := "tempfile.tmp"
FileDelete, %tempfile%
FileAppend, %decoded%, %tempfile%
; replace original
FileDelete, %filepath%
FileMove, %tempfile%, %filepath%
}
encodefile(filepath) {
FileRead, rawData, %filepath%
encoded := b64Encode(rawData)
; save encoded file first, in case of crash
tempfile := "tempfile.tmp"
FileDelete, %tempfile%
FileAppend, %encoded%, %tempfile%
; replace original
FileDelete, %filepath%
FileMove, %tempfile%, %filepath%
}
;then you can simply read the ini file, like usual.
settingsfile := "myfile.ini"
decodefile(settingsfile )
IniRead, OutputVar, %settingsfile%, section, key
;on exit, save would look like this
settingsfile := "myfile.ini"
encodefile(settingsfile)