Changeset 83808 in vbox for trunk/src/VBox/Installer/win/StubBld
- Timestamp:
- Apr 18, 2020 11:30:59 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/win/StubBld/VBoxStubBld.cpp
r82968 r83808 25 25 26 26 #include <VBox/version.h> 27 #include <iprt/types.h> 27 28 28 29 #include "VBoxStubBld.h" … … 33 34 { 34 35 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); 36 37 if (INVALID_HANDLE_VALUE == *phFile) 37 {38 38 hr = HRESULT_FROM_WIN32(GetLastError()); 39 }40 39 else 41 40 { 42 41 *pdwFileSize = ::GetFileSize(*phFile, NULL); 43 42 if (!*pdwFileSize) 44 { 45 hr = HRESULT_FROM_WIN32(GetLastError()); 46 } 43 hr = HRESULT_FROM_WIN32(GetLastError()); 47 44 } 48 45 return hr; … … 52 49 DWORD dwFileSize, 53 50 HANDLE hResourceUpdate, 54 const char * szResourceType,55 const char * szResourceId)51 const char *pszResourceType, 52 const char *pszResourceId) 56 53 { 57 54 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)) 66 60 hr = HRESULT_FROM_WIN32(GetLastError()); 67 }68 61 69 62 if (pvFile) 70 { 71 ::UnmapViewOfFile(pvFile); 72 pvFile = NULL; 73 } 63 UnmapViewOfFile(pvFile); 74 64 75 65 if (hMap) 76 { 77 ::CloseHandle(hMap); 78 hMap = NULL; 79 } 66 CloseHandle(hMap); 80 67 81 68 return hr; 82 69 } 83 70 84 HRESULT IntegrateFile (HANDLE hResourceUpdate, 85 const char* szResourceType, 86 const char* szResourceId, 87 const char* pszFilePath) 88 { 89 HRESULT hr = S_OK; 71 static HRESULT IntegrateFile(HANDLE hResourceUpdate, const char *pszResourceType, 72 const char *pszResourceId, const char *pszFilePath) 73 { 90 74 HANDLE hFile = INVALID_HANDLE_VALUE; 91 75 DWORD dwFileSize = 0; 92 93 do94 { 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); 96 80 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); 120 88 return hr; 121 89 } 122 90 123 static char * MyPathFilename(const char *pszPath) 124 { 125 const char *psz = pszPath; 91 static char *MyPathFilename(const char *pszPath) 92 { 126 93 const char *pszName = pszPath; 127 128 for (;; psz++) 94 for (const char *psz = pszPath;; psz++) 129 95 { 130 96 switch (*psz) … … 152 118 153 119 154 int main 120 int main(int argc, char* argv[]) 155 121 { 156 122 HRESULT hr = S_OK; 157 int rc = 0;123 int rcExit = RTEXITCODE_SUCCESS; 158 124 159 125 char szSetupStub[_MAX_PATH] = {"VBoxStub.exe"}; … … 161 127 HANDLE hUpdate = NULL; 162 128 163 do 129 do /* goto avoidance "loop" */ 164 130 { 165 131 printf(VBOX_PRODUCT " Stub Builder v%d.%d.%d.%d\n", … … 180 146 for (int i=1; i<argc; i++) 181 147 { 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]); 197 163 stbBuildPkg[stbHeader.byCntPkgs].byArch = VBOXSTUBPKGARCH_ALL; 198 164 stbHeader.byCntPkgs++; … … 200 166 } 201 167 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]); 205 171 stbBuildPkg[stbHeader.byCntPkgs].byArch = VBOXSTUBPKGARCH_X86; 206 172 stbHeader.byCntPkgs++; … … 208 174 } 209 175 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]); 213 179 stbBuildPkg[stbHeader.byCntPkgs].byArch = VBOXSTUBPKGARCH_AMD64; 214 180 stbHeader.byCntPkgs++; … … 218 184 { 219 185 printf("ERROR: Invalid parameter: %s\n", argv[i]); 220 hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);186 hr = E_INVALIDARG; 221 187 break; 222 188 } 223 189 if (FAILED(hr)) 224 190 { 225 printf("ERROR: StringCchCopy failed: %# x\n", hr);191 printf("ERROR: StringCchCopy failed: %#lx\n", hr); 226 192 break; 227 193 } … … 238 204 printf("Stub: %s\n", szSetupStub); 239 205 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); 250 216 251 217 PVBOXSTUBPKG pPackage = stbPkg; 252 218 char szHeaderName[_MAX_PATH] = {0}; 253 219 254 for (BYTE i =0; i<stbHeader.byCntPkgs; i++)220 for (BYTE i = 0; i < stbHeader.byCntPkgs; i++) 255 221 { 256 222 printf("Integrating (Platform %d): %s\n", stbBuildPkg[i].byArch, stbBuildPkg[i].szSourcePath); 257 223 258 224 /* Construct resource name. */ 259 hr = ::StringCchPrintf(pPackage->szResourceName, _MAX_PATH, "BIN_%02d", i);225 hr = StringCchPrintf(pPackage->szResourceName, _MAX_PATH, "BIN_%02d", i); 260 226 pPackage->byArch = stbBuildPkg[i].byArch; 261 227 262 228 /* 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)); 264 230 265 231 /* Integrate header into binary. */ 266 hr = ::StringCchPrintf(szHeaderName, _MAX_PATH, "HDR_%02d", i);232 hr = StringCchPrintf(szHeaderName, _MAX_PATH, "HDR_%02d", i); 267 233 hr = UpdateResource(hUpdate, RT_RCDATA, szHeaderName, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), pPackage, sizeof(VBOXSTUBPKG)); 268 234 … … 271 237 if (FAILED(hr)) 272 238 { 273 printf("ERROR: Could not integrate binary %s (%s): 0x%08x\n",239 printf("ERROR: Could not integrate binary %s (%s): %#lx\n", 274 240 pPackage->szResourceName, pPackage->szFileName, hr); 275 rc = 1;241 rcExit = RTEXITCODE_FAILURE; 276 242 } 277 243 … … 282 248 break; 283 249 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)) 291 257 { 292 258 hr = HRESULT_FROM_WIN32(GetLastError()); … … 302 268 if (FAILED(hr)) 303 269 { 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.