- store lnk extension

- store shellnew command range
- implement shellnew commands for type "Command" and type "NullFile"


svn path=/trunk/; revision=29693
This commit is contained in:
Johannes Anderwald 2007-10-20 00:50:07 +00:00
parent 6aa7d10022
commit 01dfe7583c

View file

@ -23,14 +23,14 @@
#define COBJMACROS #define COBJMACROS
#define NONAMELESSUNION #define NONAMELESSUNION
#define NONAMELESSSTRUCT #define NONAMELESSSTRUCT
//#define YDEBUG
#include "wine/debug.h" #include "wine/debug.h"
#include "windef.h" #include "windef.h"
#include "wingdi.h" #include "wingdi.h"
#include "pidl.h" #include "pidl.h"
#include "shlobj.h" #include "shlobj.h"
#include "shtypes.h"
#include "shell32_main.h" #include "shell32_main.h"
#include "shellfolder.h" #include "shellfolder.h"
#include "undocshell.h" #include "undocshell.h"
@ -46,6 +46,8 @@ typedef struct
IShellFolder* pSFParent; IShellFolder* pSFParent;
LONG ref; LONG ref;
BOOL bDesktop; BOOL bDesktop;
UINT iIdShellNewFirst;
UINT iIdShellNewLast;
} BgCmImpl; } BgCmImpl;
typedef enum typedef enum
@ -60,6 +62,7 @@ typedef enum
typedef struct __SHELLNEW_ITEM__ typedef struct __SHELLNEW_ITEM__
{ {
SHELLNEW_TYPE Type; SHELLNEW_TYPE Type;
LPWSTR szExt;
LPWSTR szTarget; LPWSTR szTarget;
LPWSTR szDesc; LPWSTR szDesc;
LPWSTR szIcon; LPWSTR szIcon;
@ -165,6 +168,7 @@ PSHELLNEW_ITEM LoadItem(LPWSTR szKeyName)
pNewItem->szDesc = wcsdup(szDesc); pNewItem->szDesc = wcsdup(szDesc);
pNewItem->szIcon = wcsdup(szIcon); pNewItem->szIcon = wcsdup(szIcon);
pNewItem->szExt = wcsdup(szKeyName);
pNewItem->Next = NULL; pNewItem->Next = NULL;
break; break;
} }
@ -214,11 +218,11 @@ LoadShellNewItems()
return TRUE; return TRUE;
} }
VOID VOID
InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu) InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu, BgCmImpl * This)
{ {
MENUITEMINFOW mii; MENUITEMINFOW mii;
PSHELLNEW_ITEM pCurItem; PSHELLNEW_ITEM pCurItem;
UINT i;
if (s_SnHead == NULL) if (s_SnHead == NULL)
{ {
if (!LoadShellNewItems()) if (!LoadShellNewItems())
@ -234,21 +238,148 @@ InsertShellNewItems(HMENU hMenu, UINT idFirst, UINT idMenu)
mii.fState = MFS_ENABLED; mii.fState = MFS_ENABLED;
pCurItem = s_SnHead; pCurItem = s_SnHead;
i = 0;
while(pCurItem) while(pCurItem)
{ {
mii.dwTypeData = pCurItem->szDesc; mii.dwTypeData = pCurItem->szDesc;
mii.cch = strlenW(mii.dwTypeData); mii.cch = strlenW(mii.dwTypeData);
mii.wID = idFirst; mii.wID = idFirst + i;
if (InsertMenuItemW(hMenu, idMenu, TRUE, &mii)) if (InsertMenuItemW(hMenu, idMenu, TRUE, &mii))
{ {
idMenu++; idMenu++;
idFirst++; i++;
} }
pCurItem = pCurItem->Next; pCurItem = pCurItem->Next;
} }
This->iIdShellNewFirst = idFirst;
This->iIdShellNewLast = idFirst + i;
} }
VOID
DoShellNewCmd(BgCmImpl * This, LPCMINVOKECOMMANDINFO lpcmi)
{
PSHELLNEW_ITEM pCurItem = s_SnHead;
IPersistFolder3 * psf;
LPITEMIDLIST pidl;
STRRET strTemp;
WCHAR szTemp[MAX_PATH];
WCHAR szBuffer[MAX_PATH];
WCHAR szPath[MAX_PATH];
STARTUPINFOW sInfo;
PROCESS_INFORMATION pi;
UINT i, target;
static const WCHAR szNew[] = { 'N','e','w',' ',0 }; //FIXME
static const WCHAR szP1[] = { '%', '1', 0 };
static const WCHAR szFormat[] = {'%','s',' ','(','%','u',')','%','s',0 };
i = This->iIdShellNewFirst;
target = LOWORD(lpcmi->lpVerb);
while(pCurItem)
{
if (i == target)
break;
pCurItem = pCurItem->Next;
i++;
}
if (!pCurItem)
return;
if (IShellFolder2_QueryInterface(This->pSFParent, &IID_IPersistFolder2, (LPVOID*)&psf) != S_OK)
{
ERR("Failed to get interface IID_IPersistFolder2\n");
return;
}
if (IPersistFolder2_GetCurFolder(psf, &pidl) != S_OK)
{
ERR("IPersistFolder2_GetCurFolder failed\n");
return;
}
if (IShellFolder2_GetDisplayNameOf(This->pSFParent, pidl, SHGDN_FORPARSING, &strTemp) != S_OK)
{
ERR("IShellFolder_GetDisplayNameOf failed\n");
return;
}
switch(pCurItem->Type)
{
case SHELLNEW_TYPE_COMMAND:
{
LPWSTR ptr;
LPWSTR szCmd;
if (!ExpandEnvironmentStringsW(pCurItem->szTarget, szBuffer, MAX_PATH))
{
TRACE("ExpandEnvironmentStrings failed\n");
break;
}
ptr = wcsstr(szBuffer, szP1);
if (ptr)
{
ptr[1] = 's';
//StrRetToBufW(strTemp, pidl, szPath, MAX_PATH);
//TRACE("szPath %s\n", debugstr_w(szPath));
swprintf(szTemp, szBuffer, strTemp.u.pOleStr);
ptr = szTemp;
}
else
{
ptr = szBuffer;
}
ZeroMemory(&sInfo, sizeof(sInfo));
sInfo.cb = sizeof(sizeof(sInfo));
szCmd = wcsdup(ptr);
if (!szCmd)
break;
if (CreateProcessW(NULL, szCmd, NULL, NULL,FALSE,0,NULL,NULL,&sInfo, &pi))
{
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
free(szCmd);
break;
}
case SHELLNEW_TYPE_DATA:
{
break;
}
case SHELLNEW_TYPE_FILENAME:
{
break;
}
case SHELLNEW_TYPE_NULLFILE:
{
HANDLE hFile;
i = 2;
wcscpy(szBuffer, strTemp.u.pOleStr);
PathAddBackslashW(szBuffer);
wcscat(szBuffer, szNew);
wcscat(szBuffer, pCurItem->szDesc);
wcscpy(szPath, szBuffer);
wcscat(szPath, pCurItem->szExt);
do
{
TRACE("FileName %s szBuffer %s i %d \n", debugstr_w(szPath), debugstr_w(szBuffer), i);
hFile = CreateFileW(szPath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
swprintf(szPath, szFormat, szBuffer, i, pCurItem->szExt);
i++;
}while(hFile == INVALID_HANDLE_VALUE);
break;
CloseHandle(hFile);
break;
}
}
}
/************************************************************************** /**************************************************************************
@ -384,7 +515,7 @@ static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
mii.fMask = MIIM_SUBMENU; mii.fMask = MIIM_SUBMENU;
if (GetMenuItemInfoW(hMenu, 10, TRUE, &mii)) if (GetMenuItemInfoW(hMenu, 10, TRUE, &mii))
{ {
InsertShellNewItems(mii.hSubMenu, 0x6000, 0x6000); InsertShellNewItems(mii.hSubMenu, 0x6000, 0x6000, This);
} }
TRACE("(%p)->returning 0x%x\n",This,hr); TRACE("(%p)->returning 0x%x\n",This,hr);
@ -589,6 +720,12 @@ static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
break; break;
default: default:
if (LOWORD(lpcmi->lpVerb) >= This->iIdShellNewFirst && LOWORD(lpcmi->lpVerb) <= This->iIdShellNewLast)
{
DoShellNewCmd(This, lpcmi);
break;
}
/* if it's an id just pass it to the parent shv */ /* if it's an id just pass it to the parent shv */
if (hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 ); if (hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
break; break;