-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from MaaAssistantArknights/feat/component-dir…
…-customize feat: 组件卸载和组件安装位置移动(实验性功能)
- Loading branch information
Showing
19 changed files
with
314 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Storage from '@main/storageManager' | ||
import { getAppBaseDir } from '@main/utils/path' | ||
import { getComponentAdb } from '../components/adb' | ||
import { getComponentCore } from '../components/core' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import CoreLoader from '@main/coreLoader' | ||
import _ from 'lodash' | ||
import logger from '@main/utils/logger' | ||
|
||
export function getComponentBaseDir() { | ||
const storage = new Storage() | ||
const componentDir = storage.get('setting.componentDir') as string | ||
|
||
return _.isEmpty(componentDir) ? getAppBaseDir() : componentDir | ||
} | ||
|
||
export async function moveComponentBaseDir(dir: string): Promise<boolean> { | ||
let withError = false | ||
const coreLoader = new CoreLoader() | ||
const coreStatus = coreLoader.loadStatus | ||
if (coreStatus) { | ||
coreLoader.dispose() | ||
} | ||
|
||
const sourceBaseDir = getComponentBaseDir() | ||
const adbComponent = await getComponentAdb() | ||
const coreComponent = await getComponentCore() | ||
const adbSourceDir = path.join(sourceBaseDir, adbComponent.installer!.componentDir) | ||
const coreSourceDir = path.join(sourceBaseDir, coreComponent.installer!.componentDir) | ||
|
||
const adbTargetDir = path.join(dir, adbComponent.installer!.componentDir) | ||
const coreTargetDir = path.join(dir, coreComponent.installer!.componentDir) | ||
|
||
fs.mkdirSync(dir, { recursive: true }) | ||
|
||
if (fs.existsSync(adbSourceDir)) { | ||
await fs.promises.cp(adbSourceDir, adbTargetDir, { recursive: true }) | ||
try { | ||
await fs.promises.rm(adbSourceDir, { recursive: true }) | ||
} catch (e) { | ||
withError = true | ||
logger.error(e) | ||
} | ||
} | ||
if (fs.existsSync(coreSourceDir)) { | ||
await fs.promises.cp(coreSourceDir, coreTargetDir, { recursive: true }) | ||
try { | ||
await fs.promises.rm(coreSourceDir, { recursive: true }) | ||
} catch (e) { | ||
withError = true | ||
logger.error(e) | ||
} | ||
} | ||
return withError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { openFolder, openExternal, saveTempJson } from '@main/utils/path' | ||
import { moveComponentBaseDir } from '@main/componentManager/utils/path' | ||
|
||
export default function usePathHooks(): void { | ||
globalThis.main.Util = { | ||
openFolder, | ||
openExternal, | ||
saveTempJson, | ||
moveComponentBaseDir, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.