reactos/dll/win32/shell32/wine/shellstring.c

280 lines
7.7 KiB
C
Raw Normal View History

/*
* Copyright 2000 Juergen Schmied
*
* 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
----------------------------------------------------- autocomplete.c: Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers Constify some variables. ----------------------------------------------------- dde.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- dragdrophelper.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. ----------------------------------------------------- enumidlist.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. ----------------------------------------------------- enumidlist.h: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shellreg.c: Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. Detlef Riekenberg <wine.dev@web.de> Implement SHRegQueryValueA with RegQueryValueA. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shellstring.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. ----------------------------------------------------- shlfsbind.c Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> shell32: Win64 printf format warning fixes. Andrew Talbot <Andrew.Talbot@talbotville.com> shell32: Exclude unused headers. ----------------------------------------------------- shlmenu.c: Dmitry Timoshkov <dmitry@codeweavers.com> Switch to using 'long' for INT_PTR type for 64-bit compatibility. Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. James Hawkins <truiken@gmail.com> janitorial: Remove redundant NULL checks before SHFree. Francois Gouget <fgouget@free.fr> Fix spelling of a local variable. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shpolicy.c: Dmitry Timoshkov <dmitry@codeweavers.com> Make some data static and const. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. svn path=/trunk/; revision=29485
2007-10-10 22:39:44 +00:00
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define WIN32_NO_STATUS
#define _INC_WINDOWS
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include <windef.h>
#include <winbase.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <wine/unicode.h>
#include <wine/debug.h>
#include "shell32_main.h"
#include "undocshell.h"
WINE_DEFAULT_DEBUG_CHANNEL(shell);
/************************* STRRET functions ****************************/
static const char *debugstr_strret(STRRET *s)
{
switch (s->uType)
{
case STRRET_WSTR:
return "STRRET_WSTR";
case STRRET_CSTR:
return "STRRET_CSTR";
case STRRET_OFFSET:
return "STRRET_OFFSET";
default:
return "STRRET_???";
}
}
BOOL WINAPI StrRetToStrNA(LPSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
{
TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
if (!dest)
return FALSE;
switch (src->uType)
{
case STRRET_WSTR:
WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, dest, len, NULL, NULL);
CoTaskMemFree(src->u.pOleStr);
break;
case STRRET_CSTR:
lstrcpynA(dest, src->u.cStr, len);
break;
case STRRET_OFFSET:
lstrcpynA(dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
break;
default:
FIXME("unknown type %u!\n", src->uType);
if (len)
*dest = '\0';
return FALSE;
}
TRACE("-- %s\n", debugstr_a(dest) );
return TRUE;
}
/************************************************************************/
BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
{
TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
if (!dest)
return FALSE;
switch (src->uType)
{
case STRRET_WSTR:
lstrcpynW(dest, src->u.pOleStr, len);
CoTaskMemFree(src->u.pOleStr);
break;
case STRRET_CSTR:
if (!MultiByteToWideChar(CP_ACP, 0, src->u.cStr, -1, dest, len) && len)
dest[len-1] = 0;
break;
case STRRET_OFFSET:
if (!MultiByteToWideChar(CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len)
&& len)
dest[len-1] = 0;
break;
default:
FIXME("unknown type %u!\n", src->uType);
if (len)
*dest = '\0';
return FALSE;
}
return TRUE;
}
/*************************************************************************
* StrRetToStrN [SHELL32.96]
*
* converts a STRRET to a normal string
*
* NOTES
* the pidl is for STRRET OFFSET
*/
BOOL WINAPI StrRetToStrNAW(LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
{
if(SHELL_OsIsUnicode())
return StrRetToStrNW(dest, len, src, pidl);
else
return StrRetToStrNA(dest, len, src, pidl);
}
/************************* OLESTR functions ****************************/
/************************************************************************
* StrToOleStr [SHELL32.163]
*
*/
static int StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
{
TRACE("(%p, %p %s)\n",
lpWideCharStr, lpMultiByteString, debugstr_a(lpMultiByteString));
return MultiByteToWideChar(CP_ACP, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
}
static int StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
{
TRACE("(%p, %p %s)\n",
lpWideCharStr, lpWString, debugstr_w(lpWString));
strcpyW (lpWideCharStr, lpWString );
return strlenW(lpWideCharStr);
}
BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
{
if (SHELL_OsIsUnicode())
return StrToOleStrW (lpWideCharStr, lpString);
return StrToOleStrA (lpWideCharStr, lpString);
}
/*************************************************************************
* StrToOleStrN [SHELL32.79]
* lpMulti, nMulti, nWide [IN]
* lpWide [OUT]
*/
static BOOL StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
{
TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_an(lpStrA,nStr), nStr);
return MultiByteToWideChar (CP_ACP, 0, lpStrA, nStr, lpWide, nWide);
}
static BOOL StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
{
TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_wn(lpStrW, nStr), nStr);
if (lstrcpynW (lpWide, lpStrW, nWide))
{ return lstrlenW (lpWide);
}
return FALSE;
}
BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
{
if (SHELL_OsIsUnicode())
return StrToOleStrNW (lpWide, nWide, lpStr, nStr);
return StrToOleStrNA (lpWide, nWide, lpStr, nStr);
}
/*************************************************************************
* OleStrToStrN [SHELL32.78]
*/
static BOOL OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
{
TRACE("(%p, %x, %s, %x)\n", lpStr, nStr, debugstr_wn(lpOle,nOle), nOle);
return WideCharToMultiByte (CP_ACP, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
}
static BOOL OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
{
TRACE("(%p, %x, %s, %x)\n", lpwStr, nwStr, debugstr_wn(lpOle,nOle), nOle);
if (lstrcpynW ( lpwStr, lpOle, nwStr))
{ return lstrlenW (lpwStr);
}
return FALSE;
}
BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
{
if (SHELL_OsIsUnicode())
return OleStrToStrNW (lpOut, nOut, lpIn, nIn);
return OleStrToStrNA (lpOut, nOut, lpIn, nIn);
}
/*************************************************************************
* CheckEscapesA [SHELL32.@]
*
* Checks a string for special characters which are not allowed in a path
* and encloses it in quotes if that is the case.
*
* PARAMS
* string [I/O] string to check and on return eventually quoted
* len [I] length of string
*
* RETURNS
* length of actual string
*
* NOTES
* Not really sure if this function returns actually a value at all.
*/
DWORD WINAPI CheckEscapesA(
LPSTR string, /* [I/O] string to check ??*/
DWORD len) /* [I] is 0 */
{
LPWSTR wString;
DWORD ret = 0;
----------------------------------------------------- autocomplete.c: Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers Constify some variables. ----------------------------------------------------- dde.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- dragdrophelper.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. ----------------------------------------------------- enumidlist.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. ----------------------------------------------------- enumidlist.h: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shellreg.c: Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. Detlef Riekenberg <wine.dev@web.de> Implement SHRegQueryValueA with RegQueryValueA. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shellstring.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. ----------------------------------------------------- shlfsbind.c Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> shell32: Win64 printf format warning fixes. Andrew Talbot <Andrew.Talbot@talbotville.com> shell32: Exclude unused headers. ----------------------------------------------------- shlmenu.c: Dmitry Timoshkov <dmitry@codeweavers.com> Switch to using 'long' for INT_PTR type for 64-bit compatibility. Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. James Hawkins <truiken@gmail.com> janitorial: Remove redundant NULL checks before SHFree. Francois Gouget <fgouget@free.fr> Fix spelling of a local variable. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shpolicy.c: Dmitry Timoshkov <dmitry@codeweavers.com> Make some data static and const. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. svn path=/trunk/; revision=29485
2007-10-10 22:39:44 +00:00
TRACE("(%s %d)\n", debugstr_a(string), len);
wString = LocalAlloc(LPTR, len * sizeof(WCHAR));
if (wString)
{
MultiByteToWideChar(CP_ACP, 0, string, len, wString, len);
ret = CheckEscapesW(wString, len);
WideCharToMultiByte(CP_ACP, 0, wString, len, string, len, NULL, NULL);
LocalFree(wString);
}
return ret;
}
static const WCHAR strEscapedChars[] = {' ','"',',',';','^',0};
/*************************************************************************
* CheckEscapesW [SHELL32.@]
*
Vitaliy Margolen <wine-patch@kievinfo.com> - Michael Jung <mjung@iss.tu-darmstadt.de> Set all capability flags supported by the shellfolder, disregarding the flag mask given to GetAttributesOf. Unit tests to demonstrate this behaviour. Michael Jung <mjung@iss.tu-darmstadt.de> - Added some comments to document unixfs. - Fixed crash in unixfs shellfolder handling with winamp. - Implemented UnixFolder's IPersistPropertyBag::Load method. - Initialize COM prior to displaying the SHBrowseForFolder dialog. - More robust code for querying ShellFolder attributes (some ShellFolders ignore the flag mask in GetAttributesOf). - Remove iconcache pre-initialization hack, it's not necessary any more. - Move target folder initialization to a dedicated function. - Use this function in BindToObject (should be faster). - Special handling for FolderShortcut objects in Initialize method. - Removed a todo_wine from a no longer failing unit test. - Replaced tabs with spaces. Robert Shearman <rob@codeweavers.com> - Convert SHELL32_BindToChild to Unicode and fix up the callers. Vincent Bén <vberon@mecano.gme.usherb.ca> - Unicodify systray.c. - Move functions a bit to get rid of a static declaration. Dmitry Timoshkov <dmitry@codeweavers.com> - Correctly handle flags parameter in SHAddToRecentDocs. Martin Fuchs <martin-fuchs@gmx.net> - Correct WINAPI position for MSVC portability. Mike McCormack <mike@codeweavers.com> - Partially implement and test the shelllink object's IShellLinkDataList::CopyDataBlock and GetFlags methods. - Use advapi32.CommandLineFromMsiDescriptor to get msi component paths. - Pass the correct verb. Add a space between extra parameters. Wait for ShellExecute to complete. - Handle MSI advertised shortcuts in the shelllink object. - Implement IContextMenu::QueryContextMenu and IContextMenu::InvokeCommand. - Add the IObjectWithSite interface. - Invoke shortcuts through IContextMenu, rather than trying to access them directly. - Fix a problem spotted by Dmitry and another one stopping correctly formatted lnk files from being generated. svn path=/trunk/; revision=19356
2005-11-20 08:41:46 +00:00
* See CheckEscapesA.
*/
DWORD WINAPI CheckEscapesW(
LPWSTR string,
DWORD len)
{
DWORD size = lstrlenW(string);
LPWSTR s, d;
----------------------------------------------------- autocomplete.c: Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers Constify some variables. ----------------------------------------------------- dde.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- dragdrophelper.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. ----------------------------------------------------- enumidlist.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. ----------------------------------------------------- enumidlist.h: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shellreg.c: Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. Detlef Riekenberg <wine.dev@web.de> Implement SHRegQueryValueA with RegQueryValueA. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shellstring.c: Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. ----------------------------------------------------- shlfsbind.c Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. Hans Leidekker <hans@it.vu.nl> shell32: Win64 printf format warning fixes. Andrew Talbot <Andrew.Talbot@talbotville.com> shell32: Exclude unused headers. ----------------------------------------------------- shlmenu.c: Dmitry Timoshkov <dmitry@codeweavers.com> Switch to using 'long' for INT_PTR type for 64-bit compatibility. Andrew Talbot <Andrew.Talbot@talbotville.com> Exclude unused headers. Hans Leidekker <hans@it.vu.nl> Win64 printf format warning fixes. James Hawkins <truiken@gmail.com> janitorial: Remove redundant NULL checks before SHFree. Francois Gouget <fgouget@free.fr> Fix spelling of a local variable. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. ----------------------------------------------------- shpolicy.c: Dmitry Timoshkov <dmitry@codeweavers.com> Make some data static and const. Jonathan Ernst <jonathan@ernstfamily.ch> Update the address of the Free Software Foundation. svn path=/trunk/; revision=29485
2007-10-10 22:39:44 +00:00
TRACE("(%s %d) stub\n", debugstr_w(string), len);
if (StrPBrkW(string, strEscapedChars) && size + 2 <= len)
{
s = &string[size - 1];
d = &string[size + 2];
*d-- = 0;
*d-- = '"';
for (;d > string;)
*d-- = *s--;
*d = '"';
return size + 2;
}
return size;
}