[9/10] winemenubuilder: Compute the icon name before calling extract_icon.
Per Johansson
per at morth.org
Sun Mar 17 12:18:41 CDT 2013
---
programs/winemenubuilder/appbundle.c | 14 +------
programs/winemenubuilder/winemenubuilder.c | 66 +++++++++++++++---------------
programs/winemenubuilder/winemenubuilder.h | 3 +-
programs/winemenubuilder/xdg.c | 14 +------
4 files changed, 39 insertions(+), 58 deletions(-)
diff --git a/programs/winemenubuilder/appbundle.c b/programs/winemenubuilder/appbundle.c
index b2a7915..57e9b9d 100644
--- a/programs/winemenubuilder/appbundle.c
+++ b/programs/winemenubuilder/appbundle.c
@@ -84,8 +84,7 @@ static inline int size_to_slot(int size)
#define CLASSIC_SLOT 3
-HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
- const char *destFilename, char **nativeIdentifier)
+HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW, const char *destFilename)
{
ICONDIRENTRY *iconDirEntries = NULL;
int numEntries;
@@ -156,16 +155,7 @@ HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
}
}
- if (destFilename)
- *nativeIdentifier = heap_printf("%s", destFilename);
- else
- *nativeIdentifier = compute_native_identifier(exeIndex, icoPathW);
- if (*nativeIdentifier == NULL)
- {
- hr = E_OUTOFMEMORY;
- goto end;
- }
- icnsPath = heap_printf("/tmp/%s.icns", *nativeIdentifier);
+ icnsPath = heap_printf("/tmp/%s.icns", destFilename);
if (icnsPath == NULL)
{
hr = E_OUTOFMEMORY;
diff --git a/programs/winemenubuilder/winemenubuilder.c b/programs/winemenubuilder/winemenubuilder.c
index a58e80a..c3e308d 100644
--- a/programs/winemenubuilder/winemenubuilder.c
+++ b/programs/winemenubuilder/winemenubuilder.c
@@ -1112,11 +1112,10 @@ char* compute_native_identifier(int exeIndex, LPCWSTR icoPathW)
}
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
-static char *extract_icon(LPCWSTR icoPathW, int index, const char *destFilename, BOOL bWait)
+static HRESULT extract_icon(LPCWSTR icoPathW, int index, const char *destFilename, BOOL bWait)
{
IStream *stream = NULL;
HRESULT hr;
- char *nativeIdentifier = NULL;
WINE_TRACE("path=[%s] index=%d destFilename=[%s]\n", wine_dbgstr_w(icoPathW), index, wine_dbgstr_a(destFilename));
@@ -1126,19 +1125,14 @@ static char *extract_icon(LPCWSTR icoPathW, int index, const char *destFilename,
WINE_WARN("opening icon %s index %d failed, hr=0x%08X\n", wine_dbgstr_w(icoPathW), index, hr);
goto end;
}
- hr = wmb_dispatch->write_icon(stream, index, icoPathW, destFilename, &nativeIdentifier);
+ hr = wmb_dispatch->write_icon(stream, index, icoPathW, destFilename);
if (FAILED(hr))
WINE_WARN("writing icon failed, error 0x%08X\n", hr);
end:
if (stream)
IStream_Release(stream);
- if (FAILED(hr))
- {
- HeapFree(GetProcessHeap(), 0, nativeIdentifier);
- nativeIdentifier = NULL;
- }
- return nativeIdentifier;
+ return hr;
}
static HKEY open_menus_reg_key(void)
@@ -1842,8 +1836,8 @@ static BOOL generate_associations(void *user)
*/
if (iconW)
{
- char *flattened_mime = slashes_to_minuses(mimeTypeA);
- if (flattened_mime)
+ iconA = slashes_to_minuses(mimeTypeA);
+ if (iconA)
{
int index = 0;
WCHAR *comma = strrchrW(iconW, ',');
@@ -1852,8 +1846,7 @@ static BOOL generate_associations(void *user)
*comma = 0;
index = atoiW(comma + 1);
}
- iconA = extract_icon(iconW, index, flattened_mime, FALSE);
- HeapFree(GetProcessHeap(), 0, flattened_mime);
+ extract_icon(iconW, index, iconA, FALSE);
}
}
@@ -1874,7 +1867,11 @@ static BOOL generate_associations(void *user)
executableW = assoc_query(ASSOCSTR_EXECUTABLE, extensionW, openW);
if (executableW)
- openWithIconA = extract_icon(executableW, 0, NULL, FALSE);
+ {
+ openWithIconA = compute_native_identifier(0, executableW);
+ if (openWithIconA)
+ extract_icon(executableW, 0, openWithIconA, FALSE);
+ }
friendlyAppNameW = assoc_query(ASSOCSTR_FRIENDLYAPPNAME, extensionW, openW);
if (friendlyAppNameW)
@@ -2057,13 +2054,13 @@ static BOOL InvokeShellLinker( IShellLinkW *sl, LPCWSTR link, BOOL bWait )
}
/* extract the icon */
- if( szIconPath[0] )
- icon_name = extract_icon( szIconPath , iIconId, NULL, bWait );
+ icon_name = compute_native_identifier(iIconId, szIconPath ? szIconPath : szPath);
+ if (icon_name)
+ r = extract_icon(szIconPath ? szIconPath : szPath, iIconId, icon_name, bWait);
else
- icon_name = extract_icon( szPath, iIconId, NULL, bWait );
-
+ r = E_OUTOFMEMORY;
/* fail - try once again after parent process exit */
- if( !icon_name )
+ if( FAILED(r) )
{
if (bWait)
{
@@ -2216,9 +2213,11 @@ static BOOL InvokeShellLinkerForURL( IUniformResourceLocatorW *url, LPCWSTR link
PROPSPEC ps[2];
PROPVARIANT pv[2];
char *start_path = NULL;
- BOOL has_icon = FALSE;
char *lastEntry;
+ pv[0].vt = VT_EMPTY;
+ pv[1].vt = VT_EMPTY;
+
if ( !link )
{
WINE_ERR("Link name is null\n");
@@ -2283,30 +2282,31 @@ static BOOL InvokeShellLinkerForURL( IUniformResourceLocatorW *url, LPCWSTR link
{
if (pv[0].vt == VT_LPWSTR && pv[0].u.pwszVal && pv[0].u.pwszVal[0])
{
- has_icon = TRUE;
- icon_name = extract_icon( pv[0].u.pwszVal, pv[1].u.iVal, NULL, bWait );
+ icon_name = compute_native_identifier(pv[1].u.iVal, pv[0].u.pwszVal);
WINE_TRACE("URL icon path: %s icon index: %d icon name: %s\n", wine_dbgstr_w(pv[0].u.pwszVal), pv[1].u.iVal, icon_name);
}
- PropVariantClear(&pv[0]);
- PropVariantClear(&pv[1]);
}
IPropertyStorage_Release(pPropStg);
}
IPropertySetStorage_Release(pPropSetStg);
}
- /* fail - try once again after parent process exit */
- if( has_icon && !icon_name )
+ if( icon_name )
{
- if (bWait)
+ r = extract_icon( pv[0].u.pwszVal, pv[1].u.iVal, icon_name, bWait );
+ /* fail - try once again after parent process exit */
+ if (FAILED(r))
{
- WINE_WARN("Unable to extract icon, deferring.\n");
- ret = FALSE;
- goto cleanup;
+ if (bWait)
+ {
+ WINE_WARN("Unable to extract icon, deferring.\n");
+ ret = FALSE;
+ goto cleanup;
+ }
+ WINE_ERR("failed to extract icon from %s\n",
+ wine_dbgstr_w( pv[0].u.pwszVal ));
}
- WINE_ERR("failed to extract icon from %s\n",
- wine_dbgstr_w( pv[0].u.pwszVal ));
}
hSem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
@@ -2335,6 +2335,8 @@ cleanup:
CoTaskMemFree( urlPath );
HeapFree(GetProcessHeap(), 0, escaped_urlPath);
HeapFree(GetProcessHeap(), 0, unix_link);
+ PropVariantClear(&pv[0]);
+ PropVariantClear(&pv[1]);
return ret;
}
diff --git a/programs/winemenubuilder/winemenubuilder.h b/programs/winemenubuilder/winemenubuilder.h
index 50bae90..0568b70 100644
--- a/programs/winemenubuilder/winemenubuilder.h
+++ b/programs/winemenubuilder/winemenubuilder.h
@@ -57,8 +57,7 @@ struct winemenubuilder_dispatch
int (*build_menu_link)(const char *unix_link, const char *link, const char *link_name, const char *path,
const char *args, const char *descr, const char *workdir, char *icon);
- HRESULT (*write_icon)(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
- const char *destFilename, char **nativeIdentifier);
+ HRESULT (*write_icon)(IStream *icoStream, int exeIndex, LPCWSTR icoPathW, const char *destFilename);
void *(*refresh_file_type_associations_init)(void);
diff --git a/programs/winemenubuilder/xdg.c b/programs/winemenubuilder/xdg.c
index 33c6fec..1b8e469 100644
--- a/programs/winemenubuilder/xdg.c
+++ b/programs/winemenubuilder/xdg.c
@@ -126,8 +126,7 @@ static void refresh_icon_cache(const char *iconsDir)
}
}
-static HRESULT xdg_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
- const char *destFilename, char **nativeIdentifier)
+static HRESULT xdg_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW, const char *destFilename)
{
ICONDIRENTRY *iconDirEntries = NULL;
int numEntries;
@@ -140,15 +139,6 @@ static HRESULT xdg_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW
if (FAILED(hr))
goto end;
- if (destFilename)
- *nativeIdentifier = heap_printf("%s", destFilename);
- else
- *nativeIdentifier = compute_native_identifier(exeIndex, icoPathW);
- if (*nativeIdentifier == NULL)
- {
- hr = E_OUTOFMEMORY;
- goto end;
- }
iconsDir = heap_printf("%s/icons/hicolor", xdg_data_dir);
if (iconsDir == NULL)
{
@@ -199,7 +189,7 @@ static HRESULT xdg_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW
goto endloop;
}
create_directories(iconDir);
- pngPath = heap_printf("%s/%s.png", iconDir, *nativeIdentifier);
+ pngPath = heap_printf("%s/%s.png", iconDir, destFilename);
if (pngPath == NULL)
{
hr = E_OUTOFMEMORY;
--
1.8.0.2
More information about the wine-patches
mailing list