From 9622bc93c2fd1e6e77396690d8696c43b2737dad Mon Sep 17 00:00:00 2001 From: Denis Lisenkov Date: Tue, 16 Jan 2024 16:36:20 +0300 Subject: [PATCH] GHI-167: add config storage name replacement Signed-off-by: Denis Lisenkov --- .../ZoweOldConfigConvertPreloadingActivity.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/kotlin/org/zowe/explorer/config/ZoweOldConfigConvertPreloadingActivity.kt b/src/main/kotlin/org/zowe/explorer/config/ZoweOldConfigConvertPreloadingActivity.kt index ba995ad97..2f45c32d9 100644 --- a/src/main/kotlin/org/zowe/explorer/config/ZoweOldConfigConvertPreloadingActivity.kt +++ b/src/main/kotlin/org/zowe/explorer/config/ZoweOldConfigConvertPreloadingActivity.kt @@ -97,8 +97,33 @@ class ZoweOldConfigConvertPreloadingActivity : PreloadingActivity() { } } + /** + * Replace config storage name with old one if new config file doesn't exist + */ + private fun replaceContentStorageName() { + val oldConfigStorageName = "org.zowe.explorer.config.OldConfigService" + val newConfigStorageName = "org.zowe.explorer.config.ConfigService" + val oldConfigName = "zowe_explorer_intellij_config.xml" + val newConfigName = "zowe_explorer_intellij_config_v2.xml" + val configPathDir = Paths.get(PathManager.getConfigPath(), PathManager.OPTIONS_DIRECTORY) + val oldConfigFile = File(Paths.get(configPathDir.pathString, oldConfigName).pathString) + val newConfigFile = File(Paths.get(configPathDir.pathString, newConfigName).pathString) + if (oldConfigFile.exists() && !newConfigFile.exists()) { + val charset = Charsets.UTF_8 + runCatching { + val newContent = + oldConfigFile + .readText(charset) + .replace(newConfigStorageName.toRegex(), oldConfigStorageName) + Files.write(oldConfigFile.toPath(), newContent.toByteArray(charset)) + service().reloadState(OldConfigServiceImpl::class.java) + } + } + } + override fun preload(indicator: ProgressIndicator) { convertOldVersionConfig() + replaceContentStorageName() } }