mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Merge pull request #1171 from josch1710/master
Support for opening URLs
This commit is contained in:
commit
d0172cbada
2 changed files with 92 additions and 15 deletions
|
@ -41,7 +41,7 @@ APP_AUTHOR := UnknownShadow200
|
||||||
# options for code generation
|
# options for code generation
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
CC := gcc
|
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
|
LDFLAGS := -Zhigh-mem -Zomf -Zargs-wild -Zargs-resp -Zlinker DISABLE -Zlinker 1121
|
||||||
LIBS := -lcx -lmmpm2 -lpthread -lSDL2
|
LIBS := -lcx -lmmpm2 -lpthread -lSDL2
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,9 @@ cc_bool Platform_SingleProcess;
|
||||||
#include <kernel/image.h>
|
#include <kernel/image.h>
|
||||||
#elif defined CC_BUILD_OS2
|
#elif defined CC_BUILD_OS2
|
||||||
#include <libcx/net.h>
|
#include <libcx/net.h>
|
||||||
#define INCL_DOSPROCESS
|
#define INCL_DOS
|
||||||
|
#define INCL_DOSERRORS
|
||||||
|
#define INCL_PM
|
||||||
#include <os2.h>
|
#include <os2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ TimeMS DateTime_CurrentUTC(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DateTime_CurrentLocal(struct DateTime* t) {
|
void DateTime_CurrentLocal(struct DateTime* t) {
|
||||||
struct timeval cur;
|
struct timeval cur;
|
||||||
struct tm loc_time;
|
struct tm loc_time;
|
||||||
gettimeofday(&cur, NULL);
|
gettimeofday(&cur, NULL);
|
||||||
localtime_r(&cur.tv_sec, &loc_time);
|
localtime_r(&cur.tv_sec, &loc_time);
|
||||||
|
@ -343,7 +345,7 @@ static void* ExecThread(void* param) {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void* ExecThread(void* param) {
|
static void* ExecThread(void* param) {
|
||||||
((Thread_StartFunc)param)();
|
((Thread_StartFunc)param)();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -498,7 +500,7 @@ static void FontDirCallback(const cc_string* path, void* obj) {
|
||||||
SysFonts_Register(path);
|
SysFonts_Register(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform_LoadSysFonts(void) {
|
void Platform_LoadSysFonts(void) {
|
||||||
int i;
|
int i;
|
||||||
#if defined CC_BUILD_ANDROID
|
#if defined CC_BUILD_ANDROID
|
||||||
static const cc_string dirs[] = {
|
static const cc_string dirs[] = {
|
||||||
|
@ -589,14 +591,14 @@ static cc_result ParseHost(const char* host, int port, cc_sockaddr* addrs, int*
|
||||||
if (res) return res;
|
if (res) return res;
|
||||||
|
|
||||||
/* Prefer IPv4 addresses first */
|
/* Prefer IPv4 addresses first */
|
||||||
for (cur = result; cur && i < SOCKET_MAX_ADDRS; cur = cur->ai_next)
|
for (cur = result; cur && i < SOCKET_MAX_ADDRS; cur = cur->ai_next)
|
||||||
{
|
{
|
||||||
if (cur->ai_family != AF_INET) continue;
|
if (cur->ai_family != AF_INET) continue;
|
||||||
Mem_Copy(addrs[i].data, cur->ai_addr, cur->ai_addrlen);
|
Mem_Copy(addrs[i].data, cur->ai_addr, cur->ai_addrlen);
|
||||||
addrs[i].size = cur->ai_addrlen; i++;
|
addrs[i].size = cur->ai_addrlen; i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cur = result; cur && i < SOCKET_MAX_ADDRS; cur = cur->ai_next)
|
for (cur = result; cur && i < SOCKET_MAX_ADDRS; cur = cur->ai_next)
|
||||||
{
|
{
|
||||||
if (cur->ai_family == AF_INET) continue;
|
if (cur->ai_family == AF_INET) continue;
|
||||||
Mem_Copy(addrs[i].data, cur->ai_addr, cur->ai_addrlen);
|
Mem_Copy(addrs[i].data, cur->ai_addr, cur->ai_addrlen);
|
||||||
|
@ -791,6 +793,81 @@ cc_result Process_StartOpen(const cc_string* args) {
|
||||||
}
|
}
|
||||||
#elif defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS
|
#elif defined CC_BUILD_HAIKU || defined CC_BUILD_BEOS
|
||||||
/* Implemented in interop_BeOS.cpp */
|
/* 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 = ¶mbuffer[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
|
#else
|
||||||
cc_result Process_StartOpen(const cc_string* args) {
|
cc_result Process_StartOpen(const cc_string* args) {
|
||||||
char str[NATIVE_STR_LEN];
|
char str[NATIVE_STR_LEN];
|
||||||
|
@ -1054,7 +1131,7 @@ const cc_string DynamicLib_Ext = String_FromConst(".dylib");
|
||||||
void* DynamicLib_Load2(const cc_string* path) {
|
void* DynamicLib_Load2(const cc_string* path) {
|
||||||
char str[NATIVE_STR_LEN];
|
char str[NATIVE_STR_LEN];
|
||||||
String_EncodeUtf8(str, path);
|
String_EncodeUtf8(str, path);
|
||||||
return NSAddImage(str, NSADDIMAGE_OPTION_WITH_SEARCHING |
|
return NSAddImage(str, NSADDIMAGE_OPTION_WITH_SEARCHING |
|
||||||
NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,7 +1258,7 @@ void Platform_Init(void) {
|
||||||
Platform_SingleProcess = true;
|
Platform_SingleProcess = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Platform_InitPosix();
|
Platform_InitPosix();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1217,7 +1294,7 @@ static void DecipherBlock(cc_uint32* v, const cc_uint32* key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ENC1 0xCC005EC0
|
#define ENC1 0xCC005EC0
|
||||||
#define ENC2 0x0DA4A0DE
|
#define ENC2 0x0DA4A0DE
|
||||||
#define ENC3 0xC0DED000
|
#define ENC3 0xC0DED000
|
||||||
#define MACHINEID_LEN 32
|
#define MACHINEID_LEN 32
|
||||||
#define ENC_SIZE 8 /* 2 32 bit ints per block */
|
#define ENC_SIZE 8 /* 2 32 bit ints per block */
|
||||||
|
@ -1268,7 +1345,7 @@ static cc_result GetMachineID(cc_uint32* key) {
|
||||||
#ifdef kIOPlatformUUIDKey
|
#ifdef kIOPlatformUUIDKey
|
||||||
registry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
|
registry = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
|
||||||
if (!registry) return ERR_NOT_SUPPORTED;
|
if (!registry) return ERR_NOT_SUPPORTED;
|
||||||
|
|
||||||
devID = IORegistryEntryCreateCFProperty(registry, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
|
devID = IORegistryEntryCreateCFProperty(registry, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
|
||||||
if (devID && CFStringGetCString(devID, tmp, sizeof(tmp), kCFStringEncodingUTF8)) {
|
if (devID && CFStringGetCString(devID, tmp, sizeof(tmp), kCFStringEncodingUTF8)) {
|
||||||
DecodeMachineID(tmp, String_Length(tmp), key);
|
DecodeMachineID(tmp, String_Length(tmp), key);
|
||||||
|
@ -1276,13 +1353,13 @@ static cc_result GetMachineID(cc_uint32* key) {
|
||||||
#else
|
#else
|
||||||
registry = IOServiceGetMatchingService(kIOMasterPortDefault,
|
registry = IOServiceGetMatchingService(kIOMasterPortDefault,
|
||||||
IOServiceMatching("IOPlatformExpertDevice"));
|
IOServiceMatching("IOPlatformExpertDevice"));
|
||||||
|
|
||||||
devID = IORegistryEntryCreateCFProperty(registry, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0);
|
devID = IORegistryEntryCreateCFProperty(registry, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, 0);
|
||||||
if (devID && CFStringGetCString(devID, tmp, sizeof(tmp), kCFStringEncodingUTF8)) {
|
if (devID && CFStringGetCString(devID, tmp, sizeof(tmp), kCFStringEncodingUTF8)) {
|
||||||
Mem_Copy(key, tmp, MACHINEID_LEN / 2);
|
Mem_Copy(key, tmp, MACHINEID_LEN / 2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (devID) CFRelease(devID);
|
if (devID) CFRelease(devID);
|
||||||
IOObjectRelease(registry);
|
IOObjectRelease(registry);
|
||||||
return tmp[0] ? 0 : ERR_NOT_SUPPORTED;
|
return tmp[0] ? 0 : ERR_NOT_SUPPORTED;
|
||||||
|
@ -1345,10 +1422,10 @@ extern void GetDeviceUUID(cc_string* str);
|
||||||
static cc_result GetMachineID(cc_uint32* key) {
|
static cc_result GetMachineID(cc_uint32* key) {
|
||||||
cc_string str; char strBuffer[STRING_SIZE];
|
cc_string str; char strBuffer[STRING_SIZE];
|
||||||
String_InitArray(str, strBuffer);
|
String_InitArray(str, strBuffer);
|
||||||
|
|
||||||
GetDeviceUUID(&str);
|
GetDeviceUUID(&str);
|
||||||
if (!str.length) return ERR_NOT_SUPPORTED;
|
if (!str.length) return ERR_NOT_SUPPORTED;
|
||||||
|
|
||||||
DecodeMachineID(strBuffer, str.length, key);
|
DecodeMachineID(strBuffer, str.length, key);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue