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
7 * Copyright 2004 Dmitry Timoshkov
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This program will read a Windows shortcut file using the IShellLink
25 * interface, then invoke wineshelllink with the appropriate arguments
26 * to create a KDE/Gnome menu entry for the shortcut.
28 * winemenubuilder [ -r ] <shortcut.lnk>
30 * If the -r parameter is passed, and the shortcut cannot be created,
31 * this program will add RunOnce entry to invoke itself at the next
32 * reboot. This covers the case when a ShortCut is created before the
33 * executable containing its icon.
38 #include "wine/port.h"
56 #include "wine/unicode.h"
57 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(menubuilder);
62 #define in_desktop_dir(csidl) ((csidl)==CSIDL_DESKTOPDIRECTORY || \
63 (csidl)==CSIDL_COMMON_DESKTOPDIRECTORY)
64 #define in_startmenu(csidl) ((csidl)==CSIDL_STARTMENU || \
65 (csidl)==CSIDL_COMMON_STARTMENU)
67 /* link file formats */
88 GRPICONDIRENTRY idEntries[1];
120 /* Icon extraction routines
122 * FIXME: should use PrivateExtractIcons and friends
123 * FIXME: should not use stdio
126 static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, LPCWSTR commentW)
136 BOOL aColorUsed[256] = {0};
141 if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
144 if (!(fXPMFile = fopen(szXPMFileName, "w")))
147 i = WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, NULL, 0, NULL, NULL);
149 WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, comment, i, NULL, NULL);
151 nHeight = pIcon->bmiHeader.biHeight / 2;
152 nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
153 + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
154 nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
155 + ((pIcon->bmiHeader.biWidth % 32) > 0));
156 b8BitColors = pIcon->bmiHeader.biBitCount == 8;
157 nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
158 : 1 << pIcon->bmiHeader.biBitCount;
159 pXOR = (const BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
160 pAND = pXOR + nHeight * nXORWidthBytes;
162 #define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
163 #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)
165 for (i = 0; i < nHeight; i++) {
166 for (j = 0; j < pIcon->bmiHeader.biWidth; j++) {
167 if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
169 aColorUsed[COLOR(j,i)] = TRUE;
175 if (fprintf(fXPMFile, "/* XPM */\n/* %s */\nstatic char *icon[] = {\n", comment) <= 0)
177 if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
178 (int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
181 for (i = 0; i < nColors; i++) {
183 if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
184 pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
187 if (fprintf(fXPMFile, "\" c None\"") <= 0)
190 for (i = 0; i < nHeight; i++)
192 if (fprintf(fXPMFile, ",\n\"") <= 0)
194 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
198 if (fprintf(fXPMFile, " ") <= 0)
202 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
205 if (fprintf(fXPMFile, "\"") <= 0)
208 if (fprintf(fXPMFile, "};\n") <= 0)
221 unlink( szXPMFileName );
225 static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam)
227 ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
229 if (!sEnumRes->nIndex--)
231 *sEnumRes->pResInfo = FindResourceW(hModule, lpszName, (LPCWSTR)RT_GROUP_ICON);
238 static BOOL extract_icon32(LPCWSTR szFileName, int nIndex, const char *szXPMFileName)
242 LPCWSTR lpName = NULL;
244 GRPICONDIR *pIconDir;
246 ENUMRESSTRUCT sEnumRes;
252 hModule = LoadLibraryExW(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE);
255 WINE_ERR("LoadLibraryExW (%s) failed, error %ld\n",
256 wine_dbgstr_w(szFileName), GetLastError());
262 hResInfo = FindResourceW(hModule, MAKEINTRESOURCEW(-nIndex), (LPCWSTR)RT_GROUP_ICON);
263 WINE_TRACE("FindResourceW (%s) called, return %p, error %ld\n",
264 wine_dbgstr_w(szFileName), hResInfo, GetLastError());
269 sEnumRes.pResInfo = &hResInfo;
270 sEnumRes.nIndex = nIndex;
271 EnumResourceNamesW(hModule, (LPCWSTR)RT_GROUP_ICON, EnumResNameProc, (LONG_PTR)&sEnumRes);
276 if ((hResData = LoadResource(hModule, hResInfo)))
278 if ((pIconDir = LockResource(hResData)))
280 for (i = 0; i < pIconDir->idCount; i++)
282 if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
284 if (pIconDir->idEntries[i].wBitCount > nMaxBits)
286 nMaxBits = pIconDir->idEntries[i].wBitCount;
291 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
293 lpName = MAKEINTRESOURCEW(pIconDir->idEntries[i].nID);
294 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
299 FreeResource(hResData);
304 WINE_ERR("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
305 FreeLibrary(hModule);
309 if ((hResInfo = FindResourceW(hModule, lpName, (LPCWSTR)RT_ICON)))
311 if ((hResData = LoadResource(hModule, hResInfo)))
313 if ((pIcon = LockResource(hResData)))
315 if(SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
319 FreeResource(hResData);
323 FreeLibrary(hModule);
327 static BOOL ExtractFromEXEDLL(LPCWSTR szFileName, int nIndex, const char *szXPMFileName)
329 if (!extract_icon32(szFileName, nIndex, szXPMFileName) /*&&
330 !extract_icon16(szFileName, szXPMFileName)*/)
335 static int ExtractFromICO(LPCWSTR szFileName, const char *szXPMFileName)
339 ICONDIRENTRY *pIconDirEntry;
346 filename = wine_get_unix_file_name(szFileName);
347 if (!(fICOFile = fopen(filename, "r")))
350 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
352 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
355 if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
357 if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
360 for (i = 0; i < iconDir.idCount; i++)
361 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
364 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
366 if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
368 if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
370 if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
373 if(!SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
379 HeapFree(GetProcessHeap(), 0, filename);
389 HeapFree(GetProcessHeap(), 0, filename);
393 static BOOL create_default_icon( const char *filename, const char* comment )
398 if (!(fXPM = fopen(filename, "w"))) return FALSE;
399 if (fprintf(fXPM, "/* XPM */\n/* %s */\nstatic char * icon[] = {", comment) <= 0)
401 for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++) {
402 if (fprintf( fXPM, "\n\"%s\",", wine_xpm[i]) <= 0)
405 if (fprintf( fXPM, "};\n" ) <=0)
416 static unsigned short crc16(const char* string)
418 unsigned short crc = 0;
421 for (i = 0; string[i] != 0; i++)
424 for (j = 0; j < 8; c >>= 1, j++)
426 xor_poly = (c ^ crc) & 1;
435 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
436 static char *extract_icon( LPCWSTR path, int index)
440 char *iconsdir, *ico_path, *ico_name, *xpm_path;
445 /* Where should we save the icon? */
446 WINE_TRACE("path=[%s] index=%d\n", wine_dbgstr_w(path), index);
447 iconsdir=NULL; /* Default is no icon */
448 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
450 static const WCHAR IconsDirW[] = {'I','c','o','n','s','D','i','r',0};
454 if (!RegQueryValueExW(hkey, IconsDirW, 0, NULL, NULL, &size))
456 iconsdirW = HeapAlloc(GetProcessHeap(), 0, size);
457 RegQueryValueExW(hkey, IconsDirW, 0, NULL, (LPBYTE)iconsdirW, &size);
459 s = wine_get_unix_file_name(iconsdirW);
464 int n = WideCharToMultiByte(CP_UNIXCP, 0, iconsdirW, -1, NULL, 0, NULL, NULL);
465 iconsdir = HeapAlloc(GetProcessHeap(), 0, n);
466 WideCharToMultiByte(CP_UNIXCP, 0, iconsdirW, -1, iconsdir, n, NULL, NULL);
468 HeapFree(GetProcessHeap(), 0, iconsdirW);
472 WCHAR path[MAX_PATH];
474 if (GetTempPathW(MAX_PATH, path))
476 s = wine_get_unix_file_name(path);
484 return NULL; /* No icon created */
488 HeapFree(GetProcessHeap(), 0, iconsdir);
489 return NULL; /* No icon created */
492 /* If icon path begins with a '*' then this is a deferred call */
499 /* Determine the icon base name */
500 n = WideCharToMultiByte(CP_UNIXCP, 0, path, -1, NULL, 0, NULL, NULL);
501 ico_path = HeapAlloc(GetProcessHeap(), 0, n);
502 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, ico_path, n, NULL, NULL);
505 if (*s=='/' || *s=='\\') {
513 if (*ico_name=='\\') *ico_name++='\0';
514 s=strrchr(ico_name,'.');
517 /* Compute the source-path hash */
520 /* Try to treat the source file as an exe */
521 xpm_path=HeapAlloc(GetProcessHeap(), 0, strlen(iconsdir)+1+4+1+strlen(ico_name)+1+12+1+3);
522 sprintf(xpm_path,"%s/%04x_%s.%d.xpm",iconsdir,crc,ico_name,index);
523 if (ExtractFromEXEDLL( path, index, xpm_path ))
526 /* Must be something else, ignore the index in that case */
527 sprintf(xpm_path,"%s/%04x_%s.xpm",iconsdir,crc,ico_name);
528 if (ExtractFromICO( path, xpm_path))
531 if (create_default_icon( xpm_path, ico_path ))
534 HeapFree( GetProcessHeap(), 0, xpm_path );
538 HeapFree(GetProcessHeap(), 0, iconsdir);
539 HeapFree(GetProcessHeap(), 0, ico_path);
543 static BOOL DeferToRunOnce(LPWSTR link)
547 static const WCHAR szRunOnce[] = {
548 'S','o','f','t','w','a','r','e','\\',
549 'M','i','c','r','o','s','o','f','t','\\',
550 'W','i','n','d','o','w','s','\\',
551 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
552 'R','u','n','O','n','c','e',0
554 static const WCHAR szFormat[] = { '%','s',' ','"','%','s','"',0 };
556 WCHAR szExecutable[MAX_PATH];
558 WINE_TRACE( "Deferring icon creation to reboot.\n");
560 len = GetModuleFileNameW( 0, szExecutable, MAX_PATH );
561 if (!len || len >= MAX_PATH) return FALSE;
563 len = ( lstrlenW( link ) + lstrlenW( szExecutable ) + 4)*sizeof(WCHAR);
564 buffer = HeapAlloc( GetProcessHeap(), 0, len );
568 wsprintfW( buffer, szFormat, szExecutable, link );
570 r = RegCreateKeyExW(HKEY_LOCAL_MACHINE, szRunOnce, 0,
571 NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
572 if ( r == ERROR_SUCCESS )
574 r = RegSetValueExW(hkey, link, 0, REG_SZ,
575 (LPBYTE) buffer, (lstrlenW(buffer) + 1)*sizeof(WCHAR));
578 HeapFree(GetProcessHeap(), 0, buffer);
583 /* This escapes \ in filenames */
584 static LPSTR escape(LPCWSTR arg)
591 while((esc = strchrW(esc, '\\')))
597 len += WideCharToMultiByte(CP_UNIXCP, 0, arg, -1, NULL, 0, NULL, NULL);
598 narg = HeapAlloc(GetProcessHeap(), 0, len);
603 n = WideCharToMultiByte(CP_UNIXCP, 0, arg, 1, x, len, NULL, NULL);
607 *x++='\\'; /* escape \ */
614 static int fork_and_wait( char *linker, char *link_name, char *path,
615 int desktop, char *args, char *icon_name,
616 char *workdir, char *description )
619 const char *argv[20];
622 WINE_TRACE( "linker app='%s' link='%s' mode=%s "
623 "path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
624 linker, link_name, desktop ? "desktop" : "menu",
625 path, args, icon_name, workdir, description );
627 argv[pos++] = linker ;
628 argv[pos++] = "--link";
629 argv[pos++] = link_name;
630 argv[pos++] = "--path";
632 argv[pos++] = desktop ? "--desktop" : "--menu";
633 if (args && strlen(args))
635 argv[pos++] = "--args";
640 argv[pos++] = "--icon";
641 argv[pos++] = icon_name;
643 if (workdir && strlen(workdir))
645 argv[pos++] = "--workdir";
646 argv[pos++] = workdir;
648 if (description && strlen(description))
650 argv[pos++] = "--descr";
651 argv[pos++] = description;
655 retcode=spawnvp( _P_WAIT, linker, argv );
657 WINE_ERR("%s returned %d\n",linker,retcode);
661 static char *cleanup_link( LPCWSTR link )
663 char *unix_file_name;
666 unix_file_name = wine_get_unix_file_name(link);
669 WINE_ERR("target link %s not found\n", wine_dbgstr_w(link));
673 link_name = unix_file_name;
674 p = strrchr( link_name, '/' );
678 p = strrchr( link_name, '.' );
682 p = HeapAlloc(GetProcessHeap(), 0, strlen(link_name) + 1);
683 strcpy(p, link_name);
684 HeapFree(GetProcessHeap(), 0, unix_file_name);
689 /***********************************************************************
693 * returns TRUE if successful
694 * *loc will contain CS_DESKTOPDIRECTORY, CS_STARTMENU, CS_STARTUP
696 static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *loc )
698 WCHAR filename[MAX_PATH], buffer[MAX_PATH];
699 DWORD len, i, r, filelen;
700 const DWORD locations[] = {
701 CSIDL_STARTUP, CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU,
702 CSIDL_COMMON_STARTUP, CSIDL_COMMON_DESKTOPDIRECTORY,
703 CSIDL_COMMON_STARTMENU };
705 WINE_TRACE("%s\n", wine_dbgstr_w(linkfile));
706 filelen=GetFullPathNameW( linkfile, MAX_PATH, filename, NULL );
707 if (filelen==0 || filelen>MAX_PATH)
710 WINE_TRACE("%s\n", wine_dbgstr_w(filename));
712 for( i=0; i<sizeof(locations)/sizeof(locations[0]); i++ )
714 if (!SHGetSpecialFolderPathW( 0, buffer, locations[i], FALSE ))
717 len = lstrlenW(buffer);
721 if (len > filelen || filename[len]!='\\')
723 /* do a lstrcmpinW */
725 r = lstrcmpiW( filename, buffer );
726 filename[len] = '\\';
730 /* return the remainder of the string and link type */
738 static BOOL InvokeShellLinker( IShellLinkW *sl, LPCWSTR link, BOOL bAgain )
740 char *link_name = NULL, *icon_name = NULL, *work_dir = NULL;
741 char *escaped_path = NULL, *escaped_args = NULL, *escaped_description = NULL;
742 WCHAR szDescription[INFOTIPSIZE], szPath[MAX_PATH], szWorkDir[MAX_PATH];
743 WCHAR szArgs[INFOTIPSIZE], szIconPath[MAX_PATH];
744 int iIconId = 0, r = -1;
749 WINE_ERR("Link name is null\n");
753 if( !GetLinkLocation( link, &csidl ) )
755 WINE_WARN("Unknown link location '%s'. Ignoring.\n",wine_dbgstr_w(link));
758 if (!in_desktop_dir(csidl) && !in_startmenu(csidl))
760 WINE_WARN("Not under desktop or start menu. Ignoring.\n");
765 IShellLinkW_GetWorkingDirectory( sl, szWorkDir, MAX_PATH );
766 WINE_TRACE("workdir : %s\n", wine_dbgstr_w(szWorkDir));
768 szDescription[0] = 0;
769 IShellLinkW_GetDescription( sl, szDescription, INFOTIPSIZE );
770 WINE_TRACE("description: %s\n", wine_dbgstr_w(szDescription));
773 IShellLinkW_GetPath( sl, szPath, MAX_PATH, NULL, SLGP_RAWPATH );
774 WINE_TRACE("path : %s\n", wine_dbgstr_w(szPath));
777 IShellLinkW_GetArguments( sl, szArgs, INFOTIPSIZE );
778 WINE_TRACE("args : %s\n", wine_dbgstr_w(szArgs));
781 IShellLinkW_GetIconLocation( sl, szIconPath, MAX_PATH, &iIconId );
782 WINE_TRACE("icon file : %s\n", wine_dbgstr_w(szIconPath) );
786 LPITEMIDLIST pidl = NULL;
787 IShellLinkW_GetIDList( sl, &pidl );
788 if( pidl && SHGetPathFromIDListW( pidl, szPath ) );
789 WINE_TRACE("pidl path : %s\n", wine_dbgstr_w(szPath));
792 /* extract the icon */
794 icon_name = extract_icon( szIconPath , iIconId );
796 icon_name = extract_icon( szPath, iIconId );
798 /* fail - try once again at reboot time */
803 WINE_WARN("Unable to extract icon, deferring.\n");
806 WINE_ERR("failed to extract icon.\n");
812 static const WCHAR exeW[] = {'.','e','x','e',0};
815 /* check for .exe extension */
816 if (!(p = strrchrW( szPath, '.' ))) return FALSE;
817 if (strchrW( p, '\\' ) || strchrW( p, '/' )) return FALSE;
818 if (lstrcmpiW( p, exeW )) return FALSE;
820 /* convert app working dir */
822 work_dir = wine_get_unix_file_name( szWorkDir );
826 static const WCHAR startW[] = {
827 '\\','c','o','m','m','a','n','d',
828 '\\','s','t','a','r','t','.','e','x','e',0};
830 /* if there's no path... try run the link itself */
831 lstrcpynW(szArgs, link, MAX_PATH);
832 GetWindowsDirectoryW(szPath, MAX_PATH);
833 lstrcatW(szPath, startW);
836 link_name = cleanup_link( link );
839 WINE_ERR("Couldn't clean up link name %s\n", wine_dbgstr_w(link));
843 /* escape the path and parameters */
844 escaped_path = escape(szPath);
845 escaped_args = escape(szArgs);
846 escaped_description = escape(szDescription);
848 r = fork_and_wait("wineshelllink", link_name, escaped_path,
849 in_desktop_dir(csidl), escaped_args, icon_name,
850 work_dir ? work_dir : "", escaped_description);
853 HeapFree( GetProcessHeap(), 0, icon_name );
854 HeapFree( GetProcessHeap(), 0, work_dir );
855 HeapFree( GetProcessHeap(), 0, link_name );
856 HeapFree( GetProcessHeap(), 0, escaped_args );
857 HeapFree( GetProcessHeap(), 0, escaped_path );
858 HeapFree( GetProcessHeap(), 0, escaped_description );
862 WINE_ERR("failed to fork and exec wineshelllink\n" );
870 static BOOL Process_Link( LPCWSTR linkname, BOOL bAgain )
875 WCHAR fullname[MAX_PATH];
878 WINE_TRACE("%s, again %d\n", wine_dbgstr_w(linkname), bAgain);
882 WINE_ERR("link name missing\n");
886 len=GetFullPathNameW( linkname, MAX_PATH, fullname, NULL );
887 if (len==0 || len>MAX_PATH)
889 WINE_ERR("couldn't get full path of link file\n");
893 r = CoInitialize( NULL );
896 WINE_ERR("CoInitialize failed\n");
900 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
901 &IID_IShellLinkW, (LPVOID *) &sl );
904 WINE_ERR("No IID_IShellLink\n");
908 r = IShellLinkW_QueryInterface( sl, &IID_IPersistFile, (LPVOID*) &pf );
911 WINE_ERR("No IID_IPersistFile\n");
915 r = IPersistFile_Load( pf, fullname, STGM_READ );
918 /* If something fails (eg. Couldn't extract icon)
919 * defer this menu entry to reboot via runonce
921 if( ! InvokeShellLinker( sl, fullname, bAgain ) && bAgain )
922 DeferToRunOnce( fullname );
924 WINE_TRACE("Success.\n");
927 IPersistFile_Release( pf );
928 IShellLinkW_Release( sl );
936 static CHAR *next_token( LPSTR *p )
938 LPSTR token = NULL, t = *p;
951 /* unquote the token */
953 t = strchr( token, '"' );
962 t = strchr( token, ' ' );
972 /***********************************************************************
976 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
978 LPSTR token = NULL, p;
980 HANDLE hsem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
983 /* running multiple instances of wineshelllink
984 at the same time may be dangerous */
985 if( WAIT_OBJECT_0 != WaitForSingleObject( hsem, INFINITE ) )
991 for( p = cmdline; p && *p; )
993 token = next_token( &p );
996 if( !lstrcmpA( token, "-r" ) )
998 else if( token[0] == '-' )
1000 WINE_ERR( "unknown option %s\n",token);
1004 WCHAR link[MAX_PATH];
1006 MultiByteToWideChar( CP_ACP, 0, token, -1, link, sizeof(link) );
1007 if( !Process_Link( link, bAgain ) )
1009 WINE_ERR( "failed to build menu item for %s\n",token);
1015 ReleaseSemaphore( hsem, 1, NULL );
1016 CloseHandle( hsem );