@@ -62,40 +62,49 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
6262 } ) ;
6363}
6464
65- async function loadRegistryData ( config , serverDefinitions , serversMissingUsernames , newServerNames ) : Promise < number > {
65+ async function loadRegistryData ( config : vscode . WorkspaceConfiguration , serverDefinitions , serversMissingUsernames : string [ ] , newServerNames : string [ ] ) : Promise < number > {
6666 const cmd = require ( "node-cmd" ) ;
67- const hkeyLocalMachine = "HKEY_LOCAL_MACHINE" ;
68- preloadRegistryCache ( cmd , "HKEY_CURRENT_USER\\Software\\InterSystems\\Cache\\Servers" ) ;
67+ const subFolder = "\\Intersystems\\Cache\\Servers" ;
68+ const fullPaths : string [ ] = [ ] ;
69+ fullPaths . push ( "HKEY_CURRENT_USER\\SOFTWARE" + subFolder ) ;
70+ fullPaths . push ( "HKEY_LOCAL_MACHINE\\SOFTWARE" + subFolder ) ;
71+ fullPaths . push ( "HKEY_LOCAL_MACHINE\\WOW6432Node\\SOFTWARE" + subFolder ) ;
72+ const existingUserNames : string [ ] = [ ] ;
6973 let overwriteCount = 0 ;
70- for ( const folder of [ '' , '\\WOW6432Node' ] ) {
71- const subFolder = "\\Intersystems\\Cache\\Servers" ;
72- const path = hkeyLocalMachine + "\\SOFTWARE" + folder + subFolder ;
73- preloadRegistryCache ( cmd , path ) ;
74- const regData = cmd . runSync ( "reg query " + path ) ;
74+ for ( const fullPath of fullPaths ) {
75+ const hive = fullPath . split ( "\\" ) [ 0 ] ;
76+ preloadRegistryCache ( cmd , fullPath ) ;
77+ const regData = cmd . runSync ( "reg query " + fullPath ) ;
7578 if ( regData . data === null ) {
7679 // e.g., because the key in question isn't there
7780 continue ;
7881 }
79- regData . data . split ( "\r\n" ) . forEach ( ( serverName ) => {
82+ regData . data . split ( "\r\n" ) . forEach ( ( serverName : string ) => {
8083 // We only want folders, not keys (e.g., DefaultServer)
81- if ( serverName . indexOf ( hkeyLocalMachine ) !== 0 ) {
84+ if ( ! serverName . startsWith ( hive ) ) {
8285 return ;
8386 }
84-
8587 // For WOW6432Node, skip the line for the subfolder itself
86- if ( serverName . split ( subFolder ) . pop ( ) . length === 0 ) {
88+ if ( ( serverName . split ( subFolder ) . pop ( ) ?? "" ) . length === 0 ) {
8789 return ;
8890 }
8991
9092 // remove HKEY_LOCAL_MACHINE\ and whitespace from the server name
91- const path = serverName . substring ( hkeyLocalMachine . length + 1 ) . trim ( ) ;
93+ const path = serverName . substring ( hive . length + 1 ) . trim ( ) ;
9294
93- const originalName : string = serverName . split ( "\\" ) . pop ( ) . trim ( ) ;
95+ const originalName : string = ( serverName . split ( "\\" ) . pop ( ) ?? "" ) . trim ( ) ;
9496 // Enforce the rules from package.json on the server name
9597 const name = originalName . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 - _ ~ ] / g, "~" ) ;
96- const getProperty = ( property : string ) => getStringRegKey ( cmd , hkeyLocalMachine , path , property ) ;
98+ if ( name === "" ) {
99+ return ;
100+ }
101+ const getProperty = ( property : string ) => getStringRegKey ( cmd , hive , path , property ) ;
97102
98- if ( name !== "" && ! config . has ( "servers." + name ) ) {
103+ if ( ! config . has ( "servers." + name ) ) {
104+ // Ignore incomplete definition
105+ if ( ! getProperty ( "Address" ) ) {
106+ return ;
107+ }
99108 if ( ! newServerNames . includes ( name ) ) {
100109 newServerNames . push ( name ) ;
101110 }
@@ -124,7 +133,10 @@ async function loadRegistryData(config, serverDefinitions, serversMissingUsernam
124133 }
125134 }
126135 else if ( ! name . startsWith ( "/" ) ) {
127- overwriteCount ++ ;
136+ if ( ! existingUserNames . includes ( name ) ) {
137+ existingUserNames . push ( name ) ;
138+ overwriteCount ++ ;
139+ }
128140 }
129141 } ) ;
130142 }
0 commit comments