import * as os from 'os' ; import * as util from './util' ; function platformToJreOs ( platform ) { return { win32 : 'windows' , linux : 'linux' , darwin : 'mac' } [ platform ] ; } function archToJreArch ( arch ) { return { x86_64 : 'x64' , x86 : 'x32' } [ arch ] ; } export class PlatformInformation { constructor ( public os , public arch ) { } public static GetPlatformInformation ( ) { const platform = os . platform ( ) ; let architecturePromise ; switch ( platform ) { case 'win32' : architecturePromise = PlatformInformation . GetWindowsArchitecture ( ) ; break ; case 'linux' : case 'darwin' : architecturePromise = PlatformInformation . GetUnixArchitecture ( ) ; break ; } return architecturePromise . then ( arch => { return new PlatformInformation ( platformToJreOs ( platform ) , archToJreArch ( arch ) ) ; } ) ; } public static GetUnknownArchitecture ( ) { return 'Unknown' ; } private static async GetWindowsArchitecture ( ) { return util . execChildProcess ( 'wmic os get osarchitecture' , util . extensionPath ) . then ( architecture => { if ( architecture ) { const archArray = architecture . split ( os . EOL ) ; if ( archArray . length >= 2 ) { const arch = archArray [ 1 ] . trim ( ) ; if ( arch . indexOf ( '64' ) >= 0 ) { return 'x86_64' ; } else if ( arch . indexOf ( '32' ) >= 0 ) { return 'x86' ; } } } return PlatformInformation . GetUnknownArchitecture ( ) ; } ) . catch ( error => { return PlatformInformation . GetUnknownArchitecture ( ) ; } ) ; } private static async GetUnixArchitecture ( ) { return util . execChildProcess ( 'uname -m' , util . packageJson . extensionFolderPath ) . then ( architecture => { if ( architecture ) { return architecture . trim ( ) ; } return null ; } ) ; } }