From 6d1fe87fe2d600e6e9333146373f640cdea202ac Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Sun, 24 Nov 2024 21:18:05 +0800 Subject: [PATCH] fix profile path --- src/main/config/profile.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 4c0e600..e76b128 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -1,5 +1,5 @@ import { getControledMihomoConfig } from './controledMihomo' -import { mihomoProfileWorkDir, profileConfigPath, profilePath } from '../utils/dirs' +import { mihomoProfileWorkDir, mihomoWorkDir, profileConfigPath, profilePath } from '../utils/dirs' import { addProfileUpdater } from '../core/profileUpdater' import { readFile, rm, writeFile } from 'fs/promises' import { restartCore } from '../core/manager' @@ -9,6 +9,7 @@ import axios, { AxiosResponse } from 'axios' import yaml from 'yaml' import { defaultProfile } from '../utils/template' import { subStorePort } from '../resolve/server' +import { join } from 'path' let profileConfig: IProfileConfig // profile.yaml @@ -226,17 +227,28 @@ function isAbsolutePath(path: string): boolean { } export async function getFileStr(path: string): Promise { + const { diffWorkDir = false } = await getAppConfig() + const { current } = await getProfileConfig() if (isAbsolutePath(path)) { return await readFile(path, 'utf-8') } else { - return await readFile(mihomoProfileWorkDir(path), 'utf-8') + return await readFile( + join(diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), path), + 'utf-8' + ) } } export async function setFileStr(path: string, content: string): Promise { + const { diffWorkDir = false } = await getAppConfig() + const { current } = await getProfileConfig() if (isAbsolutePath(path)) { await writeFile(path, content, 'utf-8') } else { - await writeFile(mihomoProfileWorkDir(path), content, 'utf-8') + await writeFile( + join(diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), path), + content, + 'utf-8' + ) } }