Module: wine Branch: master Commit: 6afb5f078241406caf5281854daf3ca15c915092 URL: http://source.winehq.org/git/wine.git/?a=commit;h=6afb5f078241406caf5281854d...
Author: Michał Ziętek smierc.w.wenecji@gmail.com Date: Wed Jul 20 21:47:29 2011 +0200
wscript: Implemented Host_get_Path.
---
programs/wscript/host.c | 16 ++++++++++++++-- programs/wscript/tests/run.c | 33 +++++++++++++++++++++++++++++++++ programs/wscript/tests/run.js | 1 + 3 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/programs/wscript/host.c b/programs/wscript/host.c index 8277cdf..42343b1 100644 --- a/programs/wscript/host.c +++ b/programs/wscript/host.c @@ -28,6 +28,7 @@ #include "wscript.h"
#include <wine/debug.h> +#include <wine/unicode.h>
#define BUILDVERSION 16535
@@ -127,8 +128,19 @@ static HRESULT WINAPI Host_get_FullName(IHost *iface, BSTR *out_Path)
static HRESULT WINAPI Host_get_Path(IHost *iface, BSTR *out_Path) { - WINE_FIXME("(%p)\n", out_Path); - return E_NOTIMPL; + WCHAR path[MAX_PATH]; + int howMany; + WCHAR *pos; + + WINE_TRACE("(%p)\n", out_Path); + + if(GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(WCHAR)) == 0) + return E_FAIL; + pos = strrchrW(path, '\'); + howMany = pos - path; + if(!(*out_Path = SysAllocStringLen(path, howMany))) + return E_OUTOFMEMORY; + return S_OK; }
static HRESULT WINAPI Host_get_Interactive(IHost *iface, VARIANT_BOOL *out_Interactive) diff --git a/programs/wscript/tests/run.c b/programs/wscript/tests/run.c index 30230b6..2f5dedd 100644 --- a/programs/wscript/tests/run.c +++ b/programs/wscript/tests/run.c @@ -60,6 +60,7 @@ DEFINE_EXPECT(reportSuccess); #define DISPID_TESTOBJ_TRACE 10001 #define DISPID_TESTOBJ_REPORTSUCCESS 10002 #define DISPID_TESTOBJ_WSCRIPTFULLNAME 10003 +#define DISPID_TESTOBJ_WSCRIPTPATH 10004
#define TESTOBJ_CLSID "{178fc166-f585-4e24-9c13-4bb7faf80646}"
@@ -75,6 +76,17 @@ static int strcmp_wa(LPCWSTR strw, const char *stra) return lstrcmpW(strw, buf); }
+static const WCHAR* mystrrchr(const WCHAR *str, WCHAR ch) +{ + const WCHAR *pos = NULL, *current = str; + while(*current != 0) { + if(*current == ch) + pos = current; + ++current; + } + return pos; +} + static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv) { if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IDispatch)) { @@ -123,6 +135,8 @@ static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, rgDispId[i] = DISPID_TESTOBJ_REPORTSUCCESS; }else if(!strcmp_wa(rgszNames[i], "wscriptFullName")) { rgDispId[i] = DISPID_TESTOBJ_WSCRIPTFULLNAME; + }else if(!strcmp_wa(rgszNames[i], "wscriptPath")) { + rgDispId[i] = DISPID_TESTOBJ_WSCRIPTPATH; }else { ok(0, "unexpected name %s\n", wine_dbgstr_w(rgszNames[i])); return DISP_E_UNKNOWNNAME; @@ -181,6 +195,25 @@ static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REF return E_OUTOFMEMORY; break; } + case DISPID_TESTOBJ_WSCRIPTPATH: + { + WCHAR fullPath[MAX_PATH]; + const WCHAR wscriptexe[] = {'w','s','c','r','i','p','t','.','e','x','e',0}; + DWORD res; + const WCHAR *pos; + + ok(wFlags == INVOKE_PROPERTYGET, "wFlags = %x\n", wFlags); + ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs); + ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs); + V_VT(pVarResult) = VT_BSTR; + res = SearchPathW(NULL, wscriptexe, NULL, sizeof(fullPath)/sizeof(WCHAR), fullPath, NULL); + if(res == 0) + return E_FAIL; + pos = mystrrchr(fullPath, '\'); + if(!(V_BSTR(pVarResult) = SysAllocStringLen(fullPath, pos-fullPath))) + return E_OUTOFMEMORY; + break; + } default: ok(0, "unexpected dispIdMember %d\n", dispIdMember); return E_NOTIMPL; diff --git a/programs/wscript/tests/run.js b/programs/wscript/tests/run.js index 1156e13..225abef 100644 --- a/programs/wscript/tests/run.js +++ b/programs/wscript/tests/run.js @@ -29,5 +29,6 @@ ok(WScript.Name === "Windows Script Host", "WScript.Name = " + WScript.Name); ok(typeof(WScript.Version) === "string", "typeof(WScript.Version) = " + typeof(WScript.Version)); ok(typeof(WScript.BuildVersion) === "number", "typeof(WScript.BuldVersion) = " + typeof(WScript.BuldVersion)); ok(WScript.FullName === winetest.wscriptFullName, "WScript.FullName = ", WScript.FullName); +ok(WScript.Path === winetest.wscriptPath, "WScript.Path = ", WScript.Path);
winetest.reportSuccess();