@@ -62,40 +62,49 @@ export async function importFromRegistry(scope?: vscode.ConfigurationScope) {
62
62
} ) ;
63
63
}
64
64
65
- async function loadRegistryData ( config , serverDefinitions , serversMissingUsernames , newServerNames ) : Promise < number > {
65
+ async function loadRegistryData ( config : vscode . WorkspaceConfiguration , serverDefinitions , serversMissingUsernames : string [ ] , newServerNames : string [ ] ) : Promise < number > {
66
66
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 [ ] = [ ] ;
69
73
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 ) ;
75
78
if ( regData . data === null ) {
76
79
// e.g., because the key in question isn't there
77
80
continue ;
78
81
}
79
- regData . data . split ( "\r\n" ) . forEach ( ( serverName ) => {
82
+ regData . data . split ( "\r\n" ) . forEach ( ( serverName : string ) => {
80
83
// We only want folders, not keys (e.g., DefaultServer)
81
- if ( serverName . indexOf ( hkeyLocalMachine ) !== 0 ) {
84
+ if ( ! serverName . startsWith ( hive ) ) {
82
85
return ;
83
86
}
84
-
85
87
// 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 ) {
87
89
return ;
88
90
}
89
91
90
92
// 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 ( ) ;
92
94
93
- const originalName : string = serverName . split ( "\\" ) . pop ( ) . trim ( ) ;
95
+ const originalName : string = ( serverName . split ( "\\" ) . pop ( ) ?? "" ) . trim ( ) ;
94
96
// Enforce the rules from package.json on the server name
95
97
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 ) ;
97
102
98
- if ( name !== "" && ! config . has ( "servers." + name ) ) {
103
+ if ( ! config . has ( "servers." + name ) ) {
104
+ // Ignore incomplete definition
105
+ if ( ! getProperty ( "Address" ) ) {
106
+ return ;
107
+ }
99
108
if ( ! newServerNames . includes ( name ) ) {
100
109
newServerNames . push ( name ) ;
101
110
}
@@ -124,7 +133,10 @@ async function loadRegistryData(config, serverDefinitions, serversMissingUsernam
124
133
}
125
134
}
126
135
else if ( ! name . startsWith ( "/" ) ) {
127
- overwriteCount ++ ;
136
+ if ( ! existingUserNames . includes ( name ) ) {
137
+ existingUserNames . push ( name ) ;
138
+ overwriteCount ++ ;
139
+ }
128
140
}
129
141
} ) ;
130
142
}
0 commit comments