2 * Helper program to build unix menu entries
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied
6 * Copyright 2003 Mike McCormack for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * This program will read a Windows shortcut file using the IShellLink
24 * interface, then invoke wineshelllink with the appropriate arguments
25 * to create a KDE/Gnome menu entry for the shortcut.
27 * winemenubuilder [ -r ] <shortcut.lnk>
29 * If the -r parameter is passed, and the shortcut cannot be created,
30 * this program will add RunOnce entry to invoke itself at the next
31 * reboot. This covers the case when a ShortCut is created before the
32 * executable containing its icon.
37 #include "wine/port.h"
55 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(menubuilder
);
60 /* link file formats */
81 GRPICONDIRENTRY idEntries
[1];
113 /* Icon extraction routines
115 * FIXME: should use PrivateExtractIcons and friends
116 * FIXME: should not use stdio
119 static BOOL
SaveIconResAsXPM(const BITMAPINFO
*pIcon
, const char *szXPMFileName
, const char *comment
)
129 BOOL aColorUsed
[256] = {0};
133 if (!((pIcon
->bmiHeader
.biBitCount
== 4) || (pIcon
->bmiHeader
.biBitCount
== 8)))
136 if (!(fXPMFile
= fopen(szXPMFileName
, "w")))
139 nHeight
= pIcon
->bmiHeader
.biHeight
/ 2;
140 nXORWidthBytes
= 4 * ((pIcon
->bmiHeader
.biWidth
* pIcon
->bmiHeader
.biBitCount
/ 32)
141 + ((pIcon
->bmiHeader
.biWidth
* pIcon
->bmiHeader
.biBitCount
% 32) > 0));
142 nANDWidthBytes
= 4 * ((pIcon
->bmiHeader
.biWidth
/ 32)
143 + ((pIcon
->bmiHeader
.biWidth
% 32) > 0));
144 b8BitColors
= pIcon
->bmiHeader
.biBitCount
== 8;
145 nColors
= pIcon
->bmiHeader
.biClrUsed
? pIcon
->bmiHeader
.biClrUsed
146 : 1 << pIcon
->bmiHeader
.biBitCount
;
147 pXOR
= (BYTE
*) pIcon
+ sizeof (BITMAPINFOHEADER
) + (nColors
* sizeof (RGBQUAD
));
148 pAND
= pXOR
+ nHeight
* nXORWidthBytes
;
150 #define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
151 #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)
153 for (i
= 0; i
< nHeight
; i
++) {
154 for (j
= 0; j
< pIcon
->bmiHeader
.biWidth
; j
++) {
155 if (!aColorUsed
[COLOR(j
,i
)] && !MASK(j
,i
))
157 aColorUsed
[COLOR(j
,i
)] = TRUE
;
163 if (fprintf(fXPMFile
, "/* XPM */\n/* %s */\nstatic char *icon[] = {\n", comment
) <= 0)
165 if (fprintf(fXPMFile
, "\"%d %d %d %d\",\n",
166 (int) pIcon
->bmiHeader
.biWidth
, nHeight
, nColorsUsed
+ 1, 2) <=0)
169 for (i
= 0; i
< nColors
; i
++) {
171 if (fprintf(fXPMFile
, "\"%.2X c #%.2X%.2X%.2X\",\n", i
, pIcon
->bmiColors
[i
].rgbRed
,
172 pIcon
->bmiColors
[i
].rgbGreen
, pIcon
->bmiColors
[i
].rgbBlue
) <= 0)
175 if (fprintf(fXPMFile
, "\" c None\"") <= 0)
178 for (i
= 0; i
< nHeight
; i
++)
180 if (fprintf(fXPMFile
, ",\n\"") <= 0)
182 for (j
= 0; j
< pIcon
->bmiHeader
.biWidth
; j
++)
186 if (fprintf(fXPMFile
, " ") <= 0)
190 if (fprintf(fXPMFile
, "%.2X", COLOR(j
,i
)) <= 0)
193 if (fprintf(fXPMFile
, "\"") <= 0)
196 if (fprintf(fXPMFile
, "};\n") <= 0)
207 unlink( szXPMFileName
);
211 static BOOL CALLBACK
EnumResNameProc(HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG lParam
)
213 ENUMRESSTRUCT
*sEnumRes
= (ENUMRESSTRUCT
*) lParam
;
215 if (!sEnumRes
->nIndex
--)
217 *sEnumRes
->pResInfo
= FindResourceA(hModule
, lpszName
, (LPSTR
)RT_GROUP_ICON
);
224 static BOOL
ExtractFromEXEDLL(const char *szFileName
, int nIndex
, const char *szXPMFileName
)
230 GRPICONDIR
*pIconDir
;
232 ENUMRESSTRUCT sEnumRes
;
237 if (!(hModule
= LoadLibraryExA(szFileName
, 0, LOAD_LIBRARY_AS_DATAFILE
)))
239 WINE_ERR("LoadLibraryExA (%s) failed, error %ld\n", szFileName
, GetLastError());
245 hResInfo
= FindResourceA(hModule
, MAKEINTRESOURCEA(-nIndex
), (LPSTR
)RT_GROUP_ICON
);
246 WINE_ERR("FindResourceA (%s) called, return %p, error %ld\n", szFileName
, hResInfo
, GetLastError());
251 sEnumRes
.pResInfo
= &hResInfo
;
252 sEnumRes
.nIndex
= nIndex
;
253 EnumResourceNamesA(hModule
, (LPSTR
)RT_GROUP_ICON
, &EnumResNameProc
, (LONG
) &sEnumRes
);
258 WINE_ERR("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
262 if (!(hResData
= LoadResource(hModule
, hResInfo
)))
264 WINE_ERR("LoadResource failed, error %ld\n", GetLastError());
267 if (!(pIconDir
= LockResource(hResData
)))
269 WINE_ERR("LockResource failed, error %ld\n", GetLastError());
273 for (i
= 0; i
< pIconDir
->idCount
; i
++)
274 if ((pIconDir
->idEntries
[i
].wBitCount
>= nMaxBits
) && (pIconDir
->idEntries
[i
].wBitCount
<= 8))
276 if (pIconDir
->idEntries
[i
].wBitCount
> nMaxBits
)
278 nMaxBits
= pIconDir
->idEntries
[i
].wBitCount
;
281 if ((pIconDir
->idEntries
[i
].bHeight
* pIconDir
->idEntries
[i
].bWidth
) > nMax
)
283 lpName
= MAKEINTRESOURCEA(pIconDir
->idEntries
[i
].nID
);
284 nMax
= pIconDir
->idEntries
[i
].bHeight
* pIconDir
->idEntries
[i
].bWidth
;
288 FreeResource(hResData
);
290 if (!(hResInfo
= FindResourceA(hModule
, lpName
, (LPSTR
)RT_ICON
)))
292 WINE_ERR("Second FindResourceA failed, error %ld\n", GetLastError());
295 if (!(hResData
= LoadResource(hModule
, hResInfo
)))
297 WINE_ERR("Second LoadResource failed, error %ld\n", GetLastError());
300 if (!(pIcon
= LockResource(hResData
)))
302 WINE_ERR("Second LockResource failed, error %ld\n", GetLastError());
306 if(!SaveIconResAsXPM(pIcon
, szXPMFileName
, szFileName
))
308 WINE_ERR("Failed saving icon as XPM, error %ld\n", GetLastError());
312 FreeResource(hResData
);
313 FreeLibrary(hModule
);
318 FreeResource(hResData
);
320 FreeLibrary(hModule
);
325 /* get the Unix file name for a given path, allocating the string */
326 inline static char *get_unix_file_name( const char *dos
)
328 WCHAR dosW
[MAX_PATH
];
330 MultiByteToWideChar(CP_ACP
, 0, dos
, -1, dosW
, MAX_PATH
);
331 return wine_get_unix_file_name( dosW
);
334 static int ExtractFromICO(const char *szFileName
, const char *szXPMFileName
)
338 ICONDIRENTRY
*pIconDirEntry
;
345 filename
= get_unix_file_name(szFileName
);
346 if (!(fICOFile
= fopen(filename
, "r")))
349 if (fread(&iconDir
, sizeof (ICONDIR
), 1, fICOFile
) != 1)
351 if ((iconDir
.idReserved
!= 0) || (iconDir
.idType
!= 1))
354 if ((pIconDirEntry
= malloc(iconDir
.idCount
* sizeof (ICONDIRENTRY
))) == NULL
)
356 if (fread(pIconDirEntry
, sizeof (ICONDIRENTRY
), iconDir
.idCount
, fICOFile
) != iconDir
.idCount
)
359 for (i
= 0; i
< iconDir
.idCount
; i
++)
360 if ((pIconDirEntry
[i
].bHeight
* pIconDirEntry
[i
].bWidth
) > nMax
)
363 nMax
= pIconDirEntry
[i
].bHeight
* pIconDirEntry
[i
].bWidth
;
365 if ((pIcon
= malloc(pIconDirEntry
[nIndex
].dwBytesInRes
)) == NULL
)
367 if (fseek(fICOFile
, pIconDirEntry
[nIndex
].dwImageOffset
, SEEK_SET
))
369 if (fread(pIcon
, pIconDirEntry
[nIndex
].dwBytesInRes
, 1, fICOFile
) != 1)
372 if(!SaveIconResAsXPM(pIcon
, szXPMFileName
, szFileName
))
388 HeapFree(GetProcessHeap(), 0, filename
);
392 static BOOL
create_default_icon( const char *filename
, const char* comment
)
397 if (!(fXPM
= fopen(filename
, "w"))) return FALSE
;
398 if (fprintf(fXPM
, "/* XPM */\n/* %s */\nstatic char * icon[] = {", comment
) <= 0)
400 for (i
= 0; i
< sizeof(wine_xpm
)/sizeof(wine_xpm
[0]); i
++) {
401 if (fprintf( fXPM
, "\n\"%s\",", wine_xpm
[i
]) <= 0)
404 if (fprintf( fXPM
, "};\n" ) <=0)
415 static unsigned short crc16(const char* string
)
417 unsigned short crc
= 0;
420 for (i
= 0; string
[i
] != 0; i
++)
423 for (j
= 0; j
< 8; c
>>= 1, j
++)
425 xor_poly
= (c
^ crc
) & 1;
434 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
435 static char *extract_icon( const char *path
, int index
)
439 char *iconsdir
, *ico_path
, *ico_name
, *xpm_path
;
443 /* Where should we save the icon? */
444 WINE_TRACE("path=[%s] index=%d\n",path
,index
);
445 iconsdir
=NULL
; /* Default is no icon */
446 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Wine\\Wine\\Config\\Wine", &hkey
))
449 if (RegQueryValueExA(hkey
, "IconsDir", 0, NULL
, NULL
, &size
)==0) {
450 iconsdir
= HeapAlloc(GetProcessHeap(), 0, size
);
451 RegQueryValueExA(hkey
, "IconsDir", 0, NULL
, iconsdir
, &size
);
453 s
=get_unix_file_name(iconsdir
);
455 HeapFree(GetProcessHeap(), 0, iconsdir
);
461 if (iconsdir
==NULL
|| *iconsdir
=='\0')
464 HeapFree(GetProcessHeap(), 0, iconsdir
);
465 return NULL
; /* No icon created */
468 /* If icon path begins with a '*' then this is a deferred call */
475 /* Determine the icon base name */
476 ico_path
=HeapAlloc(GetProcessHeap(), 0, lstrlenA(path
)+1);
477 strcpy(ico_path
, path
);
480 if (*s
=='/' || *s
=='\\') {
488 if (*ico_name
=='\\') *ico_name
++='\0';
489 s
=strrchr(ico_name
,'.');
492 /* Compute the source-path hash */
495 /* Try to treat the source file as an exe */
496 xpm_path
=HeapAlloc(GetProcessHeap(), 0, strlen(iconsdir
)+1+4+1+strlen(ico_name
)+1+12+1+3);
497 sprintf(xpm_path
,"%s/%04x_%s.%d.xpm",iconsdir
,crc
,ico_name
,index
);
498 if (ExtractFromEXEDLL( path
, index
, xpm_path
))
501 /* Must be something else, ignore the index in that case */
502 sprintf(xpm_path
,"%s/%04x_%s.xpm",iconsdir
,crc
,ico_name
);
503 if (ExtractFromICO( path
, xpm_path
))
506 if (create_default_icon( xpm_path
, path
))
509 HeapFree( GetProcessHeap(), 0, xpm_path
);
513 HeapFree( GetProcessHeap(), 0, ico_path
);
517 static BOOL
DeferToRunOnce(LPWSTR link
)
521 static const WCHAR szRunOnce
[] = {
522 'S','o','f','t','w','a','r','e','\\',
523 'M','i','c','r','o','s','o','f','t','\\',
524 'W','i','n','d','o','w','s','\\',
525 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
526 'R','u','n','O','n','c','e',0
528 static const WCHAR szFormat
[] = { '%','s',' ','"','%','s','"',0 };
530 WCHAR szExecutable
[MAX_PATH
];
532 WINE_TRACE( "Deferring icon creation to reboot.\n");
534 if( !GetModuleFileNameW( 0, szExecutable
, MAX_PATH
) )
537 len
= ( lstrlenW( link
) + lstrlenW( szExecutable
) + 4)*sizeof(WCHAR
);
538 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
542 wsprintfW( buffer
, szFormat
, szExecutable
, link
);
544 r
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szRunOnce
, 0,
545 NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &hkey
, NULL
);
546 if ( r
== ERROR_SUCCESS
)
548 r
= RegSetValueExW(hkey
, link
, 0, REG_SZ
,
549 (LPBYTE
) buffer
, (lstrlenW(buffer
) + 1)*sizeof(WCHAR
));
552 HeapFree(GetProcessHeap(), 0, buffer
);
557 /* This escapes \ in filenames */
562 narg
= HeapAlloc(GetProcessHeap(),0,2*strlen(arg
)+2);
567 *x
++='\\'; /* escape \ */
574 static int fork_and_wait( char *linker
, char *link_name
, char *path
,
575 int desktop
, char *args
, char *icon_name
,
576 char *workdir
, char *description
)
579 const char *argv
[20];
582 WINE_TRACE( "linker app='%s' link='%s' mode=%s "
583 "path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
584 linker
, link_name
, desktop
? "desktop" : "menu",
585 path
, args
, icon_name
, workdir
, description
);
587 argv
[pos
++] = linker
;
588 argv
[pos
++] = "--link";
589 argv
[pos
++] = link_name
;
590 argv
[pos
++] = "--path";
592 argv
[pos
++] = desktop
? "--desktop" : "--menu";
593 if (args
&& strlen(args
))
595 argv
[pos
++] = "--args";
600 argv
[pos
++] = "--icon";
601 argv
[pos
++] = icon_name
;
603 if (workdir
&& strlen(workdir
))
605 argv
[pos
++] = "--workdir";
606 argv
[pos
++] = workdir
;
608 if (description
&& strlen(description
))
610 argv
[pos
++] = "--descr";
611 argv
[pos
++] = description
;
615 retcode
=spawnvp( _P_WAIT
, linker
, argv
);
617 WINE_ERR("%s returned %d\n",linker
,retcode
);
621 /* write the name of the ShellLinker into the buffer provided */
622 static BOOL
GetLinkerName( LPSTR szLinker
, DWORD max
)
629 r
= RegOpenKeyExA( HKEY_LOCAL_MACHINE
,
630 "Software\\Wine\\Wine\\Config\\Wine",
631 0, KEY_ALL_ACCESS
, &hkey
);
634 r
= RegQueryValueExA( hkey
, "ShellLinker", 0, &type
, szLinker
, &max
);
636 if( r
|| ( type
!= REG_SZ
) )
642 static char *cleanup_link( LPCWSTR link
)
647 /* make link name a Unix name -
648 strip leading slashes & remove extension */
649 while ( (*link
== '\\') || (*link
== '/' ) )
651 len
= WideCharToMultiByte( CP_ACP
, 0, link
, -1, NULL
, 0, NULL
, NULL
);
652 link_name
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof (WCHAR
) );
655 len
= WideCharToMultiByte( CP_ACP
, 0, link
, -1, link_name
, len
, NULL
, NULL
);
656 for (p
= link_name
; *p
; p
++)
659 p
= strrchr( link_name
, '.' );
665 /***********************************************************************
669 * returns TRUE if successful
670 * *loc will contain CS_DESKTOPDIRECTORY, CS_STARTMENU, CS_STARTUP
672 static BOOL
GetLinkLocation( LPCWSTR linkfile
, DWORD
*ofs
, DWORD
*loc
)
674 WCHAR ch
, filename
[MAX_PATH
], buffer
[MAX_PATH
];
676 const DWORD locations
[] = {
677 CSIDL_STARTUP
, CSIDL_DESKTOPDIRECTORY
, CSIDL_STARTMENU
};
679 if( !GetFullPathNameW( linkfile
, MAX_PATH
, filename
, NULL
))
682 for( i
=0; i
<sizeof(locations
)/sizeof(locations
[0]); i
++ )
684 if (!SHGetSpecialFolderPathW( 0, buffer
, locations
[i
], FALSE
))
687 len
= lstrlenW(buffer
);
688 if( len
>= MAX_PATH
)
691 /* do a lstrcmpinW */
694 r
= lstrcmpiW( filename
, buffer
);
700 /* return the remainder of the string and link type */
709 static BOOL
InvokeShellLinker( IShellLinkA
*sl
, LPCWSTR link
)
711 char *link_name
, *p
, *icon_name
= NULL
, *work_dir
= NULL
;
712 char *escaped_path
= NULL
, *escaped_args
= NULL
;
713 CHAR szDescription
[MAX_PATH
], szPath
[MAX_PATH
], szWorkDir
[MAX_PATH
];
714 CHAR szArgs
[MAX_PATH
], szIconPath
[MAX_PATH
], szLinker
[MAX_PATH
];
716 DWORD ofs
=0, csidl
= -1;
720 WINE_ERR("Link name is null\n");
724 if( !GetLinkerName( szLinker
, MAX_PATH
) )
726 WINE_ERR("Can't find the name of the linker script\n");
730 if( !GetLinkLocation( link
, &ofs
, &csidl
) )
732 WINE_WARN("Unknown link location (%08lx). Ignoring\n", csidl
);
735 if( (csidl
!= CSIDL_DESKTOPDIRECTORY
) && (csidl
!= CSIDL_STARTMENU
) )
737 WINE_WARN("Not under desktop or start menu. Ignoring.\n");
742 IShellLinkA_GetWorkingDirectory( sl
, szWorkDir
, sizeof(szWorkDir
));
743 WINE_TRACE("workdir : %s\n", szWorkDir
);
745 szDescription
[0] = 0;
746 IShellLinkA_GetDescription( sl
, szDescription
, sizeof(szDescription
));
747 WINE_TRACE("description: %s\n", szDescription
);
750 IShellLinkA_GetPath( sl
, szPath
, sizeof(szPath
), NULL
, SLGP_RAWPATH
);
751 WINE_TRACE("path : %s\n", szPath
);
754 IShellLinkA_GetArguments( sl
, szArgs
, sizeof(szArgs
) );
755 WINE_TRACE("args : %s\n", szArgs
);
758 IShellLinkA_GetIconLocation( sl
, szIconPath
,
759 sizeof(szIconPath
), &iIconId
);
760 WINE_TRACE("icon file : %s\n", szIconPath
);
764 LPITEMIDLIST pidl
= NULL
;
765 IShellLinkA_GetIDList( sl
, &pidl
);
766 if( pidl
&& SHGetPathFromIDListA( pidl
, szPath
) );
767 WINE_TRACE("pidl path : %s\n", szPath
);
770 /* extract the icon */
772 icon_name
= extract_icon( szIconPath
, iIconId
);
774 icon_name
= extract_icon( szPath
, iIconId
);
776 /* fail - try once again at reboot time */
779 WINE_ERR("failed to extract icon.\n");
786 /* check for .exe extension */
787 if (!(p
= strrchr( szPath
, '.' ))) return FALSE
;
788 if (strchr( p
, '\\' ) || strchr( p
, '/' )) return FALSE
;
789 if (strcasecmp( p
, ".exe" )) return FALSE
;
791 /* convert app working dir */
793 work_dir
= get_unix_file_name( szWorkDir
);
797 /* if there's no path... try run the link itself */
798 WideCharToMultiByte( CP_ACP
, 0, link
, -1, szArgs
, MAX_PATH
, NULL
, NULL
);
799 strcpy(szPath
, "C:\\Windows\\System\\start.exe");
802 link_name
= cleanup_link( &link
[ofs
] );
805 WINE_ERR("Couldn't clean up link name\n");
809 /* escape the path and parameters */
810 escaped_path
= escape(szPath
);
812 escaped_args
= escape(szArgs
);
814 r
= fork_and_wait(szLinker
, link_name
, escaped_path
,
815 (csidl
== CSIDL_DESKTOPDIRECTORY
), escaped_args
, icon_name
,
816 work_dir
? work_dir
: "", szDescription
);
818 HeapFree( GetProcessHeap(), 0, icon_name
);
819 HeapFree( GetProcessHeap(), 0, work_dir
);
820 HeapFree( GetProcessHeap(), 0, link_name
);
822 HeapFree( GetProcessHeap(), 0, escaped_args
);
824 HeapFree( GetProcessHeap(), 0, escaped_path
);
828 WINE_ERR("failed to fork and exec %s\n", szLinker
);
836 static BOOL
Process_Link( LPWSTR linkname
, BOOL bAgain
)
841 WCHAR fullname
[MAX_PATH
];
845 WINE_ERR("link name missing\n");
849 if( !GetFullPathNameW( linkname
, MAX_PATH
, fullname
, NULL
))
851 WINE_ERR("couldn't get full path of link file\n");
855 r
= CoInitialize( NULL
);
858 WINE_ERR("CoInitialize failed\n");
862 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
863 &IID_IShellLink
, (LPVOID
*) &sl
);
866 WINE_ERR("No IID_IShellLink\n");
870 r
= IShellLinkA_QueryInterface( sl
, &IID_IPersistFile
, (LPVOID
*) &pf
);
873 WINE_ERR("No IID_IPersistFile\n");
877 r
= IPersistFile_Load( pf
, fullname
, STGM_READ
);
880 /* If we something fails (eg. Couldn't extract icon)
881 * defer this menu entry to reboot via runonce
883 if( ! InvokeShellLinker( sl
, fullname
) && bAgain
)
884 DeferToRunOnce( fullname
);
886 WINE_TRACE("Success.\n");
889 IPersistFile_Release( pf
);
890 IShellLinkA_Release( sl
);
898 static CHAR
*next_token( LPSTR
*p
)
900 LPSTR token
= NULL
, t
= *p
;
913 /* unquote the token */
915 t
= strchr( token
, '"' );
924 t
= strchr( token
, ' ' );
934 /***********************************************************************
938 int PASCAL
WinMain (HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
940 LPSTR token
= NULL
, p
;
942 HANDLE hsem
= CreateSemaphoreA( NULL
, 1, 1, "winemenubuilder_semaphore");
945 /* running multiple instances of wineshelllink
946 at the same time may be dangerous */
947 if( WAIT_OBJECT_0
!= WaitForSingleObject( hsem
, INFINITE
) )
950 for( p
= cmdline
; p
&& *p
; )
952 token
= next_token( &p
);
955 if( !lstrcmpA( token
, "-r" ) )
957 else if( token
[0] == '-' )
959 WINE_ERR( "unknown option %s\n",token
);
963 WCHAR link
[MAX_PATH
];
965 MultiByteToWideChar( CP_ACP
, 0, token
, -1, link
, sizeof(link
) );
966 if( !Process_Link( link
, bAgain
) )
968 WINE_ERR( "failed to build menu item for %s\n",token
);
975 ReleaseSemaphore( hsem
, 1, NULL
);