OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 15 matching lines...) Expand all Loading... |
26 if (file instanceof FakeFile) | 26 if (file instanceof FakeFile) |
27 return file.path; | 27 return file.path; |
28 else if ("spec" in file) | 28 else if ("spec" in file) |
29 return file.spec; | 29 return file.spec; |
30 | 30 |
31 throw new Error("Unexpected file type"); | 31 throw new Error("Unexpected file type"); |
32 }, | 32 }, |
33 | 33 |
34 _setFileContents: function(path, contents, lastModified) | 34 _setFileContents: function(path, contents, lastModified) |
35 { | 35 { |
36 ext.storage[path] = contents; | 36 safari.extension.settings[path] = contents; |
37 ext.storage[path + "/lastModified"] = lastModified || 0; | 37 safari.extension.settings[path + "/lastModified"] = lastModified || 0; |
38 }, | 38 }, |
39 | 39 |
40 lineBreak: "\n", | 40 lineBreak: "\n", |
41 | 41 |
42 resolveFilePath: function(path) | 42 resolveFilePath: function(path) |
43 { | 43 { |
44 return new FakeFile(path); | 44 return new FakeFile(path); |
45 }, | 45 }, |
46 | 46 |
47 readFromFile: function(file, listener, callback, timeLineID) | 47 readFromFile: function(file, listener, callback, timeLineID) |
48 { | 48 { |
49 var Utils = require("utils").Utils; | 49 var Utils = require("utils").Utils; |
50 Utils.runAsync(function() | 50 Utils.runAsync(function() |
51 { | 51 { |
52 var path = this._getFilePath(file); | 52 var path = this._getFilePath(file); |
53 if (!(path in ext.storage)) | 53 if (!(path in safari.extension.settings)) |
54 { | 54 { |
55 callback(new Error("File doesn't exist")) | 55 callback(new Error("File doesn't exist")) |
56 return; | 56 return; |
57 } | 57 } |
58 | 58 |
59 var lines = ext.storage[path].split(/[\r\n]+/); | 59 var lines = safari.extension.settings[path].split(/[\r\n]+/); |
60 for (var i = 0; i < lines.length; i++) | 60 for (var i = 0; i < lines.length; i++) |
61 listener.process(lines[i]); | 61 listener.process(lines[i]); |
62 listener.process(null); | 62 listener.process(null); |
63 callback(null); | 63 callback(null); |
64 }.bind(this)); | 64 }.bind(this)); |
65 }, | 65 }, |
66 | 66 |
67 writeToFile: function(file, data, callback, timeLineID) | 67 writeToFile: function(file, data, callback, timeLineID) |
68 { | 68 { |
69 var path = this._getFilePath(file); | 69 var path = this._getFilePath(file); |
(...skipping 18 matching lines...) Expand all Loading... |
88 if (e) | 88 if (e) |
89 callback(e); | 89 callback(e); |
90 else | 90 else |
91 this.writeToFile(toFile, data, callback); | 91 this.writeToFile(toFile, data, callback); |
92 }.bind(this)); | 92 }.bind(this)); |
93 }, | 93 }, |
94 | 94 |
95 renameFile: function(fromFile, newName, callback) | 95 renameFile: function(fromFile, newName, callback) |
96 { | 96 { |
97 var path = this._getFilePath(fromFile); | 97 var path = this._getFilePath(fromFile); |
98 if (!(path in ext.storage)) | 98 if (!(path in safari.extension.settings)) |
99 { | 99 { |
100 callback(new Error("File doesn't exist")) | 100 callback(new Error("File doesn't exist")) |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 this._setFileContents(newName, ext.storage[path], ext.storage[path + "/lastM
odified"]); | 104 this._setFileContents(newName, safari.extension.settings[path], safari.exten
sion.settings[path + "/lastModified"]); |
105 this.removeFile(fromFile, callback); | 105 this.removeFile(fromFile, callback); |
106 }, | 106 }, |
107 | 107 |
108 removeFile: function(file, callback) | 108 removeFile: function(file, callback) |
109 { | 109 { |
110 var path = this._getFilePath(file); | 110 var path = this._getFilePath(file); |
111 delete ext.storage[path]; | 111 delete safari.extension.settings[path]; |
112 delete ext.storage[path + "/lastModified"]; | 112 delete safari.extension.settings[path + "/lastModified"]; |
113 callback(null); | 113 callback(null); |
114 }, | 114 }, |
115 | 115 |
116 statFile: function(file, callback) | 116 statFile: function(file, callback) |
117 { | 117 { |
118 var path = this._getFilePath(file); | 118 var path = this._getFilePath(file); |
119 | 119 |
120 // This needs to use Utils.runAsync(), otherwise FilterStorage might | 120 // This needs to use Utils.runAsync(), otherwise FilterStorage might |
121 // initialize too early - see #337. | 121 // initialize too early - see #337. |
122 require("utils").Utils.runAsync(callback.bind(null, null, { | 122 require("utils").Utils.runAsync(callback.bind(null, null, { |
123 exists: path in ext.storage, | 123 exists: path in safari.extension.settings, |
124 isDirectory: false, | 124 isDirectory: false, |
125 isFile: true, | 125 isFile: true, |
126 lastModified: parseInt(ext.storage[path + "/lastModified"], 10) || 0 | 126 lastModified: parseInt(safari.extension.settings[path + "/lastModified"],
10) || 0 |
127 })); | 127 })); |
128 } | 128 } |
129 }; | 129 }; |
OLD | NEW |