MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / toggleMod

Method toggleMod

daemon/src/service/mod_service.ts:317–350  ·  view source on GitHub ↗
(instanceUuid: string, fileName: string)

Source from the content-addressed store, hash-verified

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)!;

Callers 1

Instance_router.tsFile · 0.80

Calls 6

checkPathMethod · 0.95
toAbsolutePathMethod · 0.95
resolveMCDRServerRootFunction · 0.90
absoluteCwdPathMethod · 0.80
renameMethod · 0.80
getInstanceMethod · 0.45

Tested by

no test coverage detected