| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
var Prefs = { |
|---|
| 40 |
tempLocation: null, |
|---|
| 41 |
|
|---|
| 42 |
mappings: [ |
|---|
| 43 |
['removeCompleted', true], |
|---|
| 44 |
['removeAborted', false], |
|---|
| 45 |
['removeCanceled', false], |
|---|
| 46 |
['autoClose', 'closedta', false], |
|---|
| 47 |
['timeout', 300], |
|---|
| 48 |
['maxInProgress', 'ntask', 4], |
|---|
| 49 |
['maxChunks', 4], |
|---|
| 50 |
['setTime', true], |
|---|
| 51 |
['showOnlyFilenames', true], |
|---|
| 52 |
['conflictResolution', 3], |
|---|
| 53 |
['alertingSystem', 'alertbox', (SYSTEMSLASH == '\\') ? 1 : 0], |
|---|
| 54 |
['finishEvent', ''], |
|---|
| 55 |
['showTooltip', true], |
|---|
| 56 |
['maxAutoRetries', 10], |
|---|
| 57 |
['autoRetryInterval', 0], |
|---|
| 58 |
['autoClearComplete', false], |
|---|
| 59 |
['confirmRemove', true], |
|---|
| 60 |
['permissions', 384], |
|---|
| 61 |
], |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
observe: function(subject, topic, prefName) { |
|---|
| 65 |
this._refreshPrefs(prefName); |
|---|
| 66 |
}, |
|---|
| 67 |
|
|---|
| 68 |
init: function() { |
|---|
| 69 |
makeObserver(this); |
|---|
| 70 |
|
|---|
| 71 |
try { |
|---|
| 72 |
this._resetConnPrefs(); |
|---|
| 73 |
this._refreshPrefs(); |
|---|
| 74 |
Preferences.addObserver('extensions.dta.', this); |
|---|
| 75 |
Preferences.addObserver('network.', this); |
|---|
| 76 |
} |
|---|
| 77 |
catch (ex) { |
|---|
| 78 |
Debug.log("failed to add pref-observer", ex); |
|---|
| 79 |
} |
|---|
| 80 |
}, |
|---|
| 81 |
|
|---|
| 82 |
_refreshPrefs: function(prefName) { |
|---|
| 83 |
Debug.logString("pref reload"); |
|---|
| 84 |
this.mappings.forEach( |
|---|
| 85 |
function(e) { |
|---|
| 86 |
let key, pref, def; |
|---|
| 87 |
if (!e) { |
|---|
| 88 |
return; |
|---|
| 89 |
} |
|---|
| 90 |
else if (e.length == 3) { |
|---|
| 91 |
key = e[0]; |
|---|
| 92 |
pref = e[1]; |
|---|
| 93 |
def = e[2]; |
|---|
| 94 |
} |
|---|
| 95 |
else { |
|---|
| 96 |
key = e[0]; |
|---|
| 97 |
pref = key.toLowerCase(); |
|---|
| 98 |
def = e[1]; |
|---|
| 99 |
} |
|---|
| 100 |
this[key] = Preferences.getDTA(pref, def); |
|---|
| 101 |
}, |
|---|
| 102 |
this |
|---|
| 103 |
); |
|---|
| 104 |
|
|---|
| 105 |
var perms = Prefs.permissions; |
|---|
| 106 |
if (perms & 0600) { |
|---|
| 107 |
perms |= 0100; |
|---|
| 108 |
} |
|---|
| 109 |
if (perms & 0060) { |
|---|
| 110 |
perms |= 0010; |
|---|
| 111 |
} |
|---|
| 112 |
if (perms & 0006) { |
|---|
| 113 |
perms |= 0001; |
|---|
| 114 |
} |
|---|
| 115 |
this.dirPermissions = perms; |
|---|
| 116 |
|
|---|
| 117 |
if (Preferences.getDTA("saveTemp", true)) { |
|---|
| 118 |
try { |
|---|
| 119 |
this.tempLocation = Preferences.getMultiByteDTA("tempLocation", ''); |
|---|
| 120 |
if (this.tempLocation == '') { |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
var dsp = Serv('@mozilla.org/file/directory_service;1', 'nsIProperties'); |
|---|
| 124 |
this.tempLocation = dsp.get("TmpD", Ci.nsIFile); |
|---|
| 125 |
var profD = hash(dsp.get("ProfD", Ci.nsIFile).leafName); |
|---|
| 126 |
this.tempLocation.append("dtatmp-" + profD); |
|---|
| 127 |
Debug.log(this.tempLocation.path); |
|---|
| 128 |
} |
|---|
| 129 |
else { |
|---|
| 130 |
this.tempLocation = new FileFactory(this.tempLocation); |
|---|
| 131 |
} |
|---|
| 132 |
} catch (ex) { |
|---|
| 133 |
this.tempLocation = null; |
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
else { |
|---|
| 138 |
this.tempLocation = null; |
|---|
| 139 |
} |
|---|
| 140 |
var conns = (this.maxInProgress * this.maxChunks) + 2; |
|---|
| 141 |
['network.http.max-connections', 'network.http.max-connections-per-server'].forEach( |
|---|
| 142 |
function(e) { |
|---|
| 143 |
if ((!prefName || prefName == e) && conns != Preferences.get(e, conns)) { |
|---|
| 144 |
Preferences.setDTA(e, Preferences.get(e, conns)); |
|---|
| 145 |
} |
|---|
| 146 |
if (conns > Preferences.get(e, conns)) { |
|---|
| 147 |
Preferences.set(e, conns); |
|---|
| 148 |
} |
|---|
| 149 |
conns = Math.floor(conns / 1.5); |
|---|
| 150 |
} |
|---|
| 151 |
); |
|---|
| 152 |
}, |
|---|
| 153 |
shutdown: function() { |
|---|
| 154 |
Preferences.removeObserver('network.', this); |
|---|
| 155 |
this._resetConnPrefs(); |
|---|
| 156 |
}, |
|---|
| 157 |
_resetConnPrefs: function() { |
|---|
| 158 |
['network.http.max-connections', 'network.http.max-connections-per-server'].forEach( |
|---|
| 159 |
function(e) { |
|---|
| 160 |
let conn = Preferences.getDTA(e, 0); |
|---|
| 161 |
if (conn) { |
|---|
| 162 |
Preferences.set(e, conn); |
|---|
| 163 |
Preferences.setDTA(e, 0); |
|---|
| 164 |
} |
|---|
| 165 |
} |
|---|
| 166 |
); |
|---|
| 167 |
} |
|---|
| 168 |
} |
|---|
| 169 |
Prefs.init(); |
|---|