| 476 | } |
| 477 | |
| 478 | static StringSpan getApplicationRootDirectory(StringPath& applicationRootDirectory) |
| 479 | { |
| 480 | #if SC_PLATFORM_WINDOWS |
| 481 | StringSpan exeView = getExecutablePath(applicationRootDirectory); |
| 482 | if (exeView.isEmpty()) |
| 483 | return {}; |
| 484 | native_char_t* buffer = applicationRootDirectory.writableSpan().data(); |
| 485 | size_t lastSeparator = 0; |
| 486 | bool found = false; |
| 487 | for (size_t idx = 0; idx < nativeLength(exeView); ++idx) |
| 488 | { |
| 489 | if (isSeparator(buffer[idx])) |
| 490 | { |
| 491 | lastSeparator = idx; |
| 492 | found = true; |
| 493 | } |
| 494 | } |
| 495 | if (!found) |
| 496 | { |
| 497 | (void)applicationRootDirectory.resize(0); |
| 498 | return {}; |
| 499 | } |
| 500 | (void)applicationRootDirectory.resize(lastSeparator); |
| 501 | return applicationRootDirectory.view(); |
| 502 | #elif SC_PLATFORM_APPLE |
| 503 | CFBundleRef mainBundle = CFBundleGetMainBundle(); |
| 504 | if (mainBundle != nullptr) |
| 505 | { |
| 506 | CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle); |
| 507 | if (bundleURL != nullptr) |
| 508 | { |
| 509 | uint8_t* path = reinterpret_cast<uint8_t*>(applicationRootDirectory.writableSpan().data()); |
| 510 | if (CFURLGetFileSystemRepresentation(bundleURL, true, path, StringPath::MaxPath)) |
| 511 | { |
| 512 | (void)applicationRootDirectory.resize(::strlen(reinterpret_cast<char*>(path))); |
| 513 | CFRelease(bundleURL); |
| 514 | return applicationRootDirectory.view(); |
| 515 | } |
| 516 | CFRelease(bundleURL); |
| 517 | } |
| 518 | } |
| 519 | StringSpan executablePath = getExecutablePath(applicationRootDirectory); |
| 520 | if (!executablePath.isEmpty()) |
| 521 | { |
| 522 | native_char_t* buffer = applicationRootDirectory.writableSpan().data(); |
| 523 | for (size_t idx = nativeLength(executablePath); idx > 0; --idx) |
| 524 | { |
| 525 | if (buffer[idx - 1] == '/') |
| 526 | { |
| 527 | (void)applicationRootDirectory.resize(idx - 1); |
| 528 | return applicationRootDirectory.view(); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | return {}; |
| 533 | #else |
| 534 | StringSpan executablePath = getExecutablePath(applicationRootDirectory); |
| 535 | if (!executablePath.isEmpty()) |
no test coverage detected