chore: stabilize Zhinian pilot delivery
This commit is contained in:
56
electron/utils/dotnet-runtime.ts
Normal file
56
electron/utils/dotnet-runtime.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { existsSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { prependPathEntry } from './env-path';
|
||||
|
||||
type EnvMap = Record<string, string | undefined>;
|
||||
|
||||
function dotnetExecutableName(): string {
|
||||
return process.platform === 'win32' ? 'dotnet.exe' : 'dotnet';
|
||||
}
|
||||
|
||||
export function getDotnetPathCandidates(): string[] {
|
||||
if (process.platform === 'win32') {
|
||||
return [
|
||||
path.join(homedir(), '.dotnet'),
|
||||
path.join(process.env.ProgramFiles || 'C:\\Program Files', 'dotnet'),
|
||||
path.join(process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)', 'dotnet'),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
path.join(homedir(), '.dotnet'),
|
||||
'/usr/local/share/dotnet',
|
||||
'/opt/homebrew/bin',
|
||||
'/usr/local/bin',
|
||||
];
|
||||
}
|
||||
|
||||
export function resolveDotnetExecutable(): string | null {
|
||||
const executable = dotnetExecutableName();
|
||||
for (const dir of getDotnetPathCandidates()) {
|
||||
const candidate = path.join(dir, executable);
|
||||
if (existsSync(candidate)) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function buildDotnetEnv(baseEnv: EnvMap): EnvMap {
|
||||
let env: EnvMap = { ...baseEnv };
|
||||
const existingDirs = getDotnetPathCandidates().filter((entry) => existsSync(entry));
|
||||
for (const dir of existingDirs.slice().reverse()) {
|
||||
env = prependPathEntry(env, dir).env;
|
||||
}
|
||||
|
||||
const userDotnet = path.join(homedir(), '.dotnet');
|
||||
if (existsSync(path.join(userDotnet, dotnetExecutableName()))) {
|
||||
env.DOTNET_ROOT = userDotnet;
|
||||
} else {
|
||||
const systemRoot = process.platform === 'darwin' ? '/usr/local/share/dotnet' : null;
|
||||
if (systemRoot && existsSync(path.join(systemRoot, dotnetExecutableName()))) {
|
||||
env.DOTNET_ROOT = systemRoot;
|
||||
}
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
Reference in New Issue
Block a user