FILES: Path rework & typesafety (#479)

* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
This commit is contained in:
Snarling
2023-04-24 10:26:57 -04:00
committed by GitHub
parent 6f56f35943
commit e0272ad4af
93 changed files with 3293 additions and 4297 deletions
+9 -26
View File
@@ -16,41 +16,24 @@ import AccordionSummary from "@mui/material/AccordionSummary";
import AccordionDetails from "@mui/material/AccordionDetails";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import { ServerName } from "../Types/strings";
import { allContentFiles } from "../Paths/ContentFile";
interface IServerProps {
hostname: ServerName;
interface File {
name: string;
size: number;
}
function ServerAccordion(props: IServerProps): React.ReactElement {
function ServerAccordion(props: { hostname: ServerName }): React.ReactElement {
const server = GetServer(props.hostname);
if (server === null) throw new Error(`server '${props.hostname}' should not be null`);
let totalSize = 0;
for (const f of server.scripts.values()) {
totalSize += f.code.length;
}
for (const f of server.textFiles) {
totalSize += f.text.length;
}
if (totalSize === 0) {
return <></>;
}
interface File {
name: string;
size: number;
}
const files: File[] = [];
for (const f of server.scripts.values()) {
files.push({ name: f.filename, size: f.code.length });
for (const [path, file] of allContentFiles(server)) {
totalSize += file.content.length;
files.push({ name: path, size: file.content.length });
}
for (const f of server.textFiles) {
files.push({ name: f.fn, size: f.text.length });
}
if (totalSize === 0) return <></>;
files.sort((a: File, b: File): number => b.size - a.size);