URI handling for MacOS

This commit is contained in:
Simon Robertshaw
2012-05-13 13:01:29 +01:00
parent 58ea2b2acf
commit 17229ead05
5 changed files with 59 additions and 2 deletions

View File

@@ -161,6 +161,8 @@ typedef unsigned int pixel;
typedef unsigned char uint8; typedef unsigned char uint8;
extern int saveURIOpen;
extern int amd; extern int amd;
extern int FPSB; extern int FPSB;

View File

@@ -293,6 +293,8 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt);
void info_box(pixel *vid_buf, char *msg); void info_box(pixel *vid_buf, char *msg);
void info_box_overlay(pixel *vid_buf, char *msg);
char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shadow); char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shadow);
int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn); int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn);

View File

@@ -9,6 +9,7 @@
#include "SDLMain.h" #include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */ #include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h> #include <unistd.h>
#include "defines.h"
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4, /* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare but the method still is there and works. To avoid warnings, we declare
@@ -282,6 +283,21 @@ static void CustomApplicationMain (int argc, char **argv)
return TRUE; return TRUE;
} }
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
int tempSaveOpen = [[url host] intValue];
if(tempSaveOpen > 0)
saveURIOpen = tempSaveOpen;
}
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
/* Called when the internal event loop has just started running */ /* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note - (void) applicationDidFinishLaunching: (NSNotification *) note

View File

@@ -1298,7 +1298,7 @@ void info_box(pixel *vid_buf, char *msg)
{ {
int w = textwidth(msg)+16; int w = textwidth(msg)+16;
int x0=(XRES-w)/2,y0=(YRES-24)/2; int x0=(XRES-w)/2,y0=(YRES-24)/2;
clearrect(vid_buf, x0-2, y0-2, w+4, 28); clearrect(vid_buf, x0-2, y0-2, w+4, 28);
drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255); drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255); drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
@@ -1310,6 +1310,16 @@ void info_box(pixel *vid_buf, char *msg)
#endif #endif
} }
void info_box_overlay(pixel *vid_buf, char *msg)
{
int w = textwidth(msg)+16;
int x0=(XRES-w)/2,y0=(YRES-24)/2;
clearrect(vid_buf, x0-2, y0-2, w+4, 28);
drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
}
void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt) void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
{ {
int state = 0; int state = 0;

View File

@@ -202,6 +202,8 @@ static const char *old_ver_msg = "A new version is available - click here!";
char new_message_msg[255]; char new_message_msg[255];
float mheat = 0.0f; float mheat = 0.0f;
int saveURIOpen = 0;
int do_open = 0; int do_open = 0;
int sys_pause = 0; int sys_pause = 0;
int sys_shortcuts = 1; int sys_shortcuts = 1;
@@ -777,6 +779,7 @@ int main(int argc, char *argv[])
part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
part_vbuf_store = part_vbuf; part_vbuf_store = part_vbuf;
pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
int saveOpenError = 0;
gravity_init(); gravity_init();
GSPEED = 1; GSPEED = 1;
@@ -831,6 +834,7 @@ int main(int argc, char *argv[])
svf_filename[0] = 0; svf_filename[0] = 0;
svf_fileopen = 1; svf_fileopen = 1;
} else { } else {
saveOpenError = 1;
svf_last = NULL; svf_last = NULL;
svf_lsize = 0; svf_lsize = 0;
free(file_data); free(file_data);
@@ -839,7 +843,6 @@ int main(int argc, char *argv[])
} }
i++; i++;
} }
} }
load_presets(); load_presets();
@@ -916,6 +919,11 @@ int main(int argc, char *argv[])
error_ui(vid_buf, 0, "Unsupported CPU. Try another version."); error_ui(vid_buf, 0, "Unsupported CPU. Try another version.");
return 1; return 1;
} }
if(saveOpenError)
{
error_ui(vid_buf, 0, "Unable to open save file.");
}
http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0); http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0);
if (svf_login) { if (svf_login) {
@@ -1128,6 +1136,7 @@ int main(int argc, char *argv[])
{ {
if (!do_s_check && http_async_req_status(http_session_check)) if (!do_s_check && http_async_req_status(http_session_check))
{ {
char saveURIOpenString[512];
check_data = http_async_req_stop(http_session_check, &http_s_ret, NULL); check_data = http_async_req_stop(http_session_check, &http_s_ret, NULL);
if (http_ret==200 && check_data) if (http_ret==200 && check_data)
{ {
@@ -1212,7 +1221,15 @@ int main(int argc, char *argv[])
svf_messages = 0; svf_messages = 0;
} }
http_session_check = NULL; http_session_check = NULL;
if(saveURIOpen)
{
sprintf(saveURIOpenString, "%d", saveURIOpen);
open_ui(vid_buf, saveURIOpenString, NULL);
saveURIOpen = 0;
}
} else { } else {
if(saveURIOpen)
info_box_overlay(vid_buf, "Waiting for login...");
clearrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14); clearrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14);
drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255); drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255);
drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255); drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255);
@@ -1231,6 +1248,16 @@ int main(int argc, char *argv[])
} }
do_s_check = (do_s_check+1) & 15; do_s_check = (do_s_check+1) & 15;
} }
else
{
char saveURIOpenString[512];
if(saveURIOpen)
{
sprintf(saveURIOpenString, "%d", saveURIOpen);
open_ui(vid_buf, saveURIOpenString, NULL);
saveURIOpen = 0;
}
}
#ifdef LUACONSOLE #ifdef LUACONSOLE
if(sdl_key){ if(sdl_key){
if(!luacon_keyevent(sdl_key, sdl_mod, LUACON_KDOWN)) if(!luacon_keyevent(sdl_key, sdl_mod, LUACON_KDOWN))