@@ -10,13 +10,13 @@ import * as vscode from 'vscode';
10
10
import * as which from 'which' ;
11
11
import * as positron from 'positron' ;
12
12
import * as crypto from 'crypto' ;
13
- import * as winreg from 'winreg' ;
14
13
15
14
import { RInstallation , getRHomePath } from './r-installation' ;
16
15
import { RRuntime , createJupyterKernelExtra , createJupyterKernelSpec } from './runtime' ;
17
16
import { RRuntimeManager } from './runtime-manager' ;
18
17
import { Logger } from './extension' ;
19
18
import { readLines } from './util' ;
19
+ import { HKEY } from '@vscode/windows-registry' ;
20
20
21
21
const initialDynState = {
22
22
inputPrompt : '>' ,
@@ -362,8 +362,8 @@ async function findCurrentRBinary(): Promise<string | undefined> {
362
362
}
363
363
364
364
async function findCurrentRBinaryFromRegistry ( ) : Promise < string | undefined > {
365
- const userPath = await getRegistryInstallPath ( winreg . HKCU ) ;
366
- const machinePath = await getRegistryInstallPath ( winreg . HKLM ) ;
365
+ const userPath = await getRegistryInstallPath ( 'HKEY_CURRENT_USER' ) ;
366
+ const machinePath = await getRegistryInstallPath ( 'HKEY_LOCAL_MACHINE' ) ;
367
367
if ( ! userPath && ! machinePath ) {
368
368
return undefined ;
369
369
}
@@ -378,34 +378,17 @@ async function findCurrentRBinaryFromRegistry(): Promise<string | undefined> {
378
378
return binPath ;
379
379
}
380
380
381
- async function getRegistryInstallPath ( hive : string ) : Promise < string | undefined > {
382
- try {
383
- const key = new winreg ( {
384
- hive : hive as keyof typeof winreg ,
385
- // 'R64' here is another place where we explicitly ignore 32-bit R
386
- key : '\\Software\\R-Core\\R64' ,
387
- } ) ;
388
-
389
- Logger . info ( `Checking for 'InstallPath' in registry key ${ key . key } for hive ${ key . hive } ` ) ;
381
+ async function getRegistryInstallPath ( hive : 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' ) : Promise < string | undefined > {
382
+ // 'R64' here is another place where we explicitly ignore 32-bit R
383
+ const R64_KEY : string = 'Software\\R-Core\\R64' ;
384
+ const registry = await import ( '@vscode/windows-registry' ) ;
390
385
391
- const result = await new Promise < { value : string } > ( ( resolve , reject ) => {
392
- key . get ( 'InstallPath' , ( error , result ) => {
393
- if ( error ) {
394
- reject ( error ) ;
395
- } else {
396
- resolve ( result ) ;
397
- }
398
- } ) ;
399
- } ) ;
400
-
401
- if ( ! result || typeof result . value !== 'string' ) {
402
- Logger . info ( `Invalid value of 'InstallPath'` ) ;
403
- return undefined ;
404
- }
405
-
406
- return result . value ;
407
- } catch ( error : any ) {
408
- Logger . info ( `Unable to get value of 'InstallPath': ${ error . message } ` ) ;
386
+ try {
387
+ Logger . info ( `Checking for 'InstallPath' in registry key ${ R64_KEY } for hive ${ hive } ` ) ;
388
+ const pth = registry . GetStringRegKey ( hive as HKEY , R64_KEY , 'InstallPath' ) || '' ;
389
+ return pth ;
390
+ } catch ( err ) {
391
+ Logger . info ( err as string ) ;
409
392
return undefined ;
410
393
}
411
394
}
0 commit comments