Ejemplo n.º 1
0
bool CDialog::GetVersion(LPCTSTR lpszFilename, DWORD *a, DWORD *b, DWORD *c, DWORD *d)
{
	DWORD dwHandle, dwResult = 0;
	
	// determine the size of the resource information
	DWORD dwSize = ::GetFileVersionInfoSize((LPTSTR)lpszFilename, &dwHandle);
	if (0 < dwSize)
	{
		LPBYTE lpBuffer = new BYTE[dwSize];
		
		if (::GetFileVersionInfo((LPTSTR)lpszFilename, 0, dwSize, lpBuffer) != FALSE)
		{
			// 'point to' the start of the version information block
			VS_VERSIONINFO *pVerInfo = (VS_VERSIONINFO*)lpBuffer;
			
			// the fixed section starts right after the 'VS_VERSION_INFO' string
			LPBYTE pOffsetBytes = (BYTE*)&pVerInfo->szKey[wcslen(pVerInfo->szKey) + 1];
			
			VS_FIXEDFILEINFO *pFixedInfo = (VS_FIXEDFILEINFO*)roundpos(pVerInfo, pOffsetBytes, 4);

			*a = pFixedInfo->dwFileVersionMS;
			*b = pFixedInfo->dwFileVersionLS;
			*c = pFixedInfo->dwProductVersionMS;
			*d = pFixedInfo->dwProductVersionLS;
		}
		
		delete [] lpBuffer;

		return true;
	}

	return false;
}
Ejemplo n.º 2
0
void CDialog::DisplayVersion()
{
	HANDLE	hMem;
	LPSTR	lpstrVffInfo;
	DWORD	dwVerHnd=0;
	DWORD	dwVerInfoSize;
	TCHAR	szFullPath[MAX_PATH] = {0};

	if(m_bUnInstall)
	{
		lstrcpy(szFullPath, m_szDestinationPath);
		lstrcat(szFullPath, "\\");
		lstrcat(szFullPath, FILENAME_DLL);
	}
	else
	{
		::GetModuleFileName(m_hInstance, szFullPath, MAX_PATH);
	}

	dwVerInfoSize = ::GetFileVersionInfoSize(szFullPath, &dwVerHnd);
	
	if(dwVerInfoSize)
	{
		hMem = ::GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
		lpstrVffInfo = (LPSTR)::GlobalLock(hMem);
		::GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpstrVffInfo);

		VS_VERSIONINFO *pVerInfo = (VS_VERSIONINFO*)lpstrVffInfo;
		LPBYTE pOffsetBytes = (BYTE*)&pVerInfo->szKey[wcslen(pVerInfo->szKey) + 1];
		VS_FIXEDFILEINFO *pFixedInfo = (VS_FIXEDFILEINFO*) roundpos(pFixedInfo, pOffsetBytes, 4);
		//DWORD a = pFixedInfo->dwFileVersionMS;
		//DWORD b = pFixedInfo->dwFileVersionLS;
		DWORD a = pFixedInfo->dwProductVersionMS;
		DWORD b = pFixedInfo->dwProductVersionLS;
		TCHAR	szVersion[MAX_PATH] = {0};
		wsprintf(szVersion, "%d,%d,%d,%d", HIWORD(a), LOWORD(a), HIWORD(b), LOWORD(b));

		//SetMessage(IDS_VERSION, szVersion);

		TCHAR szFormat[MAX_PATH] = {0};
		TCHAR szMessage[MAX_PATH] = {0};
		::LoadString(m_hInstance, IDS_VERSION, szFormat, sizeof(szFormat));
		wsprintf(szMessage, szFormat, szVersion);
		::SetDlgItemText(m_hwnd, IDC_VERSION, szMessage);

		GlobalUnlock(hMem);
		GlobalFree(hMem);
	}
}
Ejemplo n.º 3
0
void SetVersion(LPCTSTR lpszFile)
{
    VS_VERSIONINFO		*pVerInfo;
    LPBYTE				pOffsetBytes;
    VS_FIXEDFILEINFO	*pFixedInfo;
    DWORD				dwHandle, dwSize, dwResult = 0;
    
    // determine the size of the resource information
    dwSize = GetFileVersionInfoSize((LPTSTR)lpszFile, &dwHandle);
    if (0 < dwSize)
    {
        LPBYTE lpBuffer = new BYTE[dwSize];
        
        if (GetFileVersionInfo((LPTSTR)lpszFile, 0, dwSize, lpBuffer) != FALSE)
        {
            // these macros help to align on r-byte boundaries (thanks Ted Peck)
            
            // 'point to' the start of the version information block
            pVerInfo = (VS_VERSIONINFO *) lpBuffer;
            
            // the fixed section starts right after the 'VS_VERSION_INFO' string
            pOffsetBytes = (BYTE *) &pVerInfo->szKey[wcslen(pVerInfo->szKey) + 1];
			
            pFixedInfo = (VS_FIXEDFILEINFO *) roundpos(pVerInfo, pOffsetBytes, 4);
			
            // increment the numbers!
            pFixedInfo->dwFileVersionMS    = pFixedInfo->dwFileVersionMS + 0x00010001;
            pFixedInfo->dwFileVersionLS    = pFixedInfo->dwFileVersionLS + 0x00010001;
            pFixedInfo->dwProductVersionMS = pFixedInfo->dwProductVersionMS + 0x00010001;
            pFixedInfo->dwProductVersionLS = pFixedInfo->dwProductVersionLS + 0x00010001;
			
            HANDLE hResource = BeginUpdateResource(lpszFile, FALSE);
            if (NULL != hResource)
            {
                UINT uTemp;
				
                // get the language information
                if (VerQueryValue(lpBuffer, _T("\\VarFileInfo\\Translation"), (LPVOID *) &lpTranslate, &uTemp) != FALSE)
                {
                    // could probably just use LANG_NEUTRAL/SUBLANG_NEUTRAL
                    if (UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), lpTranslate->wLanguage, lpBuffer, dwSize) != FALSE)
                    {
                        if (EndUpdateResource(hResource, FALSE) == FALSE)
                            dwResult = GetLastError();
                    }
                    else
                        dwResult = GetLastError();
                }
            }
            else
                dwResult = GetLastError();
        }
        else
            dwResult = GetLastError();
		
        delete [] lpBuffer;
    }
    else
        dwResult = GetLastError();
	
	//if (0 != dwResult)
	//	wprintf(_T("Operation was not successful.  Result = %lu\n"), dwResult);
}
Ejemplo n.º 4
0
std::string GLCaps::getDriverVersion() {
    if (computeVendor() == MESA) {
        // Mesa includes the driver version in the renderer version
        // e.g., "1.5 Mesa 6.4.2"
        
        static std::string _glVersion = (char*)glGetString(GL_VERSION);
        int i = _glVersion.rfind(' ');
        if (i == (int)std::string::npos) {
            return "Unknown (bad MESA driver string)";
        } else {
            return _glVersion.substr(i + 1, _glVersion.length() - i);
        }
    }
    
#   ifdef G3D_WIN32
    
    std::string driver;
    
        // Locate the windows\system directory
    {
            char sysDir[1024];
            int sysSize = GetSystemDirectoryA(sysDir, 1024);
            if (sysSize == 0) {
                return "Unknown (can't find Windows directory)";
            }
            driver = sysDir;
        }

        switch (computeVendor()) {
        case ATI:
            driver = driver + "\\ati2dvag.dll";
            break;

        case NVIDIA:
            driver = driver + "\\nv4_disp.dll";
            break;
		
        default:
            return "Unknown (Unknown vendor)";

        }

        char* lpdriver = const_cast<char*>(driver.c_str());
        DWORD dummy;

        int size = GetFileVersionInfoSizeA(lpdriver, &dummy);
        if (size == 0) {
            return "Unknown (Can't find driver)";
        }

        void* buffer = new uint8[size];

        if (GetFileVersionInfoA(lpdriver, 0, size, buffer) == 0) {
            delete[] (uint8*)buffer;
            return "Unknown";
        }

	    // Interpret the VS_VERSIONINFO header pseudo-struct
	    VS_VERSIONINFO* pVS = (VS_VERSIONINFO*)buffer;
        debugAssert(!wcscmp(pVS->szKey, L"VS_VERSION_INFO"));

	    uint8* pVt = (uint8*) &pVS->szKey[wcslen(pVS->szKey) + 1];

        #define roundoffs(a,b,r)	(((uint8*)(b) - (uint8*)(a) + ((r) - 1)) & ~((r) - 1))
        #define roundpos(b, a, r)	(((uint8*)(a)) + roundoffs(a, b, r))

	    VS_FIXEDFILEINFO* pValue = (VS_FIXEDFILEINFO*) roundpos(pVt, pVS, 4);

        #undef roundoffs
        #undef roundpos

        std::string result = "Unknown (No information)";

	    if (pVS->wValueLength) {
	        result = format("%d.%d.%d.%d",
                pValue->dwProductVersionMS >> 16,
                pValue->dwProductVersionMS & 0xFFFF,
	            pValue->dwProductVersionLS >> 16,
                pValue->dwProductVersionLS & 0xFFFF);
        }