Merge pull request #1171 from josch1710/master

Support for opening URLs
This commit is contained in:
UnknownShadow200 2024-04-20 13:34:49 +10:00 committed by GitHub
commit d0172cbada
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 92 additions and 15 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
@ -791,6 +793,81 @@ 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], params[100], parambuffer[500], *paramptr;
UCHAR userPath[CCHMAXPATH], sysPath[CCHMAXPATH];
PRFPROFILE profile = { sizeof(userPath), userPath, sizeof(sysPath), sysPath };
HINI os2Ini;
HAB hAnchor = WinQueryAnchorBlock(WinQueryActiveWindow(HWND_DESKTOP));
RESULTCODES result = { 0 };
PROGDETAILS details;
// We get URL
String_EncodeUtf8(str, args);
// Initialize buffers
Mem_Set(path, 0, sizeof(path));
Mem_Set(parambuffer, 0, sizeof(parambuffer));
Mem_Set(params, 0, sizeof(params));
// 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, params, sizeof(params));
PrfCloseProfile(os2Ini);
// concat arguments
if (strlen(params) > 0) strncat(params, " ", 20);
strncat(params, str, sizeof(str));
// Build parameter buffer
strcpy(parambuffer, "Browser");
paramptr = &parambuffer[strlen(parambuffer)+1];
// copy params to buffer
strcpy(paramptr, params);
printf("params %p %p %s\n", parambuffer, paramptr, paramptr);
paramptr += strlen(params) + 1;
// To be sure: Terminate parameter list with NULL
*paramptr = '\0';
// Last step: Execute detached browser
rc = DosExecPgm(userPath, sizeof(userPath), EXEC_ASYNC,
parambuffer, 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];