VirtualBox

儲存庫 vbox 的更動 45243


忽略:
時間撮記:
2013-3-28 下午09:22:12 (12 年 以前)
作者:
vboxsync
訊息:

Use NSStartSearchPathEnumeration + NSDocumentDirectory insted of FSFindFolder because the latter fails if the directory doesn't not exist while the former work like the RTPathUserDocuments docs state.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Runtime/r3/darwin/RTPathUserDocuments-darwin.cpp

    r36611 r45243  
    55
    66/*
    7  * Copyright (C) 2011 Oracle Corporation
     7 * Copyright (C) 2011-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929*******************************************************************************/
    3030#include <iprt/path.h>
     31#include "internal/iprt.h"
     32
     33#include <iprt/assert.h>
     34#include <iprt/string.h>
    3135#include <iprt/err.h>
    32 #include <iprt/assert.h>
    3336
    34 #include <CoreServices/CoreServices.h>
     37#include <NSSystemDirectories.h>
     38#include <sys/syslimits.h>
     39#ifdef IPRT_USE_CORE_SERVICE_FOR_USER_DOCUMENTS
     40# include <CoreServices/CoreServices.h>
     41#endif
     42
    3543
    3644RTDECL(int) RTPathUserDocuments(char *pszPath, size_t cchPath)
     
    4250    AssertReturn(cchPath, VERR_INVALID_PARAMETER);
    4351
     52    /*
     53     * Try NSSystemDirectories first since that works for directories that doesn't exist.
     54     */
     55    int rc = VERR_PATH_NOT_FOUND;
     56    NSSearchPathEnumerationState EnmState = NSStartSearchPathEnumeration(NSDocumentDirectory, NSUserDomainMask);
     57    if (EnmState != 0)
     58    {
     59        char szTmp[PATH_MAX];
     60        szTmp[0] = szTmp[PATH_MAX - 1] = '\0';
     61        EnmState = NSGetNextSearchPathEnumeration(EnmState, szTmp);
     62        if (EnmState != 0)
     63        {
     64            size_t cchTmp = strlen(szTmp);
     65            if (cchTmp >= cchPath)
     66                return VERR_BUFFER_OVERFLOW;
     67
     68            if (szTmp[0] == '~' && szTmp[1] == '/')
     69            {
     70                /* Expand tilde. */
     71                rc = RTPathUserHome(pszPath, cchPath - cchTmp + 2);
     72                if (RT_FAILURE(rc))
     73                    return rc;
     74                rc = RTPathAppend(pszPath, cchPath, &szTmp[2]);
     75            }
     76            else
     77                rc = RTStrCopy(pszPath, cchPath, szTmp);
     78            return rc;
     79        }
     80    }
     81
     82#ifdef IPRT_USE_CORE_SERVICE_FOR_USER_DOCUMENTS
     83    /*
     84     * Fall back on FSFindFolder in case the above should fail...
     85     */
    4486    FSRef ref;
    4587    OSErr err = FSFindFolder(kOnAppropriateDisk, kDocumentsFolderType, false /* createFolder */, &ref);
    46     if (err != noErr)
    47         return VERR_PATH_NOT_FOUND;
    48 
    49     err = FSRefMakePath(&ref, (UInt8*)pszPath, cchPath);
    50     if (err != noErr)
    51         return VERR_PATH_NOT_FOUND;
    52 
    53     return VINF_SUCCESS;
     88    if (err == noErr)
     89    {
     90        err = FSRefMakePath(&ref, (UInt8*)pszPath, cchPath);
     91        if (err == noErr)
     92            return VINF_SUCCESS;
     93    }
     94#endif
     95    Assert(RT_FAILURE_NP(rc));
     96    return rc;
    5497}
    5598
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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