Nikolay Sivov : ole32: Use public function to get file extension in GetClassFile().
Alexandre Julliard
julliard at winehq.org
Thu Sep 30 16:04:42 CDT 2021
Module: wine
Branch: master
Commit: d3446e1ff44a50b9519e839b74deaedec174346b
URL: https://source.winehq.org/git/wine.git/?a=commit;h=d3446e1ff44a50b9519e839b74deaedec174346b
Author: Nikolay Sivov <nsivov at codeweavers.com>
Date: Thu Sep 30 11:26:49 2021 +0300
ole32: Use public function to get file extension in GetClassFile().
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ole32/Makefile.in | 2 +-
dlls/ole32/filemoniker.c | 161 +++++++++++++++++++++++------------------------
dlls/ole32/moniker.c | 31 ++-------
dlls/ole32/moniker.h | 3 -
4 files changed, 85 insertions(+), 112 deletions(-)
diff --git a/dlls/ole32/Makefile.in b/dlls/ole32/Makefile.in
index 84694e1538d..340ffdbded2 100644
--- a/dlls/ole32/Makefile.in
+++ b/dlls/ole32/Makefile.in
@@ -1,6 +1,6 @@
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_
diff --git a/dlls/ole32/filemoniker.c b/dlls/ole32/filemoniker.c
index 213971ea96b..794b4507942 100644
--- a/dlls/ole32/filemoniker.c
+++ b/dlls/ole32/filemoniker.c
@@ -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
*/
@@ -970,88 +1049,6 @@ failed:
return ret;
}
-/******************************************************************************
- * 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
*/
diff --git a/dlls/ole32/moniker.c b/dlls/ole32/moniker.c
index aed491d406f..ac47f5528c8 100644
--- a/dlls/ole32/moniker.c
+++ b/dlls/ole32/moniker.c
@@ -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;
}
diff --git a/dlls/ole32/moniker.h b/dlls/ole32/moniker.h
index 995e0459e5e..8549bd46c1e 100644
--- a/dlls/ole32/moniker.h
+++ b/dlls/ole32/moniker.h
@@ -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,
More information about the wine-cvs
mailing list