Changeset 68440 in vbox
- Timestamp:
- Aug 17, 2017 11:50:05 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 117583
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibVideo.cpp
r68436 r68440 373 373 unsigned x, unsigned y, bool fEnabled) 374 374 { 375 #if defined(VBOX_WITH_GUEST_PROPS)375 #ifdef VBOX_WITH_GUEST_PROPS 376 376 using namespace guestProp; 377 377 378 HGCMCLIENTID idClient = 0; 379 unsigned cx2, cy2, cBits2, x2, y2, cHighestScreen, cHighestScreen2; 380 bool fEnabled2; 381 int rc; 382 int rc2 = VERR_INTERNAL_ERROR; 383 384 rc = VbglR3VideoModeGetHighestSavedScreen(&cHighestScreen); 385 if (RT_SUCCESS(rc)) 378 unsigned cHighestScreen = 0; 379 int rc = VbglR3VideoModeGetHighestSavedScreen(&cHighestScreen); 380 if (RT_SUCCESS(rc)) 381 { 382 HGCMCLIENTID idClient = 0; 386 383 rc = VbglR3GuestPropConnect(&idClient); 387 if (RT_SUCCESS(rc)) 388 { 389 char szModeName[MAX_NAME_LEN]; 390 char szModeParms[MAX_VALUE_LEN]; 391 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX "%u", idScreen); 392 RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u,%ux%u,%u", cx, cy, cBits, x, y, (unsigned) fEnabled); 393 394 rc = VbglR3GuestPropWriteValue(idClient, szModeName, szModeParms); 395 /* Write out the mode using the legacy name too, in case the user 396 * re-installs older Additions. */ 397 if (idScreen == 0) 384 if (RT_SUCCESS(rc)) 398 385 { 399 RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u", cx, cy, cBits); 400 VbglR3GuestPropWriteValue(idClient, VIDEO_PROP_PREFIX "SavedMode", szModeParms); 386 int rc2; 387 char szModeName[MAX_NAME_LEN]; 388 char szModeParms[MAX_VALUE_LEN]; 389 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX "%u", idScreen); 390 RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u,%ux%u,%u", cx, cy, cBits, x, y, (unsigned) fEnabled); 391 392 rc = VbglR3GuestPropWriteValue(idClient, szModeName, szModeParms); 393 /* Write out the mode using the legacy name too, in case the user 394 * re-installs older Additions. */ 395 if (idScreen == 0) 396 { 397 RTStrPrintf(szModeParms, sizeof(szModeParms), "%ux%ux%u", cx, cy, cBits); 398 VbglR3GuestPropWriteValue(idClient, VIDEO_PROP_PREFIX "SavedMode", szModeParms); 399 } 400 401 rc2 = VbglR3GuestPropDisconnect(idClient); 402 if (rc != VINF_PERMISSION_DENIED) 403 { 404 if (RT_SUCCESS(rc)) 405 rc = rc2; 406 if (RT_SUCCESS(rc)) 407 { 408 /* Sanity check 1. We do not try to make allowance for someone else 409 * changing saved settings at the same time as us. */ 410 bool fEnabled2 = false; 411 unsigned cx2 = 0; 412 unsigned cy2 = 0; 413 unsigned cBits2 = 0; 414 unsigned x2 = 0; 415 unsigned y2 = 0; 416 rc = VbglR3RetrieveVideoMode(idScreen, &cx2, &cy2, &cBits2, &x2, &y2, &fEnabled2); 417 if ( RT_SUCCESS(rc) 418 && (cx != cx2 || cy != cy2 || cBits != cBits2 || x != x2 || y != y2 || fEnabled != fEnabled2)) 419 rc = VERR_WRITE_ERROR; 420 /* Sanity check 2. Same comment. */ 421 else if (RT_SUCCESS(rc)) 422 { 423 unsigned cHighestScreen2 = 0; 424 rc = VbglR3VideoModeGetHighestSavedScreen(&cHighestScreen2); 425 if (RT_SUCCESS(rc)) 426 if (cHighestScreen2 != RT_MAX(cHighestScreen, idScreen)) 427 rc = VERR_INTERNAL_ERROR; 428 } 429 } 430 } 401 431 } 402 432 } 403 if (idClient != 0)404 rc2 = VbglR3GuestPropDisconnect(idClient);405 if (rc == VINF_PERMISSION_DENIED)406 return rc;407 if (RT_SUCCESS(rc))408 rc = rc2;409 /* Sanity check 1. We do not try to make allowance for someone else410 * changing saved settings at the same time as us. */411 if (RT_SUCCESS(rc))412 {413 rc = VbglR3RetrieveVideoMode(idScreen, &cx2, &cy2, &cBits2, &x2, &y2, &fEnabled2);414 if ( RT_SUCCESS(rc)415 && (cx != cx2 || cy != cy2 || cBits != cBits2 || x != x2 || y != y2 || fEnabled != fEnabled2))416 rc = VERR_WRITE_ERROR;417 }418 /* Sanity check 2. Same comment. */419 if (RT_SUCCESS(rc))420 rc = VbglR3VideoModeGetHighestSavedScreen(&cHighestScreen2);421 if (RT_SUCCESS(rc))422 if (cHighestScreen2 != RT_MAX(cHighestScreen, idScreen))423 rc = VERR_INTERNAL_ERROR;424 433 return rc; 425 434 #else /* !VBOX_WITH_GUEST_PROPS */ … … 447 456 bool *pfEnabled) 448 457 { 449 #if defined(VBOX_WITH_GUEST_PROPS)458 #ifdef VBOX_WITH_GUEST_PROPS 450 459 using namespace guestProp; 451 460 … … 454 463 * guest property store. 455 464 */ 456 /* The buffer for VbglR3GuestPropReadValue. If this is too small then457 * something is wrong with the data stored in the property. */458 char szModeParms[1024];459 465 HGCMCLIENTID idClient = 0; 460 int cMatches; 461 unsigned cx, cy, cBits; 462 unsigned x = 0; 463 unsigned y = 0; 464 unsigned fEnabled = 1; 465 int rc; 466 int rc2 = VERR_UNRESOLVED_ERROR; 467 468 rc = VbglR3GuestPropConnect(&idClient); 469 if (RT_SUCCESS(rc)) 470 { 471 /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */ 472 char szModeName[MAX_NAME_LEN]; 466 int rc = VbglR3GuestPropConnect(&idClient); 467 if (RT_SUCCESS(rc)) 468 { 469 int rc2; 470 /* The buffer for VbglR3GuestPropReadValue. If this is too small then 471 * something is wrong with the data stored in the property. */ 472 char szModeParms[1024]; 473 char szModeName[MAX_NAME_LEN]; /** @todo add a VbglR3GuestPropReadValueF/FV that does the RTStrPrintf for you. */ 473 474 RTStrPrintf(szModeName, sizeof(szModeName), VIDEO_PROP_PREFIX "%u", idScreen); 474 475 rc = VbglR3GuestPropReadValue(idClient, szModeName, szModeParms, sizeof(szModeParms), NULL); … … 479 480 szModeParms, sizeof(szModeParms), 480 481 NULL); 481 }482 if (idClient != 0)483 482 rc2 = VbglR3GuestPropDisconnect(idClient); 484 if (RT_SUCCESS(rc)) 485 rc = rc2; 486 487 /* 488 * Now we convert the string returned to numeric values. 489 */ 490 if (RT_SUCCESS(rc)) 491 { 492 char c1, c2; 493 cMatches = sscanf(szModeParms, "%5ux%5ux%2u%c%5ux%5u,%1u%c", &cx, &cy, &cBits, &c1, &x, &y, &fEnabled, &c2); 494 if ((cMatches == 7 && c1 == ',') || cMatches == 3) 495 rc = VINF_SUCCESS; 496 else if (cMatches < 0) 497 rc = VERR_READ_ERROR; 498 else 499 rc = VERR_PARSE_ERROR; 500 } 501 502 /* 503 * And clean up and return the values if we successfully obtained them. 504 */ 505 if (RT_SUCCESS(rc)) 506 { 507 if (pcx) 508 *pcx = cx; 509 if (pcy) 510 *pcy = cy; 511 if (pcBits) 512 *pcBits = cBits; 513 if (px) 514 *px = x; 515 if (py) 516 *py = y; 517 if (pfEnabled) 518 *pfEnabled = RT_BOOL(fEnabled); 519 } 483 if (RT_SUCCESS(rc)) 484 rc = rc2; 485 486 /* 487 * Now we convert the string returned to numeric values. 488 */ 489 if (RT_SUCCESS(rc)) 490 { 491 unsigned cx = 0; 492 unsigned cy = 0; 493 unsigned cBits = 0; 494 unsigned x = 0; 495 unsigned y = 0; 496 unsigned fEnabled = 1; 497 char ch1 = 0; 498 char ch2 = 0; 499 int cMatches = sscanf(szModeParms, "%5ux%5ux%2u%c%5ux%5u,%1u%c", &cx, &cy, &cBits, &ch1, &x, &y, &fEnabled, &ch2); 500 if ( (cMatches == 7 && ch1 == ',') 501 || cMatches == 3) 502 { 503 if (pcx) 504 *pcx = cx; 505 if (pcy) 506 *pcy = cy; 507 if (pcBits) 508 *pcBits = cBits; 509 if (px) 510 *px = x; 511 if (py) 512 *py = y; 513 if (pfEnabled) 514 *pfEnabled = RT_BOOL(fEnabled); 515 rc = VINF_SUCCESS; 516 } 517 else if (cMatches < 0) 518 rc = VERR_READ_ERROR; 519 else 520 rc = VERR_PARSE_ERROR; 521 } 522 } 523 520 524 return rc; 521 525 #else /* !VBOX_WITH_GUEST_PROPS */
Note:
See TracChangeset
for help on using the changeset viewer.