2 * Ext JS Library 0.30
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.air.FileProvider
\r
11 * @extends Ext.state.Provider
\r
13 * An Ext state provider implementation for Adobe AIR that stores state in the application
\r
14 * storage directory.
\r
17 * @param {Object} config
\r
19 Ext.air.FileProvider = function(config){
\r
20 Ext.air.FileProvider.superclass.constructor.call(this);
\r
22 this.defaultState = {
\r
31 Ext.apply(this, config);
\r
32 this.state = this.readState();
\r
34 var provider = this;
\r
35 air.NativeApplication.nativeApplication.addEventListener('exiting', function(){
\r
36 provider.saveState();
\r
40 Ext.extend(Ext.air.FileProvider, Ext.state.Provider, {
\r
42 * @cfg {String} file
\r
43 * The file name to use for the state file in the application storage directory
\r
45 file: 'extstate.data',
\r
48 * @cfg {Object} defaultState
\r
49 * The default state if no state file can be found
\r
52 readState : function(){
\r
53 var stateFile = air.File.applicationStorageDirectory.resolvePath(this.file);
\r
54 if(!stateFile.exists){
\r
55 return this.defaultState || {};
\r
58 var stream = new air.FileStream();
\r
59 stream.open(stateFile, air.FileMode.READ);
\r
61 var stateData = stream.readObject();
\r
64 return stateData || this.defaultState || {};
\r
68 saveState : function(name, value){
\r
69 var stateFile = air.File.applicationStorageDirectory.resolvePath(this.file);
\r
70 var stream = new air.FileStream();
\r
71 stream.open(stateFile, air.FileMode.WRITE);
\r
72 stream.writeObject(this.state);
\r