- Timestamp:
- Jan 8, 2022 3:07:46 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/os2/VBoxOs2AdditionsInstall.cpp
r93144 r93145 84 84 /** Verbose or quiet. */ 85 85 static bool g_fVerbose = true; 86 /** Whether this is a real run (true) or just a trial. */ 87 static bool g_fRealRun = false; 86 88 87 89 /** The standard output handle. */ … … 1327 1329 1328 1330 /** 1331 * Tells the loader to cache all the pages in @a pszFile and close it, so that 1332 * we can modify or replace it. 1333 */ 1334 static void CacheLdrFile(const char *pszFile) 1335 { 1336 if (g_fVerbose) 1337 DoWriteNStr(g_hStdOut, RT_STR_TUPLE("info: Sharing violation - applying DosReplaceModule...\r\n")); 1338 1339 APIRET rc = DosReplaceModule(pszFile, NULL, NULL); 1340 if (rc != NO_ERROR) 1341 ApiErrorN(rc, 3, "DosReplaceModule(\"", pszFile, "\",,)"); 1342 } 1343 1344 1345 /** 1329 1346 * Worker for CopyFiles that handles one copying operation. 1330 1347 */ 1331 1348 static RTEXITCODE CopyOneFile(const char *pszSrc, const char *pszDst) 1332 1349 { 1350 FILESTATUS3 FileSts; 1333 1351 if (g_fVerbose) 1334 1352 WriteStrings(g_hStdOut, "info: Copying \"", pszSrc, "\" to \"", pszDst, "\"...\r\n", NULL); 1335 1353 1336 /* Make sure the destination file isn't read-only before attempting to copying it. */ 1337 FILESTATUS3 FileSts; 1338 APIRET rc = DosQueryPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts)); 1339 if (rc == NO_ERROR && (FileSts.attrFile & FILE_READONLY)) 1340 { 1341 FileSts.attrFile &= ~FILE_READONLY; 1342 1343 /* Don't update the timestamps: */ 1344 *(USHORT *)&FileSts.fdateCreation = 0; 1345 *(USHORT *)&FileSts.ftimeCreation = 0; 1346 *(USHORT *)&FileSts.fdateLastAccess = 0; 1347 *(USHORT *)&FileSts.ftimeLastAccess = 0; 1348 *(USHORT *)&FileSts.fdateLastWrite = 0; 1349 *(USHORT *)&FileSts.ftimeLastWrite = 0; 1350 1351 rc = DosSetPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts), 0 /*fOptions*/); 1352 if (rc != NO_ERROR) 1353 ApiErrorN(rc, 3, "DosSetPathInfo(\"", pszDst, "\",~READONLY,)"); 1354 } 1355 1356 /* Do the copying. */ 1357 rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING); 1358 if (rc == NO_ERROR) 1359 return RTEXITCODE_SUCCESS; 1360 if (rc != ERROR_SHARING_VIOLATION) 1354 if (g_fRealRun) 1355 { 1356 /* Make sure the destination file isn't read-only before attempting to copying it. */ 1357 APIRET rc = DosQueryPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts)); 1358 if (rc == NO_ERROR && (FileSts.attrFile & FILE_READONLY)) 1359 { 1360 FileSts.attrFile &= ~FILE_READONLY; 1361 1362 /* Don't update the timestamps: */ 1363 *(USHORT *)&FileSts.fdateCreation = 0; 1364 *(USHORT *)&FileSts.ftimeCreation = 0; 1365 *(USHORT *)&FileSts.fdateLastAccess = 0; 1366 *(USHORT *)&FileSts.ftimeLastAccess = 0; 1367 *(USHORT *)&FileSts.fdateLastWrite = 0; 1368 *(USHORT *)&FileSts.ftimeLastWrite = 0; 1369 1370 rc = DosSetPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts), 0 /*fOptions*/); 1371 if (rc == ERROR_SHARING_VIOLATION) 1372 { 1373 CacheLdrFile(pszDst); 1374 rc = DosSetPathInfo(pszDst, FIL_STANDARD, &FileSts, sizeof(FileSts), 0 /*fOptions*/); 1375 } 1376 1377 if (rc != NO_ERROR) 1378 ApiErrorN(rc, 3, "DosSetPathInfo(\"", pszDst, "\",~READONLY,)"); 1379 } 1380 1381 /* Do the copying. */ 1382 rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING); 1383 if (rc == NO_ERROR) 1384 return RTEXITCODE_SUCCESS; 1385 if (rc != ERROR_SHARING_VIOLATION) 1386 return ApiErrorN(rc, 3, "Failed copying to \"", pszDst, "\""); 1387 1388 CacheLdrFile(pszDst); 1389 rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING); 1390 if (rc == NO_ERROR) 1391 return RTEXITCODE_SUCCESS; 1361 1392 return ApiErrorN(rc, 3, "Failed copying to \"", pszDst, "\""); 1362 1363 if (g_fVerbose)1364 DoWriteNStr(g_hStdOut, RT_STR_TUPLE("info: Sharing violation - applying DosReplaceModule...\r\n"));1365 rc = DosReplaceModule(pszDst, NULL, NULL);1366 if (rc != NO_ERROR)1367 ApiErrorN(rc, 3, "DosReplaceModule(\"", pszDst, "\",,)");1368 1369 rc = DosCopy(pszSrc, pszDst, DCPY_EXISTING);1370 if (rc == NO_ERROR)1371 return RTEXITCODE_SUCCESS;1372 return ApiErrorN(rc, 3, "Failed copying to \"", pszDst, "\"");1393 } 1394 /* 1395 * Dry run: just check that the source file exists. 1396 */ 1397 else 1398 { 1399 APIRET rc = DosQueryPathInfo(pszSrc, FIL_STANDARD, &FileSts, sizeof(FileSts)); 1400 if (rc == NO_ERROR) 1401 return RTEXITCODE_SUCCESS; 1402 return ApiErrorN(rc, 3, "DosQueryPathInfo failed on \"", pszSrc, "\""); 1403 } 1373 1404 } 1374 1405 … … 1379 1410 static RTEXITCODE CopyFiles(void) 1380 1411 { 1381 /* 1382 * Create the install directory. We do this from the root up as that is 1383 * a nice feature and saves us dealing with trailing slash troubles. 1384 */ 1385 char *psz = g_szDstPath; 1386 if (psz[1] == ':' && RTPATH_IS_SLASH(psz[2])) 1387 psz += 3; 1388 else if (psz[1] == ':') 1389 psz += 2; 1390 else 1391 return ApiError("Unexpected condition", __LINE__); 1392 1393 for (;;) 1394 { 1395 char ch; 1396 while ((ch = *psz) != '\0' && !RTPATH_IS_SLASH(ch)) 1397 psz++; 1398 if (ch != '\0') 1399 *psz = '\0'; 1400 APIRET rc = DosMkDir(g_szDstPath, 0); 1401 if (rc != NO_ERROR && rc != ERROR_ACCESS_DENIED /*HPFS*/ && rc != ERROR_ALREADY_EXISTS /*what one would expect*/) 1402 return ApiErrorN(rc, 3, "DosMkDir(\"", g_szDstPath, "\")"); 1403 if (ch == '\0') 1404 break; 1405 *psz++ = ch; 1406 while ((ch = *psz) != '\0' && RTPATH_IS_SLASH(ch)) 1407 psz++; 1408 if (ch == '\0') 1409 break; 1412 if (g_fRealRun) 1413 { 1414 /* 1415 * Create the install directory. We do this from the root up as that is 1416 * a nice feature and saves us dealing with trailing slash troubles. 1417 */ 1418 char *psz = g_szDstPath; 1419 if (psz[1] == ':' && RTPATH_IS_SLASH(psz[2])) 1420 psz += 3; 1421 else if (psz[1] == ':') 1422 psz += 2; 1423 else 1424 return ApiError("Unexpected condition", __LINE__); 1425 1426 for (;;) 1427 { 1428 char ch; 1429 while ((ch = *psz) != '\0' && !RTPATH_IS_SLASH(ch)) 1430 psz++; 1431 if (ch != '\0') 1432 *psz = '\0'; 1433 APIRET rc = DosMkDir(g_szDstPath, 0); 1434 if (rc != NO_ERROR && rc != ERROR_ACCESS_DENIED /*HPFS*/ && rc != ERROR_ALREADY_EXISTS /*what one would expect*/) 1435 return ApiErrorN(rc, 3, "DosMkDir(\"", g_szDstPath, "\")"); 1436 if (ch == '\0') 1437 break; 1438 *psz++ = ch; 1439 while ((ch = *psz) != '\0' && RTPATH_IS_SLASH(ch)) 1440 psz++; 1441 if (ch == '\0') 1442 break; 1443 } 1410 1444 } 1411 1445 … … 1508 1542 "\r\n" 1509 1543 "Options:\r\n" 1544 " -i, --do-install / -z, --dry-run\r\n" 1545 " Controls whether to do a real install or not. Default: --dry-run\r\n" 1510 1546 " -s<path>, --source[=]<path>\r\n" 1511 1547 " Specifies where the files to install are. Default: Same as installer\r\n" … … 1681 1717 || MatchOptWord(&pszArgs, RT_STR_TUPLE("source"), true)) 1682 1718 ch = 's'; 1719 else if (MatchOptWord(&pszArgs, RT_STR_TUPLE("do-install"))) 1720 ch = 'i'; 1721 else if (MatchOptWord(&pszArgs, RT_STR_TUPLE("dry-run"))) 1722 ch = 'z'; 1683 1723 else if (MatchOptWord(&pszArgs, RT_STR_TUPLE("shared-folders"))) 1684 1724 ch = 'f'; … … 1751 1791 break; 1752 1792 1793 case 'i': 1794 g_fRealRun = true; 1795 break; 1796 1797 case 'z': 1798 g_fRealRun = false; 1799 break; 1800 1753 1801 #define SKIP_OPT_CASES(a_chSkip, a_chDontSkip, a_fFlag) \ 1754 1802 case a_chDontSkip: g_fSkipMask &= ~(a_fFlag); break; \ … … 1809 1857 if (rcExit == RTEXITCODE_SUCCESS) 1810 1858 rcExit = CopyFiles(); 1811 if (rcExit == RTEXITCODE_SUCCESS) 1812 rcExit = WriteConfigSys(); 1813 if (rcExit == RTEXITCODE_SUCCESS) 1814 rcExit = WriteStartupCmd(); 1815 1859 if (g_fRealRun) 1860 { 1861 if (rcExit == RTEXITCODE_SUCCESS) 1862 rcExit = WriteConfigSys(); 1863 if (rcExit == RTEXITCODE_SUCCESS) 1864 rcExit = WriteStartupCmd(); 1865 1866 /* 1867 * Status summary. 1868 */ 1869 if (rcExit == RTEXITCODE_SUCCESS) 1870 WriteStrings(g_hStdOut, "info: Installation successful\r\n", NULL); 1871 else 1872 WriteStrings(g_hStdErr, "info: Installation failed!\r\n", NULL); 1873 } 1874 else if (rcExit == RTEXITCODE_SUCCESS) 1875 WriteStrings(g_hStdOut, "info: Trial run successful\r\n", NULL); 1876 else 1877 WriteStrings(g_hStdErr, "info: Trial run failed!\r\n", NULL); 1816 1878 return rcExit; 1817 1879 }
Note:
See TracChangeset
for help on using the changeset viewer.