import * as os from 'os' ; import { LinuxDistribution } from './linuxDistribution' ; import * as plist from 'plist' ; import * as fs from 'fs' ; import * as logger from './logger' ; import * as nls from 'vscode-nls' ; nls . config ( { messageFormat : nls . MessageFormat . bundle , bundleFormat : nls . BundleFormat . standalone } ) ( ) ; const localize = nls . loadMessageBundle ( ) ; export function GetOSName ( processPlatform ) { switch ( processPlatform ) { case "win32" : return "Windows" ; case "darwin" : return "macOS" ; case "linux" : return "Linux" ; default : return undefined ; } } export class PlatformInformation { constructor ( public platform , public architecture , public distribution ? , public version ? ) { } public static async GetPlatformInformation ( ) { const platform = os . platform ( ) ; const architecture = PlatformInformation . GetArchitecture ( ) ; let distribution ; let version ; switch ( platform ) { case "win32" : break ; case "linux" : distribution = await LinuxDistribution . GetDistroInformation ( ) ; break ; case "darwin" : version = await PlatformInformation . GetDarwinVersion ( ) ; break ; default : throw new Error ( localize ( "unknown.os.platform" , "Unknown OS platform" ) ) ; } return new PlatformInformation ( platform , architecture , distribution , version ) ; } public static GetArchitecture ( ) { const arch = os . arch ( ) ; switch ( arch ) { case "x64" : case "arm64" : case "arm" : return arch ; case "x32" : case "ia32" : return "x86" ; default : if ( os . platform ( ) === "win32" ) { return "x86" ; } else { return "x64" ; } } } private static GetDarwinVersion ( ) { const DARWIN_SYSTEM_VERSION_PLIST = "/System/Library/CoreServices/SystemVersion.plist" ; let productDarwinVersion = "" ; let errorMessage = "" ; if ( fs . existsSync ( DARWIN_SYSTEM_VERSION_PLIST ) ) { const systemVersionPListBuffer = fs . readFileSync ( DARWIN_SYSTEM_VERSION_PLIST ) ; const systemVersionData = plist . parse ( systemVersionPListBuffer . toString ( ) ) ; if ( systemVersionData ) { productDarwinVersion = systemVersionData . ProductVersion ; } else { errorMessage = localize ( "missing.plist.productversion" , "Could not get ProduceVersion from SystemVersion.plist" ) ; } } else { errorMessage = localize ( "missing.darwin.systemversion.file" , "Failed to find SystemVersion.plist in {0}." , DARWIN_SYSTEM_VERSION_PLIST ) ; } if ( errorMessage ) { logger . getOutputChannel ( ) . appendLine ( errorMessage ) ; logger . showOutputChannel ( ) ; } return Promise . resolve ( productDarwinVersion ) ; } }