OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 30 matching lines...) Expand all Loading... |
41 }, errorCallback); | 41 }, errorCallback); |
42 }, | 42 }, |
43 | 43 |
44 lineBreak: "\n", | 44 lineBreak: "\n", |
45 | 45 |
46 resolveFilePath: function(path) | 46 resolveFilePath: function(path) |
47 { | 47 { |
48 return new FakeFile(path); | 48 return new FakeFile(path); |
49 }, | 49 }, |
50 | 50 |
51 readFromFile: function(file, decode, listener, callback, timeLineID) | 51 readFromFile: function(file, listener, callback, timeLineID) |
52 { | 52 { |
53 // Hack to allow importing old data | 53 // Hack to allow importing old data |
54 if (typeof file == "string") | 54 if (typeof file == "string") |
55 { | 55 { |
56 var Utils = require("utils").Utils; | 56 var Utils = require("utils").Utils; |
57 Utils.runAsync(function() | 57 Utils.runAsync(function() |
58 { | 58 { |
59 var lines = file.split(/[\r\n]+/); | 59 var lines = file.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 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 if ("spec" in file && /^defaults\b/.test(file.spec)) | |
69 { | |
70 // Code attempts to read the default patterns.ini, we don't have that. | |
71 // Make sure to execute first-run actions instead. | |
72 var Utils = require("utils").Utils; | |
73 Utils.runAsync(function() | |
74 { | |
75 if (ext.storage.currentVersion) | |
76 seenDataCorruption = true; | |
77 delete ext.storage.currentVersion; | |
78 callback(null); | |
79 }); | |
80 return; | |
81 } | |
82 | |
83 this._getFileEntry(file, false, function(fs, fileEntry) | 68 this._getFileEntry(file, false, function(fs, fileEntry) |
84 { | 69 { |
85 fileEntry.file(function(file) | 70 fileEntry.file(function(file) |
86 { | 71 { |
87 var reader = new FileReader(); | 72 var reader = new FileReader(); |
88 reader.onloadend = function() | 73 reader.onloadend = function() |
89 { | 74 { |
90 if (reader.error) | 75 if (reader.error) |
91 callback(reader.error); | 76 callback(reader.error); |
92 else | 77 else |
93 { | 78 { |
94 var lines = reader.result.split(/[\r\n]+/); | 79 var lines = reader.result.split(/[\r\n]+/); |
95 for (var i = 0; i < lines.length; i++) | 80 for (var i = 0; i < lines.length; i++) |
96 listener.process(lines[i]); | 81 listener.process(lines[i]); |
97 listener.process(null); | 82 listener.process(null); |
98 callback(null); | 83 callback(null); |
99 } | 84 } |
100 }; | 85 }; |
101 reader.readAsText(file); | 86 reader.readAsText(file); |
102 }, callback); | 87 }, callback); |
103 }, callback); | 88 }, callback); |
104 }, | 89 }, |
105 | 90 |
106 writeToFile: function(file, encode, data, callback, timeLineID) | 91 writeToFile: function(file, data, callback, timeLineID) |
107 { | 92 { |
108 this._getFileEntry(file, true, function(fs, fileEntry) | 93 this._getFileEntry(file, true, function(fs, fileEntry) |
109 { | 94 { |
110 fileEntry.createWriter(function(writer) | 95 fileEntry.createWriter(function(writer) |
111 { | 96 { |
112 var executeWriteOperation = function(op, nextOperation) | 97 var executeWriteOperation = function(op, nextOperation) |
113 { | 98 { |
114 writer.onwriteend = function() | 99 writer.onwriteend = function() |
115 { | 100 { |
116 if (writer.error) | 101 if (writer.error) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 callback(null, { | 193 callback(null, { |
209 exists: true, | 194 exists: true, |
210 isDirectory: fileEntry.isDirectory, | 195 isDirectory: fileEntry.isDirectory, |
211 isFile: fileEntry.isFile, | 196 isFile: fileEntry.isFile, |
212 lastModified: metadata.modificationTime.getTime() | 197 lastModified: metadata.modificationTime.getTime() |
213 }); | 198 }); |
214 }, callback); | 199 }, callback); |
215 }, callback); | 200 }, callback); |
216 } | 201 } |
217 }; | 202 }; |
OLD | NEW |