VirtualBox

Changeset 53825 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Jan 15, 2015 2:50:38 PM (10 years ago)
Author:
vboxsync
Message:

Runtime: try the official Windows XP+ way to get the home (profile) directory, and if that doesn't work fall back to using the environment (without HOME as this isn't used on Windows)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/path-win.cpp

    r52944 r53825  
    55
    66/*
    7  * Copyright (C) 2006-2011 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    158158RTDECL(int) RTPathUserHome(char *pszPath, size_t cchPath)
    159159{
     160    /*
     161     * Validate input
     162     */
     163    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
     164    AssertReturn(cchPath, VERR_INVALID_PARAMETER);
     165
    160166    RTUTF16 wszPath[RTPATH_MAX];
    161167    DWORD   dwAttr;
    162 
    163     /*
    164      * There are multiple definitions for what WE think of as user home...
    165      */
    166     if (    !GetEnvironmentVariableW(L"HOME", &wszPath[0], RTPATH_MAX)
     168    bool    fValidFolderPath = false;
     169
     170    /*
     171     * Try with Windows XP+ functionality first.
     172     */
     173    {
     174        RTLDRMOD hShell32;
     175        int rc = RTLdrLoadSystem("Shell32.dll", true /*fNoUnload*/, &hShell32);
     176        if (RT_SUCCESS(rc))
     177        {
     178            PFNSHGETFOLDERPATHW pfnSHGetFolderPathW;
     179            rc = RTLdrGetSymbol(hShell32, "SHGetFolderPathW", (void**)&pfnSHGetFolderPathW);
     180            if (RT_SUCCESS(rc))
     181            {
     182                HRESULT hrc = pfnSHGetFolderPathW(0, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, wszPath);
     183                fValidFolderPath = (hrc == S_OK);
     184            }
     185            RTLdrClose(hShell32);
     186        }
     187    }
     188
     189    if (    !fValidFolderPath
    167190        ||  (dwAttr = GetFileAttributesW(&wszPath[0])) == INVALID_FILE_ATTRIBUTES
    168191        ||  !(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
    169192    {
     193        /*
     194         * Fall back to Windows specific environment variables. HOME is not used.
     195         */
    170196        if (    !GetEnvironmentVariableW(L"USERPROFILE", &wszPath[0], RTPATH_MAX)
    171197            ||  (dwAttr = GetFileAttributesW(&wszPath[0])) == INVALID_FILE_ATTRIBUTES
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