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"
58 #include "wine/unicode.h"
59 #include "wine/debug.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(menubuilder);
64 #define in_desktop_dir(csidl) ((csidl)==CSIDL_DESKTOPDIRECTORY || \
65 (csidl)==CSIDL_COMMON_DESKTOPDIRECTORY)
66 #define in_startmenu(csidl) ((csidl)==CSIDL_STARTMENU || \
67 (csidl)==CSIDL_COMMON_STARTMENU)
69 /* link file formats */
90 GRPICONDIRENTRY idEntries[1];
122 /* Icon extraction routines
124 * FIXME: should use PrivateExtractIcons and friends
125 * FIXME: should not use stdio
128 static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, LPCWSTR commentW)
138 BOOL aColorUsed[256] = {0};
143 if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
146 if (!(fXPMFile = fopen(szXPMFileName, "w")))
149 i = WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, NULL, 0, NULL, NULL);
151 WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, comment, i, NULL, NULL);
153 nHeight = pIcon->bmiHeader.biHeight / 2;
154 nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
155 + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
156 nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
157 + ((pIcon->bmiHeader.biWidth % 32) > 0));
158 b8BitColors = pIcon->bmiHeader.biBitCount == 8;
159 nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
160 : 1 << pIcon->bmiHeader.biBitCount;
161 pXOR = (const BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
162 pAND = pXOR + nHeight * nXORWidthBytes;
164 #define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
165 #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)
167 for (i = 0; i < nHeight; i++) {
168 for (j = 0; j < pIcon->bmiHeader.biWidth; j++) {
169 if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
171 aColorUsed[COLOR(j,i)] = TRUE;
177 if (fprintf(fXPMFile, "/* XPM */\n/* %s */\nstatic char *icon[] = {\n", comment) <= 0)
179 if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
180 (int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
183 for (i = 0; i < nColors; i++) {
185 if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
186 pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
189 if (fprintf(fXPMFile, "\" c None\"") <= 0)
192 for (i = 0; i < nHeight; i++)
194 if (fprintf(fXPMFile, ",\n\"") <= 0)
196 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
200 if (fprintf(fXPMFile, " ") <= 0)
204 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
207 if (fprintf(fXPMFile, "\"") <= 0)
210 if (fprintf(fXPMFile, "};\n") <= 0)
223 unlink( szXPMFileName );
227 static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam)
229 ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
231 if (!sEnumRes->nIndex--)
233 *sEnumRes->pResInfo = FindResourceW(hModule, lpszName, (LPCWSTR)RT_GROUP_ICON);
240 static BOOL extract_icon32(LPCWSTR szFileName, int nIndex, const char *szXPMFileName)
244 LPCWSTR lpName = NULL;
246 GRPICONDIR *pIconDir;
248 ENUMRESSTRUCT sEnumRes;
254 hModule = LoadLibraryExW(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE);
257 WINE_ERR("LoadLibraryExW (%s) failed, error %ld\n",
258 wine_dbgstr_w(szFileName), GetLastError());
264 hResInfo = FindResourceW(hModule, MAKEINTRESOURCEW(-nIndex), (LPCWSTR)RT_GROUP_ICON);
265 WINE_TRACE("FindResourceW (%s) called, return %p, error %ld\n",
266 wine_dbgstr_w(szFileName), hResInfo, GetLastError());
271 sEnumRes.pResInfo = &hResInfo;
272 sEnumRes.nIndex = nIndex;
273 EnumResourceNamesW(hModule, (LPCWSTR)RT_GROUP_ICON, EnumResNameProc, (LONG_PTR)&sEnumRes);
278 if ((hResData = LoadResource(hModule, hResInfo)))
280 if ((pIconDir = LockResource(hResData)))
282 for (i = 0; i < pIconDir->idCount; i++)
284 if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
286 if (pIconDir->idEntries[i].wBitCount > nMaxBits)
288 nMaxBits = pIconDir->idEntries[i].wBitCount;
293 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
295 lpName = MAKEINTRESOURCEW(pIconDir->idEntries[i].nID);
296 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
301 FreeResource(hResData);
306 WINE_ERR("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
307 FreeLibrary(hModule);
311 if ((hResInfo = FindResourceW(hModule, lpName, (LPCWSTR)RT_ICON)))
313 if ((hResData = LoadResource(hModule, hResInfo)))
315 if ((pIcon = LockResource(hResData)))
317 if(SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
321 FreeResource(hResData);
325 FreeLibrary(hModule);
329 static BOOL ExtractFromEXEDLL(LPCWSTR szFileName, int nIndex, const char *szXPMFileName)
331 if (!extract_icon32(szFileName, nIndex, szXPMFileName) /*&&
332 !extract_icon16(szFileName, szXPMFileName)*/)
337 static int ExtractFromICO(LPCWSTR szFileName, const char *szXPMFileName)
341 ICONDIRENTRY *pIconDirEntry;
348 filename = wine_get_unix_file_name(szFileName);
349 if (!(fICOFile = fopen(filename, "r")))
352 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
354 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
357 if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
359 if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
362 for (i = 0; i < iconDir.idCount; i++)
363 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
366 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
368 if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
370 if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
372 if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
375 if(!SaveIconResAsXPM(pIcon, szXPMFileName, szFileName))
381 HeapFree(GetProcessHeap(), 0, filename);
391 HeapFree(GetProcessHeap(), 0, filename);
395 static BOOL create_default_icon( const char *filename, const char* comment )
400 if (!(fXPM = fopen(filename, "w"))) return FALSE;
401 if (fprintf(fXPM, "/* XPM */\n/* %s */\nstatic char * icon[] = {", comment) <= 0)
403 for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++) {
404 if (fprintf( fXPM, "\n\"%s\",", wine_xpm[i]) <= 0)
407 if (fprintf( fXPM, "};\n" ) <=0)
418 static unsigned short crc16(const char* string)
420 unsigned short crc = 0;
423 for (i = 0; string[i] != 0; i++)
426 for (j = 0; j < 8; c >>= 1, j++)
428 xor_poly = (c ^ crc) & 1;
437 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
438 static char *extract_icon( LPCWSTR path, int index)
442 char *iconsdir, *ico_path, *ico_name, *xpm_path;
447 /* Where should we save the icon? */
448 WINE_TRACE("path=[%s] index=%d\n", wine_dbgstr_w(path), index);
449 iconsdir=NULL; /* Default is no icon */
450 if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey ))
452 static const WCHAR IconsDirW[] = {'I','c','o','n','s','D','i','r',0};
456 if (!RegQueryValueExW(hkey, IconsDirW, 0, NULL, NULL, &size))
458 iconsdirW = HeapAlloc(GetProcessHeap(), 0, size);
459 RegQueryValueExW(hkey, IconsDirW, 0, NULL, (LPBYTE)iconsdirW, &size);
461 s = wine_get_unix_file_name(iconsdirW);
466 int n = WideCharToMultiByte(CP_UNIXCP, 0, iconsdirW, -1, NULL, 0, NULL, NULL);
467 iconsdir = HeapAlloc(GetProcessHeap(), 0, n);
468 WideCharToMultiByte(CP_UNIXCP, 0, iconsdirW, -1, iconsdir, n, NULL, NULL);
470 HeapFree(GetProcessHeap(), 0, iconsdirW);
474 WCHAR path[MAX_PATH];
476 if (GetTempPathW(MAX_PATH, path))
478 s = wine_get_unix_file_name(path);
486 return NULL; /* No icon created */
490 HeapFree(GetProcessHeap(), 0, iconsdir);
491 return NULL; /* No icon created */
494 /* If icon path begins with a '*' then this is a deferred call */
501 /* Determine the icon base name */
502 n = WideCharToMultiByte(CP_UNIXCP, 0, path, -1, NULL, 0, NULL, NULL);
503 ico_path = HeapAlloc(GetProcessHeap(), 0, n);
504 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, ico_path, n, NULL, NULL);
507 if (*s=='/' || *s=='\\') {
515 if (*ico_name=='\\') *ico_name++='\0';
516 s=strrchr(ico_name,'.');
519 /* Compute the source-path hash */
522 /* Try to treat the source file as an exe */
523 xpm_path=HeapAlloc(GetProcessHeap(), 0, strlen(iconsdir)+1+4+1+strlen(ico_name)+1+12+1+3);
524 sprintf(xpm_path,"%s/%04x_%s.%d.xpm",iconsdir,crc,ico_name,index);
525 if (ExtractFromEXEDLL( path, index, xpm_path ))
528 /* Must be something else, ignore the index in that case */
529 sprintf(xpm_path,"%s/%04x_%s.xpm",iconsdir,crc,ico_name);
530 if (ExtractFromICO( path, xpm_path))
533 if (create_default_icon( xpm_path, ico_path ))
536 HeapFree( GetProcessHeap(), 0, xpm_path );
540 HeapFree(GetProcessHeap(), 0, iconsdir);
541 HeapFree(GetProcessHeap(), 0, ico_path);
545 static BOOL DeferToRunOnce(LPWSTR link)
549 static const WCHAR szRunOnce[] = {
550 'S','o','f','t','w','a','r','e','\\',
551 'M','i','c','r','o','s','o','f','t','\\',
552 'W','i','n','d','o','w','s','\\',
553 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
554 'R','u','n','O','n','c','e',0
556 static const WCHAR szFormat[] = { '%','s',' ','"','%','s','"',0 };
558 WCHAR szExecutable[MAX_PATH];
560 WINE_TRACE( "Deferring icon creation to reboot.\n");
562 len = GetModuleFileNameW( 0, szExecutable, MAX_PATH );
563 if (!len || len >= MAX_PATH) return FALSE;
565 len = ( lstrlenW( link ) + lstrlenW( szExecutable ) + 4)*sizeof(WCHAR);
566 buffer = HeapAlloc( GetProcessHeap(), 0, len );
570 wsprintfW( buffer, szFormat, szExecutable, link );
572 r = RegCreateKeyExW(HKEY_LOCAL_MACHINE, szRunOnce, 0,
573 NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, NULL);
574 if ( r == ERROR_SUCCESS )
576 r = RegSetValueExW(hkey, link, 0, REG_SZ,
577 (LPBYTE) buffer, (lstrlenW(buffer) + 1)*sizeof(WCHAR));
580 HeapFree(GetProcessHeap(), 0, buffer);
585 /* This escapes \ in filenames */
586 static LPSTR escape(LPCWSTR arg)
593 while((esc = strchrW(esc, '\\')))
599 len += WideCharToMultiByte(CP_UNIXCP, 0, arg, -1, NULL, 0, NULL, NULL);
600 narg = HeapAlloc(GetProcessHeap(), 0, len);
605 n = WideCharToMultiByte(CP_UNIXCP, 0, arg, 1, x, len, NULL, NULL);
609 *x++='\\'; /* escape \ */
616 static int fork_and_wait( char *linker, char *link_name, char *path,
617 int desktop, char *args, char *icon_name,
618 char *workdir, char *description )
621 const char *argv[20];
624 WINE_TRACE( "linker app='%s' link='%s' mode=%s "
625 "path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
626 linker, link_name, desktop ? "desktop" : "menu",
627 path, args, icon_name, workdir, description );
629 argv[pos++] = linker ;
630 argv[pos++] = "--link";
631 argv[pos++] = link_name;
632 argv[pos++] = "--path";
634 argv[pos++] = desktop ? "--desktop" : "--menu";
635 if (args && strlen(args))
637 argv[pos++] = "--args";
642 argv[pos++] = "--icon";
643 argv[pos++] = icon_name;
645 if (workdir && strlen(workdir))
647 argv[pos++] = "--workdir";
648 argv[pos++] = workdir;
650 if (description && strlen(description))
652 argv[pos++] = "--descr";
653 argv[pos++] = description;
657 retcode=spawnvp( _P_WAIT, linker, argv );
659 WINE_ERR("%s returned %d\n",linker,retcode);
663 static char *cleanup_link( LPCWSTR link )
665 char *unix_file_name;
668 unix_file_name = wine_get_unix_file_name(link);
671 WINE_ERR("target link %s not found\n", wine_dbgstr_w(link));
675 link_name = unix_file_name;
676 p = strrchr( link_name, '/' );
680 p = strrchr( link_name, '.' );
684 p = HeapAlloc(GetProcessHeap(), 0, strlen(link_name) + 1);
685 strcpy(p, link_name);
686 HeapFree(GetProcessHeap(), 0, unix_file_name);
691 /***********************************************************************
695 * returns TRUE if successful
696 * *loc will contain CS_DESKTOPDIRECTORY, CS_STARTMENU, CS_STARTUP
698 static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *loc )
700 WCHAR filename[MAX_PATH], buffer[MAX_PATH];
701 DWORD len, i, r, filelen;
702 const DWORD locations[] = {
703 CSIDL_STARTUP, CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU,
704 CSIDL_COMMON_STARTUP, CSIDL_COMMON_DESKTOPDIRECTORY,
705 CSIDL_COMMON_STARTMENU };
707 WINE_TRACE("%s\n", wine_dbgstr_w(linkfile));
708 filelen=GetFullPathNameW( linkfile, MAX_PATH, filename, NULL );
709 if (filelen==0 || filelen>MAX_PATH)
712 WINE_TRACE("%s\n", wine_dbgstr_w(filename));
714 for( i=0; i<sizeof(locations)/sizeof(locations[0]); i++ )
716 if (!SHGetSpecialFolderPathW( 0, buffer, locations[i], FALSE ))
719 len = lstrlenW(buffer);
723 if (len > filelen || filename[len]!='\\')
725 /* do a lstrcmpinW */
727 r = lstrcmpiW( filename, buffer );
728 filename[len] = '\\';
732 /* return the remainder of the string and link type */
740 static BOOL InvokeShellLinker( IShellLinkW *sl, LPCWSTR link, BOOL bAgain )
742 char *link_name = NULL, *icon_name = NULL, *work_dir = NULL;
743 char *escaped_path = NULL, *escaped_args = NULL, *escaped_description = NULL;
744 WCHAR szDescription[INFOTIPSIZE], szPath[MAX_PATH], szWorkDir[MAX_PATH];
745 WCHAR szArgs[INFOTIPSIZE], szIconPath[MAX_PATH];
746 int iIconId = 0, r = -1;
751 WINE_ERR("Link name is null\n");
755 if( !GetLinkLocation( link, &csidl ) )
757 WINE_WARN("Unknown link location '%s'. Ignoring.\n",wine_dbgstr_w(link));
760 if (!in_desktop_dir(csidl) && !in_startmenu(csidl))
762 WINE_WARN("Not under desktop or start menu. Ignoring.\n");
767 IShellLinkW_GetWorkingDirectory( sl, szWorkDir, MAX_PATH );
768 WINE_TRACE("workdir : %s\n", wine_dbgstr_w(szWorkDir));
770 szDescription[0] = 0;
771 IShellLinkW_GetDescription( sl, szDescription, INFOTIPSIZE );
772 WINE_TRACE("description: %s\n", wine_dbgstr_w(szDescription));
775 IShellLinkW_GetPath( sl, szPath, MAX_PATH, NULL, SLGP_RAWPATH );
776 WINE_TRACE("path : %s\n", wine_dbgstr_w(szPath));
779 IShellLinkW_GetArguments( sl, szArgs, INFOTIPSIZE );
780 WINE_TRACE("args : %s\n", wine_dbgstr_w(szArgs));
783 IShellLinkW_GetIconLocation( sl, szIconPath, MAX_PATH, &iIconId );
784 WINE_TRACE("icon file : %s\n", wine_dbgstr_w(szIconPath) );
788 LPITEMIDLIST pidl = NULL;
789 IShellLinkW_GetIDList( sl, &pidl );
790 if( pidl && SHGetPathFromIDListW( pidl, szPath ) );
791 WINE_TRACE("pidl path : %s\n", wine_dbgstr_w(szPath));
794 /* extract the icon */
796 icon_name = extract_icon( szIconPath , iIconId );
798 icon_name = extract_icon( szPath, iIconId );
800 /* fail - try once again at reboot time */
805 WINE_WARN("Unable to extract icon, deferring.\n");
808 WINE_ERR("failed to extract icon.\n");
814 static const WCHAR exeW[] = {'.','e','x','e',0};
817 /* check for .exe extension */
818 if (!(p = strrchrW( szPath, '.' ))) return FALSE;
819 if (strchrW( p, '\\' ) || strchrW( p, '/' )) return FALSE;
820 if (lstrcmpiW( p, exeW )) return FALSE;
822 /* convert app working dir */
824 work_dir = wine_get_unix_file_name( szWorkDir );
828 static const WCHAR startW[] = {
829 '\\','c','o','m','m','a','n','d',
830 '\\','s','t','a','r','t','.','e','x','e',0};
832 /* if there's no path... try run the link itself */
833 lstrcpynW(szArgs, link, MAX_PATH);
834 GetWindowsDirectoryW(szPath, MAX_PATH);
835 lstrcatW(szPath, startW);
838 link_name = cleanup_link( link );
841 WINE_ERR("Couldn't clean up link name %s\n", wine_dbgstr_w(link));
845 /* escape the path and parameters */
846 escaped_path = escape(szPath);
847 escaped_args = escape(szArgs);
848 escaped_description = escape(szDescription);
850 r = fork_and_wait("wineshelllink", link_name, escaped_path,
851 in_desktop_dir(csidl), escaped_args, icon_name,
852 work_dir ? work_dir : "", escaped_description);
855 HeapFree( GetProcessHeap(), 0, icon_name );
856 HeapFree( GetProcessHeap(), 0, work_dir );
857 HeapFree( GetProcessHeap(), 0, link_name );
858 HeapFree( GetProcessHeap(), 0, escaped_args );
859 HeapFree( GetProcessHeap(), 0, escaped_path );
860 HeapFree( GetProcessHeap(), 0, escaped_description );
864 WINE_ERR("failed to fork and exec wineshelllink\n" );
872 static BOOL Process_Link( LPCWSTR linkname, BOOL bAgain )
877 WCHAR fullname[MAX_PATH];
880 WINE_TRACE("%s, again %d\n", wine_dbgstr_w(linkname), bAgain);
884 WINE_ERR("link name missing\n");
888 len=GetFullPathNameW( linkname, MAX_PATH, fullname, NULL );
889 if (len==0 || len>MAX_PATH)
891 WINE_ERR("couldn't get full path of link file\n");
895 r = CoInitialize( NULL );
898 WINE_ERR("CoInitialize failed\n");
902 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
903 &IID_IShellLinkW, (LPVOID *) &sl );
906 WINE_ERR("No IID_IShellLink\n");
910 r = IShellLinkW_QueryInterface( sl, &IID_IPersistFile, (LPVOID*) &pf );
913 WINE_ERR("No IID_IPersistFile\n");
917 r = IPersistFile_Load( pf, fullname, STGM_READ );
920 /* If something fails (eg. Couldn't extract icon)
921 * defer this menu entry to reboot via runonce
923 if( ! InvokeShellLinker( sl, fullname, bAgain ) && bAgain )
924 DeferToRunOnce( fullname );
926 WINE_TRACE("Success.\n");
929 IPersistFile_Release( pf );
930 IShellLinkW_Release( sl );
938 static CHAR *next_token( LPSTR *p )
940 LPSTR token = NULL, t = *p;
953 /* unquote the token */
955 t = strchr( token, '"' );
964 t = strchr( token, ' ' );
974 /***********************************************************************
978 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
980 LPSTR token = NULL, p;
982 HANDLE hsem = CreateSemaphoreA( NULL, 1, 1, "winemenubuilder_semaphore");
985 /* running multiple instances of wineshelllink
986 at the same time may be dangerous */
987 if( WAIT_OBJECT_0 != WaitForSingleObject( hsem, INFINITE ) )
993 for( p = cmdline; p && *p; )
995 token = next_token( &p );
998 if( !lstrcmpA( token, "-r" ) )
1000 else if( token[0] == '-' )
1002 WINE_ERR( "unknown option %s\n",token);
1006 WCHAR link[MAX_PATH];
1008 MultiByteToWideChar( CP_ACP, 0, token, -1, link, sizeof(link) );
1009 if( !Process_Link( link, bAgain ) )
1011 WINE_ERR( "failed to build menu item for %s\n",token);
1018 ReleaseSemaphore( hsem, 1, NULL );
1019 CloseHandle( hsem );