@@ -408,30 +408,58 @@ void sys_main_c::SpawnProcess(const char* cmdName, const char* argList)
408
408
#endif
409
409
}
410
410
411
+ std::string GetWineHostVersion ()
412
+ {
413
+ #ifdef _WIN32
414
+ using WineHostVersionFun = void (const char ** /* sysname*/ , const char ** /* release*/ );
415
+ HMODULE mod = GetModuleHandleA (" ntdll.dll" );
416
+ if (!mod)
417
+ return " " ;
418
+ auto ptr = GetProcAddress (mod, " wine_get_host_version" );
419
+ if (!ptr)
420
+ return " " ;
421
+ auto fun = (WineHostVersionFun*)ptr;
422
+ const char * sysname{};
423
+ const char * release{};
424
+ fun (&sysname, &release);
425
+ return sysname ? sysname : " " ;
426
+ #else
427
+ return " " ;
428
+ #endif
429
+ }
430
+
411
431
#if _WIN32 || __linux__
412
- void PlatformOpenURL (const char * url)
432
+ const char * PlatformOpenURL (const char * url)
413
433
{
414
434
#ifdef _WIN32
415
- // There is a surprisingly low limit for the maximum URL length that ShellExecute and browsers can open.
416
- // A common lower limit on Windows is 2083, so we'll definitely refuse to open URLs longer than that.
417
- // Wine on Linux has an indeterminate boundary above which it either crashes or silently does nothing,
418
- // one one system it landed at around 1575 bytes before failure, so put the limit somewhat below that.
419
- if (strlen (url) <= 1500 )
420
- {
421
- ShellExecuteA (NULL , " open" , url, NULL , NULL , SW_SHOWDEFAULT);
422
- }
435
+ const std::string wineHost = GetWineHostVersion ();
436
+ /*
437
+ Wine has some loosely determined maximum length on how long of an URL
438
+ can be, so we pick a "safe" maximum and refuse to open anything longer.
439
+ */
440
+ if ((wineHost == " Linux" || wineHost == " Darwin" ) && strlen (url) > 1500 )
441
+ return AllocString (" Did not open URL, length likely too long for the OS." );
442
+ ShellExecuteA (NULL , " open" , url, NULL , NULL , SW_SHOWDEFAULT);
443
+ return nullptr ;
423
444
#else
424
445
#warning LV: URL opening not implemented on this OS.
425
446
// TODO(LV): Implement URL opening for other OSes.
447
+ return AllocString (" URL opening not implemented on this OS." );
426
448
#endif
427
449
}
428
450
#else
429
- void PlatformOpenURL (const char * url);
451
+ const char * PlatformOpenURL (const char * url);
430
452
#endif
431
453
432
- void sys_main_c::OpenURL (const char * url)
454
+ std::optional<std::string> sys_main_c::OpenURL (const char * url)
433
455
{
434
- PlatformOpenURL (url);
456
+ if (auto err = PlatformOpenURL (url))
457
+ {
458
+ std::string ret = err;
459
+ FreeString (err);
460
+ return ret;
461
+ }
462
+ return {};
435
463
}
436
464
437
465
// ==============================
0 commit comments