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
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
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
|
|
|
|
* interface, then invoke wineshelllink with the appropriate arguments
|
|
|
|
* to create a KDE/Gnome menu entry for the shortcut.
|
|
|
|
*
|
|
|
|
* winemenubuilder [ -r ] <shortcut.lnk>
|
|
|
|
*
|
|
|
|
* If the -r parameter is passed, and the shortcut cannot be created,
|
2005-12-19 21:25:52 +01:00
|
|
|
* this program will add a RunOnce entry to invoke itself at the next
|
2003-05-21 20:50:53 +02:00
|
|
|
* reboot. This covers the case when a ShortCut is created before the
|
|
|
|
* 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.
|
|
|
|
*
|
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>
|
|
|
|
|
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>
|
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"
|
2003-12-08 22:44:24 +01:00
|
|
|
#include "wine.xpm"
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
/* Icon extraction routines
|
|
|
|
*
|
|
|
|
* FIXME: should use PrivateExtractIcons and friends
|
|
|
|
* FIXME: should not use stdio
|
|
|
|
*/
|
|
|
|
|
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 MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
static BOOL extract_icon32(LPCWSTR szFileName, int nIndex, const 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
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
WINE_ERR("LoadLibraryExW (%s) failed, error %ld\n",
|
|
|
|
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);
|
|
|
|
WINE_TRACE("FindResourceW (%s) called, return %p, error %ld\n",
|
|
|
|
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,
|
|
|
|
EnumResNameProc, (LONG_PTR)&sEnumRes))
|
|
|
|
{
|
|
|
|
WINE_TRACE("EnumResourceNamesW failed, error %ld\n", GetLastError());
|
|
|
|
}
|
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++)
|
|
|
|
{
|
2005-08-22 11:17:25 +02:00
|
|
|
if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
|
|
|
|
{
|
|
|
|
nMaxBits = pIconDir->idEntries[i].wBitCount;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
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-01-11 12:09:53 +01:00
|
|
|
WINE_ERR("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)))
|
|
|
|
{
|
|
|
|
if(SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
static BOOL ExtractFromEXEDLL(LPCWSTR szFileName, int nIndex, const 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
|
|
|
}
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
static int ExtractFromICO(LPCWSTR szFileName, const char *szXPMFileName)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
FILE *fICOFile;
|
|
|
|
ICONDIR iconDir;
|
|
|
|
ICONDIRENTRY *pIconDirEntry;
|
|
|
|
int nMax = 0;
|
|
|
|
int nIndex = 0;
|
|
|
|
void *pIcon;
|
|
|
|
int i;
|
|
|
|
char *filename;
|
|
|
|
|
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));
|
2003-05-21 20:50:53 +02:00
|
|
|
goto error1;
|
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))
|
|
|
|
{
|
|
|
|
WINE_ERR("Invalid ico file format\n");
|
2003-05-21 20:50:53 +02:00
|
|
|
goto error2;
|
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)
|
2003-05-21 20:50:53 +02:00
|
|
|
goto error2;
|
|
|
|
if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
|
|
|
|
goto error3;
|
|
|
|
|
|
|
|
for (i = 0; i < iconDir.idCount; i++)
|
|
|
|
if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
|
|
|
|
{
|
|
|
|
nIndex = i;
|
|
|
|
nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
|
|
|
|
}
|
2006-01-17 13:34:31 +01:00
|
|
|
if ((pIcon = HeapAlloc(GetProcessHeap(), 0, pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
|
2003-05-21 20:50:53 +02:00
|
|
|
goto error3;
|
|
|
|
if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
|
|
|
|
goto error4;
|
|
|
|
if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
|
|
|
|
goto error4;
|
|
|
|
|
|
|
|
if(!SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
|
|
|
|
goto error4;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
error4:
|
2006-01-17 13:34:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pIcon);
|
2003-05-21 20:50:53 +02:00
|
|
|
error3:
|
2006-01-17 13:34:31 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, pIconDirEntry);
|
2003-05-21 20:50:53 +02:00
|
|
|
error2:
|
|
|
|
fclose(fICOFile);
|
|
|
|
error1:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
|
2005-02-17 12:51:44 +01:00
|
|
|
static char *extract_icon( LPCWSTR path, int index)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
int nodefault = 1;
|
|
|
|
unsigned short crc;
|
|
|
|
char *iconsdir, *ico_path, *ico_name, *xpm_path;
|
|
|
|
char* s;
|
|
|
|
HKEY hkey;
|
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);
|
2003-05-21 20:50:53 +02:00
|
|
|
iconsdir=NULL; /* Default is no icon */
|
2005-07-06 17:47:48 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\WineMenuBuilder */
|
|
|
|
if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\WineMenuBuilder", &hkey ))
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
static const WCHAR IconsDirW[] = {'I','c','o','n','s','D','i','r',0};
|
|
|
|
LPWSTR iconsdirW;
|
2003-05-21 20:50:53 +02:00
|
|
|
DWORD size = 0;
|
2005-02-16 17:04:05 +01:00
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
if (!RegQueryValueExW(hkey, IconsDirW, 0, NULL, NULL, &size))
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
iconsdirW = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
RegQueryValueExW(hkey, IconsDirW, 0, NULL, (LPBYTE)iconsdirW, &size);
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-06-30 12:17:57 +02:00
|
|
|
if (!(iconsdir = wine_get_unix_file_name(iconsdirW)))
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
2005-02-17 12:51:44 +01:00
|
|
|
int n = WideCharToMultiByte(CP_UNIXCP, 0, iconsdirW, -1, NULL, 0, NULL, NULL);
|
|
|
|
iconsdir = HeapAlloc(GetProcessHeap(), 0, n);
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, iconsdirW, -1, iconsdir, n, NULL, NULL);
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, iconsdirW);
|
2005-02-16 17:04:05 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
2005-06-30 12:17:57 +02:00
|
|
|
|
|
|
|
if (!iconsdir)
|
|
|
|
{
|
|
|
|
WCHAR path[MAX_PATH];
|
2006-01-03 12:09:47 +01:00
|
|
|
if (GetTempPathW(MAX_PATH, path))
|
|
|
|
iconsdir = wine_get_unix_file_name(path);
|
|
|
|
if (!iconsdir)
|
|
|
|
{
|
|
|
|
WINE_TRACE("no IconsDir\n");
|
|
|
|
return NULL; /* No icon created */
|
|
|
|
}
|
2005-06-30 12:17:57 +02:00
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
|
|
|
|
if (!*iconsdir)
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2006-01-03 12:09:47 +01:00
|
|
|
WINE_TRACE("icon generation disabled\n");
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, iconsdir);
|
2003-05-21 20:50:53 +02:00
|
|
|
return NULL; /* No icon created */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If icon path begins with a '*' then this is a deferred call */
|
|
|
|
if (path[0] == '*')
|
|
|
|
{
|
|
|
|
path++;
|
|
|
|
nodefault = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
sprintf(xpm_path,"%s/%04x_%s.%d.xpm",iconsdir,crc,ico_name,index);
|
|
|
|
if (ExtractFromEXEDLL( path, index, xpm_path ))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Must be something else, ignore the index in that case */
|
|
|
|
sprintf(xpm_path,"%s/%04x_%s.xpm",iconsdir,crc,ico_name);
|
|
|
|
if (ExtractFromICO( path, xpm_path))
|
|
|
|
goto end;
|
|
|
|
if (!nodefault)
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL DeferToRunOnce(LPWSTR link)
|
|
|
|
{
|
|
|
|
HKEY hkey;
|
|
|
|
LONG r, len;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szRunOnce[] = {
|
2003-05-21 20:50:53 +02:00
|
|
|
'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'R','u','n','O','n','c','e',0
|
|
|
|
};
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szFormat[] = { '%','s',' ','"','%','s','"',0 };
|
2003-05-21 20:50:53 +02:00
|
|
|
LPWSTR buffer;
|
|
|
|
WCHAR szExecutable[MAX_PATH];
|
|
|
|
|
|
|
|
WINE_TRACE( "Deferring icon creation to reboot.\n");
|
|
|
|
|
2004-05-19 05:22:55 +02:00
|
|
|
len = GetModuleFileNameW( 0, szExecutable, MAX_PATH );
|
|
|
|
if (!len || len >= MAX_PATH) return FALSE;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
len = ( lstrlenW( link ) + lstrlenW( szExecutable ) + 4)*sizeof(WCHAR);
|
|
|
|
buffer = HeapAlloc( GetProcessHeap(), 0, len );
|
|
|
|
if( !buffer )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
wsprintfW( buffer, szFormat, szExecutable, link );
|
|
|
|
|
|
|
|
r = RegCreateKeyExW(HKEY_LOCAL_MACHINE, szRunOnce, 0,
|
|
|
|
NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
|
|
|
|
if ( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
r = RegSetValueExW(hkey, link, 0, REG_SZ,
|
|
|
|
(LPBYTE) buffer, (lstrlenW(buffer) + 1)*sizeof(WCHAR));
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
|
|
|
|
return ! r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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-06-02 17:11:32 +02:00
|
|
|
static int fork_and_wait( const char *linker, const char *link_name, const char *path,
|
|
|
|
int desktop, const char *args, const char *icon_name,
|
|
|
|
const char *workdir, const char *description )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
|
|
|
int pos = 0;
|
2003-10-15 05:35:54 +02:00
|
|
|
const char *argv[20];
|
2004-01-06 21:39:17 +01:00
|
|
|
int retcode;
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
WINE_TRACE( "linker app='%s' link='%s' mode=%s "
|
|
|
|
"path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
|
|
|
|
linker, link_name, desktop ? "desktop" : "menu",
|
|
|
|
path, args, icon_name, workdir, description );
|
|
|
|
|
|
|
|
argv[pos++] = linker ;
|
|
|
|
argv[pos++] = "--link";
|
|
|
|
argv[pos++] = link_name;
|
|
|
|
argv[pos++] = "--path";
|
|
|
|
argv[pos++] = path;
|
|
|
|
argv[pos++] = desktop ? "--desktop" : "--menu";
|
|
|
|
if (args && strlen(args))
|
|
|
|
{
|
|
|
|
argv[pos++] = "--args";
|
|
|
|
argv[pos++] = args;
|
|
|
|
}
|
|
|
|
if (icon_name)
|
|
|
|
{
|
|
|
|
argv[pos++] = "--icon";
|
|
|
|
argv[pos++] = icon_name;
|
|
|
|
}
|
|
|
|
if (workdir && strlen(workdir))
|
|
|
|
{
|
|
|
|
argv[pos++] = "--workdir";
|
|
|
|
argv[pos++] = workdir;
|
|
|
|
}
|
|
|
|
if (description && strlen(description))
|
|
|
|
{
|
|
|
|
argv[pos++] = "--descr";
|
|
|
|
argv[pos++] = description;
|
|
|
|
}
|
|
|
|
argv[pos] = NULL;
|
|
|
|
|
2004-01-06 21:39:17 +01:00
|
|
|
retcode=spawnvp( _P_WAIT, linker, argv );
|
|
|
|
if (retcode!=0)
|
|
|
|
WINE_ERR("%s returned %d\n",linker,retcode);
|
|
|
|
return retcode;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
2005-12-19 21:25:52 +01:00
|
|
|
/* Return a heap-allocated copy of the unix format difference between the two
|
|
|
|
* Windows-format paths.
|
|
|
|
* locn is the owning location
|
|
|
|
* link is within locn
|
|
|
|
*/
|
|
|
|
static char *relative_path( LPCWSTR link, LPCWSTR locn )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2005-12-19 21:25:52 +01:00
|
|
|
char *unix_locn, *unix_link;
|
|
|
|
char *relative = NULL;
|
2005-02-17 12:51:44 +01:00
|
|
|
|
2005-12-19 21:25:52 +01:00
|
|
|
unix_locn = wine_get_unix_file_name(locn);
|
|
|
|
unix_link = wine_get_unix_file_name(link);
|
|
|
|
if (unix_locn && unix_link)
|
2005-02-17 12:51:44 +01:00
|
|
|
{
|
2005-12-19 21:25:52 +01:00
|
|
|
size_t len_unix_locn, len_unix_link;
|
|
|
|
len_unix_locn = strlen (unix_locn);
|
|
|
|
len_unix_link = strlen (unix_link);
|
|
|
|
if (len_unix_locn < len_unix_link && memcmp (unix_locn, unix_link, len_unix_locn) == 0 && unix_link[len_unix_locn] == '/')
|
|
|
|
{
|
|
|
|
size_t len_rel;
|
|
|
|
char *p = strrchr (unix_link + len_unix_locn, '/');
|
|
|
|
p = strrchr (p, '.');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
len_unix_link = p - unix_link;
|
|
|
|
}
|
|
|
|
len_rel = len_unix_link - len_unix_locn;
|
|
|
|
relative = HeapAlloc(GetProcessHeap(), 0, len_rel);
|
|
|
|
if (relative)
|
|
|
|
{
|
|
|
|
memcpy (relative, unix_link + len_unix_locn + 1, len_rel);
|
|
|
|
}
|
|
|
|
}
|
2005-02-17 12:51:44 +01:00
|
|
|
}
|
2005-12-19 21:25:52 +01:00
|
|
|
if (!relative)
|
|
|
|
WINE_WARN("Could not separate the relative link path of %s in %s\n", wine_dbgstr_w(link), wine_dbgstr_w(locn));
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_locn);
|
|
|
|
HeapFree(GetProcessHeap(), 0, unix_link);
|
|
|
|
return relative;
|
2003-05-21 20:50:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* GetLinkLocation
|
|
|
|
*
|
|
|
|
* returns TRUE if successful
|
2005-12-19 21:25:52 +01:00
|
|
|
* *loc will contain CS_DESKTOPDIRECTORY, CS_STARTMENU, CS_STARTUP etc.
|
|
|
|
* *relative will contain the address of a heap-allocated copy of the portion
|
|
|
|
* of the filename that is within the specified location, in unix form
|
2003-05-21 20:50:53 +02:00
|
|
|
*/
|
2005-12-19 21:25:52 +01:00
|
|
|
static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *loc, char **relative )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
2004-08-30 21:28:59 +02:00
|
|
|
WCHAR filename[MAX_PATH], buffer[MAX_PATH];
|
|
|
|
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));
|
|
|
|
filelen=GetFullPathNameW( linkfile, MAX_PATH, filename, NULL );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-02-22 20:31:19 +01:00
|
|
|
static BOOL InvokeShellLinker( IShellLinkW *sl, LPCWSTR link, BOOL bAgain )
|
2003-05-21 20:50:53 +02:00
|
|
|
{
|
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;
|
|
|
|
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;
|
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
|
|
|
{
|
2004-08-30 21:28:59 +02: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
|
|
|
|
2005-02-16 17:04:05 +01:00
|
|
|
szWorkDir[0] = 0;
|
2005-02-18 13:52:33 +01:00
|
|
|
IShellLinkW_GetWorkingDirectory( sl, 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
|
|
|
|
|
|
|
szDescription[0] = 0;
|
2005-02-17 12:51:44 +01:00
|
|
|
IShellLinkW_GetDescription( sl, szDescription, INFOTIPSIZE );
|
|
|
|
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
|
|
|
|
|
|
|
szIconPath[0] = 0;
|
2005-02-17 12:51:44 +01:00
|
|
|
IShellLinkW_GetIconLocation( sl, szIconPath, MAX_PATH, &iIconId );
|
|
|
|
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] )
|
|
|
|
icon_name = extract_icon( szIconPath , iIconId );
|
|
|
|
else
|
|
|
|
icon_name = extract_icon( szPath, iIconId );
|
|
|
|
|
|
|
|
/* fail - try once again at reboot time */
|
|
|
|
if( !icon_name )
|
|
|
|
{
|
2005-02-22 20:31:19 +01:00
|
|
|
if (bAgain)
|
|
|
|
{
|
|
|
|
WINE_WARN("Unable to extract icon, deferring.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
WINE_ERR("failed to extract icon.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
2005-02-17 12:51:44 +01:00
|
|
|
if (!(p = strrchrW( szPath, '.' ))) return FALSE;
|
|
|
|
if (strchrW( p, '\\' ) || strchrW( p, '/' )) return FALSE;
|
|
|
|
if (lstrcmpiW( p, exeW )) return FALSE;
|
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
|
|
|
|
{
|
2005-02-18 13:52:33 +01:00
|
|
|
static const WCHAR startW[] = {
|
|
|
|
'\\','c','o','m','m','a','n','d',
|
|
|
|
'\\','s','t','a','r','t','.','e','x','e',0};
|
|
|
|
|
2003-05-21 20:50:53 +02:00
|
|
|
/* 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
|
|
|
|
2004-06-19 00:29:56 +02:00
|
|
|
r = fork_and_wait("wineshelllink", link_name, escaped_path,
|
2004-09-21 22:08:10 +02:00
|
|
|
in_desktop_dir(csidl), escaped_args, icon_name,
|
2005-02-17 12:51:44 +01:00
|
|
|
work_dir ? work_dir : "", escaped_description);
|
2003-05-21 20:50:53 +02:00
|
|
|
|
2005-02-22 20:31:19 +01:00
|
|
|
cleanup:
|
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
|
|
|
|
|
|
|
if (r)
|
|
|
|
{
|
2004-06-19 00:29:56 +02:00
|
|
|
WINE_ERR("failed to fork and exec wineshelllink\n" );
|
2003-05-21 20:50:53 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-17 12:51:44 +01:00
|
|
|
static BOOL Process_Link( LPCWSTR linkname, BOOL bAgain )
|
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;
|
|
|
|
|
2005-02-16 17:04:05 +01:00
|
|
|
WINE_TRACE("%s, again %d\n", wine_dbgstr_w(linkname), bAgain);
|
|
|
|
|
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)
|
2003-05-21 20:50:53 +02:00
|
|
|
* defer this menu entry to reboot via runonce
|
|
|
|
*/
|
2005-02-22 20:31:19 +01:00
|
|
|
if( ! InvokeShellLinker( sl, fullname, bAgain ) && bAgain )
|
2003-05-21 20:50:53 +02:00
|
|
|
DeferToRunOnce( fullname );
|
|
|
|
else
|
|
|
|
WINE_TRACE("Success.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* WinMain
|
|
|
|
*/
|
|
|
|
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
|
|
|
|
{
|
|
|
|
LPSTR token = NULL, p;
|
|
|
|
BOOL bAgain = FALSE;
|
|
|
|
HANDLE hsem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
/* running multiple instances of wineshelllink
|
|
|
|
at the same time may be dangerous */
|
|
|
|
if( WAIT_OBJECT_0 != WaitForSingleObject( hsem, INFINITE ) )
|
2005-02-16 17:04:05 +01:00
|
|
|
{
|
|
|
|
CloseHandle(hsem);
|
2003-05-21 20:50:53 +02:00
|
|
|
return FALSE;
|
2005-02-16 17:04:05 +01:00
|
|
|
}
|
2003-05-21 20:50:53 +02:00
|
|
|
|
|
|
|
for( p = cmdline; p && *p; )
|
|
|
|
{
|
|
|
|
token = next_token( &p );
|
|
|
|
if( !token )
|
|
|
|
break;
|
|
|
|
if( !lstrcmpA( token, "-r" ) )
|
|
|
|
bAgain = TRUE;
|
|
|
|
else if( token[0] == '-' )
|
|
|
|
{
|
|
|
|
WINE_ERR( "unknown option %s\n",token);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR link[MAX_PATH];
|
|
|
|
|
2005-09-13 00:07:53 +02:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, token, -1, link, sizeof(link)/sizeof(WCHAR) );
|
2003-05-21 20:50:53 +02:00
|
|
|
if( !Process_Link( link, bAgain ) )
|
|
|
|
{
|
|
|
|
WINE_ERR( "failed to build menu item for %s\n",token);
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseSemaphore( hsem, 1, NULL );
|
|
|
|
CloseHandle( hsem );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|