Replaced host.windowsversion with os.getversion

This commit is contained in:
Jason Perkins 2011-03-26 17:12:10 -04:00
parent 8e538baa6d
commit b2e7af94cf
7 changed files with 188 additions and 89 deletions

View File

@ -16,6 +16,7 @@ Makefile
*.sdf
*.sln
*.suo
*.ncb
*.vcproj*
*.vcxproj*
*.opensdf

View File

@ -8,7 +8,7 @@
* Switched PS3 builds from GCC to SNC
* Ignore NoRTTI flag for Managed C++ projects (Nick Darnell)
* Added host.is64bit
* Added host.windowsversion
* Added os.getversion
-------

View File

@ -58,6 +58,7 @@
configuration "macosx"
defines { "LUA_USE_MACOSX" }
links { "CoreServices.framework" }
configuration { "macosx", "gmake" }
buildoptions { "-mmacosx-version-min=10.1" }

View File

@ -1,16 +1,14 @@
/**
* \file host.c
* \brief Functions to query the specifics of the operating environment.
* \author Copyright (c) 2011 Jason Perkins and the Premake project
*/
/**
* \file host.c
* \brief Functions to query the specifics of the operating environment.
* \author Copyright (c) 2011 Jason Perkins and the Premake project
*/
#include "premake.h"
#if PLATFORM_WINDOWS
#define VER_SUITE_WH_SERVER (0x00008000)
#endif
/**
* Determine if we're running under 64-bit Windows.
*/
int windows_is_64bit_running_under_wow(struct lua_State* L)
{
#if PLATFORM_WINDOWS
@ -18,86 +16,14 @@ int windows_is_64bit_running_under_wow(struct lua_State* L)
BOOL is_wow = FALSE;
wow_func_sig func = (wow_func_sig)GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
if(func)
if (func)
{
if(! func(GetCurrentProcess(),&is_wow))
luaL_error(L, "IsWow64Process returned an error");
}
#else
int is_wow = 0;
#endif
lua_pushboolean(L, is_wow);
return 1;
}
int windows_version(struct lua_State* L)
{
#if PLATFORM_WINDOWS
OSVERSIONINFOEX versionInfo;
SYSTEM_INFO systemInfo;
ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX));
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO*)&versionInfo);
ZeroMemory(&systemInfo, sizeof(SYSTEM_INFO));
GetSystemInfo(&systemInfo);
if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0)
{
lua_pushliteral(L, "Windows2000");
}
else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1)
{
lua_pushliteral(L, "WindowsXP");
}
else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 2)
{
if (versionInfo.wProductType == VER_NT_WORKSTATION &&
systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
{
lua_pushliteral(L, "WindowsXPProfessionalx64");
}
else if (versionInfo.wSuiteMask & VER_SUITE_WH_SERVER)
{
lua_pushliteral(L, "WindowsHomeServer");
}
else if (GetSystemMetrics(SM_SERVERR2) == 0)
{
lua_pushliteral(L, "WindowsServer2003");
}
else
{
lua_pushliteral(L, "WindowsServer2003R2");
}
}
else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0)
{
if (versionInfo.wProductType == VER_NT_WORKSTATION)
{
lua_pushliteral(L, "WindowsVista");
}
else
{
lua_pushliteral(L, "WindowsServer2008");
}
}
else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 )
{
if (versionInfo.wProductType != VER_NT_WORKSTATION)
{
lua_pushliteral(L, "WindowsServer2008R2");
}
else
{
lua_pushliteral(L, "Windows7");
}
}
else
{
lua_pushliteral(L, "unknown windows version");
}
#else
lua_pushliteral(L, "host is not windows");
#endif
return 1;
}

171
src/host/os_getversion.c Executable file
View File

