mod enabling and disabling

This commit is contained in:
SpikeHD
2022-07-25 20:25:43 -07:00
parent c99080168c
commit 9566beaf29
5 changed files with 107 additions and 12 deletions

View File

@@ -1,3 +1,4 @@
import { invoke } from '@tauri-apps/api'
import { getConfigOption } from './configuration'
export async function getModsFolder() {
@@ -11,3 +12,60 @@ export async function getModsFolder() {
return pathArr.join('/') + '/Mods/'
}
export async function disableMod(modId: string) {
const path = (await getModsFolder()) + modId
const pathExists = await invoke('dir_exists', {
path,
})
if (!pathExists) return console.log("Path doesn't exist")
const modName = path.replace(/\\/g, '/').split('/').pop()
await invoke('rename', {
path,
newName: `DISABLED_${modName}`,
})
}
export async function enableMod(modId: string) {
const path = (await getModsFolder()) + `DISABLED_${modId}`
const modName = path.replace(/\\/g, '/').split('/').pop()
const pathExists = await invoke('dir_exists', {
path,
})
if (!pathExists) return console.log("Path doesn't exist")
if (!modName?.includes('DISABLED_')) return
const newName = modName.replace('DISABLED_', '')
await invoke('rename', {
path,
newName,
})
}
export async function getModFolderName(modId: string) {
const modsFolder = await getModsFolder()
if (!modsFolder) return null
const modEnabled = await invoke('dir_exists', {
path: modsFolder + modId,
})
const modDisabled = await invoke('dir_exists', {
path: modsFolder + 'DISABLED_' + modId,
})
if (!modEnabled && !modDisabled) return null
if (modEnabled) return modId
if (modDisabled) return 'DISABLED_' + modId
}
export async function modIsEnabled(modId: string) {
return !(await getModFolderName(modId))?.includes('DISABLED_')
}