Skip to content

Commit

Permalink
Migrate old cache to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ramvibhakar committed Aug 2, 2015
1 parent 99f454d commit b813feb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<![CDATA[
import sg.edu.smu.ksketch2.KSketchAssets;
import sg.edu.smu.ksketch2.KSketch_Config;
import sg.edu.smu.ksketch2.utils.KSketch_MigrateCache;
import sg.edu.smu.ksketch2.utils.KSketch_Preference;
private var timer:Timer;
Expand Down Expand Up @@ -51,6 +52,9 @@
canvasCover.visible = true;
stage.setAspectRatio("landscape");
//Migrate old cache to new cache structure if it exists
var migrations:KSketch_MigrateCache = new KSketch_MigrateCache();
migrations.migrateData();
if (!KSketch_Config.isMobile && !KSketch_Preference.isPrefsAvailable()) {
navigator.pushView(KSketch_LicenseAggrement);
} else {
Expand Down
32 changes: 32 additions & 0 deletions KSKInterface/src/sg/edu/smu/ksketch2/utils/KSketch_MigrateCache.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Created by ramvibhakar on 02/08/15.
*/
package sg.edu.smu.ksketch2.utils {
import flash.net.SharedObject;
import com.adobe.serialization.json.JSON;
import sg.edu.smu.ksketch2.canvas.controls.KSketch_CacheControl;

public class KSketch_MigrateCache {
private var _mySOV1:SharedObject = SharedObject.getLocal("mydata");
private var _cacheControl:KSketch_CacheControl = new KSketch_CacheControl(null);
public function KSketch_MigrateCache() {
}
public function migrateData(){
if(_mySOV1.data){
if(_mySOV1.data.userSketch) {
var obj:Object = com.adobe.serialization.json.JSON.decode(_mySOV1.data.userSketch, true);
buildCacheV2(obj.sketches)
}
}
}
private function buildCacheV2(sketches:Array){
if(sketches){
for(var i:int=0; i<sketches.length;i++){
_cacheControl.addToCache(sketches[i]);
}
_mySOV1.clear();
}

}
}
}

0 comments on commit b813feb

Please sign in to comment.