(instanceUuid: string, fileName: string)
| 315 | } |
| 316 | |
| 317 | public async toggleMod(instanceUuid: string, fileName: string): Promise<void> { |
| 318 | const instance = InstanceSubsystem.getInstance(instanceUuid)!; |
| 319 | const cwd = instance.absoluteCwdPath(); |
| 320 | const fileManager = new FileManager( |
| 321 | resolveMCDRServerRoot(instance.config.type, cwd) ?? cwd, |
| 322 | instance.config?.fileCode |
| 323 | ); |
| 324 | if (!fileManager.checkPath(fileName)) throw new Error("Invalid file name"); |
| 325 | const rootDir = fileManager.toAbsolutePath("."); |
| 326 | |
| 327 | const possibleDirs = ["mods", "plugins", "Mods", "Plugins"]; |
| 328 | let filePath = ""; |
| 329 | |
| 330 | for (const dirName of possibleDirs) { |
| 331 | const p = path.join(rootDir, dirName, fileName); |
| 332 | if (await fs.pathExists(p)) { |
| 333 | filePath = p; |
| 334 | break; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | if (!filePath) { |
| 339 | throw new Error("File not found"); |
| 340 | } |
| 341 | |
| 342 | let newPath: string; |
| 343 | if (fileName.endsWith(".disabled")) { |
| 344 | newPath = filePath.replace(".disabled", ""); |
| 345 | } else { |
| 346 | newPath = filePath + ".disabled"; |
| 347 | } |
| 348 | |
| 349 | await fs.rename(filePath, newPath); |
| 350 | } |
| 351 | |
| 352 | public async deleteMod(instanceUuid: string, fileName: string): Promise<void> { |
| 353 | const instance = InstanceSubsystem.getInstance(instanceUuid)!; |
no test coverage detected