зеркало из https://github.com/mozilla/pjs.git
make the downloader work again!
This commit is contained in:
Родитель
48a4f84526
Коммит
90d006f517
|
@ -40,7 +40,7 @@ const nsIIncrementalDownload = Components.interfaces.nsIIncrementalDownload;
|
|||
|
||||
const XMLNS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
|
||||
const PREF_UPDATE_MANUAL_URL = "app.update.manual.url";
|
||||
const PREF_UPDATE_MANUAL_URL = "app.update.url.manual";
|
||||
|
||||
const STATE_DOWNLOADING = "downloading";
|
||||
const STATE_PENDING = "pending";
|
||||
|
@ -161,7 +161,6 @@ var gCheckingPage = {
|
|||
var aus = Components.classes["@mozilla.org/updates/update-service;1"]
|
||||
.getService(Components.interfaces.nsIApplicationUpdateService);
|
||||
gUpdates.update = aus.selectUpdate(updates, updates.length);
|
||||
LOG("SELECTEDUPDATE = " + gUpdates.update.patchCount);
|
||||
if (!gUpdates.update) {
|
||||
LOG("Could not select an appropriate update, either because there were none," +
|
||||
" or |selectUpdate| failed.");
|
||||
|
@ -267,7 +266,9 @@ var gLicensePage = {
|
|||
};
|
||||
|
||||
var gDownloadingPage = {
|
||||
_createAndInsertItem: function(update, state) {
|
||||
_updatesView: null,
|
||||
|
||||
_createAndInsertItem: function(update) {
|
||||
var element = document.createElementNS(XMLNS_XUL, "update");
|
||||
this._updatesView.appendChild(element);
|
||||
element.setUpdate(update);
|
||||
|
@ -276,16 +277,6 @@ var gDownloadingPage = {
|
|||
|
||||
onPageShow: function() {
|
||||
this._updatesView = document.getElementById("updatesView");
|
||||
|
||||
var um = Components.classes["@mozilla.org/updates/update-manager;1"]
|
||||
.getService(Components.interfaces.nsIUpdateManager);
|
||||
var activeUpdate = um.activeUpdate;
|
||||
if (um.activeUpdate) {
|
||||
var element = this._createAndInsertItem(activeUpdate);
|
||||
element.id = "activeDownloadItem";
|
||||
}
|
||||
this._updatesView.addEventListener("update-pause", this.onPause, false);
|
||||
|
||||
if (gUpdates.update) {
|
||||
// Add this UI as a listener for active downloads
|
||||
var updates =
|
||||
|
@ -297,6 +288,15 @@ var gDownloadingPage = {
|
|||
else
|
||||
updates.addDownloadListener(this);
|
||||
}
|
||||
|
||||
var um = Components.classes["@mozilla.org/updates/update-manager;1"]
|
||||
.getService(Components.interfaces.nsIUpdateManager);
|
||||
var activeUpdate = um.activeUpdate;
|
||||
if (activeUpdate) {
|
||||
var element = this._createAndInsertItem(activeUpdate);
|
||||
element.id = "activeDownloadItem";
|
||||
}
|
||||
this._updatesView.addEventListener("update-pause", this.onPause, false);
|
||||
|
||||
// Build the UI for previously installed updates
|
||||
for (var i = 0; i < um.updateCount; ++i) {
|
||||
|
@ -310,6 +310,7 @@ var gDownloadingPage = {
|
|||
|
||||
_paused: false,
|
||||
onPause: function() {
|
||||
LOG("PAUSE/RESUME DOWNLOAD");
|
||||
var updates =
|
||||
Components.classes["@mozilla.org/updates/update-service;1"].
|
||||
getService(Components.interfaces.nsIApplicationUpdateService);
|
||||
|
@ -340,7 +341,7 @@ var gDownloadingPage = {
|
|||
|
||||
onProgress: function(request, context, progress, maxProgress) {
|
||||
request.QueryInterface(nsIIncrementalDownload);
|
||||
//LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
|
||||
LOG("gDownloadingPage.onProgress: " + request.URI.spec + ", " + progress + "/" + maxProgress);
|
||||
|
||||
var active = document.getElementById("activeDownloadItem");
|
||||
active.setAttribute("progress", Math.floor(100 * (progress/maxProgress)));
|
||||
|
@ -359,14 +360,16 @@ var gDownloadingPage = {
|
|||
var updates =
|
||||
Components.classes["@mozilla.org/updates/update-service;1"]
|
||||
.getService(Components.interfaces.nsIApplicationUpdateService);
|
||||
if (status == Components.results.NS_ERROR_UNEXPECTED &&
|
||||
!gUpdates.update.isCompleteUpdate) {
|
||||
// If we were downloading a patch and the patch verification phase
|
||||
// failed, log this and then commence downloading the complete update.
|
||||
LOG("Verification of patch failed, downloading complete update");
|
||||
gUpdates.update.isCompleteUpdate = true;
|
||||
var state = updates.downloadUpdate(gUpdates.update, false);
|
||||
if (state == "failed")
|
||||
if (status == Components.results.NS_ERROR_UNEXPECTED) {
|
||||
var state = STATE_FAILED;
|
||||
if (!gUpdates.update.isCompleteUpdate) {
|
||||
// If we were downloading a patch and the patch verification phase
|
||||
// failed, log this and then commence downloading the complete update.
|
||||
LOG("Verification of patch failed, downloading complete update");
|
||||
gUpdates.update.isCompleteUpdate = true;
|
||||
state = updates.downloadUpdate(gUpdates.update, false);
|
||||
}
|
||||
if (state == STATE_FAILED)
|
||||
this.showVerificationError();
|
||||
else
|
||||
return;
|
||||
|
|
|
@ -125,6 +125,7 @@
|
|||
return val;
|
||||
]]></setter>
|
||||
</property>
|
||||
<field name="eventPrefix">"update-"</field>
|
||||
<property name="state"
|
||||
onset="this.setAttribute('state', val); return val;"
|
||||
onget="return this.getAttribute('state');"/>
|
||||
|
|
|
@ -662,7 +662,6 @@ UpdateManager.prototype = {
|
|||
* @returns The array of nsIUpdate items held in the file.
|
||||
*/
|
||||
_loadXMLFileIntoArray: function(file) {
|
||||
LOG(FILE_UPDATE_ACTIVE);
|
||||
if (!file.exists())
|
||||
return [];
|
||||
|
||||
|
@ -686,7 +685,6 @@ UpdateManager.prototype = {
|
|||
result.push(new Update(updateNode));
|
||||
}
|
||||
}
|
||||
LOG("ARY RESULT = " + result);
|
||||
return result;
|
||||
},
|
||||
|
||||
|
@ -741,6 +739,8 @@ UpdateManager.prototype = {
|
|||
},
|
||||
set activeUpdate(activeUpdate) {
|
||||
this._ensureActiveUpdate();
|
||||
if (!activeUpdate)
|
||||
this._updates = [this._activeUpdate].concat(this._updates);
|
||||
this._activeUpdate = activeUpdate;
|
||||
this._writeUpdatesToXMLFile([this._activeUpdate],
|
||||
getFile(KEY_APPDIR, [FILE_UPDATE_ACTIVE]));
|
||||
|
@ -767,29 +767,36 @@ UpdateManager.prototype = {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
_writeUpdatesToXMLFile: function(updates) {
|
||||
_writeUpdatesToXMLFile: function(updates, file) {
|
||||
var fos = Components.classes["@mozilla.org/network/safe-file-output-stream;1"]
|
||||
.createInstance(Components.interfaces.nsIFileOutputStream);
|
||||
var updatesDB = getFile(KEY_APPDIR, [FILE_UPDATES_DB]);
|
||||
var modeFlags = MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE;
|
||||
if (!updatesDB.exists())
|
||||
updatesDB.create(nsILocalFile.NORMAL_FILE_TYPE, PERMS_FILE);
|
||||
fos.init(updatesDB, modeFlags, PERMS_FILE, 0);
|
||||
if (!file.exists())
|
||||
file.create(nsILocalFile.NORMAL_FILE_TYPE, PERMS_FILE);
|
||||
fos.init(file, modeFlags, PERMS_FILE, 0);
|
||||
|
||||
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMParser);
|
||||
const EMPTY_UPDATES_DOCUMENT = "<?xml version=\"1.0\"?><updates xmlns=\"http://www.mozilla.org/2005/app-update\"></updates>";
|
||||
var doc = parser.parseFromString(EMPTY_UPDATES_DOCUMENT, "text/xml");
|
||||
|
||||
for (var i = 0; i < updates.length; ++i)
|
||||
doc.documentElement.appendChild(updates[i].serialize(doc));
|
||||
for (var i = 0; i < updates.length; ++i) {
|
||||
if (updates[i])
|
||||
doc.documentElement.appendChild(updates[i].serialize(doc));
|
||||
}
|
||||
|
||||
var serializer = Components.classes["@mozilla.org/xmlextras/xmlserializer;1"]
|
||||
.createInstance(Components.interfaces.nsIDOMSerializer);
|
||||
serializer.serializeToStream(doc.documentElement, fos, null);
|
||||
|
||||
if (fos instanceof Components.interfaces.nsISafeOutputStream)
|
||||
fos.finish();
|
||||
if (fos instanceof Components.interfaces.nsISafeOutputStream) {
|
||||
try {
|
||||
fos.finish();
|
||||
}
|
||||
catch (e) {
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
fos.close();
|
||||
},
|
||||
|
@ -803,7 +810,6 @@ UpdateManager.prototype = {
|
|||
getFile(KEY_APPDIR, [FILE_UPDATE_ACTIVE]));
|
||||
}
|
||||
if (this._updates) {
|
||||
LOG("UPDATES = " + this._updates);
|
||||
this._writeUpdatesToXMLFile(this._updates,
|
||||
getFile(KEY_APPDIR, [FILE_UPDATES_DB]));
|
||||
}
|
||||
|
@ -1061,7 +1067,7 @@ Checker.prototype = {
|
|||
*
|
||||
*/
|
||||
onProgress: function(event) {
|
||||
LOG("*** download progress: " + event.position + "/" + event.totalSize);
|
||||
LOG("Checker.onProgress: " + event.position + "/" + event.totalSize);
|
||||
this._callback.onProgress(event.target, event.position, event.totalSize);
|
||||
},
|
||||
|
||||
|
@ -1277,7 +1283,6 @@ Downloader.prototype = {
|
|||
* @returns A nsIUpdatePatch object matching the type specified
|
||||
*/
|
||||
function getPatchOfType(type) {
|
||||
LOG("PATCHCOUNT = " + update.patchCount);
|
||||
for (var i = 0; i < update.patchCount; ++i) {
|
||||
var patch = update.getPatchAt(i);
|
||||
if (patch && patch.type == type)
|
||||
|
@ -1300,9 +1305,9 @@ Downloader.prototype = {
|
|||
// that we do not know about, then remove it and use our default logic.
|
||||
var useComplete = false;
|
||||
if (selectedPatch) {
|
||||
var state = this._readStatusFile(updateDir)
|
||||
LOG("found existing patch [state="+state+"]");
|
||||
|
||||
switch (this._readStatusFile(updateDir)) {
|
||||
switch (state) {
|
||||
case STATE_DOWNLOADING:
|
||||
LOG("resuming download");
|
||||
return selectedPatch;
|
||||
|
@ -1338,14 +1343,16 @@ Downloader.prototype = {
|
|||
|
||||
// If we were not able to discover an update from a previous download, we
|
||||
// select the best patch from the given set.
|
||||
var partialPatch = getPatchOfType("partial");
|
||||
if (!useComplete)
|
||||
selectedPatch = getPatchOfType("partial");
|
||||
if (!selectedPatch)
|
||||
selectedPatch = partialPatch;
|
||||
if (!selectedPatch) {
|
||||
partialPatch.selected = false;
|
||||
selectedPatch = getPatchOfType("complete");
|
||||
|
||||
}
|
||||
selectedPatch.selected = true;
|
||||
update.isCompleteUpdate = useComplete;
|
||||
|
||||
|
||||
// Reset the Active Update object on the Update Manager and flush the
|
||||
// Active Update DB.
|
||||
var um = Components.classes["@mozilla.org/updates/update-manager;1"]
|
||||
|
@ -1487,6 +1494,7 @@ Downloader.prototype = {
|
|||
this._update.state = state;
|
||||
var um = Components.classes["@mozilla.org/updates/update-manager;1"]
|
||||
.getService(Components.interfaces.nsIUpdateManager);
|
||||
um.activeUpdate = null;
|
||||
um.saveUpdates();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче