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
|
2008-11-11 20:39:56 +01: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-07 18:32:07 +02:00
|
|
|
* Clean up fd.o menus when they are deleted in Windows.
|
|
|
|
* Generate icons for file open handlers to go into the "Open with..."
|
|
|
|
* list. What does Windows use, the default icon for the .EXE file? It's
|
|
|
|
* not in the registry.
|
|
|
|
* 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
|
|
|
|
|
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>
|
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"
|
2003-12-08 22:44:24 +01:00
|
|
|
#include "wine.xpm"
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
#ifdef HAVE_PNG_H
|
|
|
|
#undef FAR
|
|
|
|
#include <png.h>
|
|
|
|
#endif
|
|
|
|
|
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)
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
/* Icon extraction routines
|
|
|
|
*
|
|
|
|
* FIXME: should use PrivateExtractIcons and friends
|
|
|
|
* FIXME: should not use stdio
|
|
|
|
*/
|
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
#define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
|
|
|
|
|
|
|
|
/* PNG-specific code */
|
|
|
|
#ifdef SONAME_LIBPNG
|
|
|
|
|
|
|
|
static void *libpng_handle;
|
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f
|
|
|
|
MAKE_FUNCPTR(png_create_info_struct);
|
|
|
|
MAKE_FUNCPTR(png_create_write_struct);
|
|
|
|
MAKE_FUNCPTR(png_destroy_write_struct);
|
|
|
|
MAKE_FUNCPTR(png_init_io);
|
|
|
|
MAKE_FUNCPTR(png_set_bgr);
|
|
|
|
MAKE_FUNCPTR(png_set_text);
|
|
|
|
MAKE_FUNCPTR(png_set_IHDR);
|
|
|
|
MAKE_FUNCPTR(png_write_end);
|
|
|
|
MAKE_FUNCPTR(png_write_info);
|
|
|
|
MAKE_FUNCPTR(png_write_row);
|
|
|
|
#undef MAKE_FUNCPTR
|
|
|
|
|
|
|
|
static void *load_libpng(void)
|
|
|
|
{
|
|
|
|
if ((libpng_handle = wine_dlopen(SONAME_LIBPNG, RTLD_NOW, NULL, 0)) != NULL)
|
|
|
|
{
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if((p##f = wine_dlsym(libpng_handle, #f, NULL, 0)) == NULL) { \
|
|
|
|
libpng_handle = NULL; \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
LOAD_FUNCPTR(png_create_info_struct);
|
|
|
|
LOAD_FUNCPTR(png_create_write_struct);
|
|
|
|
LOAD_FUNCPTR(png_destroy_write_struct);
|
|
|
|
LOAD_FUNCPTR(png_init_io);
|
|
|
|
LOAD_FUNCPTR(png_set_bgr);
|
|
|
|
LOAD_FUNCPTR(png_set_IHDR);
|
|
|
|
LOAD_FUNCPTR(png_set_text);
|
|
|
|
LOAD_FUNCPTR(png_write_end);
|
|
|
|
LOAD_FUNCPTR(png_write_info);
|
|
|
|
LOAD_FUNCPTR(png_write_row);
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
}
|
|
|
|
return libpng_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL SaveIconResAsPNG(const BITMAPINFO *pIcon, const char *png_filename, LPCWSTR commentW)
|
|
|
|
{
|
|
|
|
static const char comment_key[] = "Created from";
|
|
|
|
FILE *fp;
|
|
|
|
png_structp png_ptr;
|
|
|
|
png_infop info_ptr;
|
|
|
|
png_text comment;
|
|
|
|
int nXORWidthBytes, nANDWidthBytes, color_type = 0, i, j;
|
2008-05-13 20:26:57 +02:00
|
|
|
BYTE *row, *copy = NULL;
|
|
|
|
const BYTE *pXOR, *pAND = NULL;
|
2008-03-23 21:16:38 +01:00
|
|
|
int nWidth = pIcon->bmiHeader.biWidth;
|
|
|
|
int nHeight = pIcon->bmiHeader.biHeight;
|
|
|
|
int nBpp = pIcon->bmiHeader.biBitCount;
|
|
|
|
|
|
|
|
switch (nBpp)
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
color_type |= PNG_COLOR_MASK_ALPHA;
|
|
|
|
/* fall through */
|
|
|
|
case 24:
|
|
|
|
color_type |= PNG_COLOR_MASK_COLOR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!libpng_handle && !load_libpng())
|
|
|
|
{
|
|
|
|
WINE_WARN("Unable to load libpng\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(fp = fopen(png_filename, "w")))
|
|
|
|
{
|
|
|
|
WINE_ERR("unable to open '%s' for writing: %s\n", png_filename, strerror(errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nXORWidthBytes = 4 * ((nWidth * nBpp + 31) / 32);
|
|
|
|
nANDWidthBytes = 4 * ((nWidth + 31 ) / 32);
|
2008-05-13 20:26:57 +02:00
|
|
|
pXOR = (const BYTE*) pIcon + sizeof(BITMAPINFOHEADER) + pIcon->bmiHeader.biClrUsed * sizeof(RGBQUAD);
|
2008-03-23 21:16:38 +01:00
|
|
|
if (nHeight > nWidth)
|
|
|
|
{
|
|
|
|
nHeight /= 2;
|
|
|
|
pAND = pXOR + nHeight * nXORWidthBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Apply mask if present */
|
|
|
|
if (pAND)
|
|
|
|
{
|
|
|
|
RGBQUAD bgColor;
|
|
|
|
|
2008-05-13 20:26:57 +02:00
|
|
|
/* copy bytes before modifying them */
|
|
|
|
copy = HeapAlloc( GetProcessHeap(), 0, nHeight * nXORWidthBytes );
|
|
|
|
memcpy( copy, pXOR, nHeight * nXORWidthBytes );
|
|
|
|
pXOR = copy;
|
|
|
|
|
|
|
|
/* image and mask are upside down reversed */
|
|
|
|
row = copy + (nHeight - 1) * nXORWidthBytes;
|
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
/* top left corner */
|
|
|
|
bgColor.rgbRed = row[0];
|
|
|
|
bgColor.rgbGreen = row[1];
|
|
|
|
bgColor.rgbBlue = row[2];
|
|
|
|
bgColor.rgbReserved = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nHeight; i++, row -= nXORWidthBytes)
|
|
|
|
for (j = 0; j < nWidth; j++, row += nBpp >> 3)
|
|
|
|
if (MASK(j, i))
|
|
|
|
{
|
|
|
|
RGBQUAD *pixel = (RGBQUAD *)row;
|
|
|
|
pixel->rgbBlue = bgColor.rgbBlue;
|
|
|
|
pixel->rgbGreen = bgColor.rgbGreen;
|
|
|
|
pixel->rgbRed = bgColor.rgbRed;
|
|
|
|
if (nBpp == 32)
|
|
|
|
pixel->rgbReserved = bgColor.rgbReserved;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
comment.text = NULL;
|
|
|
|
|
|
|
|
if (!(png_ptr = ppng_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)) ||
|
|
|
|
!(info_ptr = ppng_create_info_struct(png_ptr)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (setjmp(png_jmpbuf(png_ptr)))
|
|
|
|
{
|
|
|
|
/* All future errors jump here */
|
|
|
|
WINE_ERR("png error\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ppng_init_io(png_ptr, fp);
|
|
|
|
ppng_set_IHDR(png_ptr, info_ptr, nWidth, nHeight, 8,
|
|
|
|
color_type,
|
|
|
|
PNG_INTERLACE_NONE,
|
|
|
|
PNG_COMPRESSION_TYPE_DEFAULT,
|
|
|
|
PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
|
|
|
|
/* Set comment */
|
|
|
|
comment.compression = PNG_TEXT_COMPRESSION_NONE;
|
|
|
|
comment.key = (png_charp)comment_key;
|
|
|
|
i = WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, NULL, 0, NULL, NULL);
|
|
|
|
comment.text = HeapAlloc(GetProcessHeap(), 0, i);
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, comment.text, i, NULL, NULL);
|
|
|
|
comment.text_length = i - 1;
|
|
|
|
ppng_set_text(png_ptr, info_ptr, &comment, 1);
|
|
|
|
|
|
|
|
|
|
|
|
ppng_write_info(png_ptr, info_ptr);
|
|
|
|
ppng_set_bgr(png_ptr);
|
|
|
|
for (i = nHeight - 1; i >= 0 ; i--)
|
|
|
|
ppng_write_row(png_ptr, (png_bytep)pXOR + nXORWidthBytes * i);
|
|
|
|
ppng_write_end(png_ptr, info_ptr);
|
|
|
|
|
|
|
|
ppng_destroy_write_struct(&png_ptr, &info_ptr);
|
|
|
|
if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL);
|
|
|
|
fclose(fp);
|
2008-05-13 20:26:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, copy);
|
2008-03-23 21:16:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, comment.text);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (png_ptr) ppng_destroy_write_struct(&png_ptr, NULL);
|
|
|
|
fclose(fp);
|
|
|
|
unlink(png_filename);
|
2008-05-13 20:26:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, copy);
|
2008-03-23 21:16:38 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, comment.text);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif /* SONAME_LIBPNG */
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, LPCWSTR commentW)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
FILE *fXPMFile;
|
|
|
|
int nHeight;
|
|
|
|
int nXORWidthBytes;
|
|
|
|
int nANDWidthBytes;
|
|
|
|
BOOL b8BitColors;
|
|
|
|
int nColors;
|
2004-11-30 22:38:57 +01:00
|
|
|
const BYTE *pXOR;
|
|
|
|
const BYTE *pAND;
|
2003-05-21 20:50:53 +02:00
|
|
|
BOOL aColorUsed[256] = {0};
|
|
|
|
int nColorsUsed = 0;
|
|
|
|
int i,j;
|
2005-02-17 12:51:44 +01:00
|
|
|
char *comment;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
|
2006-01-17 13:34:31 +01:00
|
|
|
{
|
|
|
|
WINE_FIXME("Unsupported color depth %d-bit\n", pIcon->bmiHeader.biBitCount);
|
2003-05-21 20:50:53 +02:00
|
|
|
return FALSE;
|
2006-01-17 13:34:31 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if (!(fXPMFile = fopen(szXPMFileName, "w")))
|
2006-01-03 12:09:47 +01:00
|
|
|
{
|
|
|
|
WINE_TRACE("unable to open '%s' for writing: %s\n", szXPMFileName, strerror(errno));
|
2003-05-21 20:50:53 +02:00
|
|
|
return FALSE;
|
2006-01-03 12:09:47 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
i = WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, NULL, 0, NULL, NULL);
|
2006-01-17 13:34:31 +01:00
|
|
|
comment = HeapAlloc(GetProcessHeap(), 0, i);
|
2005-02-17 12:51:44 +01:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, comment, i, NULL, NULL);
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
nHeight = pIcon->bmiHeader.biHeight / 2;
|
|
|
|
nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
|
|
|
|
+ ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
|
|
|
|
nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
|
|
|
|
+ ((pIcon->bmiHeader.biWidth % 32) > 0));
|
|
|
|
b8BitColors = pIcon->bmiHeader.biBitCount == 8;
|
|
|
|
nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
|
|
|
|
: 1 << pIcon->bmiHeader.biBitCount;
|
2004-11-30 22:38:57 +01:00
|
|
|
pXOR = (const BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
|
2003-05-21 20:50:53 +02:00
|
|
|
pAND = pXOR + nHeight * nXORWidthBytes;
|
|
|
|
|
|
|
|
#define COLOR(x,y) (b8BitColors ? pXOR[(x) + (nHeight - (y) - 1) * nXORWidthBytes] : (x) % 2 ? pXOR[(x) / 2 + (nHeight - (y) - 1) * nXORWidthBytes] & 0xF : (pXOR[(x) / 2 + (nHeight - (y) - 1) * nXORWidthBytes] & 0xF0) >> 4)
|
|
|
|
|
|
|
|
for (i = 0; i < nHeight; i++) {
|
|
|
|
for (j = 0; j < pIcon->bmiHeader.biWidth; j++) {
|
|
|
|
if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
|
|
|
|
{
|
|
|
|
aColorUsed[COLOR(j,i)] = TRUE;
|
|
|
|
nColorsUsed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fprintf(fXPMFile, "/* XPM */\n/* %s */\nstatic char *icon[] = {\n", comment) <= 0)
|
|
|
|
goto error;
|
|
|
|
if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
|
|
|
|
(int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < nColors; i++) {
|
|
|
|
if (aColorUsed[i])
|
|
|
|
if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
|
|
|
|
pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (fprintf(fXPMFile, "\" c None\"") <= 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < nHeight; i++)
|
|
|
|
{
|
|
|
|
if (fprintf(fXPMFile, ",\n\"") <= 0)
|
|
|
|
goto error;
|
|
|
|
for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
|
|
|
|
{
|
|
|
|
if MASK(j,i)
|
|
|
|
{
|
|
|
|
if (fprintf(fXPMFile, " ") <= 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (fprintf(fXPMFile, "\"") <= 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (fprintf(fXPMFile, "};\n") <= 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
#undef MASK
|
|
|
|
#undef COLOR
|
|
|
|
|
2006-01-17 13:34:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, comment);
|
2003-05-21 20:50:53 +02:00
|
|
|
fclose(fXPMFile);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
2006-01-17 13:34:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, comment);
|
2003-05-21 20:50:53 +02:00
|
|
|
fclose(fXPMFile);
|
|
|
|
unlink( szXPMFileName );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
static BOOL extract_icon32(LPCWSTR szFileName, int nIndex, char *szXPMFileName)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
HMODULE hModule;
|
|
|
|
HRSRC hResInfo;
|
2005-02-17 12:51:44 +01:00
|
|
|
LPCWSTR lpName = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
HGLOBAL hResData;
|
|
|
|
GRPICONDIR *pIconDir;
|
|
|
|
BITMAPINFO *pIcon;
|
|
|
|
ENUMRESSTRUCT sEnumRes;
|
|
|
|
int nMax = 0;
|
|
|
|
int nMaxBits = 0;
|
|
|
|
int i;
|
2005-02-17 12:51:44 +01:00
|
|
|
BOOL ret = FALSE;
|
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
|
|
|
{
|
2006-11-24 23:39:51 +01:00
|
|
|
WINE_WARN("LoadLibraryExW (%s) failed, error %d\n",
|
2005-02-17 12:51:44 +01:00
|
|
|
wine_dbgstr_w(szFileName), GetLastError());
|
2005-02-16 17:04:05 +01:00
|
|
|
return FALSE;
|
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)))
|
|
|
|
{
|
|
|
|
for (i = 0; i < pIconDir->idCount; i++)
|
|
|
|
{
|
2008-12-27 13:37:48 +01:00
|
|
|
if (pIconDir->idEntries[i].wBitCount >= nMaxBits)
|
2005-08-22 11:17:25 +02:00
|
|
|
{
|
|
|
|
if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) >= nMax)
|
|
|
|
{
|
|
|
|
lpName = MAKEINTRESOURCEW(pIconDir->idEntries[i].nID);
|
|
|
|
nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
|
2008-12-27 13:37:48 +01:00
|
|
|
nMaxBits = pIconDir->idEntries[i].wBitCount;
|
2005-08-22 11:17:25 +02:00
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
|
|
|
|
if ((hResInfo = FindResourceW(hModule, lpName, (LPCWSTR)RT_ICON)))
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
if ((hResData = LoadResource(hModule, hResInfo)))
|
|
|
|
{
|
|
|
|
if ((pIcon = LockResource(hResData)))
|
|
|
|
{
|
2008-03-23 21:16:38 +01:00
|
|
|
#ifdef SONAME_LIBPNG
|
|
|
|
if (SaveIconResAsPNG(pIcon, szXPMFileName, szFileName))
|
2005-02-17 12:51:44 +01:00
|
|
|
ret = TRUE;
|
2008-03-23 21:16:38 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
memcpy(szXPMFileName + strlen(szXPMFileName) - 3, "xpm", 3);
|
|
|
|
if (SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
FreeLibrary(hModule);
|
2005-02-17 12:51:44 +01:00
|
|
|
return ret;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
static BOOL ExtractFromEXEDLL(LPCWSTR szFileName, int nIndex, char *szXPMFileName)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
if (!extract_icon32(szFileName, nIndex, szXPMFileName) /*&&
|
|
|
|
!extract_icon16(szFileName, szXPMFileName)*/)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
static int ExtractFromICO(LPCWSTR szFileName, char *szXPMFileName)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2008-03-23 21:16:38 +01:00
|
|
|
FILE *fICOFile = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
ICONDIR iconDir;
|
2008-03-23 21:16:38 +01:00
|
|
|
ICONDIRENTRY *pIconDirEntry = NULL;
|
2006-11-30 01:54:06 +01:00
|
|
|
int nMax = 0, nMaxBits = 0;
|
2003-05-21 20:50:53 +02:00
|
|
|
int nIndex = 0;
|
2008-03-23 21:16:38 +01:00
|
|
|
void *pIcon = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
int i;
|
2008-03-23 21:16:38 +01:00
|
|
|
char *filename = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
filename = wine_get_unix_file_name(szFileName);
|
2003-05-21 20:50:53 +02:00
|
|
|
if (!(fICOFile = fopen(filename, "r")))
|
2006-01-03 12:09:47 +01:00
|
|
|
{
|
|
|
|
WINE_TRACE("unable to open '%s' for reading: %s\n", filename, strerror(errno));
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2006-01-03 12:09:47 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2006-01-17 13:34:31 +01:00
|
|
|
if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1 ||
|
|
|
|
(iconDir.idReserved != 0) || (iconDir.idType != 1))
|
|
|
|
{
|
2006-11-24 23:39:51 +01:00
|
|
|
WINE_WARN("Invalid ico file format\n");
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2006-01-17 13:34:31 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2006-01-17 13:34:31 +01:00
|
|
|
if ((pIconDirEntry = HeapAlloc(GetProcessHeap(), 0, iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2003-05-21 20:50:53 +02:00
|
|
|
if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
for (i = 0; i < iconDir.idCount; 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);
|
|
|
|
|
2006-01-17 13:34:31 +01:00
|
|
|
if ((pIcon = HeapAlloc(GetProcessHeap(), 0, pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2003-05-21 20:50:53 +02:00
|
|
|
if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2003-05-21 20:50:53 +02:00
|
|
|
if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
|
2008-03-23 21:16:38 +01:00
|
|
|
goto error;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
|
|
|
|
/* Prefer PNG over XPM */
|
|
|
|
#ifdef SONAME_LIBPNG
|
|
|
|
if (!SaveIconResAsPNG(pIcon, szXPMFileName, szFileName))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
memcpy(szXPMFileName + strlen(szXPMFileName) - 3, "xpm", 3);
|
|
|
|
if (!SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
|
|
|
|
goto error;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2006-01-17 13:34:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pIcon);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pIconDirEntry);
|
2003-05-21 20:50:53 +02:00
|
|
|
fclose(fICOFile);
|
2005-02-17 12:51:44 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename);
|
2003-05-21 20:50:53 +02:00
|
|
|
return 1;
|
|
|
|
|
2008-03-23 21:16:38 +01:00
|
|
|
error:
|
2006-01-17 13:34:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pIcon);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pIconDirEntry);
|
2008-03-23 21:16:38 +01:00
|
|
|
if (fICOFile) fclose(fICOFile);
|
2003-05-21 20:50:53 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, filename);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL create_default_icon( const char *filename, const char* comment )
|
|
|
|
{
|
|
|
|
FILE *fXPM;
|
2004-09-22 04:46:38 +02:00
|
|
|
unsigned int i;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if (!(fXPM = fopen(filename, "w"))) return FALSE;
|
|
|
|
if (fprintf(fXPM, "/* XPM */\n/* %s */\nstatic char * icon[] = {", comment) <= 0)
|
|
|
|
goto error;
|
|
|
|
for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++) {
|
|
|
|
if (fprintf( fXPM, "\n\"%s\",", wine_xpm[i]) <= 0)
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (fprintf( fXPM, "};\n" ) <=0)
|
|
|
|
goto error;
|
|
|
|
fclose( fXPM );
|
|
|
|
return TRUE;
|
|
|
|
error:
|
|
|
|
fclose( fXPM );
|
|
|
|
unlink( filename );
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-02 14:10:40 +01:00
|
|
|
static char* heap_printf(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int size = 4096;
|
|
|
|
char *buffer;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (buffer == NULL)
|
|
|
|
break;
|
|
|
|
n = vsnprintf(buffer, size, format, args);
|
|
|
|
if (n == -1)
|
|
|
|
size *= 2;
|
|
|
|
else if (n >= size)
|
|
|
|
size = n + 1;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
|
2007-06-28 03:23:33 +02:00
|
|
|
static char *extract_icon( LPCWSTR path, int index, BOOL bWait )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
unsigned short crc;
|
2008-11-02 14:10:40 +01:00
|
|
|
char *iconsdir = NULL, *ico_path = NULL, *ico_name, *xpm_path = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
char* s;
|
2005-02-17 12:51:44 +01:00
|
|
|
int n;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
/* Where should we save the icon? */
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_TRACE("path=[%s] index=%d\n", wine_dbgstr_w(path), index);
|
2008-11-02 14:10:40 +01:00
|
|
|
iconsdir = heap_printf("%s/icons", xdg_data_dir);
|
|
|
|
if (iconsdir)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2008-11-02 14:10:40 +01:00
|
|
|
if (mkdir(iconsdir, 0777) && errno != EEXIST)
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
2008-11-02 14:10:40 +01:00
|
|
|
WINE_WARN("couldn't make icons directory %s\n", wine_dbgstr_a(iconsdir));
|
|
|
|
goto end;
|
2005-02-16 17:04:05 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2008-11-02 14:10:40 +01:00
|
|
|
else
|
2005-06-30 12:17:57 +02:00
|
|
|
{
|
2008-11-02 14:10:40 +01:00
|
|
|
WINE_TRACE("no icon created\n");
|
|
|
|
return NULL;
|
2005-06-30 12:17:57 +02:00
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* Determine the icon base name */
|
2005-02-17 12:51:44 +01:00
|
|
|
n = WideCharToMultiByte(CP_UNIXCP, 0, path, -1, NULL, 0, NULL, NULL);
|
|
|
|
ico_path = HeapAlloc(GetProcessHeap(), 0, n);
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, path, -1, ico_path, n, NULL, NULL);
|
2003-05-21 20:50:53 +02:00
|
|
|
s=ico_name=ico_path;
|
|
|
|
while (*s!='\0') {
|
|
|
|
if (*s=='/' || *s=='\\') {
|
|
|
|
*s='\\';
|
|
|
|
ico_name=s;
|
|
|
|
} else {
|
|
|
|
*s=tolower(*s);
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
if (*ico_name=='\\') *ico_name++='\0';
|
|
|
|
s=strrchr(ico_name,'.');
|
|
|
|
if (s) *s='\0';
|
|
|
|
|
|
|
|
/* Compute the source-path hash */
|
|
|
|
crc=crc16(ico_path);
|
|
|
|
|
|
|
|
/* Try to treat the source file as an exe */
|
|
|
|
xpm_path=HeapAlloc(GetProcessHeap(), 0, strlen(iconsdir)+1+4+1+strlen(ico_name)+1+12+1+3);
|
2008-03-23 21:16:38 +01:00
|
|
|
sprintf(xpm_path,"%s/%04x_%s.%d.png",iconsdir,crc,ico_name,index);
|
2003-05-21 20:50:53 +02:00
|
|
|
if (ExtractFromEXEDLL( path, index, xpm_path ))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Must be something else, ignore the index in that case */
|
2008-03-23 21:16:38 +01:00
|
|
|
sprintf(xpm_path,"%s/%04x_%s.png",iconsdir,crc,ico_name);
|
2003-05-21 20:50:53 +02:00
|
|
|
if (ExtractFromICO( path, xpm_path))
|
|
|
|
goto end;
|
2007-06-28 03:23:33 +02:00
|
|
|
if (!bWait)
|
2008-03-23 21:16:38 +01:00
|
|
|
{
|
|
|
|
sprintf(xpm_path,"%s/%04x_%s.xpm",iconsdir,crc,ico_name);
|
2005-02-17 12:51:44 +01:00
|
|
|
if (create_default_icon( xpm_path, ico_path ))
|
2003-05-21 20:50:53 +02:00
|
|
|
goto end;
|
2008-03-23 21:16:38 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, xpm_path );
|
|
|
|
xpm_path=NULL;
|
|
|
|
|
|
|
|
end:
|
2004-08-30 21:28:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, iconsdir);
|
|
|
|
HeapFree(GetProcessHeap(), 0, ico_path);
|
2003-05-21 20:50:53 +02:00
|
|
|
return xpm_path;
|
|
|
|
}
|
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
static BOOL write_desktop_entry(const char *location, const char *linkname, const char *path,
|
|
|
|
const char *args, const char *descr, const char *workdir,
|
|
|
|
const char *icon)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s,%s,%s,%s,%s,%s,%s)\n", wine_dbgstr_a(location),
|
|
|
|
wine_dbgstr_a(linkname), wine_dbgstr_a(path), wine_dbgstr_a(args),
|
|
|
|
wine_dbgstr_a(descr), wine_dbgstr_a(workdir), wine_dbgstr_a(icon));
|
|
|
|
|
|
|
|
file = fopen(location, "w");
|
|
|
|
if (file == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
fprintf(file, "[Desktop Entry]\n");
|
|
|
|
fprintf(file, "Name=%s\n", linkname);
|
|
|
|
fprintf(file, "Exec=env WINEPREFIX=\"%s\" wine \"%s\" %s\n",
|
|
|
|
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);
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL write_menu_file(const char *filename)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
tempfilename = tempnam(xdg_config_dir, "_wine");
|
|
|
|
if (tempfilename)
|
|
|
|
{
|
|
|
|
int tempfd = open(tempfilename, O_EXCL | O_CREAT | O_WRONLY, 0666);
|
|
|
|
if (tempfd >= 0)
|
|
|
|
{
|
|
|
|
tempfile = fdopen(tempfd, "w");
|
|
|
|
if (tempfile)
|
|
|
|
break;
|
|
|
|
close(tempfd);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
else if (errno == EEXIST)
|
|
|
|
{
|
|
|
|
free(tempfilename);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
free(tempfilename);
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
fprintf(tempfile, " <Name>%s%s</Name>\n", count ? "" : "wine-", name);
|
|
|
|
fprintf(tempfile, " <Directory>%s%s.directory</Directory>\n", count ? "" : "wine-", name);
|
|
|
|
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");
|
|
|
|
fprintf(tempfile, " <Filename>%s</Filename>\n", name);
|
|
|
|
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);
|
|
|
|
free(tempfilename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, menuPath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL write_menu_entry(const char *link, const char *path, const char *args,
|
|
|
|
const char *descr, const char *workdir, const char *icon)
|
|
|
|
{
|
|
|
|
const char *linkname;
|
|
|
|
char *desktopPath = NULL;
|
|
|
|
char *desktopDir;
|
|
|
|
char *filename = NULL;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s, %s, %s, %s, %s, %s)\n", wine_dbgstr_a(link), wine_dbgstr_a(path),
|
|
|
|
wine_dbgstr_a(args), wine_dbgstr_a(descr), wine_dbgstr_a(workdir),
|
|
|
|
wine_dbgstr_a(icon));
|
|
|
|
|
|
|
|
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 = '/';
|
|
|
|
if (!write_desktop_entry(desktopPath, linkname, path, args, descr, workdir, icon))
|
|
|
|
{
|
|
|
|
WINE_WARN("couldn't make desktop entry %s\n", wine_dbgstr_a(desktopPath));
|
|
|
|
ret = FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
filename = heap_printf("wine/%s.desktop", link);
|
|
|
|
if (!filename || !write_menu_file(filename))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* This escapes \ in filenames */
|
2005-02-17 12:51:44 +01:00
|
|
|
static LPSTR escape(LPCWSTR arg)
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
|
|
|
LPSTR narg, x;
|
2005-02-17 12:51:44 +01:00
|
|
|
LPCWSTR esc;
|
|
|
|
int len = 0, n;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
esc = arg;
|
|
|
|
while((esc = strchrW(esc, '\\')))
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
esc++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
len += WideCharToMultiByte(CP_UNIXCP, 0, arg, -1, NULL, 0, NULL, NULL);
|
|
|
|
narg = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
|
2005-02-18 13:52:33 +01:00
|
|
|
x = narg;
|
|
|
|
while (*arg)
|
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
n = WideCharToMultiByte(CP_UNIXCP, 0, arg, 1, x, len, NULL, NULL);
|
|
|
|
x += n;
|
|
|
|
len -= n;
|
2003-05-21 20:50:53 +02:00
|
|
|
if (*arg == '\\')
|
|
|
|
*x++='\\'; /* escape \ */
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
*x = 0;
|
|
|
|
return narg;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
int bcount, in_quotes;
|
|
|
|
|
|
|
|
/* Extract the application path */
|
|
|
|
bcount=0;
|
|
|
|
in_quotes=0;
|
|
|
|
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-05-19 21:40:41 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-05-19 21:40:41 +02:00
|
|
|
mime_type_entry->mimeType = heap_printf("%s", line);
|
|
|
|
mime_type_entry->glob = heap_printf("%s", pos + 1);
|
|
|
|
if (mime_type_entry->mimeType && mime_type_entry->glob)
|
|
|
|
list_add_tail(mime_types, &mime_type_entry->entry);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->mimeType);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->glob);
|
|
|
|
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);
|
2009-04-11 10:10:59 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry->mimeType);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mime_type_entry);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, native_mime_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL build_native_mime_types(const char *xdg_data_home, struct list **mime_types)
|
|
|
|
{
|
|
|
|
char *xdg_data_dirs;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
*mime_types = NULL;
|
|
|
|
|
|
|
|
xdg_data_dirs = getenv("XDG_DATA_DIRS");
|
|
|
|
if (xdg_data_dirs == NULL)
|
|
|
|
xdg_data_dirs = heap_printf("/usr/local/share/:/usr/share/");
|
|
|
|
else
|
|
|
|
xdg_data_dirs = heap_printf("%s", xdg_data_dirs);
|
|
|
|
|
|
|
|
if (xdg_data_dirs)
|
|
|
|
{
|
|
|
|
*mime_types = HeapAlloc(GetProcessHeap(), 0, sizeof(struct list));
|
|
|
|
if (*mime_types)
|
|
|
|
{
|
|
|
|
const char *begin;
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
list_init(*mime_types);
|
|
|
|
ret = add_mimes(xdg_data_home, *mime_types);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
for (begin = xdg_data_dirs; (end = strchr(begin, ':')); begin = end + 1)
|
|
|
|
{
|
|
|
|
*end = '\0';
|
|
|
|
ret = add_mimes(begin, *mime_types);
|
|
|
|
*end = ':';
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
ret = add_mimes(begin, *mime_types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, xdg_data_dirs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = FALSE;
|
|
|
|
if (!ret && *mime_types)
|
|
|
|
{
|
|
|
|
free_native_mime_types(*mime_types);
|
|
|
|
*mime_types = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-05-27 19:07:32 +02:00
|
|
|
static BOOL match_glob(struct list *native_mime_types, const char *extension,
|
|
|
|
char **match)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
if (fnmatch(mime_type_entry->glob, extension, 0) == 0)
|
|
|
|
{
|
|
|
|
if (*match == NULL || matchLength < strlen(mime_type_entry->glob))
|
|
|
|
{
|
|
|
|
*match = mime_type_entry->mimeType;
|
|
|
|
matchLength = strlen(mime_type_entry->glob);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*match != NULL)
|
|
|
|
{
|
|
|
|
*match = heap_printf("%s", *match);
|
|
|
|
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;
|
|
|
|
BOOL ret = match_glob(native_mime_types, extensionA, mime_type);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ret = match_glob(native_mime_types, lower_extensionA, mime_type);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-06-04 21:57:45 +02:00
|
|
|
static CHAR* reg_get_valA(HKEY key, LPCSTR subkey, LPCSTR name)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
if (RegGetValueA(key, subkey, name, RRF_RT_REG_SZ, NULL, NULL, &size) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
CHAR *ret = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (RegGetValueA(key, subkey, name, RRF_RT_REG_SZ, NULL, ret, &size) == ERROR_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
}
|
2009-06-06 21:24:20 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret);
|
2009-06-04 21:57:45 +02:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-03 18:33:28 +02:00
|
|
|
static WCHAR* reg_get_valW(HKEY key, LPCWSTR subkey, LPCWSTR name)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
if (RegGetValueW(key, subkey, name, RRF_RT_REG_SZ, NULL, NULL, &size) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR *ret = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (RegGetValueW(key, subkey, name, RRF_RT_REG_SZ, NULL, ret, &size) == ERROR_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
}
|
2009-06-06 21:24:20 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, ret);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL has_association_changed(LPCSTR extensionA, LPCWSTR extensionW, LPCSTR mimeType, LPCWSTR progId, LPCSTR appName, LPCWSTR docName)
|
|
|
|
{
|
|
|
|
static const WCHAR ProgIDW[] = {'P','r','o','g','I','D',0};
|
|
|
|
static const WCHAR DocNameW[] = {'D','o','c','N','a','m','e',0};
|
|
|
|
HKEY assocKey;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
CHAR *valueA;
|
|
|
|
WCHAR *value;
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
valueA = reg_get_valA(assocKey, extensionA, "MimeType");
|
|
|
|
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);
|
|
|
|
|
|
|
|
valueA = reg_get_valA(assocKey, extensionA, "AppName");
|
|
|
|
if (!valueA || lstrcmpA(valueA, appName))
|
|
|
|
ret = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, valueA);
|
|
|
|
|
|
|
|
value = reg_get_valW(assocKey, extensionW, DocNameW);
|
|
|
|
if (docName && (!value || strcmpW(value, docName)))
|
|
|
|
ret = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, value);
|
|
|
|
|
|
|
|
RegCloseKey(assocKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_ERR("error opening associations registry key\n");
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_association(LPCWSTR extension, LPCSTR mimeType, LPCWSTR progId, LPCSTR appName, LPCWSTR docName, LPCSTR desktopFile)
|
|
|
|
{
|
|
|
|
static const WCHAR ProgIDW[] = {'P','r','o','g','I','D',0};
|
|
|
|
static const WCHAR DocNameW[] = {'D','o','c','N','a','m','e',0};
|
|
|
|
HKEY assocKey;
|
|
|
|
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
HKEY subkey;
|
|
|
|
if (RegCreateKeyW(assocKey, extension, &subkey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
RegSetValueExA(subkey, "MimeType", 0, REG_SZ, (BYTE*) mimeType, lstrlenA(mimeType) + 1);
|
|
|
|
RegSetValueExW(subkey, ProgIDW, 0, REG_SZ, (BYTE*) progId, (lstrlenW(progId) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExA(subkey, "AppName", 0, REG_SZ, (BYTE*) appName, lstrlenA(appName) + 1);
|
|
|
|
if (docName)
|
|
|
|
RegSetValueExW(subkey, DocNameW, 0, REG_SZ, (BYTE*) docName, (lstrlenW(docName) + 1) * sizeof(WCHAR));
|
|
|
|
RegSetValueExA(subkey, "DesktopFile", 0, REG_SZ, (BYTE*) desktopFile, (lstrlenA(desktopFile) + 1));
|
|
|
|
RegCloseKey(subkey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("could not create extension subkey\n");
|
|
|
|
RegCloseKey(assocKey);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
WINE_ERR("could not open file associations key\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL cleanup_associations(void)
|
|
|
|
{
|
|
|
|
HKEY assocKey;
|
|
|
|
BOOL hasChanged = FALSE;
|
|
|
|
if ((assocKey = open_associations_reg_key()))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL done = FALSE;
|
|
|
|
for (i = 0; !done; i++)
|
|
|
|
{
|
|
|
|
WCHAR *extensionW = NULL;
|
|
|
|
char *extensionA = 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;
|
|
|
|
extensionA = wchars_to_utf8_chars(extensionW);
|
|
|
|
if (extensionA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
done = TRUE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
command = assoc_query(ASSOCSTR_COMMAND, extensionW, NULL);
|
|
|
|
if (command == NULL)
|
|
|
|
{
|
|
|
|
char *desktopFile = reg_get_valA(assocKey, extensionA, "DesktopFile");
|
|
|
|
if (desktopFile)
|
|
|
|
{
|
|
|
|
WINE_TRACE("removing file type association for %s\n", wine_dbgstr_a(extensionA));
|
|
|
|
remove(desktopFile);
|
|
|
|
}
|
|
|
|
RegDeleteKeyW(assocKey, extensionW);
|
|
|
|
hasChanged = TRUE;
|
|
|
|
HeapFree(GetProcessHeap(), 0, desktopFile);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ret != ERROR_NO_MORE_ITEMS)
|
|
|
|
WINE_ERR("error %d while reading registry\n", ret);
|
|
|
|
done = TRUE;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
HeapFree(GetProcessHeap(), 0, extensionA);
|
|
|
|
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");
|
|
|
|
fprintf(packageFile, " <mime-type type=\"%s\">\n", mime_type);
|
|
|
|
fprintf(packageFile, " <glob pattern=\"*%s\"/>\n", dot_extension);
|
|
|
|
if (comment)
|
|
|
|
fprintf(packageFile, " <comment>%s</comment>\n", comment);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
const char *progId)
|
|
|
|
{
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
FILE *desktop;
|
|
|
|
|
|
|
|
WINE_TRACE("writing association for file type %s, friendlyAppName=%s, MIME type %s, progID=%s, to file %s\n",
|
|
|
|
wine_dbgstr_a(dot_extension), wine_dbgstr_a(friendlyAppName), wine_dbgstr_a(mimeType),
|
|
|
|
wine_dbgstr_a(progId), wine_dbgstr_a(desktopPath));
|
|
|
|
|
|
|
|
desktop = fopen(desktopPath, "w");
|
|
|
|
if (desktop)
|
|
|
|
{
|
|
|
|
fprintf(desktop, "[Desktop Entry]\n");
|
|
|
|
fprintf(desktop, "Type=Application\n");
|
|
|
|
fprintf(desktop, "Name=%s\n", friendlyAppName);
|
|
|
|
fprintf(desktop, "MimeType=%s\n", mimeType);
|
|
|
|
fprintf(desktop, "Exec=wine start /ProgIDOpen %s %%f\n", progId);
|
|
|
|
fprintf(desktop, "NoDisplay=true\n");
|
|
|
|
fprintf(desktop, "StartupNotify=true\n");
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct list *nativeMimeTypes = NULL;
|
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;
|
|
|
|
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;
|
2009-05-19 21:40:41 +02:00
|
|
|
|
|
|
|
extensionA = wchars_to_utf8_chars(extensionW);
|
|
|
|
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);
|
|
|
|
if (iconW)
|
|
|
|
{
|
|
|
|
WCHAR *comma = strrchrW(iconW, ',');
|
|
|
|
int index = 0;
|
|
|
|
if (comma)
|
|
|
|
{
|
|
|
|
*comma = 0;
|
|
|
|
index = atoiW(comma + 1);
|
|
|
|
}
|
|
|
|
iconA = extract_icon(iconW, index, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-05-19 21:40:41 +02:00
|
|
|
contentTypeW = assoc_query(ASSOCSTR_CONTENTTYPE, extensionW, NULL);
|
2009-05-27 19:07:32 +02: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
|
|
|
{
|
|
|
|
if (contentTypeW != NULL)
|
|
|
|
mimeTypeA = wchars_to_utf8_chars(contentTypeW);
|
|
|
|
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)
|
|
|
|
{
|
2009-06-07 18:32:07 +02:00
|
|
|
/* Gnome seems to ignore the <icon> tag in MIME packages,
|
|
|
|
* and the default name is more intuitive anyway.
|
|
|
|
*/
|
|
|
|
if (iconA)
|
|
|
|
{
|
|
|
|
char *flattened_mime = slashes_to_minuses(mimeTypeA);
|
|
|
|
if (flattened_mime)
|
|
|
|
{
|
|
|
|
char *dstIconPath = heap_printf("%s/icons/%s%s", xdg_data_dir,
|
|
|
|
flattened_mime, strrchr(iconA, '.'));
|
|
|
|
if (dstIconPath)
|
|
|
|
{
|
|
|
|
rename(iconA, dstIconPath);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dstIconPath);
|
|
|
|
}
|
|
|
|
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-03 18:33:28 +02:00
|
|
|
commandW = assoc_query(ASSOCSTR_COMMAND, extensionW, NULL);
|
|
|
|
if (commandW == NULL)
|
|
|
|
/* no command => no application is associated */
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
friendlyAppNameW = assoc_query(ASSOCSTR_FRIENDLYAPPNAME, extensionW, NULL);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
progIdA = wchars_to_utf8_chars(progIdW);
|
|
|
|
if (progIdA == NULL)
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto end; /* no progID => not a file type association */
|
|
|
|
|
2009-06-04 21:57:45 +02:00
|
|
|
if (has_association_changed(extensionA, extensionW, mimeTypeA, progIdW, friendlyAppNameA, friendlyDocNameW))
|
2009-06-03 18:33:28 +02:00
|
|
|
{
|
|
|
|
char *desktopPath = heap_printf("%s/wine-extension-%s.desktop", applications_dir, &extensionA[1]);
|
|
|
|
if (desktopPath)
|
|
|
|
{
|
|
|
|
if (write_freedesktop_association_entry(desktopPath, extensionA, friendlyAppNameA, mimeTypeA, progIdA))
|
|
|
|
{
|
|
|
|
hasChanged = TRUE;
|
2009-06-04 21:57:45 +02:00
|
|
|
update_association(extensionW, mimeTypeA, progIdW, friendlyAppNameA, friendlyDocNameW, desktopPath);
|
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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_native_mime_types(nativeMimeTypes);
|
|
|
|
return hasChanged;
|
2009-04-11 10:10:59 +02:00
|
|
|
}
|
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
static BOOL InvokeShellLinker( IShellLinkW *sl, LPCWSTR link, BOOL bWait )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
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;
|
|
|
|
char *escaped_path = NULL, *escaped_args = NULL, *escaped_description = 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];
|
|
|
|
WCHAR szArgs[INFOTIPSIZE], szIconPath[MAX_PATH];
|
2005-02-18 13:52:33 +01:00
|
|
|
int iIconId = 0, r = -1;
|
2005-02-17 12:51:44 +01:00
|
|
|
DWORD csidl = -1;
|
2007-06-28 03:23:30 +02:00
|
|
|
HANDLE hsem = NULL;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
if ( !link )
|
|
|
|
{
|
|
|
|
WINE_ERR("Link name is null\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2005-11-10 12:36:26 +01:00
|
|
|
get_cmdline( sl, szPath, MAX_PATH, szArgs, INFOTIPSIZE);
|
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
|
|
|
|
|
|
|
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] )
|
2007-06-28 03:23:33 +02:00
|
|
|
icon_name = extract_icon( szIconPath , iIconId, bWait );
|
2003-05-21 20:50:53 +02:00
|
|
|
else
|
2007-06-28 03:23:33 +02:00
|
|
|
icon_name = extract_icon( szPath, iIconId, bWait );
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
/* fail - try once again after parent process exit */
|
2003-05-21 20:50:53 +02:00
|
|
|
if( !icon_name )
|
|
|
|
{
|
2007-06-28 03:23:33 +02:00
|
|
|
if (bWait)
|
2005-02-22 20:31:19 +01:00
|
|
|
{
|
|
|
|
WINE_WARN("Unable to extract icon, deferring.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2006-11-24 23:39:51 +01:00
|
|
|
WINE_ERR("failed to extract icon from %s\n",
|
|
|
|
wine_dbgstr_w( szIconPath[0] ? szIconPath : szPath ));
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check the path */
|
|
|
|
if( szPath[0] )
|
|
|
|
{
|
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);
|
|
|
|
}
|
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);
|
|
|
|
escaped_description = escape(szDescription);
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
/* building multiple menus concurrently has race conditions */
|
2007-06-28 03:23:30 +02:00
|
|
|
hsem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
|
2008-04-21 20:34:30 +02:00
|
|
|
if( WAIT_OBJECT_0 != MsgWaitForMultipleObjects( 1, &hsem, FALSE, INFINITE, QS_ALLINPUT ) )
|
2007-06-28 03:23:30 +02:00
|
|
|
{
|
|
|
|
WINE_ERR("failed wait for semaphore\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-11-08 10:03:39 +01:00
|
|
|
if (in_desktop_dir(csidl))
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
r = !write_desktop_entry(location, lastEntry, escaped_path, escaped_args, escaped_description, work_dir, icon_name);
|
|
|
|
HeapFree(GetProcessHeap(), 0, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-11-11 20:39:56 +01:00
|
|
|
r = !write_menu_entry(link_name, escaped_path, escaped_args, escaped_description, work_dir, icon_name);
|
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 );
|
2005-02-17 12:51:44 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, escaped_description );
|
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 )
|
|
|
|
{
|
|
|
|
char *link_name = NULL;
|
|
|
|
DWORD csidl = -1;
|
|
|
|
LPWSTR urlPath;
|
|
|
|
char *escaped_urlPath = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hSem = NULL;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
int r = -1;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
escaped_urlPath = escape(urlPath);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
r = !write_desktop_entry(location, lastEntry, "winebrowser", escaped_urlPath, NULL, NULL, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
r = !write_menu_entry(link_name, "winebrowser", escaped_urlPath, NULL, NULL, NULL);
|
|
|
|
ret = (r != 0);
|
|
|
|
ReleaseSemaphore(hSem, 1, NULL);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (hSem)
|
|
|
|
CloseHandle(hSem);
|
|
|
|
HeapFree(GetProcessHeap(), 0, link_name);
|
|
|
|
CoTaskMemFree( urlPath );
|
|
|
|
HeapFree(GetProcessHeap(), 0, escaped_urlPath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-28 03:23:33 +02:00
|
|
|
static BOOL WaitForParentProcess( void )
|
|
|
|
{
|
|
|
|
PROCESSENTRY32 procentry;
|
|
|
|
HANDLE hsnapshot = NULL, hprocess = NULL;
|
|
|
|
DWORD ourpid = GetCurrentProcessId();
|
|
|
|
BOOL ret = FALSE, rc;
|
|
|
|
|
|
|
|
WINE_TRACE("Waiting for parent process\n");
|
|
|
|
if ((hsnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 )) ==
|
|
|
|
INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = CoInitialize( NULL );
|
|
|
|
if( FAILED( r ) )
|
2004-01-06 21:39:17 +01:00
|
|
|
{
|
|
|
|
WINE_ERR("CoInitialize failed\n");
|
2003-05-21 20:50:53 +02:00
|
|
|
return 1;
|
2004-01-06 21:39:17 +01:00
|
|
|
}
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
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");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
len=GetFullPathNameW( urlname, MAX_PATH, fullname, NULL );
|
|
|
|
if (len==0 || len>MAX_PATH)
|
|
|
|
{
|
|
|
|
WINE_ERR("couldn't get full path of URL file\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = CoInitialize( NULL );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("CoInitialize failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = CoCreateInstance( &CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER,
|
|
|
|
&IID_IUniformResourceLocatorW, (LPVOID *) &url );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("No IID_IUniformResourceLocatorW\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = url->lpVtbl->QueryInterface( url, &IID_IPersistFile, (LPVOID*) &pf );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WINE_ERR("No IID_IPersistFile\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
char *command = heap_printf("update-mime-database %s", mime_dir);
|
|
|
|
if (command)
|
|
|
|
{
|
|
|
|
system(command);
|
|
|
|
HeapFree(GetProcessHeap(), 0, command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2009-06-03 18:33:28 +02:00
|
|
|
|
|
|
|
command = heap_printf("update-desktop-database %s/applications", xdg_data_dir);
|
|
|
|
if (command)
|
|
|
|
{
|
|
|
|
system(command);
|
|
|
|
HeapFree(GetProcessHeap(), 0, command);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINE_ERR("out of memory\n");
|
|
|
|
goto end;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
static CHAR *next_token( LPSTR *p )
|
|
|
|
{
|
|
|
|
LPSTR token = NULL, t = *p;
|
|
|
|
|
|
|
|
if( !t )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while( t && !token )
|
|
|
|
{
|
|
|
|
switch( *t )
|
|
|
|
{
|
|
|
|
case ' ':
|
|
|
|
t++;
|
|
|
|
continue;
|
|
|
|
case '"':
|
|
|
|
/* unquote the token */
|
|
|
|
token = ++t;
|
|
|
|
t = strchr( token, '"' );
|
|
|
|
if( t )
|
|
|
|
*t++ = 0;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
t = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
token = t;
|
|
|
|
t = strchr( token, ' ' );
|
|
|
|
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"))
|
|
|
|
xdg_data_dir = heap_printf("%s", getenv("XDG_DATA_HOME"));
|
|
|
|
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
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* WinMain
|
|
|
|
*/
|
|
|
|
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
|
|
|
|
{
|
|
|
|
LPSTR 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;
|
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
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
for( p = cmdline; p && *p; )
|
|
|
|
{
|
|
|
|
token = next_token( &p );
|
|
|
|
if( !token )
|
|
|
|
break;
|
2009-04-05 08:14:53 +02:00
|
|
|
if( !lstrcmpA( token, "-a" ) )
|
|
|
|
{
|
|
|
|
RefreshFileTypeAssociations();
|
|
|
|
break;
|
|
|
|
}
|
2007-06-28 03:23:33 +02:00
|
|
|
if( !lstrcmpA( token, "-w" ) )
|
|
|
|
bWait = TRUE;
|
2008-11-13 07:19:25 +01:00
|
|
|
else if ( !lstrcmpA( token, "-u" ) )
|
|
|
|
bURL = TRUE;
|
2003-05-21 20:50:53 +02:00
|
|
|
else if( token[0] == '-' )
|
|
|
|
{
|
|
|
|
WINE_ERR( "unknown option %s\n",token);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR link[MAX_PATH];
|
2008-11-13 07:19:25 +01:00
|
|
|
BOOL bRet;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-09-13 00:07:53 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, token, -1, link, sizeof(link)/sizeof(WCHAR) );
|
2008-11-13 07:19:25 +01:00
|
|
|
if (bURL)
|
|
|
|
bRet = Process_URL( link, bWait );
|
|
|
|
else
|
|
|
|
bRet = Process_Link( link, bWait );
|
|
|
|
if (!bRet)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2008-11-13 07:19:25 +01:00
|
|
|
WINE_ERR( "failed to build menu item for %s\n",token);
|
|
|
|
ret = 1;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|