mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-29 19:13:49 +01:00
Merge pull request #1790 from alainbryden/1773-dont-append-js-to-all-script-files
#1773 - Fix duplicate file extensions
This commit is contained in:
commit
1a06b25ff7
@ -56,7 +56,7 @@ export class Script {
|
|||||||
* Download the script as a file
|
* Download the script as a file
|
||||||
*/
|
*/
|
||||||
download(): void {
|
download(): void {
|
||||||
const filename = this.filename + ".js";
|
const filename = this.filename;
|
||||||
const file = new Blob([this.code], { type: "text/plain" });
|
const file = new Blob([this.code], { type: "text/plain" });
|
||||||
const navigator = window.navigator as any;
|
const navigator = window.navigator as any;
|
||||||
if (navigator.msSaveOrOpenBlob) {
|
if (navigator.msSaveOrOpenBlob) {
|
||||||
|
@ -19,43 +19,29 @@ export function download(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fn = args[0] + "";
|
const fn = args[0] + "";
|
||||||
if (fn === "*" || fn === "*.script" || fn === "*.txt") {
|
// If the parameter starts with *, download all files that match the wildcard pattern
|
||||||
// Download all scripts as a zip
|
if (fn.startsWith("*")) {
|
||||||
|
const matchEnding = fn.length == 1 || fn === "*.*" ? null : fn.slice(1); // Treat *.* the same as *
|
||||||
const zip = new JSZip();
|
const zip = new JSZip();
|
||||||
if (fn === "*" || fn === "*.script") {
|
// Helper function to zip any file contents whose name matches the pattern
|
||||||
for (let i = 0; i < server.scripts.length; ++i) {
|
let zipFiles = (fileNames: string[], fileContents: string[]) => {
|
||||||
const file = new Blob([server.scripts[i].code], {
|
for (let i = 0; i < fileContents.length; ++i) {
|
||||||
type: "text/plain",
|
let name = fileNames[i];
|
||||||
});
|
if (name.startsWith("/")) name = name.slice(1);
|
||||||
let name = server.scripts[i].filename;
|
if (!matchEnding || name.endsWith(matchEnding))
|
||||||
if (name.startsWith("/")) {
|
zip.file(name, new Blob([fileContents[i]], { type: "text/plain" }));
|
||||||
name = name.slice(1);
|
|
||||||
}
|
|
||||||
zip.file(name + ".js", file);
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
if (fn === "*" || fn === "*.txt") {
|
// In the case of script files, we pull from the server.scripts array
|
||||||
for (let i = 0; i < server.textFiles.length; ++i) {
|
if (!matchEnding || isScriptFilename(matchEnding))
|
||||||
const file = new Blob([server.textFiles[i].text], {
|
zipFiles(server.scripts.map(s => s.filename), server.scripts.map(s => s.code));
|
||||||
type: "text/plain",
|
// In the case of text files, we pull from the server.scripts array
|
||||||
});
|
if (!matchEnding || matchEnding.endsWith(".txt"))
|
||||||
zip.file(server.textFiles[i].fn, file);
|
zipFiles(server.textFiles.map(s => s.fn), server.textFiles.map(s => s.text));
|
||||||
}
|
// Return an error if no files matched, rather than an empty zip folder
|
||||||
}
|
if (Object.keys(zip.files).length == 0)
|
||||||
|
return terminal.error(`No files match the pattern ${fn}`);
|
||||||
let zipFn = "";
|
const zipFn = `bitburner${isScriptFilename(fn) ? "Scripts" : fn === "*.txt" ? "Texts" : "Files"}.zip`;
|
||||||
switch (fn) {
|
|
||||||
case "*.script":
|
|
||||||
zipFn = "bitburnerScripts.zip";
|
|
||||||
break;
|
|
||||||
case "*.txt":
|
|
||||||
zipFn = "bitburnerTexts.zip";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
zipFn = "bitburnerFiles.zip";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
zip.generateAsync({ type: "blob" }).then((content: any) => FileSaver.saveAs(content, zipFn));
|
zip.generateAsync({ type: "blob" }).then((content: any) => FileSaver.saveAs(content, zipFn));
|
||||||
return;
|
return;
|
||||||
} else if (isScriptFilename(fn)) {
|
} else if (isScriptFilename(fn)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user