2003-05-21 20:50:53 +02:00
|
|
|
/*
|
|
|
|
* Helper program to build unix menu entries
|
|
|
|
*
|
|
|
|
* Copyright 1997 Marcus Meissner
|
|
|
|
* Copyright 1998 Juergen Schmied
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2003 Mike McCormack for CodeWeavers
|
2005-02-17 12:51:44 +01:00
|
|
|
* Copyright 2004 Dmitry Timoshkov
|
2005-12-19 21:25:52 +01:00
|
|
|
* Copyright 2005 Bill Medland
|
2008-11-02 14:10:40 +01:00
|
|
|
* Copyright 2008 Damjan Jovanovic
|
2003-05-21 20:50:53 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-05-21 20:50:53 +02:00
|
|
|
*
|
|
|
|
*
|
2005-12-19 21:25:52 +01:00
|
|
|
* This program is used to replicate the Windows desktop and start menu
|
|
|
|
* into the native desktop's copies. Desktop entries are merged directly
|
|
|
|
* into the native desktop. The Windows Start Menu corresponds to a Wine
|
|
|
|
* entry within the native "start" menu and replicates the whole tree
|
|
|
|
* structure of the Windows Start Menu. Currently it does not differentiate
|
|
|
|
* between the user's desktop/start menu and the "All Users" copies.
|
|
|
|
*
|
2003-05-21 20:50:53 +02:00
|
|
|
* This program will read a Windows shortcut file using the IShellLink
|
2012-05-15 10:15:32 +02:00
|
|
|
* interface, then create a KDE/GNOME menu entry for the shortcut.
|
2003-05-21 20:50:53 +02:00
|
|
|
*
|
2007-06-28 03:23:33 +02:00
|
|
|
* winemenubuilder [ -w ] <shortcut.lnk>
|
2003-05-21 20:50:53 +02:00
|
|
|
*
|
2007-06-28 03:23:33 +02:00
|
|
|
* If the -w parameter is passed, and the shortcut cannot be created,
|
|
|
|
* this program will wait for the parent process to finish and then try
|
|
|
|
* again. This covers the case when a ShortCut is created before the
|
2003-05-21 20:50:53 +02:00
|
|
|
* executable containing its icon.
|
|
|
|
*
|
2005-12-19 21:25:52 +01:00
|
|
|
* TODO
|
|
|
|
* Handle data lnk files. There is no icon in the file; the icon is in
|
|
|
|
* the handler for the file type (or pointed to by the lnk file). Also it
|
|
|
|
* might be better to use a native handler (e.g. a native acroread for pdf
|
|
|
|
* files).
|
|
|
|
* Differentiate between the user's entries and the "All Users" entries.
|
|
|
|
* If it is possible to add the desktop files to the native system's
|
|
|
|
* shared location for an "All Users" entry then do so. As a suggestion the
|
|
|
|
* shared menu Wine base could be writable to the wine group, or a wineadm
|
|
|
|
* group.
|
2009-06-18 07:13:02 +02:00
|
|
|
* Clean up fd.o menu icons and .directory files when the menu is deleted
|
|
|
|
* in Windows.
|
2009-06-07 18:32:07 +02:00
|
|
|
* Associate applications under HKCR\Applications to open any MIME type
|
|
|
|
* (by associating with application/octet-stream, or how?).
|
|
|
|
* Clean up fd.o MIME types when they are deleted in Windows, their icons
|
|
|
|
* too. Very hard - once we associate them with fd.o, we can't tell whether
|
|
|
|
* they are ours or not, and the extension <-> MIME type mapping isn't
|
|
|
|
* one-to-one either.
|
|
|
|
* Wine's HKCR is broken - it doesn't merge HKCU\Software\Classes, so apps
|
|
|
|
* that write associations there won't associate (#17019).
|
2003-05-21 20:50:53 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
2011-01-04 15:58:22 +01:00
|
|
|
#define NONAMELESSUNION
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
#include <windows.h>
|
2021-10-01 10:46:39 +02:00
|
|
|
#include <winternl.h>
|
2003-05-21 20:50:53 +02:00
|
|
|
#include <shlobj.h>
|
|
|
|
#include <objidl.h>
|
|
|
|
#include <shlguid.h>
|
2005-11-08 11:55:25 +01:00
|
|
|
#include <appmgmt.h>
|
2007-06-28 03:23:33 +02:00
|
|
|
#include <tlhelp32.h>
|
2008-11-13 07:19:25 +01:00
|
|
|
#include <intshcut.h>
|
2009-05-19 21:40:41 +02:00
|
|
|
#include <shlwapi.h>
|
2010-07-22 21:40:14 +02:00
|
|
|
#include <initguid.h>
|
|
|
|
#include <wincodec.h>
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2009-04-11 10:10:59 +02:00
|
|
|
#include "wine/list.h"
|
2010-11-18 10:52:10 +01:00
|
|
|
#include "wine/rbtree.h"
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(menubuilder);
|
|
|
|
|
2004-09-21 22:08:10 +02:00
|
|
|
#define in_desktop_dir(csidl) ((csidl)==CSIDL_DESKTOPDIRECTORY || \
|
|
|
|
(csidl)==CSIDL_COMMON_DESKTOPDIRECTORY)
|
|
|
|
#define in_startmenu(csidl) ((csidl)==CSIDL_STARTMENU || \
|
|
|
|
(csidl)==CSIDL_COMMON_STARTMENU)
|
2015-03-16 17:44:43 +01:00
|
|
|
|
2018-07-25 09:22:57 +02:00
|
|
|
#define IS_OPTION_TRUE(ch) \
|
|
|
|
((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* link file formats */
|
|
|
|
|
|
|
|
#include "pshpack1.h"
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE bWidth;
|
|
|
|
BYTE bHeight;
|
|
|
|
BYTE bColorCount;
|
|
|
|
BYTE bReserved;
|
|
|
|
WORD wPlanes;
|
|
|
|
WORD wBitCount;
|
|
|
|
DWORD dwBytesInRes;
|
|
|
|
WORD nID;
|
|
|
|
} GRPICONDIRENTRY;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD idReserved;
|
|
|
|
WORD idType;
|
|
|
|
WORD idCount;
|
|
|
|
GRPICONDIRENTRY idEntries[1];
|
|
|
|
} GRPICONDIR;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE bWidth;
|
|
|
|
BYTE bHeight;
|
|
|
|
BYTE bColorCount;
|
|
|
|
BYTE bReserved;
|
|
|
|
WORD wPlanes;
|
|
|
|
WORD wBitCount;
|
|
|
|
DWORD dwBytesInRes;
|
|
|
|
DWORD dwImageOffset;
|
|
|
|
} ICONDIRENTRY;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD idReserved;
|
|
|
|
WORD idType;
|
|
|
|
WORD idCount;
|
|
|
|
} ICONDIR;
|
|
|
|
|
2011-05-22 14:09:05 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD offset;
|
|
|
|
WORD length;
|
|
|
|
WORD flags;
|
|
|
|
WORD id;
|
|
|
|
WORD handle;
|
|
|
|
WORD usage;
|
|
|
|
} NE_NAMEINFO;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
WORD type_id;
|
|
|
|
WORD count;
|
|
|
|
DWORD resloader;
|
|
|
|
} NE_TYPEINFO;
|
|
|
|
|
|
|
|
#define NE_RSCTYPE_ICON 0x8003
|
|
|
|
#define NE_RSCTYPE_GROUP_ICON 0x800e
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
#include "poppack.h"
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HRSRC *pResInfo;
|
|
|
|
int nIndex;
|
|
|
|
} ENUMRESSTRUCT;
|
|
|
|
|
2009-04-11 10:10:59 +02:00
|
|
|
struct xdg_mime_type
|
|
|
|
{
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *mimeType;
|
|
|
|
WCHAR *glob;
|
2009-04-11 10:10:59 +02:00
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
2010-11-18 10:52:10 +01:00
|
|
|
struct rb_string_entry
|
|
|
|
{
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *string;
|
2010-11-18 10:52:10 +01:00
|
|
|
struct wine_rb_entry entry;
|
|
|
|
};
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static WCHAR *xdg_menu_dir;
|
|
|
|
static WCHAR *xdg_data_dir;
|
|
|
|
static WCHAR xdg_desktop_dir[MAX_PATH];
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-06-07 21:40:26 +02:00
|
|
|
|
2010-08-24 15:03:13 +02:00
|
|
|
/* Utility routines */
|
2021-10-01 10:25:27 +02:00
|
|
|
static unsigned short crc16(const WCHAR *string)
|
2010-08-24 15:03:13 +02:00
|
|
|
{
|
|
|
|
unsigned short crc = 0;
|
|
|
|
int i, j, xor_poly;
|
|
|
|
|
|
|
|
for (i = 0; string[i] != 0; i++)
|
|
|
|
{
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR c = string[i];
|
|
|
|
for (j = 0; j < 16; c >>= 1, j++)
|
2010-08-24 15:03:13 +02:00
|
|
|
{
|
|
|
|
xor_poly = (c ^ crc) & 1;
|
|
|
|
crc >>= 1;
|
|
|
|
if (xor_poly)
|
|
|
|
crc ^= 0xa001;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2021-10-01 09:35:48 +02:00
|
|
|
static void *xmalloc( size_t size )
|
|
|
|
{
|
|
|
|
void *ret = HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
ERR( "out of memory\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *xrealloc( void *ptr, size_t size )
|
|
|
|
{
|
|
|
|
if (!ptr) return xmalloc( size );
|
|
|
|
ptr = HeapReAlloc( GetProcessHeap(), 0, ptr, size );
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
ERR( "out of memory\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static WCHAR *xwcsdup( const WCHAR *str )
|
|
|
|
{
|
|
|
|
WCHAR *ret;
|
|
|
|
|
|
|
|
if (!str) return NULL;
|
2021-10-01 10:46:39 +02:00
|
|
|
ret = xmalloc( (lstrlenW(str) + 1) * sizeof(WCHAR) );
|
|
|
|
lstrcpyW( ret, str );
|
2021-10-01 10:25:27 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-01 09:35:48 +02:00
|
|
|
static void heap_free( void *ptr )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, ptr );
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static WCHAR * WINAPIV heap_wprintf(const WCHAR *format, ...)
|
|
|
|
{
|
2021-10-25 11:02:26 +02:00
|
|
|
va_list args;
|
2021-10-01 10:25:27 +02:00
|
|
|
int size = 4096;
|
|
|
|
WCHAR *buffer;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
buffer = xmalloc(size * sizeof(WCHAR));
|
2021-10-25 11:02:26 +02:00
|
|
|
va_start(args, format);
|
2021-10-01 10:25:27 +02:00
|
|
|
n = _vsnwprintf(buffer, size, format, args);
|
2021-10-25 11:02:26 +02:00
|
|
|
va_end(args);
|
2021-10-01 10:25:27 +02:00
|
|
|
if (n == -1)
|
|
|
|
size *= 2;
|
|
|
|
else if (n >= size)
|
|
|
|
size = n + 1;
|
|
|
|
else
|
|
|
|
return buffer;
|
|
|
|
heap_free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 10:52:10 +01:00
|
|
|
static int winemenubuilder_rb_string_compare(const void *key, const struct wine_rb_entry *entry)
|
|
|
|
{
|
|
|
|
const struct rb_string_entry *t = WINE_RB_ENTRY_VALUE(entry, const struct rb_string_entry, entry);
|
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
return wcscmp((WCHAR *)key, t->string);
|
2010-11-18 10:52:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void winemenubuilder_rb_destroy(struct wine_rb_entry *entry, void *context)
|
|
|
|
{
|
|
|
|
struct rb_string_entry *t = WINE_RB_ENTRY_VALUE(entry, struct rb_string_entry, entry);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(t->string);
|
|
|
|
heap_free(t);
|
2010-11-18 10:52:10 +01:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
static BOOL create_directories(WCHAR *directory)
|
2010-08-24 15:03:13 +02:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WCHAR *p = PathSkipRootW( directory );
|
|
|
|
|
|
|
|
for ( ; p && *p; p++)
|
|
|
|
{
|
|
|
|
if (*p == '\\')
|
|
|
|
{
|
|
|
|
*p = 0;
|
|
|
|
CreateDirectoryW( directory, NULL );
|
|
|
|
*p = '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CreateDirectoryW( directory, NULL ) || GetLastError() == ERROR_ALREADY_EXISTS;
|
2010-08-24 15:03:13 +02:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static char* wchars_to_utf8_chars(LPCWSTR string)
|
2010-08-24 15:03:13 +02:00
|
|
|
{
|
|
|
|
char *ret;
|
2021-10-01 10:29:44 +02:00
|
|
|
INT size = WideCharToMultiByte(CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
|
2021-10-01 09:35:48 +02:00
|
|
|
ret = xmalloc(size);
|
2021-10-01 10:29:44 +02:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, string, -1, ret, size, NULL, NULL);
|
2010-08-24 15:03:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR* utf8_chars_to_wchars(LPCSTR string)
|
|
|
|
{
|
|
|
|
WCHAR *ret;
|
|
|
|
INT size = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0);
|
2021-10-01 09:35:48 +02:00
|
|
|
ret = xmalloc(size * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, string, -1, ret, size);
|
2010-08-24 15:03:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static char *wchars_to_xml_text(const WCHAR *string)
|
|
|
|
{
|
|
|
|
int i, pos;
|
|
|
|
char *text = wchars_to_utf8_chars( string );
|
|
|
|
char *ret = xmalloc( 6 * strlen(text) + 1 );
|
|
|
|
|
|
|
|
for (i = pos = 0; text[i]; i++)
|
|
|
|
{
|
|
|
|
if (text[i] == '&')
|
|
|
|
pos += sprintf(ret + pos, "&");
|
|
|
|
else if (text[i] == '<')
|
|
|
|
pos += sprintf(ret + pos, "<");
|
|
|
|
else if (text[i] == '>')
|
|
|
|
pos += sprintf(ret + pos, ">");
|
|
|
|
else if (text[i] == '\'')
|
|
|
|
pos += sprintf(ret + pos, "'");
|
|
|
|
else if (text[i] == '"')
|
|
|
|
pos += sprintf(ret + pos, """);
|
|
|
|
else
|
|
|
|
ret[pos++] = text[i];
|
|
|
|
}
|
|
|
|
heap_free( text );
|
|
|
|
ret[pos] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* Icon extraction routines
|
|
|
|
*
|
|
|
|
* FIXME: should use PrivateExtractIcons and friends
|
|
|
|
* FIXME: should not use stdio
|
|
|
|
*/
|
|
|
|
|
2011-09-27 00:14:10 +02:00
|
|
|
static HRESULT convert_to_native_icon(IStream *icoFile, int *indices, int numIndices,
|
2021-10-01 10:30:28 +02:00
|
|
|
const CLSID *outputFormat, const WCHAR *outputFileName)
|
2010-07-22 21:40:14 +02:00
|
|
|
{
|
|
|
|
IWICImagingFactory *factory = NULL;
|
|
|
|
IWICBitmapDecoder *decoder = NULL;
|
|
|
|
IWICBitmapEncoder *encoder = NULL;
|
|
|
|
IStream *outputFile = NULL;
|
2010-08-24 15:04:07 +02:00
|
|
|
int i;
|
2010-07-22 21:40:14 +02:00
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IWICImagingFactory, (void**)&factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX creating IWICImagingFactory\n", hr);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = IWICImagingFactory_CreateDecoderFromStream(factory, icoFile, NULL,
|
|
|
|
WICDecodeMetadataCacheOnDemand, &decoder);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX creating IWICBitmapDecoder\n", hr);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2010-08-24 15:04:07 +02:00
|
|
|
hr = CoCreateInstance(outputFormat, NULL, CLSCTX_INPROC_SERVER,
|
2010-07-22 21:40:14 +02:00
|
|
|
&IID_IWICBitmapEncoder, (void**)&encoder);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX creating bitmap encoder\n", hr);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2021-10-01 10:30:28 +02:00
|
|
|
hr = SHCreateStreamOnFileW(outputFileName, STGM_CREATE | STGM_WRITE, &outputFile);
|
2010-07-22 21:40:14 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX creating output file %s\n", hr, wine_dbgstr_w(outputFileName));
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2018-11-09 00:46:48 +01:00
|
|
|
hr = IWICBitmapEncoder_Initialize(encoder, outputFile, WICBitmapEncoderNoCache);
|
2010-07-22 21:40:14 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX initializing encoder\n", hr);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2010-08-24 15:04:07 +02:00
|
|
|
|
2011-09-27 00:14:10 +02:00
|
|
|
for (i = 0; i < numIndices; i++)
|
2010-07-22 21:40:14 +02:00
|
|
|
{
|
2010-08-24 15:04:07 +02:00
|
|
|
IWICBitmapFrameDecode *sourceFrame = NULL;
|
|
|
|
IWICBitmapSource *sourceBitmap = NULL;
|
|
|
|
IWICBitmapFrameEncode *dstFrame = NULL;
|
|
|
|
IPropertyBag2 *options = NULL;
|
|
|
|
UINT width, height;
|
|
|
|
|
2011-09-27 00:14:10 +02:00
|
|
|
hr = IWICBitmapDecoder_GetFrame(decoder, indices[i], &sourceFrame);
|
2010-08-24 15:04:07 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX getting frame %d\n", hr, indices[i]);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = WICConvertBitmapSource(&GUID_WICPixelFormat32bppBGRA, (IWICBitmapSource*)sourceFrame, &sourceBitmap);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX converting bitmap to 32bppBGRA\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapEncoder_CreateNewFrame(encoder, &dstFrame, &options);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX creating encoder frame\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_Initialize(dstFrame, options);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX initializing encoder frame\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapSource_GetSize(sourceBitmap, &width, &height);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX getting source bitmap size\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_SetSize(dstFrame, width, height);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX setting destination bitmap size\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_SetResolution(dstFrame, 96, 96);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX setting destination bitmap resolution\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_WriteSource(dstFrame, sourceBitmap, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX copying bitmaps\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_Commit(dstFrame);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX committing frame\n", hr);
|
2010-08-24 15:04:07 +02:00
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
endloop:
|
|
|
|
if (sourceFrame)
|
|
|
|
IWICBitmapFrameDecode_Release(sourceFrame);
|
|
|
|
if (sourceBitmap)
|
|
|
|
IWICBitmapSource_Release(sourceBitmap);
|
|
|
|
if (dstFrame)
|
|
|
|
IWICBitmapFrameEncode_Release(dstFrame);
|
2014-08-27 08:53:18 +02:00
|
|
|
if (options)
|
|
|
|
IPropertyBag2_Release(options);
|
2010-07-22 21:40:14 +02:00
|
|
|
}
|
2010-08-24 15:04:07 +02:00
|
|
|
|
|
|
|
hr = IWICBitmapEncoder_Commit(encoder);
|
2010-07-22 21:40:14 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX committing encoder\n", hr);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (factory)
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
if (decoder)
|
|
|
|
IWICBitmapDecoder_Release(decoder);
|
|
|
|
if (encoder)
|
|
|
|
IWICBitmapEncoder_Release(encoder);
|
|
|
|
if (outputFile)
|
|
|
|
IStream_Release(outputFile);
|
2010-08-24 15:04:07 +02:00
|
|
|
return hr;
|
2010-07-22 21:40:14 +02:00
|
|
|
}
|
|
|
|
|
2011-05-22 14:09:05 +02:00
|
|
|
struct IconData16 {
|
|
|
|
BYTE *fileBytes;
|
|
|
|
DWORD fileSize;
|
|
|
|
NE_TYPEINFO *iconResources;
|
|
|
|
WORD alignmentShiftCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int populate_module16_icons(struct IconData16 *iconData16, GRPICONDIR *grpIconDir, ICONDIRENTRY *iconDirEntries, BYTE *icons, SIZE_T *iconOffset)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int validEntries = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < grpIconDir->idCount; i++)
|
|
|
|
{
|
|
|
|
BYTE *iconPtr = (BYTE*)iconData16->iconResources;
|
|
|
|
NE_NAMEINFO *matchingIcon = NULL;
|
|
|
|
iconPtr += sizeof(NE_TYPEINFO);
|
|
|
|
for (j = 0; j < iconData16->iconResources->count; j++)
|
|
|
|
{
|
|
|
|
NE_NAMEINFO *iconInfo = (NE_NAMEINFO*)iconPtr;
|
2019-03-08 21:16:55 +01:00
|
|
|
if ((iconPtr + sizeof(NE_NAMEINFO)) > (iconData16->fileBytes + iconData16->fileSize))
|
2011-05-22 14:09:05 +02:00
|
|
|
{
|
|
|
|
WINE_WARN("file too small for icon NE_NAMEINFO\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (iconInfo->id == (0x8000 | grpIconDir->idEntries[i].nID))
|
|
|
|
{
|
|
|
|
matchingIcon = iconInfo;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iconPtr += sizeof(NE_NAMEINFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matchingIcon == NULL)
|
|
|
|
continue;
|
|
|
|
if (((matchingIcon->offset << iconData16->alignmentShiftCount) + grpIconDir->idEntries[i].dwBytesInRes) > iconData16->fileSize)
|
|
|
|
{
|
|
|
|
WINE_WARN("file too small for icon contents\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconDirEntries[validEntries].bWidth = grpIconDir->idEntries[i].bWidth;
|
|
|
|
iconDirEntries[validEntries].bHeight = grpIconDir->idEntries[i].bHeight;
|
|
|
|
iconDirEntries[validEntries].bColorCount = grpIconDir->idEntries[i].bColorCount;
|
|
|
|
iconDirEntries[validEntries].bReserved = grpIconDir->idEntries[i].bReserved;
|
|
|
|
iconDirEntries[validEntries].wPlanes = grpIconDir->idEntries[i].wPlanes;
|
|
|
|
iconDirEntries[validEntries].wBitCount = grpIconDir->idEntries[i].wBitCount;
|
|
|
|
iconDirEntries[validEntries].dwBytesInRes = grpIconDir->idEntries[i].dwBytesInRes;
|
|
|
|
iconDirEntries[validEntries].dwImageOffset = *iconOffset;
|
|
|
|
validEntries++;
|
|
|
|
memcpy(&icons[*iconOffset], &iconData16->fileBytes[matchingIcon->offset << iconData16->alignmentShiftCount], grpIconDir->idEntries[i].dwBytesInRes);
|
|
|
|
*iconOffset += grpIconDir->idEntries[i].dwBytesInRes;
|
|
|
|
}
|
|
|
|
return validEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int populate_module_icons(HMODULE hModule, GRPICONDIR *grpIconDir, ICONDIRENTRY *iconDirEntries, BYTE *icons, SIZE_T *iconOffset)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int validEntries = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < grpIconDir->idCount; i++)
|
|
|
|
{
|
|
|
|
HRSRC hResInfo;
|
|
|
|
LPCWSTR lpName = MAKEINTRESOURCEW(grpIconDir->idEntries[i].nID);
|
|
|
|
if ((hResInfo = FindResourceW(hModule, lpName, (LPCWSTR)RT_ICON)))
|
|
|
|
{
|
|
|
|
HGLOBAL hResData;
|
|
|
|
if ((hResData = LoadResource(hModule, hResInfo)))
|
|
|
|
{
|
|
|
|
BITMAPINFO *pIcon;
|
2014-08-28 18:05:19 +02:00
|
|
|
DWORD size = min( grpIconDir->idEntries[i].dwBytesInRes, ((IMAGE_RESOURCE_DATA_ENTRY *)hResInfo)->Size );
|
2011-05-22 14:09:05 +02:00
|
|
|
if ((pIcon = LockResource(hResData)))
|
|
|
|
{
|
|
|
|
iconDirEntries[validEntries].bWidth = grpIconDir->idEntries[i].bWidth;
|
|
|
|
iconDirEntries[validEntries].bHeight = grpIconDir->idEntries[i].bHeight;
|
|
|
|
iconDirEntries[validEntries].bColorCount = grpIconDir->idEntries[i].bColorCount;
|
|
|
|
iconDirEntries[validEntries].bReserved = grpIconDir->idEntries[i].bReserved;
|
|
|
|
iconDirEntries[validEntries].wPlanes = grpIconDir->idEntries[i].wPlanes;
|
|
|
|
iconDirEntries[validEntries].wBitCount = grpIconDir->idEntries[i].wBitCount;
|
2014-08-28 18:05:19 +02:00
|
|
|
iconDirEntries[validEntries].dwBytesInRes = size;
|
2011-05-22 14:09:05 +02:00
|
|
|
iconDirEntries[validEntries].dwImageOffset = *iconOffset;
|
|
|
|
validEntries++;
|
2014-08-28 18:05:19 +02:00
|
|
|
memcpy(&icons[*iconOffset], pIcon, size);
|
|
|
|
*iconOffset += size;
|
2011-05-22 14:09:05 +02:00
|
|
|
}
|
|
|
|
FreeResource(hResData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return validEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IStream *add_module_icons_to_stream(struct IconData16 *iconData16, HMODULE hModule, GRPICONDIR *grpIconDir)
|
2010-07-22 21:41:03 +02:00
|
|
|
{
|
2010-08-22 19:46:51 +02:00
|
|
|
int i;
|
|
|
|
SIZE_T iconsSize = 0;
|
|
|
|
BYTE *icons = NULL;
|
|
|
|
ICONDIRENTRY *iconDirEntries = NULL;
|
2010-07-22 21:41:03 +02:00
|
|
|
IStream *stream = NULL;
|
|
|
|
HRESULT hr = E_FAIL;
|
2010-08-22 19:46:51 +02:00
|
|
|
ULONG bytesWritten;
|
|
|
|
ICONDIR iconDir;
|
|
|
|
SIZE_T iconOffset;
|
|
|
|
int validEntries = 0;
|
|
|
|
LARGE_INTEGER zero;
|
|
|
|
|
|
|
|
for (i = 0; i < grpIconDir->idCount; i++)
|
|
|
|
iconsSize += grpIconDir->idEntries[i].dwBytesInRes;
|
2021-10-01 09:35:48 +02:00
|
|
|
icons = xmalloc(iconsSize);
|
|
|
|
iconDirEntries = xmalloc(grpIconDir->idCount*sizeof(ICONDIRENTRY));
|
2010-08-22 19:46:51 +02:00
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
|
2010-07-22 21:41:03 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2010-08-22 19:46:51 +02:00
|
|
|
WINE_ERR("error creating icon stream\n");
|
2010-07-22 21:41:03 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2010-08-22 19:46:51 +02:00
|
|
|
|
|
|
|
iconOffset = 0;
|
2011-05-22 14:09:05 +02:00
|
|
|
if (iconData16)
|
|
|
|
validEntries = populate_module16_icons(iconData16, grpIconDir, iconDirEntries, icons, &iconOffset);
|
|
|
|
else if (hModule)
|
|
|
|
validEntries = populate_module_icons(hModule, grpIconDir, iconDirEntries, icons, &iconOffset);
|
2010-08-22 19:46:51 +02:00
|
|
|
|
|
|
|
if (validEntries == 0)
|
|
|
|
{
|
|
|
|
WINE_ERR("no valid icon entries\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconDir.idReserved = 0;
|
|
|
|
iconDir.idType = 1;
|
|
|
|
iconDir.idCount = validEntries;
|
|
|
|
hr = IStream_Write(stream, &iconDir, sizeof(iconDir), &bytesWritten);
|
|
|
|
if (FAILED(hr) || bytesWritten != sizeof(iconDir))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX writing icon stream\n", hr);
|
2010-08-22 19:46:51 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
for (i = 0; i < validEntries; i++)
|
|
|
|
iconDirEntries[i].dwImageOffset += sizeof(ICONDIR) + validEntries*sizeof(ICONDIRENTRY);
|
|
|
|
hr = IStream_Write(stream, iconDirEntries, validEntries*sizeof(ICONDIRENTRY), &bytesWritten);
|
|
|
|
if (FAILED(hr) || bytesWritten != validEntries*sizeof(ICONDIRENTRY))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX writing icon dir entries to stream\n", hr);
|
2010-08-22 19:46:51 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = IStream_Write(stream, icons, iconOffset, &bytesWritten);
|
|
|
|
if (FAILED(hr) || bytesWritten != iconOffset)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error 0x%08lX writing icon images to stream\n", hr);
|
2010-08-22 19:46:51 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
|
2010-07-22 21:41:03 +02:00
|
|
|
|
|
|
|
end:
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(icons);
|
|
|
|
heap_free(iconDirEntries);
|
2010-08-22 19:42:18 +02:00
|
|
|
if (FAILED(hr) && stream != NULL)
|
|
|
|
{
|
2010-07-22 21:41:03 +02:00
|
|
|
IStream_Release(stream);
|
2010-08-22 19:42:18 +02:00
|
|
|
stream = NULL;
|
|
|
|
}
|
|
|
|
return stream;
|
2010-07-22 21:41:03 +02:00
|
|
|
}
|
|
|
|
|
2011-05-22 14:09:05 +02:00
|
|
|
static HRESULT open_module16_icon(LPCWSTR szFileName, int nIndex, IStream **ppStream)
|
|
|
|
{
|
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE hFileMapping = NULL;
|
|
|
|
DWORD fileSize;
|
|
|
|
BYTE *fileBytes = NULL;
|
|
|
|
IMAGE_DOS_HEADER *dosHeader;
|
|
|
|
IMAGE_OS2_HEADER *neHeader;
|
|
|
|
BYTE *rsrcTab;
|
|
|
|
NE_TYPEINFO *iconGroupResources;
|
|
|
|
NE_TYPEINFO *iconResources;
|
|
|
|
NE_NAMEINFO *iconDirPtr;
|
|
|
|
GRPICONDIR *iconDir;
|
|
|
|
WORD alignmentShiftCount;
|
|
|
|
struct IconData16 iconData16;
|
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
|
|
|
|
hFile = CreateFileW(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("opening %s failed with error %ld\n", wine_dbgstr_w(szFileName), GetLastError());
|
2011-05-22 14:09:05 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
|
|
|
|
if (hFileMapping == NULL)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("CreateFileMapping failed, error %ld\n", GetLastError());
|
2011-05-22 14:09:05 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileSize = GetFileSize(hFile, NULL);
|
|
|
|
|
|
|
|
fileBytes = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
if (fileBytes == NULL)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("MapViewOfFile failed, error %ld\n", GetLastError());
|
2011-05-22 14:09:05 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
dosHeader = (IMAGE_DOS_HEADER*)fileBytes;
|
|
|
|
if (sizeof(IMAGE_DOS_HEADER) >= fileSize || dosHeader->e_magic != IMAGE_DOS_SIGNATURE)
|
|
|
|
{
|
|
|
|
WINE_WARN("file too small for MZ header\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
neHeader = (IMAGE_OS2_HEADER*)(fileBytes + dosHeader->e_lfanew);
|
|
|
|
if ((((BYTE*)neHeader) + sizeof(IMAGE_OS2_HEADER)) > (fileBytes + fileSize) ||
|
|
|
|
neHeader->ne_magic != IMAGE_OS2_SIGNATURE)
|
|
|
|
{
|
|
|
|
WINE_WARN("file too small for NE header\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
rsrcTab = ((BYTE*)neHeader) + neHeader->ne_rsrctab;
|
|
|
|
if ((rsrcTab + 2) > (fileBytes + fileSize))
|
|
|
|
{
|
|
|
|
WINE_WARN("file too small for resource table\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
alignmentShiftCount = *(WORD*)rsrcTab;
|
|
|
|
rsrcTab += 2;
|
|
|
|
iconGroupResources = NULL;
|
|
|
|
iconResources = NULL;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
NE_TYPEINFO *neTypeInfo = (NE_TYPEINFO*)rsrcTab;
|
|
|
|
if ((rsrcTab + sizeof(NE_TYPEINFO)) > (fileBytes + fileSize))
|
|
|
|
{
|
|
|
|
WINE_WARN("file too small for resource table\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (neTypeInfo->type_id == 0)
|
|
|
|
break;
|
|
|
|
else if (neTypeInfo->type_id == NE_RSCTYPE_GROUP_ICON)
|
|
|
|
iconGroupResources = neTypeInfo;
|
|
|
|
else if (neTypeInfo->type_id == NE_RSCTYPE_ICON)
|
|
|
|
iconResources = neTypeInfo;
|
|
|
|
rsrcTab += sizeof(NE_TYPEINFO) + neTypeInfo->count*sizeof(NE_NAMEINFO);
|
|
|
|
}
|
|
|
|
if (iconGroupResources == NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("no group icon resource type found\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (iconResources == NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("no icon resource type found\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nIndex >= iconGroupResources->count)
|
|
|
|
{
|
|
|
|
WINE_WARN("icon index out of range\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconDirPtr = (NE_NAMEINFO*)(((BYTE*)iconGroupResources) + sizeof(NE_TYPEINFO) + nIndex*sizeof(NE_NAMEINFO));
|
|
|
|
if ((((BYTE*)iconDirPtr) + sizeof(NE_NAMEINFO)) > (fileBytes + fileSize))
|
|
|
|
{
|
2014-01-06 02:13:41 +01:00
|
|
|
WINE_WARN("file too small for icon group NE_NAMEINFO\n");
|
2011-05-22 14:09:05 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
iconDir = (GRPICONDIR*)(fileBytes + (iconDirPtr->offset << alignmentShiftCount));
|
|
|
|
if ((((BYTE*)iconDir) + sizeof(GRPICONDIR) + iconDir->idCount*sizeof(GRPICONDIRENTRY)) > (fileBytes + fileSize))
|
|
|
|
{
|
|
|
|
WINE_WARN("file too small for GRPICONDIR\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconData16.fileBytes = fileBytes;
|
|
|
|
iconData16.fileSize = fileSize;
|
|
|
|
iconData16.iconResources = iconResources;
|
|
|
|
iconData16.alignmentShiftCount = alignmentShiftCount;
|
|
|
|
*ppStream = add_module_icons_to_stream(&iconData16, NULL, iconDir);
|
|
|
|
if (*ppStream)
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (hFile != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(hFile);
|
|
|
|
if (hFileMapping != NULL)
|
|
|
|
CloseHandle(hFileMapping);
|
|
|
|
if (fileBytes != NULL)
|
|
|
|
UnmapViewOfFile(fileBytes);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
|
|
|
|
|
|
|
|
if (!sEnumRes->nIndex--)
|
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
*sEnumRes->pResInfo = FindResourceW(hModule, lpszName, (LPCWSTR)RT_GROUP_ICON);
|
2005-02-16 17:04:05 +01:00
|
|
|
return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
else
|
2005-02-16 17:04:05 +01:00
|
|
|
return TRUE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2010-08-22 19:42:18 +02:00
|
|
|
static HRESULT open_module_icon(LPCWSTR szFileName, int nIndex, IStream **ppStream)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
HMODULE hModule;
|
|
|
|
HRSRC hResInfo;
|
|
|
|
HGLOBAL hResData;
|
|
|
|
GRPICONDIR *pIconDir;
|
|
|
|
ENUMRESSTRUCT sEnumRes;
|
2010-08-22 19:42:18 +02:00
|
|
|
HRESULT hr = E_FAIL;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
hModule = LoadLibraryExW(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE);
|
2005-02-16 17:04:05 +01:00
|
|
|
if (!hModule)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2011-05-22 14:09:05 +02:00
|
|
|
if (GetLastError() == ERROR_BAD_EXE_FORMAT)
|
|
|
|
return open_module16_icon(szFileName, nIndex, ppStream);
|
|
|
|
else
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("LoadLibraryExW (%s) failed, error %ld\n",
|
2011-05-22 14:09:05 +02:00
|
|
|
wine_dbgstr_w(szFileName), GetLastError());
|
|
|
|
return HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nIndex < 0)
|
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
hResInfo = FindResourceW(hModule, MAKEINTRESOURCEW(-nIndex), (LPCWSTR)RT_GROUP_ICON);
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_TRACE("FindResourceW (%s) called, return %p, error %ld\n",
|
2005-02-17 12:51:44 +01:00
|
|
|
wine_dbgstr_w(szFileName), hResInfo, GetLastError());
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-07-02 06:30:55 +02:00
|
|
|
hResInfo=NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
sEnumRes.pResInfo = &hResInfo;
|
|
|
|
sEnumRes.nIndex = nIndex;
|
2006-01-11 12:09:53 +01:00
|
|
|
if (!EnumResourceNamesW(hModule, (LPCWSTR)RT_GROUP_ICON,
|
2008-01-11 09:57:15 +01:00
|
|
|
EnumResNameProc, (LONG_PTR)&sEnumRes) &&
|
2009-03-11 17:16:41 +01:00
|
|
|
sEnumRes.nIndex != -1)
|
2006-01-11 12:09:53 +01:00
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_TRACE("EnumResourceNamesW failed, error %ld\n", GetLastError());
|
2006-01-11 12:09:53 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
if (hResInfo)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
if ((hResData = LoadResource(hModule, hResInfo)))
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
if ((pIconDir = LockResource(hResData)))
|
|
|
|
{
|
2011-05-22 14:09:05 +02:00
|
|
|
*ppStream = add_module_icons_to_stream(0, hModule, pIconDir);
|
2010-08-22 19:46:51 +02:00
|
|
|
if (*ppStream)
|
|
|
|
hr = S_OK;
|
2005-02-17 12:51:44 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
FreeResource(hResData);
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
else
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2006-11-24 23:39:51 +01:00
|
|
|
WINE_WARN("found no icon\n");
|
2005-02-17 12:51:44 +01:00
|
|
|
FreeLibrary(hModule);
|
2010-08-22 19:42:18 +02:00
|
|
|
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FreeLibrary(hModule);
|
2010-08-22 19:42:18 +02:00
|
|
|
return hr;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2010-08-24 15:04:54 +02:00
|
|
|
static HRESULT read_ico_direntries(IStream *icoStream, ICONDIRENTRY **ppIconDirEntries, int *numEntries)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
ICONDIR iconDir;
|
2010-08-22 19:42:18 +02:00
|
|
|
ULONG bytesRead;
|
2010-07-22 21:40:14 +02:00
|
|
|
HRESULT hr;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-08-24 15:04:54 +02:00
|
|
|
*ppIconDirEntries = NULL;
|
|
|
|
|
|
|
|
hr = IStream_Read(icoStream, &iconDir, sizeof(ICONDIR), &bytesRead);
|
2010-08-22 19:42:18 +02:00
|
|
|
if (FAILED(hr) || bytesRead != sizeof(ICONDIR) ||
|
2006-01-17 13:34:31 +01:00
|
|
|
(iconDir.idReserved != 0) || (iconDir.idType != 1))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("Invalid ico file format (hr=0x%08lX, bytesRead=%ld)\n", hr, bytesRead);
|
2010-08-22 19:42:18 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
goto end;
|
2006-01-17 13:34:31 +01:00
|
|
|
}
|
2010-08-24 15:04:54 +02:00
|
|
|
*numEntries = iconDir.idCount;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2021-10-01 09:35:48 +02:00
|
|
|
*ppIconDirEntries = xmalloc(sizeof(ICONDIRENTRY)*iconDir.idCount);
|
2010-08-24 15:04:54 +02:00
|
|
|
hr = IStream_Read(icoStream, *ppIconDirEntries, sizeof(ICONDIRENTRY)*iconDir.idCount, &bytesRead);
|
2010-08-22 19:42:18 +02:00
|
|
|
if (FAILED(hr) || bytesRead != sizeof(ICONDIRENTRY)*iconDir.idCount)
|
|
|
|
{
|
|
|
|
if (SUCCEEDED(hr)) hr = E_FAIL;
|
|
|
|
goto end;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-08-24 15:04:54 +02:00
|
|
|
end:
|
|
|
|
if (FAILED(hr))
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(*ppIconDirEntries);
|
2010-08-24 15:04:54 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:44:43 +01:00
|
|
|
static HRESULT validate_ico(IStream **ppStream, ICONDIRENTRY **ppIconDirEntries, int *numEntries)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = read_ico_direntries(*ppStream, ppIconDirEntries, numEntries);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (*numEntries)
|
|
|
|
return hr;
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(*ppIconDirEntries);
|
2015-03-16 17:44:43 +01:00
|
|
|
*ppIconDirEntries = NULL;
|
|
|
|
}
|
|
|
|
IStream_Release(*ppStream);
|
|
|
|
*ppStream = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_native_icon(IStream *iconStream, ICONDIRENTRY *pIconDirEntry,
|
2021-10-01 10:30:28 +02:00
|
|
|
int numEntries, const WCHAR *icon_name)
|
2010-08-24 15:04:54 +02:00
|
|
|
{
|
|
|
|
int nMax = 0, nMaxBits = 0;
|
|
|
|
int nIndex = 0;
|
|
|
|
int i;
|
|
|
|
LARGE_INTEGER position;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
for (i = 0; i < numEntries; i++)
|
2008-03-23 21:16:38 +01:00
|
|
|
{
|
|
|
|
WINE_TRACE("[%d]: %d x %d @ %d\n", i, pIconDirEntry[i].bWidth, pIconDirEntry[i].bHeight, pIconDirEntry[i].wBitCount);
|
|
|
|
if (pIconDirEntry[i].wBitCount >= nMaxBits &&
|
2006-11-30 01:54:06 +01:00
|
|
|
(pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) >= nMax)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
nIndex = i;
|
|
|
|
nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
|
2006-11-30 01:54:06 +01:00
|
|
|
nMaxBits = pIconDirEntry[i].wBitCount;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2008-03-23 21:16:38 +01:00
|
|
|
}
|
|
|
|
WINE_TRACE("Selected: %d\n", nIndex);
|
|
|
|
|
2010-08-22 19:42:18 +02:00
|
|
|
position.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(iconStream, position, STREAM_SEEK_SET, NULL);
|
2016-08-21 20:38:18 +02:00
|
|
|
if (FAILED(hr)) return hr;
|
2021-10-01 10:25:27 +02:00
|
|
|
return convert_to_native_icon(iconStream, &nIndex, 1, &CLSID_WICPngEncoder, icon_name);
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2015-03-16 17:44:39 +01:00
|
|
|
static WCHAR* assoc_query(ASSOCSTR assocStr, LPCWSTR name, LPCWSTR extra)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
WCHAR *value = NULL;
|
|
|
|
DWORD size = 0;
|
|
|
|
hr = AssocQueryStringW(0, assocStr, name, extra, NULL, &size);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
value = xmalloc(size * sizeof(WCHAR));
|
|
|
|
hr = AssocQueryStringW(0, assocStr, name, extra, value, &size);
|
|
|
|
if (FAILED(hr))
|
2015-03-16 17:44:39 +01:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(value);
|
|
|
|
value = NULL;
|
2015-03-16 17:44:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2010-08-22 19:42:18 +02:00
|
|
|
static HRESULT open_file_type_icon(LPCWSTR szFileName, IStream **ppStream)
|
2010-06-07 21:40:26 +02:00
|
|
|
{
|
|
|
|
WCHAR *extension;
|
|
|
|
WCHAR *icon = NULL;
|
|
|
|
WCHAR *comma;
|
2010-06-08 22:05:04 +02:00
|
|
|
WCHAR *executable = NULL;
|
2010-06-07 21:40:26 +02:00
|
|
|
int index = 0;
|
2010-08-22 19:42:18 +02:00
|
|
|
HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
|
2010-06-07 21:40:26 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
extension = wcsrchr(szFileName, '.');
|
2010-06-07 21:40:26 +02:00
|
|
|
if (extension == NULL)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
icon = assoc_query(ASSOCSTR_DEFAULTICON, extension, NULL);
|
2010-06-08 22:05:04 +02:00
|
|
|
if (icon)
|
|
|
|
{
|
2021-10-01 10:46:39 +02:00
|
|
|
comma = wcsrchr(icon, ',');
|
2010-06-08 22:05:04 +02:00
|
|
|
if (comma)
|
|
|
|
{
|
|
|
|
*comma = 0;
|
2021-10-01 10:46:39 +02:00
|
|
|
index = wcstol(comma + 1, NULL, 10);
|
2010-06-08 22:05:04 +02:00
|
|
|
}
|
2014-11-22 19:39:43 +01:00
|
|
|
hr = open_module_icon(icon, index, ppStream);
|
2010-06-08 22:05:04 +02:00
|
|
|
}
|
|
|
|
else
|
2010-06-07 21:40:26 +02:00
|
|
|
{
|
2021-10-01 11:09:28 +02:00
|
|
|
executable = assoc_query(ASSOCSTR_EXECUTABLE, extension, L"open");
|
2010-06-08 22:05:04 +02:00
|
|
|
if (executable)
|
2014-11-22 19:39:43 +01:00
|
|
|
hr = open_module_icon(executable, 0, ppStream);
|
2010-06-07 21:40:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(icon);
|
|
|
|
heap_free(executable);
|
2010-08-22 19:42:18 +02:00
|
|
|
return hr;
|
2010-06-07 21:40:26 +02:00
|
|
|
}
|
|
|
|
|
2010-08-22 19:42:18 +02:00
|
|
|
static HRESULT open_default_icon(IStream **ppStream)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2021-10-01 11:09:28 +02:00
|
|
|
return open_module_icon(L"user32", -(INT_PTR)IDI_WINLOGO, ppStream);
|
2010-08-22 19:42:18 +02:00
|
|
|
}
|
|
|
|
|
2015-03-16 17:44:43 +01:00
|
|
|
static HRESULT open_icon(LPCWSTR filename, int index, BOOL bWait, IStream **ppStream, ICONDIRENTRY **ppIconDirEntries, int *numEntries)
|
2010-08-22 19:42:18 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = open_module_icon(filename, index, ppStream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2013-01-23 14:07:44 +01:00
|
|
|
if(bWait && hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
|
|
|
|
{
|
|
|
|
WINE_WARN("Can't find file: %s, give a chance to parent process to create it\n",
|
|
|
|
wine_dbgstr_w(filename));
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-16 17:44:43 +01:00
|
|
|
/* This might be a raw .ico file */
|
|
|
|
hr = SHCreateStreamOnFileW(filename, STGM_READ, ppStream);
|
2013-01-23 14:07:44 +01:00
|
|
|
}
|
2010-08-22 19:42:18 +02:00
|
|
|
}
|
2015-03-16 17:44:43 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = validate_ico(ppStream, ppIconDirEntries, numEntries);
|
|
|
|
|
2010-08-22 19:42:18 +02:00
|
|
|
if (FAILED(hr))
|
2015-03-16 17:44:43 +01:00
|
|
|
{
|
2010-08-22 19:42:18 +02:00
|
|
|
hr = open_file_type_icon(filename, ppStream);
|
2015-03-16 17:44:43 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = validate_ico(ppStream, ppIconDirEntries, numEntries);
|
|
|
|
}
|
2010-08-22 19:42:18 +02:00
|
|
|
if (FAILED(hr) && !bWait)
|
2015-03-16 17:44:43 +01:00
|
|
|
{
|
2010-08-22 19:42:18 +02:00
|
|
|
hr = open_default_icon(ppStream);
|
2015-03-16 17:44:43 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = validate_ico(ppStream, ppIconDirEntries, numEntries);
|
|
|
|
}
|
2010-08-22 19:42:18 +02:00
|
|
|
return hr;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static WCHAR *compute_native_identifier(int exeIndex, LPCWSTR icoPathW, LPCWSTR filename)
|
2012-11-01 23:20:13 +01:00
|
|
|
{
|
|
|
|
unsigned short crc;
|
2021-10-01 10:25:27 +02:00
|
|
|
const WCHAR *basename, *ext;
|
2012-11-01 23:20:13 +01:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
if (filename) return xwcsdup( filename );
|
2012-11-01 23:20:13 +01:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
crc = crc16(icoPathW);
|
2021-10-01 10:46:39 +02:00
|
|
|
basename = wcsrchr(icoPathW, '\\');
|
2021-10-01 10:25:27 +02:00
|
|
|
if (basename == NULL) basename = icoPathW;
|
|
|
|
else basename++;
|
2021-10-01 10:46:39 +02:00
|
|
|
ext = wcsrchr(basename, '.');
|
|
|
|
if (!ext) ext = basename + lstrlenW(basename);
|
2021-10-01 10:25:27 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
return heap_wprintf(L"%04X_%.*s.%d", crc, (int)(ext - basename), basename, exeIndex);
|
2012-11-01 23:20:13 +01:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:28 +02:00
|
|
|
static void refresh_icon_cache(const WCHAR *iconsDir)
|
2011-01-15 09:37:52 +01:00
|
|
|
{
|
2021-10-01 10:30:28 +02:00
|
|
|
WCHAR buffer[MAX_PATH];
|
|
|
|
|
2011-01-15 09:37:52 +01:00
|
|
|
/* The icon theme spec only requires the mtime on the "toplevel"
|
|
|
|
* directory (whatever that is) to be changed for a refresh,
|
2012-05-15 10:15:32 +02:00
|
|
|
* but on GNOME you have to create a file in that directory
|
|
|
|
* instead. Creating a file also works on KDE, Xfce and LXDE.
|
2011-01-15 09:37:52 +01:00
|
|
|
*/
|
2021-10-01 11:09:28 +02:00
|
|
|
GetTempFileNameW( iconsDir, L"icn", 0, buffer );
|
2021-10-01 10:30:28 +02:00
|
|
|
DeleteFileW( buffer );
|
2011-01-15 09:37:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-16 17:44:43 +01:00
|
|
|
static HRESULT platform_write_icon(IStream *icoStream, ICONDIRENTRY *iconDirEntries,
|
|
|
|
int numEntries, int exeIndex, LPCWSTR icoPathW,
|
2021-10-01 10:25:27 +02:00
|
|
|
const WCHAR *destFilename, WCHAR **nativeIdentifier)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2011-01-05 11:57:18 +01:00
|
|
|
int i;
|
2021-10-01 10:30:28 +02:00
|
|
|
WCHAR *iconsDir;
|
2010-09-22 22:14:04 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
LARGE_INTEGER zero;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
*nativeIdentifier = compute_native_identifier(exeIndex, icoPathW, destFilename);
|
2021-10-01 11:09:28 +02:00
|
|
|
iconsDir = heap_wprintf(L"%s\\icons\\hicolor", xdg_data_dir);
|
2011-01-15 09:37:52 +01:00
|
|
|
|
|
|
|
for (i = 0; i < numEntries; i++)
|
2010-08-22 19:42:18 +02:00
|
|
|
{
|
2011-05-17 22:33:03 +02:00
|
|
|
int bestIndex = i;
|
2011-01-15 09:37:52 +01:00
|
|
|
int j;
|
|
|
|
BOOLEAN duplicate = FALSE;
|
|
|
|
int w, h;
|
2021-10-01 10:30:28 +02:00
|
|
|
WCHAR *iconDir;
|
|
|
|
WCHAR *pngPath;
|
2011-01-15 09:37:52 +01:00
|
|
|
|
|
|
|
WINE_TRACE("[%d]: %d x %d @ %d\n", i, iconDirEntries[i].bWidth,
|
|
|
|
iconDirEntries[i].bHeight, iconDirEntries[i].wBitCount);
|
|
|
|
|
|
|
|
for (j = 0; j < i; j++)
|
|
|
|
{
|
|
|
|
if (iconDirEntries[j].bWidth == iconDirEntries[i].bWidth &&
|
|
|
|
iconDirEntries[j].bHeight == iconDirEntries[i].bHeight)
|
|
|
|
{
|
|
|
|
duplicate = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (duplicate)
|
|
|
|
continue;
|
2011-05-17 22:33:03 +02:00
|
|
|
for (j = i + 1; j < numEntries; j++)
|
2011-01-15 09:37:52 +01:00
|
|
|
{
|
|
|
|
if (iconDirEntries[j].bWidth == iconDirEntries[i].bWidth &&
|
|
|
|
iconDirEntries[j].bHeight == iconDirEntries[i].bHeight &&
|
2011-05-17 22:33:03 +02:00
|
|
|
iconDirEntries[j].wBitCount >= iconDirEntries[bestIndex].wBitCount)
|
2011-01-15 09:37:52 +01:00
|
|
|
{
|
|
|
|
bestIndex = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WINE_TRACE("Selected: %d\n", bestIndex);
|
|
|
|
|
|
|
|
w = iconDirEntries[bestIndex].bWidth ? iconDirEntries[bestIndex].bWidth : 256;
|
|
|
|
h = iconDirEntries[bestIndex].bHeight ? iconDirEntries[bestIndex].bHeight : 256;
|
2021-10-01 11:09:28 +02:00
|
|
|
iconDir = heap_wprintf(L"%s\\%dx%d\\apps", iconsDir, w, h);
|
2021-10-01 10:30:40 +02:00
|
|
|
create_directories(iconDir);
|
2021-10-01 11:09:28 +02:00
|
|
|
pngPath = heap_wprintf(L"%s\\%s.png", iconDir, *nativeIdentifier);
|
2011-01-15 09:37:52 +01:00
|
|
|
zero.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(icoStream, zero, STREAM_SEEK_SET, NULL);
|
2021-10-01 09:35:48 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2021-10-01 10:25:27 +02:00
|
|
|
hr = convert_to_native_icon(icoStream, &bestIndex, 1, &CLSID_WICPngEncoder, pngPath);
|
2011-01-15 09:37:52 +01:00
|
|
|
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(iconDir);
|
|
|
|
heap_free(pngPath);
|
2010-08-22 19:42:18 +02:00
|
|
|
}
|
2011-01-15 09:37:52 +01:00
|
|
|
refresh_icon_cache(iconsDir);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(iconsDir);
|
2010-09-22 22:14:04 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
|
2021-10-01 10:25:27 +02:00
|
|
|
static WCHAR *extract_icon(LPCWSTR icoPathW, int index, const WCHAR *destFilename, BOOL bWait)
|
2010-09-22 22:14:04 +02:00
|
|
|
{
|
|
|
|
IStream *stream = NULL;
|
2015-03-16 17:44:43 +01:00
|
|
|
ICONDIRENTRY *pIconDirEntries = NULL;
|
|
|
|
int numEntries;
|
2010-09-22 22:14:04 +02:00
|
|
|
HRESULT hr;
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *nativeIdentifier = NULL;
|
2010-09-22 22:14:04 +02:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
WINE_TRACE("path=[%s] index=%d destFilename=[%s]\n", wine_dbgstr_w(icoPathW), index, wine_dbgstr_w(destFilename));
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2015-03-16 17:44:43 +01:00
|
|
|
hr = open_icon(icoPathW, index, bWait, &stream, &pIconDirEntries, &numEntries);
|
2010-09-22 22:14:04 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("opening icon %s index %d failed, hr=0x%08lX\n", wine_dbgstr_w(icoPathW), index, hr);
|
2010-09-22 22:14:04 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2015-03-16 17:44:43 +01:00
|
|
|
hr = platform_write_icon(stream, pIconDirEntries, numEntries, index, icoPathW, destFilename, &nativeIdentifier);
|
2010-09-22 22:14:04 +02:00
|
|
|
if (FAILED(hr))
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("writing icon failed, error 0x%08lX\n", hr);
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-09-22 22:14:04 +02:00
|
|
|
end:
|
2010-08-22 19:42:18 +02:00
|
|
|
if (stream)
|
|
|
|
IStream_Release(stream);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(pIconDirEntries);
|
2010-09-22 22:14:04 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(nativeIdentifier);
|
2010-09-22 22:14:04 +02:00
|
|
|
nativeIdentifier = NULL;
|
|
|
|
}
|
|
|
|
return nativeIdentifier;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
static HKEY open_menus_reg_key(void)
|
|
|
|
{
|
|
|
|
HKEY assocKey;
|
2010-04-30 13:41:40 +02:00
|
|
|
DWORD ret;
|
2021-10-01 11:09:28 +02:00
|
|
|
ret = RegCreateKeyW(HKEY_CURRENT_USER, L"Software\\Wine\\MenuFiles", &assocKey);
|
2010-04-30 13:41:40 +02:00
|
|
|
if (ret == ERROR_SUCCESS)
|
2009-06-18 07:13:02 +02:00
|
|
|
return assocKey;
|
2010-04-30 13:41:40 +02:00
|
|
|
SetLastError(ret);
|
2009-06-18 07:13:02 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static DWORD register_menus_entry(const WCHAR *menu_file, const WCHAR *windows_file)
|
2010-04-30 13:41:40 +02:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
HKEY hkey;
|
2010-04-30 13:41:40 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
2021-10-01 09:35:48 +02:00
|
|
|
hkey = open_menus_reg_key();
|
|
|
|
if (hkey)
|
2010-04-30 13:41:40 +02:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
ret = RegSetValueExW(hkey, menu_file, 0, REG_SZ, (const BYTE*)windows_file,
|
2021-10-01 10:46:39 +02:00
|
|
|
(lstrlenW(windows_file) + 1) * sizeof(WCHAR));
|
2021-10-01 09:35:48 +02:00
|
|
|
RegCloseKey(hkey);
|
2010-04-30 13:41:40 +02:00
|
|
|
}
|
|
|
|
else
|
2021-10-01 09:35:48 +02:00
|
|
|
ret = GetLastError();
|
2010-04-30 13:41:40 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:57 +02:00
|
|
|
/* This escapes reserved characters in .desktop files' Exec keys. */
|
|
|
|
static LPSTR escape(LPCWSTR arg)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
WCHAR *escaped_string;
|
|
|
|
char *utf8_string;
|
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
escaped_string = xmalloc((4 * lstrlenW(arg) + 1) * sizeof(WCHAR));
|
2021-10-01 10:25:57 +02:00
|
|
|
for (i = j = 0; arg[i]; i++)
|
|
|
|
{
|
|
|
|
switch (arg[i])
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
escaped_string[j++] = '\\';
|
|
|
|
escaped_string[j++] = '\\';
|
|
|
|
escaped_string[j++] = '\\';
|
|
|
|
escaped_string[j++] = '\\';
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
case '\n':
|
|
|
|
case '"':
|
|
|
|
case '\'':
|
|
|
|
case '>':
|
|
|
|
case '<':
|
|
|
|
case '~':
|
|
|
|
case '|':
|
|
|
|
case '&':
|
|
|
|
case ';':
|
|
|
|
case '$':
|
|
|
|
case '*':
|
|
|
|
case '?':
|
|
|
|
case '#':
|
|
|
|
case '(':
|
|
|
|
case ')':
|
|
|
|
case '`':
|
|
|
|
escaped_string[j++] = '\\';
|
|
|
|
escaped_string[j++] = '\\';
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
escaped_string[j++] = arg[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
escaped_string[j] = 0;
|
|
|
|
utf8_string = wchars_to_utf8_chars(escaped_string);
|
|
|
|
heap_free(escaped_string);
|
|
|
|
return utf8_string;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static BOOL write_desktop_entry(const WCHAR *link, const WCHAR *location, const WCHAR *linkname,
|
2021-10-01 10:25:57 +02:00
|
|
|
const WCHAR *path, const WCHAR *args, const WCHAR *descr,
|
|
|
|
const WCHAR *workdir, const WCHAR *icon, const WCHAR *wmclass)
|
2008-11-08 10:03:39 +01:00
|
|
|
{
|
|
|
|
FILE *file;
|
2021-10-01 10:25:57 +02:00
|
|
|
char *workdir_unix;
|
2021-10-01 10:29:44 +02:00
|
|
|
int needs_chmod = FALSE;
|
|
|
|
const WCHAR *name;
|
2021-10-01 10:46:39 +02:00
|
|
|
const WCHAR *prefix = _wgetenv( L"WINECONFIGDIR" );
|
2008-11-08 10:03:39 +01:00
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_TRACE("(%s,%s,%s,%s,%s,%s,%s,%s,%s)\n", wine_dbgstr_w(link), wine_dbgstr_w(location),
|
2021-10-01 10:25:57 +02:00
|
|
|
wine_dbgstr_w(linkname), wine_dbgstr_w(path), wine_dbgstr_w(args),
|
|
|
|
wine_dbgstr_w(descr), wine_dbgstr_w(workdir), wine_dbgstr_w(icon),
|
|
|
|
wine_dbgstr_w(wmclass));
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
name = PathFindFileNameW( linkname );
|
|
|
|
if (!location)
|
|
|
|
{
|
2021-10-01 11:09:28 +02:00
|
|
|
location = heap_wprintf(L"%s\\%s.desktop", xdg_desktop_dir, name);
|
2021-10-01 10:29:44 +02:00
|
|
|
needs_chmod = TRUE;
|
|
|
|
}
|
2008-11-08 10:03:39 +01:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
file = _wfopen( location, L"wb" );
|
2008-11-08 10:03:39 +01:00
|
|
|
if (file == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fprintf(file, "[Desktop Entry]\n");
|
2021-10-01 10:29:44 +02:00
|
|
|
fprintf(file, "Name=%s\n", wchars_to_utf8_chars(name));
|
2021-10-01 10:25:57 +02:00
|
|
|
fprintf(file, "Exec=" );
|
2020-04-17 12:46:06 +02:00
|
|
|
if (prefix)
|
2021-10-01 10:46:39 +02:00
|
|
|
{
|
|
|
|
char *path = wine_get_unix_file_name( prefix );
|
|
|
|
fprintf(file, "env WINEPREFIX=\"%s\" ", path);
|
|
|
|
heap_free( path );
|
|
|
|
}
|
2021-10-01 10:25:57 +02:00
|
|
|
fprintf(file, "wine %s", escape(path));
|
|
|
|
if (args) fprintf(file, " %s", escape(args) );
|
|
|
|
fputc( '\n', file );
|
2008-11-08 10:03:39 +01:00
|
|
|
fprintf(file, "Type=Application\n");
|
2009-01-06 19:59:07 +01:00
|
|
|
fprintf(file, "StartupNotify=true\n");
|
2018-10-23 15:54:15 +02:00
|
|
|
if (descr && *descr)
|
2021-10-01 10:25:57 +02:00
|
|
|
fprintf(file, "Comment=%s\n", wchars_to_utf8_chars(descr));
|
|
|
|
if (workdir && *workdir && (workdir_unix = wine_get_unix_file_name(workdir)))
|
|
|
|
fprintf(file, "Path=%s\n", workdir_unix);
|
2018-10-23 15:54:15 +02:00
|
|
|
if (icon && *icon)
|
2021-10-01 10:25:27 +02:00
|
|
|
fprintf(file, "Icon=%s\n", wchars_to_utf8_chars(icon));
|
2018-10-23 15:54:15 +02:00
|
|
|
if (wmclass && *wmclass)
|
2021-10-01 10:25:57 +02:00
|
|
|
fprintf(file, "StartupWMClass=%s\n", wchars_to_utf8_chars(wmclass));
|
2008-11-08 10:03:39 +01:00
|
|
|
|
|
|
|
fclose(file);
|
2009-06-18 07:13:02 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
if (needs_chmod)
|
|
|
|
{
|
|
|
|
const char *argv[] = { "chmod", "+x", wine_get_unix_file_name(location), NULL };
|
|
|
|
__wine_unix_spawnvp( (char **)argv, FALSE );
|
|
|
|
}
|
2021-10-01 10:25:57 +02:00
|
|
|
|
2021-10-01 10:19:27 +02:00
|
|
|
if (link)
|
2009-06-18 07:13:02 +02:00
|
|
|
{
|
2021-10-01 10:19:27 +02:00
|
|
|
DWORD ret = register_menus_entry(location, link);
|
2010-04-30 13:41:40 +02:00
|
|
|
if (ret != ERROR_SUCCESS)
|
2009-06-18 07:13:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static BOOL write_directory_entry(const WCHAR *directory, const WCHAR *location)
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_TRACE("(%s,%s)\n", wine_dbgstr_w(directory), wine_dbgstr_w(location));
|
2008-11-11 20:39:56 +01:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
file = _wfopen( location, L"wb" );
|
2008-11-11 20:39:56 +01:00
|
|
|
if (file == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fprintf(file, "[Desktop Entry]\n");
|
|
|
|
fprintf(file, "Type=Directory\n");
|
2021-10-01 11:09:28 +02:00
|
|
|
if (wcscmp(directory, L"wine") == 0)
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
|
|
|
fprintf(file, "Name=Wine\n");
|
|
|
|
fprintf(file, "Icon=wine\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
fprintf(file, "Name=%s\n", wchars_to_utf8_chars(directory));
|
2008-11-11 20:39:56 +01:00
|
|
|
fprintf(file, "Icon=folder\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
static BOOL write_menu_file(const WCHAR *windows_link, const WCHAR *link)
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WCHAR tempfilename[MAX_PATH];
|
2008-11-11 20:39:56 +01:00
|
|
|
FILE *tempfile = NULL;
|
2021-10-01 10:29:44 +02:00
|
|
|
WCHAR *filename, *lastEntry, *menuPath;
|
2008-11-11 20:39:56 +01:00
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_TRACE("(%s)\n", wine_dbgstr_w(link));
|
2008-11-11 20:39:56 +01:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
GetTempFileNameW( xdg_menu_dir, L"mnu", 0, tempfilename );
|
2021-10-01 10:46:39 +02:00
|
|
|
if (!(tempfile = _wfopen( tempfilename, L"wb" ))) return FALSE;
|
2008-11-11 20:39:56 +01:00
|
|
|
|
|
|
|
fprintf(tempfile, "<!DOCTYPE Menu PUBLIC \"-//freedesktop//DTD Menu 1.0//EN\"\n");
|
|
|
|
fprintf(tempfile, "\"http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd\">\n");
|
|
|
|
fprintf(tempfile, "<Menu>\n");
|
|
|
|
fprintf(tempfile, " <Name>Applications</Name>\n");
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
filename = heap_wprintf(L"wine\\%s.desktop", link);
|
2021-10-01 10:29:44 +02:00
|
|
|
lastEntry = filename;
|
2008-11-11 20:39:56 +01:00
|
|
|
for (i = 0; filename[i]; i++)
|
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
if (filename[i] == '\\')
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WCHAR *dir_file_name;
|
|
|
|
const char *prefix = count ? "" : "wine-";
|
|
|
|
|
|
|
|
filename[i] = 0;
|
2008-11-11 20:39:56 +01:00
|
|
|
fprintf(tempfile, " <Menu>\n");
|
2021-10-01 10:29:44 +02:00
|
|
|
fprintf(tempfile, " <Name>%s%s</Name>\n",
|
|
|
|
prefix, wchars_to_xml_text(filename));
|
|
|
|
fprintf(tempfile, " <Directory>%s%s.directory</Directory>\n",
|
|
|
|
prefix, wchars_to_xml_text(filename));
|
2021-10-01 11:09:28 +02:00
|
|
|
dir_file_name = heap_wprintf(L"%s\\desktop-directories\\%s%s.directory",
|
|
|
|
xdg_data_dir, count ? L"" : L"wine-", filename);
|
2021-10-01 10:29:44 +02:00
|
|
|
if (GetFileAttributesW( dir_file_name ) == INVALID_FILE_ATTRIBUTES)
|
2021-10-01 09:35:48 +02:00
|
|
|
write_directory_entry(lastEntry, dir_file_name);
|
|
|
|
heap_free(dir_file_name);
|
2021-10-01 10:29:44 +02:00
|
|
|
filename[i] = '-';
|
|
|
|
lastEntry = &filename[i+1];
|
2008-11-11 20:39:56 +01:00
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
2021-10-01 10:29:44 +02:00
|
|
|
filename[i] = 0;
|
2008-11-11 20:39:56 +01:00
|
|
|
|
|
|
|
fprintf(tempfile, " <Include>\n");
|
2021-10-01 10:29:44 +02:00
|
|
|
fprintf(tempfile, " <Filename>%s</Filename>\n", wchars_to_xml_text(filename));
|
2008-11-11 20:39:56 +01:00
|
|
|
fprintf(tempfile, " </Include>\n");
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
fprintf(tempfile, " </Menu>\n");
|
|
|
|
fprintf(tempfile, "</Menu>\n");
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
menuPath = heap_wprintf(L"%s\\%s", xdg_menu_dir, filename);
|
|
|
|
lstrcpyW(menuPath + lstrlenW(menuPath) - lstrlenW(L".desktop"), L".menu");
|
2008-11-11 20:39:56 +01:00
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
fclose(tempfile);
|
|
|
|
ret = MoveFileExW( tempfilename, menuPath, MOVEFILE_REPLACE_EXISTING );
|
2009-06-18 07:13:02 +02:00
|
|
|
if (ret)
|
2021-10-01 10:29:44 +02:00
|
|
|
register_menus_entry(menuPath, windows_link);
|
|
|
|
else
|
|
|
|
DeleteFileW( tempfilename );
|
|
|
|
heap_free(filename);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(menuPath);
|
2008-11-11 20:39:56 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:57 +02:00
|
|
|
static BOOL write_menu_entry(const WCHAR *windows_link, const WCHAR *link, const WCHAR *path, const WCHAR *args,
|
|
|
|
const WCHAR *descr, const WCHAR *workdir, const WCHAR *icon, const WCHAR *wmclass)
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WCHAR *desktopPath;
|
|
|
|
WCHAR *desktopDir;
|
|
|
|
WCHAR *filename = NULL;
|
2008-11-11 20:39:56 +01:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
2021-10-01 10:25:57 +02:00
|
|
|
WINE_TRACE("(%s, %s, %s, %s, %s, %s, %s, %s)\n", wine_dbgstr_w(windows_link), wine_dbgstr_w(link),
|
|
|
|
wine_dbgstr_w(path), wine_dbgstr_w(args), wine_dbgstr_w(descr),
|
|
|
|
wine_dbgstr_w(workdir), wine_dbgstr_w(icon), wine_dbgstr_w(wmclass));
|
2008-11-11 20:39:56 +01:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
desktopPath = heap_wprintf(L"%s\\applications\\wine\\%s.desktop", xdg_data_dir, link);
|
2021-10-01 10:46:39 +02:00
|
|
|
desktopDir = wcsrchr(desktopPath, '\\');
|
2008-11-11 20:39:56 +01:00
|
|
|
*desktopDir = 0;
|
2021-10-01 10:30:40 +02:00
|
|
|
if (!create_directories(desktopPath))
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_WARN("couldn't make parent directories for %s\n", wine_dbgstr_w(desktopPath));
|
2008-11-11 20:39:56 +01:00
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
2021-10-01 10:29:44 +02:00
|
|
|
*desktopDir = '\\';
|
2021-10-01 10:25:57 +02:00
|
|
|
if (!write_desktop_entry(windows_link, desktopPath, link, path, args, descr, workdir, icon, wmclass))
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_WARN("couldn't make desktop entry %s\n", wine_dbgstr_w(desktopPath));
|
2008-11-11 20:39:56 +01:00
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:29:44 +02:00
|
|
|
if (!write_menu_file(windows_link, link))
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_WARN("couldn't make menu file %s\n", wine_dbgstr_w(filename));
|
2008-11-11 20:39:56 +01:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(desktopPath);
|
|
|
|
heap_free(filename);
|
2008-11-11 20:39:56 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/***********************************************************************
|
2021-10-01 10:25:57 +02:00
|
|
|
* get_link_location
|
2003-05-21 20:50:53 +02:00
|
|
|
*
|
|
|
|
* returns TRUE if successful
|
2005-12-19 21:25:52 +01:00
|
|
|
* *loc will contain CS_DESKTOPDIRECTORY, CS_STARTMENU, CS_STARTUP etc.
|
|
|
|
* *relative will contain the address of a heap-allocated copy of the portion
|
|
|
|
* of the filename that is within the specified location, in unix form
|
2003-05-21 20:50:53 +02:00
|
|
|
*/
|
2021-10-01 10:25:57 +02:00
|
|
|
static BOOL get_link_location( LPCWSTR linkfile, DWORD *loc, WCHAR **relative )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2008-01-06 19:09:24 +01:00
|
|
|
WCHAR filename[MAX_PATH], shortfilename[MAX_PATH], buffer[MAX_PATH];
|
2021-10-01 10:25:57 +02:00
|
|
|
DWORD len, i, filelen;
|
2003-05-21 20:50:53 +02:00
|
|
|
const DWORD locations[] = {
|
2004-09-21 22:08:10 +02:00
|
|
|
CSIDL_STARTUP, CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU,
|
|
|
|
CSIDL_COMMON_STARTUP, CSIDL_COMMON_DESKTOPDIRECTORY,
|
|
|
|
CSIDL_COMMON_STARTMENU };
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2004-08-30 21:28:59 +02:00
|
|
|
WINE_TRACE("%s\n", wine_dbgstr_w(linkfile));
|
2008-01-06 19:09:24 +01:00
|
|
|
filelen=GetFullPathNameW( linkfile, MAX_PATH, shortfilename, NULL );
|
|
|
|
if (filelen==0 || filelen>MAX_PATH)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
WINE_TRACE("%s\n", wine_dbgstr_w(shortfilename));
|
|
|
|
|
|
|
|
/* the CSLU Toolkit uses a short path name when creating .lnk files;
|
|
|
|
* expand or our hardcoded list won't match.
|
|
|
|
*/
|
|
|
|
filelen=GetLongPathNameW(shortfilename, filename, MAX_PATH);
|
2004-08-30 21:28:59 +02:00
|
|
|
if (filelen==0 || filelen>MAX_PATH)
|
2003-05-21 20:50:53 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("%s\n", wine_dbgstr_w(filename));
|
|
|
|
|
2018-08-10 12:27:54 +02:00
|
|
|
for( i=0; i<ARRAY_SIZE( locations ); i++ )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
if (!SHGetSpecialFolderPathW( 0, buffer, locations[i], FALSE ))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = lstrlenW(buffer);
|
2004-08-30 21:28:59 +02:00
|
|
|
if (len >= MAX_PATH)
|
2005-12-19 21:25:52 +01:00
|
|
|
continue; /* We've just trashed memory! Hopefully we are OK */
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2004-08-30 21:28:59 +02:00
|
|
|
if (len > filelen || filename[len]!='\\')
|
|
|
|
continue;
|
2021-10-01 10:46:39 +02:00
|
|
|
if (wcsnicmp( filename, buffer, len )) continue;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
/* return the remainder of the string and link type */
|
|
|
|
*loc = locations[i];
|
2021-10-01 10:25:57 +02:00
|
|
|
*relative = xwcsdup( filename + len + 1 );
|
|
|
|
PathRemoveExtensionW( *relative );
|
|
|
|
return TRUE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-08 11:55:25 +01:00
|
|
|
/* gets the target path directly or through MSI */
|
2005-11-10 12:36:26 +01:00
|
|
|
static HRESULT get_cmdline( IShellLinkW *sl, LPWSTR szPath, DWORD pathSize,
|
|
|
|
LPWSTR szArgs, DWORD argsSize)
|
2005-11-08 11:55:25 +01:00
|
|
|
{
|
|
|
|
IShellLinkDataList *dl = NULL;
|
|
|
|
EXP_DARWIN_LINK *dar = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
szPath[0] = 0;
|
2005-11-10 12:36:26 +01:00
|
|
|
szArgs[0] = 0;
|
|
|
|
|
|
|
|
hr = IShellLinkW_GetPath( sl, szPath, pathSize, NULL, SLGP_RAWPATH );
|
2005-11-08 11:55:25 +01:00
|
|
|
if (hr == S_OK && szPath[0])
|
2005-11-10 12:36:26 +01:00
|
|
|
{
|
|
|
|
IShellLinkW_GetArguments( sl, szArgs, argsSize );
|
2005-11-08 11:55:25 +01:00
|
|
|
return hr;
|
2005-11-10 12:36:26 +01:00
|
|
|
}
|
2005-11-08 11:55:25 +01:00
|
|
|
|
|
|
|
hr = IShellLinkW_QueryInterface( sl, &IID_IShellLinkDataList, (LPVOID*) &dl );
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2005-11-10 12:36:26 +01:00
|
|
|
WCHAR* szCmdline;
|
|
|
|
DWORD cmdSize;
|
|
|
|
|
|
|
|
cmdSize=0;
|
|
|
|
hr = CommandLineFromMsiDescriptor( dar->szwDarwinID, NULL, &cmdSize );
|
|
|
|
if (hr == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
cmdSize++;
|
2021-10-01 09:35:48 +02:00
|
|
|
szCmdline = xmalloc(cmdSize*sizeof(WCHAR) );
|
2005-11-10 12:36:26 +01:00
|
|
|
hr = CommandLineFromMsiDescriptor( dar->szwDarwinID, szCmdline, &cmdSize );
|
|
|
|
WINE_TRACE(" command : %s\n", wine_dbgstr_w(szCmdline));
|
|
|
|
if (hr == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR *s, *d;
|
2014-02-28 18:56:54 +01:00
|
|
|
int bcount = 0;
|
|
|
|
BOOL in_quotes = FALSE;
|
2005-11-10 12:36:26 +01:00
|
|
|
|
|
|
|
/* Extract the application path */
|
|
|
|
s=szCmdline;
|
|
|
|
d=szPath;
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
if ((*s==0x0009 || *s==0x0020) && !in_quotes)
|
|
|
|
{
|
|
|
|
/* skip the remaining spaces */
|
|
|
|
do {
|
|
|
|
s++;
|
|
|
|
} while (*s==0x0009 || *s==0x0020);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (*s==0x005c)
|
|
|
|
{
|
|
|
|
/* '\\' */
|
|
|
|
*d++=*s++;
|
|
|
|
bcount++;
|
|
|
|
}
|
|
|
|
else if (*s==0x0022)
|
|
|
|
{
|
|
|
|
/* '"' */
|
|
|
|
if ((bcount & 1)==0)
|
|
|
|
{
|
|
|
|
/* Preceded by an even number of '\', this is
|
|
|
|
* half that number of '\', plus a quote which
|
|
|
|
* we erase.
|
|
|
|
*/
|
|
|
|
d-=bcount/2;
|
|
|
|
in_quotes=!in_quotes;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Preceded by an odd number of '\', this is
|
|
|
|
* half that number of '\' followed by a '"'
|
|
|
|
*/
|
|
|
|
d=d-bcount/2-1;
|
|
|
|
*d++='"';
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* a regular character */
|
|
|
|
*d++=*s++;
|
|
|
|
bcount=0;
|
|
|
|
}
|
|
|
|
if ((d-szPath) == pathSize)
|
|
|
|
{
|
|
|
|
/* Keep processing the path till we get to the
|
|
|
|
* arguments, but 'stand still'
|
|
|
|
*/
|
|
|
|
d--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Close the application path */
|
|
|
|
*d=0;
|
|
|
|
|
|
|
|
lstrcpynW(szArgs, s, argsSize);
|
|
|
|
}
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(szCmdline );
|
2005-11-10 12:36:26 +01:00
|
|
|
}
|
2005-11-08 11:55:25 +01:00
|
|
|
LocalFree( dar );
|
|
|
|
}
|
|
|
|
|
|
|
|
IShellLinkDataList_Release( dl );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static WCHAR *slashes_to_minuses(const WCHAR *string)
|
2009-06-07 18:32:07 +02:00
|
|
|
{
|
|
|
|
int i;
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *ret = xwcsdup(string);
|
2021-10-01 09:35:48 +02:00
|
|
|
|
|
|
|
for (i = 0; ret[i]; i++) if (ret[i] == '/') ret[i] = '-';
|
|
|
|
return ret;
|
2009-06-07 18:32:07 +02:00
|
|
|
}
|
|
|
|
|
2009-04-11 10:10:59 +02:00
|
|
|
static BOOL next_line(FILE *file, char **line, int *size)
|
|
|
|
{
|
|
|
|
int pos = 0;
|
|
|
|
char *cr;
|
|
|
|
if (*line == NULL)
|
|
|
|
{
|
|
|
|
*size = 4096;
|
2021-10-01 09:35:48 +02:00
|
|
|
*line = xmalloc(*size);
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
while (*line != NULL)
|
|
|
|
{
|
|
|
|
if (fgets(&(*line)[pos], *size - pos, file) == NULL)
|
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(*line);
|
2009-04-11 10:10:59 +02:00
|
|
|
*line = NULL;
|
|
|
|
if (feof(file))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pos = strlen(*line);
|
|
|
|
cr = strchr(*line, '\n');
|
|
|
|
if (cr == NULL)
|
|
|
|
{
|
|
|
|
(*size) *= 2;
|
2021-10-01 09:35:48 +02:00
|
|
|
*line = xrealloc(*line, *size);
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*cr = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
static BOOL add_mimes(const WCHAR *dir, struct list *mime_types)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2021-10-01 10:30:40 +02:00
|
|
|
WCHAR *globs_filename;
|
2009-04-11 10:10:59 +02:00
|
|
|
BOOL ret = TRUE;
|
2021-10-01 09:35:48 +02:00
|
|
|
FILE *globs_file;
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
globs_filename = heap_wprintf(L"%s\\mime\\globs", dir);
|
2021-10-01 10:46:39 +02:00
|
|
|
globs_file = _wfopen( globs_filename, L"r" );
|
2021-10-01 09:35:48 +02:00
|
|
|
if (globs_file) /* doesn't have to exist */
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
char *line = NULL;
|
|
|
|
int size = 0;
|
|
|
|
while (ret && (ret = next_line(globs_file, &line, &size)) && line)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2021-10-01 09:36:17 +02:00
|
|
|
char *pos;
|
2021-10-01 09:35:48 +02:00
|
|
|
struct xdg_mime_type *mime_type_entry = NULL;
|
|
|
|
if (line[0] != '#' && (pos = strchr(line, ':')))
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
mime_type_entry = xmalloc(sizeof(struct xdg_mime_type));
|
|
|
|
*pos = 0;
|
2021-10-01 10:25:27 +02:00
|
|
|
mime_type_entry->mimeType = utf8_chars_to_wchars(line);
|
|
|
|
mime_type_entry->glob = utf8_chars_to_wchars(pos + 1);
|
2021-10-01 09:35:48 +02:00
|
|
|
list_add_tail(mime_types, &mime_type_entry->entry);
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(line);
|
|
|
|
fclose(globs_file);
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(globs_filename);
|
2009-04-11 10:10:59 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_native_mime_types(struct list *native_mime_types)
|
|
|
|
{
|
|
|
|
struct xdg_mime_type *mime_type_entry, *mime_type_entry2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(mime_type_entry, mime_type_entry2, native_mime_types, struct xdg_mime_type, entry)
|
|
|
|
{
|
|
|
|
list_remove(&mime_type_entry->entry);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(mime_type_entry->glob);
|
|
|
|
heap_free(mime_type_entry->mimeType);
|
|
|
|
heap_free(mime_type_entry);
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
static BOOL build_native_mime_types(struct list *mime_types)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2021-10-01 10:46:39 +02:00
|
|
|
WCHAR *dirs, *dir, *dos_name, *ctx, *p;
|
2009-04-11 10:10:59 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
if (_wgetenv( L"XDG_DATA_DIRS" ))
|
|
|
|
dirs = xwcsdup( _wgetenv( L"XDG_DATA_DIRS" ));
|
2009-04-11 10:10:59 +02:00
|
|
|
else
|
2021-10-01 10:46:39 +02:00
|
|
|
dirs = xwcsdup( L"/usr/local/share/:/usr/share/" );
|
2009-04-11 10:10:59 +02:00
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
ret = add_mimes(xdg_data_dir, mime_types);
|
2021-10-01 09:35:48 +02:00
|
|
|
if (ret)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2021-10-01 10:46:39 +02:00
|
|
|
for (dir = wcstok( dirs, L":", &ctx ); dir; dir = wcstok( NULL, L":", &ctx ))
|
2021-10-01 10:30:40 +02:00
|
|
|
{
|
2021-10-01 10:46:39 +02:00
|
|
|
dos_name = heap_wprintf( L"\\\\?\\unix%s", dir );
|
|
|
|
for (p = dos_name; *p; p++) if (*p == '/') *p = '\\';
|
|
|
|
if (p > dos_name + 9 && p[-1] == '\\') p[-1] = 0;
|
2021-10-01 10:30:40 +02:00
|
|
|
ret = add_mimes(dos_name, mime_types);
|
|
|
|
heap_free( dos_name );
|
2021-10-01 10:46:39 +02:00
|
|
|
if (!ret)
|
|
|
|
break;
|
2021-10-01 10:30:40 +02:00
|
|
|
}
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
2021-10-01 10:46:39 +02:00
|
|
|
heap_free(dirs);
|
2021-10-01 09:35:48 +02:00
|
|
|
|
2015-12-21 23:23:29 +01:00
|
|
|
if (!ret)
|
|
|
|
free_native_mime_types(mime_types);
|
2009-04-11 10:10:59 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-04 07:51:22 +02:00
|
|
|
static WCHAR *freedesktop_mime_type_for_extension(struct list *native_mime_types,
|
|
|
|
const WCHAR *extensionW)
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
|
|
|
struct xdg_mime_type *mime_type_entry;
|
|
|
|
int matchLength = 0;
|
2021-10-04 07:51:22 +02:00
|
|
|
const WCHAR* match = NULL;
|
2009-05-27 19:07:32 +02:00
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(mime_type_entry, native_mime_types, struct xdg_mime_type, entry)
|
|
|
|
{
|
2021-10-01 10:25:27 +02:00
|
|
|
if (PathMatchSpecW( extensionW, mime_type_entry->glob ))
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2021-10-04 07:51:22 +02:00
|
|
|
if (match == NULL || matchLength < lstrlenW(mime_type_entry->glob))
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2021-10-04 07:51:22 +02:00
|
|
|
match = mime_type_entry->mimeType;
|
2021-10-01 10:46:39 +02:00
|
|
|
matchLength = lstrlenW(mime_type_entry->glob);
|
2009-05-27 19:07:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 07:51:22 +02:00
|
|
|
return match ? xwcsdup(match) : NULL;
|
2009-05-27 19:07:32 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 07:20:36 +02:00
|
|
|
static WCHAR *reg_enum_keyW(HKEY key, DWORD index)
|
|
|
|
{
|
|
|
|
WCHAR *subkey;
|
|
|
|
DWORD size = 1024 * sizeof(WCHAR);
|
|
|
|
LSTATUS ret;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
subkey = xmalloc(size);
|
|
|
|
ret = RegEnumKeyExW(key, index, subkey, &size, NULL, NULL, NULL, NULL);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
return subkey;
|
|
|
|
}
|
|
|
|
if (ret != ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
heap_free(subkey);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
size *= 2;
|
|
|
|
heap_free(subkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-04 21:40:34 +02:00
|
|
|
static WCHAR* reg_get_valW(HKEY key, LPCWSTR subkey, LPCWSTR name)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
|
|
|
DWORD size;
|
2010-05-04 21:40:34 +02:00
|
|
|
if (RegGetValueW(key, subkey, name, RRF_RT_REG_SZ, NULL, NULL, &size) == ERROR_SUCCESS)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
WCHAR *ret = xmalloc(size);
|
|
|
|
if (RegGetValueW(key, subkey, name, RRF_RT_REG_SZ, NULL, ret, &size) == ERROR_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
heap_free(ret);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HKEY open_associations_reg_key(void)
|
|
|
|
{
|
|
|
|
HKEY assocKey;
|
2021-10-01 11:09:28 +02:00
|
|
|
if (RegCreateKeyW(HKEY_CURRENT_USER, L"Software\\Wine\\FileOpenAssociations", &assocKey) == ERROR_SUCCESS)
|
2009-06-04 21:57:45 +02:00
|
|
|
return assocKey;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static BOOL has_association_changed(LPCWSTR extensionW, const WCHAR *mimeType, const WCHAR *progId,
|
|
|
|
const WCHAR *appName, const WCHAR *openWithIcon)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
|
|
|
HKEY assocKey;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
WCHAR *value;
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
value = reg_get_valW(assocKey, extensionW, L"MimeType");
|
2021-10-01 10:46:39 +02:00
|
|
|
if (!value || wcscmp(value, mimeType))
|
2009-06-04 21:57:45 +02:00
|
|
|
ret = TRUE;
|
2021-10-01 10:25:27 +02:00
|
|
|
heap_free(value);
|
2009-06-04 21:57:45 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
value = reg_get_valW(assocKey, extensionW, L"ProgID");
|
2021-10-01 10:46:39 +02:00
|
|
|
if (!value || wcscmp(value, progId))
|
2009-06-04 21:57:45 +02:00
|
|
|
ret = TRUE;
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(value);
|
2009-06-04 21:57:45 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
value = reg_get_valW(assocKey, extensionW, L"AppName");
|
2021-10-01 10:46:39 +02:00
|
|
|
if (!value || wcscmp(value, appName))
|
2009-06-04 21:57:45 +02:00
|
|
|
ret = TRUE;
|
2021-10-01 10:25:27 +02:00
|
|
|
heap_free(value);
|
2009-06-04 21:57:45 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
value = reg_get_valW(assocKey, extensionW, L"OpenWithIcon");
|
2021-10-01 10:25:27 +02:00
|
|
|
if ((openWithIcon && !value) ||
|
|
|
|
(!openWithIcon && value) ||
|
2021-10-01 10:46:39 +02:00
|
|
|
(openWithIcon && value && wcscmp(value, openWithIcon)))
|
2010-11-17 11:12:08 +01:00
|
|
|
ret = TRUE;
|
2021-10-01 10:25:27 +02:00
|
|
|
heap_free(value);
|
2010-11-17 11:12:08 +01:00
|
|
|
|
2009-06-04 21:57:45 +02:00
|
|
|
RegCloseKey(assocKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_ERR("error opening associations registry key\n");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static void update_association(LPCWSTR extension, const WCHAR *mimeType, const WCHAR *progId,
|
2021-10-01 10:30:40 +02:00
|
|
|
const WCHAR *appName, const WCHAR *desktopFile, const WCHAR *openWithIcon)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
HKEY assocKey = NULL;
|
|
|
|
HKEY subkey = NULL;
|
|
|
|
|
|
|
|
assocKey = open_associations_reg_key();
|
|
|
|
if (assocKey == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("could not open file associations key\n");
|
|
|
|
goto done;
|
|
|
|
}
|
2009-06-04 21:57:45 +02:00
|
|
|
|
2010-05-04 21:40:34 +02:00
|
|
|
if (RegCreateKeyW(assocKey, extension, &subkey) != ERROR_SUCCESS)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
WINE_ERR("could not create extension subkey\n");
|
|
|
|
goto done;
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
2010-05-04 21:40:34 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
RegSetValueExW(subkey, L"MimeType", 0, REG_SZ, (const BYTE*) mimeType, (lstrlenW(mimeType) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExW(subkey, L"ProgID", 0, REG_SZ, (const BYTE*) progId, (lstrlenW(progId) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExW(subkey, L"AppName", 0, REG_SZ, (const BYTE*) appName, (lstrlenW(appName) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExW(subkey, L"DesktopFile", 0, REG_SZ, (const BYTE*) desktopFile, (lstrlenW(desktopFile) + 1) * sizeof(WCHAR));
|
2010-11-17 11:12:08 +01:00
|
|
|
if (openWithIcon)
|
2021-10-01 11:09:28 +02:00
|
|
|
RegSetValueExW(subkey, L"OpenWithIcon", 0, REG_SZ, (const BYTE*) openWithIcon, (lstrlenW(openWithIcon) + 1) * sizeof(WCHAR));
|
2010-11-17 11:12:08 +01:00
|
|
|
else
|
2021-10-01 11:09:28 +02:00
|
|
|
RegDeleteValueW(subkey, L"OpenWithIcon");
|
2010-05-04 21:40:34 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
RegCloseKey(assocKey);
|
|
|
|
RegCloseKey(subkey);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL cleanup_associations(void)
|
|
|
|
{
|
|
|
|
HKEY assocKey;
|
|
|
|
BOOL hasChanged = FALSE;
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
2021-10-13 07:20:36 +02:00
|
|
|
int i = 0;
|
|
|
|
for (;;)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
2021-10-13 07:20:36 +02:00
|
|
|
WCHAR *extensionW;
|
|
|
|
WCHAR *command;
|
2009-06-04 21:57:45 +02:00
|
|
|
|
2021-10-13 07:20:36 +02:00
|
|
|
if (!(extensionW = reg_enum_keyW(assocKey, i)))
|
|
|
|
break;
|
2009-06-04 21:57:45 +02:00
|
|
|
|
2021-10-13 07:20:36 +02:00
|
|
|
if (!(command = assoc_query(ASSOCSTR_COMMAND, extensionW, L"open")))
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
2021-10-13 07:20:36 +02:00
|
|
|
WCHAR *desktopFile = reg_get_valW(assocKey, extensionW, L"DesktopFile");
|
|
|
|
if (desktopFile)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
2021-10-13 07:20:36 +02:00
|
|
|
WINE_TRACE("removing file type association for %s\n", wine_dbgstr_w(extensionW));
|
|
|
|
DeleteFileW(desktopFile);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
2021-10-13 07:20:36 +02:00
|
|
|
RegDeleteKeyW(assocKey, extensionW);
|
|
|
|
hasChanged = TRUE;
|
|
|
|
heap_free(desktopFile);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-13 07:20:36 +02:00
|
|
|
i++;
|
|
|
|
heap_free(command);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(extensionW);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
RegCloseKey(assocKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("could not open file associations key\n");
|
|
|
|
return hasChanged;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
static BOOL write_freedesktop_mime_type_entry(const WCHAR *packages_dir, const WCHAR *dot_extension,
|
2021-10-01 10:25:27 +02:00
|
|
|
const WCHAR *mime_type, const WCHAR *comment)
|
2009-05-19 21:40:41 +02:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
2021-10-01 10:30:40 +02:00
|
|
|
WCHAR *filename;
|
2021-10-01 09:35:48 +02:00
|
|
|
FILE *packageFile;
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
WINE_TRACE("writing MIME type %s, extension=%s, comment=%s\n", wine_dbgstr_w(mime_type),
|
|
|
|
wine_dbgstr_w(dot_extension), wine_dbgstr_w(comment));
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
filename = heap_wprintf(L"%s\\x-wine-extension-%s.xml", packages_dir, dot_extension + 1);
|
2021-10-01 10:46:39 +02:00
|
|
|
packageFile = _wfopen( filename, L"wb" );
|
2021-10-01 09:35:48 +02:00
|
|
|
if (packageFile)
|
|
|
|
{
|
|
|
|
fprintf(packageFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
|
|
|
fprintf(packageFile, "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n");
|
2021-10-01 10:29:44 +02:00
|
|
|
fprintf(packageFile, " <mime-type type=\"%s\">\n", wchars_to_xml_text(mime_type));
|
|
|
|
fprintf(packageFile, " <glob pattern=\"*%s\"/>\n", wchars_to_xml_text(dot_extension));
|
|
|
|
if (comment) fprintf(packageFile, " <comment>%s</comment>\n", wchars_to_xml_text(comment));
|
2021-10-01 09:35:48 +02:00
|
|
|
fprintf(packageFile, " </mime-type>\n");
|
|
|
|
fprintf(packageFile, "</mime-info>\n");
|
|
|
|
ret = TRUE;
|
|
|
|
fclose(packageFile);
|
2009-05-19 21:40:41 +02:00
|
|
|
}
|
|
|
|
else
|
2021-10-01 10:30:40 +02:00
|
|
|
WINE_ERR("error writing file %s\n", debugstr_w(filename));
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(filename);
|
2009-05-19 21:40:41 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-17 13:33:20 +02:00
|
|
|
static BOOL is_extension_banned(LPCWSTR extension)
|
2009-06-02 19:15:58 +02:00
|
|
|
{
|
|
|
|
/* These are managed through external tools like wine.desktop, to evade malware created file type associations */
|
2021-10-01 11:09:28 +02:00
|
|
|
if (!wcsicmp(extension, L".com") ||
|
|
|
|
!wcsicmp(extension, L".exe") ||
|
|
|
|
!wcsicmp(extension, L".msi"))
|
2009-06-02 19:15:58 +02:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
static WCHAR *get_special_mime_type(LPCWSTR extension)
|
2010-05-18 21:33:03 +02:00
|
|
|
{
|
2021-10-01 11:09:28 +02:00
|
|
|
if (!wcsicmp(extension, L".lnk"))
|
|
|
|
return xwcsdup(L"application/x-ms-shortcut");
|
2010-05-18 21:33:03 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
static BOOL write_freedesktop_association_entry(const WCHAR *desktopPath, const WCHAR *friendlyAppName,
|
2021-10-01 10:25:27 +02:00
|
|
|
const WCHAR *mimeType, const WCHAR *progId,
|
|
|
|
const WCHAR *openWithIcon)
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
FILE *desktop;
|
2021-10-01 10:46:39 +02:00
|
|
|
const WCHAR *prefix = _wgetenv( L"WINECONFIGDIR" );
|
2009-06-03 18:33:28 +02:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
WINE_TRACE("friendlyAppName=%s, MIME type %s, progID=%s, icon=%s to file %s\n",
|
|
|
|
wine_dbgstr_w(friendlyAppName), wine_dbgstr_w(mimeType),
|
2021-10-01 10:30:40 +02:00
|
|
|
wine_dbgstr_w(progId), wine_dbgstr_w(openWithIcon), wine_dbgstr_w(desktopPath));
|
2009-06-03 18:33:28 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
desktop = _wfopen( desktopPath, L"wb" );
|
2009-06-03 18:33:28 +02:00
|
|
|
if (desktop)
|
|
|
|
{
|
|
|
|
fprintf(desktop, "[Desktop Entry]\n");
|
|
|
|
fprintf(desktop, "Type=Application\n");
|
2021-10-01 10:25:27 +02:00
|
|
|
fprintf(desktop, "Name=%s\n", wchars_to_utf8_chars(friendlyAppName));
|
|
|
|
fprintf(desktop, "MimeType=%s;\n", wchars_to_utf8_chars(mimeType));
|
2020-04-17 12:46:06 +02:00
|
|
|
if (prefix)
|
2021-10-01 10:46:39 +02:00
|
|
|
{
|
|
|
|
char *path = wine_get_unix_file_name( prefix );
|
|
|
|
fprintf(desktop, "Exec=env WINEPREFIX=\"%s\" wine start /ProgIDOpen %s %%f\n", path, escape(progId));
|
|
|
|
heap_free( path );
|
|
|
|
}
|
2020-04-17 12:46:06 +02:00
|
|
|
else
|
2021-10-01 10:25:27 +02:00
|
|
|
fprintf(desktop, "Exec=wine start /ProgIDOpen %s %%f\n", escape(progId));
|
2009-06-03 18:33:28 +02:00
|
|
|
fprintf(desktop, "NoDisplay=true\n");
|
|
|
|
fprintf(desktop, "StartupNotify=true\n");
|
2010-11-17 11:12:08 +01:00
|
|
|
if (openWithIcon)
|
2021-10-01 10:25:27 +02:00
|
|
|
fprintf(desktop, "Icon=%s\n", wchars_to_utf8_chars(openWithIcon));
|
2009-06-03 18:33:28 +02:00
|
|
|
ret = TRUE;
|
|
|
|
fclose(desktop);
|
|
|
|
}
|
|
|
|
else
|
2021-10-01 10:30:40 +02:00
|
|
|
WINE_ERR("error writing association file %s\n", wine_dbgstr_w(desktopPath));
|
2009-06-03 18:33:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
static BOOL generate_associations(const WCHAR *packages_dir, const WCHAR *applications_dir)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2016-08-30 21:30:41 +02:00
|
|
|
struct wine_rb_tree mimeProgidTree = { winemenubuilder_rb_string_compare };
|
|
|
|
struct list nativeMimeTypes = LIST_INIT(nativeMimeTypes);
|
2009-05-19 21:40:41 +02:00
|
|
|
int i;
|
|
|
|
BOOL hasChanged = FALSE;
|
2009-04-11 10:10:59 +02:00
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
if (!build_native_mime_types(&nativeMimeTypes))
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("could not build native MIME types\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-05-19 21:40:41 +02:00
|
|
|
|
|
|
|
for (i = 0; ; i++)
|
|
|
|
{
|
2021-10-13 07:20:36 +02:00
|
|
|
WCHAR *extensionW;
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-13 07:20:36 +02:00
|
|
|
if (!(extensionW = reg_enum_keyW(HKEY_CLASSES_ROOT, i)))
|
|
|
|
break;
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-13 07:20:36 +02:00
|
|
|
if (extensionW[0] == '.' && !is_extension_banned(extensionW))
|
2009-05-19 21:40:41 +02:00
|
|
|
{
|
|
|
|
WCHAR *commandW = NULL;
|
2010-11-17 11:12:08 +01:00
|
|
|
WCHAR *executableW = NULL;
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *openWithIcon = NULL;
|
2009-05-19 21:40:41 +02:00
|
|
|
WCHAR *friendlyDocNameW = NULL;
|
2009-06-07 18:32:07 +02:00
|
|
|
WCHAR *iconW = NULL;
|
2009-05-19 21:40:41 +02:00
|
|
|
WCHAR *contentTypeW = NULL;
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *mimeType = NULL;
|
|
|
|
const WCHAR *friendlyAppName;
|
2009-06-03 18:33:28 +02:00
|
|
|
WCHAR *progIdW = NULL;
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *mimeProgId = NULL;
|
2021-10-01 09:35:48 +02:00
|
|
|
struct rb_string_entry *entry;
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
wcslwr(extensionW);
|
2009-05-19 21:40:41 +02:00
|
|
|
friendlyDocNameW = assoc_query(ASSOCSTR_FRIENDLYDOCNAME, extensionW, NULL);
|
|
|
|
|
2009-06-07 18:32:07 +02:00
|
|
|
iconW = assoc_query(ASSOCSTR_DEFAULTICON, extensionW, NULL);
|
|
|
|
|
2009-05-19 21:40:41 +02:00
|
|
|
contentTypeW = assoc_query(ASSOCSTR_CONTENTTYPE, extensionW, NULL);
|
2010-05-14 15:35:04 +02:00
|
|
|
if (contentTypeW)
|
2021-10-01 10:46:39 +02:00
|
|
|
wcslwr(contentTypeW);
|
2009-05-27 19:07:32 +02:00
|
|
|
|
2021-10-04 07:51:22 +02:00
|
|
|
mimeType = freedesktop_mime_type_for_extension(&nativeMimeTypes, extensionW);
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
if (mimeType == NULL)
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2021-10-01 10:46:39 +02:00
|
|
|
if (contentTypeW != NULL && wcschr(contentTypeW, '/'))
|
2021-10-01 10:25:27 +02:00
|
|
|
mimeType = xwcsdup(contentTypeW);
|
|
|
|
else if (!(mimeType = get_special_mime_type(extensionW)))
|
2021-10-01 11:09:28 +02:00
|
|
|
mimeType = heap_wprintf(L"application/x-wine-extension-%s", &extensionW[1]);
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-01 09:35:48 +02:00
|
|
|
/* GNOME seems to ignore the <icon> tag in MIME packages,
|
|
|
|
* and the default name is more intuitive anyway.
|
|
|
|
*/
|
|
|
|
if (iconW)
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2021-10-01 10:25:27 +02:00
|
|
|
WCHAR *flattened_mime = slashes_to_minuses(mimeType);
|
2021-10-01 09:35:48 +02:00
|
|
|
int index = 0;
|
2021-10-01 10:46:39 +02:00
|
|
|
WCHAR *comma = wcsrchr(iconW, ',');
|
2021-10-01 09:35:48 +02:00
|
|
|
if (comma)
|
2009-06-07 18:32:07 +02:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
*comma = 0;
|
2021-10-01 10:46:39 +02:00
|
|
|
index = wcstol(comma + 1, NULL, 10);
|
2009-06-07 18:32:07 +02:00
|
|
|
}
|
2021-10-01 10:25:27 +02:00
|
|
|
extract_icon(iconW, index, flattened_mime, FALSE);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(flattened_mime);
|
2009-05-27 19:07:32 +02:00
|
|
|
}
|
2021-10-01 09:35:48 +02:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
write_freedesktop_mime_type_entry(packages_dir, extensionW, mimeType, friendlyDocNameW);
|
2021-10-01 09:35:48 +02:00
|
|
|
hasChanged = TRUE;
|
2009-05-27 19:07:32 +02:00
|
|
|
}
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
commandW = assoc_query(ASSOCSTR_COMMAND, extensionW, L"open");
|
2009-06-03 18:33:28 +02:00
|
|
|
if (commandW == NULL)
|
|
|
|
/* no command => no application is associated */
|
|
|
|
goto end;
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
executableW = assoc_query(ASSOCSTR_EXECUTABLE, extensionW, L"open");
|
2010-11-17 11:12:08 +01:00
|
|
|
if (executableW)
|
2021-10-01 10:25:27 +02:00
|
|
|
openWithIcon = compute_native_identifier(0, executableW, NULL);
|
2010-11-17 11:12:08 +01:00
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
friendlyAppName = assoc_query(ASSOCSTR_FRIENDLYAPPNAME, extensionW, L"open");
|
|
|
|
if (!friendlyAppName) friendlyAppName = L"A Wine application";
|
2009-06-03 18:33:28 +02:00
|
|
|
|
|
|
|
progIdW = reg_get_valW(HKEY_CLASSES_ROOT, extensionW, NULL);
|
2021-10-01 10:25:27 +02:00
|
|
|
if (!progIdW) goto end; /* no progID => not a file type association */
|
2009-06-03 18:33:28 +02:00
|
|
|
|
2010-11-18 10:52:10 +01:00
|
|
|
/* Do not allow duplicate ProgIDs for a MIME type, it causes unnecessary duplication in Open dialogs */
|
2021-10-01 11:09:28 +02:00
|
|
|
mimeProgId = heap_wprintf(L"%s=>%s", mimeType, progIdW);
|
2021-10-01 09:35:48 +02:00
|
|
|
if (wine_rb_get(&mimeProgidTree, mimeProgId))
|
2010-11-18 10:52:10 +01:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(mimeProgId);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
entry = xmalloc(sizeof(struct rb_string_entry));
|
|
|
|
entry->string = mimeProgId;
|
|
|
|
if (wine_rb_put(&mimeProgidTree, mimeProgId, &entry->entry))
|
|
|
|
{
|
|
|
|
WINE_ERR("error updating rb tree\n");
|
|
|
|
goto end;
|
2010-11-18 10:52:10 +01:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
if (has_association_changed(extensionW, mimeType, progIdW, friendlyAppName, openWithIcon))
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
2021-10-01 11:09:28 +02:00
|
|
|
WCHAR *desktopPath = heap_wprintf(L"%s\\wine-extension-%s.desktop",
|
|
|
|
applications_dir, extensionW + 1 );
|
2021-10-01 10:25:27 +02:00
|
|
|
if (write_freedesktop_association_entry(desktopPath, friendlyAppName, mimeType, progIdW, openWithIcon))
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
hasChanged = TRUE;
|
2021-10-01 10:25:27 +02:00
|
|
|
update_association(extensionW, mimeType, progIdW, friendlyAppName, desktopPath, openWithIcon);
|
2009-06-03 18:33:28 +02:00
|
|
|
}
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(desktopPath);
|
2009-06-03 18:33:28 +02:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
if (hasChanged && openWithIcon) extract_icon(executableW, 0, openWithIcon, FALSE);
|
2020-11-13 10:30:56 +01:00
|
|
|
|
2009-05-19 21:40:41 +02:00
|
|
|
end:
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(commandW);
|
|
|
|
heap_free(executableW);
|
2021-10-01 10:25:27 +02:00
|
|
|
heap_free(openWithIcon);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(friendlyDocNameW);
|
|
|
|
heap_free(iconW);
|
|
|
|
heap_free(contentTypeW);
|
2021-10-01 10:25:27 +02:00
|
|
|
heap_free(mimeType);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(progIdW);
|
|
|
|
}
|
|
|
|
heap_free(extensionW);
|
2009-05-19 21:40:41 +02:00
|
|
|
}
|
|
|
|
|
2010-11-18 10:52:10 +01:00
|
|
|
wine_rb_destroy(&mimeProgidTree, winemenubuilder_rb_destroy, NULL);
|
2015-12-21 23:23:29 +01:00
|
|
|
free_native_mime_types(&nativeMimeTypes);
|
2009-05-19 21:40:41 +02:00
|
|
|
return hasChanged;
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
static BOOL InvokeShellLinker( IShellLinkW *sl, LPCWSTR link, BOOL bWait )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2021-10-01 10:25:57 +02:00
|
|
|
WCHAR *icon_name, *link_name;
|
2008-01-23 18:31:06 +01:00
|
|
|
WCHAR szTmp[INFOTIPSIZE];
|
2005-02-17 12:51:44 +01:00
|
|
|
WCHAR szDescription[INFOTIPSIZE], szPath[MAX_PATH], szWorkDir[MAX_PATH];
|
2017-09-08 17:54:30 +02:00
|
|
|
WCHAR szArgs[INFOTIPSIZE], szIconPath[MAX_PATH], szWMClass[MAX_PATH];
|
2005-02-18 13:52:33 +01:00
|
|
|
int iIconId = 0, r = -1;
|
2005-02-17 12:51:44 +01:00
|
|
|
DWORD csidl = -1;
|
2007-06-28 03:23:30 +02:00
|
|
|
HANDLE hsem = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if ( !link )
|
|
|
|
{
|
|
|
|
WINE_ERR("Link name is null\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:57 +02:00
|
|
|
if( !get_link_location( link, &csidl, &link_name ) )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2007-01-18 11:40:15 +01:00
|
|
|
WINE_WARN("Unknown link location %s. Ignoring.\n",wine_dbgstr_w(link));
|
2003-05-21 20:50:53 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-09-21 22:08:10 +02:00
|
|
|
if (!in_desktop_dir(csidl) && !in_startmenu(csidl))
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
WINE_WARN("Not under desktop or start menu. Ignoring.\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
2021-10-01 10:25:57 +02:00
|
|
|
WINE_TRACE("Link : %s\n", wine_dbgstr_w(link_name));
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-01-23 18:31:06 +01:00
|
|
|
szTmp[0] = 0;
|
|
|
|
IShellLinkW_GetWorkingDirectory( sl, szTmp, MAX_PATH );
|
|
|
|
ExpandEnvironmentStringsW(szTmp, szWorkDir, MAX_PATH);
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("workdir : %s\n", wine_dbgstr_w(szWorkDir));
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-01-23 18:31:06 +01:00
|
|
|
szTmp[0] = 0;
|
|
|
|
IShellLinkW_GetDescription( sl, szTmp, INFOTIPSIZE );
|
|
|
|
ExpandEnvironmentStringsW(szTmp, szDescription, INFOTIPSIZE);
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("description: %s\n", wine_dbgstr_w(szDescription));
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-05-14 15:35:55 +02:00
|
|
|
get_cmdline( sl, szTmp, MAX_PATH, szArgs, INFOTIPSIZE);
|
|
|
|
ExpandEnvironmentStringsW(szTmp, szPath, MAX_PATH);
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("path : %s\n", wine_dbgstr_w(szPath));
|
|
|
|
WINE_TRACE("args : %s\n", wine_dbgstr_w(szArgs));
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-01-23 18:31:06 +01:00
|
|
|
szTmp[0] = 0;
|
|
|
|
IShellLinkW_GetIconLocation( sl, szTmp, MAX_PATH, &iIconId );
|
|
|
|
ExpandEnvironmentStringsW(szTmp, szIconPath, MAX_PATH);
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("icon file : %s\n", wine_dbgstr_w(szIconPath) );
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2017-09-08 17:54:30 +02:00
|
|
|
szWMClass[0] = 0;
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( !szPath[0] )
|
|
|
|
{
|
|
|
|
LPITEMIDLIST pidl = NULL;
|
2005-02-17 12:51:44 +01:00
|
|
|
IShellLinkW_GetIDList( sl, &pidl );
|
2005-09-21 11:46:28 +02:00
|
|
|
if( pidl && SHGetPathFromIDListW( pidl, szPath ) )
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("pidl path : %s\n", wine_dbgstr_w(szPath));
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* extract the icon */
|
|
|
|
if( szIconPath[0] )
|
2009-06-30 21:04:32 +02:00
|
|
|
icon_name = extract_icon( szIconPath , iIconId, NULL, bWait );
|
2003-05-21 20:50:53 +02:00
|
|
|
else
|
2009-06-30 21:04:32 +02:00
|
|
|
icon_name = extract_icon( szPath, iIconId, NULL, bWait );
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
/* fail - try once again after parent process exit */
|
2003-05-21 20:50:53 +02:00
|
|
|
if( !icon_name )
|
|
|
|
{
|
2007-06-28 03:23:33 +02:00
|
|
|
if (bWait)
|
2005-02-22 20:31:19 +01:00
|
|
|
{
|
|
|
|
WINE_WARN("Unable to extract icon, deferring.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2006-11-24 23:39:51 +01:00
|
|
|
WINE_ERR("failed to extract icon from %s\n",
|
|
|
|
wine_dbgstr_w( szIconPath[0] ? szIconPath : szPath ));
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check the path */
|
|
|
|
if( szPath[0] )
|
|
|
|
{
|
2021-10-01 10:20:15 +02:00
|
|
|
/* FIXME: Use AppUserModelID if present. */
|
|
|
|
WCHAR *p = PathFindFileNameW(szPath);
|
2005-02-18 13:52:33 +01:00
|
|
|
|
2021-10-01 10:20:15 +02:00
|
|
|
if (p)
|
2006-11-21 00:26:08 +01:00
|
|
|
{
|
2017-09-08 17:54:30 +02:00
|
|
|
lstrcpyW(szWMClass, p);
|
|
|
|
CharLowerW(szWMClass);
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
/* building multiple menus concurrently has race conditions */
|
2007-06-28 03:23:30 +02:00
|
|
|
hsem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
|
2008-04-21 20:34:30 +02:00
|
|
|
if( WAIT_OBJECT_0 != MsgWaitForMultipleObjects( 1, &hsem, FALSE, INFINITE, QS_ALLINPUT ) )
|
2007-06-28 03:23:30 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("failed wait for semaphore\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
if (in_desktop_dir(csidl))
|
|
|
|
{
|
2021-10-01 10:20:15 +02:00
|
|
|
if (csidl == CSIDL_COMMON_DESKTOPDIRECTORY || !szPath[0])
|
2021-10-01 10:25:57 +02:00
|
|
|
r = !write_desktop_entry(link, NULL, link_name, link, NULL,
|
|
|
|
szDescription, szWorkDir, icon_name, szWMClass);
|
2021-10-01 09:35:48 +02:00
|
|
|
else
|
2021-10-01 10:25:57 +02:00
|
|
|
r = !write_desktop_entry(NULL, NULL, link_name, szPath, szArgs,
|
|
|
|
szDescription, szWorkDir, icon_name, szWMClass);
|
2008-11-08 10:03:39 +01:00
|
|
|
}
|
|
|
|
else
|
2021-10-01 10:25:57 +02:00
|
|
|
r = !write_menu_entry(link, link_name, link, NULL, szDescription, szWorkDir, icon_name, szWMClass);
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2007-06-28 03:23:30 +02:00
|
|
|
ReleaseSemaphore( hsem, 1, NULL );
|
|
|
|
|
2005-02-22 20:31:19 +01:00
|
|
|
cleanup:
|
2007-06-28 03:23:30 +02:00
|
|
|
if (hsem) CloseHandle( hsem );
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(icon_name );
|
|
|
|
heap_free(link_name );
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2007-06-29 02:47:59 +02:00
|
|
|
if (r && !bWait)
|
2008-11-08 10:03:39 +01:00
|
|
|
WINE_ERR("failed to build the menu\n" );
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2007-06-29 02:47:59 +02:00
|
|
|
return ( r == 0 );
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2008-11-13 07:19:25 +01:00
|
|
|
static BOOL InvokeShellLinkerForURL( IUniformResourceLocatorW *url, LPCWSTR link, BOOL bWait )
|
|
|
|
{
|
2021-10-01 10:25:57 +02:00
|
|
|
WCHAR *link_name, *icon_name = NULL;
|
2008-11-13 07:19:25 +01:00
|
|
|
DWORD csidl = -1;
|
2013-05-30 05:30:22 +02:00
|
|
|
LPWSTR urlPath = NULL;
|
2008-11-13 07:19:25 +01:00
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hSem = NULL;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
int r = -1;
|
2010-11-25 07:34:35 +01:00
|
|
|
IPropertySetStorage *pPropSetStg;
|
|
|
|
IPropertyStorage *pPropStg;
|
|
|
|
PROPSPEC ps[2];
|
|
|
|
PROPVARIANT pv[2];
|
2012-09-19 21:48:16 +02:00
|
|
|
BOOL has_icon = FALSE;
|
2008-11-13 07:19:25 +01:00
|
|
|
|
|
|
|
if ( !link )
|
|
|
|
{
|
|
|
|
WINE_ERR("Link name is null\n");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-10-01 10:25:57 +02:00
|
|
|
if( !get_link_location( link, &csidl, &link_name ) )
|
2008-11-13 07:19:25 +01:00
|
|
|
{
|
|
|
|
WINE_WARN("Unknown link location %s. Ignoring.\n",wine_dbgstr_w(link));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (!in_desktop_dir(csidl) && !in_startmenu(csidl))
|
|
|
|
{
|
|
|
|
WINE_WARN("Not under desktop or start menu. Ignoring.\n");
|
|
|
|
ret = TRUE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2021-10-01 10:25:57 +02:00
|
|
|
WINE_TRACE("Link : %s\n", wine_dbgstr_w(link_name));
|
2008-11-13 07:19:25 +01:00
|
|
|
|
|
|
|
hr = url->lpVtbl->GetURL(url, &urlPath);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
WINE_TRACE("path : %s\n", wine_dbgstr_w(urlPath));
|
|
|
|
|
2010-11-25 07:34:35 +01:00
|
|
|
ps[0].ulKind = PRSPEC_PROPID;
|
2011-01-04 15:58:22 +01:00
|
|
|
ps[0].u.propid = PID_IS_ICONFILE;
|
2010-11-25 07:34:35 +01:00
|
|
|
ps[1].ulKind = PRSPEC_PROPID;
|
2011-01-04 15:58:22 +01:00
|
|
|
ps[1].u.propid = PID_IS_ICONINDEX;
|
2010-11-25 07:34:35 +01:00
|
|
|
|
|
|
|
hr = url->lpVtbl->QueryInterface(url, &IID_IPropertySetStorage, (void **) &pPropSetStg);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IPropertySetStorage_Open(pPropSetStg, &FMTID_Intshcut, STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IPropertyStorage_ReadMultiple(pPropStg, 2, ps, pv);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2021-03-23 00:31:22 +01:00
|
|
|
if (pv[0].vt == VT_LPWSTR && pv[0].pwszVal && pv[0].pwszVal[0])
|
2011-01-09 17:02:54 +01:00
|
|
|
{
|
2012-09-19 21:48:16 +02:00
|
|
|
has_icon = TRUE;
|
2021-03-23 00:31:22 +01:00
|
|
|
icon_name = extract_icon( pv[0].pwszVal, pv[1].iVal, NULL, bWait );
|
2010-11-25 07:34:35 +01:00
|
|
|
|
2021-10-01 10:25:27 +02:00
|
|
|
WINE_TRACE("URL icon path: %s icon index: %d icon name: %s\n", wine_dbgstr_w(pv[0].pwszVal), pv[1].iVal, debugstr_w(icon_name));
|
2011-01-09 17:02:54 +01:00
|
|
|
}
|
2010-12-08 19:20:36 +01:00
|
|
|
PropVariantClear(&pv[0]);
|
|
|
|
PropVariantClear(&pv[1]);
|
2010-11-25 07:34:35 +01:00
|
|
|
}
|
|
|
|
IPropertyStorage_Release(pPropStg);
|
|
|
|
}
|
|
|
|
IPropertySetStorage_Release(pPropSetStg);
|
|
|
|
}
|
|
|
|
|
2010-12-11 18:58:04 +01:00
|
|
|
/* fail - try once again after parent process exit */
|
2012-09-19 21:48:16 +02:00
|
|
|
if( has_icon && !icon_name )
|
2010-12-11 18:58:04 +01:00
|
|
|
{
|
|
|
|
if (bWait)
|
|
|
|
{
|
|
|
|
WINE_WARN("Unable to extract icon, deferring.\n");
|
|
|
|
ret = FALSE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
WINE_ERR("failed to extract icon from %s\n",
|
2021-03-23 00:31:22 +01:00
|
|
|
wine_dbgstr_w( pv[0].pwszVal ));
|
2010-12-11 18:58:04 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 07:19:25 +01:00
|
|
|
hSem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
|
|
|
|
if( WAIT_OBJECT_0 != MsgWaitForMultipleObjects( 1, &hSem, FALSE, INFINITE, QS_ALLINPUT ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("failed wait for semaphore\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (in_desktop_dir(csidl))
|
2021-10-01 11:09:28 +02:00
|
|
|
r = !write_desktop_entry(NULL, NULL, link_name, L"start.exe", urlPath, NULL, NULL, icon_name, NULL);
|
2008-11-13 07:19:25 +01:00
|
|
|
else
|
2021-10-01 11:09:28 +02:00
|
|
|
r = !write_menu_entry(link, link_name, L"start.exe", urlPath, NULL, NULL, icon_name, NULL);
|
2012-09-19 21:49:23 +02:00
|
|
|
ret = (r == 0);
|
2008-11-13 07:19:25 +01:00
|
|
|
ReleaseSemaphore(hSem, 1, NULL);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (hSem)
|
|
|
|
CloseHandle(hSem);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(icon_name );
|
|
|
|
heap_free(link_name);
|
2008-11-13 07:19:25 +01:00
|
|
|
CoTaskMemFree( urlPath );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
static BOOL WaitForParentProcess( void )
|
|
|
|
{
|
|
|
|
PROCESSENTRY32 procentry;
|
|
|
|
HANDLE hsnapshot = NULL, hprocess = NULL;
|
|
|
|
DWORD ourpid = GetCurrentProcessId();
|
|
|
|
BOOL ret = FALSE, rc;
|
|
|
|
|
|
|
|
WINE_TRACE("Waiting for parent process\n");
|
|
|
|
if ((hsnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 )) ==
|
|
|
|
INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("CreateToolhelp32Snapshot failed, error %ld\n", GetLastError());
|
2007-06-28 03:23:33 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
procentry.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
rc = Process32First( hsnapshot, &procentry );
|
|
|
|
while (rc)
|
|
|
|
{
|
|
|
|
if (procentry.th32ProcessID == ourpid) break;
|
|
|
|
rc = Process32Next( hsnapshot, &procentry );
|
|
|
|
}
|
|
|
|
if (!rc)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("Unable to find current process id %ld when listing processes\n", ourpid);
|
2007-06-28 03:23:33 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hprocess = OpenProcess( SYNCHRONIZE, FALSE, procentry.th32ParentProcessID )) ==
|
|
|
|
NULL)
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_WARN("OpenProcess failed pid=%ld, error %ld\n", procentry.th32ParentProcessID,
|
2007-06-28 03:23:33 +02:00
|
|
|
GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2008-04-21 20:34:30 +02:00
|
|
|
if (MsgWaitForMultipleObjects( 1, &hprocess, FALSE, INFINITE, QS_ALLINPUT ) == WAIT_OBJECT_0)
|
2007-06-28 03:23:33 +02:00
|
|
|
ret = TRUE;
|
|
|
|
else
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("Unable to wait for parent process, error %ld\n", GetLastError());
|
2007-06-28 03:23:33 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (hprocess) CloseHandle( hprocess );
|
|
|
|
if (hsnapshot) CloseHandle( hsnapshot );
|
|
|
|
return ret;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
static BOOL Process_Link( LPCWSTR linkname, BOOL bWait )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
IShellLinkW *sl;
|
2003-05-21 20:50:53 +02:00
|
|
|
IPersistFile *pf;
|
|
|
|
HRESULT r;
|
|
|
|
WCHAR fullname[MAX_PATH];
|
2004-08-30 21:28:59 +02:00
|
|
|
DWORD len;
|
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
WINE_TRACE("%s, wait %d\n", wine_dbgstr_w(linkname), bWait);
|
2005-02-16 17:04:05 +01:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
if( !linkname[0] )
|
|
|
|
{
|
|
|
|
WINE_ERR("link name missing\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2004-08-30 21:28:59 +02:00
|
|
|
len=GetFullPathNameW( linkname, MAX_PATH, fullname, NULL );
|
|
|
|
if (len==0 || len>MAX_PATH)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("couldn't get full path of link file\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
2005-02-17 12:51:44 +01:00
|
|
|
&IID_IShellLinkW, (LPVOID *) &sl );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("No IID_IShellLink\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
r = IShellLinkW_QueryInterface( sl, &IID_IPersistFile, (LPVOID*) &pf );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("No IID_IPersistFile\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r = IPersistFile_Load( pf, fullname, STGM_READ );
|
|
|
|
if( SUCCEEDED( r ) )
|
|
|
|
{
|
2005-02-16 17:04:05 +01:00
|
|
|
/* If something fails (eg. Couldn't extract icon)
|
2007-06-28 03:23:33 +02:00
|
|
|
* wait for parent process and try again
|
2003-05-21 20:50:53 +02:00
|
|
|
*/
|
2007-06-28 03:23:33 +02:00
|
|
|
if( ! InvokeShellLinker( sl, fullname, bWait ) && bWait )
|
|
|
|
{
|
|
|
|
WaitForParentProcess();
|
|
|
|
InvokeShellLinker( sl, fullname, FALSE );
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2009-03-11 17:18:17 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_ERR("unable to load %s\n", wine_dbgstr_w(linkname));
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
IPersistFile_Release( pf );
|
2005-02-17 12:51:44 +01:00
|
|
|
IShellLinkW_Release( sl );
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
return !r;
|
|
|
|
}
|
|
|
|
|
2008-11-13 07:19:25 +01:00
|
|
|
static BOOL Process_URL( LPCWSTR urlname, BOOL bWait )
|
|
|
|
{
|
|
|
|
IUniformResourceLocatorW *url;
|
|
|
|
IPersistFile *pf;
|
|
|
|
HRESULT r;
|
|
|
|
WCHAR fullname[MAX_PATH];
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
WINE_TRACE("%s, wait %d\n", wine_dbgstr_w(urlname), bWait);
|
|
|
|
|
|
|
|
if( !urlname[0] )
|
|
|
|
{
|
|
|
|
WINE_ERR("URL name missing\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2008-11-13 07:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
len=GetFullPathNameW( urlname, MAX_PATH, fullname, NULL );
|
|
|
|
if (len==0 || len>MAX_PATH)
|
|
|
|
{
|
|
|
|
WINE_ERR("couldn't get full path of URL file\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2008-11-13 07:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
r = CoCreateInstance( &CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IUniformResourceLocatorW, (LPVOID *) &url );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("No IID_IUniformResourceLocatorW\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2008-11-13 07:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
r = url->lpVtbl->QueryInterface( url, &IID_IPersistFile, (LPVOID*) &pf );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("No IID_IPersistFile\n");
|
2014-04-28 20:10:23 +02:00
|
|
|
return FALSE;
|
2008-11-13 07:19:25 +01:00
|
|
|
}
|
|
|
|
r = IPersistFile_Load( pf, fullname, STGM_READ );
|
|
|
|
if( SUCCEEDED( r ) )
|
|
|
|
{
|
|
|
|
/* If something fails (eg. Couldn't extract icon)
|
|
|
|
* wait for parent process and try again
|
|
|
|
*/
|
|
|
|
if( ! InvokeShellLinkerForURL( url, fullname, bWait ) && bWait )
|
|
|
|
{
|
|
|
|
WaitForParentProcess();
|
|
|
|
InvokeShellLinkerForURL( url, fullname, FALSE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IPersistFile_Release( pf );
|
|
|
|
url->lpVtbl->Release( url );
|
|
|
|
|
|
|
|
return !r;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2009-04-05 08:14:53 +02:00
|
|
|
static void RefreshFileTypeAssociations(void)
|
|
|
|
{
|
|
|
|
HANDLE hSem = NULL;
|
2021-10-01 10:30:40 +02:00
|
|
|
WCHAR *mime_dir;
|
|
|
|
WCHAR *packages_dir;
|
|
|
|
WCHAR *applications_dir;
|
2009-05-19 21:40:41 +02:00
|
|
|
BOOL hasChanged;
|
2009-04-05 08:14:53 +02:00
|
|
|
|
|
|
|
hSem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
|
|
|
|
if( WAIT_OBJECT_0 != MsgWaitForMultipleObjects( 1, &hSem, FALSE, INFINITE, QS_ALLINPUT ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("failed wait for semaphore\n");
|
|
|
|
CloseHandle(hSem);
|
2021-10-01 10:30:40 +02:00
|
|
|
return;
|
2009-04-05 08:14:53 +02:00
|
|
|
}
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
mime_dir = heap_wprintf(L"%s\\mime", xdg_data_dir);
|
|
|
|
packages_dir = heap_wprintf(L"%s\\packages", mime_dir);
|
2009-04-05 08:14:53 +02:00
|
|
|
create_directories(packages_dir);
|
|
|
|
|
2021-10-01 11:09:28 +02:00
|
|
|
applications_dir = heap_wprintf(L"%s\\applications", xdg_data_dir);
|
2009-04-05 08:14:53 +02:00
|
|
|
create_directories(applications_dir);
|
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
hasChanged = generate_associations(packages_dir, applications_dir);
|
2009-06-04 21:57:45 +02:00
|
|
|
hasChanged |= cleanup_associations();
|
2009-05-19 21:40:41 +02:00
|
|
|
if (hasChanged)
|
|
|
|
{
|
2009-06-30 14:27:35 +02:00
|
|
|
const char *argv[3];
|
2009-06-03 18:33:28 +02:00
|
|
|
|
2009-06-30 14:27:35 +02:00
|
|
|
argv[0] = "update-mime-database";
|
2021-10-01 10:30:40 +02:00
|
|
|
argv[1] = wine_get_unix_file_name(mime_dir);
|
2009-06-30 14:27:35 +02:00
|
|
|
argv[2] = NULL;
|
2021-10-01 10:46:39 +02:00
|
|
|
__wine_unix_spawnvp( (char **)argv, FALSE );
|
2009-06-30 14:27:35 +02:00
|
|
|
|
|
|
|
argv[0] = "update-desktop-database";
|
2021-10-01 10:30:40 +02:00
|
|
|
argv[1] = wine_get_unix_file_name(applications_dir);
|
2021-10-01 10:46:39 +02:00
|
|
|
__wine_unix_spawnvp( (char **)argv, FALSE );
|
2009-05-19 21:40:41 +02:00
|
|
|
}
|
2009-04-11 10:10:59 +02:00
|
|
|
|
2021-10-01 10:30:40 +02:00
|
|
|
ReleaseSemaphore(hSem, 1, NULL);
|
|
|
|
CloseHandle(hSem);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(mime_dir);
|
|
|
|
heap_free(packages_dir);
|
|
|
|
heap_free(applications_dir);
|
2009-04-05 08:14:53 +02:00
|
|
|
}
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
static void cleanup_menus(void)
|
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
|
|
|
|
hkey = open_menus_reg_key();
|
|
|
|
if (hkey)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
LSTATUS lret = ERROR_SUCCESS;
|
|
|
|
for (i = 0; lret == ERROR_SUCCESS; )
|
|
|
|
{
|
2010-05-03 20:58:16 +02:00
|
|
|
WCHAR *value = NULL;
|
|
|
|
WCHAR *data = NULL;
|
2009-06-18 07:13:02 +02:00
|
|
|
DWORD valueSize = 4096;
|
|
|
|
DWORD dataSize = 4096;
|
|
|
|
while (1)
|
|
|
|
{
|
2021-10-01 09:35:48 +02:00
|
|
|
value = xmalloc(valueSize * sizeof(WCHAR));
|
|
|
|
data = xmalloc(dataSize * sizeof(WCHAR));
|
2010-05-03 20:58:16 +02:00
|
|
|
lret = RegEnumValueW(hkey, i, value, &valueSize, NULL, NULL, (BYTE*)data, &dataSize);
|
2015-10-14 00:00:18 +02:00
|
|
|
if (lret != ERROR_MORE_DATA)
|
2009-06-18 07:13:02 +02:00
|
|
|
break;
|
|
|
|
valueSize *= 2;
|
|
|
|
dataSize *= 2;
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(value);
|
|
|
|
heap_free(data);
|
2009-06-18 07:13:02 +02:00
|
|
|
value = data = NULL;
|
|
|
|
}
|
|
|
|
if (lret == ERROR_SUCCESS)
|
|
|
|
{
|
2021-10-01 10:19:27 +02:00
|
|
|
if (GetFileAttributesW( data ) == INVALID_FILE_ATTRIBUTES)
|
2009-06-18 07:13:02 +02:00
|
|
|
{
|
2021-10-01 10:29:44 +02:00
|
|
|
WINE_TRACE("removing menu related file %s\n", debugstr_w(value));
|
|
|
|
DeleteFileW( value );
|
2021-10-01 09:35:48 +02:00
|
|
|
RegDeleteValueW(hkey, value);
|
2009-06-18 07:13:02 +02:00
|
|
|
}
|
|
|
|
else
|
2021-10-01 09:35:48 +02:00
|
|
|
i++;
|
2009-06-18 07:13:02 +02:00
|
|
|
}
|
|
|
|
else if (lret != ERROR_NO_MORE_ITEMS)
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("error %ld reading registry\n", lret);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(value);
|
|
|
|
heap_free(data);
|
2009-06-18 07:13:02 +02:00
|
|
|
}
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-26 06:52:38 +02:00
|
|
|
static void thumbnail_lnk(LPCWSTR lnkPath, LPCWSTR outputPath)
|
|
|
|
{
|
|
|
|
char *utf8lnkPath = NULL;
|
|
|
|
WCHAR *winLnkPath = NULL;
|
|
|
|
IShellLinkW *shellLink = NULL;
|
|
|
|
IPersistFile *persistFile = NULL;
|
|
|
|
WCHAR szTmp[MAX_PATH];
|
|
|
|
WCHAR szPath[MAX_PATH];
|
|
|
|
WCHAR szArgs[INFOTIPSIZE];
|
|
|
|
WCHAR szIconPath[MAX_PATH];
|
|
|
|
int iconId;
|
2010-08-22 19:42:18 +02:00
|
|
|
IStream *stream = NULL;
|
2015-03-16 17:44:43 +01:00
|
|
|
ICONDIRENTRY *pIconDirEntries = NULL;
|
|
|
|
int numEntries;
|
2010-07-26 06:52:38 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
utf8lnkPath = wchars_to_utf8_chars(lnkPath);
|
|
|
|
winLnkPath = wine_get_dos_file_name(utf8lnkPath);
|
|
|
|
if (winLnkPath == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("could not convert %s to DOS path\n", utf8lnkPath);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IShellLinkW, (LPVOID*)&shellLink);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("could not create IShellLinkW, error 0x%08lX\n", hr);
|
2010-07-26 06:52:38 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellLinkW_QueryInterface(shellLink, &IID_IPersistFile, (LPVOID)&persistFile);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("could not query IPersistFile, error 0x%08lX\n", hr);
|
2010-07-26 06:52:38 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPersistFile_Load(persistFile, winLnkPath, STGM_READ);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("could not read .lnk, error 0x%08lX\n", hr);
|
2010-07-26 06:52:38 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_cmdline(shellLink, szTmp, MAX_PATH, szArgs, INFOTIPSIZE);
|
|
|
|
ExpandEnvironmentStringsW(szTmp, szPath, MAX_PATH);
|
|
|
|
szTmp[0] = 0;
|
|
|
|
IShellLinkW_GetIconLocation(shellLink, szTmp, MAX_PATH, &iconId);
|
|
|
|
ExpandEnvironmentStringsW(szTmp, szIconPath, MAX_PATH);
|
|
|
|
|
|
|
|
if(!szPath[0])
|
|
|
|
{
|
|
|
|
LPITEMIDLIST pidl = NULL;
|
|
|
|
IShellLinkW_GetIDList(shellLink, &pidl);
|
|
|
|
if (pidl && SHGetPathFromIDListW(pidl, szPath))
|
|
|
|
WINE_TRACE("pidl path : %s\n", wine_dbgstr_w(szPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (szIconPath[0])
|
|
|
|
{
|
2015-03-16 17:44:43 +01:00
|
|
|
hr = open_icon(szIconPath, iconId, FALSE, &stream, &pIconDirEntries, &numEntries);
|
2010-08-22 19:42:18 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2021-10-01 10:30:28 +02:00
|
|
|
hr = write_native_icon(stream, pIconDirEntries, numEntries, outputPath);
|
2010-07-26 06:52:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-16 17:44:43 +01:00
|
|
|
hr = open_icon(szPath, iconId, FALSE, &stream, &pIconDirEntries, &numEntries);
|
2010-08-22 19:42:18 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2021-10-01 10:30:28 +02:00
|
|
|
hr = write_native_icon(stream, pIconDirEntries, numEntries, outputPath);
|
2010-07-26 06:52:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(utf8lnkPath);
|
|
|
|
heap_free(winLnkPath);
|
2010-07-26 06:52:38 +02:00
|
|
|
if (shellLink != NULL)
|
|
|
|
IShellLinkW_Release(shellLink);
|
|
|
|
if (persistFile != NULL)
|
|
|
|
IPersistFile_Release(persistFile);
|
2010-08-22 19:42:18 +02:00
|
|
|
if (stream != NULL)
|
|
|
|
IStream_Release(stream);
|
2021-10-01 09:35:48 +02:00
|
|
|
heap_free(pIconDirEntries);
|
2010-07-26 06:52:38 +02:00
|
|
|
}
|
|
|
|
|
2010-05-04 21:38:21 +02:00
|
|
|
static WCHAR *next_token( LPWSTR *p )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2010-05-04 21:38:21 +02:00
|
|
|
LPWSTR token = NULL, t = *p;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if( !t )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while( t && !token )
|
|
|
|
{
|
|
|
|
switch( *t )
|
|
|
|
{
|
|
|
|
case ' ':
|
|
|
|
t++;
|
|
|
|
continue;
|
|
|
|
case '"':
|
|
|
|
/* unquote the token */
|
|
|
|
token = ++t;
|
2021-10-01 10:46:39 +02:00
|
|
|
t = wcschr( token, '"' );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( t )
|
|
|
|
*t++ = 0;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
t = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
token = t;
|
2021-10-01 10:46:39 +02:00
|
|
|
t = wcschr( token, ' ' );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( t )
|
|
|
|
*t++ = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*p = t;
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:10:40 +01:00
|
|
|
static BOOL init_xdg(void)
|
|
|
|
{
|
2021-10-01 10:46:39 +02:00
|
|
|
WCHAR *p;
|
2021-10-01 10:29:44 +02:00
|
|
|
HRESULT hr = SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, SHGFP_TYPE_CURRENT, xdg_desktop_dir);
|
|
|
|
|
|
|
|
if (FAILED(hr)) return FALSE;
|
2009-03-30 20:06:31 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
if ((p = _wgetenv( L"XDG_CONFIG_HOME" )))
|
|
|
|
xdg_menu_dir = heap_wprintf( L"\\??\\unix%s/menus/applications-merged", p );
|
2008-11-02 14:10:40 +01:00
|
|
|
else
|
2021-10-01 10:46:39 +02:00
|
|
|
xdg_menu_dir = heap_wprintf( L"%s/.config/menus/applications-merged", _wgetenv(L"WINEHOMEDIR") );
|
|
|
|
for (p = xdg_menu_dir; *p; p++) if (*p == '/') *p = '\\';
|
|
|
|
xdg_menu_dir[1] = '\\'; /* change \??\ to \\?\ */
|
2021-10-01 10:30:40 +02:00
|
|
|
create_directories(xdg_menu_dir);
|
2021-10-01 09:35:48 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
if ((p = _wgetenv( L"XDG_DATA_HOME" )))
|
|
|
|
xdg_data_dir = heap_wprintf( L"\\??\\unix%s", p );
|
2021-10-01 09:35:48 +02:00
|
|
|
else
|
2021-10-01 10:46:39 +02:00
|
|
|
xdg_data_dir = heap_wprintf( L"%s/.local/share", _wgetenv(L"WINEHOMEDIR") );
|
|
|
|
for (p = xdg_data_dir; *p; p++) if (*p == '/') *p = '\\';
|
|
|
|
xdg_data_dir[1] = '\\'; /* change \??\ to \\?\ */
|
2021-10-01 09:35:48 +02:00
|
|
|
|
2021-10-01 10:46:39 +02:00
|
|
|
p = heap_wprintf( L"%s\\desktop-directories", xdg_data_dir );
|
|
|
|
create_directories(p);
|
|
|
|
heap_free(p);
|
2021-10-01 09:35:48 +02:00
|
|
|
return TRUE;
|
2008-11-02 14:10:40 +01:00
|
|
|
}
|
|
|
|
|
2018-07-25 09:22:57 +02:00
|
|
|
static BOOL associations_enabled(void)
|
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
HKEY hkey;
|
|
|
|
BYTE buf[32];
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
if ((hkey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
len = sizeof(buf);
|
|
|
|
if (!RegQueryValueExA(hkey, "Enable", NULL, NULL, buf, &len))
|
|
|
|
ret = IS_OPTION_TRUE(buf[0]);
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2010-05-04 21:38:21 +02:00
|
|
|
* wWinMain
|
2003-05-21 20:50:53 +02:00
|
|
|
*/
|
2010-05-04 21:38:21 +02:00
|
|
|
int PASCAL wWinMain (HINSTANCE hInstance, HINSTANCE prev, LPWSTR cmdline, int show)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2010-05-04 21:38:21 +02:00
|
|
|
LPWSTR token = NULL, p;
|
2007-06-28 03:23:33 +02:00
|
|
|
BOOL bWait = FALSE;
|
2008-11-13 07:19:25 +01:00
|
|
|
BOOL bURL = FALSE;
|
2010-07-20 21:16:29 +02:00
|
|
|
HRESULT hr;
|
2003-05-21 20:50:53 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-03-30 20:06:31 +02:00
|
|
|
if (!init_xdg())
|
|
|
|
return 1;
|
2008-11-02 14:10:40 +01:00
|
|
|
|
2010-07-20 21:16:29 +02:00
|
|
|
hr = CoInitialize(NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2022-02-07 08:41:01 +01:00
|
|
|
WINE_ERR("could not initialize COM, error 0x%08lX\n", hr);
|
2010-07-20 21:16:29 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
for( p = cmdline; p && *p; )
|
|
|
|
{
|
|
|
|
token = next_token( &p );
|
|
|
|
if( !token )
|
|
|
|
break;
|
2021-10-01 11:09:28 +02:00
|
|
|
if( !wcscmp( token, L"-a" ) )
|
2009-04-05 08:14:53 +02:00
|
|
|
{
|
2018-07-25 09:22:57 +02:00
|
|
|
if (associations_enabled())
|
|
|
|
RefreshFileTypeAssociations();
|
2009-06-25 21:01:59 +02:00
|
|
|
continue;
|
2009-04-05 08:14:53 +02:00
|
|
|
}
|
2021-10-01 11:09:28 +02:00
|
|
|
if( !wcscmp( token, L"-r" ) )
|
2009-06-18 07:13:02 +02:00
|
|
|
{
|
|
|
|
cleanup_menus();
|
2009-06-25 21:01:59 +02:00
|
|
|
continue;
|
2009-06-18 07:13:02 +02:00
|
|
|
}
|
2021-10-01 11:09:28 +02:00
|
|
|
if( !wcscmp( token, L"-w" ) )
|
2007-06-28 03:23:33 +02:00
|
|
|
bWait = TRUE;
|
2021-10-01 11:09:28 +02:00
|
|
|
else if ( !wcscmp( token, L"-u" ) )
|
2008-11-13 07:19:25 +01:00
|
|
|
bURL = TRUE;
|
2021-10-01 11:09:28 +02:00
|
|
|
else if ( !wcscmp( token, L"-t" ) )
|
2010-07-26 06:52:38 +02:00
|
|
|
{
|
|
|
|
WCHAR *lnkFile = next_token( &p );
|
|
|
|
if (lnkFile)
|
|
|
|
{
|
|
|
|
WCHAR *outputFile = next_token( &p );
|
|
|
|
if (outputFile)
|
|
|
|
thumbnail_lnk(lnkFile, outputFile);
|
|
|
|
}
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
else if( token[0] == '-' )
|
|
|
|
{
|
2010-05-04 21:38:21 +02:00
|
|
|
WINE_ERR( "unknown option %s\n", wine_dbgstr_w(token) );
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-13 07:19:25 +01:00
|
|
|
BOOL bRet;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-11-13 07:19:25 +01:00
|
|
|
if (bURL)
|
2010-05-04 21:38:21 +02:00
|
|
|
bRet = Process_URL( token, bWait );
|
2008-11-13 07:19:25 +01:00
|
|
|
else
|
2010-05-04 21:38:21 +02:00
|
|
|
bRet = Process_Link( token, bWait );
|
2008-11-13 07:19:25 +01:00
|
|
|
if (!bRet)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2010-05-04 21:38:21 +02:00
|
|
|
WINE_ERR( "failed to build menu item for %s\n", wine_dbgstr_w(token) );
|
2008-11-13 07:19:25 +01:00
|
|
|
ret = 1;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 21:16:29 +02:00
|
|
|
CoUninitialize();
|
2003-05-21 20:50:53 +02:00
|
|
|
return ret;
|
|
|
|
}
|