1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // openhtml.cpp : Defines the entry point for the application.
24 LONG
GetRegKey(HKEY key
, LPCTSTR subkey
, LPTSTR retdata
)
27 LONG retval
= RegOpenKeyEx(key
, subkey
, 0, KEY_QUERY_VALUE
, &hkey
);
29 if (retval
== ERROR_SUCCESS
)
31 long datasize
= MAX_PATH
;
33 RegQueryValue(hkey
, NULL
, data
, &datasize
);
34 lstrcpy(retdata
,data
);
41 bool OpenFile (LPCTSTR filename
, LPCTSTR ext
, int showcmd
)
43 TCHAR key
[MAX_PATH
+ MAX_PATH
];
45 // First try ShellExecute()
46 HINSTANCE result
= ShellExecute(NULL
, "open", filename
, NULL
,NULL
, showcmd
);
48 // If it failed, get the .htm regkey and lookup the program
49 if ((UINT
)result
<= HINSTANCE_ERROR
)
51 if (GetRegKey(HKEY_CLASSES_ROOT
, ext
, key
) == ERROR_SUCCESS
)
53 lstrcat(key
, "\\shell\\open\\command");
55 if (GetRegKey(HKEY_CLASSES_ROOT
,key
,key
) == ERROR_SUCCESS
)
58 pos
= strstr(key
, "\"%1\"");
59 if (pos
== NULL
) { // No quotes found
60 pos
= strstr(key
, "%1"); // Check for %1, without quotes
61 if (pos
== NULL
) // No parameter at all...
62 pos
= key
+lstrlen(key
)-1;
64 *pos
= '\0'; // Remove the parameter
67 *pos
= '\0'; // Remove the parameter
70 lstrcat(pos
, filename
);
71 int res
= WinExec(key
,showcmd
);
82 int APIENTRY
WinMain(HINSTANCE hInstance
,
83 HINSTANCE hPrevInstance
,
87 // TODO: Place code here.
88 if (strcmp (lpCmdLine
, "")==0)
90 MessageBox (NULL
, "Open a file with the default application.\nUsage: open_file [filepath]", "Open file", MB_OK
|MB_ICONINFORMATION
);
95 _splitpath (lpCmdLine
, NULL
, NULL
, NULL
, ext
);
96 OpenFile(lpCmdLine
, ext
, SW_SHOW
);