@@ -10,13 +10,13 @@ import * as vscode from 'vscode';
1010import * as which from 'which' ;
1111import * as positron from 'positron' ;
1212import * as crypto from 'crypto' ;
13- import * as winreg from 'winreg' ;
1413
1514import { RInstallation , getRHomePath } from './r-installation' ;
1615import { RRuntime , createJupyterKernelExtra , createJupyterKernelSpec } from './runtime' ;
1716import { RRuntimeManager } from './runtime-manager' ;
1817import { Logger } from './extension' ;
1918import { readLines } from './util' ;
19+ import { HKEY } from '@vscode/windows-registry' ;
2020
2121const initialDynState = {
2222 inputPrompt : '>' ,
@@ -362,8 +362,8 @@ async function findCurrentRBinary(): Promise<string | undefined> {
362362}
363363
364364async 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' ) ;
367367 if ( ! userPath && ! machinePath ) {
368368 return undefined ;
369369 }
@@ -378,34 +378,17 @@ async function findCurrentRBinaryFromRegistry(): Promise<string | undefined> {
378378 return binPath ;
379379}
380380
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' ) ;
390385
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 ) ;
409392 return undefined ;
410393 }
411394}
0 commit comments