From bd371b56e13dc99346e8b4aaea2a7adfabcaad89 Mon Sep 17 00:00:00 2001 From: silentrald Date: Thu, 5 Sep 2024 09:37:32 +0800 Subject: [PATCH] [bugfix-560] don't move old installation path if it doesn't exist --- src/main/ipcs/bs-installer-ipcs.ts | 2 +- .../services/installation-location.service.ts | 16 ++++++++++------ src/renderer/pages/settings-page.component.tsx | 2 +- .../services/installation-location.service.ts | 10 ++++++++-- src/renderer/services/setup.service.ts | 2 +- src/shared/models/ipc/ipc-routes.ts | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/ipcs/bs-installer-ipcs.ts b/src/main/ipcs/bs-installer-ipcs.ts index 25672b13..893b697e 100644 --- a/src/main/ipcs/bs-installer-ipcs.ts +++ b/src/main/ipcs/bs-installer-ipcs.ts @@ -23,5 +23,5 @@ ipc.on("bs-installer.install-path", (_, reply) => { ipc.on("bs-installer.set-install-path", (args, reply) => { const service = InstallationLocationService.getInstance(); - reply(from(service.setInstallationDirectory(args))); + reply(from(service.setInstallationDirectory(args.path, args.move))); }); diff --git a/src/main/services/installation-location.service.ts b/src/main/services/installation-location.service.ts index 1696ea0d..6acb0ace 100644 --- a/src/main/services/installation-location.service.ts +++ b/src/main/services/installation-location.service.ts @@ -40,18 +40,22 @@ export class InstallationLocationService { this.updateListeners.forEach(listener => listener()); } - public async setInstallationDirectory(newDir: string): Promise { + /** + * @param move - if true, move the old installation path to the path param + */ + public async setInstallationDirectory(newDir: string, move: boolean): Promise { newDir = path.basename(newDir) === this.INSTALLATION_FOLDER ? path.join(newDir, "..") : newDir; - const oldDir = this.installationDirectory(); - await ensureFolderExist(oldDir); - await copyDirectoryWithJunctions(oldDir, path.join(newDir, this.INSTALLATION_FOLDER), { overwrite: true }); + if (move) { + const oldDir = this.installationDirectory(); + await ensureFolderExist(oldDir); + await copyDirectoryWithJunctions(oldDir, path.join(newDir, this.INSTALLATION_FOLDER), { overwrite: true }); + deleteFolder(oldDir); + } this._installationDirectory = newDir; this.staticConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir); - deleteFolder(oldDir); - return this.installationDirectory(); } diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index 1cea476e..f7a1fd1b 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -204,7 +204,7 @@ export function SettingsPage() { notificationService.notifySuccess({ title: "notifications.settings.move-folder.success.titles.transfer-started", desc: "notifications.settings.move-folder.success.descs.transfer-started" }); - lastValueFrom(installationLocationService.setInstallationFolder(fileChooserRes.filePaths[0])).then(res => { + lastValueFrom(installationLocationService.setInstallationFolder(fileChooserRes.filePaths[0], true)).then(res => { progressBarService.complete(); progressBarService.hide(true); diff --git a/src/renderer/services/installation-location.service.ts b/src/renderer/services/installation-location.service.ts index db1d01ad..45445e07 100644 --- a/src/renderer/services/installation-location.service.ts +++ b/src/renderer/services/installation-location.service.ts @@ -23,7 +23,13 @@ export class InstallationLocationService { return lastValueFrom(this.ipcService.sendV2("bs-installer.install-path")); } - public setInstallationFolder(path: string): Observable { - return this.ipcService.sendV2("bs-installer.set-install-path", path); + /** + * @param move - if true, move the old installation path to the path param + */ + public setInstallationFolder(path: string, move: boolean): Observable { + return this.ipcService.sendV2( + "bs-installer.set-install-path", + { path, move } + ); } } diff --git a/src/renderer/services/setup.service.ts b/src/renderer/services/setup.service.ts index c88f3c97..5bb38f18 100644 --- a/src/renderer/services/setup.service.ts +++ b/src/renderer/services/setup.service.ts @@ -52,7 +52,7 @@ export class SetupService { { closable: false } ); - await lastValueFrom(this.installationLocationService.setInstallationFolder(modalResponse.data.installPath)); + await lastValueFrom(this.installationLocationService.setInstallationFolder(modalResponse.data.installPath, false)); // Refresh the versions tab await this.versionManagerService.askInstalledVersions(); diff --git a/src/shared/models/ipc/ipc-routes.ts b/src/shared/models/ipc/ipc-routes.ts index b7871cdd..b145955f 100644 --- a/src/shared/models/ipc/ipc-routes.ts +++ b/src/shared/models/ipc/ipc-routes.ts @@ -46,7 +46,7 @@ export interface IpcChannelMapping { "bs-installer.folder-exists": { request: void, response: boolean }; "bs-installer.default-install-path": { request: void, response: string }; "bs-installer.install-path": { request: void, response: string}; - "bs-installer.set-install-path": { request: string, response: string}; + "bs-installer.set-install-path": { request: { path: string, move: boolean }, response: string}; /* ** bs-launcher-ipcs ** */ "create-launch-shortcut": { request: LaunchOption, response: boolean };