wine/programs/wscript/main.c
2010-07-28 16:28:22 +02:00

91 lines
2.5 KiB
C

/*
* Copyright 2010 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <ole2.h>
#include <wine/debug.h>
#include <wine/unicode.h>
WINE_DEFAULT_DEBUG_CHANNEL(wscript);
static BOOL get_engine_clsid(const WCHAR *ext, CLSID *clsid)
{
WCHAR fileid[64], progid[64];
DWORD res;
LONG size;
HKEY hkey;
HRESULT hres;
static const WCHAR script_engineW[] =
{'\\','S','c','r','i','p','t','E','n','g','i','n','e',0};
res = RegOpenKeyW(HKEY_CLASSES_ROOT, ext, &hkey);
if(res != ERROR_SUCCESS)
return FALSE;
size = sizeof(fileid)/sizeof(WCHAR);
res = RegQueryValueW(hkey, NULL, fileid, &size);
RegCloseKey(hkey);
if(res != ERROR_SUCCESS)
return FALSE;
WINE_TRACE("fileid is %s\n", wine_dbgstr_w(fileid));
strcatW(fileid, script_engineW);
res = RegOpenKeyW(HKEY_CLASSES_ROOT, fileid, &hkey);
if(res != ERROR_SUCCESS)
return FALSE;
size = sizeof(progid)/sizeof(WCHAR);
res = RegQueryValueW(hkey, NULL, progid, &size);
RegCloseKey(hkey);
if(res != ERROR_SUCCESS)
return FALSE;
WINE_TRACE("ProgID is %s\n", wine_dbgstr_w(progid));
hres = CLSIDFromProgID(progid, clsid);
return SUCCEEDED(hres);
}
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
{
const WCHAR *ext;
CLSID clsid;
WINE_FIXME("(%p %p %s %x)\n", hInst, hPrevInst, wine_dbgstr_w(cmdline), cmdshow);
if(!*cmdline)
return 1;
ext = strchrW(cmdline, '.');
if(!ext)
ext = cmdline;
if(!get_engine_clsid(ext, &clsid)) {
WINE_FIXME("Could not fine engine for %s\n", wine_dbgstr_w(ext));
return 1;
}
return 0;
}