mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 09:04:45 +01:00
mod enabling and disabling
This commit is contained in:
@@ -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_')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user