|
26 | 26 | toURL: function(value) {
|
27 | 27 | return "data:text/plain;base64," + Global.Utils.encodeBase64(value || "");
|
28 | 28 | }
|
29 |
| - } |
| 29 | + }; |
30 | 30 |
|
31 | 31 | function LocalStorage() {
|
32 | 32 | this.storage = window.localStorage;
|
|
41 | 41 | },
|
42 | 42 |
|
43 | 43 | saveFileSystem: function() {
|
| 44 | + if (!this.storage) |
| 45 | + return; |
44 | 46 | this.storage.setItem(this.descriptor, JSON.stringify(this.files));
|
45 | 47 | },
|
46 | 48 |
|
47 | 49 | readFileSystem: function() {
|
| 50 | + if (!this.storage) |
| 51 | + return null; |
48 | 52 | var fileSystem = this.storage.getItem(this.descriptor);
|
49 | 53 | if (!fileSystem)
|
50 | 54 | return {
|
|
55 | 59 | },
|
56 | 60 |
|
57 | 61 | getDirectoryEntry: function(path, create) {
|
| 62 | + if (!this.files) |
| 63 | + return; |
58 | 64 | var entry = this.files.root;
|
59 | 65 | for (var i = 0; i < path.length; ++i) {
|
60 | 66 | var folderName = path[i];
|
|
74 | 80 | },
|
75 | 81 |
|
76 | 82 | saveFileEntry: function(entry, value) {
|
| 83 | + if (!this.storage) |
| 84 | + return; |
77 | 85 | var filePath = entry.path,
|
78 | 86 | fileName = entry.name,
|
79 | 87 | dirEntry = this.getDirectoryEntry(filePath, true);
|
|
90 | 98 | },
|
91 | 99 |
|
92 | 100 | removeFileEntry: function(entry, value) {
|
| 101 | + if (!this.storage) |
| 102 | + return; |
93 | 103 | var filePath = entry.path,
|
94 | 104 | fileName = entry.name,
|
95 | 105 | dirEntry = this.getDirectoryEntry(filePath, true);
|
|
102 | 112 | },
|
103 | 113 |
|
104 | 114 | loadFileEntry: function(entry) {
|
| 115 | + if (!this.storage) |
| 116 | + return null; |
105 | 117 | var filePath = entry.path,
|
106 | 118 | fileName = entry.name,
|
107 | 119 | dirEntry = this.getDirectoryEntry(filePath, false);
|
|
115 | 127 |
|
116 | 128 | get: function(path, callback) {
|
117 | 129 | var self = this;
|
118 |
| - this.getEntry(path, |
| 130 | + this.getEntry(path, |
119 | 131 | function(err, entry) {
|
120 | 132 | if (err) {
|
121 | 133 | callback(err);
|
|
149 | 161 | dirEntry = this.getDirectoryEntry(filePath, true),
|
150 | 162 | list = [],
|
151 | 163 | self = this;
|
| 164 | + if (!dirEntry) |
| 165 | + return callback(null, []); |
152 | 166 | $.each(dirEntry, function(i, entry) {
|
153 | 167 | list.push(new FileEntry(self, filePath, entry.name));
|
154 | 168 | });
|
|
0 commit comments