Skip to content

Commit fc0e83b

Browse files
authored
Merge pull request #1 from SydneyhSmith/WindowsCoreCheck
Windows core check
2 parents ddbf324 + f5e99d4 commit fc0e83b

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

src/platform.ts

+32-10
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,39 @@ export function getDefaultPowerShellPath(
6969

7070
// Find the path to powershell.exe based on the current platform
7171
// and the user's desire to run the x86 version of PowerShell
72-
if (platformDetails.operatingSystem === OperatingSystem.Windows) {
73-
if (use32Bit) {
74-
powerShellExePath =
75-
platformDetails.isOS64Bit && platformDetails.isProcess64Bit
76-
? SysWow64PowerShellPath
77-
: System32PowerShellPath;
72+
if (platformDetails.operatingSystem === OperatingSystem.Windows) {
73+
const psCoreInstallPath =
74+
(!platformDetails.isProcess64Bit ? process.env.ProgramW6432 : process.env.ProgramFiles) + "\\PowerShell";
75+
if (fs.existsSync(psCoreInstallPath)) {
76+
const arch = platformDetails.isProcess64Bit ? "(x64)" : "(x86)";
77+
const psCorePaths =
78+
fs.readdirSync(psCoreInstallPath)
79+
.map((item) => path.join(psCoreInstallPath, item))
80+
.filter((item) => {
81+
const exePath = path.join(item, "pwsh.exe");
82+
return fs.lstatSync(item).isDirectory() && fs.existsSync(exePath);
83+
})
84+
.map((item) => ({
85+
versionName: `PowerShell Core ${path.parse(item).base} ${arch}`,
86+
exePath: path.join(item, "pwsh.exe"),
87+
}));
88+
89+
if (psCorePaths) {
90+
powerShellExePath = psCorePaths[0].exePath;
91+
}
92+
7893
} else {
79-
powerShellExePath =
80-
!platformDetails.isOS64Bit || platformDetails.isProcess64Bit
81-
? System32PowerShellPath
82-
: SysnativePowerShellPath;
94+
if (use32Bit) {
95+
powerShellExePath =
96+
platformDetails.isOS64Bit && platformDetails.isProcess64Bit
97+
? SysWow64PowerShellPath
98+
: System32PowerShellPath;
99+
} else {
100+
powerShellExePath =
101+
!platformDetails.isOS64Bit || platformDetails.isProcess64Bit
102+
? System32PowerShellPath
103+
: SysnativePowerShellPath;
104+
}
83105
}
84106
} else if (platformDetails.operatingSystem === OperatingSystem.MacOS) {
85107
// Always default to the stable version of PowerShell (if installed) but handle case of only Preview installed

src/session.ts

-28
Original file line numberDiff line numberDiff line change
@@ -113,34 +113,6 @@ export class SessionManager implements Middleware {
113113

114114
this.powerShellExePath = this.getPowerShellExePath();
115115

116-
// Check for OpenSSL dependency on macOS when running PowerShell Core alpha. Look for the default
117-
// Homebrew installation path and if that fails check the system-wide library path.
118-
if (os.platform() === "darwin" && this.getPowerShellVersionLabel() === "alpha") {
119-
if (!(utils.checkIfFileExists("/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib") &&
120-
utils.checkIfFileExists("/usr/local/opt/openssl/lib/libssl.1.0.0.dylib")) &&
121-
!(utils.checkIfFileExists("/usr/local/lib/libcrypto.1.0.0.dylib") &&
122-
utils.checkIfFileExists("/usr/local/lib/libssl.1.0.0.dylib"))) {
123-
const thenable =
124-
vscode.window.showWarningMessage(
125-
"The PowerShell extension will not work without OpenSSL on macOS and OS X when using " +
126-
"PowerShell Core alpha",
127-
"Show Documentation");
128-
129-
thenable.then(
130-
(s) => {
131-
if (s === "Show Documentation") {
132-
cp.exec("open https://github.com/PowerShell/vscode-powershell/blob/master/docs/" +
133-
"troubleshooting.md#1-powershell-intellisense-does-not-work-cant-debug-scripts");
134-
}
135-
});
136-
137-
// Don't continue initializing since Editor Services will not load successfully
138-
this.setSessionFailure(
139-
"Cannot start PowerShell Editor Services due to missing OpenSSL dependency.");
140-
return;
141-
}
142-
}
143-
144116
this.suppressRestartPrompt = false;
145117

146118
if (this.powerShellExePath) {

0 commit comments

Comments
 (0)