- display recently used programs

- append %1 to allow executing in default command
- store prog id as default key in new file ext
- assign default file association when requested

svn path=/trunk/; revision=30990
This commit is contained in:
Johannes Anderwald 2007-12-03 22:52:27 +00:00
parent ab3c49a539
commit f076b05fed

View file

@ -270,15 +270,30 @@ static void AddListViewItem(HWND hwndDlg, WCHAR * item, UINT state, UINT index)
LV_ITEMW listItem; LV_ITEMW listItem;
HWND hList; HWND hList;
WCHAR * ptr; WCHAR * ptr;
WCHAR szApp[MAX_PATH];
hList = GetDlgItem(hwndDlg, 14002); hList = GetDlgItem(hwndDlg, 14002);
szApp[0] = 0;
ptr = wcsrchr(item, L'\\');
if (ptr)
{
ptr++;
}
else
{
ptr = item;
}
wcscpy(szApp, ptr);
ptr = wcsrchr(szApp, L'.');
if (ptr)
ptr[0] = 0;
ptr = wcsrchr(item, L'\\') + 1;
ZeroMemory(&listItem, sizeof(LV_ITEM)); ZeroMemory(&listItem, sizeof(LV_ITEM));
listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE; listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
listItem.state = state; listItem.state = state;
listItem.pszText = ptr; listItem.pszText = szApp;
listItem.iImage = -1; listItem.iImage = -1;
listItem.iItem = index; listItem.iItem = index;
listItem.lParam = (LPARAM)item; listItem.lParam = (LPARAM)item;
@ -291,6 +306,7 @@ static void AddListViewItems(HWND hwndDlg, SHEOWImpl * This)
HWND hList; HWND hList;
RECT clientRect; RECT clientRect;
LV_COLUMN col; LV_COLUMN col;
int index;
hList = GetDlgItem(hwndDlg, 14002); hList = GetDlgItem(hwndDlg, 14002);
@ -302,10 +318,22 @@ static void AddListViewItems(HWND hwndDlg, SHEOWImpl * This)
col.cx = (clientRect.right - clientRect.left) - GetSystemMetrics(SM_CXVSCROLL); col.cx = (clientRect.right - clientRect.left) - GetSystemMetrics(SM_CXVSCROLL);
(void)ListView_InsertColumn(hList, 0, &col); (void)ListView_InsertColumn(hList, 0, &col);
/* FIXME
* add default items
*/
This->iSelItem = -1; This->iSelItem = -1;
if (!This->szArray)
return;
for(index = 0; index < This->count; index++)
{
if (This->szArray[index] == NULL)
continue;
TRACE("val %s\n", debugstr_w(This->szArray[index]));
AddListViewItem(hwndDlg, This->szArray[index], 0, index);
}
/* FIXME
* select default item
*/
} }
static void FreeListViewItems(HWND hwndDlg) static void FreeListViewItems(HWND hwndDlg)
{ {
@ -332,12 +360,17 @@ static void FreeListViewItems(HWND hwndDlg)
BOOL HideApplicationFromList(WCHAR * pFileName) BOOL HideApplicationFromList(WCHAR * pFileName)
{ {
WCHAR szBuffer[100]; WCHAR szBuffer[100];
DWORD dwSize; DWORD dwSize = 0;
LONG result;
wcscpy(szBuffer, L"Applications\\"); wcscpy(szBuffer, L"Applications\\");
wcscat(szBuffer, pFileName); wcscat(szBuffer, pFileName);
if (RegGetValueW(HKEY_CLASSES_ROOT, szBuffer, L"NoOpenWith", RRF_RT_REG_SZ, NULL, NULL, &dwSize) == ERROR_SUCCESS) result = RegGetValueW(HKEY_CLASSES_ROOT, szBuffer, L"NoOpenWith", RRF_RT_REG_SZ, NULL, NULL, &dwSize);
TRACE("result %d szBuffer %s\n", result, debugstr_w(szBuffer));
if (result == ERROR_SUCCESS)
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -349,6 +382,7 @@ BOOL WriteStaticShellExtensionKey(HKEY hRootKey, WCHAR * pVerb, WCHAR *pFullPath
HKEY hVerb; HKEY hVerb;
HKEY hCmd; HKEY hCmd;
LONG result; LONG result;
WCHAR szPath[MAX_PATH+10];
if (RegCreateKeyExW(hRootKey, L"shell", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hShell, NULL) != ERROR_SUCCESS) if (RegCreateKeyExW(hRootKey, L"shell", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hShell, NULL) != ERROR_SUCCESS)
{ {
@ -369,7 +403,10 @@ BOOL WriteStaticShellExtensionKey(HKEY hRootKey, WCHAR * pVerb, WCHAR *pFullPath
return FALSE; return FALSE;
} }
result = RegSetValueExW(hCmd, NULL, 0, REG_SZ, (const BYTE*)pFullPath, (strlenW(pFullPath)+1)* sizeof(WCHAR)); wcscpy(szPath, pFullPath);
wcscat(szPath, L" %1");
result = RegSetValueExW(hCmd, NULL, 0, REG_SZ, (const BYTE*)szPath, (strlenW(szPath)+1)* sizeof(WCHAR));
RegCloseKey(hCmd); RegCloseKey(hCmd);
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS)
return TRUE; return TRUE;
@ -395,7 +432,6 @@ BOOL StoreApplicationsPathForUser(WCHAR *pFileName, WCHAR* pFullPath)
RegCloseKey(hRootKey); RegCloseKey(hRootKey);
return FALSE; return FALSE;
} }
RegCloseKey(hKey);
RegCloseKey(hRootKey); RegCloseKey(hRootKey);
result = WriteStaticShellExtensionKey(hKey, L"open", pFullPath); result = WriteStaticShellExtensionKey(hKey, L"open", pFullPath);
@ -451,50 +487,37 @@ BOOL StoreNewSettings(WCHAR * pExt, WCHAR * pFileName, WCHAR * pFullPath)
RegCloseKey(hRootKey); RegCloseKey(hRootKey);
if (dwDisposition & REG_CREATED_NEW_KEY)
{
result = RegSetValueExW(hKey, L"a", 0, REG_SZ, (const BYTE*)pFileName, (strlenW(pFileName)+1) * sizeof(WCHAR));
if (result != ERROR_SUCCESS)
{
ERR("Error: failed to set value\n");
RegCloseKey(hKey);
return FALSE;
}
result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const BYTE*)L"a", 2 * sizeof(WCHAR));
RegCloseKey(hKey);
if (result == ERROR_SUCCESS)
return TRUE;
else
return FALSE;
}
dwBuffer = sizeof(szBuffer); dwBuffer = sizeof(szBuffer);
result = RegGetValueW(hKey, NULL, L"MRUList", RRF_RT_REG_SZ, NULL, szBuffer, &dwBuffer); result = RegGetValueW(hKey, NULL, L"MRUList", RRF_RT_REG_SZ, NULL, szBuffer, &dwBuffer);
if (result != ERROR_SUCCESS) if (result != ERROR_SUCCESS)
{ {
/* FIXME /* FIXME
* recreate info * should rescan all values and rebuild the list
*/ */
ERR("Failed to get value of MRUList\n"); szBuffer[0] = 0;
RegCloseKey(hKey);
return FALSE;
} }
dwMask = 0; dwMask = 0;
CurChar[1] = 0; CurChar[1] = 0;
dwBuffer = (dwBuffer / sizeof(WCHAR)); dwBuffer = strlenW(szBuffer); //FIXME
for(dwIndex = 0; dwIndex < dwBuffer - 1; dwIndex++)
TRACE("MRUList %s length %u\n", debugstr_w(szBuffer), dwBuffer);
for(dwIndex = 0; dwIndex < dwBuffer; dwIndex++)
{ {
CurChar[0] = szBuffer[dwIndex]; CurChar[0] = szBuffer[dwIndex];
dwMask |= (1 << (CurChar[0] - L'a')); dwMask |= (1 << (szBuffer[0] - L'a'));
TRACE("dwMask %x CurChar %s\n", dwMask, debugstr_w(CurChar));
dwVal = sizeof(szVal); dwVal = sizeof(szVal);
if (RegGetValueW(hKey, NULL, CurChar, RRF_RT_REG_SZ, NULL, szVal, &dwVal) == ERROR_SUCCESS) if (RegGetValueW(hKey, NULL, CurChar, RRF_RT_REG_SZ, NULL, szVal, &dwVal) == ERROR_SUCCESS)
{ {
if (!wcsicmp(szVal, pFileName)) if (!wcsicmp(szVal, pFileName))
{ {
memmove(&szBuffer[0], &szBuffer[1], dwIndex * sizeof(WCHAR)); if (dwIndex)
memmove(&szBuffer[1], &szBuffer[0], dwIndex * sizeof(WCHAR));
szBuffer[0] = CurChar[0]; szBuffer[0] = CurChar[0];
result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const BYTE*)szBuffer, dwBuffer * sizeof(WCHAR)); result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const BYTE*)szBuffer, dwBuffer * sizeof(WCHAR));
RegCloseKey(hKey); RegCloseKey(hKey);
@ -505,6 +528,7 @@ BOOL StoreNewSettings(WCHAR * pExt, WCHAR * pFileName, WCHAR * pFullPath)
} }
} }
} }
TRACE("dwMask %x\n", dwMask);
dwIndex = 0; dwIndex = 0;
while(dwMask & (1 << dwIndex)) while(dwMask & (1 << dwIndex))
@ -519,12 +543,17 @@ BOOL StoreNewSettings(WCHAR * pExt, WCHAR * pFileName, WCHAR * pFullPath)
} }
CurChar[0] = L'a' + dwIndex; CurChar[0] = L'a' + dwIndex;
TRACE("new index %u CurChar %s\n", dwIndex, debugstr_w(CurChar));
result = RegSetValueExW(hKey, CurChar, 0, REG_SZ, (const BYTE*)pFileName, (strlenW(pFileName) + 1) * sizeof(WCHAR)); result = RegSetValueExW(hKey, CurChar, 0, REG_SZ, (const BYTE*)pFileName, (strlenW(pFileName) + 1) * sizeof(WCHAR));
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS)
{ {
memmove(&szBuffer[0], &szBuffer[1], dwBuffer * sizeof(WCHAR)); memmove(&szBuffer[1], &szBuffer[0], (dwBuffer + 1) * sizeof(WCHAR));
szBuffer[0] = CurChar[0]; szBuffer[0] = CurChar[0];
result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const BYTE*)szBuffer, dwBuffer * sizeof(WCHAR)); dwBuffer = strlenW(szBuffer);
TRACE("New MRUList %s length %u\n", debugstr_w(szBuffer), dwBuffer);
result = RegSetValueExW(hKey, L"MRUList", 0, REG_SZ, (const BYTE*)szBuffer, (dwBuffer+1) * sizeof(WCHAR));
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS)
{ {
StoreApplicationsPathForUser(pFileName, pFullPath); StoreApplicationsPathForUser(pFileName, pFullPath);
@ -539,7 +568,7 @@ BOOL StoreNewSettings(WCHAR * pExt, WCHAR * pFileName, WCHAR * pFullPath)
return FALSE; return FALSE;
} }
BOOL BOOL
SetProgrammAsDefaultHandler(WCHAR *pFileExt, WCHAR* pFullPath) SetProgramAsDefaultHandler(WCHAR *pFileExt, WCHAR* pFullPath)
{ {
HKEY hExtKey; HKEY hExtKey;
HKEY hProgKey; HKEY hProgKey;
@ -558,11 +587,17 @@ SetProgrammAsDefaultHandler(WCHAR *pFileExt, WCHAR* pFullPath)
{ {
wcscpy(szBuffer, &pFileExt[1]); wcscpy(szBuffer, &pFileExt[1]);
wcscat(szBuffer, L"_auto_file"); wcscat(szBuffer, L"_auto_file");
if (RegSetValueExW(hExtKey, NULL, 0, REG_SZ, (const BYTE*)szBuffer, (strlenW(szBuffer)+1) * sizeof(WCHAR)) != ERROR_SUCCESS)
{
ERR("Error: failed to store default key\n");
RegCloseKey(hExtKey);
return FALSE;
}
} }
else else
{ {
dwSize = sizeof(szBuffer); dwSize = sizeof(szBuffer);
if (!RegGetValueW(hExtKey, NULL, NULL, RRF_RT_REG_SZ, NULL, szBuffer, &dwSize)) if (RegGetValueW(hExtKey, NULL, NULL, RRF_RT_REG_SZ, NULL, szBuffer, &dwSize) != ERROR_SUCCESS)
{ {
ERR("Error: failed to retrieve subkey\n"); ERR("Error: failed to retrieve subkey\n");
RegCloseKey(hExtKey); RegCloseKey(hExtKey);
@ -596,7 +631,7 @@ static BOOL CALLBACK OpenWithProgrammDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam,
LPFNOFN ofnProc; LPFNOFN ofnProc;
WCHAR szBuffer[MAX_PATH + 30] = { 0 }; WCHAR szBuffer[MAX_PATH + 30] = { 0 };
WCHAR szPath[MAX_PATH * 2 +1] = { 0 }; WCHAR szPath[MAX_PATH * 2 +1] = { 0 };
WCHAR * pExt; WCHAR * pExt, *pFileName;
int res; int res;
LVITEMW lvItem; LVITEMW lvItem;
STARTUPINFOW si; STARTUPINFOW si;
@ -657,38 +692,43 @@ static BOOL CALLBACK OpenWithProgrammDlg(HWND hwndDlg, UINT uMsg, WPARAM wParam,
case 14005: /* ok */ case 14005: /* ok */
ZeroMemory(&lvItem, sizeof(LVITEMW)); ZeroMemory(&lvItem, sizeof(LVITEMW));
lvItem.mask = LVIF_PARAM | LVIF_TEXT; lvItem.mask = LVIF_PARAM;
lvItem.iItem = This->iSelItem; lvItem.iItem = This->iSelItem;
lvItem.pszText = szBuffer;
if (!ListView_GetItemW(GetDlgItem(hwndDlg, 14002), &lvItem)) if (!ListView_GetItemW(GetDlgItem(hwndDlg, 14002), &lvItem))
{ {
ERR("Failed to get item index %d\n", This->iSelItem); ERR("Failed to get item lparam %d\n", This->iSelItem);
DestroyWindow(hwndDlg); DestroyWindow(hwndDlg);
return FALSE; return FALSE;
} }
pExt = wcsrchr(szBuffer, L'.');
if (!HideApplicationFromList(szBuffer)) pFileName = wcsrchr((WCHAR*)lvItem.lParam, L'\\');
pExt = wcsrchr(This->szPath, L'\\');
if (pExt)
{ {
#if 0 pExt = wcsrchr(pExt + 1, L'.');
if (!StoreNewSettings(pExt, szBuffer, (WCHAR*)lvItem.lParam)) }
if (pFileName && pExt)
{
pFileName++;
if (!HideApplicationFromList(pFileName))
{
if (!StoreNewSettings(pExt, pFileName, (WCHAR*)lvItem.lParam))
{ {
/* failed to store setting */
WARN("Error: failed to store settings for app %s\n", debugstr_w(szBuffer)); WARN("Error: failed to store settings for app %s\n", debugstr_w(szBuffer));
} }
#endif
} }
if (SendDlgItemMessage(hwndDlg, 14003, BM_GETCHECK, 0, 0) == BST_CHECKED) if (SendDlgItemMessage(hwndDlg, 14003, BM_GETCHECK, 0, 0) == BST_CHECKED)
{ {
#if 0 if (!SetProgramAsDefaultHandler(pExt, (WCHAR*)lvItem.lParam))
if (!SetProgrammAsDefaultHandler(pExt, (WCHAR*)lvItem.lParam))
{ {
/* failed to associate programm */ /* failed to associate programm */
WARN("Error: failed to associate programm\n"); WARN("Error: failed to associate programm\n");
} }
#endif
} }
}
ZeroMemory(&si, sizeof(STARTUPINFOW)); ZeroMemory(&si, sizeof(STARTUPINFOW));
si.cb = sizeof(STARTUPINFOW); si.cb = sizeof(STARTUPINFOW);
wcscpy(szPath, (WCHAR*)lvItem.lParam); wcscpy(szPath, (WCHAR*)lvItem.lParam);
@ -761,7 +801,12 @@ SHEOWCm_fnInvokeCommand( IContextMenu2* iface, LPCMINVOKECOMMANDINFO lpici )
MSG msg; MSG msg;
BOOL bRet; BOOL bRet;
HWND hwnd = CreateDialogParam(shell32_hInstance, MAKEINTRESOURCE(OPEN_WITH_PROGRAMM_DLG), lpici->hwnd, OpenWithProgrammDlg, (LPARAM)This); HWND hwnd = CreateDialogParam(shell32_hInstance, MAKEINTRESOURCE(OPEN_WITH_PROGRAMM_DLG), lpici->hwnd, OpenWithProgrammDlg, (LPARAM)This);
ShowWindow(hwnd, SW_SHOW); if (hwnd == NULL)
{
ERR("Failed to create dialog\n");
return E_FAIL;
}
ShowWindow(hwnd, SW_SHOWNORMAL);
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{ {
@ -859,25 +904,18 @@ void
SHEOW_AddOWItem(SHEOWImpl *This, WCHAR * szAppName) SHEOW_AddOWItem(SHEOWImpl *This, WCHAR * szAppName)
{ {
UINT index; UINT index;
WCHAR * szPtr;
if (This->count + 1 >= This->size || !This->szArray) if (This->count + 1 >= This->size || !This->szArray)
{ {
if (!SHEOW_ResizeArray(This)) if (!SHEOW_ResizeArray(This))
return; return;
} }
szPtr = wcsrchr(szAppName, '.');
if (szPtr)
{
szPtr[0] = 0;
}
for(index = 0; index < This->count; index++) for(index = 0; index < This->count; index++)
{ {
if (!wcsicmp(This->szArray[index], szAppName)) if (!wcsicmp(This->szArray[index], szAppName))
return; return;
} }
This->szArray[This->count] = wcsdup(szAppName); This->szArray[This->count] = wcsdup(szAppName);
if (This->szArray[This->count]) if (This->szArray[This->count])
@ -902,7 +940,7 @@ SHEW_AddOpenWithItem(SHEOWImpl *This, HKEY hKey)
LONG result = ERROR_SUCCESS; LONG result = ERROR_SUCCESS;
WCHAR szName[10]; WCHAR szName[10];
WCHAR szValue[MAX_PATH]; WCHAR szValue[MAX_PATH];
WCHAR szMRUList[MAX_PATH] = {0}; WCHAR szMRUList[32] = {0};
static const WCHAR szMRU[] = {'M','R','U','L','i','s','t', 0 }; static const WCHAR szMRU[] = {'M','R','U','L','i','s','t', 0 };
@ -925,14 +963,14 @@ SHEW_AddOpenWithItem(SHEOWImpl *This, HKEY hKey)
if (result == ERROR_SUCCESS) if (result == ERROR_SUCCESS)
{ {
if (wcsicmp(szValue, szMRU)) if (!wcsicmp(szName, szMRU))
{ {
SHEOW_AddOWItem(This, szValue); wcsncpy(szMRUList, szValue, sizeof(szMRU) / sizeof(WCHAR));
NumItems++;
} }
else else
{ {
wcscpy(szMRUList, szValue); SHEOW_AddOWItem(This, szValue);
NumItems++;
} }
} }
dwIndex++; dwIndex++;
@ -1170,9 +1208,6 @@ SHEOW_LoadOpenWithItems(SHEOWImpl *This, IDataObject *pdtobj)
return S_OK; return S_OK;
} }
static HRESULT WINAPI static HRESULT WINAPI
SHEOW_ExtInit_Initialize( IShellExtInit* iface, LPCITEMIDLIST pidlFolder, SHEOW_ExtInit_Initialize( IShellExtInit* iface, LPCITEMIDLIST pidlFolder,
IDataObject *pdtobj, HKEY hkeyProgID ) IDataObject *pdtobj, HKEY hkeyProgID )