From 9074f257e027c323a3a0a3a0e623e65a7f515c39 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Thu, 17 Feb 2005 11:51:44 +0000 Subject: [PATCH] Convert winemenubuilder to unicode. --- dlls/shell32/shelllink.c | 6 +- programs/winemenubuilder/winemenubuilder.c | 329 +++++++++++---------- 2 files changed, 181 insertions(+), 154 deletions(-) diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c index f08a6421261..ffb32bf8214 100644 --- a/dlls/shell32/shelllink.c +++ b/dlls/shell32/shelllink.c @@ -1281,7 +1281,7 @@ static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR { IShellLinkImpl *This = (IShellLinkImpl *)iface; - FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved); + TRACE("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved); HeapFree(GetProcessHeap(), 0, This->sPathRel); This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel); @@ -1296,7 +1296,7 @@ static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWOR IShellLinkImpl *This = (IShellLinkImpl *)iface; - FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags); + TRACE("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags); /*FIXME: use IResolveShellLink interface */ @@ -1721,7 +1721,7 @@ static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWOR _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface); - FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags); + TRACE("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags); /*FIXME: use IResolveShellLink interface */ diff --git a/programs/winemenubuilder/winemenubuilder.c b/programs/winemenubuilder/winemenubuilder.c index ad6271e9890..6fa56c7ae8b 100644 --- a/programs/winemenubuilder/winemenubuilder.c +++ b/programs/winemenubuilder/winemenubuilder.c @@ -4,6 +4,7 @@ * Copyright 1997 Marcus Meissner * Copyright 1998 Juergen Schmied * Copyright 2003 Mike McCormack for CodeWeavers + * Copyright 2004 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -54,6 +55,7 @@ #include #include +#include "wine/unicode.h" #include "wine/debug.h" #include "wine.xpm" @@ -123,7 +125,7 @@ typedef struct * FIXME: should not use stdio */ -static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, const char *comment) +static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, LPCWSTR commentW) { FILE *fXPMFile; int nHeight; @@ -136,6 +138,7 @@ static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, BOOL aColorUsed[256] = {0}; int nColorsUsed = 0; int i,j; + char *comment; if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8))) return FALSE; @@ -143,6 +146,10 @@ static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, if (!(fXPMFile = fopen(szXPMFileName, "w"))) return FALSE; + i = WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, NULL, 0, NULL, NULL); + comment = malloc(i); + WideCharToMultiByte(CP_UNIXCP, 0, commentW, -1, comment, i, NULL, NULL); + nHeight = pIcon->bmiHeader.biHeight / 2; nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32) + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0)); @@ -206,33 +213,35 @@ static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName, #undef MASK #undef COLOR + free(comment); fclose(fXPMFile); return TRUE; error: + free(comment); fclose(fXPMFile); unlink( szXPMFileName ); return FALSE; } -static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCSTR lpszType, LPSTR lpszName, LONG lParam) +static BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCWSTR lpszType, LPWSTR lpszName, LONG_PTR lParam) { ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam; if (!sEnumRes->nIndex--) { - *sEnumRes->pResInfo = FindResourceA(hModule, lpszName, (LPSTR)RT_GROUP_ICON); + *sEnumRes->pResInfo = FindResourceW(hModule, lpszName, (LPCWSTR)RT_GROUP_ICON); return FALSE; } else return TRUE; } -static BOOL ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *szXPMFileName) +static BOOL extract_icon32(LPCWSTR szFileName, int nIndex, const char *szXPMFileName) { HMODULE hModule; HRSRC hResInfo; - char *lpName = NULL; + LPCWSTR lpName = NULL; HGLOBAL hResData; GRPICONDIR *pIconDir; BITMAPINFO *pIcon; @@ -240,106 +249,92 @@ static BOOL ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *sz int nMax = 0; int nMaxBits = 0; int i; + BOOL ret = FALSE; - hModule = LoadLibraryExA(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE); + hModule = LoadLibraryExW(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE); if (!hModule) { - WINE_ERR("LoadLibraryExA (%s) failed, error %ld\n", szFileName, GetLastError()); + WINE_ERR("LoadLibraryExW (%s) failed, error %ld\n", + wine_dbgstr_w(szFileName), GetLastError()); return FALSE; } if (nIndex < 0) { - hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(-nIndex), (LPSTR)RT_GROUP_ICON); - WINE_TRACE("FindResourceA (%s) called, return %p, error %ld\n", - szFileName, hResInfo, GetLastError()); + 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()); } else { hResInfo=NULL; sEnumRes.pResInfo = &hResInfo; sEnumRes.nIndex = nIndex; - EnumResourceNamesA(hModule, (LPSTR)RT_GROUP_ICON, &EnumResNameProc, (LONG) &sEnumRes); + EnumResourceNamesW(hModule, (LPCWSTR)RT_GROUP_ICON, EnumResNameProc, (LONG_PTR)&sEnumRes); } - if (!hResInfo) + if (hResInfo) + { + if ((hResData = LoadResource(hModule, hResInfo))) + { + if ((pIconDir = LockResource(hResData))) + { + for (i = 0; i < pIconDir->idCount; i++) + { + if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8)) + { + if (pIconDir->idEntries[i].wBitCount > nMaxBits) + { + nMaxBits = pIconDir->idEntries[i].wBitCount; + nMax = 0; + } + } + + 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; + } + } + } + + FreeResource(hResData); + } + } + else { WINE_ERR("ExtractFromEXEDLL failed, error %ld\n", GetLastError()); - goto error2; + FreeLibrary(hModule); + return FALSE; } - - if (!(hResData = LoadResource(hModule, hResInfo))) + + if ((hResInfo = FindResourceW(hModule, lpName, (LPCWSTR)RT_ICON))) { - WINE_ERR("LoadResource failed, error %ld\n", GetLastError()); - goto error2; - } - if (!(pIconDir = LockResource(hResData))) - { - WINE_ERR("LockResource failed, error %ld\n", GetLastError()); - goto error3; - } - - for (i = 0; i < pIconDir->idCount; i++) - if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8)) + if ((hResData = LoadResource(hModule, hResInfo))) { - if (pIconDir->idEntries[i].wBitCount > nMaxBits) - { - nMaxBits = pIconDir->idEntries[i].wBitCount; - nMax = 0; - } - if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax) - { - lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID); - nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth; - } + if ((pIcon = LockResource(hResData))) + { + if(SaveIconResAsXPM(pIcon, szXPMFileName, szFileName)) + ret = TRUE; + } + + FreeResource(hResData); } - - FreeResource(hResData); - - if (!(hResInfo = FindResourceA(hModule, lpName, (LPSTR)RT_ICON))) - { - WINE_ERR("Second FindResourceA failed, error %ld\n", GetLastError()); - goto error2; - } - if (!(hResData = LoadResource(hModule, hResInfo))) - { - WINE_ERR("Second LoadResource failed, error %ld\n", GetLastError()); - goto error2; - } - if (!(pIcon = LockResource(hResData))) - { - WINE_ERR("Second LockResource failed, error %ld\n", GetLastError()); - goto error3; } - if(!SaveIconResAsXPM(pIcon, szXPMFileName, szFileName)) - { - WINE_ERR("Failed saving icon as XPM, error %ld\n", GetLastError()); - goto error3; - } - - FreeResource(hResData); FreeLibrary(hModule); - - return TRUE; - - error3: - FreeResource(hResData); - error2: - FreeLibrary(hModule); - return FALSE; + return ret; } -/* get the Unix file name for a given path, allocating the string */ -inline static char *get_unix_file_name( LPCSTR dos ) +static BOOL ExtractFromEXEDLL(LPCWSTR szFileName, int nIndex, const char *szXPMFileName) { - WCHAR dosW[MAX_PATH]; - - MultiByteToWideChar(CP_ACP, 0, dos, -1, dosW, MAX_PATH); - return wine_get_unix_file_name( dosW ); + if (!extract_icon32(szFileName, nIndex, szXPMFileName) /*&& + !extract_icon16(szFileName, szXPMFileName)*/) + return FALSE; + return TRUE; } -static int ExtractFromICO(const char *szFileName, const char *szXPMFileName) +static int ExtractFromICO(LPCWSTR szFileName, const char *szXPMFileName) { FILE *fICOFile; ICONDIR iconDir; @@ -350,7 +345,7 @@ static int ExtractFromICO(const char *szFileName, const char *szXPMFileName) int i; char *filename; - filename = get_unix_file_name(szFileName); + filename = wine_get_unix_file_name(szFileName); if (!(fICOFile = fopen(filename, "r"))) goto error1; @@ -383,7 +378,7 @@ static int ExtractFromICO(const char *szFileName, const char *szXPMFileName) free(pIcon); free(pIconDirEntry); fclose(fICOFile); - + HeapFree(GetProcessHeap(), 0, filename); return 1; error4: @@ -440,47 +435,57 @@ static unsigned short crc16(const char* string) } /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */ -static char *extract_icon( const char *path, int index) +static char *extract_icon( LPCWSTR path, int index) { int nodefault = 1; unsigned short crc; char *iconsdir, *ico_path, *ico_name, *xpm_path; char* s; HKEY hkey; + int n; /* Where should we save the icon? */ - WINE_TRACE("path=[%s] index=%d\n",path,index); + WINE_TRACE("path=[%s] index=%d\n", wine_dbgstr_w(path), index); iconsdir=NULL; /* Default is no icon */ if (!RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine", &hkey )) { + static const WCHAR IconsDirW[] = {'I','c','o','n','s','D','i','r',0}; + LPWSTR iconsdirW; DWORD size = 0; - if (RegQueryValueExA(hkey, "IconsDir", 0, NULL, NULL, &size)==0) + if (!RegQueryValueExW(hkey, IconsDirW, 0, NULL, NULL, &size)) { - iconsdir = HeapAlloc(GetProcessHeap(), 0, size); - RegQueryValueExA(hkey, "IconsDir", 0, NULL, iconsdir, &size); + iconsdirW = HeapAlloc(GetProcessHeap(), 0, size); + RegQueryValueExW(hkey, IconsDirW, 0, NULL, (LPBYTE)iconsdirW, &size); - s = get_unix_file_name(iconsdir); + s = wine_get_unix_file_name(iconsdirW); if (s) + iconsdir = s; + else { - HeapFree(GetProcessHeap(), 0, iconsdir); - iconsdir=s; + 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); } + HeapFree(GetProcessHeap(), 0, iconsdirW); } else { - char path[MAX_PATH]; + WCHAR path[MAX_PATH]; - if (GetTempPath(sizeof(path),path)) + if (GetTempPathW(MAX_PATH, path)) { - s = get_unix_file_name(path); + s = wine_get_unix_file_name(path); if (s) iconsdir = s; } } RegCloseKey( hkey ); } - if (iconsdir==NULL || *iconsdir=='\0') + if (!iconsdir) + return NULL; /* No icon created */ + + if (!*iconsdir) { HeapFree(GetProcessHeap(), 0, iconsdir); return NULL; /* No icon created */ @@ -494,8 +499,9 @@ static char *extract_icon( const char *path, int index) } /* Determine the icon base name */ - ico_path=HeapAlloc(GetProcessHeap(), 0, lstrlenA(path)+1); - strcpy(ico_path, path); + 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); s=ico_name=ico_path; while (*s!='\0') { if (*s=='/' || *s=='\\') { @@ -524,7 +530,7 @@ static char *extract_icon( const char *path, int index) if (ExtractFromICO( path, xpm_path)) goto end; if (!nodefault) - if (create_default_icon( xpm_path, path )) + if (create_default_icon( xpm_path, ico_path )) goto end; HeapFree( GetProcessHeap(), 0, xpm_path ); @@ -577,15 +583,27 @@ static BOOL DeferToRunOnce(LPWSTR link) } /* This escapes \ in filenames */ -static LPSTR escape(LPCSTR arg) +static LPSTR escape(LPCWSTR arg) { LPSTR narg, x; + LPCWSTR esc; + int len = 0, n; - narg = HeapAlloc(GetProcessHeap(),0,2*strlen(arg)+2); - x = narg; - while (*arg) + esc = arg; + while((esc = strchrW(esc, '\\'))) { - *x++ = *arg; + esc++; + len++; + } + + len += WideCharToMultiByte(CP_UNIXCP, 0, arg, -1, NULL, 0, NULL, NULL); + narg = HeapAlloc(GetProcessHeap(), 0, len); + + x = narg; + while (*arg) { + n = WideCharToMultiByte(CP_UNIXCP, 0, arg, 1, x, len, NULL, NULL); + x += n; + len -= n; if (*arg == '\\') *x++='\\'; /* escape \ */ arg++; @@ -643,25 +661,30 @@ static int fork_and_wait( char *linker, char *link_name, char *path, static char *cleanup_link( LPCWSTR link ) { + char *unix_file_name; char *p, *link_name; - int len; - /* make link name a Unix name - - strip leading slashes & remove extension */ - while ( (*link == '\\') || (*link == '/' ) ) - link++; - len = WideCharToMultiByte( CP_ACP, 0, link, -1, NULL, 0, NULL, NULL); - link_name = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) ); - if( ! link_name ) - return link_name; - len = WideCharToMultiByte( CP_ACP, 0, link, -1, link_name, len, NULL, NULL); - for (p = link_name; *p; p++) - if (*p == '\\') - *p = '/'; + unix_file_name = wine_get_unix_file_name(link); + if (!unix_file_name) + { + WINE_ERR("target link %s not found\n", wine_dbgstr_w(link)); + return NULL; + } + + link_name = unix_file_name; + p = strrchr( link_name, '/' ); + if (p) + link_name = p + 1; + p = strrchr( link_name, '.' ); if (p) *p = 0; - return link_name; + + p = HeapAlloc(GetProcessHeap(), 0, strlen(link_name) + 1); + strcpy(p, link_name); + HeapFree(GetProcessHeap(), 0, unix_file_name); + + return p; } /*********************************************************************** @@ -671,7 +694,7 @@ static char *cleanup_link( LPCWSTR link ) * returns TRUE if successful * *loc will contain CS_DESKTOPDIRECTORY, CS_STARTMENU, CS_STARTUP */ -static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *ofs, DWORD *loc ) +static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *loc ) { WCHAR filename[MAX_PATH], buffer[MAX_PATH]; DWORD len, i, r, filelen; @@ -685,6 +708,8 @@ static BOOL GetLinkLocation( LPCWSTR linkfile, DWORD *ofs, DWORD *loc ) if (filelen==0 || filelen>MAX_PATH) return FALSE; + WINE_TRACE("%s\n", wine_dbgstr_w(filename)); + for( i=0; i