X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FOpenGL_Windows.cpp;h=34c264716534427b0a58eb11bcea292389507432;hb=cbf8f0bfaf3c752f852f0cf87c620305797c73b8;hp=5c8f491fd2dfc67e38d413a840fb8cd505f3102d;hpb=464f909216b95d2a35bc332f0fc83e278e7b8864;p=lugaru.git diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 5c8f491..34c2647 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -425,6 +425,11 @@ static void initSDLKeyTable(void) static inline int clamp_sdl_mouse_button(Uint8 button) { + if (button == 2) // right mouse button is button 3 in SDL. + button = 3; + else if (button == 3) + button = 2; + if ((button >= 1) && (button <= 3)) return button - 1; return -1; @@ -549,8 +554,7 @@ Boolean SetUp (Game & game) randSeed = UpTime().lo; osx = 0; -// ifstream ipstream(":Data:config.txt", std::ios::in /*| std::ios::nocreate*/); - ifstream ipstream("./Data/config.txt", std::ios::in /*| std::ios::nocreate*/); + ifstream ipstream(ConvertFileName(":Data:config.txt"), std::ios::in /*| std::ios::nocreate*/); detail=1; ismotionblur=0; usermousesensitivity=1; @@ -600,8 +604,7 @@ Boolean SetUp (Game & game) selectDetail(kContextWidth, kContextHeight, kBitsPerPixel, detail); if(!ipstream) { - //ofstream opstream(":Data:config.txt"); - ofstream opstream("./Data/config.txt"); + ofstream opstream(ConvertFileName(":Data:config.txt", "w")); opstream << "Screenwidth:\n"; opstream << kContextWidth; opstream << "\nScreenheight:\n"; @@ -1316,6 +1319,88 @@ static bool IsFocused() return true; } + +#if PLATFORM_LINUX +#include +#include +static bool try_launch_browser(const char *browser, const char *url) +{ + // make sure string isn't empty... + while ( (*browser) && (isspace(*browser)) ) browser++; + if (*browser == '\0') return false; + + bool seenurl = false; + char buf[4096]; // !!! FIXME: we aren't checking for overflow here! + char *dst = buf; + while (*browser) + { + char ch = *(browser++); + if (ch == '%') + { + ch = *(browser++); + if (ch == '%') + *(dst++) = '%'; + else if (ch == 's') // "%s" == insert URL here. + { + *(dst++) = '\''; + strcpy(dst, url); + dst += strlen(url); + *(dst++) = '\''; + seenurl = true; + } + // (not %% or %s? Drop the char.) + } + else + { + *(dst++) = ch; + } + } + + *dst = '\0'; + if (!seenurl) + { + strcat(dst, " "); + strcat(dst, url); + } + return(system(buf) == 0); +} +#endif + + +static void launch_web_browser(const char *url) +{ +#ifdef WIN32 + ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); + +// lousy linux doesn't have a clean way to do this, but you can point people +// to docs on the BROWSER variable: +// http://www.catb.org/~esr/BROWSER/ +#elif PLATFORM_LINUX + if (strchr(url, '\'') != NULL) // Prevent simple shell injection. + return; + + const char *envr = getenv("BROWSER"); + if (envr == NULL) // not specified? We'll try a pseudo-sane list... + envr = "opera:mozilla:konqueror:firefox:netscape:xterm -e links:xterm -e lynx:"; + + char *ptr = (char *) alloca(strlen(envr) + 1); + if (ptr == NULL) + return; + strcpy(ptr, envr); + envr = ptr; + + while ((ptr = strchr(envr, ':')) != NULL) + { + *ptr = '\0'; + if (try_launch_browser(envr, url)) + return; + envr = ptr + 1; + } + + try_launch_browser(envr, url); +#endif +} + int main (void) { LOGFUNC; @@ -1431,14 +1516,7 @@ int main (void) // if(game.registernow){ if(regnow) { - #ifndef WIN32 - STUBBED("launch a web browser"); - #else - char url[100]; - sprintf(url,"http://www.wolfire.com/registerpc.html"); - // LaunchURL(url); - ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); - #endif + launch_web_browser("http://www.wolfire.com/registerpc.html"); } return 0; }