VirtualBox

Ignore:
Timestamp:
Apr 18, 2020 11:30:59 PM (5 years ago)
Author:
vboxsync
Message:

VBoxStub[Bld]: VC++ 14.1 warnings and some cleaning up. bugref:8489

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/StubBld/VBoxStubBld.cpp

    r82968 r83808  
    2525
    2626#include <VBox/version.h>
     27#include <iprt/types.h>
    2728
    2829#include "VBoxStubBld.h"
     
    3334{
    3435    HRESULT hr = S_OK;
    35     *phFile = ::CreateFile(pszFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     36    *phFile = CreateFile(pszFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    3637    if (INVALID_HANDLE_VALUE == *phFile)
    37     {
    3838        hr = HRESULT_FROM_WIN32(GetLastError());
    39     }
    4039    else
    4140    {
    4241        *pdwFileSize = ::GetFileSize(*phFile, NULL);
    4342        if (!*pdwFileSize)
    44         {
    45             hr = HRESULT_FROM_WIN32(GetLastError());
    46         }
     43            hr = HRESULT_FROM_WIN32(GetLastError());
    4744    }
    4845    return hr;
     
    5249                       DWORD dwFileSize,
    5350                       HANDLE hResourceUpdate,
    54                        const char *szResourceType,
    55                        const char *szResourceId)
     51                       const char *pszResourceType,
     52                       const char *pszResourceId)
    5653{
    5754    HRESULT hr = S_OK;
    58     PVOID pvFile = NULL;
    59     HANDLE hMap = NULL;
    60 
    61     hMap = ::CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
    62     pvFile = ::MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, dwFileSize);
    63     if (!::UpdateResourceA(hResourceUpdate, szResourceType, szResourceId,
    64                            MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pvFile, dwFileSize))
    65     {
     55
     56    HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
     57    PVOID pvFile = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, dwFileSize);
     58    if (!UpdateResourceA(hResourceUpdate, pszResourceType, pszResourceId,
     59                         MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pvFile, dwFileSize))
    6660        hr = HRESULT_FROM_WIN32(GetLastError());
    67     }
    6861
    6962    if (pvFile)
    70     {
    71         ::UnmapViewOfFile(pvFile);
    72         pvFile = NULL;
    73     }
     63        UnmapViewOfFile(pvFile);
    7464
    7565    if (hMap)
    76     {
    77         ::CloseHandle(hMap);
    78         hMap = NULL;
    79     }
     66        CloseHandle(hMap);
    8067
    8168    return hr;
    8269}
    8370
    84 HRESULT IntegrateFile (HANDLE hResourceUpdate,
    85                        const char* szResourceType,
    86                        const char* szResourceId,
    87                        const char* pszFilePath)
    88 {
    89     HRESULT hr = S_OK;
     71static HRESULT IntegrateFile(HANDLE hResourceUpdate, const char *pszResourceType,
     72                             const char *pszResourceId, const char *pszFilePath)
     73{
    9074    HANDLE hFile = INVALID_HANDLE_VALUE;
    9175    DWORD dwFileSize = 0;
    92 
    93     do
    94     {
    95         hr = GetFile(pszFilePath, &hFile, &dwFileSize);
     76    HRESULT hr = GetFile(pszFilePath, &hFile, &dwFileSize);
     77    if (SUCCEEDED(hr))
     78    {
     79        hr = UpdateResource(hFile, dwFileSize, hResourceUpdate, pszResourceType, pszResourceId);
    9680        if (FAILED(hr))
    97         {
    98             hr = HRESULT_FROM_WIN32(GetLastError());
    99             break;
    100         }
    101         else
    102         {
    103             hr = UpdateResource(hFile, dwFileSize, hResourceUpdate, szResourceType, szResourceId);
    104             if (FAILED(hr))
    105             {
    106                 printf("ERROR: Error updating resource for file %s!", pszFilePath);
    107                 break;
    108             }
    109         }
    110 
    111     } while (0);
    112 
    113 
    114     if (INVALID_HANDLE_VALUE != hFile)
    115     {
    116         ::CloseHandle(hFile);
    117         hFile = INVALID_HANDLE_VALUE;
    118     }
    119 
     81            printf("ERROR: Error updating resource for file %s!", pszFilePath);
     82    }
     83    else
     84        hr = HRESULT_FROM_WIN32(GetLastError());
     85
     86    if (hFile != INVALID_HANDLE_VALUE)
     87        CloseHandle(hFile);
    12088    return hr;
    12189}
    12290
    123 static char * MyPathFilename(const char *pszPath)
    124 {
    125     const char *psz = pszPath;
     91static char *MyPathFilename(const char *pszPath)
     92{
    12693    const char *pszName = pszPath;
    127 
    128     for (;; psz++)
     94    for (const char *psz = pszPath;; psz++)
    12995    {
    13096        switch (*psz)
     
    152118
    153119
    154 int main (int argc, char* argv[])
     120int main(int argc, char* argv[])
    155121{
    156122    HRESULT hr = S_OK;
    157     int rc = 0;
     123    int rcExit = RTEXITCODE_SUCCESS;
    158124
    159125    char szSetupStub[_MAX_PATH] = {"VBoxStub.exe"};
     
    161127    HANDLE hUpdate = NULL;
    162128
    163     do
     129    do /* goto avoidance "loop" */
    164130    {
    165131        printf(VBOX_PRODUCT " Stub Builder v%d.%d.%d.%d\n",
     
    180146        for (int i=1; i<argc; i++)
    181147        {
    182             if (0 == stricmp(argv[i], "-out") && argc > i+1)
    183             {
    184                 hr = ::StringCchCopy(szOutput, _MAX_PATH, argv[i+1]);
    185                 i++;
    186             }
    187 
    188             else if (0 == stricmp(argv[i], "-stub") && argc > i+1)
    189             {
    190                 hr = ::StringCchCopy(szSetupStub, _MAX_PATH, argv[i+1]);
    191                 i++;
    192             }
    193 
    194             else if (0 == stricmp(argv[i], "-target-all") && argc > i+1)
    195             {
    196                 hr = ::StringCchCopy(stbBuildPkg[stbHeader.byCntPkgs].szSourcePath, _MAX_PATH, argv[i+1]);
     148            if (!stricmp(argv[i], "-out") && argc > i+1)
     149            {
     150                hr = StringCchCopy(szOutput, _MAX_PATH, argv[i+1]);
     151                i++;
     152            }
     153
     154            else if (!stricmp(argv[i], "-stub") && argc > i+1)
     155            {
     156                hr = StringCchCopy(szSetupStub, _MAX_PATH, argv[i+1]);
     157                i++;
     158            }
     159
     160            else if (!stricmp(argv[i], "-target-all") && argc > i+1)
     161            {
     162                hr = StringCchCopy(stbBuildPkg[stbHeader.byCntPkgs].szSourcePath, _MAX_PATH, argv[i+1]);
    197163                stbBuildPkg[stbHeader.byCntPkgs].byArch = VBOXSTUBPKGARCH_ALL;
    198164                stbHeader.byCntPkgs++;
     
    200166            }
    201167
    202             else if (0 == stricmp(argv[i], "-target-x86") && argc > i+1)
    203             {
    204                 hr = ::StringCchCopy(stbBuildPkg[stbHeader.byCntPkgs].szSourcePath, _MAX_PATH, argv[i+1]);
     168            else if (!stricmp(argv[i], "-target-x86") && argc > i+1)
     169            {
     170                hr = StringCchCopy(stbBuildPkg[stbHeader.byCntPkgs].szSourcePath, _MAX_PATH, argv[i+1]);
    205171                stbBuildPkg[stbHeader.byCntPkgs].byArch = VBOXSTUBPKGARCH_X86;
    206172                stbHeader.byCntPkgs++;
     
    208174            }
    209175
    210             else if (0 == stricmp(argv[i], "-target-amd64") && argc > i+1)
    211             {
    212                 hr = ::StringCchCopy(stbBuildPkg[stbHeader.byCntPkgs].szSourcePath, _MAX_PATH, argv[i+1]);
     176            else if (!stricmp(argv[i], "-target-amd64") && argc > i+1)
     177            {
     178                hr = StringCchCopy(stbBuildPkg[stbHeader.byCntPkgs].szSourcePath, _MAX_PATH, argv[i+1]);
    213179                stbBuildPkg[stbHeader.byCntPkgs].byArch = VBOXSTUBPKGARCH_AMD64;
    214180                stbHeader.byCntPkgs++;
     
    218184            {
    219185                printf("ERROR: Invalid parameter: %s\n", argv[i]);
    220                 hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
     186                hr = E_INVALIDARG;
    221187                break;
    222188            }
    223189            if (FAILED(hr))
    224190            {
    225                 printf("ERROR: StringCchCopy failed: %#x\n", hr);
     191                printf("ERROR: StringCchCopy failed: %#lx\n", hr);
    226192                break;
    227193            }
     
    238204        printf("Stub: %s\n", szSetupStub);
    239205        printf("Output: %s\n", szOutput);
    240         printf("# Packages: %d\n", stbHeader.byCntPkgs);
    241 
    242         if (!::CopyFile(szSetupStub, szOutput, FALSE))
    243         {
    244             hr = HRESULT_FROM_WIN32(GetLastError());
    245             printf("ERROR: Could not create stub loader: 0x%08x\n", hr);
    246             break;
    247         }
    248 
    249         hUpdate = ::BeginUpdateResource(szOutput, FALSE);
     206        printf("# Packages: %u\n", stbHeader.byCntPkgs);
     207
     208        if (!CopyFile(szSetupStub, szOutput, FALSE))
     209        {
     210            hr = HRESULT_FROM_WIN32(GetLastError());
     211            printf("ERROR: Could not create stub loader: %#lx\n", hr);
     212            break;
     213        }
     214
     215        hUpdate = BeginUpdateResource(szOutput, FALSE);
    250216
    251217        PVBOXSTUBPKG pPackage = stbPkg;
    252218        char szHeaderName[_MAX_PATH] = {0};
    253219
    254         for (BYTE i=0; i<stbHeader.byCntPkgs; i++)
     220        for (BYTE i = 0; i < stbHeader.byCntPkgs; i++)
    255221        {
    256222            printf("Integrating (Platform %d): %s\n", stbBuildPkg[i].byArch, stbBuildPkg[i].szSourcePath);
    257223
    258224            /* Construct resource name. */
    259             hr = ::StringCchPrintf(pPackage->szResourceName, _MAX_PATH, "BIN_%02d", i);
     225            hr = StringCchPrintf(pPackage->szResourceName, _MAX_PATH, "BIN_%02d", i);
    260226            pPackage->byArch = stbBuildPkg[i].byArch;
    261227
    262228            /* Construct final name used when extracting. */
    263             hr = ::StringCchCopy(pPackage->szFileName, _MAX_PATH, MyPathFilename(stbBuildPkg[i].szSourcePath));
     229            hr = StringCchCopy(pPackage->szFileName, _MAX_PATH, MyPathFilename(stbBuildPkg[i].szSourcePath));
    264230
    265231            /* Integrate header into binary. */
    266             hr = ::StringCchPrintf(szHeaderName, _MAX_PATH, "HDR_%02d", i);
     232            hr = StringCchPrintf(szHeaderName, _MAX_PATH, "HDR_%02d", i);
    267233            hr = UpdateResource(hUpdate, RT_RCDATA, szHeaderName, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pPackage, sizeof(VBOXSTUBPKG));
    268234
     
    271237            if (FAILED(hr))
    272238            {
    273                 printf("ERROR: Could not integrate binary %s (%s): 0x%08x\n",
     239                printf("ERROR: Could not integrate binary %s (%s): %#lx\n",
    274240                         pPackage->szResourceName, pPackage->szFileName, hr);
    275                 rc = 1;
     241                rcExit = RTEXITCODE_FAILURE;
    276242            }
    277243
     
    282248            break;
    283249
    284         if (!::UpdateResource(hUpdate, RT_RCDATA, "MANIFEST", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &stbHeader, sizeof(VBOXSTUBPKGHEADER)))
    285         {
    286             hr = HRESULT_FROM_WIN32(GetLastError());
    287             break;
    288         }
    289 
    290         if (!::EndUpdateResource(hUpdate, FALSE))
     250        if (!UpdateResource(hUpdate, RT_RCDATA, "MANIFEST", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &stbHeader, sizeof(VBOXSTUBPKGHEADER)))
     251        {
     252            hr = HRESULT_FROM_WIN32(GetLastError());
     253            break;
     254        }
     255
     256        if (!EndUpdateResource(hUpdate, FALSE))
    291257        {
    292258            hr = HRESULT_FROM_WIN32(GetLastError());
     
    302268    if (FAILED(hr))
    303269    {
    304         printf("ERROR: Building failed! Last error: %d\n", GetLastError());
    305         rc = 1;
    306     }
    307     return rc;
    308 }
     270        printf("ERROR: Building failed! Last error: %lu\n", GetLastError());
     271        rcExit = RTEXITCODE_FAILURE;
     272    }
     273    return rcExit;
     274}
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