]> icculus.org git repositories - taylor/freespace2.git/blob - src/platform/win.cpp
Merge branch 'sdl2'
[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 <windows.h>
13 #include <shellapi.h>
14
15 #include "SDL.h"
16
17
18 int platform_open_url(const char *url)
19 {
20         char s_url[256];
21
22         // make sure it's a valid www address
23         if ( !SDL_strncasecmp(url, "http://", 7) || !SDL_strncasecmp(url, "https://", 8) ) {
24                 SDL_strlcpy(s_url, url, SDL_arraysize(s_url));
25         } else {
26                 SDL_strlcpy(s_url, "http://", SDL_arraysize(s_url));
27                 SDL_strlcat(s_url, url, SDL_arraysize(s_url));
28         }
29
30         int rval = (int) ShellExecute(NULL, (LPCTSTR)"open", (LPCTSTR)s_url, NULL, NULL, SW_SHOW);
31
32         if (rval < 32) {
33                 switch (rval) {
34                         case 0:
35                         case ERROR_BAD_FORMAT:
36                         case SE_ERR_ACCESSDENIED:
37                         case SE_ERR_ASSOCINCOMPLETE:
38                         case SE_ERR_DDEBUSY:
39                         case SE_ERR_DDEFAIL:
40                         case SE_ERR_DDETIMEOUT:
41                         case SE_ERR_DLLNOTFOUND:
42                         case SE_ERR_OOM:
43                         case SE_ERR_SHARE:
44                         case SE_ERR_NOASSOC:
45                         case ERROR_FILE_NOT_FOUND:
46                         case ERROR_PATH_NOT_FOUND:
47                                 return -1;
48                 }
49         }
50
51         return 0;
52 }
53
54 #endif