[8/10] winemenubuilder: Move osx_write_icon to appbundle.c

Per Johansson per at morth.org
Sun Mar 17 12:18:40 CDT 2013


Stop using it for xdg dispatch.
---
 programs/winemenubuilder/appbundle.c       | 131 +++++++++++++++++++++++++++-
 programs/winemenubuilder/winemenubuilder.c | 134 -----------------------------
 programs/winemenubuilder/winemenubuilder.h |   2 +
 programs/winemenubuilder/xdg.c             |   9 --
 4 files changed, 131 insertions(+), 145 deletions(-)

diff --git a/programs/winemenubuilder/appbundle.c b/programs/winemenubuilder/appbundle.c
index 4abdc63..b2a7915 100644
--- a/programs/winemenubuilder/appbundle.c
+++ b/programs/winemenubuilder/appbundle.c
@@ -64,8 +64,135 @@ WINE_DEFAULT_DEBUG_CHANNEL(menubuilder);
 static char *mac_desktop_dir = NULL;
 static char *wine_applications_dir = NULL;
 
-extern HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
-                                   const char *destFilename, char **nativeIdentifier);
+#define ICNS_SLOTS 6
+
+static inline int size_to_slot(int size)
+{
+    switch (size)
+    {
+        case 16: return 0;
+        case 32: return 1;
+        case 48: return 2;
+        case 64: return -2;  /* Classic Mode */
+        case 128: return 3;
+        case 256: return 4;
+        case 512: return 5;
+    }
+
+    return -1;
+}
+
+#define CLASSIC_SLOT 3
+
+HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
+                                   const char *destFilename, char **nativeIdentifier)
+{
+    ICONDIRENTRY *iconDirEntries = NULL;
+    int numEntries;
+    struct {
+        int index;
+        int maxBits;
+        BOOL scaled;
+    } best[ICNS_SLOTS];
+    int indexes[ICNS_SLOTS];
+    int i;
+    char *icnsPath = NULL;
+    LARGE_INTEGER zero;
+    HRESULT hr;
+
+    hr = read_ico_direntries(icoStream, &iconDirEntries, &numEntries);
+    if (FAILED(hr))
+        goto end;
+    for (i = 0; i < ICNS_SLOTS; i++)
+    {
+        best[i].index = -1;
+        best[i].maxBits = 0;
+    }
+    for (i = 0; i < numEntries; i++)
+    {
+        int slot;
+        int width = iconDirEntries[i].bWidth ? iconDirEntries[i].bWidth : 256;
+        int height = iconDirEntries[i].bHeight ? iconDirEntries[i].bHeight : 256;
+        BOOL scaled = FALSE;
+
+        WINE_TRACE("[%d]: %d x %d @ %d\n", i, width, height, iconDirEntries[i].wBitCount);
+        if (height != width)
+            continue;
+        slot = size_to_slot(width);
+        if (slot == -2)
+        {
+            scaled = TRUE;
+            slot = CLASSIC_SLOT;
+        }
+        else if (slot < 0)
+            continue;
+        if (scaled && best[slot].maxBits && !best[slot].scaled)
+            continue; /* don't replace unscaled with scaled */
+        if (iconDirEntries[i].wBitCount >= best[slot].maxBits || (!scaled && best[slot].scaled))
+        {
+            best[slot].index = i;
+            best[slot].maxBits = iconDirEntries[i].wBitCount;
+            best[slot].scaled = scaled;
+        }
+    }
+    /* remove the scaled icon if a larger unscaled icon exists */
+    if (best[CLASSIC_SLOT].scaled)
+    {
+        for (i = CLASSIC_SLOT+1; i < ICNS_SLOTS; i++)
+            if (best[i].index >= 0 && !best[i].scaled)
+            {
+                best[CLASSIC_SLOT].index = -1;
+                break;
+            }
+    }
+
+    numEntries = 0;
+    for (i = 0; i < ICNS_SLOTS; i++)
+    {
+        if (best[i].index >= 0)
+        {
+            indexes[numEntries] = best[i].index;
+            numEntries++;
+        }
+    }
+
+    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);
+    if (icnsPath == NULL)
+    {
+        hr = E_OUTOFMEMORY;
+        WINE_WARN("out of memory creating ICNS path\n");
+        goto end;
+    }
+    zero.QuadPart = 0;
+    hr = IStream_Seek(icoStream, zero, STREAM_SEEK_SET, NULL);
+    if (FAILED(hr))
+    {
+        WINE_WARN("seeking icon stream failed, error 0x%08X\n", hr);
+        goto end;
+    }
+    hr = convert_to_native_icon(icoStream, indexes, numEntries, &CLSID_WICIcnsEncoder,
+                                icnsPath, icoPathW);
+    if (FAILED(hr))
+    {
+        WINE_WARN("converting %s to %s failed, error 0x%08X\n",
+            wine_dbgstr_w(icoPathW), wine_dbgstr_a(icnsPath), hr);
+        goto end;
+    }
+
+end:
+    HeapFree(GetProcessHeap(), 0, iconDirEntries);
+    HeapFree(GetProcessHeap(), 0, icnsPath);
+    return hr;
+}
 
 /* inspired by write_desktop_entry() in xdg support code */
 static BOOL generate_bundle_script(const char *file, const char *path,
diff --git a/programs/winemenubuilder/winemenubuilder.c b/programs/winemenubuilder/winemenubuilder.c
index 2eccd69..a58e80a 100644
--- a/programs/winemenubuilder/winemenubuilder.c
+++ b/programs/winemenubuilder/winemenubuilder.c
@@ -167,8 +167,6 @@ struct rb_string_entry
     struct wine_rb_entry entry;
 };
 
-DEFINE_GUID(CLSID_WICIcnsEncoder, 0x312fb6f1,0xb767,0x409d,0x8a,0x6d,0x0f,0xc1,0x54,0xd4,0xf0,0x5c);
-
 const struct winemenubuilder_dispatch *wmb_dispatch;
 
 static WCHAR* assoc_query(ASSOCSTR assocStr, LPCWSTR name, LPCWSTR extra);
@@ -1113,138 +1111,6 @@ char* compute_native_identifier(int exeIndex, LPCWSTR icoPathW)
     return nativeIdentifier;
 }
 
-#ifdef __APPLE__
-#define ICNS_SLOTS 6
-
-static inline int size_to_slot(int size)
-{
-    switch (size)
-    {
-        case 16: return 0;
-        case 32: return 1;
-        case 48: return 2;
-        case 64: return -2;  /* Classic Mode */
-        case 128: return 3;
-        case 256: return 4;
-        case 512: return 5;
-    }
-
-    return -1;
-}
-
-#define CLASSIC_SLOT 3
-
-HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
-                                   const char *destFilename, char **nativeIdentifier)
-{
-    ICONDIRENTRY *iconDirEntries = NULL;
-    int numEntries;
-    struct {
-        int index;
-        int maxBits;
-        BOOL scaled;
-    } best[ICNS_SLOTS];
-    int indexes[ICNS_SLOTS];
-    int i;
-    char *icnsPath = NULL;
-    LARGE_INTEGER zero;
-    HRESULT hr;
-
-    hr = read_ico_direntries(icoStream, &iconDirEntries, &numEntries);
-    if (FAILED(hr))
-        goto end;
-    for (i = 0; i < ICNS_SLOTS; i++)
-    {
-        best[i].index = -1;
-        best[i].maxBits = 0;
-    }
-    for (i = 0; i < numEntries; i++)
-    {
-        int slot;
-        int width = iconDirEntries[i].bWidth ? iconDirEntries[i].bWidth : 256;
-        int height = iconDirEntries[i].bHeight ? iconDirEntries[i].bHeight : 256;
-        BOOL scaled = FALSE;
-
-        WINE_TRACE("[%d]: %d x %d @ %d\n", i, width, height, iconDirEntries[i].wBitCount);
-        if (height != width)
-            continue;
-        slot = size_to_slot(width);
-        if (slot == -2)
-        {
-            scaled = TRUE;
-            slot = CLASSIC_SLOT;
-        }
-        else if (slot < 0)
-            continue;
-        if (scaled && best[slot].maxBits && !best[slot].scaled)
-            continue; /* don't replace unscaled with scaled */
-        if (iconDirEntries[i].wBitCount >= best[slot].maxBits || (!scaled && best[slot].scaled))
-        {
-            best[slot].index = i;
-            best[slot].maxBits = iconDirEntries[i].wBitCount;
-            best[slot].scaled = scaled;
-        }
-    }
-    /* remove the scaled icon if a larger unscaled icon exists */
-    if (best[CLASSIC_SLOT].scaled)
-    {
-        for (i = CLASSIC_SLOT+1; i < ICNS_SLOTS; i++)
-            if (best[i].index >= 0 && !best[i].scaled)
-            {
-                best[CLASSIC_SLOT].index = -1;
-                break;
-            }
-    }
-
-    numEntries = 0;
-    for (i = 0; i < ICNS_SLOTS; i++)
-    {
-        if (best[i].index >= 0)
-        {
-            indexes[numEntries] = best[i].index;
-            numEntries++;
-        }
-    }
-
-    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);
-    if (icnsPath == NULL)
-    {
-        hr = E_OUTOFMEMORY;
-        WINE_WARN("out of memory creating ICNS path\n");
-        goto end;
-    }
-    zero.QuadPart = 0;
-    hr = IStream_Seek(icoStream, zero, STREAM_SEEK_SET, NULL);
-    if (FAILED(hr))
-    {
-        WINE_WARN("seeking icon stream failed, error 0x%08X\n", hr);
-        goto end;
-    }
-    hr = convert_to_native_icon(icoStream, indexes, numEntries, &CLSID_WICIcnsEncoder,
-                                icnsPath, icoPathW);
-    if (FAILED(hr))
-    {
-        WINE_WARN("converting %s to %s failed, error 0x%08X\n",
-            wine_dbgstr_w(icoPathW), wine_dbgstr_a(icnsPath), hr);
-        goto end;
-    }
-
-end:
-    HeapFree(GetProcessHeap(), 0, iconDirEntries);
-    HeapFree(GetProcessHeap(), 0, icnsPath);
-    return hr;
-}
-#endif /* defined(__APPLE__) */
-
 /* 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)
 {
diff --git a/programs/winemenubuilder/winemenubuilder.h b/programs/winemenubuilder/winemenubuilder.h
index 9cc3939..50bae90 100644
--- a/programs/winemenubuilder/winemenubuilder.h
+++ b/programs/winemenubuilder/winemenubuilder.h
@@ -35,6 +35,8 @@ typedef struct
     WORD idCount;
 } ICONDIR;
 
+DEFINE_GUID(CLSID_WICIcnsEncoder, 0x312fb6f1,0xb767,0x409d,0x8a,0x6d,0x0f,0xc1,0x54,0xd4,0xf0,0x5c);
+
 char *strdupA( const char *str );
 char* heap_printf(const char *format, ...);
 BOOL create_directories(char *directory);
diff --git a/programs/winemenubuilder/xdg.c b/programs/winemenubuilder/xdg.c
index f5c776a..33c6fec 100644
--- a/programs/winemenubuilder/xdg.c
+++ b/programs/winemenubuilder/xdg.c
@@ -106,10 +106,6 @@ static void write_xml_text(FILE *file, const char *text)
     }
 }
 
-#ifdef __APPLE__
-extern HRESULT osx_write_icon(IStream *icoStream, int exeIndex, LPCWSTR icoPathW,
-                                   const char *destFilename, char **nativeIdentifier);
-#else
 static void refresh_icon_cache(const char *iconsDir)
 {
     /* The icon theme spec only requires the mtime on the "toplevel"
@@ -227,7 +223,6 @@ end:
     HeapFree(GetProcessHeap(), 0, iconsDir);
     return hr;
 }
-#endif /* defined(__APPLE__) */
 
 static BOOL write_desktop_entry(const char *unix_link, const char *location, const char *linkname,
                                 const char *path, const char *args, const char *descr,
@@ -927,11 +922,7 @@ const struct winemenubuilder_dispatch xdg_dispatch =
     xdg_build_desktop_link,
     xdg_build_menu_link,
 
-#ifdef __APPLE__
-    osx_write_icon,
-#else
     xdg_write_icon,
-#endif
 
     xdg_refresh_file_type_associations_init,
     freedesktop_mime_type_for_extension,
-- 
1.8.0.2




More information about the wine-patches mailing list