VirtualBox

Changeset 33462 in vbox for trunk/src/VBox/Installer/win


Ignore:
Timestamp:
Oct 26, 2010 12:15:19 PM (14 years ago)
Author:
vboxsync
Message:

VBoxStub.cpp: assertion macro confusion, RTStrAPrintf -> RTPathAppend.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/Stub/VBoxStub.cpp

    r32375 r33462  
    121121    do
    122122    {
    123         AssertBreakStmt(pszDataName, "Resource name is empty!");
     123        AssertMsgBreak(pszDataName, ("Resource name is empty!\n"));
    124124
    125125        /* Find our resource. */
    126126        HRSRC hRsrc = FindResourceEx(hInst, RT_RCDATA, pszDataName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
    127         AssertBreakStmt(hRsrc, "Could not find resource!");
     127        AssertMsgBreak(hRsrc, ("Could not find resource!\n"));
    128128
    129129        /* Get resource size. */
    130130        *pdwSize = SizeofResource(hInst, hRsrc);
    131         AssertBreakStmt(*pdwSize > 0, "Size of resource is invalid!");
     131        AssertMsgBreak((*pdwSize > 0, "Size of resource is invalid!\n"));
    132132
    133133        /* Get pointer to resource. */
    134134        HGLOBAL hData = LoadResource(hInst, hRsrc);
    135         AssertBreakStmt(hData, "Could not load resource!");
     135        AssertMsgBreak(hData, ("Could not load resource!\n"));
    136136
    137137        /* Lock resource. */
    138138        *ppvResource = LockResource(hData);
    139         AssertBreakStmt(*ppvResource, "Could not lock resource!");
     139        AssertMsgBreak(*ppvResource, ("Could not lock resource!\n"));
     140        return VINF_SUCCESS;
     141
    140142    } while (0);
    141     return *ppvResource ? VINF_SUCCESS : VERR_IO_GEN_FAILURE;
     143
     144    return VERR_IO_GEN_FAILURE;
    142145}
    143146
     
    157160                            char       **ppszTempFile)
    158161{
    159     return RTStrAPrintf(ppszTempFile, "%s\\%s", pszTempPath, pszTargetFileName);
     162    if (RTStrAPrintf(ppszTempFile, "%s\\%s", pszTempPath, pszTargetFileName) >= 0)
     163        return VINF_SUCCESS;
     164    return VERR_NO_STR_MEMORY;
    160165}
    161166
     
    179184    do
    180185    {
    181         AssertBreakStmt(pszResourceName, "Resource pointer invalid!");
    182         AssertBreakStmt(pszTempFile, "Temp file pointer invalid!");
     186        AssertMsgBreak(pszResourceName, ("Resource pointer invalid!\n"));
     187        AssertMsgBreak(pszTempFile, ("Temp file pointer invalid!"));
    183188
    184189        /* Read the data of the built-in resource. */
     
    186191        DWORD dwDataSize = 0;
    187192        rc = ReadData(NULL, pszResourceName, &pvData, &dwDataSize);
    188         AssertRCBreakStmt(rc, "Could not read resource data!");
     193        AssertMsgRCBreak(rc, ("Could not read resource data!\n"));
    189194
    190195        /* Create new (and replace an old) file. */
     
    194199                        | RTFILE_O_DENY_NOT_DELETE
    195200                        | RTFILE_O_DENY_WRITE);
    196         AssertRCBreakStmt(rc, "Could not open file for writing!");
     201        AssertMsgRCBreak(rc, ("Could not open file for writing!\n"));
    197202        bCreatedFile = TRUE;
    198203
     
    200205        size_t cbWritten = 0;
    201206        rc = RTFileWrite(fh, pvData, dwDataSize, &cbWritten);
    202         AssertRCBreakStmt(rc, "Could not open file for writing!");
    203         AssertBreakStmt((dwDataSize == cbWritten), "File was not extracted completely! Disk full?");
     207        AssertMsgRCBreak(rc, ("Could not open file for writing!\n"));
     208        AssertMsgBreak(dwDataSize == cbWritten, ("File was not extracted completely! Disk full?\n"));
    204209
    205210    } while (0);
     
    346351    BOOL fEnableLogging = FALSE;
    347352    BOOL bExit = FALSE;
    348     char *pszTempPathFull = NULL; /* Contains the final extraction directory later. */
    349353
    350354    /* Temp variables for arguments. */
    351     char szExtractPath[1024] = {0};
    352     char szMSIArgs[1024] = {0};
     355    char szExtractPath[RTPATH_MAX] = {0};
     356    char szMSIArgs[RTPATH_MAX] = {0};
    353357
    354358    /* Process arguments. */
     
    382386        {
    383387            vrc = ::StringCbCat(szExtractPath, sizeof(szExtractPath), pArgV[i+1]);
    384             pszTempPathFull = szExtractPath; /* Point to the new path. */
    385388            i++; /* Avoid the specify path from being parsed */
    386389        }
     
    445448    HRESULT hr = S_OK;
    446449
    447     do
     450    do /* break loop */
    448451    {
    449452        /* Get/create our temp path (only if not already set). */
    450         if (pszTempPathFull == NULL)
    451         {
    452             char szTemp[_MAX_PATH] = {0};
    453             vrc = RTPathTemp(szTemp, sizeof(szTemp));
    454             AssertRCBreakStmt(vrc, "Could not retrieve temp directory!");
    455             vrc = RTStrAPrintf(&pszTempPathFull, "%s\\VirtualBox", szTemp);
    456             AssertRCBreakStmt(vrc, "Could not construct temp directory!");
    457         }
    458 
    459         if (!RTDirExists(pszTempPathFull))
    460         {
    461             vrc = RTDirCreate(pszTempPathFull, 0700);
    462             AssertRCBreakStmt(vrc, "Could not create temp directory!");
     453        if (szExtractPath[0] == '\0')
     454        {
     455            vrc = RTPathTemp(szExtractPath, sizeof(szExtractPath));
     456            AssertMsgRCBreak(vrc, ("Could not retrieve temp directory!\n"));
     457
     458            vrc = RTPathAppend(szExtractPath, sizeof(szExtractPath), "VirtualBox");
     459            AssertMsgRCBreak(vrc, ("Could not construct temp directory!\n"));
     460        }
     461        if (!RTDirExists(szExtractPath))
     462        {
     463            vrc = RTDirCreate(szExtractPath, 0700);
     464            AssertMsgRCBreak(vrc, ("Could not create temp directory!\n"));
    463465        }
    464466
     
    472474        DWORD cbHeader = 0;
    473475        vrc = ReadData(NULL, "MANIFEST", (LPVOID*)&pHeader, &cbHeader);
    474         AssertRCBreakStmt(vrc, "Manifest not found!");
     476        AssertMsgRCBreak(vrc, ("Manifest not found!\n"));
    475477
    476478        /* Extract files. */
     
    483485            hr = ::StringCchPrintf(szHeaderName, _MAX_PATH, "HDR_%02d", k);
    484486            vrc = ReadData(NULL, szHeaderName, (LPVOID*)&pPackage, &cbPackage);
    485             AssertRCBreakStmt(vrc, "Header not found!"); /** @todo include header name, how? */
     487            AssertMsgRCBreak(vrc, ("Header not found!\n")); /** @todo include header name, how? */
    486488
    487489            if (PackageIsNeeded(pPackage) || fExtractOnly)
    488490            {
    489491                char *pszTempFile = NULL;
    490                 vrc = GetTempFileAlloc(pszTempPathFull, pPackage->szFileName, &pszTempFile);
    491                 AssertRCBreakStmt(vrc, "Could not create name for temporary extracted file!");
     492                vrc = GetTempFileAlloc(szExtractPath, pPackage->szFileName, &pszTempFile);
     493                AssertMsgRCBreak(vrc, ("Could not create name for temporary extracted file!\n"));
    492494                vrc = Extract(pPackage, pszTempFile);
    493                 AssertRCBreakStmt(vrc, "Could not extract file!");
     495                AssertMsgRCBreak(vrc, ("Could not extract file!\n"));
    494496                RTStrFree(pszTempFile);
    495497            }
     
    502504             * file(s) can use it.
    503505             */
    504             char *pszPathCustomDir;
    505             vrc = RTStrAPrintf(&pszPathCustomDir, "%s\\.custom", szPathExe);
    506             if (RT_SUCCESS(vrc) && RTDirExists(pszPathCustomDir))
     506            char *pszPathCustomDir = RTPathJoinA(szPathExe, ".custom");
     507            if (pszPathCustomDir && RTDirExists(pszPathCustomDir))
    507508            {
    508                 vrc = CopyDir(pszTempPathFull, pszPathCustomDir);
     509                vrc = CopyDir(szExtractPath, pszPathCustomDir);
    509510                if (RT_FAILURE(vrc)) /* Don't fail if it's missing! */
    510511                    vrc = VINF_SUCCESS;
     
    522523                hr = StringCchPrintf(szHeaderName, _MAX_PATH, "HDR_%02d", k);
    523524                vrc = ReadData(NULL, szHeaderName, (LPVOID*)&pPackage, &cbPackage);
    524                 AssertRCBreakStmt(vrc, "Package not found!");
     525                AssertMsgRCBreak(vrc, ("Package not found!\n"));
    525526
    526527                if (PackageIsNeeded(pPackage))
     
    528529                    char *pszTempFile = NULL;
    529530
    530                     vrc = GetTempFileAlloc(pszTempPathFull, pPackage->szFileName, &pszTempFile);
    531                     AssertRCBreakStmt(vrc, "Could not create name for temporary action file!");
     531                    vrc = GetTempFileAlloc(szExtractPath, pPackage->szFileName, &pszTempFile);
     532                    AssertMsgRCBreak(vrc, ("Could not create name for temporary action file!\n"));
    532533
    533534                    /* Handle MSI files. */
     
    539540                                                                  : INSTALLUILEVEL_FULL,
    540541                                                                    NULL);
    541                         AssertBreakStmt((UILevel != INSTALLUILEVEL_NOCHANGE), "Could not set installer UI level!");
     542                        AssertMsgBreak(UILevel != INSTALLUILEVEL_NOCHANGE, ("Could not set installer UI level!\n"));
    542543
    543544                        /* Enable logging? */
    544545                        if (fEnableLogging)
    545546                        {
    546                             char *pszLog = NULL;
    547                             vrc = RTStrAPrintf(&pszLog, "%s\\VBoxInstallLog.txt", pszTempPathFull);
    548                             char *pszMSILog = NULL;
    549                             AssertRCBreakStmt(vrc, "Could not convert MSI log string to current codepage!");
     547                            char *pszLog = RTPathJoinA(szExtractPath, "VBoxInstallLog.txt");
     548                            AssertMsgRCBreak(vrc, ("Could not convert MSI log string to current codepage!\n"));
    550549                            UINT uLogLevel = MsiEnableLog(INSTALLLOGMODE_VERBOSE,
    551550                                                          pszLog, INSTALLLOGATTRIBUTES_FLUSHEACHLINE);
    552551                            RTStrFree(pszLog);
    553                             AssertBreakStmt((uLogLevel == ERROR_SUCCESS), "Could not set installer logging level!");
     552                            AssertMsgBreak(uLogLevel == ERROR_SUCCESS, ("Could not set installer logging level!\n"));
    554553                        }
    555554
     
    596595            for (int i=0; i<5; i++)
    597596            {
    598                 vrc = RTDirRemoveRecursive(pszTempPathFull, 0 /*fFlags*/);
     597                vrc = RTDirRemoveRecursive(szExtractPath, 0 /*fFlags*/);
    599598                if (RT_SUCCESS(vrc))
    600599                    break;
     
    607606    if (RT_SUCCESS(vrc))
    608607    {
    609         if (    fExtractOnly
    610             && !fSilent
    611             )
    612         {
    613             ShowInfo("Files were extracted to: %s", pszTempPathFull);
     608        if (   fExtractOnly
     609            && !fSilent)
     610        {
     611            ShowInfo("Files were extracted to: %s", szExtractPath);
    614612        }
    615613
    616614        /** @todo Add more post installation stuff here if required. */
    617615    }
    618 
    619     if (strlen(szExtractPath) <= 0)
    620         RTStrFree(pszTempPathFull);
    621616
    622617    /* Release instance mutex. */
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