Changeset 9dfc10


Ignore:
Timestamp:
Apr 21, 2008, 1:40:37 PM (13 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
8d1159
Parents:
4ce2f0
Message:

move user-options for changed preferences, unified setup for different future upgrade

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_upgrade.js

    r4ce2f0 r9dfc10  
    2828            .getBranch("extensions.virtualIdentity."),
    2929           
     30    versionChecker : Components.classes["@mozilla.org/xpcom/version-comparator;1"]
     31            .getService(Components.interfaces.nsIVersionComparator),
     32
    3033    init : function() {
    3134        document.documentElement.getButton("cancel").setAttribute("hidden", "true")
     
    3740    skipUpgradePages : function() {
    3841        var preUpdateWizardPage = document.getElementById("license")       
    39         var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
    40             .getService(Components.interfaces.nsIVersionComparator);
    4142        // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
    42         if (versionChecker.compare(vI_rdfDatasource.getCurrentExtFileVersion(), "0.5.0") >= 0)
     43        if (vI_upgrade.versionChecker.compare(vI_rdfDatasource.getCurrentExtFileVersion(), "0.5.0") >= 0)
    4344            preUpdateWizardPage.setAttribute("next", "upgrade")
    4445    },
     
    7677   
    7778    extUpgrade : function() {
     79        var currentVersion = vI_rdfDatasource.getCurrentExtFileVersion();
    7880        vI_notificationBar.dump("checking for previous version, found " +
    79             vI_rdfDatasource.getCurrentExtFileVersion() + "\nextension-upgrade required.\n")
    80         switch (vI_rdfDatasource.getCurrentExtFileVersion()) {
     81            currentVersion + "\nextension-upgrade required.\n")
     82        switch (currentVersion) {
    8183            case null:
    82                 vI_upgrade.__transferAllVIdentityABookToRDF();
    83                 vI_upgrade.__removeObsoleteUserPrefs();
     84                vI_upgrade.__transferAllVIdentityABookToRDF(); // no break
     85            default:
     86                vI_upgrade.__transferMovedUserPrefs(currentVersion);
     87                vI_upgrade.__removeObsoleteUserPrefs(currentVersion);
    8488        }
    8589        vI_rdfDatasource.storeExtVersion();
     
    8791    },
    8892       
    89     __removeObsoleteUserPrefs : function() {
     93    __transferMovedUserPrefs : function(currentVersion) {
     94        // transfer renamed preferences
     95        var transferPrefs = [   { version : "0.5.3",
     96                    prefs : Array({ sourcePref : "smart_reply_ask", targetPref : "idSelection_ask" },
     97                        { sourcePref : "smart_reply_ask_always", targetPref : "idSelection_ask_always" },
     98                        { sourcePref : "smart_reply_autocreate", targetPref : "idSelection_autocreate" },
     99                        { sourcePref : "smart_timestamp", targetPref : "autoTimestamp" },
     100                        { sourcePref : "storage_prefer_smart_reply", targetPref : "idSelection_storage_prefer_smart_reply" },
     101                        { sourcePref : "storage_ignore_smart_reply", targetPref : "idSelection_storage_ignore_smart_reply" }) }];
    90102        // remove obsolete preference-tree virtualIdentity
    91        
    92         // remove any obsolete preferences under extensions.virtualIdentity
    93         vI_notificationBar.dump("removing obsolete preferences:\n")
    94         for each (pref in Array("aBook_use", "aBook_storedefault", "aBook_dont_update_multiple",
    95                 "aBook_show_switch", "aBook_warn_update", "aBook_use_for_smart_reply", "aBook_prefer_smart_reply",
    96                 "aBook_ignore_smart_reply", "aBook_warn_vI_replace", "aBook_use_non_vI", "aBook_notification", "storeVIdentity",
    97                 "experimental")) {
    98             try { vI_upgrade.preferences.clearUserPref(pref); vI_notificationBar.dump(".") }
    99             catch (e) { };
    100         }
    101         vI_notificationBar.dump("done.\n")
     103        for (i = 0; i < transferPrefs.length; i++) {
     104            // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
     105            if (!currentVersion || (vI_upgrade.versionChecker.compare(currentVersion, transferPrefs[i].version) < 0)) {
     106                // remove any obsolete preferences under extensions.virtualIdentity
     107                vI_notificationBar.dump("transfer changed preferences of pre-" + transferPrefs[i].version + " release:\n")
     108                for each (transferPref in transferPrefs[i].prefs) {
     109                    try {   vI_upgrade.preferences.setBoolPref(transferPref.targetPref,
     110                            vI_upgrade.preferences.getBoolPref(transferPref.sourcePref));
     111                        vI_upgrade.preferences.clearUserPref(transferPref.sourcePref);
     112                        vI_notificationBar.dump(".")
     113                    }
     114                    catch (e) { };
     115                }
     116                vI_notificationBar.dump("done.\n")
     117            }
     118        }
     119    },
     120   
     121    __removeObsoleteUserPrefs : function(currentVersion) {
     122        var obsoletePrefs = [   { version : "0.5.0",
     123                    prefs : Array("aBook_use", "aBook_storedefault", "aBook_dont_update_multiple",
     124                    "aBook_show_switch", "aBook_warn_update", "aBook_use_for_smart_reply",
     125                    "aBook_prefer_smart_reply", "aBook_ignore_smart_reply", "aBook_warn_vI_replace",
     126                    "aBook_use_non_vI", "aBook_notification", "storeVIdentity", "experimental",
     127                    "storage_use_for_smart_reply") },
     128                    { version : "0.5.3", prefs : Array("storage_use_for_smart_reply") } ];
     129        // remove obsolete preference-tree virtualIdentity
     130        for (i = 0; i < obsoletePrefs.length; i++) {
     131            // if former version of extension was at least 0.5.0, start with WizardPage 0.5.2
     132            if (!currentVersion || (vI_upgrade.versionChecker.compare(currentVersion, obsoletePrefs[i].version) < 0)) {
     133                // remove any obsolete preferences under extensions.virtualIdentity
     134                vI_notificationBar.dump("removing obsolete preferences of pre-" + obsoletePrefs[i].version + " release:\n")
     135                for each (pref in obsoletePrefs[i].prefs) {
     136                    try { vI_upgrade.preferences.clearUserPref(pref); vI_notificationBar.dump(".") }
     137                    catch (e) { };
     138                }
     139                vI_notificationBar.dump("done.\n")
     140            }
     141        }
    102142    },
    103143
Note: See TracChangeset for help on using the changeset viewer.