2021-09-15 03:47:42 +02:00
|
|
|
import React from "react";
|
2021-10-07 22:56:01 +02:00
|
|
|
import { GetServer, GetAllServers } from "../Server/AllServers";
|
2021-09-15 03:47:42 +02:00
|
|
|
import { Modal } from "../ui/React/Modal";
|
2023-02-11 19:18:50 +01:00
|
|
|
import { formatBigNumber } from "../ui/formatNumber";
|
2021-09-15 03:47:42 +02:00
|
|
|
|
2021-09-17 01:23:03 +02:00
|
|
|
import Table from "@mui/material/Table";
|
|
|
|
import TableBody from "@mui/material/TableBody";
|
|
|
|
import TableCell from "@mui/material/TableCell";
|
|
|
|
import TableContainer from "@mui/material/TableContainer";
|
|
|
|
import TableHead from "@mui/material/TableHead";
|
|
|
|
import TableRow from "@mui/material/TableRow";
|
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
import Paper from "@mui/material/Paper";
|
|
|
|
import Accordion from "@mui/material/Accordion";
|
|
|
|
import AccordionSummary from "@mui/material/AccordionSummary";
|
|
|
|
import AccordionDetails from "@mui/material/AccordionDetails";
|
|
|
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
2023-04-18 09:19:45 +02:00
|
|
|
import { ServerName } from "../Types/strings";
|
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).
2023-04-24 16:26:57 +02:00
|
|
|
import { allContentFiles } from "../Paths/ContentFile";
|
2021-09-15 03:47:42 +02:00
|
|
|
|
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).
2023-04-24 16:26:57 +02:00
|
|
|
interface File {
|
|
|
|
name: string;
|
|
|
|
size: number;
|
2021-09-15 03:47:42 +02:00
|
|
|
}
|
|
|
|
|
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).
2023-04-24 16:26:57 +02:00
|
|
|
function ServerAccordion(props: { hostname: ServerName }): React.ReactElement {
|
2021-10-07 23:55:49 +02:00
|
|
|
const server = GetServer(props.hostname);
|
2021-11-22 17:36:13 +01:00
|
|
|
if (server === null) throw new Error(`server '${props.hostname}' should not be null`);
|
2021-09-15 03:47:42 +02:00
|
|
|
let totalSize = 0;
|
|
|
|
const files: File[] = [];
|
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).
2023-04-24 16:26:57 +02:00
|
|
|
for (const [path, file] of allContentFiles(server)) {
|
|
|
|
totalSize += file.content.length;
|
|
|
|
files.push({ name: path, size: file.content.length });
|
2021-09-15 03:47:42 +02:00
|
|
|
}
|
|
|
|
|
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).
2023-04-24 16:26:57 +02:00
|
|
|
if (totalSize === 0) return <></>;
|
2021-09-15 03:47:42 +02:00
|
|
|
|
|
|
|
files.sort((a: File, b: File): number => b.size - a.size);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Accordion TransitionProps={{ unmountOnExit: true }}>
|
|
|
|
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
|
|
|
<Typography>
|
2023-02-11 19:18:50 +01:00
|
|
|
{server.hostname} ({formatBigNumber(totalSize)}b)
|
2021-09-15 03:47:42 +02:00
|
|
|
</Typography>
|
|
|
|
</AccordionSummary>
|
|
|
|
<AccordionDetails>
|
|
|
|
<TableContainer component={Paper}>
|
|
|
|
<Table>
|
|
|
|
<TableHead>
|
|
|
|
<TableRow>
|
|
|
|
<TableCell>
|
|
|
|
<Typography>Filename</Typography>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell align="right">
|
|
|
|
<Typography>Size</Typography>
|
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
</TableHead>
|
|
|
|
<TableBody>
|
|
|
|
{files.map((file: File) => (
|
|
|
|
<TableRow key={file.name}>
|
|
|
|
<TableCell component="th" scope="row">
|
|
|
|
<Typography>{file.name}</Typography>
|
|
|
|
</TableCell>
|
|
|
|
<TableCell align="right">
|
2023-02-11 19:18:50 +01:00
|
|
|
<Typography>{formatBigNumber(file.size)}b</Typography>
|
2021-09-15 03:47:42 +02:00
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
|
|
|
))}
|
|
|
|
</TableBody>
|
|
|
|
</Table>
|
|
|
|
</TableContainer>
|
|
|
|
<ul></ul>
|
|
|
|
</AccordionDetails>
|
|
|
|
</Accordion>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
open: boolean;
|
|
|
|
onClose: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function FileDiagnosticModal(props: IProps): React.ReactElement {
|
2021-10-07 22:04:04 +02:00
|
|
|
const keys: string[] = [];
|
2021-11-22 17:36:13 +01:00
|
|
|
for (const key of GetAllServers()) {
|
|
|
|
keys.push(key.hostname);
|
2021-09-15 03:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal open={props.open} onClose={props.onClose}>
|
|
|
|
<>
|
|
|
|
<Typography>
|
|
|
|
Welcome to the file diagnostic! If your save file is really big it's likely because you have too many
|
|
|
|
text/scripts. This tool can help you narrow down where they are.
|
|
|
|
</Typography>
|
2021-10-07 23:55:49 +02:00
|
|
|
{keys.map((hostname: string) => (
|
|
|
|
<ServerAccordion key={hostname} hostname={hostname} />
|
2021-09-15 03:47:42 +02:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|