Opens given file in associated application
| 339 | |
| 340 | // Opens given file in associated application |
| 341 | bool OpenDocument( const std::filesystem::path& path ) |
| 342 | { |
| 343 | #ifdef _WIN32 |
| 344 | HINSTANCE result = ShellExecuteW( NULL, L"open", path.c_str(), NULL, NULL, SW_SHOWNORMAL); |
| 345 | // "If the function succeeds, it returns a value greater than 32" |
| 346 | if ( ( INT_PTR )result <= 32 ) |
| 347 | { |
| 348 | spdlog::warn( "Error opening {}, error code {}", utf8string( path ), ( int )( INT_PTR )result ); |
| 349 | return false; |
| 350 | } |
| 351 | return true; |
| 352 | |
| 353 | #else |
| 354 | #ifdef __EMSCRIPTEN__ |
| 355 | ( void )path; |
| 356 | return false; |
| 357 | #else |
| 358 | std::ostringstream command; |
| 359 | #ifdef __APPLE__ |
| 360 | command << "open " << std::quoted( path.string(), '\'' ); |
| 361 | #else |
| 362 | command << "xdg-open " << std::quoted( path.string(), '\'' ) << " &"; |
| 363 | #endif |
| 364 | auto openres = system( command.str().c_str() ); |
| 365 | if ( openres == -1 ) |
| 366 | { |
| 367 | spdlog::warn( "Error opening {}", path.string() ); |
| 368 | return false; |
| 369 | } |
| 370 | return true; |
| 371 | #endif |
| 372 | #endif // _WIN32 |
| 373 | } |
| 374 | |
| 375 | #ifdef _WIN32 |
| 376 | std::filesystem::path GetWindowsInstallDirectory() |
no test coverage detected