SDA-3800 (Backup and overwrite global config to persist data) (#1469)

* SDA-3800 - Copy and replace global config

* SDA-3800 - Copy and replace global config - macOS
This commit is contained in:
Kiran Niranjan 2022-08-10 06:32:52 +05:30 committed by GitHub
parent 50b7276ea8
commit c36c71d6e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 0 deletions

View File

@ -19,11 +19,32 @@ Function uninstallSymphony
done: done:
FunctionEnd FunctionEnd
!macro copySystemGlobalConfig
IfFileExists $PROGRAMFILES64\Symphony\Symphony\config\Symphony.config 0 +2
CopyFiles /SILENT $PROGRAMFILES64\Symphony\Symphony\config\Symphony.config $WINDIR\Temp\temp-sys-Symphony.config
!macroend
!macro copyLocalGlobalConfig
IfFileExists $LOCALAPPDATA\Symphony\Symphony\config\Symphony.config 0 +2
CopyFiles /SILENT $LOCALAPPDATA\Symphony\Symphony\config\Symphony.config $WINDIR\Temp\temp-local-Symphony.config
!macroend
!macro replaceSystemGlobalConfig
IfFileExists $WINDIR\Temp\temp-sys-Symphony.config 0 +2
CopyFiles /SILENT $WINDIR\Temp\temp-sys-Symphony.config $PROGRAMFILES64\Symphony\Symphony\config\Symphony.config
!macroend
!macro replaceLocalGlobalConfig
IfFileExists $WINDIR\Temp\temp-local-Symphony.config 0 +2
CopyFiles /SILENT $WINDIR\Temp\temp-local-Symphony.config $PROGRAMFILES64\Symphony\Symphony\config\Symphony.config
!macroend
!macro bothM !macro bothM
MessageBox MB_OK "Auto update not supported as there is two version installed" MessageBox MB_OK "Auto update not supported as there is two version installed"
!macroend !macroend
!macro perUserM !macro perUserM
!insertmacro copyLocalGlobalConfig
Call uninstallSymphony Call uninstallSymphony
Sleep 10000 Sleep 10000
SetRegView 64 SetRegView 64
@ -37,6 +58,7 @@ FunctionEnd
!insertmacro UAC_RunElevated !insertmacro UAC_RunElevated
Quit Quit
${endif} ${endif}
!insertmacro copySystemGlobalConfig
Call uninstallSymphony Call uninstallSymphony
Sleep 10000 Sleep 10000
SetRegView 64 SetRegView 64
@ -70,6 +92,16 @@ FunctionEnd
${EndIf} ${EndIf}
!macroend !macroend
!macro customInstall
${If} $PerUser == "exists"
!insertmacro replaceLocalGlobalConfig
${ElseIf} $AllUser == "exists"
!insertmacro replaceSystemGlobalConfig
${Else}
!insertmacro abortM
${EndIf}
!macroend
!macro customUnInit !macro customUnInit
!insertmacro validateInstallation !insertmacro validateInstallation
${If} $AllUser == "exists" ${If} $AllUser == "exists"

View File

@ -102,6 +102,9 @@ export class AutoUpdate {
} }
setImmediate(() => { setImmediate(() => {
if (this.autoUpdater) { if (this.autoUpdater) {
if (isMac) {
config.backupGlobalConfig();
}
this.autoUpdater.quitAndInstall(); this.autoUpdater.quitAndInstall();
} }
}); });

View File

@ -144,6 +144,7 @@ class Config {
private bootCount: number | undefined; private bootCount: number | undefined;
private readonly configFileName: string; private readonly configFileName: string;
private readonly installVariantFilename: string; private readonly installVariantFilename: string;
private readonly tempGlobalConfigFilePath: string;
private readonly installVariantPath: string; private readonly installVariantPath: string;
private readonly userConfigPath: string; private readonly userConfigPath: string;
private readonly appPath: string; private readonly appPath: string;
@ -152,6 +153,10 @@ class Config {
constructor() { constructor() {
this.configFileName = 'Symphony.config'; this.configFileName = 'Symphony.config';
this.tempGlobalConfigFilePath = path.join(
app.getPath('userData'),
'temp-local.Symphony.config',
);
this.installVariantFilename = 'InstallVariant.info'; this.installVariantFilename = 'InstallVariant.info';
this.userConfigPath = path.join( this.userConfigPath = path.join(
app.getPath('userData'), app.getPath('userData'),
@ -594,6 +599,23 @@ class Config {
} }
} }
/**
* Creates a backup of the global config file
*/
public backupGlobalConfig() {
fs.copyFileSync(this.globalConfigPath, this.tempGlobalConfigFilePath);
}
/**
* Overwrites the global config file with the backed up config file
*/
public copyGlobalConfig() {
if (fs.existsSync(this.tempGlobalConfigFilePath)) {
fs.copyFileSync(this.tempGlobalConfigFilePath, this.globalConfigPath);
fs.unlinkSync(this.tempGlobalConfigFilePath);
}
}
/** /**
* filters out the cloud config * filters out the cloud config
*/ */

View File

@ -13,6 +13,7 @@ import {
IApiArgs, IApiArgs,
INotificationData, INotificationData,
} from '../common/api-interface'; } from '../common/api-interface';
import { isMac } from '../common/env';
import { i18n, LocaleType } from '../common/i18n'; import { i18n, LocaleType } from '../common/i18n';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { activityDetection } from './activity-detection'; import { activityDetection } from './activity-detection';
@ -343,6 +344,9 @@ ipcMain.on(
break; break;
case apiCmds.setPodUrl: case apiCmds.setPodUrl:
await config.updateUserConfig({ url: arg.newPodUrl }); await config.updateUserConfig({ url: arg.newPodUrl });
if (isMac) {
config.copyGlobalConfig();
}
app.relaunch(); app.relaunch();
app.exit(); app.exit();
break; break;