Changed save.js, fdc.js, and diskdump.js to use a shared download function

This commit is contained in:
Jeff Parsons 2016-02-23 00:06:38 -08:00
commit 255700f88a
7 changed files with 1332 additions and 1337 deletions

View file

@ -477,19 +477,8 @@ FDC.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
if (drive) {
if (drive.disk) {
if (DEBUG) fdc.println("saving disk " + drive.disk.sDiskPath + "...");
var sURI = "data:application/octet-stream;base64," + drive.disk.encodeAsBase64();
var link = document.createElement('a');
var sFileName = drive.disk.sDiskFile.replace(".json", ".img");
if (typeof link.download == 'string') {
link.href = sURI;
link.download = sFileName;
document.body.appendChild(link); // Firefox requires the link to be in the body
link.click();
document.body.removeChild(link);
} else {
window.open(sURI);
web.alertUser('The disk is being downloaded, but you will need to manually rename it to "' + sFileName + '".');
}
var sAlert = web.downloadFile(drive.disk.encodeAsBase64(), "octet-stream", true, drive.disk.sDiskFile.replace(".json", ".img"));
web.alertUser(sAlert);
} else {
fdc.notice("No disk loaded in drive");
}