Commit 474022d1 authored by Graham Ranson's avatar Graham Ranson

can now use preference data i think?

parent 727b31ec
......@@ -66,38 +66,54 @@ end
-- @return True if it was loaded, false otherwise.
function Data:load()
-- Load the encoded data from preferences
local encodedData
-- Create a blank contents table
self._contents = {}
if self:isPreferenceStorageEnabled() then
encodedData = system.getPreference( "app", "encodedData", "string" )
else
-- Load te encoded data from preferences
local encodedPreferenceData = system.getPreference( "app", "encodedData", "string" )
-- Check that a path is set and that the file exists
if self._path and puggle.utils:fileExists( self._path, system.DocumentsDirectory ) then
-- Do we have some data?
if encodedPreferenceData then
-- Load the encoded data from a file
encodedData = puggle.utils:readInFile( self._path, system.DocumentsDirectory )
-- Now binary 64 decode it
local data = puggle.utils:b64Decode( encodedPreferenceData )
-- Decode the data from json into a table
local jsonData = puggle.utils:jsonDecode( data ) or {}
for k, v in pairs( jsonData ) do
self._contents[ k ] = v
end
end
-- Pre declare the encoded data
local encodedData
-- Check that a path is set and that the file exists
if self._path and puggle.utils:fileExists( self._path, system.DocumentsDirectory ) then
-- Load the encoded data from a file
encodedData = puggle.utils:readInFile( self._path, system.DocumentsDirectory )
end
if encodedData then
-- Now binary 64 decode it
data = puggle.utils:b64Decode( encodedData )
local data = puggle.utils:b64Decode( encodedData )
-- Decode the data from json into a table
self._contents = puggle.utils:jsonDecode( data ) or {}
local jsonData = puggle.utils:jsonDecode( data ) or {}
for k, v in pairs( jsonData ) do
self._contents[ k ] = v
end
return true
end
-- Create a blank contents table
self._contents = {}
return false
end
......@@ -112,26 +128,20 @@ function Data:save()
-- Now binary 64 encode it
data = puggle.utils:b64Encode( data )
if self:isPreferenceStorageEnabled() then
-- Save out the data to preferences
return system.setPreferences( "app", { encodedData = data } )
-- Save out the data to preferences
local preferenceSaveResult = system.setPreferences( "app", { encodedData = data } )
else
-- Check that we have a path set
if self._path then
-- Save it out to the file
puggle.utils:writeOutFile( data, self._path, system.DocumentsDirectory )
-- Check that we have a path set
if self._path then
return true
-- Save it out to the file
puggle.utils:writeOutFile( data, self._path, system.DocumentsDirectory )
end
return true
end
return false
return preferenceSaveResult
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment