Commit d3446e1f authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Use public function to get file extension in GetClassFile().

parent 966d74a1
MODULE = ole32.dll
IMPORTLIB = ole32
IMPORTS = uuid advapi32 user32 gdi32 combase rpcrt4
IMPORTS = uuid advapi32 user32 gdi32 combase rpcrt4 kernelbase
DELAYIMPORTS = oleaut32
EXTRADEFS = -D_OLE32_
......
......@@ -631,6 +631,85 @@ static void free_stringtable(LPOLESTR *stringTable)
CoTaskMemFree(stringTable);
}
static int FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
{
LPOLESTR word;
int i=0,j,tabIndex=0, ret=0;
LPOLESTR *strgtable ;
int len=lstrlenW(str);
TRACE("%s, %p\n", debugstr_w(str), *stringTable);
strgtable = CoTaskMemAlloc((len + 1)*sizeof(*strgtable));
if (strgtable==NULL)
return E_OUTOFMEMORY;
word = CoTaskMemAlloc((len + 1)*sizeof(WCHAR));
if (word==NULL)
{
ret = E_OUTOFMEMORY;
goto lend;
}
while(str[i]!=0){
if (str[i] == L'\\')
{
strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
if (strgtable[tabIndex]==NULL)
{
ret = E_OUTOFMEMORY;
goto lend;
}
lstrcpyW(strgtable[tabIndex++], L"\\");
i++;
}
else {
for (j = 0; str[i] && str[i] != L'\\'; i++, j++)
word[j]=str[i];
word[j]=0;
strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
if (strgtable[tabIndex]==NULL)
{
ret = E_OUTOFMEMORY;
goto lend;
}
lstrcpyW(strgtable[tabIndex++],word);
}
}
strgtable[tabIndex]=NULL;
*stringTable=strgtable;
ret = tabIndex;
lend:
if (ret < 0)
{
for (i = 0; i < tabIndex; i++)
CoTaskMemFree(strgtable[i]);
CoTaskMemFree(strgtable);
}
CoTaskMemFree(word);
return ret;
}
/******************************************************************************
* FileMoniker_ComposeWith
*/
......@@ -971,88 +1050,6 @@ failed:
}
/******************************************************************************
* DecomposePath (local function)
*/
int FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable)
{
LPOLESTR word;
int i=0,j,tabIndex=0, ret=0;
LPOLESTR *strgtable ;
int len=lstrlenW(str);
TRACE("%s, %p\n", debugstr_w(str), *stringTable);
strgtable = CoTaskMemAlloc((len + 1)*sizeof(*strgtable));
if (strgtable==NULL)
return E_OUTOFMEMORY;
word = CoTaskMemAlloc((len + 1)*sizeof(WCHAR));
if (word==NULL)
{
ret = E_OUTOFMEMORY;
goto lend;
}
while(str[i]!=0){
if (str[i] == L'\\')
{
strgtable[tabIndex]=CoTaskMemAlloc(2*sizeof(WCHAR));
if (strgtable[tabIndex]==NULL)
{
ret = E_OUTOFMEMORY;
goto lend;
}
lstrcpyW(strgtable[tabIndex++], L"\\");
i++;
}
else {
for (j = 0; str[i] && str[i] != L'\\'; i++, j++)
word[j]=str[i];
word[j]=0;
strgtable[tabIndex]=CoTaskMemAlloc(sizeof(WCHAR)*(j+1));
if (strgtable[tabIndex]==NULL)
{
ret = E_OUTOFMEMORY;
goto lend;
}
lstrcpyW(strgtable[tabIndex++],word);
}
}
strgtable[tabIndex]=NULL;
*stringTable=strgtable;
ret = tabIndex;
lend:
if (ret < 0)
{
for (i = 0; i < tabIndex; i++)
CoTaskMemFree(strgtable[i]);
CoTaskMemFree(strgtable);
}
CoTaskMemFree(word);
return ret;
}
/******************************************************************************
* FileMoniker_RelativePathTo
*/
static HRESULT WINAPI
......
......@@ -32,6 +32,7 @@
#include "compobj_private.h"
#include "moniker.h"
#include "irot.h"
#include "pathcch.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
......@@ -910,10 +911,9 @@ HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
{
IStorage *pstg=0;
HRESULT res;
int nbElm, length, i;
LONG sizeProgId, ret;
LPOLESTR *pathDec=0,absFile=0,progId=0;
LPWSTR extension;
LPOLESTR progId=0;
const WCHAR *extension;
TRACE("%s, %p\n", debugstr_w(filePathName), pclsid);
......@@ -954,26 +954,9 @@ HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
/* if the above strategies fail then search for the extension key in the registry */
/* get the last element (absolute file) in the path name */
nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
absFile=pathDec[nbElm-1];
/* failed if the path represents a directory and not an absolute file name*/
if (!wcscmp(absFile, L"\\")) {
CoTaskMemFree(pathDec);
res = PathCchFindExtension(filePathName, PATHCCH_MAX_CCH, &extension);
if (FAILED(res) || !extension || !*extension || !wcscmp(extension, L"."))
return MK_E_INVALIDEXTENSION;
}
/* get the extension of the file */
extension = NULL;
length=lstrlenW(absFile);
for(i = length-1; (i >= 0) && *(extension = &absFile[i]) != '.'; i--)
/* nothing */;
if (!extension || !wcscmp(extension, L".")) {
CoTaskMemFree(pathDec);
return MK_E_INVALIDEXTENSION;
}
ret = RegQueryValueW(HKEY_CLASSES_ROOT, extension, NULL, &sizeProgId);
if (!ret) {
......@@ -990,10 +973,6 @@ HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
else
res = HRESULT_FROM_WIN32(ret);
for(i=0; pathDec[i]!=NULL;i++)
CoTaskMemFree(pathDec[i]);
CoTaskMemFree(pathDec);
return res != S_OK ? MK_E_INVALIDEXTENSION : res;
}
......
......@@ -38,9 +38,6 @@ HRESULT WINAPI ClassMoniker_CreateInstance(IClassFactory *iface, IUnknown *pUnk,
HRESULT WINAPI PointerMoniker_CreateInstance(IClassFactory *iface, IUnknown *pUnk, REFIID riid, void **ppv);
HRESULT WINAPI ComCat_CreateInstance(IClassFactory *iface, IUnknown *pUnk, REFIID riid, void **ppv);
/* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
int FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable) DECLSPEC_HIDDEN;
HRESULT FileMoniker_CreateFromDisplayName(LPBC pbc, LPCOLESTR szDisplayName,
LPDWORD pchEaten, LPMONIKER *ppmk) DECLSPEC_HIDDEN;
HRESULT ClassMoniker_CreateFromDisplayName(LPBC pbc, LPCOLESTR szDisplayName,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment