Advertisement
Guest User

firefox, backup simple storage

a guest
Apr 30th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (!ss.storage.yourSaveData)
  2.     ss.storage.yourSaveData = [{testProp: "test"}];
  3.  
  4. //setup subfolder
  5. customFolder = dirService.get('ProfD', Ci.nsIFile);
  6. customFolder.append("customFolderName");
  7. if (!customFolder.exists()){
  8.     file.mkpath(stylesFolder.path);
  9. };
  10. // set up for the save json
  11. var customFile = getPathForStorage();
  12. if (customFile && customFile.exists()) {  // read from customFile
  13.     json = file.read(dirStart.path);
  14.     ss.storage.yourSaveData = JSON.parse(json);
  15. }else{  // stor to customFile
  16.     writeStorageForAddon();
  17. };
  18.  
  19. function getPathForStorage() {
  20.     var dir = dirService.get('ProfD', Ci.nsIFile);
  21.     dir.append('customFolderName');
  22.     dir.append('customStorage.json');
  23.     return dir;
  24. };
  25.  
  26. function writeStorageForAddon() {
  27.     var stream = file.open(getPathForStorage().path, "w");
  28.     try {
  29.         stream.write(JSON.stringify(ss.storage.yourSaveData));
  30.     } catch (err) {
  31.         stream.close();
  32.     }
  33.     stream.close();
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement