mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 12:45:45 +01:00
fileExists no longer case sensitive for programs
This commit is contained in:
parent
ad3b217b8f
commit
8bf13b6fd3
@ -17,7 +17,7 @@ fileExists(filename: string, host?: string): boolean;
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| filename | string | Filename of file to check. |
|
||||
| host | string | _(Optional)_ Host of target server. This is optional. If it is not specified then the function will use the current server as the target server. |
|
||||
| host | string | _(Optional)_ Host of target server. Optional, defaults to the server the script is running on. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
@ -29,9 +29,7 @@ True if specified file exists, and false otherwise.
|
||||
|
||||
RAM cost: 0.1 GB
|
||||
|
||||
Returns a boolean indicating whether the specified file exists on the target server. The filename for scripts is case-sensitive, but for other types of files it is not. For example, fileExists(“brutessh.exe”) will work fine, even though the actual program is named 'BruteSSH.exe'.
|
||||
|
||||
If the hostname/ip argument is omitted, then the function will search through the current server (the server running the script that calls this function) for the file.
|
||||
Returns a boolean indicating whether the specified file exists on the target server. The filename for programs is case insensitive, other file types are case sensitive. For example, fileExists(“brutessh.exe”) will work fine, even though the actual program is named 'BruteSSH.exe'.
|
||||
|
||||
\*
|
||||
|
||||
|
@ -1125,21 +1125,19 @@ export const ns: InternalAPI<NSFull> = {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
return GetServer(hostname) !== null;
|
||||
},
|
||||
fileExists:
|
||||
(ctx) =>
|
||||
(_filename, _hostname = ctx.workerScript.hostname) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
const path = resolveFilePath(filename, ctx.workerScript.name);
|
||||
if (!path) return false;
|
||||
if (hasScriptExtension(path)) return server.scripts.has(path);
|
||||
if (hasTextExtension(path)) return server.textFiles.has(path);
|
||||
if (hasProgramExtension(path)) return server.programs.includes(path);
|
||||
if (path.endsWith(".lit") || path.endsWith(".msg")) return server.messages.includes(path as any);
|
||||
if (hasContractExtension(path)) return !!server.contracts.find(({ fn }) => fn === path);
|
||||
return false;
|
||||
},
|
||||
fileExists: (ctx) => (_filename, _hostname) => {
|
||||
const filename = helpers.string(ctx, "filename", _filename);
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname ?? ctx.workerScript.hostname);
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
const path = resolveFilePath(filename, ctx.workerScript.name);
|
||||
if (!path) return false;
|
||||
if (hasScriptExtension(path)) return server.scripts.has(path);
|
||||
if (hasTextExtension(path)) return server.textFiles.has(path);
|
||||
if (path.endsWith(".lit") || path.endsWith(".msg")) return server.messages.includes(path as any);
|
||||
if (hasContractExtension(path)) return !!server.contracts.find(({ fn }) => fn === path);
|
||||
const lowerPath = path.toLowerCase();
|
||||
return server.programs.map((programName) => programName.toLowerCase()).includes(lowerPath);
|
||||
},
|
||||
isRunning:
|
||||
(ctx) =>
|
||||
(fn, hostname, ...scriptArgs) => {
|
||||
|
7
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
7
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5750,13 +5750,10 @@ export interface NS {
|
||||
* RAM cost: 0.1 GB
|
||||
*
|
||||
* Returns a boolean indicating whether the specified file exists on the target server.
|
||||
* The filename for scripts is case-sensitive, but for other types of files it is not.
|
||||
* The filename for programs is case insensitive, other file types are case sensitive.
|
||||
* For example, fileExists(“brutessh.exe”) will work fine, even though the actual program
|
||||
* is named 'BruteSSH.exe'.
|
||||
*
|
||||
* If the hostname/ip argument is omitted, then the function will search through the current
|
||||
* server (the server running the script that calls this function) for the file.
|
||||
*
|
||||
* * @example
|
||||
* ```js
|
||||
* // The function call will return true if the script named foo.js exists on the foodnstuff server, and false otherwise.
|
||||
@ -5766,7 +5763,7 @@ export interface NS {
|
||||
* ns.fileExists("ftpcrack.exe");
|
||||
* ```
|
||||
* @param filename - Filename of file to check.
|
||||
* @param host - Host of target server. This is optional. If it is not specified then the function will use the current server as the target server.
|
||||
* @param host - Host of target server. Optional, defaults to the server the script is running on.
|
||||
* @returns True if specified file exists, and false otherwise.
|
||||
*/
|
||||
fileExists(filename: string, host?: string): boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user