|
1 | 1 | import * as fs from 'fs-extra'; |
2 | | -import * as os from 'os'; |
3 | 2 | import path = require('path'); |
4 | 3 | import winreg = require('winreg'); |
| 4 | +import { RExecutable, RExecutableFactory } from '../executable'; |
5 | 5 |
|
6 | 6 | import { AbstractLocatorService } from './shared'; |
7 | 7 |
|
8 | 8 | export class WindowsExecLocator extends AbstractLocatorService { |
9 | | - public get hasBinaries(): boolean { |
10 | | - return this.binary_paths.length > 0; |
| 9 | + constructor() { |
| 10 | + super(); |
| 11 | + this._binaryPaths = []; |
| 12 | + this._executables = []; |
11 | 13 | } |
12 | | - public get binaries(): string[] { |
13 | | - return this.binary_paths; |
| 14 | + public get hasExecutables(): boolean { |
| 15 | + return this._executables.length > 0; |
| 16 | + } |
| 17 | + public get executables(): RExecutable[] { |
| 18 | + return this._executables; |
| 19 | + } |
| 20 | + public get binaryPaths(): string[] { |
| 21 | + return this._binaryPaths; |
14 | 22 | } |
15 | 23 | public refreshPaths(): void { |
16 | | - this.binary_paths = Array.from( |
| 24 | + const paths = Array.from( |
17 | 25 | new Set([ |
18 | 26 | ...this.getHomeFromDirs(), |
19 | 27 | ...this.getHomeFromEnv(), |
20 | 28 | ...this.getHomeFromRegistry(), |
21 | 29 | // ... this.getHomeFromConda() |
22 | 30 | ]) |
23 | 31 | ); |
| 32 | + for (const path of paths) { |
| 33 | + if (!this._binaryPaths?.includes(path)) { |
| 34 | + this._binaryPaths.push(path); |
| 35 | + this._executables.push(RExecutableFactory.createExecutable(path)); |
| 36 | + } |
| 37 | + } |
24 | 38 | } |
25 | 39 |
|
26 | | - private potential_bin_paths: string[] = [ |
27 | | - '%ProgramFiles%\\R\\', |
28 | | - '%ProgramFiles(x86)%\\R\\' |
29 | | - ]; |
30 | | - |
31 | 40 | private getHomeFromRegistry(): string[] { |
32 | 41 | const registryBins: string[] = []; |
33 | 42 | const potentialBins = [ |
@@ -68,7 +77,11 @@ export class WindowsExecLocator extends AbstractLocatorService { |
68 | 77 |
|
69 | 78 | private getHomeFromDirs(): string[] { |
70 | 79 | const dirBins: string[] = []; |
71 | | - for (const bin of this.potential_bin_paths) { |
| 80 | + const potential_bin_paths: string[] = [ |
| 81 | + '%ProgramFiles%\\R\\', |
| 82 | + '%ProgramFiles(x86)%\\R\\' |
| 83 | + ]; |
| 84 | + for (const bin of potential_bin_paths) { |
72 | 85 | const resolvedBin = path.resolve(bin); |
73 | 86 | if (fs.existsSync(resolvedBin)) { |
74 | 87 | const i386 = `${resolvedBin}\\i386\\`; |
|
0 commit comments