OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 "use strict"; |
| 19 |
| 20 const {Filter, ActiveFilter} = require("filterClasses"); |
| 21 const {FilterNotifier} = require("filterNotifier"); |
| 22 const {FilterStorage} = require("filterStorage"); |
| 23 const {IO} = require("io"); |
| 24 const {Prefs} = require("prefs"); |
| 25 const {SpecialSubscription} = require("subscriptionClasses"); |
| 26 |
| 27 Promise.all([FilterNotifier.once("load"), Prefs.untilLoaded]).then(() => |
| 28 { |
| 29 if (Prefs.data_cleanup_done) |
| 30 return; |
| 31 |
| 32 if (FilterStorage.firstRun) |
| 33 { |
| 34 Prefs.data_cleanup_done = true; |
| 35 return; |
| 36 } |
| 37 |
| 38 let haveHitCounts = []; |
| 39 |
| 40 for (let key in Filter.knownFilters) |
| 41 { |
| 42 let filter = Filter.knownFilters[key]; |
| 43 if (!(filter instanceof ActiveFilter)) |
| 44 continue; |
| 45 |
| 46 if (filter.disabled) |
| 47 { |
| 48 // Enable or replace disabled filters |
| 49 filter.disabled = false; |
| 50 |
| 51 for (let subscription of filter.subscriptions) |
| 52 { |
| 53 if (subscription instanceof SpecialSubscription) |
| 54 { |
| 55 while (true) |
| 56 { |
| 57 let position = subscription.filters.indexOf(filter); |
| 58 if (position < 0) |
| 59 break; |
| 60 |
| 61 let newFilter = Filter.fromText("! " + filter.text); |
| 62 FilterStorage.removeFilter(filter, subscription, position); |
| 63 FilterStorage.addFilter(newFilter, subscription, position); |
| 64 } |
| 65 } |
| 66 } |
| 67 } |
| 68 |
| 69 if (filter.hitCount || filter.lastHit) |
| 70 haveHitCounts.push(filter); |
| 71 } |
| 72 |
| 73 // Reset hit statistics on any filters having them |
| 74 FilterStorage.resetHitCounts(haveHitCounts); |
| 75 |
| 76 // Remove any existing automatic backups |
| 77 let backups = []; |
| 78 for (let i = 1; i < 100; i++) |
| 79 backups.push(`file:patterns-backup${i}.ini`); |
| 80 browser.storage.local.remove(backups).then(() => |
| 81 { |
| 82 Prefs.data_cleanup_done = true; |
| 83 }); |
| 84 }); |
OLD | NEW |