Fix bug with tmlp format, do raw migrate

This commit is contained in:
Ilya Ig. Petrov 2017-10-31 18:42:20 +05:00
parent c9c7b15d9b
commit 41913e7dad
2 changed files with 19 additions and 15 deletions

View File

@ -161,13 +161,13 @@
}; };
const getCurrentConfigs = function getCurrentConfigs() { const getCurrentConfigs = function getCurrentConfigs(ifRaw = false) {
const oldMods = kitchenState(modsKey); const oldMods = kitchenState(modsKey);
/*if (oldMods) { if (ifRaw) {
// No migration! // No migration!
return oldMods; return oldMods;
}*/ }
// Client may expect mods.included and mods.excluded! // Client may expect mods.included and mods.excluded!
// On first install they are not defined. // On first install they are not defined.
@ -228,7 +228,7 @@
if (self.customProxyStringRaw) { if (self.customProxyStringRaw) {
customProxyArray = self.customProxyStringRaw customProxyArray = self.customProxyStringRaw
.replace(/#.*$/mg, '') // Strip comments. .replace(/#.*$/mg, '') // Strip comments.
.split( /(?:[^\S\r\n]*(?:;|\r?\n)+[^\S\r\n]*)+/g ) // Split by (<other whitespace>*<semi-colon or newline>+<other whitespace>*)+ .split( /(?:\s*(?:;\r?\n)+\s*)+/g )
.map( (p) => p.trim() ) .map( (p) => p.trim() )
.filter( (p) => p && /\s+/g.test(p) ); // At least one space is required. .filter( (p) => p && /\s+/g.test(p) ); // At least one space is required.
if (self.ifUseSecureProxiesOnly) { if (self.ifUseSecureProxiesOnly) {
@ -294,6 +294,7 @@
window.apis.pacKitchen = { window.apis.pacKitchen = {
getPacMods: getCurrentConfigs, getPacMods: getCurrentConfigs,
getPacModsRaw: () => getCurrentConfigs(true),
getOrderedConfigs: getOrderedConfigsForUser, getOrderedConfigs: getOrderedConfigsForUser,
cook(pacData, pacMods = mandatory()) { cook(pacData, pacMods = mandatory()) {

View File

@ -524,24 +524,27 @@
} }
// UPDATE & MIGRATION // UPDATE & MIGRATION
console.log('Updating from', oldStorage.version, 'to', antiCensorRu.version);
if (window.apis.version.isLeq(oldStorage.version, '0.0.1.5')) {
// Change semicolons to semicolons followed by newlines in proxy string (raw). const ifUpdatedCb = () => antiCensorRu.pushToStorageAsync(() => {
const migrateProxies = (oldStr) => oldStr.replace(/;\r?\n?/g, ';\n');
const modsMutated = window.apis.pacKitchen.getPacMods();
modsMutated['customProxyStringRaw'] = migrateProxies(conf.value);
window.apis.pacKitchen.keepCookedNowAsync(modsMutated, cb);
}
antiCensorRu.pushToStorageAsync(() => {
console.log('Extension updated.'); console.log('Extension updated.');
resolve(); resolve();
}); });
console.log('Updating from', oldStorage.version, 'to', antiCensorRu.version);
if (window.apis.version.isLeq(oldStorage.version, '0.0.1.5')) {
// Change semicolons to semicolons followed by newlines in proxy string (raw).
const migrateProxies = (oldStr) => oldStr.replace(/;\\r?\\n?/g, ';\\n');
const modsMutated = window.apis.pacKitchen.getPacModsRaw();
modsMutated['customProxyStringRaw'] = migrateProxies(conf.value);
window.apis.pacKitchen.keepCookedNowAsync(modsMutated, ifUpdatedCb);
} else {
ifUpdatedCb();
}
}); });
if (antiCensorRu.getPacProvider()) { if (antiCensorRu.getPacProvider()) {