2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
2000-06-02 01:25:44 +02:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-06-02 01:25:44 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
2002-06-01 01:06:46 +02:00
|
|
|
#include <stdlib.h>
|
2000-06-02 01:25:44 +02:00
|
|
|
|
2003-01-07 21:36:20 +01:00
|
|
|
#define NONAMELESSUNION
|
2015-03-20 09:46:28 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2000-06-02 01:25:44 +02:00
|
|
|
#include "winnls.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2001-11-06 23:31:19 +01:00
|
|
|
#include "winreg.h"
|
2000-06-02 01:25:44 +02:00
|
|
|
|
2000-09-26 02:00:55 +02:00
|
|
|
#include "shlobj.h"
|
2003-03-27 00:59:51 +01:00
|
|
|
#include "shlwapi.h"
|
2000-08-14 16:35:01 +02:00
|
|
|
#include "shell32_main.h"
|
2001-08-16 20:49:56 +02:00
|
|
|
#include "undocshell.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-06-02 01:25:44 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
2000-06-02 01:25:44 +02:00
|
|
|
|
|
|
|
/************************* STRRET functions ****************************/
|
|
|
|
|
2012-09-12 12:21:41 +02:00
|
|
|
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_???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-10 03:18:50 +01:00
|
|
|
BOOL WINAPI StrRetToStrNA(LPSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
2012-09-12 12:21:41 +02:00
|
|
|
TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
|
2001-09-07 17:24:25 +02:00
|
|
|
|
2004-02-10 03:18:50 +01:00
|
|
|
if (!dest)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-09-12 12:23:24 +02:00
|
|
|
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:
|
2012-09-12 12:21:41 +02:00
|
|
|
FIXME("unknown type %u!\n", src->uType);
|
2012-09-12 12:23:24 +02:00
|
|
|
if (len)
|
|
|
|
*dest = '\0';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
TRACE("-- %s\n", debugstr_a(dest) );
|
|
|
|
return TRUE;
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
2002-01-18 19:57:43 +01:00
|
|
|
/************************************************************************/
|
2001-09-11 01:16:31 +02:00
|
|
|
|
2004-02-10 03:18:50 +01:00
|
|
|
BOOL WINAPI StrRetToStrNW(LPWSTR dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
2012-09-12 12:21:41 +02:00
|
|
|
TRACE("dest=%p len=0x%x strret=%p(%s) pidl=%p\n", dest, len, src, debugstr_strret(src), pidl);
|
2001-09-07 17:24:25 +02:00
|
|
|
|
2004-02-10 03:18:50 +01:00
|
|
|
if (!dest)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-09-12 12:23:24 +02:00
|
|
|
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:
|
2012-09-12 12:21:41 +02:00
|
|
|
FIXME("unknown type %u!\n", src->uType);
|
2012-09-12 12:23:24 +02:00
|
|
|
if (len)
|
|
|
|
*dest = '\0';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
2000-07-26 19:51:32 +02:00
|
|
|
|
2001-09-11 01:16:31 +02:00
|
|
|
|
2002-01-18 19:57:43 +01:00
|
|
|
/*************************************************************************
|
2012-09-12 12:23:24 +02:00
|
|
|
* StrRetToStrN [SHELL32.96]
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2002-01-18 19:57:43 +01:00
|
|
|
* converts a STRRET to a normal string
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* the pidl is for STRRET OFFSET
|
|
|
|
*/
|
2004-02-10 03:18:50 +01:00
|
|
|
BOOL WINAPI StrRetToStrNAW(LPVOID dest, DWORD len, LPSTRRET src, const ITEMIDLIST *pidl)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
2012-09-12 12:23:24 +02:00
|
|
|
if(SHELL_OsIsUnicode())
|
2004-02-10 03:18:50 +01:00
|
|
|
return StrRetToStrNW(dest, len, src, pidl);
|
|
|
|
else
|
|
|
|
return StrRetToStrNA(dest, len, src, pidl);
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************* OLESTR functions ****************************/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* StrToOleStr [SHELL32.163]
|
|
|
|
*
|
|
|
|
*/
|
2008-12-03 12:09:38 +01:00
|
|
|
static int StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p, %p %s)\n",
|
|
|
|
lpWideCharStr, lpMultiByteString, debugstr_a(lpMultiByteString));
|
|
|
|
|
2012-09-24 13:04:26 +02:00
|
|
|
return MultiByteToWideChar(CP_ACP, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
|
2000-06-02 01:25:44 +02:00
|
|
|
|
|
|
|
}
|
2008-12-03 12:09:38 +01:00
|
|
|
static int StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p, %p %s)\n",
|
|
|
|
lpWideCharStr, lpWString, debugstr_w(lpWString));
|
|
|
|
|
2021-09-17 17:16:11 +02:00
|
|
|
lstrcpyW (lpWideCharStr, lpWString );
|
|
|
|
return lstrlenW(lpWideCharStr);
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
|
|
|
|
{
|
2000-08-14 16:35:01 +02:00
|
|
|
if (SHELL_OsIsUnicode())
|
2000-06-02 01:25:44 +02:00
|
|
|
return StrToOleStrW (lpWideCharStr, lpString);
|
|
|
|
return StrToOleStrA (lpWideCharStr, lpString);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* StrToOleStrN [SHELL32.79]
|
|
|
|
* lpMulti, nMulti, nWide [IN]
|
|
|
|
* lpWide [OUT]
|
|
|
|
*/
|
2008-12-03 12:09:38 +01:00
|
|
|
static BOOL StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_an(lpStrA,nStr), nStr);
|
2012-09-24 13:04:26 +02:00
|
|
|
return MultiByteToWideChar (CP_ACP, 0, lpStrA, nStr, lpWide, nWide);
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
2008-12-03 12:09:38 +01:00
|
|
|
static BOOL StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p, %x, %s, %x)\n", lpWide, nWide, debugstr_wn(lpStrW, nStr), nStr);
|
|
|
|
|
|
|
|
if (lstrcpynW (lpWide, lpStrW, nWide))
|
|
|
|
{ return lstrlenW (lpWide);
|
|
|
|
}
|
2014-04-28 20:01:45 +02:00
|
|
|
return FALSE;
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
2000-08-14 16:35:01 +02:00
|
|
|
if (SHELL_OsIsUnicode())
|
2000-06-02 01:25:44 +02:00
|
|
|
return StrToOleStrNW (lpWide, nWide, lpStr, nStr);
|
|
|
|
return StrToOleStrNA (lpWide, nWide, lpStr, nStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* OleStrToStrN [SHELL32.78]
|
|
|
|
*/
|
2008-12-03 12:09:38 +01:00
|
|
|
static BOOL OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p, %x, %s, %x)\n", lpStr, nStr, debugstr_wn(lpOle,nOle), nOle);
|
2012-09-24 13:04:26 +02:00
|
|
|
return WideCharToMultiByte (CP_ACP, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
2008-12-03 12:09:38 +01:00
|
|
|
static BOOL OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p, %x, %s, %x)\n", lpwStr, nwStr, debugstr_wn(lpOle,nOle), nOle);
|
|
|
|
|
|
|
|
if (lstrcpynW ( lpwStr, lpOle, nwStr))
|
|
|
|
{ return lstrlenW (lpwStr);
|
|
|
|
}
|
2013-10-22 00:16:09 +02:00
|
|
|
return FALSE;
|
2000-06-02 01:25:44 +02:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
|
2000-06-02 01:25:44 +02:00
|
|
|
{
|
2000-08-14 16:35:01 +02:00
|
|
|
if (SHELL_OsIsUnicode())
|
2000-06-02 01:25:44 +02:00
|
|
|
return OleStrToStrNW (lpOut, nOut, lpIn, nIn);
|
|
|
|
return OleStrToStrNA (lpOut, nOut, lpIn, nIn);
|
|
|
|
}
|
2002-01-29 19:21:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-03-27 00:59:51 +01:00
|
|
|
* 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.
|
2002-01-29 19:21:20 +01:00
|
|
|
*/
|
|
|
|
DWORD WINAPI CheckEscapesA(
|
2003-03-27 00:59:51 +01:00
|
|
|
LPSTR string, /* [I/O] string to check ??*/
|
|
|
|
DWORD len) /* [I] is 0 */
|
2002-01-29 19:21:20 +01:00
|
|
|
{
|
2003-03-27 00:59:51 +01:00
|
|
|
LPWSTR wString;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
2006-10-07 20:18:14 +02:00
|
|
|
TRACE("(%s %d)\n", debugstr_a(string), len);
|
2008-11-05 23:00:50 +01:00
|
|
|
wString = LocalAlloc(LPTR, len * sizeof(WCHAR));
|
2003-03-27 00:59:51 +01:00
|
|
|
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;
|
2002-01-29 19:21:20 +01:00
|
|
|
}
|
|
|
|
|
2003-03-27 00:59:51 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* CheckEscapesW [SHELL32.@]
|
|
|
|
*
|
2005-11-10 12:15:22 +01:00
|
|
|
* See CheckEscapesA.
|
2003-03-27 00:59:51 +01:00
|
|
|
*/
|
2002-01-29 19:21:20 +01:00
|
|
|
DWORD WINAPI CheckEscapesW(
|
2003-03-27 00:59:51 +01:00
|
|
|
LPWSTR string,
|
|
|
|
DWORD len)
|
2002-01-29 19:21:20 +01:00
|
|
|
{
|
2003-03-27 00:59:51 +01:00
|
|
|
DWORD size = lstrlenW(string);
|
|
|
|
LPWSTR s, d;
|
|
|
|
|
2019-11-05 12:33:47 +01:00
|
|
|
TRACE("%s, %u.\n", debugstr_w(string), len);
|
2003-03-27 00:59:51 +01:00
|
|
|
|
2021-09-20 12:58:52 +02:00
|
|
|
if (StrPBrkW(string, L" \",;^") && size + 2 <= len)
|
2003-03-27 00:59:51 +01:00
|
|
|
{
|
|
|
|
s = &string[size - 1];
|
|
|
|
d = &string[size + 2];
|
|
|
|
*d-- = 0;
|
|
|
|
*d-- = '"';
|
|
|
|
for (;d > string;)
|
|
|
|
*d-- = *s--;
|
|
|
|
*d = '"';
|
|
|
|
return size + 2;
|
|
|
|
}
|
|
|
|
return size;
|
2002-01-29 19:21:20 +01:00
|
|
|
}
|