wscript.exe: Added engine lookup implementation.
[wine/multimedia.git] / programs / wscript / main.c
blob5169b749e1eb2ef07c04255132b1af7c348e3f3a
1 /*
2 * Copyright 2010 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
21 #include <windef.h>
22 #include <winbase.h>
23 #include <winreg.h>
24 #include <ole2.h>
26 #include <wine/debug.h>
27 #include <wine/unicode.h>
29 WINE_DEFAULT_DEBUG_CHANNEL(wscript);
31 static BOOL get_engine_clsid(const WCHAR *ext, CLSID *clsid)
33 WCHAR fileid[64], progid[64];
34 DWORD res;
35 LONG size;
36 HKEY hkey;
37 HRESULT hres;
39 static const WCHAR script_engineW[] =
40 {'\\','S','c','r','i','p','t','E','n','g','i','n','e',0};
42 res = RegOpenKeyW(HKEY_CLASSES_ROOT, ext, &hkey);
43 if(res != ERROR_SUCCESS)
44 return FALSE;
46 size = sizeof(fileid)/sizeof(WCHAR);
47 res = RegQueryValueW(hkey, NULL, fileid, &size);
48 RegCloseKey(hkey);
49 if(res != ERROR_SUCCESS)
50 return FALSE;
52 WINE_TRACE("fileid is %s\n", wine_dbgstr_w(fileid));
54 strcatW(fileid, script_engineW);
55 res = RegOpenKeyW(HKEY_CLASSES_ROOT, fileid, &hkey);
56 if(res != ERROR_SUCCESS)
57 return FALSE;
59 size = sizeof(progid)/sizeof(WCHAR);
60 res = RegQueryValueW(hkey, NULL, progid, &size);
61 RegCloseKey(hkey);
62 if(res != ERROR_SUCCESS)
63 return FALSE;
65 WINE_TRACE("ProgID is %s\n", wine_dbgstr_w(progid));
67 hres = CLSIDFromProgID(progid, clsid);
68 return SUCCEEDED(hres);
71 int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
73 const WCHAR *ext;
74 CLSID clsid;
76 WINE_FIXME("(%p %p %s %x)\n", hInst, hPrevInst, wine_dbgstr_w(cmdline), cmdshow);
78 if(!*cmdline)
79 return 1;
81 ext = strchrW(cmdline, '.');
82 if(!ext)
83 ext = cmdline;
84 if(!get_engine_clsid(ext, &clsid)) {
85 WINE_FIXME("Could not fine engine for %s\n", wine_dbgstr_w(ext));
86 return 1;
89 return 0;