I need to find the current Systems
OS Name
Version - Major, Minor and Revision
Build Number
For example - if i run my code in Mavericks, i should get
Mac OSX Maverics
10.9.2
13C64
I'm aware that we have an API called 'uname'. This gives me the old Darwin Version number rather than the Marketing Version numbers.
This API gives me 13.0.0 for Maverics.
I would rather like to get the Marketing version and I dont get the Build Number properly too.
So i found that there is a command - sw_vers which gives the following output
So i decided to use this in my code
The code is self explanatory - i execute the command to get the Version and Build number and read the output from files and then i use a Switch statement to get the OSX Name based on the version.
I dont like this approach!!!
We execute a shell command, we read Files, we use bad Switch code to extract the MacOSX Name, which will need constant maintaining every time Apple releases a new OS.
Can someone guide me on a better way to do this??
I heard there is an API - Gestalt() But that is deprecated!!!!
Common Apple we need a simple API to do this!!!
Thanks in advance!
OS Name
Version - Major, Minor and Revision
Build Number
For example - if i run my code in Mavericks, i should get
Mac OSX Maverics
10.9.2
13C64
I'm aware that we have an API called 'uname'. This gives me the old Darwin Version number rather than the Marketing Version numbers.
This API gives me 13.0.0 for Maverics.
I would rather like to get the Marketing version and I dont get the Build Number properly too.
So i found that there is a command - sw_vers which gives the following output
mac-kmallick-01:SysPortLib kmallick$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.9.2
BuildVersion: 13C64
So i decided to use this in my code
Code:
system("sw_vers -productVersion > /tmp/MacVersion.txt && sw_vers -buildVersion > /tmp/MacBuild.txt");
MtxString strValues;
strValues = "";
//Lets read the file
FILEHANDLE hFile = FileOpen ("/tmp/MacVersion.txt", FILEOPEN_READONLY);
if (FILEOPEN_ERROR != hFile)
{
ULONG ulBufferSize = FileGetSize ("/tmp/MacVersion.txt");
//Do we have a buffer?
if (ulBufferSize > 0)
{
LPSTR ptrBuffer = (LPSTR) Malloc (ulBufferSize+1);
if (ptrBuffer != NULL)
{
FileRead (hFile, (LPSTR) ptrBuffer, ulBufferSize);
ptrBuffer[ulBufferSize] = '\0';
strValues.SetTo (ptrBuffer);
free (ptrBuffer);
}
}
FileClose (hFile);
}
MtxVector<MtxString> vecVersions;
strValues.Split('.', vecVersions, false);
//As the Version is got in format of Major : Minor : Revision (10.9.2) we split the
//string and extract the versions
if (vecVersions.Size () == 3)
{
ulMajor = vecVersions[0].ToUL ();
ulMinor = vecVersions[1].ToUL ();
ulRev = vecVersions[2].ToUL ();
}
//Lets read the file
FILEHANDLE hFileBuild = FileOpen ("/tmp/MacBuild.txt", FILEOPEN_READONLY);
if (FILEOPEN_ERROR != hFileBuild)
{
ULONG ulBufferSizeBuild = FileGetSize ("/tmp/MacBuild.txt");
//Do we have a buffer?
if (ulBufferSizeBuild > 0)
{
LPSTR ptrBuffer = (LPSTR) Malloc (ulBufferSizeBuild+1);
if (ptrBuffer != NULL)
{
FileRead (hFileBuild, (LPSTR) ptrBuffer, ulBufferSizeBuild);
ptrBuffer[ulBufferSizeBuild] = '\0';
strValues.SetTo (ptrBuffer);
free (ptrBuffer);
}
}
FileClose (hFileBuild);
}
....
....
//Get the Build number
//Use a Switch statement to get the MacOSX Name
//based on the version.
The code is self explanatory - i execute the command to get the Version and Build number and read the output from files and then i use a Switch statement to get the OSX Name based on the version.
I dont like this approach!!!
We execute a shell command, we read Files, we use bad Switch code to extract the MacOSX Name, which will need constant maintaining every time Apple releases a new OS.
Can someone guide me on a better way to do this??
I heard there is an API - Gestalt() But that is deprecated!!!!
Common Apple we need a simple API to do this!!!
Thanks in advance!