mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-30 03:23:48 +01:00
Merge pull request #1993 from Nick-Colclasure/file-read-patch
Fix problems finding root files in cat and ns.read
This commit is contained in:
commit
3255768259
@ -16,7 +16,8 @@ export function cat(
|
|||||||
terminal.error("Incorrect usage of cat command. Usage: cat [file]");
|
terminal.error("Incorrect usage of cat command. Usage: cat [file]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const filename = terminal.getFilepath(args[0] + "");
|
const relative_filename = args[0] + "";
|
||||||
|
const filename = terminal.getFilepath(relative_filename);
|
||||||
if (!filename.endsWith(".msg") && !filename.endsWith(".lit") && !filename.endsWith(".txt")) {
|
if (!filename.endsWith(".msg") && !filename.endsWith(".lit") && !filename.endsWith(".txt")) {
|
||||||
terminal.error(
|
terminal.error(
|
||||||
"Only .msg, .txt, and .lit files are viewable with cat (filename must end with .msg, .txt, or .lit)",
|
"Only .msg, .txt, and .lit files are viewable with cat (filename must end with .msg, .txt, or .lit)",
|
||||||
@ -39,7 +40,7 @@ export function cat(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (filename.endsWith(".txt")) {
|
} else if (filename.endsWith(".txt")) {
|
||||||
const txt = terminal.getTextFile(player, filename);
|
const txt = terminal.getTextFile(player, relative_filename);
|
||||||
if (txt != null) {
|
if (txt != null) {
|
||||||
txt.show();
|
txt.show();
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
||||||
import { BaseServer } from "./Server/BaseServer";
|
import { BaseServer } from "./Server/BaseServer";
|
||||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "./utils/JSONReviver";
|
import { Generic_fromJSON, Generic_toJSON, Reviver } from "./utils/JSONReviver";
|
||||||
|
import { removeLeadingSlash, isInRootDirectory } from "./Terminal/DirectoryHelpers"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a plain text file that is typically stored on a server.
|
* Represents a plain text file that is typically stored on a server.
|
||||||
@ -101,7 +102,11 @@ Reviver.constructors.TextFile = TextFile;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export function getTextFile(fn: string, server: BaseServer): TextFile | null {
|
export function getTextFile(fn: string, server: BaseServer): TextFile | null {
|
||||||
const filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
|
let filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
|
||||||
|
|
||||||
|
if (isInRootDirectory(filename)) {
|
||||||
|
filename = removeLeadingSlash(filename);
|
||||||
|
}
|
||||||
|
|
||||||
for (const file of server.textFiles as TextFile[]) {
|
for (const file of server.textFiles as TextFile[]) {
|
||||||
if (file.fn === filename) {
|
if (file.fn === filename) {
|
||||||
|
Loading…
Reference in New Issue
Block a user