@ -0,0 +1,171 @@
/**
* \file os_getversioninfo.c
* \brief Retrieve operating system version information.
* \author Copyright (c) 2011 Jason Perkins and the Premake project
*/
#include "premake.h"
struct OsVersionInfo
{
int majorversion;
int minorversion;
int revision;
const char* description;
} ;
static void getversion(struct OsVersionInfo* info);
int os_getversion(lua_State* L)
{
struct OsVersionInfo info;
getversion(&info);
lua_newtable(L);
lua_pushstring(L, "majorversion");
lua_pushnumber(L, info.majorversion);
lua_settable(L, -3);
lua_pushstring(L, "minorversion");
lua_pushnumber(L, info.minorversion);
lua_settable(L, -3);
lua_pushstring(L, "revision");
lua_pushnumber(L, info.revision);
lua_settable(L, -3);
lua_pushstring(L, "description");
lua_pushstring(L, info.description);
lua_settable(L, -3);
return 1;
}
/*************************************************************/
#if defined(PLATFORM_WINDOWS)
#if !defined(VER_SUITE_WH_SERVER)
#define VER_SUITE_WH_SERVER (0x00008000)
#endif
void getversion(struct OsVersionInfo* info)
{
OSVERSIONINFOEX versionInfo;
SYSTEM_INFO systemInfo;
ZeroMemory(&versionInfo, sizeof(OSVERSIONINFOEX));
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx((OSVERSIONINFO*)&versionInfo);
info->majorversion = versionInfo.dwMajorVersion;
info->minorversion = versionInfo.dwMinorVersion;
info->revision = versionInfo.wServicePackMajor;
ZeroMemory(&systemInfo, sizeof(SYSTEM_INFO));
GetSystemInfo(&systemInfo);
if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 0)
{
info->description = "Windows 2000";
}
else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 1)
{
info->description = "Windows XP";
}
else if (versionInfo.dwMajorVersion == 5 && versionInfo.dwMinorVersion == 2)
{
if (versionInfo.wProductType == VER_NT_WORKSTATION &&
systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
{
info->description = "Windows XP Professional x64";
}
else if (versionInfo.wSuiteMask & VER_SUITE_WH_SERVER)
{
info->description = "Windows Home Server";
}
else if (GetSystemMetrics(SM_SERVERR2) == 0)
{
info->description = "Windows Server 2003";
}
else
{
info->description = "Windows Server 2003 R2";
}
}
else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 0)
{
if (versionInfo.wProductType == VER_NT_WORKSTATION)
{
info->description = "Windows Vista";
}
else
{
info->description = "Windows Server 2008";
}
}
else if (versionInfo.dwMajorVersion == 6 && versionInfo.dwMinorVersion == 1 )
{
if (versionInfo.wProductType != VER_NT_WORKSTATION)
{
info->description = "Windows Server 2008 R2";
}
else
{
info->description = "Windows 7";
}
}
else
{
info->description = "Windows";
}
}
/*************************************************************/
#elif defined(PLATFORM_MACOSX)
#include <CoreServices/CoreServices.h>
void getversion(struct OsVersionInfo* info)
{
Gestalt(gestaltSystemVersionMajor, &info->majorversion);
Gestalt(gestaltSystemVersionMinor, &info->minorversion);
Gestalt(gestaltSystemVersionBugFix, &info->revision);
info->description = "Mac OS X";
if (info->majorversion == 10)
{
switch (info->minorversion)
{
case 4:
info->description = "Mac OS X Tiger";
break;
case 5:
info->description = "Mac OS X Leopard";
break;
case 6:
info->description = "Mac OS X Snow Leopard";
break;
case 7:
info->description = "Mac OS X Lion";
break;
}
}
}
/*************************************************************/
#else
void getversion(struct OsVersionInfo* info)
{
info->majorversion = 0;
info->minorversion = 0;
info->revision = 0;
info->description = PLATFORM_STRING;
}
#endif

View File

@ -38,6 +38,7 @@ static const luaL_Reg os_functions[] = {
{ "copyfile", os_copyfile },
{ "isdir", os_isdir },
{ "getcwd", os_getcwd },
{ "getversion", os_getversion },
{ "isfile", os_isfile },
{ "matchdone", os_matchdone },
{ "matchisfile", os_matchisfile },
@ -59,7 +60,6 @@ static const luaL_Reg string_functions[] = {
static const luaL_Reg host_functions[] =
{
{ "windows_is_64bit_running_under_wow", windows_is_64bit_running_under_wow },
{ "windowsversion",windows_version},
{ NULL, NULL }
};
@ -77,7 +77,7 @@ int main(int argc, const char** argv)
luaL_register(L, "path", path_functions);
luaL_register(L, "os", os_functions);
luaL_register(L, "string", string_functions);
luaL_register(L, "host", host_functions);
luaL_register(L, "host", host_functions);
/* push the application metadata */
lua_pushstring(L, LUA_COPYRIGHT);

View File

@ -55,6 +55,7 @@ int path_isabsolute(lua_State* L);
int os_chdir(lua_State* L);
int os_copyfile(lua_State* L);
int os_getcwd(lua_State* L);
int os_getversion(lua_State* L);
int os_isdir(lua_State* L);
int os_isfile(lua_State* L);
int os_matchdone(lua_State* L);
@ -68,6 +69,5 @@ int os_rmdir(lua_State* L);
int os_uuid(lua_State* L);
int string_endswith(lua_State* L);
int windows_is_64bit_running_under_wow(struct lua_State* l);
int windows_version(struct lua_State* l);