'use strict' ; import * as vscode from 'vscode' ; import * as fs from 'fs-extra' ; import { ExtensionCommands } from '../../ExtensionCommands' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { FabricEnvironmentRegistryEntry , LogType , FabricEnvironmentRegistry , EnvironmentType , FabricGatewayRegistryEntry , FileSystemUtil } from 'ibm-blockchain-platform-common' ; import { SettingConfigurations } from '../configurations' ; import { UserInputUtil } from './UserInputUtil' ; import { FabricEnvironmentManager } from '../fabric/environments/FabricEnvironmentManager' ; import { FabricGatewayConnectionManager } from '../fabric/FabricGatewayConnectionManager' ; export async function deleteExtensionDirectory ( ) { try { const confirmed = await UserInputUtil . showConfirmationWarningMessage ( `This will delete the extension directory. Do you want to continue?` ) ; if ( ! confirmed ) { return ; } const environments = await FabricEnvironmentRegistry . instance ( ) . getAll ( ) ; try { const connectedGatewayRegistry = await FabricGatewayConnectionManager . instance ( ) . getGatewayRegistryEntry ( ) ; if ( connectedGatewayRegistry ) { await vscode . commands . executeCommand ( ExtensionCommands . DISCONNECT_GATEWAY ) ; } } catch ( error ) { } try { const connectedEnvironmentRegistry = FabricEnvironmentManager . instance ( ) . getEnvironmentRegistryEntry ( ) ; if ( connectedEnvironmentRegistry ) { await vscode . commands . executeCommand ( ExtensionCommands . DISCONNECT_ENVIRONMENT ) ; } } catch ( error ) { } for ( const environment of environments ) { if ( environment . environmentType === EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT ) { try { await vscode . commands . executeCommand ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , environment . name ) ; } catch ( error ) { } try { await FabricEnvironmentRegistry . instance ( ) . delete ( environment . name ) ; } catch ( error ) { } } } const extDir = vscode . workspace . getConfiguration ( ) . get ( SettingConfigurations . EXTENSION_DIRECTORY ) ; const resolvedExtDir = FileSystemUtil . getDirPath ( extDir ) ; const exists = await fs . pathExists ( resolvedExtDir ) ; if ( ! exists ) { throw new Error ( 'Extension path not found' ) ; } await fs . remove ( resolvedExtDir ) ; await vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ; } catch ( error ) { VSCodeBlockchainOutputAdapter . instance ( ) . log ( LogType . ERROR , `Error deleting directory: ${ error . message }` , `Error deleting directory: ${ error . toString ( ) }` ) ; } }