mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 03:31:24 +08:00
* feat: Implement occupied directories handling during data copy - Added `occupiedDirs` constant to manage directories that should not be copied. - Enhanced the `copyOccupiedDirsInMainProcess` function to copy occupied directories to a new app data path in the main process. - Updated IPC and preload APIs to support passing occupied directories during the copy operation. - Modified the DataSettings component to utilize the new copy functionality with occupied directories. * fix: Improve occupied directories handling during data copy - Updated the filter logic in the `registerIpc` function to resolve directory paths correctly. - Modified the `DataSettings` component to pass the correct occupied directories format during the copy operation.
34 lines
979 B
TypeScript
34 lines
979 B
TypeScript
import { occupiedDirs } from '@shared/config/constant'
|
||
import { app } from 'electron'
|
||
import fs from 'fs'
|
||
import path from 'path'
|
||
|
||
import { initAppDataDir } from './utils/file'
|
||
|
||
app.isPackaged && initAppDataDir()
|
||
|
||
// 在主进程中复制 appData 中某些一直被占用的文件
|
||
// 在renderer进程还没有启动时,主进程可以复制这些文件到新的appData中
|
||
function copyOccupiedDirsInMainProcess() {
|
||
const newAppDataPath = process.argv
|
||
.slice(1)
|
||
.find((arg) => arg.startsWith('--new-data-path='))
|
||
?.split('--new-data-path=')[1]
|
||
if (!newAppDataPath) {
|
||
return
|
||
}
|
||
|
||
if (process.platform === 'win32') {
|
||
const appDataPath = app.getPath('userData')
|
||
occupiedDirs.forEach((dir) => {
|
||
const dirPath = path.join(appDataPath, dir)
|
||
const newDirPath = path.join(newAppDataPath, dir)
|
||
if (fs.existsSync(dirPath)) {
|
||
fs.cpSync(dirPath, newDirPath, { recursive: true })
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
copyOccupiedDirsInMainProcess()
|