VirtualBox

Changeset 24686 in vbox for trunk


Ignore:
Timestamp:
Nov 16, 2009 10:14:48 AM (15 years ago)
Author:
vboxsync
Message:

VbglR3/VBoxService: Split up and removed redundant code.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxGuestLib.h

    r24660 r24686  
    417417VBGLR3DECL(int)     VbglR3WaitEvent(uint32_t fMask, uint32_t cMillies, uint32_t *pfEvents);
    418418VBGLR3DECL(int)     VbglR3GetAdditionsVersion(char **ppszVer, char **ppszRev);
     419VBGLR3DECL(int)     VbglR3GetAdditionsInstallationPath(char **ppszPath);
    419420/** @} */
    420421
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibMisc.cpp

    r24390 r24686  
    226226
    227227/**
     228 * Looks up the storage path handle (registry).
     229 *
     230 * @returns IPRT status value
     231 * @param   hKey        Receives pointer of allocated version string. NULL is
     232 *                      accepted. The returned pointer must be closed by
     233 *                      vbglR3CloseAdditionsWinStoragePath().
     234 */
     235static int vbglR3GetAdditionsWinStoragePath(PHKEY phKey)
     236{
     237    /*
     238     * Try get the *installed* version first.
     239     */
     240    LONG r;
     241
     242    /* Check the new path first. */
     243    r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, phKey);
     244# ifdef RT_ARCH_AMD64
     245    if (r != ERROR_SUCCESS)
     246    {
     247        /* Check Wow6432Node (for new entries). */
     248        r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, phKey);
     249    }
     250# endif
     251
     252    /* Still no luck? Then try the old xVM paths ... */
     253    if (r != ERROR_SUCCESS)
     254    {
     255        r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, phKey);
     256# ifdef RT_ARCH_AMD64
     257        if (r != ERROR_SUCCESS)
     258        {
     259            /* Check Wow6432Node (for new entries). */
     260            r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, phKey);
     261        }
     262# endif
     263    }
     264    return RTErrConvertFromNtStatus(r);
     265}
     266
     267
     268/**
     269 * Closes the storage path handle (registry).
     270 *
     271 * @returns IPRT status value
     272 * @param   hKey        Handle to close, retrieved by
     273 *                      vbglR3GetAdditionsWinStoragePath().
     274 */
     275static int vbglR3CloseAdditionsWinStoragePath(HKEY hKey)
     276{
     277    return RTErrConvertFromNtStatus(RegCloseKey(hKey));
     278}
     279
     280
     281/**
    228282 * Retrieves the installed Guest Additions version and/or revision.
    229283 *
     
    239293{
    240294#ifdef RT_OS_WINDOWS
    241     /*
    242      * Try get the *installed* version first.
    243      */
    244     HKEY hKey = NULL;
    245     LONG r;
    246 
    247     /* Check the new path first. */
    248     r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    249 # ifdef RT_ARCH_AMD64
    250     if (r != ERROR_SUCCESS)
    251     {
    252         /* Check Wow6432Node (for new entries). */
    253         r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    254     }
    255 # endif
    256 
    257     /* Still no luck? Then try the old xVM paths ... */
    258     if (r != ERROR_SUCCESS)
    259     {
    260         r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    261 # ifdef RT_ARCH_AMD64
    262         if (r != ERROR_SUCCESS)
    263         {
    264             /* Check Wow6432Node (for new entries). */
    265             r = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    266         }
    267 # endif
    268     }
    269 
    270     /* Did we get something worth looking at? */
    271     int rc = VINF_SUCCESS;
    272     if (r == ERROR_SUCCESS)
     295    HKEY hKey;
     296    int rc = vbglR3GetAdditionsWinStoragePath(&hKey);
     297    if (RT_SUCCESS(rc))
    273298    {
    274299        /* Version. */
     300        LONG l;
    275301        DWORD dwType;
    276302        DWORD dwSize = 32;
     
    281307            if (pszTmp)
    282308            {
    283                 r = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
    284                 if (r == ERROR_SUCCESS)
     309                l = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
     310                if (l == ERROR_SUCCESS)
    285311                {
    286312                    if (dwType == REG_SZ)
     
    291317                else
    292318                {
    293                     rc = RTErrConvertFromNtStatus(r);
     319                    rc = RTErrConvertFromNtStatus(l);
    294320                }
    295321                RTMemFree(pszTmp);
     
    305331            if (pszTmp)
    306332            {
    307                 r = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
    308                 if (r == ERROR_SUCCESS)
     333                l = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
     334                if (l == ERROR_SUCCESS)
    309335                {
    310336                    if (dwType == REG_SZ)
     
    315341                else
    316342                {
    317                     rc = RTErrConvertFromNtStatus(r);
     343                    rc = RTErrConvertFromNtStatus(l);
    318344                }
    319345                RTMemFree(pszTmp);
     
    328354            }
    329355        }
    330         if (hKey != NULL)
    331             RegCloseKey(hKey);
     356        rc = vbglR3CloseAdditionsWinStoragePath(hKey);
    332357    }
    333358    else
     
    349374}
    350375
     376
     377/**
     378 * Retrieves the installation path of Guest Additions.
     379 *
     380 * @returns IPRT status value
     381 * @param   ppszPath    Receives pointer of allocated installation path string.
     382 *                      The returned pointer must be freed using
     383 *                      RTStrFree().
     384 */
     385VBGLR3DECL(int) VbglR3GetAdditionsInstallationPath(char **ppszPath)
     386{
     387    int rc;
     388#ifdef RT_OS_WINDOWS
     389    HKEY hKey;
     390    rc = vbglR3GetAdditionsWinStoragePath(&hKey);
     391    if (RT_SUCCESS(rc))
     392    {
     393        /* Installation directory. */
     394        DWORD dwType;
     395        DWORD dwSize = _MAX_PATH * sizeof(char);
     396        char *pszTmp = (char*)RTMemAlloc(dwSize + 1);
     397        if (pszTmp)
     398        {
     399            LONG l = RegQueryValueEx(hKey, "InstallDir", NULL, &dwType, (BYTE*)(LPCTSTR)pszTmp, &dwSize);
     400            if ((l != ERROR_SUCCESS) && (l != ERROR_FILE_NOT_FOUND))
     401            {
     402                rc = RTErrConvertFromNtStatus(l);
     403            }
     404            else
     405            {
     406                if (dwType == REG_SZ)
     407                    rc = RTStrDupEx(ppszPath, pszTmp);
     408                else
     409                    rc = VERR_INVALID_PARAMETER;
     410                if (RT_SUCCESS(rc))
     411                {
     412                    /* Flip slashes. */
     413                    for (char* pszTmp2 = ppszPath[0]; ppszPath; ++ppszPath)
     414                        if (*pszTmp2 == '\\')
     415                            *pszTmp2 = '/';
     416                }
     417            }
     418            RTMemFree(pszTmp);
     419        }
     420        else
     421            rc = VERR_NO_MEMORY;
     422        rc = vbglR3CloseAdditionsWinStoragePath(hKey);
     423    }
     424#else
     425    /** @todo implement me */
     426    rc = VINF_NOT_IMPLEMENTED;
     427#endif
     428    return rc;
     429}
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp

    r24369 r24686  
    329329
    330330#endif /* TARGET_NT4 */
    331 
    332 int VBoxServiceWinGetAddsVersion(uint32_t uiClientID)
    333 {
    334     char szInstDir[_MAX_PATH] = {0};
    335     char szRev[_MAX_PATH] = {0};
    336     char szVer[_MAX_PATH] = {0};
    337 
    338     HKEY hKey = NULL;
    339     int rc;
    340     DWORD dwSize = 0;
    341     DWORD dwType = 0;
    342 
    343     VBoxServiceVerbose(3, "Guest Additions version lookup: Looking up ...\n");
    344 
    345     /* Check the new path first. */
    346     rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    347 #ifdef RT_ARCH_AMD64
    348     if (rc != ERROR_SUCCESS)
    349     {
    350         /* Check Wow6432Node (for new entries). */
    351         rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    352     }
    353 #endif
    354 
    355     /* Still no luck? Then try the old xVM paths ... */
    356     if (RT_FAILURE(rc))
    357     {
    358         rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    359 #ifdef RT_ARCH_AMD64
    360         if (rc != ERROR_SUCCESS)
    361         {
    362             /* Check Wow6432Node (for new entries). */
    363             rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Wow6432Node\\Sun\\xVM VirtualBox Guest Additions", 0, KEY_READ, &hKey);
    364         }
    365 #endif
    366     }
    367 
    368     /* Did we get something worth looking at? */
    369     if (RT_FAILURE(rc))
    370     {
    371         VBoxServiceError("Failed to open registry key (guest additions)! Error: %Rrc\n", rc);
    372     }
    373     else
    374     {
    375         VBoxServiceVerbose(3, "Guest Additions version lookup: Key: 0x%p, rc: %Rrc\n", hKey, rc);
    376         /* Installation directory. */
    377         dwSize = sizeof(szInstDir);
    378         rc = RegQueryValueEx(hKey, "InstallDir", NULL, &dwType, (BYTE*)(LPCTSTR)szInstDir, &dwSize);
    379         if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
    380         {
    381             VBoxServiceError("Failed to query registry key (install directory)! Error: %Rrc\n", rc);
    382         }
    383         else
    384         {
    385             /* Flip slashes. */
    386             for (char* pszTmp = &szInstDir[0]; *pszTmp; ++pszTmp)
    387                 if (*pszTmp == '\\')
    388                     *pszTmp = '/';
    389         }
    390         /* Revision. */
    391         dwSize = sizeof(szRev);
    392         rc = RegQueryValueEx(hKey, "Revision", NULL, &dwType, (BYTE*)(LPCTSTR)szRev, &dwSize);
    393         if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
    394             VBoxServiceError("Failed to query registry key (revision)! Error: %Rrc\n", rc);
    395         /* Version. */
    396         dwSize = sizeof(szVer);
    397         rc = RegQueryValueEx(hKey, "Version", NULL, &dwType, (BYTE*)(LPCTSTR)szVer, &dwSize);
    398         if ((rc != ERROR_SUCCESS) && (rc != ERROR_FILE_NOT_FOUND))
    399             VBoxServiceError("Failed to query registry key (version)! Error: %Rrc\n", rc);
    400     }
    401 
    402     /* Write information to host. */
    403     rc = VBoxServiceWritePropF(uiClientID, "/VirtualBox/GuestAdd/InstallDir", "%s", szInstDir);
    404     rc = VBoxServiceWritePropF(uiClientID, "/VirtualBox/GuestAdd/Revision", "%s", szRev);
    405     rc = VBoxServiceWritePropF(uiClientID, "/VirtualBox/GuestAdd/Version", "%s", szVer);
    406 
    407     if (NULL != hKey)
    408         RegCloseKey(hKey);
    409 
    410     return rc;
    411 }
    412331
    413332int VBoxServiceWinGetComponentVersions(uint32_t uiClientID)
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r24512 r24686  
    7373fnWTSGetActiveConsoleSessionId g_pfnWTSGetActiveConsoleSessionId = NULL;
    7474/** External functions. */
    75 extern int VBoxServiceWinGetAddsVersion(uint32_t uiClientID);
    7675extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);
    7776#endif
     
    171170
    172171    /* Retrieve version information about Guest Additions and installed files (components). */
    173 #ifdef RT_OS_WINDOWS
    174     rc = VBoxServiceWinGetAddsVersion(g_VMInfoGuestPropSvcClientID);
     172    char *pszAddVer, *pszAddRev;
     173    rc = VbglR3GetAdditionsVersion(&pszAddVer, &pszAddRev);
     174    if (RT_SUCCESS(rc))
     175    {
     176        /* Write information to host. */
     177        rc = VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision", "%s", pszAddVer);
     178        rc = VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version", "%s", pszAddRev);
     179        RTStrFree(pszAddVer);
     180        RTStrFree(pszAddRev);
     181    }
     182
     183#ifdef RT_OS_WINDOWS
     184    char *pszInstDir;
     185    rc = VbglR3GetAdditionsInstallationPath(&pszInstDir);
     186    if (RT_SUCCESS(rc))
     187    {
     188        rc = VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/InstallDir", "%s", pszInstDir);
     189        RTStrFree(pszInstDir);
     190    }
    175191    rc = VBoxServiceWinGetComponentVersions(g_VMInfoGuestPropSvcClientID);
    176 #else
    177     /* VBoxServiceGetAddsVersion !RT_OS_WINDOWS */
    178     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Version", "%s", VBOX_VERSION_STRING);
    179 
    180     char szRevision[32];
    181     RTStrPrintf(szRevision, sizeof(szRevision), "%u", VBOX_SVN_REV);
    182     VBoxServiceWritePropF(g_VMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/Revision", "%s", szRevision);
    183192#endif
    184193
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette