Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!ss.storage.yourSaveData)
- ss.storage.yourSaveData = [{testProp: "test"}];
- //setup subfolder
- customFolder = dirService.get('ProfD', Ci.nsIFile);
- customFolder.append("customFolderName");
- if (!customFolder.exists()){
- file.mkpath(stylesFolder.path);
- };
- // set up for the save json
- var customFile = getPathForStorage();
- if (customFile && customFile.exists()) { // read from customFile
- json = file.read(dirStart.path);
- ss.storage.yourSaveData = JSON.parse(json);
- }else{ // stor to customFile
- writeStorageForAddon();
- };
- function getPathForStorage() {
- var dir = dirService.get('ProfD', Ci.nsIFile);
- dir.append('customFolderName');
- dir.append('customStorage.json');
- return dir;
- };
- function writeStorageForAddon() {
- var stream = file.open(getPathForStorage().path, "w");
- try {
- stream.write(JSON.stringify(ss.storage.yourSaveData));
- } catch (err) {
- stream.close();
- }
- stream.close();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement