Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Class LocalConfigurationOps is responsible for working with our local configuration
- */
- package XXXX.ops {
- import com.ideas2executables.util.C;
- import flash.data.EncryptedLocalStore;
- import flash.utils.ByteArray;
- public class LocalConfigurationOps {
- public static function get():Object {
- var keysBytes:ByteArray = EncryptedLocalStore.getItem("localConfig.keys");
- if(keysBytes == null) {
- return null;
- }
- var data:Object = {};
- var keys:Object = JSON.parse(keysBytes.readUTFBytes(keysBytes.length));
- for(var i:int = 0; i < keys.length; i++) {
- var buffer:ByteArray = EncryptedLocalStore.getItem("localConfig.item." + keys[i]);
- if(buffer == null) {
- data[keys[i]] = null;
- } else {
- data[keys[i]] = JSON.parse(buffer.readUTFBytes(buffer.length));
- }
- }
- return data;
- }
- public static function set(data:Object):void {
- var existing:Object = LocalConfigurationOps.get();
- var k:String = null;
- var buffer:ByteArray = null;
- if(existing != null) {
- for(k in existing) {
- EncryptedLocalStore.removeItem("localConfig.item." + k);
- }
- }
- var keys:Array = [];
- for(k in data) {
- buffer = new ByteArray();
- buffer.writeUTFBytes(JSON.stringify(data[k]));
- EncryptedLocalStore.setItem("localConfig.item." + k, buffer);
- keys.push(k);
- }
- buffer = new ByteArray();
- buffer.writeUTFBytes(JSON.stringify(keys))
- EncryptedLocalStore.setItem("localConfig.keys", buffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement