GGData is a simple persistent data storage class for the Corona SDK.
local GGData = require( "GGData" )
local box = GGData:new( "sample" )
box:set( "message", "hello, world" )
box.anotherValue = 10
print( box:get( "anotherValue" ) ) -- prints 10
print( box.message ) -- prints 'hello, world'
box:save()
box:setSync( true )
box:setSync( false )
print( box:getSync() )
Enable integrity checking. This should be set BEFORE adding values and needs to be set on each run as the key is not stored ( as it would defeat the point ).
local crypto = require( "crypto" )
box:enableIntegrityControl( crypto.sha512, "SECRET_KEY" )
If you decide to enable integrity checking after you have already set a bunch of values you will want to update all the hashes.
box1:enableIntegrityControl( crypto.sha512, "MONKEY" )
box1:updateAllIntegrityHashes()
When adding or editing values via any of the helper methods integrity data will be stored automatically but if you store the data manually you will also need to add this extra data.
box.newValue = "Hello, World!"
box:storeIntegrityHash( "newValue" )
Verify the integrity of all items. Any values that are detected as wrong will be nilled out. Remember to save after doing this :-)
local corruptEntries = box1:verifyIntegrity()
print( corruptEntries ) -- How many, if any, values were removed due to being different than expected.