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