Added support for opening URLs

This commit is contained in:
Jochen Sch„fer 2024-04-11 09:17:26 +02:00
parent 69d4a3f0ff
commit aa6643370a
2 changed files with 68 additions and 3 deletions

View File

@ -41,7 +41,7 @@ APP_AUTHOR := UnknownShadow200
# options for code generation
#---------------------------------------------------------------------------------
CC := gcc
CFLAGS := -pipe -fno-math-errno -O0 -g -mtune=pentium4 -msse2 -march=i686 -idirafter /@unixroot/usr/include/os2tk45 -DOS2
CFLAGS := -pipe -fno-math-errno -O3 -g -mtune=pentium4 -msse2 -march=i686 -idirafter /@unixroot/usr/include/os2tk45 -DOS2
LDFLAGS := -Zhigh-mem -Zomf -Zargs-wild -Zargs-resp -Zlinker DISABLE -Zlinker 1121
LIBS := -lcx -lmmpm2 -lpthread -lSDL2

View File

@ -63,7 +63,9 @@ cc_bool Platform_SingleProcess;
#include <kernel/image.h>
#elif defined CC_BUILD_OS2
#include <libcx/net.h>
#define INCL_DOSPROCESS
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_PM
#include <os2.h>
#endif
@ -786,6 +788,69 @@ cc_result Process_StartOpen(const cc_string* args) {
}
#elif defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS
/* Implemented in interop_BeOS.cpp */
#elif defined CC_BUILD_OS2
inline static void ShowErrorMessage(const char *url) {
static char errorMsg[] = "Could not open browser. Please go to: ";
cc_string message = String_Init(errorMsg, strlen(errorMsg), 500);
String_AppendConst(&message, url);
Logger_DialogWarn(&message);
}
cc_result Process_StartOpen(const cc_string* args) {
char str[NATIVE_STR_LEN];
APIRET rc;
UCHAR path[CCHMAXPATH], parameter[NATIVE_STR_LEN];
UCHAR userPath[CCHMAXPATH], sysPath[CCHMAXPATH];
PRFPROFILE profile = { sizeof(userPath), userPath, sizeof(sysPath), sysPath };
HINI os2Ini;
HAB hAnchor = WinQueryAnchorBlock(WinQueryActiveWindow(HWND_DESKTOP));
RESULTCODES result = { 0 };
// We get URL
String_EncodeUtf8(str, args);
// Initialize buffers
Mem_Set(path, 0, sizeof(path));
Mem_Set(parameter, 0, sizeof(parameter));
// We have to look in the OS/2 configuration for the default browser.
// First step: Find the configuration files
if (!PrfQueryProfile(hAnchor, &profile)) {
ShowErrorMessage(str);
return 0;
}
// Second step: Open the configuration files and read exe path and parameters
os2Ini = PrfOpenProfile(hAnchor, userPath);
if (os2Ini == NULLHANDLE) {
ShowErrorMessage(str);
return 0;
}
if (!PrfQueryProfileString(os2Ini, "WPURLDEFAULTSETTINGS", "DefaultBrowserExe",
NULL, path, sizeof(path))) {
PrfCloseProfile(os2Ini);
ShowErrorMessage(str);
return 0;
}
PrfQueryProfileString(os2Ini, "WPURLDEFAULTSETTINGS", "DefaultBrowserParameters",
NULL, parameter, sizeof(parameter));
PrfCloseProfile(os2Ini);
// concat arguments
strncat(parameter, " ", 20);
strncat(parameter, str, sizeof(str));
// Last step: Execute detached browser
rc = DosExecPgm(userPath, sizeof(userPath), EXEC_ASYNC,
parameter, NULL, &result, path);
if (rc != NO_ERROR) {
ShowErrorMessage(str);
return 0;
}
return 0;
}
#else
cc_result Process_StartOpen(const cc_string* args) {
char str[NATIVE_STR_LEN];