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