]> icculus.org git repositories - taylor/freespace2.git/blob - src/platform/win.cpp
support opening URLs in default browser
[taylor/freespace2.git] / src / platform / win.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 #ifndef PLAT_UNIX
10
11 #define WIN32_LEAN_AND_MEAN
12 #include <shellapi.h>
13
14 #include "SDL.h"
15
16
17 int platform_open_url(const char *url)
18 {
19         char s_url[256];
20
21         // make sure it's a valid www address
22         if ( !SDL_strncasecmp(url, "http://", 7) || !SDL_strncasecmp(url, "https://", 8) ) {
23                 SDL_strlcpy(s_url, url, SDL_arraysize(s_url));
24         } else {
25                 SDL_strlcpy(s_url, "http://", SDL_arraysize(s_url));
26                 SDL_strlcat(s_url, url, SDL_arraysize(s_url));
27         }
28
29         int rval = (int) ShellExecute(NULL, "open", s_url, NULL, NULL, SW_SHOW);
30
31         if (rval < 32) {
32                 switch (rval) {
33                         case 0:
34                         case ERROR_BAD_FORMAT:
35                         case SE_ERR_ACCESSDENIED:
36                         case SE_ERR_ASSOCINCOMPLETE:
37                         case SE_ERR_DDEBUSY:
38                         case SE_ERR_DDEFAIL:
39                         case SE_ERR_DDETIMEOUT:
40                         case SE_ERR_DLLNOTFOUND:
41                         case SE_ERR_OOM:
42                         case SE_ERR_SHARE:
43                         case SE_ERR_NOASSOC:
44                         case ERROR_FILE_NOT_FOUND:
45                         case ERROR_PATH_NOT_FOUND:
46                                 return -1;
47                 }
48         }
49
50         return 0;
51 }
52
53 #endif