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 "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
2009-06-01 12:51:54 +02:00
|
|
|
#ifdef HAVE_FNMATCH_H
|
2009-05-19 21:40:41 +02:00
|
|
|
#include <fnmatch.h>
|
2009-06-01 12:51:54 +02:00
|
|
|
#endif
|
2003-05-21 20:50:53 +02:00
|
|
|
|
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>
|
|
|
|
#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
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
#include "wine/unicode.h"
|
2003-05-21 20:50:53 +02:00
|
|
|
#include "wine/debug.h"
|
2008-03-23 21:16:38 +01:00
|
|
|
#include "wine/library.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
|
|
|
|
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
|
|
|
|
{
|
|
|
|
char *mimeType;
|
|
|
|
char *glob;
|
2011-08-28 21:21:46 +02:00
|
|
|
char *lower_glob;
|
2009-04-11 10:10:59 +02:00
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
2010-11-18 10:52:10 +01:00
|
|
|
struct rb_string_entry
|
|
|
|
{
|
|
|
|
char *string;
|
|
|
|
struct wine_rb_entry entry;
|
|
|
|
};
|
|
|
|
|
2010-09-22 22:14:47 +02:00
|
|
|
DEFINE_GUID(CLSID_WICIcnsEncoder, 0x312fb6f1,0xb767,0x409d,0x8a,0x6d,0x0f,0xc1,0x54,0xd4,0xf0,0x5c);
|
|
|
|
|
2008-11-03 20:19:30 +01:00
|
|
|
static char *xdg_config_dir;
|
|
|
|
static char *xdg_data_dir;
|
2009-03-30 20:06:31 +02:00
|
|
|
static char *xdg_desktop_dir;
|
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 */
|
|
|
|
static unsigned short crc16(const char* string)
|
|
|
|
{
|
|
|
|
unsigned short crc = 0;
|
|
|
|
int i, j, xor_poly;
|
|
|
|
|
|
|
|
for (i = 0; string[i] != 0; i++)
|
|
|
|
{
|
|
|
|
char c = string[i];
|
|
|
|
for (j = 0; j < 8; c >>= 1, j++)
|
|
|
|
{
|
|
|
|
xor_poly = (c ^ crc) & 1;
|
|
|
|
crc >>= 1;
|
|
|
|
if (xor_poly)
|
|
|
|
crc ^= 0xa001;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *strdupA( const char *str )
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
if (!str) return NULL;
|
|
|
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* heap_printf(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int size = 4096;
|
|
|
|
char *buffer, *ret;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (buffer == NULL)
|
|
|
|
break;
|
2012-02-16 01:28:29 +01:00
|
|
|
va_start(args, format);
|
2010-08-24 15:03:13 +02:00
|
|
|
n = vsnprintf(buffer, size, format, args);
|
2012-02-16 01:28:29 +01:00
|
|
|
va_end(args);
|
2010-08-24 15:03:13 +02:00
|
|
|
if (n == -1)
|
|
|
|
size *= 2;
|
|
|
|
else if (n >= size)
|
|
|
|
size = n + 1;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
}
|
2012-02-16 01:28:29 +01:00
|
|
|
|
2010-08-24 15:03:13 +02:00
|
|
|
if (!buffer) return NULL;
|
|
|
|
ret = HeapReAlloc(GetProcessHeap(), 0, buffer, strlen(buffer) + 1 );
|
|
|
|
if (!ret) ret = buffer;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return strcmp((char*)key, t->string);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
HeapFree(GetProcessHeap(), 0, t->string);
|
|
|
|
HeapFree(GetProcessHeap(), 0, t);
|
|
|
|
}
|
|
|
|
|
2010-08-24 15:03:13 +02:00
|
|
|
static void write_xml_text(FILE *file, const char *text)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; text[i]; i++)
|
|
|
|
{
|
|
|
|
if (text[i] == '&')
|
|
|
|
fputs("&", file);
|
|
|
|
else if (text[i] == '<')
|
|
|
|
fputs("<", file);
|
|
|
|
else if (text[i] == '>')
|
|
|
|
fputs(">", file);
|
|
|
|
else if (text[i] == '\'')
|
|
|
|
fputs("'", file);
|
|
|
|
else if (text[i] == '"')
|
|
|
|
fputs(""", file);
|
|
|
|
else
|
|
|
|
fputc(text[i], file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL create_directories(char *directory)
|
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; directory[i]; i++)
|
|
|
|
{
|
|
|
|
if (i > 0 && directory[i] == '/')
|
|
|
|
{
|
|
|
|
directory[i] = 0;
|
|
|
|
mkdir(directory, 0777);
|
|
|
|
directory[i] = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mkdir(directory, 0777) && errno != EEXIST)
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* wchars_to_utf8_chars(LPCWSTR string)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
INT size = WideCharToMultiByte(CP_UTF8, 0, string, -1, NULL, 0, NULL, NULL);
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (ret)
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, string, -1, ret, size, NULL, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char* wchars_to_unix_chars(LPCWSTR string)
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
INT size = WideCharToMultiByte(CP_UNIXCP, 0, string, -1, NULL, 0, NULL, NULL);
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (ret)
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, string, -1, ret, size, NULL, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR* utf8_chars_to_wchars(LPCSTR string)
|
|
|
|
{
|
|
|
|
WCHAR *ret;
|
|
|
|
INT size = MultiByteToWideChar(CP_UTF8, 0, string, -1, NULL, 0);
|
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (ret)
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, string, -1, ret, size);
|
|
|
|
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,
|
2010-08-24 15:04:07 +02:00
|
|
|
const CLSID *outputFormat, const char *outputFileName, LPCWSTR commentW)
|
2010-07-22 21:40:14 +02:00
|
|
|
{
|
2010-08-24 15:04:07 +02:00
|
|
|
WCHAR *dosOutputFileName = NULL;
|
2010-07-22 21:40:14 +02:00
|
|
|
IWICImagingFactory *factory = NULL;
|
|
|
|
IWICBitmapDecoder *decoder = NULL;
|
|
|
|
IWICBitmapEncoder *encoder = NULL;
|
2012-10-18 23:05:28 +02:00
|
|
|
IWICBitmapScaler *scaler = NULL;
|
2010-07-22 21:40:14 +02:00
|
|
|
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;
|
|
|
|
|
2010-08-24 15:04:07 +02:00
|
|
|
dosOutputFileName = wine_get_dos_file_name(outputFileName);
|
|
|
|
if (dosOutputFileName == NULL)
|
2010-07-22 21:40:14 +02:00
|
|
|
{
|
2010-08-24 15:04:07 +02:00
|
|
|
WINE_ERR("error converting %s to DOS file name\n", outputFileName);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = CoCreateInstance(&CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IWICImagingFactory, (void**)&factory);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X creating IWICImagingFactory\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = IWICImagingFactory_CreateDecoderFromStream(factory, icoFile, NULL,
|
|
|
|
WICDecodeMetadataCacheOnDemand, &decoder);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X creating IWICBitmapDecoder\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
2012-10-18 23:05:28 +02:00
|
|
|
if (IsEqualCLSID(outputFormat,&CLSID_WICIcnsEncoder))
|
|
|
|
{
|
|
|
|
hr = IWICImagingFactory_CreateBitmapScaler(factory, &scaler);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_WARN("error 0x%08X creating IWICBitmapScaler\n", hr);
|
|
|
|
}
|
|
|
|
}
|
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))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X creating bitmap encoder\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
2010-08-24 15:04:07 +02:00
|
|
|
hr = SHCreateStreamOnFileW(dosOutputFileName, STGM_CREATE | STGM_WRITE, &outputFile);
|
2010-07-22 21:40:14 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-06-26 18:26:27 +02:00
|
|
|
WINE_ERR("error 0x%08X creating output file %s\n", hr, wine_dbgstr_w(dosOutputFileName));
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapEncoder_Initialize(encoder, outputFile, GENERIC_WRITE);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X initializing encoder\n", hr);
|
|
|
|
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))
|
|
|
|
{
|
2011-09-27 00:14:10 +02:00
|
|
|
WINE_ERR("error 0x%08X 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))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X converting bitmap to 32bppBGRA\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
2012-10-18 23:05:28 +02:00
|
|
|
if ( scaler)
|
|
|
|
{
|
|
|
|
IWICBitmapSource_GetSize(sourceBitmap, &width, &height);
|
|
|
|
if (width == 64) /* Classic Mode */
|
|
|
|
{
|
|
|
|
hr = IWICBitmapScaler_Initialize( scaler, sourceBitmap, 128, 128,
|
|
|
|
WICBitmapInterpolationModeNearestNeighbor);
|
|
|
|
if (FAILED(hr))
|
|
|
|
WINE_ERR("error 0x%08X scaling bitmap\n", hr);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IWICBitmapSource_Release(sourceBitmap);
|
|
|
|
IWICBitmapScaler_QueryInterface(scaler, &IID_IWICBitmapSource, (LPVOID)&sourceBitmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-24 15:04:07 +02:00
|
|
|
hr = IWICBitmapEncoder_CreateNewFrame(encoder, &dstFrame, &options);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X creating encoder frame\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_Initialize(dstFrame, options);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X initializing encoder frame\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapSource_GetSize(sourceBitmap, &width, &height);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X getting source bitmap size\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_SetSize(dstFrame, width, height);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X setting destination bitmap size\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_SetResolution(dstFrame, 96, 96);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X setting destination bitmap resolution\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_WriteSource(dstFrame, sourceBitmap, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X copying bitmaps\n", hr);
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
hr = IWICBitmapFrameEncode_Commit(dstFrame);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X committing frame\n", hr);
|
|
|
|
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))
|
|
|
|
{
|
2010-08-24 15:04:07 +02:00
|
|
|
WINE_ERR("error 0x%08X committing encoder\n", hr);
|
2010-07-22 21:40:14 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2010-08-24 15:04:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, dosOutputFileName);
|
2010-07-22 21:40:14 +02:00
|
|
|
if (factory)
|
|
|
|
IWICImagingFactory_Release(factory);
|
|
|
|
if (decoder)
|
|
|
|
IWICBitmapDecoder_Release(decoder);
|
2012-10-18 23:05:28 +02:00
|
|
|
if (scaler)
|
|
|
|
IWICBitmapScaler_Release(scaler);
|
2010-07-22 21:40:14 +02:00
|
|
|
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;
|
|
|
|
if ((((BYTE*)iconPtr) + sizeof(NE_NAMEINFO)) > (iconData16->fileBytes + iconData16->fileSize))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
icons = HeapAlloc(GetProcessHeap(), 0, iconsSize);
|
|
|
|
if (icons == NULL)
|
2010-07-22 21:41:03 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("out of memory allocating icon\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2010-08-22 19:46:51 +02:00
|
|
|
iconDirEntries = HeapAlloc(GetProcessHeap(), 0, grpIconDir->idCount*sizeof(ICONDIRENTRY));
|
|
|
|
if (iconDirEntries == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory allocating icon dir entries\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X writing icon stream\n", hr);
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X writing icon dir entries to stream\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
hr = IStream_Write(stream, icons, iconOffset, &bytesWritten);
|
|
|
|
if (FAILED(hr) || bytesWritten != iconOffset)
|
|
|
|
{
|
|
|
|
WINE_ERR("error 0x%08X writing icon images to stream\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
|
2010-07-22 21:41:03 +02:00
|
|
|
|
|
|
|
end:
|
2010-08-22 19:46:51 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, icons);
|
|
|
|
HeapFree(GetProcessHeap(), 0, 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)
|
|
|
|
{
|
|
|
|
WINE_WARN("opening %s failed with error %d\n", wine_dbgstr_w(szFileName), GetLastError());
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hFileMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
|
|
|
|
if (hFileMapping == NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("CreateFileMapping failed, error %d\n", GetLastError());
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileSize = GetFileSize(hFile, NULL);
|
|
|
|
|
|
|
|
fileBytes = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
if (fileBytes == NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("MapViewOfFile failed, error %d\n", GetLastError());
|
|
|
|
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
|
|
|
|
{
|
|
|
|
WINE_WARN("LoadLibraryExW (%s) failed, error %d\n",
|
|
|
|
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);
|
2006-10-02 23:22:58 +02:00
|
|
|
WINE_TRACE("FindResourceW (%s) called, return %p, error %d\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
|
|
|
{
|
2006-10-02 23:22:58 +02:00
|
|
|
WINE_TRACE("EnumResourceNamesW failed, error %d\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))
|
|
|
|
{
|
2010-08-22 19:42:18 +02:00
|
|
|
WINE_WARN("Invalid ico file format (hr=0x%08X, bytesRead=%d)\n", hr, bytesRead);
|
|
|
|
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
|
|
|
|
2010-08-24 15:04:54 +02:00
|
|
|
if ((*ppIconDirEntries = HeapAlloc(GetProcessHeap(), 0, sizeof(ICONDIRENTRY)*iconDir.idCount)) == NULL)
|
2010-08-22 19:42:18 +02:00
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
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))
|
|
|
|
HeapFree(GetProcessHeap(), 0, *ppIconDirEntries);
|
|
|
|
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;
|
|
|
|
HeapFree(GetProcessHeap(), 0, *ppIconDirEntries);
|
|
|
|
*ppIconDirEntries = NULL;
|
|
|
|
}
|
|
|
|
IStream_Release(*ppStream);
|
|
|
|
*ppStream = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_native_icon(IStream *iconStream, ICONDIRENTRY *pIconDirEntry,
|
|
|
|
int numEntries, const char *icon_name, LPCWSTR szFileName)
|
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;
|
|
|
|
return convert_to_native_icon(iconStream, &nIndex, 1, &CLSID_WICPngEncoder, icon_name, szFileName);
|
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))
|
|
|
|
{
|
|
|
|
value = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
hr = AssocQueryStringW(0, assocStr, name, extra, value, &size);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, value);
|
|
|
|
value = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2011-08-24 04:47:07 +02:00
|
|
|
static const WCHAR openW[] = {'o','p','e','n',0};
|
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
|
|
|
|
|
|
|
extension = strrchrW(szFileName, '.');
|
|
|
|
if (extension == NULL)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
icon = assoc_query(ASSOCSTR_DEFAULTICON, extension, NULL);
|
2010-06-08 22:05:04 +02:00
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
comma = strrchrW(icon, ',');
|
|
|
|
if (comma)
|
|
|
|
{
|
|
|
|
*comma = 0;
|
|
|
|
index = atoiW(comma + 1);
|
|
|
|
}
|
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
|
|
|
{
|
2011-08-24 04:47:07 +02:00
|
|
|
executable = assoc_query(ASSOCSTR_EXECUTABLE, extension, openW);
|
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:
|
|
|
|
HeapFree(GetProcessHeap(), 0, icon);
|
2010-06-08 22:05:04 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, 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
|
|
|
{
|
2010-06-28 16:39:39 +02:00
|
|
|
static const WCHAR user32W[] = {'u','s','e','r','3','2',0};
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-08-22 19:42:18 +02:00
|
|
|
return open_module_icon(user32W, -(INT_PTR)IDI_WINLOGO, ppStream);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-01 23:20:13 +01:00
|
|
|
static char* compute_native_identifier(int exeIndex, LPCWSTR icoPathW)
|
|
|
|
{
|
|
|
|
char* nativeIdentifier;
|
|
|
|
char *icoPathA;
|
|
|
|
unsigned short crc;
|
|
|
|
char *basename, *ext;
|
|
|
|
|
|
|
|
icoPathA = wchars_to_utf8_chars(icoPathW);
|
|
|
|
if (icoPathA == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
crc = crc16(icoPathA);
|
|
|
|
basename = strrchr(icoPathA, '\\');
|
|
|
|
if (basename == NULL)
|
|
|
|
basename = icoPathA;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*basename = 0;
|
|
|
|
basename++;
|
|
|
|
}
|
|
|
|
ext = strrchr(basename, '.');
|
|
|
|
if (ext)
|
|
|
|
*ext = 0;
|
|
|
|
|
|
|
|
nativeIdentifier = heap_printf("%04X_%s.%d", crc, basename, exeIndex);
|
|
|
|
HeapFree(GetProcessHeap(), 0, icoPathA);
|
|
|
|
return nativeIdentifier;
|
|
|
|
}
|
|
|
|
|
2010-09-22 22:14:47 +02:00
|
|
|
#ifdef __APPLE__
|
2011-01-05 11:57:18 +01:00
|
|
|
#define ICNS_SLOTS 6
|
|
|
|
|
|
|
|
static inline int size_to_slot(int size)
|
|
|
|
{
|
|
|
|
switch (size)
|
|
|
|
{
|
|
|
|
case 16: return 0;
|
|
|
|
case 32: return 1;
|
|
|
|
case 48: return 2;
|
2012-10-18 23:05:28 +02:00
|
|
|
case 64: return -2; /* Classic Mode */
|
2011-01-05 11:57:18 +01:00
|
|
|
case 128: return 3;
|
|
|
|
case 256: return 4;
|
|
|
|
case 512: return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-18 23:05:28 +02:00
|
|
|
#define CLASSIC_SLOT 3
|
|
|
|
|
2015-03-18 15:50:41 +01:00
|
|
|
static HRESULT platform_write_icon(IStream *icoStream, ICONDIRENTRY *iconDirEntries,
|
2015-03-16 17:44:43 +01:00
|
|
|
int numEntries, int exeIndex, LPCWSTR icoPathW,
|
2010-09-22 22:14:47 +02:00
|
|
|
const char *destFilename, char **nativeIdentifier)
|
|
|
|
{
|
2011-01-05 11:57:18 +01:00
|
|
|
struct {
|
|
|
|
int index;
|
|
|
|
int maxBits;
|
2012-10-18 23:05:28 +02:00
|
|
|
BOOL scaled;
|
2011-01-05 11:57:18 +01:00
|
|
|
} best[ICNS_SLOTS];
|
|
|
|
int indexes[ICNS_SLOTS];
|
|
|
|
int i;
|
2014-09-23 22:23:35 +02:00
|
|
|
const char* tmpdir;
|
2010-09-22 22:14:47 +02:00
|
|
|
char *icnsPath = NULL;
|
|
|
|
LARGE_INTEGER zero;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-01-05 11:57:18 +01:00
|
|
|
for (i = 0; i < ICNS_SLOTS; i++)
|
|
|
|
{
|
|
|
|
best[i].index = -1;
|
|
|
|
best[i].maxBits = 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < numEntries; i++)
|
|
|
|
{
|
|
|
|
int slot;
|
2011-01-12 07:17:20 +01:00
|
|
|
int width = iconDirEntries[i].bWidth ? iconDirEntries[i].bWidth : 256;
|
|
|
|
int height = iconDirEntries[i].bHeight ? iconDirEntries[i].bHeight : 256;
|
2012-10-18 23:05:28 +02:00
|
|
|
BOOL scaled = FALSE;
|
2011-01-05 11:57:18 +01:00
|
|
|
|
2011-01-12 07:17:20 +01:00
|
|
|
WINE_TRACE("[%d]: %d x %d @ %d\n", i, width, height, iconDirEntries[i].wBitCount);
|
2011-01-12 07:17:25 +01:00
|
|
|
if (height != width)
|
|
|
|
continue;
|
2011-01-12 07:17:20 +01:00
|
|
|
slot = size_to_slot(width);
|
2012-10-18 23:05:28 +02:00
|
|
|
if (slot == -2)
|
|
|
|
{
|
|
|
|
scaled = TRUE;
|
|
|
|
slot = CLASSIC_SLOT;
|
|
|
|
}
|
|
|
|
else if (slot < 0)
|
2011-01-05 11:57:18 +01:00
|
|
|
continue;
|
2012-10-18 23:05:28 +02:00
|
|
|
if (scaled && best[slot].maxBits && !best[slot].scaled)
|
|
|
|
continue; /* don't replace unscaled with scaled */
|
|
|
|
if (iconDirEntries[i].wBitCount >= best[slot].maxBits || (!scaled && best[slot].scaled))
|
2011-01-05 11:57:18 +01:00
|
|
|
{
|
|
|
|
best[slot].index = i;
|
|
|
|
best[slot].maxBits = iconDirEntries[i].wBitCount;
|
2012-10-18 23:05:28 +02:00
|
|
|
best[slot].scaled = scaled;
|
2011-01-05 11:57:18 +01:00
|
|
|
}
|
|
|
|
}
|
2012-10-18 23:05:28 +02:00
|
|
|
/* remove the scaled icon if a larger unscaled icon exists */
|
|
|
|
if (best[CLASSIC_SLOT].scaled)
|
|
|
|
{
|
|
|
|
for (i = CLASSIC_SLOT+1; i < ICNS_SLOTS; i++)
|
|
|
|
if (best[i].index >= 0 && !best[i].scaled)
|
|
|
|
{
|
2012-10-20 06:59:29 +02:00
|
|
|
best[CLASSIC_SLOT].index = -1;
|
2012-10-18 23:05:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-05 11:57:18 +01:00
|
|
|
numEntries = 0;
|
|
|
|
for (i = 0; i < ICNS_SLOTS; i++)
|
|
|
|
{
|
|
|
|
if (best[i].index >= 0)
|
|
|
|
{
|
|
|
|
indexes[numEntries] = best[i].index;
|
|
|
|
numEntries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-01 23:20:13 +01:00
|
|
|
if (destFilename)
|
|
|
|
*nativeIdentifier = heap_printf("%s", destFilename);
|
|
|
|
else
|
|
|
|
*nativeIdentifier = compute_native_identifier(exeIndex, icoPathW);
|
|
|
|
if (*nativeIdentifier == NULL)
|
2010-09-22 22:14:47 +02:00
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
2014-09-23 22:23:35 +02:00
|
|
|
if (!(tmpdir = getenv("TMPDIR"))) tmpdir = "/tmp";
|
|
|
|
icnsPath = heap_printf("%s/%s.icns", tmpdir, *nativeIdentifier);
|
2010-09-22 22:14:47 +02:00
|
|
|
if (icnsPath == NULL)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
WINE_WARN("out of memory creating ICNS path\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(icoStream, zero, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_WARN("seeking icon stream failed, error 0x%08X\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
2011-01-05 11:57:18 +01:00
|
|
|
hr = convert_to_native_icon(icoStream, indexes, numEntries, &CLSID_WICIcnsEncoder,
|
2010-09-22 22:14:47 +02:00
|
|
|
icnsPath, icoPathW);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_WARN("converting %s to %s failed, error 0x%08X\n",
|
|
|
|
wine_dbgstr_w(icoPathW), wine_dbgstr_a(icnsPath), hr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2012-11-01 23:21:00 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, icnsPath);
|
2010-09-22 22:14:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
#else
|
2011-01-15 09:37:52 +01:00
|
|
|
static void refresh_icon_cache(const char *iconsDir)
|
|
|
|
{
|
|
|
|
/* 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
|
|
|
*/
|
|
|
|
char *filename = heap_printf("%s/.wine-refresh-XXXXXX", iconsDir);
|
|
|
|
if (filename != NULL)
|
|
|
|
{
|
|
|
|
int fd = mkstemps(filename, 0);
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
unlink(filename);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 17:44:43 +01:00
|
|
|
static HRESULT platform_write_icon(IStream *icoStream, ICONDIRENTRY *iconDirEntries,
|
|
|
|
int numEntries, int exeIndex, LPCWSTR icoPathW,
|
2010-09-22 22:14:04 +02:00
|
|
|
const char *destFilename, char **nativeIdentifier)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2011-01-05 11:57:18 +01:00
|
|
|
int i;
|
2010-09-22 22:14:04 +02:00
|
|
|
char *iconsDir = NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
LARGE_INTEGER zero;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2009-06-30 21:04:32 +02:00
|
|
|
if (destFilename)
|
2010-09-22 22:14:04 +02:00
|
|
|
*nativeIdentifier = heap_printf("%s", destFilename);
|
2009-06-30 21:04:32 +02:00
|
|
|
else
|
2012-11-01 23:20:13 +01:00
|
|
|
*nativeIdentifier = compute_native_identifier(exeIndex, icoPathW);
|
2010-09-22 22:14:04 +02:00
|
|
|
if (*nativeIdentifier == NULL)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
2011-01-15 09:37:52 +01:00
|
|
|
iconsDir = heap_printf("%s/icons/hicolor", xdg_data_dir);
|
2010-09-22 22:14:04 +02:00
|
|
|
if (iconsDir == NULL)
|
2009-06-30 21:04:32 +02:00
|
|
|
{
|
2010-09-22 22:14:04 +02:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto end;
|
2009-06-30 21:04:32 +02:00
|
|
|
}
|
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;
|
|
|
|
char *iconDir = NULL;
|
|
|
|
char *pngPath = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
iconDir = heap_printf("%s/%dx%d/apps", iconsDir, w, h);
|
|
|
|
if (iconDir == NULL)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
create_directories(iconDir);
|
|
|
|
pngPath = heap_printf("%s/%s.png", iconDir, *nativeIdentifier);
|
|
|
|
if (pngPath == NULL)
|
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto endloop;
|
|
|
|
}
|
|
|
|
zero.QuadPart = 0;
|
|
|
|
hr = IStream_Seek(icoStream, zero, STREAM_SEEK_SET, NULL);
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto endloop;
|
|
|
|
hr = convert_to_native_icon(icoStream, &bestIndex, 1, &CLSID_WICPngEncoder,
|
|
|
|
pngPath, icoPathW);
|
|
|
|
|
|
|
|
endloop:
|
|
|
|
HeapFree(GetProcessHeap(), 0, iconDir);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pngPath);
|
2010-08-22 19:42:18 +02:00
|
|
|
}
|
2011-01-15 09:37:52 +01:00
|
|
|
refresh_icon_cache(iconsDir);
|
2010-09-22 22:14:04 +02:00
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, iconsDir);
|
|
|
|
return hr;
|
|
|
|
}
|
2010-09-22 22:14:47 +02:00
|
|
|
#endif /* defined(__APPLE__) */
|
2010-09-22 22:14:04 +02:00
|
|
|
|
|
|
|
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
|
|
|
|
static char *extract_icon(LPCWSTR icoPathW, int index, const char *destFilename, BOOL bWait)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
char *nativeIdentifier = NULL;
|
|
|
|
|
|
|
|
WINE_TRACE("path=[%s] index=%d destFilename=[%s]\n", wine_dbgstr_w(icoPathW), index, wine_dbgstr_a(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))
|
|
|
|
{
|
|
|
|
WINE_WARN("opening icon %s index %d failed, hr=0x%08X\n", wine_dbgstr_w(icoPathW), index, hr);
|
|
|
|
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))
|
|
|
|
WINE_WARN("writing icon failed, error 0x%08X\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);
|
2015-03-16 17:44:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pIconDirEntries);
|
2010-09-22 22:14:04 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, nativeIdentifier);
|
|
|
|
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)
|
|
|
|
{
|
2015-06-16 20:13:07 +02:00
|
|
|
static const WCHAR Software_Wine_FileOpenMenuFilesW[] = {
|
2009-06-18 07:13:02 +02:00
|
|
|
'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','M','e','n','u','F','i','l','e','s',0};
|
|
|
|
HKEY assocKey;
|
2010-04-30 13:41:40 +02:00
|
|
|
DWORD ret;
|
2015-06-16 20:13:07 +02:00
|
|
|
ret = RegCreateKeyW(HKEY_CURRENT_USER, Software_Wine_FileOpenMenuFilesW, &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;
|
|
|
|
}
|
|
|
|
|
2010-04-30 13:41:40 +02:00
|
|
|
static DWORD register_menus_entry(const char *unix_file, const char *windows_file)
|
|
|
|
{
|
|
|
|
WCHAR *unix_fileW;
|
|
|
|
WCHAR *windows_fileW;
|
|
|
|
INT size;
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
size = MultiByteToWideChar(CP_UNIXCP, 0, unix_file, -1, NULL, 0);
|
|
|
|
unix_fileW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (unix_fileW)
|
|
|
|
{
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, unix_file, -1, unix_fileW, size);
|
|
|
|
size = MultiByteToWideChar(CP_UNIXCP, 0, windows_file, -1, NULL, 0);
|
|
|
|
windows_fileW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (windows_fileW)
|
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
MultiByteToWideChar(CP_UNIXCP, 0, windows_file, -1, windows_fileW, size);
|
|
|
|
hkey = open_menus_reg_key();
|
|
|
|
if (hkey)
|
|
|
|
{
|
|
|
|
ret = RegSetValueExW(hkey, unix_fileW, 0, REG_SZ, (const BYTE*)windows_fileW,
|
|
|
|
(strlenW(windows_fileW) + 1) * sizeof(WCHAR));
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = GetLastError();
|
|
|
|
HeapFree(GetProcessHeap(), 0, windows_fileW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_fileW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
static BOOL write_desktop_entry(const char *unix_link, const char *location, const char *linkname,
|
|
|
|
const char *path, const char *args, const char *descr,
|
2017-09-08 17:54:30 +02:00
|
|
|
const char *workdir, const char *icon, const char *wmclass)
|
2008-11-08 10:03:39 +01:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
2017-09-08 17:54:30 +02:00
|
|
|
WINE_TRACE("(%s,%s,%s,%s,%s,%s,%s,%s,%s)\n", wine_dbgstr_a(unix_link), wine_dbgstr_a(location),
|
2008-11-08 10:03:39 +01:00
|
|
|
wine_dbgstr_a(linkname), wine_dbgstr_a(path), wine_dbgstr_a(args),
|
2017-09-08 17:54:30 +02:00
|
|
|
wine_dbgstr_a(descr), wine_dbgstr_a(workdir), wine_dbgstr_a(icon),
|
|
|
|
wine_dbgstr_a(wmclass));
|
2008-11-08 10:03:39 +01:00
|
|
|
|
|
|
|
file = fopen(location, "w");
|
|
|
|
if (file == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fprintf(file, "[Desktop Entry]\n");
|
|
|
|
fprintf(file, "Name=%s\n", linkname);
|
2010-05-08 23:20:32 +02:00
|
|
|
fprintf(file, "Exec=env WINEPREFIX=\"%s\" wine %s %s\n",
|
2008-11-08 10:03:39 +01:00
|
|
|
wine_get_config_dir(), path, args);
|
|
|
|
fprintf(file, "Type=Application\n");
|
2009-01-06 19:59:07 +01:00
|
|
|
fprintf(file, "StartupNotify=true\n");
|
2008-11-08 10:03:39 +01:00
|
|
|
if (descr && lstrlenA(descr))
|
|
|
|
fprintf(file, "Comment=%s\n", descr);
|
|
|
|
if (workdir && lstrlenA(workdir))
|
|
|
|
fprintf(file, "Path=%s\n", workdir);
|
|
|
|
if (icon && lstrlenA(icon))
|
|
|
|
fprintf(file, "Icon=%s\n", icon);
|
2017-09-08 17:54:30 +02:00
|
|
|
if (wmclass && lstrlenA(wmclass))
|
|
|
|
fprintf(file, "StartupWMClass=%s\n", wmclass);
|
2008-11-08 10:03:39 +01:00
|
|
|
|
|
|
|
fclose(file);
|
2009-06-18 07:13:02 +02:00
|
|
|
|
|
|
|
if (unix_link)
|
|
|
|
{
|
2010-04-30 13:41:40 +02:00
|
|
|
DWORD ret = register_menus_entry(location, unix_link);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
2009-06-18 07:13:02 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-11-11 20:39:56 +01:00
|
|
|
static BOOL write_directory_entry(const char *directory, const char *location)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s,%s)\n", wine_dbgstr_a(directory), wine_dbgstr_a(location));
|
|
|
|
|
|
|
|
file = fopen(location, "w");
|
|
|
|
if (file == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fprintf(file, "[Desktop Entry]\n");
|
|
|
|
fprintf(file, "Type=Directory\n");
|
|
|
|
if (strcmp(directory, "wine") == 0)
|
|
|
|
{
|
|
|
|
fprintf(file, "Name=Wine\n");
|
|
|
|
fprintf(file, "Icon=wine\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(file, "Name=%s\n", directory);
|
|
|
|
fprintf(file, "Icon=folder\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
static BOOL write_menu_file(const char *unix_link, const char *filename)
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
|
|
|
char *tempfilename;
|
|
|
|
FILE *tempfile = NULL;
|
|
|
|
char *lastEntry;
|
|
|
|
char *name = NULL;
|
|
|
|
char *menuPath = NULL;
|
|
|
|
int i;
|
|
|
|
int count = 0;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s)\n", wine_dbgstr_a(filename));
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2009-06-25 07:19:07 +02:00
|
|
|
tempfilename = heap_printf("%s/wine-menu-XXXXXX", xdg_config_dir);
|
2008-11-11 20:39:56 +01:00
|
|
|
if (tempfilename)
|
|
|
|
{
|
2009-06-25 07:19:07 +02:00
|
|
|
int tempfd = mkstemps(tempfilename, 0);
|
2008-11-11 20:39:56 +01:00
|
|
|
if (tempfd >= 0)
|
|
|
|
{
|
|
|
|
tempfile = fdopen(tempfd, "w");
|
|
|
|
if (tempfile)
|
|
|
|
break;
|
|
|
|
close(tempfd);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
else if (errno == EEXIST)
|
|
|
|
{
|
2009-06-25 07:19:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, tempfilename);
|
2008-11-11 20:39:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2009-06-25 07:19:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, tempfilename);
|
2008-11-11 20:39:56 +01:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, lstrlenA(filename) + 1);
|
|
|
|
if (name == NULL) goto end;
|
|
|
|
lastEntry = name;
|
|
|
|
for (i = 0; filename[i]; i++)
|
|
|
|
{
|
|
|
|
name[i] = filename[i];
|
|
|
|
if (filename[i] == '/')
|
|
|
|
{
|
|
|
|
char *dir_file_name;
|
|
|
|
struct stat st;
|
|
|
|
name[i] = 0;
|
|
|
|
fprintf(tempfile, " <Menu>\n");
|
2009-11-14 08:10:30 +01:00
|
|
|
fprintf(tempfile, " <Name>%s", count ? "" : "wine-");
|
|
|
|
write_xml_text(tempfile, name);
|
|
|
|
fprintf(tempfile, "</Name>\n");
|
|
|
|
fprintf(tempfile, " <Directory>%s", count ? "" : "wine-");
|
|
|
|
write_xml_text(tempfile, name);
|
|
|
|
fprintf(tempfile, ".directory</Directory>\n");
|
2008-11-11 20:39:56 +01:00
|
|
|
dir_file_name = heap_printf("%s/desktop-directories/%s%s.directory",
|
|
|
|
xdg_data_dir, count ? "" : "wine-", name);
|
|
|
|
if (dir_file_name)
|
|
|
|
{
|
|
|
|
if (stat(dir_file_name, &st) != 0 && errno == ENOENT)
|
|
|
|
write_directory_entry(lastEntry, dir_file_name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dir_file_name);
|
|
|
|
}
|
|
|
|
name[i] = '-';
|
|
|
|
lastEntry = &name[i+1];
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name[i] = 0;
|
|
|
|
|
|
|
|
fprintf(tempfile, " <Include>\n");
|
2009-11-14 08:10:30 +01:00
|
|
|
fprintf(tempfile, " <Filename>");
|
|
|
|
write_xml_text(tempfile, name);
|
|
|
|
fprintf(tempfile, "</Filename>\n");
|
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");
|
|
|
|
|
|
|
|
menuPath = heap_printf("%s/%s", xdg_config_dir, name);
|
|
|
|
if (menuPath == NULL) goto end;
|
|
|
|
strcpy(menuPath + strlen(menuPath) - strlen(".desktop"), ".menu");
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (tempfile)
|
|
|
|
fclose(tempfile);
|
|
|
|
if (ret)
|
|
|
|
ret = (rename(tempfilename, menuPath) == 0);
|
|
|
|
if (!ret && tempfilename)
|
|
|
|
remove(tempfilename);
|
2009-06-25 07:19:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, tempfilename);
|
2009-06-18 07:13:02 +02:00
|
|
|
if (ret)
|
2010-04-30 13:41:40 +02:00
|
|
|
register_menus_entry(menuPath, unix_link);
|
2008-11-11 20:39:56 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, menuPath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
static BOOL write_menu_entry(const char *unix_link, const char *link, const char *path, const char *args,
|
2017-09-08 17:54:30 +02:00
|
|
|
const char *descr, const char *workdir, const char *icon, const char *wmclass)
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
|
|
|
const char *linkname;
|
|
|
|
char *desktopPath = NULL;
|
|
|
|
char *desktopDir;
|
|
|
|
char *filename = NULL;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
2017-09-08 17:54:30 +02:00
|
|
|
WINE_TRACE("(%s, %s, %s, %s, %s, %s, %s, %s)\n", wine_dbgstr_a(unix_link), wine_dbgstr_a(link),
|
2009-06-18 07:13:02 +02:00
|
|
|
wine_dbgstr_a(path), wine_dbgstr_a(args), wine_dbgstr_a(descr),
|
2017-09-08 17:54:30 +02:00
|
|
|
wine_dbgstr_a(workdir), wine_dbgstr_a(icon), wine_dbgstr_a(wmclass));
|
2008-11-11 20:39:56 +01:00
|
|
|
|
|
|
|
linkname = strrchr(link, '/');
|
|
|
|
if (linkname == NULL)
|
|
|
|
linkname = link;
|
|
|
|
else
|
|
|
|
++linkname;
|
|
|
|
|
|
|
|
desktopPath = heap_printf("%s/applications/wine/%s.desktop", xdg_data_dir, link);
|
|
|
|
if (!desktopPath)
|
|
|
|
{
|
|
|
|
WINE_WARN("out of memory creating menu entry\n");
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
desktopDir = strrchr(desktopPath, '/');
|
|
|
|
*desktopDir = 0;
|
|
|
|
if (!create_directories(desktopPath))
|
|
|
|
{
|
|
|
|
WINE_WARN("couldn't make parent directories for %s\n", wine_dbgstr_a(desktopPath));
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
*desktopDir = '/';
|
2017-09-08 17:54:30 +02:00
|
|
|
if (!write_desktop_entry(unix_link, desktopPath, linkname, path, args, descr, workdir, icon, wmclass))
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
|
|
|
WINE_WARN("couldn't make desktop entry %s\n", wine_dbgstr_a(desktopPath));
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
filename = heap_printf("wine/%s.desktop", link);
|
2009-06-18 07:13:02 +02:00
|
|
|
if (!filename || !write_menu_file(unix_link, filename))
|
2008-11-11 20:39:56 +01:00
|
|
|
{
|
|
|
|
WINE_WARN("couldn't make menu file %s\n", wine_dbgstr_a(filename));
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, desktopPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-08 23:20:32 +02:00
|
|
|
/* This escapes reserved characters in .desktop files' Exec keys. */
|
2005-02-17 12:51:44 +01:00
|
|
|
static LPSTR escape(LPCWSTR arg)
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
2010-05-08 23:20:32 +02:00
|
|
|
int i, j;
|
|
|
|
WCHAR *escaped_string;
|
|
|
|
char *utf8_string;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-05-08 23:20:32 +02:00
|
|
|
escaped_string = HeapAlloc(GetProcessHeap(), 0, (4 * strlenW(arg) + 1) * sizeof(WCHAR));
|
|
|
|
if (escaped_string == NULL) return NULL;
|
|
|
|
for (i = j = 0; arg[i]; i++)
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
2010-05-08 23:20:32 +02:00
|
|
|
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;
|
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
}
|
2010-05-08 23:20:32 +02:00
|
|
|
escaped_string[j] = 0;
|
2005-02-17 12:51:44 +01:00
|
|
|
|
2010-05-08 23:20:32 +02:00
|
|
|
utf8_string = wchars_to_utf8_chars(escaped_string);
|
|
|
|
if (utf8_string == NULL)
|
2005-02-18 13:52:33 +01:00
|
|
|
{
|
2010-05-08 23:20:32 +02:00
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2010-05-08 23:20:32 +02:00
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, escaped_string);
|
|
|
|
return utf8_string;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2005-12-19 21:25:52 +01:00
|
|
|
/* Return a heap-allocated copy of the unix format difference between the two
|
|
|
|
* Windows-format paths.
|
|
|
|
* locn is the owning location
|
|
|
|
* link is within locn
|
|
|
|
*/
|
|
|
|
static char *relative_path( LPCWSTR link, LPCWSTR locn )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-12-19 21:25:52 +01:00
|
|
|
char *unix_locn, *unix_link;
|
|
|
|
char *relative = NULL;
|
2005-02-17 12:51:44 +01:00
|
|
|
|
2005-12-19 21:25:52 +01:00
|
|
|
unix_locn = wine_get_unix_file_name(locn);
|
|
|
|
unix_link = wine_get_unix_file_name(link);
|
|
|
|
if (unix_locn && unix_link)
|
2005-02-17 12:51:44 +01:00
|
|
|
{
|
2005-12-19 21:25:52 +01:00
|
|
|
size_t len_unix_locn, len_unix_link;
|
|
|
|
len_unix_locn = strlen (unix_locn);
|
|
|
|
len_unix_link = strlen (unix_link);
|
|
|
|
if (len_unix_locn < len_unix_link && memcmp (unix_locn, unix_link, len_unix_locn) == 0 && unix_link[len_unix_locn] == '/')
|
|
|
|
{
|
|
|
|
size_t len_rel;
|
|
|
|
char *p = strrchr (unix_link + len_unix_locn, '/');
|
|
|
|
p = strrchr (p, '.');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
len_unix_link = p - unix_link;
|
|
|
|
}
|
|
|
|
len_rel = len_unix_link - len_unix_locn;
|
|
|
|
relative = HeapAlloc(GetProcessHeap(), 0, len_rel);
|
|
|
|
if (relative)
|
|
|
|
{
|
|
|
|
memcpy (relative, unix_link + len_unix_locn + 1, len_rel);
|
|
|
|
}
|
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
}
|
2005-12-19 21:25:52 +01:00
|
|
|
if (!relative)
|
|
|
|
WINE_WARN("Could not separate the relative link path of %s in %s\n", wine_dbgstr_w(link), wine_dbgstr_w(locn));
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_locn);
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_link);
|
|
|
|
return relative;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* GetLinkLocation
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
2005-12-19 21:25:52 +01:00
|
|
|
static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *loc, char **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];
|
2004-08-30 21:28:59 +02:00
|
|
|
DWORD len, i, r, 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));
|
|
|
|
|
2003-06-18 21:45:22 +02:00
|
|
|
for( i=0; i<sizeof(locations)/sizeof(locations[0]); 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;
|
2003-05-21 20:50:53 +02:00
|
|
|
/* do a lstrcmpinW */
|
|
|
|
filename[len] = 0;
|
|
|
|
r = lstrcmpiW( filename, buffer );
|
2004-08-30 21:28:59 +02:00
|
|
|
filename[len] = '\\';
|
2003-05-21 20:50:53 +02:00
|
|
|
if ( r )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* return the remainder of the string and link type */
|
|
|
|
*loc = locations[i];
|
2005-12-19 21:25:52 +01:00
|
|
|
*relative = relative_path (filename, buffer);
|
|
|
|
return (*relative != NULL);
|
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++;
|
|
|
|
szCmdline = HeapAlloc( GetProcessHeap(), 0, cmdSize*sizeof(WCHAR) );
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, szCmdline );
|
|
|
|
}
|
2005-11-08 11:55:25 +01:00
|
|
|
LocalFree( dar );
|
|
|
|
}
|
|
|
|
|
|
|
|
IShellLinkDataList_Release( dl );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-06-07 18:32:07 +02:00
|
|
|
static char *slashes_to_minuses(const char *string)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *ret = HeapAlloc(GetProcessHeap(), 0, lstrlenA(string) + 1);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
for (i = 0; string[i]; i++)
|
|
|
|
{
|
|
|
|
if (string[i] == '/')
|
|
|
|
ret[i] = '-';
|
|
|
|
else
|
|
|
|
ret[i] = string[i];
|
|
|
|
}
|
|
|
|
ret[i] = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
*line = HeapAlloc(GetProcessHeap(), 0, *size);
|
|
|
|
}
|
|
|
|
while (*line != NULL)
|
|
|
|
{
|
|
|
|
if (fgets(&(*line)[pos], *size - pos, file) == NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, *line);
|
|
|
|
*line = NULL;
|
|
|
|
if (feof(file))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pos = strlen(*line);
|
|
|
|
cr = strchr(*line, '\n');
|
|
|
|
if (cr == NULL)
|
|
|
|
{
|
|
|
|
char *line2;
|
|
|
|
(*size) *= 2;
|
|
|
|
line2 = HeapReAlloc(GetProcessHeap(), 0, *line, *size);
|
|
|
|
if (line2)
|
|
|
|
*line = line2;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, *line);
|
|
|
|
*line = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*cr = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL add_mimes(const char *xdg_data_dir, struct list *mime_types)
|
|
|
|
{
|
|
|
|
char *globs_filename = NULL;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
globs_filename = heap_printf("%s/mime/globs", xdg_data_dir);
|
|
|
|
if (globs_filename)
|
|
|
|
{
|
|
|
|
FILE *globs_file = fopen(globs_filename, "r");
|
|
|
|
if (globs_file) /* doesn't have to exist */
|
|
|
|
{
|
|
|
|
char *line = NULL;
|
|
|
|
int size = 0;
|
|
|
|
while (ret && (ret = next_line(globs_file, &line, &size)) && line)
|
|
|
|
{
|
|
|
|
char *pos;
|
|
|
|
struct xdg_mime_type *mime_type_entry = NULL;
|
|
|
|
if (line[0] != '#' && (pos = strchr(line, ':')))
|
|
|
|
{
|
|
|
|
mime_type_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(struct xdg_mime_type));
|
|
|
|
if (mime_type_entry)
|
|
|
|
{
|
|
|
|
*pos = 0;
|
2009-07-24 10:41:25 +02:00
|
|
|
mime_type_entry->mimeType = strdupA(line);
|
|
|
|
mime_type_entry->glob = strdupA(pos + 1);
|
2011-08-28 21:21:46 +02:00
|
|
|
mime_type_entry->lower_glob = strdupA(pos + 1);
|
|
|
|
if (mime_type_entry->lower_glob)
|
|
|
|
{
|
|
|
|
char *l;
|
|
|
|
for (l = mime_type_entry->lower_glob; *l; l++)
|
|
|
|
*l = tolower(*l);
|
|
|
|
}
|
|
|
|
if (mime_type_entry->mimeType && mime_type_entry->glob && mime_type_entry->lower_glob)
|
2009-05-19 21:40:41 +02:00
|
|
|
list_add_tail(mime_types, &mime_type_entry->entry);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->mimeType);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->glob);
|
2011-08-28 21:21:46 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->lower_glob);
|
2009-05-19 21:40:41 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry);
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, line);
|
|
|
|
fclose(globs_file);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, globs_filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
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);
|
2009-05-19 21:40:41 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->glob);
|
2011-08-28 21:21:46 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->lower_glob);
|
2009-04-11 10:10:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->mimeType);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 23:23:29 +01:00
|
|
|
static BOOL build_native_mime_types(const char *xdg_data_home, struct list *mime_types)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
|
|
|
char *xdg_data_dirs;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
xdg_data_dirs = getenv("XDG_DATA_DIRS");
|
|
|
|
if (xdg_data_dirs == NULL)
|
|
|
|
xdg_data_dirs = heap_printf("/usr/local/share/:/usr/share/");
|
|
|
|
else
|
2009-07-24 10:41:25 +02:00
|
|
|
xdg_data_dirs = strdupA(xdg_data_dirs);
|
2009-04-11 10:10:59 +02:00
|
|
|
|
|
|
|
if (xdg_data_dirs)
|
|
|
|
{
|
2015-12-21 23:23:29 +01:00
|
|
|
const char *begin;
|
|
|
|
char *end;
|
2009-04-11 10:10:59 +02:00
|
|
|
|
2015-12-21 23:23:29 +01:00
|
|
|
ret = add_mimes(xdg_data_home, mime_types);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
for (begin = xdg_data_dirs; (end = strchr(begin, ':')); begin = end + 1)
|
2009-04-11 10:10:59 +02:00
|
|
|
{
|
2015-12-21 23:23:29 +01:00
|
|
|
*end = '\0';
|
|
|
|
ret = add_mimes(begin, mime_types);
|
|
|
|
*end = ':';
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
2015-12-21 23:23:29 +01:00
|
|
|
if (ret)
|
|
|
|
ret = add_mimes(begin, mime_types);
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, xdg_data_dirs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-27 19:07:32 +02:00
|
|
|
static BOOL match_glob(struct list *native_mime_types, const char *extension,
|
2011-08-28 21:21:46 +02:00
|
|
|
int ignoreGlobCase, char **match)
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2009-06-01 12:51:54 +02:00
|
|
|
#ifdef HAVE_FNMATCH
|
2009-05-27 19:07:32 +02:00
|
|
|
struct xdg_mime_type *mime_type_entry;
|
|
|
|
int matchLength = 0;
|
|
|
|
|
|
|
|
*match = NULL;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(mime_type_entry, native_mime_types, struct xdg_mime_type, entry)
|
|
|
|
{
|
2011-08-28 21:21:46 +02:00
|
|
|
const char *glob = ignoreGlobCase ? mime_type_entry->lower_glob : mime_type_entry->glob;
|
|
|
|
if (fnmatch(glob, extension, 0) == 0)
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2011-08-28 21:21:46 +02:00
|
|
|
if (*match == NULL || matchLength < strlen(glob))
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
|
|
|
*match = mime_type_entry->mimeType;
|
2011-08-28 21:21:46 +02:00
|
|
|
matchLength = strlen(glob);
|
2009-05-27 19:07:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*match != NULL)
|
|
|
|
{
|
2009-07-24 10:41:25 +02:00
|
|
|
*match = strdupA(*match);
|
2009-05-27 19:07:32 +02:00
|
|
|
if (*match == NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-06-01 12:51:54 +02:00
|
|
|
#else
|
|
|
|
*match = NULL;
|
|
|
|
#endif
|
2009-05-27 19:07:32 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL freedesktop_mime_type_for_extension(struct list *native_mime_types,
|
|
|
|
const char *extensionA,
|
|
|
|
LPCWSTR extensionW,
|
|
|
|
char **mime_type)
|
|
|
|
{
|
|
|
|
WCHAR *lower_extensionW;
|
|
|
|
INT len;
|
2011-08-28 21:21:46 +02:00
|
|
|
BOOL ret = match_glob(native_mime_types, extensionA, 0, mime_type);
|
2009-05-27 19:07:32 +02:00
|
|
|
if (ret == FALSE || *mime_type != NULL)
|
|
|
|
return ret;
|
|
|
|
len = strlenW(extensionW);
|
|
|
|
lower_extensionW = HeapAlloc(GetProcessHeap(), 0, (len + 1)*sizeof(WCHAR));
|
|
|
|
if (lower_extensionW)
|
|
|
|
{
|
|
|
|
char *lower_extensionA;
|
|
|
|
memcpy(lower_extensionW, extensionW, (len + 1)*sizeof(WCHAR));
|
|
|
|
strlwrW(lower_extensionW);
|
|
|
|
lower_extensionA = wchars_to_utf8_chars(lower_extensionW);
|
|
|
|
if (lower_extensionA)
|
|
|
|
{
|
2011-08-28 21:21:46 +02:00
|
|
|
ret = match_glob(native_mime_types, lower_extensionA, 1, mime_type);
|
2009-05-27 19:07:32 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lower_extensionA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
WINE_FIXME("out of memory\n");
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, lower_extensionW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = FALSE;
|
|
|
|
WINE_FIXME("out of memory\n");
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
WCHAR *ret = HeapAlloc(GetProcessHeap(), 0, size);
|
2009-06-04 21:57:45 +02:00
|
|
|
if (ret)
|
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
if (RegGetValueW(key, subkey, name, RRF_RT_REG_SZ, NULL, ret, &size) == ERROR_SUCCESS)
|
2009-06-04 21:57:45 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2009-06-06 21:24:20 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-04 21:40:34 +02:00
|
|
|
static CHAR* reg_get_val_utf8(HKEY key, LPCWSTR subkey, LPCWSTR name)
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
WCHAR *valW = reg_get_valW(key, subkey, name);
|
|
|
|
if (valW)
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
char *val = wchars_to_utf8_chars(valW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, valW);
|
|
|
|
return val;
|
2009-06-03 18:33:28 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-04 21:57:45 +02:00
|
|
|
static HKEY open_associations_reg_key(void)
|
|
|
|
{
|
|
|
|
static const WCHAR Software_Wine_FileOpenAssociationsW[] = {
|
|
|
|
'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\','F','i','l','e','O','p','e','n','A','s','s','o','c','i','a','t','i','o','n','s',0};
|
|
|
|
HKEY assocKey;
|
|
|
|
if (RegCreateKeyW(HKEY_CURRENT_USER, Software_Wine_FileOpenAssociationsW, &assocKey) == ERROR_SUCCESS)
|
|
|
|
return assocKey;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-17 11:12:08 +01:00
|
|
|
static BOOL has_association_changed(LPCWSTR extensionW, LPCSTR mimeType, LPCWSTR progId,
|
2011-02-25 16:20:09 +01:00
|
|
|
LPCSTR appName, LPCSTR openWithIcon)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
|
|
|
static const WCHAR ProgIDW[] = {'P','r','o','g','I','D',0};
|
2010-05-04 21:40:34 +02:00
|
|
|
static const WCHAR MimeTypeW[] = {'M','i','m','e','T','y','p','e',0};
|
|
|
|
static const WCHAR AppNameW[] = {'A','p','p','N','a','m','e',0};
|
2010-11-17 11:12:08 +01:00
|
|
|
static const WCHAR OpenWithIconW[] = {'O','p','e','n','W','i','t','h','I','c','o','n',0};
|
2009-06-04 21:57:45 +02:00
|
|
|
HKEY assocKey;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
CHAR *valueA;
|
|
|
|
WCHAR *value;
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
2010-05-04 21:40:34 +02:00
|
|
|
valueA = reg_get_val_utf8(assocKey, extensionW, MimeTypeW);
|
2009-06-04 21:57:45 +02:00
|
|
|
if (!valueA || lstrcmpA(valueA, mimeType))
|
|
|
|
ret = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, valueA);
|
|
|
|
|
|
|
|
value = reg_get_valW(assocKey, extensionW, ProgIDW);
|
|
|
|
if (!value || strcmpW(value, progId))
|
|
|
|
ret = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, value);
|
|
|
|
|
2010-05-04 21:40:34 +02:00
|
|
|
valueA = reg_get_val_utf8(assocKey, extensionW, AppNameW);
|
2009-06-04 21:57:45 +02:00
|
|
|
if (!valueA || lstrcmpA(valueA, appName))
|
|
|
|
ret = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, valueA);
|
|
|
|
|
2010-11-17 11:12:08 +01:00
|
|
|
valueA = reg_get_val_utf8(assocKey, extensionW, OpenWithIconW);
|
|
|
|
if ((openWithIcon && !valueA) ||
|
|
|
|
(!openWithIcon && valueA) ||
|
|
|
|
(openWithIcon && valueA && lstrcmpA(valueA, openWithIcon)))
|
|
|
|
ret = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, valueA);
|
|
|
|
|
2009-06-04 21:57:45 +02:00
|
|
|
RegCloseKey(assocKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_ERR("error opening associations registry key\n");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-17 11:12:08 +01:00
|
|
|
static void update_association(LPCWSTR extension, LPCSTR mimeType, LPCWSTR progId,
|
2011-02-25 16:20:09 +01:00
|
|
|
LPCSTR appName, LPCSTR desktopFile, LPCSTR openWithIcon)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
|
|
|
static const WCHAR ProgIDW[] = {'P','r','o','g','I','D',0};
|
2010-05-04 21:40:34 +02:00
|
|
|
static const WCHAR MimeTypeW[] = {'M','i','m','e','T','y','p','e',0};
|
|
|
|
static const WCHAR AppNameW[] = {'A','p','p','N','a','m','e',0};
|
|
|
|
static const WCHAR DesktopFileW[] = {'D','e','s','k','t','o','p','F','i','l','e',0};
|
2010-11-17 11:12:08 +01:00
|
|
|
static const WCHAR OpenWithIconW[] = {'O','p','e','n','W','i','t','h','I','c','o','n',0};
|
2010-05-04 21:40:34 +02:00
|
|
|
HKEY assocKey = NULL;
|
|
|
|
HKEY subkey = NULL;
|
|
|
|
WCHAR *mimeTypeW = NULL;
|
|
|
|
WCHAR *appNameW = NULL;
|
|
|
|
WCHAR *desktopFileW = NULL;
|
2010-11-17 11:12:08 +01:00
|
|
|
WCHAR *openWithIconW = NULL;
|
2010-05-04 21:40:34 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
mimeTypeW = utf8_chars_to_wchars(mimeType);
|
|
|
|
if (mimeTypeW == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
appNameW = utf8_chars_to_wchars(appName);
|
|
|
|
if (appNameW == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
desktopFileW = utf8_chars_to_wchars(desktopFile);
|
|
|
|
if (desktopFileW == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2010-11-17 11:12:08 +01:00
|
|
|
if (openWithIcon)
|
|
|
|
{
|
|
|
|
openWithIconW = utf8_chars_to_wchars(openWithIcon);
|
|
|
|
if (openWithIconW == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-04 21:40:34 +02:00
|
|
|
RegSetValueExW(subkey, MimeTypeW, 0, REG_SZ, (const BYTE*) mimeTypeW, (lstrlenW(mimeTypeW) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExW(subkey, ProgIDW, 0, REG_SZ, (const BYTE*) progId, (lstrlenW(progId) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExW(subkey, AppNameW, 0, REG_SZ, (const BYTE*) appNameW, (lstrlenW(appNameW) + 1) * sizeof(WCHAR));
|
2010-05-11 22:31:41 +02:00
|
|
|
RegSetValueExW(subkey, DesktopFileW, 0, REG_SZ, (const BYTE*) desktopFileW, (lstrlenW(desktopFileW) + 1) * sizeof(WCHAR));
|
2010-11-17 11:12:08 +01:00
|
|
|
if (openWithIcon)
|
|
|
|
RegSetValueExW(subkey, OpenWithIconW, 0, REG_SZ, (const BYTE*) openWithIconW, (lstrlenW(openWithIconW) + 1) * sizeof(WCHAR));
|
|
|
|
else
|
|
|
|
RegDeleteValueW(subkey, OpenWithIconW);
|
2010-05-04 21:40:34 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
RegCloseKey(assocKey);
|
|
|
|
RegCloseKey(subkey);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mimeTypeW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, appNameW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, desktopFileW);
|
2010-11-17 11:12:08 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, openWithIconW);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL cleanup_associations(void)
|
|
|
|
{
|
2009-06-27 15:28:34 +02:00
|
|
|
static const WCHAR openW[] = {'o','p','e','n',0};
|
2010-05-04 21:40:34 +02:00
|
|
|
static const WCHAR DesktopFileW[] = {'D','e','s','k','t','o','p','F','i','l','e',0};
|
2009-06-04 21:57:45 +02:00
|
|
|
HKEY assocKey;
|
|
|
|
BOOL hasChanged = FALSE;
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL done = FALSE;
|
2011-03-30 16:22:23 +02:00
|
|
|
for (i = 0; !done;)
|
2009-06-04 21:57:45 +02:00
|
|
|
{
|
|
|
|
WCHAR *extensionW = NULL;
|
|
|
|
DWORD size = 1024;
|
|
|
|
LSTATUS ret;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, extensionW);
|
|
|
|
extensionW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (extensionW == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
ret = ERROR_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = RegEnumKeyExW(assocKey, i, extensionW, &size, NULL, NULL, NULL, NULL);
|
|
|
|
size *= 2;
|
|
|
|
} while (ret == ERROR_MORE_DATA);
|
|
|
|
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR *command;
|
2009-06-27 15:28:34 +02:00
|
|
|
command = assoc_query(ASSOCSTR_COMMAND, extensionW, openW);
|
2009-06-04 21:57:45 +02:00
|
|
|
if (command == NULL)
|
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
char *desktopFile = reg_get_val_utf8(assocKey, extensionW, DesktopFileW);
|
2009-06-04 21:57:45 +02:00
|
|
|
if (desktopFile)
|
|
|
|
{
|
2010-05-04 21:40:34 +02:00
|
|
|
WINE_TRACE("removing file type association for %s\n", wine_dbgstr_w(extensionW));
|
2009-06-04 21:57:45 +02:00
|
|
|
remove(desktopFile);
|
|
|
|
}
|
|
|
|
RegDeleteKeyW(assocKey, extensionW);
|
|
|
|
hasChanged = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, desktopFile);
|
|
|
|
}
|
2011-03-30 16:22:23 +02:00
|
|
|
else
|
|
|
|
i++;
|
2009-06-04 21:57:45 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ret != ERROR_NO_MORE_ITEMS)
|
|
|
|
WINE_ERR("error %d while reading registry\n", ret);
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, extensionW);
|
|
|
|
}
|
|
|
|
RegCloseKey(assocKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("could not open file associations key\n");
|
|
|
|
return hasChanged;
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:40:41 +02:00
|
|
|
static BOOL write_freedesktop_mime_type_entry(const char *packages_dir, const char *dot_extension,
|
|
|
|
const char *mime_type, const char *comment)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
WINE_TRACE("writing MIME type %s, extension=%s, comment=%s\n", wine_dbgstr_a(mime_type),
|
|
|
|
wine_dbgstr_a(dot_extension), wine_dbgstr_a(comment));
|
|
|
|
|
|
|
|
filename = heap_printf("%s/x-wine-extension-%s.xml", packages_dir, &dot_extension[1]);
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
FILE *packageFile = fopen(filename, "w");
|
|
|
|
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");
|
2009-11-12 20:42:19 +01:00
|
|
|
fprintf(packageFile, " <mime-type type=\"");
|
|
|
|
write_xml_text(packageFile, mime_type);
|
|
|
|
fprintf(packageFile, "\">\n");
|
|
|
|
fprintf(packageFile, " <glob pattern=\"*");
|
|
|
|
write_xml_text(packageFile, dot_extension);
|
|
|
|
fprintf(packageFile, "\"/>\n");
|
2009-05-19 21:40:41 +02:00
|
|
|
if (comment)
|
2009-11-12 20:42:19 +01:00
|
|
|
{
|
|
|
|
fprintf(packageFile, " <comment>");
|
|
|
|
write_xml_text(packageFile, comment);
|
|
|
|
fprintf(packageFile, "</comment>\n");
|
|
|
|
}
|
2009-05-19 21:40:41 +02:00
|
|
|
fprintf(packageFile, " </mime-type>\n");
|
|
|
|
fprintf(packageFile, "</mime-info>\n");
|
|
|
|
ret = TRUE;
|
|
|
|
fclose(packageFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("error writing file %s\n", filename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-02 19:15:58 +02:00
|
|
|
static BOOL is_extension_blacklisted(LPCWSTR extension)
|
|
|
|
{
|
|
|
|
/* These are managed through external tools like wine.desktop, to evade malware created file type associations */
|
|
|
|
static const WCHAR comW[] = {'.','c','o','m',0};
|
|
|
|
static const WCHAR exeW[] = {'.','e','x','e',0};
|
|
|
|
static const WCHAR msiW[] = {'.','m','s','i',0};
|
|
|
|
|
|
|
|
if (!strcmpiW(extension, comW) ||
|
|
|
|
!strcmpiW(extension, exeW) ||
|
|
|
|
!strcmpiW(extension, msiW))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-05-18 21:33:03 +02:00
|
|
|
static const char* get_special_mime_type(LPCWSTR extension)
|
|
|
|
{
|
|
|
|
static const WCHAR lnkW[] = {'.','l','n','k',0};
|
|
|
|
if (!strcmpiW(extension, lnkW))
|
|
|
|
return "application/x-ms-shortcut";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-03 18:33:28 +02:00
|
|
|
static BOOL write_freedesktop_association_entry(const char *desktopPath, const char *dot_extension,
|
|
|
|
const char *friendlyAppName, const char *mimeType,
|
2010-11-17 11:12:08 +01:00
|
|
|
const char *progId, const char *openWithIcon)
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
FILE *desktop;
|
|
|
|
|
2010-11-17 11:12:08 +01:00
|
|
|
WINE_TRACE("writing association for file type %s, friendlyAppName=%s, MIME type %s, progID=%s, icon=%s to file %s\n",
|
2009-06-03 18:33:28 +02:00
|
|
|
wine_dbgstr_a(dot_extension), wine_dbgstr_a(friendlyAppName), wine_dbgstr_a(mimeType),
|
2010-11-17 11:12:08 +01:00
|
|
|
wine_dbgstr_a(progId), wine_dbgstr_a(openWithIcon), wine_dbgstr_a(desktopPath));
|
2009-06-03 18:33:28 +02:00
|
|
|
|
|
|
|
desktop = fopen(desktopPath, "w");
|
|
|
|
if (desktop)
|
|
|
|
{
|
|
|
|
fprintf(desktop, "[Desktop Entry]\n");
|
|
|
|
fprintf(desktop, "Type=Application\n");
|
|
|
|
fprintf(desktop, "Name=%s\n", friendlyAppName);
|
2010-12-13 18:17:17 +01:00
|
|
|
fprintf(desktop, "MimeType=%s;\n", mimeType);
|
2011-03-22 13:36:45 +01:00
|
|
|
fprintf(desktop, "Exec=env WINEPREFIX=\"%s\" wine start /ProgIDOpen %s %%f\n", wine_get_config_dir(), 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)
|
|
|
|
fprintf(desktop, "Icon=%s\n", openWithIcon);
|
2009-06-03 18:33:28 +02:00
|
|
|
ret = TRUE;
|
|
|
|
fclose(desktop);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("error writing association file %s\n", wine_dbgstr_a(desktopPath));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-11 10:10:59 +02:00
|
|
|
static BOOL generate_associations(const char *xdg_data_home, const char *packages_dir, const char *applications_dir)
|
|
|
|
{
|
2009-06-27 15:28:34 +02:00
|
|
|
static const WCHAR openW[] = {'o','p','e','n',0};
|
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
|
|
|
LSTATUS ret = 0;
|
|
|
|
int i;
|
|
|
|
BOOL hasChanged = FALSE;
|
2009-04-11 10:10:59 +02:00
|
|
|
|
|
|
|
if (!build_native_mime_types(xdg_data_home, &nativeMimeTypes))
|
|
|
|
{
|
|
|
|
WINE_ERR("could not build native MIME types\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-05-19 21:40:41 +02:00
|
|
|
|
|
|
|
for (i = 0; ; i++)
|
|
|
|
{
|
|
|
|
WCHAR *extensionW = NULL;
|
|
|
|
DWORD size = 1024;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, extensionW);
|
|
|
|
extensionW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
|
|
|
|
if (extensionW == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
ret = ERROR_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = RegEnumKeyExW(HKEY_CLASSES_ROOT, i, extensionW, &size, NULL, NULL, NULL, NULL);
|
|
|
|
size *= 2;
|
|
|
|
} while (ret == ERROR_MORE_DATA);
|
|
|
|
|
2009-06-02 19:15:58 +02:00
|
|
|
if (ret == ERROR_SUCCESS && extensionW[0] == '.' && !is_extension_blacklisted(extensionW))
|
2009-05-19 21:40:41 +02:00
|
|
|
{
|
|
|
|
char *extensionA = NULL;
|
|
|
|
WCHAR *commandW = NULL;
|
2010-11-17 11:12:08 +01:00
|
|
|
WCHAR *executableW = NULL;
|
|
|
|
char *openWithIconA = NULL;
|
2009-05-19 21:40:41 +02:00
|
|
|
WCHAR *friendlyDocNameW = NULL;
|
|
|
|
char *friendlyDocNameA = NULL;
|
2009-06-07 18:32:07 +02:00
|
|
|
WCHAR *iconW = NULL;
|
|
|
|
char *iconA = NULL;
|
2009-05-19 21:40:41 +02:00
|
|
|
WCHAR *contentTypeW = NULL;
|
|
|
|
char *mimeTypeA = NULL;
|
2009-06-03 18:33:28 +02:00
|
|
|
WCHAR *friendlyAppNameW = NULL;
|
|
|
|
char *friendlyAppNameA = NULL;
|
|
|
|
WCHAR *progIdW = NULL;
|
|
|
|
char *progIdA = NULL;
|
2010-11-18 10:52:10 +01:00
|
|
|
char *mimeProgId = NULL;
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2011-02-20 19:05:44 +01:00
|
|
|
extensionA = wchars_to_utf8_chars(strlwrW(extensionW));
|
2009-05-19 21:40:41 +02:00
|
|
|
if (extensionA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
friendlyDocNameW = assoc_query(ASSOCSTR_FRIENDLYDOCNAME, extensionW, NULL);
|
|
|
|
if (friendlyDocNameW)
|
|
|
|
{
|
|
|
|
friendlyDocNameA = wchars_to_utf8_chars(friendlyDocNameW);
|
|
|
|
if (friendlyDocNameA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
strlwrW(contentTypeW);
|
2009-05-27 19:07:32 +02:00
|
|
|
|
2015-12-21 23:23:29 +01:00
|
|
|
if (!freedesktop_mime_type_for_extension(&nativeMimeTypes, extensionA, extensionW, &mimeTypeA))
|
2009-05-19 21:40:41 +02:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (mimeTypeA == NULL)
|
2009-05-27 19:07:32 +02:00
|
|
|
{
|
2009-10-22 19:38:37 +02:00
|
|
|
if (contentTypeW != NULL && strchrW(contentTypeW, '/'))
|
2009-05-27 19:07:32 +02:00
|
|
|
mimeTypeA = wchars_to_utf8_chars(contentTypeW);
|
2010-05-18 21:33:03 +02:00
|
|
|
else if ((get_special_mime_type(extensionW)))
|
|
|
|
mimeTypeA = strdupA(get_special_mime_type(extensionW));
|
2009-05-27 19:07:32 +02:00
|
|
|
else
|
|
|
|
mimeTypeA = heap_printf("application/x-wine-extension-%s", &extensionA[1]);
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2009-05-27 19:07:32 +02:00
|
|
|
if (mimeTypeA != NULL)
|
|
|
|
{
|
2012-05-15 10:15:32 +02:00
|
|
|
/* GNOME seems to ignore the <icon> tag in MIME packages,
|
2009-06-07 18:32:07 +02:00
|
|
|
* and the default name is more intuitive anyway.
|
|
|
|
*/
|
2009-06-30 21:04:32 +02:00
|
|
|
if (iconW)
|
2009-06-07 18:32:07 +02:00
|
|
|
{
|
|
|
|
char *flattened_mime = slashes_to_minuses(mimeTypeA);
|
|
|
|
if (flattened_mime)
|
|
|
|
{
|
2009-06-30 21:04:32 +02:00
|
|
|
int index = 0;
|
|
|
|
WCHAR *comma = strrchrW(iconW, ',');
|
|
|
|
if (comma)
|
2009-06-07 18:32:07 +02:00
|
|
|
{
|
2009-06-30 21:04:32 +02:00
|
|
|
*comma = 0;
|
|
|
|
index = atoiW(comma + 1);
|
2009-06-07 18:32:07 +02:00
|
|
|
}
|
2009-06-30 21:04:32 +02:00
|
|
|
iconA = extract_icon(iconW, index, flattened_mime, FALSE);
|
2009-06-07 18:32:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, flattened_mime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-27 19:07:32 +02:00
|
|
|
write_freedesktop_mime_type_entry(packages_dir, extensionA, mimeTypeA, friendlyDocNameA);
|
|
|
|
hasChanged = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_FIXME("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
2009-05-19 21:40:41 +02:00
|
|
|
|
2009-06-27 15:28:34 +02:00
|
|
|
commandW = assoc_query(ASSOCSTR_COMMAND, extensionW, openW);
|
2009-06-03 18:33:28 +02:00
|
|
|
if (commandW == NULL)
|
|
|
|
/* no command => no application is associated */
|
|
|
|
goto end;
|
|
|
|
|
2010-11-17 11:12:08 +01:00
|
|
|
executableW = assoc_query(ASSOCSTR_EXECUTABLE, extensionW, openW);
|
|
|
|
if (executableW)
|
|
|
|
openWithIconA = extract_icon(executableW, 0, NULL, FALSE);
|
|
|
|
|
2011-08-24 04:47:07 +02:00
|
|
|
friendlyAppNameW = assoc_query(ASSOCSTR_FRIENDLYAPPNAME, extensionW, openW);
|
2009-06-03 18:33:28 +02:00
|
|
|
if (friendlyAppNameW)
|
|
|
|
{
|
|
|
|
friendlyAppNameA = wchars_to_utf8_chars(friendlyAppNameW);
|
|
|
|
if (friendlyAppNameA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
friendlyAppNameA = heap_printf("A Wine application");
|
|
|
|
if (friendlyAppNameA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
progIdW = reg_get_valW(HKEY_CLASSES_ROOT, extensionW, NULL);
|
|
|
|
if (progIdW)
|
|
|
|
{
|
2010-05-08 23:20:32 +02:00
|
|
|
progIdA = escape(progIdW);
|
2009-06-03 18:33:28 +02:00
|
|
|
if (progIdA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto end; /* no progID => not a file type association */
|
|
|
|
|
2010-11-18 10:52:10 +01:00
|
|
|
/* Do not allow duplicate ProgIDs for a MIME type, it causes unnecessary duplication in Open dialogs */
|
|
|
|
mimeProgId = heap_printf("%s=>%s", mimeTypeA, progIdA);
|
|
|
|
if (mimeProgId)
|
|
|
|
{
|
|
|
|
struct rb_string_entry *entry;
|
|
|
|
if (wine_rb_get(&mimeProgidTree, mimeProgId))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, mimeProgId);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(struct rb_string_entry));
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory allocating rb_string_entry\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
entry->string = mimeProgId;
|
|
|
|
if (wine_rb_put(&mimeProgidTree, mimeProgId, &entry->entry))
|
|
|
|
{
|
|
|
|
WINE_ERR("error updating rb tree\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 16:20:09 +01:00
|
|
|
if (has_association_changed(extensionW, mimeTypeA, progIdW, friendlyAppNameA, openWithIconA))
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
|
|
|
char *desktopPath = heap_printf("%s/wine-extension-%s.desktop", applications_dir, &extensionA[1]);
|
|
|
|
if (desktopPath)
|
|
|
|
{
|
2010-11-17 11:12:08 +01:00
|
|
|
if (write_freedesktop_association_entry(desktopPath, extensionA, friendlyAppNameA, mimeTypeA, progIdA, openWithIconA))
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
|
|
|
hasChanged = TRUE;
|
2011-02-25 16:20:09 +01:00
|
|
|
update_association(extensionW, mimeTypeA, progIdW, friendlyAppNameA, desktopPath, openWithIconA);
|
2009-06-03 18:33:28 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, desktopPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:40:41 +02:00
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, extensionA);
|
|
|
|
HeapFree(GetProcessHeap(), 0, commandW);
|
2010-11-17 11:12:08 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, executableW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, openWithIconA);
|
2009-05-19 21:40:41 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, friendlyDocNameW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, friendlyDocNameA);
|
2009-06-07 18:32:07 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, iconW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, iconA);
|
2009-05-19 21:40:41 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, contentTypeW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mimeTypeA);
|
2009-06-03 18:33:28 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, friendlyAppNameW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, friendlyAppNameA);
|
|
|
|
HeapFree(GetProcessHeap(), 0, progIdW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, progIdA);
|
2009-05-19 21:40:41 +02:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, extensionW);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-24 21:18:08 +02:00
|
|
|
static char *get_start_exe_path(void)
|
|
|
|
{
|
|
|
|
static const WCHAR startW[] = {'\\','c','o','m','m','a','n','d',
|
|
|
|
'\\','s','t','a','r','t','.','e','x','e',0};
|
|
|
|
WCHAR start_path[MAX_PATH];
|
|
|
|
GetWindowsDirectoryW(start_path, MAX_PATH);
|
|
|
|
lstrcatW(start_path, startW);
|
|
|
|
return escape(start_path);
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:00:39 +02:00
|
|
|
static char* escape_unix_link_arg(LPCSTR unix_link)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
WCHAR *unix_linkW = utf8_chars_to_wchars(unix_link);
|
|
|
|
if (unix_linkW)
|
|
|
|
{
|
|
|
|
char *escaped_lnk = escape(unix_linkW);
|
|
|
|
if (escaped_lnk)
|
|
|
|
{
|
|
|
|
ret = heap_printf("/Unix %s", escaped_lnk);
|
|
|
|
HeapFree(GetProcessHeap(), 0, escaped_lnk);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_linkW);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2006-11-21 00:26:08 +01:00
|
|
|
static const WCHAR startW[] = {'\\','c','o','m','m','a','n','d',
|
|
|
|
'\\','s','t','a','r','t','.','e','x','e',0};
|
2005-02-17 12:51:44 +01:00
|
|
|
char *link_name = NULL, *icon_name = NULL, *work_dir = NULL;
|
2010-05-08 23:20:32 +02:00
|
|
|
char *escaped_path = NULL, *escaped_args = NULL, *description = NULL;
|
2017-09-08 17:54:30 +02:00
|
|
|
char *wmclass = NULL;
|
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;
|
2009-06-18 07:13:02 +02:00
|
|
|
char *unix_link = NULL;
|
2010-05-24 21:18:08 +02:00
|
|
|
char *start_path = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if ( !link )
|
|
|
|
{
|
|
|
|
WINE_ERR("Link name is null\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-12-19 21:25:52 +01:00
|
|
|
if( !GetLinkLocation( 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;
|
|
|
|
}
|
2005-12-19 21:25:52 +01:00
|
|
|
WINE_TRACE("Link : %s\n", wine_dbgstr_a(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
|
|
|
}
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
unix_link = wine_get_unix_file_name(link);
|
|
|
|
if (unix_link == NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("couldn't find unix path of %s\n", wine_dbgstr_w(link));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* check the path */
|
|
|
|
if( szPath[0] )
|
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
static const WCHAR exeW[] = {'.','e','x','e',0};
|
|
|
|
WCHAR *p;
|
2005-02-18 13:52:33 +01:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* check for .exe extension */
|
2006-11-21 00:26:08 +01:00
|
|
|
if (!(p = strrchrW( szPath, '.' )) ||
|
|
|
|
strchrW( p, '\\' ) || strchrW( p, '/' ) ||
|
|
|
|
lstrcmpiW( p, exeW ))
|
|
|
|
{
|
|
|
|
/* Not .exe - use 'start.exe' to launch this file */
|
|
|
|
p = szArgs + lstrlenW(szPath) + 2;
|
|
|
|
if (szArgs[0])
|
|
|
|
{
|
|
|
|
p[0] = ' ';
|
|
|
|
memmove( p+1, szArgs, min( (lstrlenW(szArgs) + 1) * sizeof(szArgs[0]),
|
|
|
|
sizeof(szArgs) - (p + 1 - szArgs) * sizeof(szArgs[0]) ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p[0] = 0;
|
|
|
|
|
|
|
|
szArgs[0] = '"';
|
|
|
|
lstrcpyW(szArgs + 1, szPath);
|
|
|
|
p[-1] = '"';
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(szPath, MAX_PATH);
|
|
|
|
lstrcatW(szPath, startW);
|
|
|
|
}
|
2017-09-08 17:54:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: Use AppUserModelID if present. */
|
|
|
|
WCHAR *p = PathFindFileNameW(szPath);
|
|
|
|
|
|
|
|
lstrcpyW(szWMClass, p);
|
|
|
|
CharLowerW(szWMClass);
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
/* convert app working dir */
|
|
|
|
if (szWorkDir[0])
|
2005-02-17 12:51:44 +01:00
|
|
|
work_dir = wine_get_unix_file_name( szWorkDir );
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* if there's no path... try run the link itself */
|
2005-02-17 12:51:44 +01:00
|
|
|
lstrcpynW(szArgs, link, MAX_PATH);
|
|
|
|
GetWindowsDirectoryW(szPath, MAX_PATH);
|
|
|
|
lstrcatW(szPath, startW);
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* escape the path and parameters */
|
|
|
|
escaped_path = escape(szPath);
|
2005-02-17 12:51:44 +01:00
|
|
|
escaped_args = escape(szArgs);
|
2010-05-08 23:20:32 +02:00
|
|
|
description = wchars_to_utf8_chars(szDescription);
|
2017-09-08 17:54:30 +02:00
|
|
|
wmclass = wchars_to_utf8_chars(szWMClass);
|
|
|
|
if (escaped_path == NULL || escaped_args == NULL || description == NULL || wmclass == NULL)
|
2010-05-08 23:20:32 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("out of memory allocating/escaping parameters\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2010-05-24 21:18:08 +02:00
|
|
|
start_path = get_start_exe_path();
|
|
|
|
if (start_path == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
char *location;
|
|
|
|
const char *lastEntry;
|
|
|
|
lastEntry = strrchr(link_name, '/');
|
|
|
|
if (lastEntry == NULL)
|
|
|
|
lastEntry = link_name;
|
|
|
|
else
|
|
|
|
++lastEntry;
|
2009-03-30 20:06:31 +02:00
|
|
|
location = heap_printf("%s/%s.desktop", xdg_desktop_dir, lastEntry);
|
2008-11-08 10:03:39 +01:00
|
|
|
if (location)
|
|
|
|
{
|
2010-09-30 22:00:39 +02:00
|
|
|
if (csidl == CSIDL_COMMON_DESKTOPDIRECTORY)
|
|
|
|
{
|
|
|
|
char *link_arg = escape_unix_link_arg(unix_link);
|
|
|
|
if (link_arg)
|
|
|
|
{
|
|
|
|
r = !write_desktop_entry(unix_link, location, lastEntry,
|
2017-09-08 17:54:30 +02:00
|
|
|
start_path, link_arg, description, work_dir, icon_name, wmclass);
|
2010-09-30 22:00:39 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, link_arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-09-08 17:54:30 +02:00
|
|
|
r = !write_desktop_entry(NULL, location, lastEntry, escaped_path, escaped_args, description, work_dir, icon_name, wmclass);
|
2010-05-05 22:53:57 +02:00
|
|
|
if (r == 0)
|
|
|
|
chmod(location, 0755);
|
2008-11-08 10:03:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-05-07 08:29:02 +02:00
|
|
|
{
|
2010-09-30 22:00:39 +02:00
|
|
|
char *link_arg = escape_unix_link_arg(unix_link);
|
|
|
|
if (link_arg)
|
2010-05-07 08:29:02 +02:00
|
|
|
{
|
2017-09-08 17:54:30 +02:00
|
|
|
r = !write_menu_entry(unix_link, link_name, start_path, link_arg, description, work_dir, icon_name, wmclass);
|
2010-09-30 22:00:39 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, link_arg);
|
2010-05-07 08:29:02 +02:00
|
|
|
}
|
|
|
|
}
|
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 );
|
2003-05-21 20:50:53 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, icon_name );
|
|
|
|
HeapFree( GetProcessHeap(), 0, work_dir );
|
|
|
|
HeapFree( GetProcessHeap(), 0, link_name );
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, escaped_args );
|
|
|
|
HeapFree( GetProcessHeap(), 0, escaped_path );
|
2010-05-08 23:20:32 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, description );
|
2017-09-08 17:54:30 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, wmclass );
|
2010-05-24 21:18:08 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, unix_link );
|
|
|
|
HeapFree( GetProcessHeap(), 0, start_path );
|
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 )
|
|
|
|
{
|
2010-11-25 07:34:35 +01:00
|
|
|
char *link_name = NULL, *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
|
|
|
char *escaped_urlPath = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hSem = NULL;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
int r = -1;
|
2009-06-18 07:13:02 +02:00
|
|
|
char *unix_link = NULL;
|
2010-11-25 07:34:35 +01:00
|
|
|
IPropertySetStorage *pPropSetStg;
|
|
|
|
IPropertyStorage *pPropStg;
|
|
|
|
PROPSPEC ps[2];
|
|
|
|
PROPVARIANT pv[2];
|
2011-08-11 20:21:25 +02:00
|
|
|
char *start_path = NULL;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !GetLinkLocation( link, &csidl, &link_name ) )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
WINE_TRACE("Link : %s\n", wine_dbgstr_a(link_name));
|
|
|
|
|
|
|
|
hr = url->lpVtbl->GetURL(url, &urlPath);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
WINE_TRACE("path : %s\n", wine_dbgstr_w(urlPath));
|
|
|
|
|
2009-06-18 07:13:02 +02:00
|
|
|
unix_link = wine_get_unix_file_name(link);
|
|
|
|
if (unix_link == NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("couldn't find unix path of %s\n", wine_dbgstr_w(link));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-11-13 07:19:25 +01:00
|
|
|
escaped_urlPath = escape(urlPath);
|
2010-05-08 23:20:32 +02:00
|
|
|
if (escaped_urlPath == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("couldn't escape url, out of memory\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-11-13 07:19:25 +01:00
|
|
|
|
2011-08-11 20:21:25 +02:00
|
|
|
start_path = get_start_exe_path();
|
|
|
|
if (start_path == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
{
|
2012-09-19 21:48:16 +02:00
|
|
|
if (pv[0].vt == VT_LPWSTR && pv[0].u.pwszVal && pv[0].u.pwszVal[0])
|
2011-01-09 17:02:54 +01:00
|
|
|
{
|
2012-09-19 21:48:16 +02:00
|
|
|
has_icon = TRUE;
|
2011-01-09 17:02:54 +01:00
|
|
|
icon_name = extract_icon( pv[0].u.pwszVal, pv[1].u.iVal, NULL, bWait );
|
2010-11-25 07:34:35 +01:00
|
|
|
|
2011-01-09 17:02:54 +01:00
|
|
|
WINE_TRACE("URL icon path: %s icon index: %d icon name: %s\n", wine_dbgstr_w(pv[0].u.pwszVal), pv[1].u.iVal, icon_name);
|
|
|
|
}
|
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",
|
2011-01-04 15:58:22 +01:00
|
|
|
wine_dbgstr_w( pv[0].u.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))
|
|
|
|
{
|
|
|
|
char *location;
|
|
|
|
const char *lastEntry;
|
|
|
|
lastEntry = strrchr(link_name, '/');
|
|
|
|
if (lastEntry == NULL)
|
|
|
|
lastEntry = link_name;
|
|
|
|
else
|
|
|
|
++lastEntry;
|
2009-03-30 20:06:31 +02:00
|
|
|
location = heap_printf("%s/%s.desktop", xdg_desktop_dir, lastEntry);
|
2008-11-13 07:19:25 +01:00
|
|
|
if (location)
|
|
|
|
{
|
2017-09-08 17:54:30 +02:00
|
|
|
r = !write_desktop_entry(NULL, location, lastEntry, start_path, escaped_urlPath, NULL, NULL, icon_name, NULL);
|
2010-05-05 22:53:57 +02:00
|
|
|
if (r == 0)
|
|
|
|
chmod(location, 0755);
|
2008-11-13 07:19:25 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-09-08 17:54:30 +02:00
|
|
|
r = !write_menu_entry(unix_link, link_name, start_path, escaped_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);
|
2010-11-25 07:34:35 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, icon_name );
|
2008-11-13 07:19:25 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, link_name);
|
|
|
|
CoTaskMemFree( urlPath );
|
|
|
|
HeapFree(GetProcessHeap(), 0, escaped_urlPath);
|
2009-06-18 07:13:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, unix_link);
|
2008-11-13 07:19:25 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
WINE_ERR("CreateToolhelp32Snapshot failed, error %d\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
procentry.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
rc = Process32First( hsnapshot, &procentry );
|
|
|
|
while (rc)
|
|
|
|
{
|
|
|
|
if (procentry.th32ProcessID == ourpid) break;
|
|
|
|
rc = Process32Next( hsnapshot, &procentry );
|
|
|
|
}
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
WINE_WARN("Unable to find current process id %d when listing processes\n", ourpid);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((hprocess = OpenProcess( SYNCHRONIZE, FALSE, procentry.th32ParentProcessID )) ==
|
|
|
|
NULL)
|
|
|
|
{
|
|
|
|
WINE_WARN("OpenProcess failed pid=%d, error %d\n", procentry.th32ParentProcessID,
|
|
|
|
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
|
|
|
|
WINE_ERR("Unable to wait for parent process, error %d\n", GetLastError());
|
|
|
|
|
|
|
|
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;
|
|
|
|
char *mime_dir = NULL;
|
|
|
|
char *packages_dir = NULL;
|
|
|
|
char *applications_dir = NULL;
|
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);
|
|
|
|
hSem = NULL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
mime_dir = heap_printf("%s/mime", xdg_data_dir);
|
|
|
|
if (mime_dir == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
create_directories(mime_dir);
|
|
|
|
|
|
|
|
packages_dir = heap_printf("%s/packages", mime_dir);
|
|
|
|
if (packages_dir == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
create_directories(packages_dir);
|
|
|
|
|
|
|
|
applications_dir = heap_printf("%s/applications", xdg_data_dir);
|
|
|
|
if (applications_dir == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
create_directories(applications_dir);
|
|
|
|
|
2009-05-19 21:40:41 +02:00
|
|
|
hasChanged = generate_associations(xdg_data_dir, 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";
|
|
|
|
argv[1] = mime_dir;
|
|
|
|
argv[2] = NULL;
|
2013-04-09 13:50:40 +02:00
|
|
|
_spawnvp( _P_DETACH, argv[0], argv );
|
2009-06-30 14:27:35 +02:00
|
|
|
|
|
|
|
argv[0] = "update-desktop-database";
|
|
|
|
argv[1] = applications_dir;
|
2013-04-09 13:50:40 +02:00
|
|
|
_spawnvp( _P_DETACH, argv[0], argv );
|
2009-05-19 21:40:41 +02:00
|
|
|
}
|
2009-04-11 10:10:59 +02:00
|
|
|
|
2009-04-05 08:14:53 +02:00
|
|
|
end:
|
|
|
|
if (hSem)
|
|
|
|
{
|
|
|
|
ReleaseSemaphore(hSem, 1, NULL);
|
|
|
|
CloseHandle(hSem);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_dir);
|
|
|
|
HeapFree(GetProcessHeap(), 0, packages_dir);
|
|
|
|
HeapFree(GetProcessHeap(), 0, applications_dir);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
lret = ERROR_OUTOFMEMORY;
|
2010-05-03 20:58:16 +02:00
|
|
|
value = HeapAlloc(GetProcessHeap(), 0, valueSize * sizeof(WCHAR));
|
2009-06-18 07:13:02 +02:00
|
|
|
if (value == NULL)
|
|
|
|
break;
|
2010-05-03 20:58:16 +02:00
|
|
|
data = HeapAlloc(GetProcessHeap(), 0, dataSize * sizeof(WCHAR));
|
2009-06-18 07:13:02 +02:00
|
|
|
if (data == NULL)
|
|
|
|
break;
|
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;
|
|
|
|
HeapFree(GetProcessHeap(), 0, value);
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
value = data = NULL;
|
|
|
|
}
|
|
|
|
if (lret == ERROR_SUCCESS)
|
|
|
|
{
|
2010-05-03 20:58:16 +02:00
|
|
|
char *unix_file;
|
|
|
|
char *windows_file;
|
|
|
|
unix_file = wchars_to_unix_chars(value);
|
|
|
|
windows_file = wchars_to_unix_chars(data);
|
|
|
|
if (unix_file != NULL && windows_file != NULL)
|
2009-06-18 07:13:02 +02:00
|
|
|
{
|
2010-05-03 20:58:16 +02:00
|
|
|
struct stat filestats;
|
|
|
|
if (stat(windows_file, &filestats) < 0 && errno == ENOENT)
|
|
|
|
{
|
|
|
|
WINE_TRACE("removing menu related file %s\n", unix_file);
|
|
|
|
remove(unix_file);
|
|
|
|
RegDeleteValueW(hkey, value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
2009-06-18 07:13:02 +02:00
|
|
|
}
|
|
|
|
else
|
2010-05-03 20:58:16 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("out of memory enumerating menus\n");
|
|
|
|
lret = ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_file);
|
|
|
|
HeapFree(GetProcessHeap(), 0, windows_file);
|
2009-06-18 07:13:02 +02:00
|
|
|
}
|
|
|
|
else if (lret != ERROR_NO_MORE_ITEMS)
|
2010-05-03 20:58:16 +02:00
|
|
|
WINE_ERR("error %d reading registry\n", lret);
|
2009-06-18 07:13:02 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, value);
|
|
|
|
HeapFree(GetProcessHeap(), 0, data);
|
|
|
|
}
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("error opening registry key, menu cleanup failed\n");
|
|
|
|
}
|
|
|
|
|
2010-07-26 06:52:38 +02:00
|
|
|
static void thumbnail_lnk(LPCWSTR lnkPath, LPCWSTR outputPath)
|
|
|
|
{
|
|
|
|
char *utf8lnkPath = NULL;
|
|
|
|
char *utf8OutputPath = 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);
|
|
|
|
if (utf8lnkPath == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory converting paths\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
utf8OutputPath = wchars_to_utf8_chars(outputPath);
|
|
|
|
if (utf8OutputPath == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory converting paths\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
WINE_ERR("could not create IShellLinkW, error 0x%08X\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IShellLinkW_QueryInterface(shellLink, &IID_IPersistFile, (LPVOID)&persistFile);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("could not query IPersistFile, error 0x%08X\n", hr);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IPersistFile_Load(persistFile, winLnkPath, STGM_READ);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WINE_ERR("could not read .lnk, error 0x%08X\n", hr);
|
|
|
|
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))
|
2015-03-16 17:44:43 +01:00
|
|
|
hr = write_native_icon(stream, pIconDirEntries, numEntries, utf8OutputPath, NULL);
|
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))
|
2015-03-16 17:44:43 +01:00
|
|
|
hr = write_native_icon(stream, pIconDirEntries, numEntries, utf8OutputPath, NULL);
|
2010-07-26 06:52:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, utf8lnkPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, utf8OutputPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, winLnkPath);
|
|
|
|
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);
|
2015-03-16 17:44:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, 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;
|
2010-05-04 21:38:21 +02:00
|
|
|
t = strchrW( token, '"' );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( t )
|
|
|
|
*t++ = 0;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
t = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
token = t;
|
2010-05-04 21:38:21 +02:00
|
|
|
t = strchrW( 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)
|
|
|
|
{
|
2009-03-30 20:06:31 +02:00
|
|
|
WCHAR shellDesktopPath[MAX_PATH];
|
|
|
|
HRESULT hr = SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, SHGFP_TYPE_CURRENT, shellDesktopPath);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
xdg_desktop_dir = wine_get_unix_file_name(shellDesktopPath);
|
|
|
|
if (xdg_desktop_dir == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("error looking up the desktop directory\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:10:40 +01:00
|
|
|
if (getenv("XDG_CONFIG_HOME"))
|
|
|
|
xdg_config_dir = heap_printf("%s/menus/applications-merged", getenv("XDG_CONFIG_HOME"));
|
|
|
|
else
|
|
|
|
xdg_config_dir = heap_printf("%s/.config/menus/applications-merged", getenv("HOME"));
|
|
|
|
if (xdg_config_dir)
|
|
|
|
{
|
2008-12-16 15:08:49 +01:00
|
|
|
create_directories(xdg_config_dir);
|
2008-11-02 14:10:40 +01:00
|
|
|
if (getenv("XDG_DATA_HOME"))
|
2009-07-24 10:41:25 +02:00
|
|
|
xdg_data_dir = strdupA(getenv("XDG_DATA_HOME"));
|
2008-11-02 14:10:40 +01:00
|
|
|
else
|
|
|
|
xdg_data_dir = heap_printf("%s/.local/share", getenv("HOME"));
|
|
|
|
if (xdg_data_dir)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
create_directories(xdg_data_dir);
|
|
|
|
buffer = heap_printf("%s/desktop-directories", xdg_data_dir);
|
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
mkdir(buffer, 0777);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, xdg_config_dir);
|
|
|
|
}
|
2009-03-30 20:06:31 +02:00
|
|
|
WINE_ERR("out of memory\n");
|
2008-11-02 14:10:40 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static const WCHAR dash_aW[] = {'-','a',0};
|
|
|
|
static const WCHAR dash_rW[] = {'-','r',0};
|
2010-07-26 06:52:38 +02:00
|
|
|
static const WCHAR dash_tW[] = {'-','t',0};
|
2010-05-04 21:38:21 +02:00
|
|
|
static const WCHAR dash_uW[] = {'-','u',0};
|
|
|
|
static const WCHAR dash_wW[] = {'-','w',0};
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
WINE_ERR("could not initialize COM, error 0x%08X\n", hr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
for( p = cmdline; p && *p; )
|
|
|
|
{
|
|
|
|
token = next_token( &p );
|
|
|
|
if( !token )
|
|
|
|
break;
|
2010-05-04 21:38:21 +02:00
|
|
|
if( !strcmpW( token, dash_aW ) )
|
2009-04-05 08:14:53 +02:00
|
|
|
{
|
|
|
|
RefreshFileTypeAssociations();
|
2009-06-25 21:01:59 +02:00
|
|
|
continue;
|
2009-04-05 08:14:53 +02:00
|
|
|
}
|
2010-05-04 21:38:21 +02:00
|
|
|
if( !strcmpW( token, dash_rW ) )
|
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
|
|
|
}
|
2010-05-04 21:38:21 +02:00
|
|
|
if( !strcmpW( token, dash_wW ) )
|
2007-06-28 03:23:33 +02:00
|
|
|
bWait = TRUE;
|
2010-05-04 21:38:21 +02:00
|
|
|
else if ( !strcmpW( token, dash_uW ) )
|
2008-11-13 07:19:25 +01:00
|
|
|
bURL = TRUE;
|
2010-07-26 06:52:38 +02:00
|
|
|
else if ( !strcmpW( token, dash_tW ) )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|