Skip to content

Commit 7c75e74

Browse files
committed
Support upload of existing discs (sort of) See #488
1 parent 91a1be2 commit 7c75e74

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

index.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ <h5 class="modal-title" id="google-driveModalLabel">
622622
<div>
623623
<form class="well" role="form" action="#">
624624
<input type="text" placeholder="Create disc..." autofocus class="disc-name" />
625+
<label class="checkbox-inline">
626+
<input type="checkbox" class="create-from-existing" value="" />
627+
Use current disc image
628+
</label>
625629
<button type="submit" class="btn btn-secondary create-button">Create</button>
626630
</form>
627631
</div>
@@ -654,7 +658,7 @@ <h5 class="modal-title loading" id="loadingModalLabel"></h5>
654658
Google Drive requires you to authorize jsbeeb to access your files by logging in.<br />
655659
Please click Authorize to open a Google Drive pop-up to authenticate and give permission to jsbeeb.
656660
<form class="well" role="form" action="#">
657-
<button type="submit" class="btn btn-secondary create-button">Authorize</button>
661+
<button type="submit" class="btn btn-secondary">Authorize</button>
658662
</form>
659663
</div>
660664
</div>

src/google-drive.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,8 @@ export class GoogleDriveLoader {
128128
});
129129
}
130130

131-
async create(fdc, name) {
131+
async create(fdc, name, data) {
132132
console.log(`Google Drive: creating disc image: '${name}'`);
133-
const byteSize = utils.discImageSize(name).byteSize;
134-
const data = new Uint8Array(byteSize);
135-
utils.setDiscName(data, name);
136133
const response = await this.saveFile(name, data);
137134
const meta = response.result;
138135
return { fileId: meta.id, disc: this.makeDisc(fdc, data, meta) };

src/main.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1019,16 +1019,29 @@ $.each(availableImages, function (i, image) {
10191019

10201020
$("#google-drive form").on("submit", async function (e) {
10211021
e.preventDefault();
1022-
const text = $("#google-drive .disc-name").val();
1023-
if (!text) return;
1022+
let name = $("#google-drive .disc-name").val();
1023+
if (!name) return;
10241024

10251025
popupLoading("Connecting to Google Drive");
10261026
$googleDriveModal.hide();
1027-
popupLoading("Creating '" + text + "' on Google Drive");
1027+
popupLoading("Creating '" + name + "' on Google Drive");
1028+
1029+
let data;
1030+
if ($("#google-drive .create-from-existing").prop("checked")) {
1031+
const disc = processor.fdc.drives[0].disc;
1032+
data = toSsdOrDsd(disc);
1033+
name = name.substring(0, name.lastIndexOf(".")) + (disc.isDoubleSided ? ".dsd" : ".ssd");
1034+
console.log(`Saving existing disc: ${name}`);
1035+
} else {
1036+
const byteSize = utils.discImageSize(name).byteSize;
1037+
data = new Uint8Array(byteSize);
1038+
utils.setDiscName(data, name);
1039+
console.log(`Creating blank: ${name}`);
1040+
}
10281041

10291042
try {
1030-
const result = await googleDrive.create(processor.fdc, text);
1031-
setDisc1Image("gd:" + result.fileId + "/" + text);
1043+
const result = await googleDrive.create(processor.fdc, name, data);
1044+
setDisc1Image("gd:" + result.fileId + "/" + name);
10321045
processor.fdc.loadDisc(0, result.disc);
10331046
loadingFinished();
10341047
} catch (error) {

0 commit comments

Comments
 (0)