Commit 712b3571 authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

winemenubuilder: Use the same icon name on Mac OS X as on Unix.

parent 923ac2e5
...@@ -199,7 +199,6 @@ static WCHAR* assoc_query(ASSOCSTR assocStr, LPCWSTR name, LPCWSTR extra); ...@@ -199,7 +199,6 @@ static WCHAR* assoc_query(ASSOCSTR assocStr, LPCWSTR name, LPCWSTR extra);
static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppStream); static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppStream);
/* Utility routines */ /* Utility routines */
#ifndef __APPLE__
static unsigned short crc16(const char* string) static unsigned short crc16(const char* string)
{ {
unsigned short crc = 0; unsigned short crc = 0;
...@@ -218,7 +217,6 @@ static unsigned short crc16(const char* string) ...@@ -218,7 +217,6 @@ static unsigned short crc16(const char* string)
} }
return crc; return crc;
} }
#endif
static char *strdupA( const char *str ) static char *strdupA( const char *str )
{ {
...@@ -1069,6 +1067,35 @@ static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppSt ...@@ -1069,6 +1067,35 @@ static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppSt
return hr; return hr;
} }
static char* compute_native_identifier(int exeIndex, LPCWSTR icoPathW)
{
char* nativeIdentifier;
char *icoPathA;
unsigned short crc;
char *basename, *ext;
icoPathA = wchars_to_utf8_chars(icoPathW);
if (icoPathA == NULL)
return NULL;
crc = crc16(icoPathA);
basename = strrchr(icoPathA, '\\');
if (basename == NULL)
basename = icoPathA;
else
{
*basename = 0;
basename++;
}
ext = strrchr(basename, '.');
if (ext)
*ext = 0;
nativeIdentifier = heap_printf("%04X_%s.%d", crc, basename, exeIndex);
HeapFree(GetProcessHeap(), 0, icoPathA);
return nativeIdentifier;
}
#ifdef __APPLE__ #ifdef __APPLE__
#define ICNS_SLOTS 6 #define ICNS_SLOTS 6
...@@ -1102,9 +1129,6 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico ...@@ -1102,9 +1129,6 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico
} best[ICNS_SLOTS]; } best[ICNS_SLOTS];
int indexes[ICNS_SLOTS]; int indexes[ICNS_SLOTS];
int i; int i;
GUID guid;
WCHAR *guidStrW = NULL;
char *guidStrA = NULL;
char *icnsPath = NULL; char *icnsPath = NULL;
LARGE_INTEGER zero; LARGE_INTEGER zero;
HRESULT hr; HRESULT hr;
...@@ -1165,26 +1189,16 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico ...@@ -1165,26 +1189,16 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico
} }
} }
hr = CoCreateGuid(&guid); if (destFilename)
if (FAILED(hr)) *nativeIdentifier = heap_printf("%s", destFilename);
{ else
WINE_WARN("CoCreateGuid failed, error 0x%08X\n", hr); *nativeIdentifier = compute_native_identifier(exeIndex, icoPathW);
goto end; if (*nativeIdentifier == NULL)
}
hr = StringFromCLSID(&guid, &guidStrW);
if (FAILED(hr))
{
WINE_WARN("StringFromCLSID failed, error 0x%08X\n", hr);
goto end;
}
guidStrA = wchars_to_utf8_chars(guidStrW);
if (guidStrA == NULL)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
WINE_WARN("out of memory converting GUID string\n");
goto end; goto end;
} }
icnsPath = heap_printf("/tmp/%s.icns", guidStrA); icnsPath = heap_printf("/tmp/%s.icns", *nativeIdentifier);
if (icnsPath == NULL) if (icnsPath == NULL)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
...@@ -1209,8 +1223,6 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico ...@@ -1209,8 +1223,6 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico
end: end:
HeapFree(GetProcessHeap(), 0, iconDirEntries); HeapFree(GetProcessHeap(), 0, iconDirEntries);
CoTaskMemFree(guidStrW);
HeapFree(GetProcessHeap(), 0, guidStrA);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
*nativeIdentifier = icnsPath; *nativeIdentifier = icnsPath;
else else
...@@ -1244,10 +1256,7 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico ...@@ -1244,10 +1256,7 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico
ICONDIRENTRY *iconDirEntries = NULL; ICONDIRENTRY *iconDirEntries = NULL;
int numEntries; int numEntries;
int i; int i;
char *icoPathA = NULL;
char *iconsDir = NULL; char *iconsDir = NULL;
unsigned short crc;
char *p, *q;
HRESULT hr = S_OK; HRESULT hr = S_OK;
LARGE_INTEGER zero; LARGE_INTEGER zero;
...@@ -1255,28 +1264,10 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico ...@@ -1255,28 +1264,10 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico
if (FAILED(hr)) if (FAILED(hr))
goto end; goto end;
icoPathA = wchars_to_utf8_chars(icoPathW);
if (icoPathA == NULL)
{
hr = E_OUTOFMEMORY;
goto end;
}
crc = crc16(icoPathA);
p = strrchr(icoPathA, '\\');
if (p == NULL)
p = icoPathA;
else
{
*p = 0;
p++;
}
q = strrchr(p, '.');
if (q)
*q = 0;
if (destFilename) if (destFilename)
*nativeIdentifier = heap_printf("%s", destFilename); *nativeIdentifier = heap_printf("%s", destFilename);
else else
*nativeIdentifier = heap_printf("%04X_%s.%d", crc, p, exeIndex); *nativeIdentifier = compute_native_identifier(exeIndex, icoPathW);
if (*nativeIdentifier == NULL) if (*nativeIdentifier == NULL)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
...@@ -1353,7 +1344,6 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico ...@@ -1353,7 +1344,6 @@ static HRESULT platform_write_icon(IStream *icoStream, int exeIndex, LPCWSTR ico
end: end:
HeapFree(GetProcessHeap(), 0, iconDirEntries); HeapFree(GetProcessHeap(), 0, iconDirEntries);
HeapFree(GetProcessHeap(), 0, icoPathA);
HeapFree(GetProcessHeap(), 0, iconsDir); HeapFree(GetProcessHeap(), 0, iconsDir);
return hr; return hr;
} }
......
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