ReactOS 0.4.16-dev-1272-g2c12489
COpenWithList Class Reference
Collaboration diagram for COpenWithList:

Classes

struct  _LANGANDCODEPAGE
 
struct  SApp
 

Public Member Functions

 COpenWithList ()
 
 ~COpenWithList ()
 
BOOL Load ()
 
SAppAdd (LPCWSTR pwszPath)
 
SAppFind (LPCWSTR pwszFilename)
 
BOOL IsNoOpen (VOID)
 
BOOL LoadRecommended (LPCWSTR pwszFilePath)
 
BOOL SetDefaultHandler (SApp *pApp, LPCWSTR pwszFilename)
 
SAppGetList ()
 
UINT GetCount ()
 
UINT GetRecommendedCount ()
 

Static Public Member Functions

static BOOL SaveApp (SApp *pApp)
 
static LPCWSTR GetName (SApp *pApp)
 
static HICON GetIcon (SApp *pApp)
 
static BOOL Execute (SApp *pApp, LPCWSTR pwszFilePath)
 
static BOOL IsHidden (SApp *pApp)
 

Private Types

typedef struct COpenWithList::_LANGANDCODEPAGE LANGANDCODEPAGE
 
typedef struct COpenWithList::_LANGANDCODEPAGELPLANGANDCODEPAGE
 

Private Member Functions

SAppAddInternal (LPCWSTR pwszFilename)
 
BOOL LoadProgIdList (HKEY hKey, LPCWSTR pwszExt)
 
BOOL LoadMRUList (HKEY hKey)
 
BOOL LoadAppList (HKEY hKey)
 
VOID LoadFromProgIdKey (HKEY hKey, LPCWSTR pwszExt)
 
VOID LoadRecommendedFromHKCR (LPCWSTR pwszExt)
 
VOID LoadRecommendedFromHKCU (LPCWSTR pwszExt)
 
VOID SetRecommended (SApp *pApp)
 

Static Private Member Functions

static BOOL LoadInfo (SApp *pApp)
 
static BOOL GetPathFromCmd (LPWSTR pwszAppPath, LPCWSTR pwszCmd)
 
static HANDLE OpenMRUList (HKEY hKey)
 
static BOOL AddAppToMRUList (SApp *pApp, LPCWSTR pwszFilename)
 

Private Attributes

SAppm_pApp
 
UINT m_cApp
 
UINT m_cRecommended
 
BOOL m_bNoOpen
 

Detailed Description

Definition at line 145 of file COpenWithMenu.cpp.

Member Typedef Documentation

◆ LANGANDCODEPAGE

◆ LPLANGANDCODEPAGE

Constructor & Destructor Documentation

◆ COpenWithList()

COpenWithList::COpenWithList ( )

Definition at line 210 of file COpenWithMenu.cpp.

210 :
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117

◆ ~COpenWithList()

COpenWithList::~COpenWithList ( )

Definition at line 213 of file COpenWithMenu.cpp.

214{
215 for (UINT i = 0; i < m_cApp; ++i)
216 if (m_pApp[i].hIcon)
218
220}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2390

Member Function Documentation

◆ Add()

COpenWithList::SApp * COpenWithList::Add ( LPCWSTR  pwszPath)

Definition at line 283 of file COpenWithMenu.cpp.

284{
285 SApp *pApp = AddInternal(PathFindFileNameW(pwszPath));
286
287 if (pApp)
288 {
289 StringCbPrintfW(pApp->wszCmd, sizeof(pApp->wszCmd), L"\"%s\" \"%%1\"", pwszPath);
290 SaveApp(pApp);
291 }
292
293 return pApp;
294}
static BOOL SaveApp(SApp *pApp)
SApp * AddInternal(LPCWSTR pwszFilename)
WCHAR *WINAPI PathFindFileNameW(const WCHAR *path)
Definition: path.c:1644
#define L(x)
Definition: ntvdm.h:50
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557

Referenced by COpenWithDialog::Browse().

◆ AddAppToMRUList()

BOOL COpenWithList::AddAppToMRUList ( SApp pApp,
LPCWSTR  pwszFilename 
)
staticprivate

Definition at line 769 of file COpenWithMenu.cpp.

770{
771 WCHAR wszBuf[100];
772 LPCWSTR pwszExt;
773 HKEY hKey;
775
776 /* Get file extension */
777 pwszExt = PathFindExtensionW(pwszFilename);
778 if (!pwszExt[0])
779 return FALSE;
780
781 /* Build registry key */
782 if (FAILED(StringCbPrintfW(wszBuf, sizeof(wszBuf),
783 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",
784 pwszExt)))
785 {
786 ERR("insufficient buffer\n");
787 return FALSE;
788 }
789
790 /* Open base key for this file extension */
792 return FALSE;
793
794 /* Open MRU list */
796 if (hList)
797 {
798 /* Insert the entry */
799 AddMRUStringW(hList, pApp->wszFilename);
800
801 /* Set MRU presence */
802 pApp->bMRUList = TRUE;
803
804 /* Close MRU list */
806 }
807
809 return TRUE;
810}
#define ERR(fmt,...)
Definition: precomp.h:57
#define RegCloseKey(hKey)
Definition: registry.h:49
static HANDLE OpenMRUList(HKEY hKey)
INT WINAPI AddMRUStringW(HANDLE hList, LPCWSTR lpszString)
void WINAPI FreeMRUList(HANDLE hMRUList)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LPWSTR WINAPI PathFindExtensionW(const WCHAR *path)
Definition: path.c:1217
FxAutoRegKey hKey
#define FAILED(hr)
Definition: intsafe.h:51
HWND hList
Definition: livecd.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_WRITE
Definition: nt_native.h:1031
#define HKEY_CURRENT_USER
Definition: winreg.h:11
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by Execute().

◆ AddInternal()

COpenWithList::SApp * COpenWithList::AddInternal ( LPCWSTR  pwszFilename)
private

Definition at line 419 of file COpenWithMenu.cpp.

420{
421 /* Check for duplicate */
422 SApp *pApp = Find(pwszFilename);
423 if (pApp)
424 return pApp;
425
426 /* Create new item */
427 if (!m_pApp)
428 m_pApp = static_cast<SApp *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(m_pApp[0])));
429 else
430 m_pApp = static_cast<SApp *>(HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, m_pApp, (m_cApp + 1)*sizeof(m_pApp[0])));
431 if (!m_pApp)
432 {
433 ERR("Allocation failed\n");
434 return NULL;
435 }
436
437 pApp = &m_pApp[m_cApp++];
438 wcscpy(pApp->wszFilename, pwszFilename);
439 return pApp;
440}
SApp * Find(LPCWSTR pwszFilename)
wcscpy
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define HEAP_ZERO_MEMORY
Definition: compat.h:134

Referenced by Add(), Load(), and LoadFromProgIdKey().

◆ Execute()

BOOL COpenWithList::Execute ( COpenWithList::SApp pApp,
LPCWSTR  pwszFilePath 
)
static

Definition at line 369 of file COpenWithMenu.cpp.

370{
371 WCHAR wszBuf[256];
372 HKEY hKey;
373
374 /* Add app to registry if it wasnt there before */
375 SaveApp(pApp);
376 if (!pApp->bMRUList)
377 AddAppToMRUList(pApp, pwszFilePath);
378
379 /* Get a handle to the reg key */
380 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename);
382 {
383 ERR("RegOpenKeyEx failed\n");
384 return FALSE;
385 }
386
387 /* Let ShellExecuteExW do the work */
389 sei.nShow = SW_SHOWNORMAL;
390 sei.hkeyClass = hKey;
391 sei.lpFile = pwszFilePath;
392
393 ShellExecuteExW(&sei);
394
395 return TRUE;
396}
static BOOL AddAppToMRUList(SApp *pApp, LPCWSTR pwszFilename)
#define SEE_MASK_CLASSKEY
Definition: shellapi.h:26
struct _SHELLEXECUTEINFOW SHELLEXECUTEINFOW
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2461
WCHAR wszFilename[MAX_PATH]
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SW_SHOWNORMAL
Definition: winuser.h:781

Referenced by COpenWithDialog::Accept(), and COpenWithMenu::InvokeCommand().

◆ Find()

COpenWithList::SApp * COpenWithList::Find ( LPCWSTR  pwszFilename)

Definition at line 315 of file COpenWithMenu.cpp.

316{
317 for (UINT i = 0; i < m_cApp; ++i)
318 if (_wcsicmp(m_pApp[i].wszFilename, pwszFilename) == 0)
319 return &m_pApp[i];
320 return NULL;
321}
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by AddInternal(), LoadAppList(), LoadMRUList(), and LoadRecommendedFromHKCU().

◆ GetCount()

UINT COpenWithList::GetCount ( )
inline

Definition at line 176 of file COpenWithMenu.cpp.

176{ return m_cApp; }

Referenced by COpenWithDialog::Init(), and COpenWithMenu::QueryContextMenu().

◆ GetIcon()

HICON COpenWithList::GetIcon ( SApp pApp)
static

Definition at line 344 of file COpenWithMenu.cpp.

345{
346 if (!pApp->hIcon)
347 {
348 WCHAR wszPath[MAX_PATH];
349
350 GetPathFromCmd(wszPath, pApp->wszCmd);
351 if (!ExtractIconExW(wszPath, 0, NULL, &pApp->hIcon, 1))
352 {
353 SHFILEINFO fi;
354 /* FIXME: Ideally we should include SHGFI_USEFILEATTRIBUTES because we already
355 ** know the file has no icons but SHGetFileInfo is broken in that case (CORE-19122).
356 ** Without SHGFI_USEFILEATTRIBUTES we needlessly hit the disk again but it will
357 ** return the correct default .exe icon.
358 */
359 SHGetFileInfoW(wszPath, 0, &fi, sizeof(fi), SHGFI_ICON|SHGFI_SMALLICON|SHGFI_SHELLICONSIZE);
360 pApp->hIcon = fi.hIcon;
361 }
362 }
363
364 TRACE("%ls icon: %p\n", pApp->wszFilename, pApp->hIcon);
365
366 return pApp->hIcon;
367}
static BOOL GetPathFromCmd(LPWSTR pwszAppPath, LPCWSTR pwszCmd)
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:855
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:430
#define SHGFI_ICON
Definition: shellapi.h:164
#define SHGFI_SMALLICON
Definition: shellapi.h:176
#define SHGFI_SHELLICONSIZE
Definition: shellapi.h:179
#define TRACE(s)
Definition: solgame.cpp:4
HICON hIcon
Definition: shellapi.h:377

Referenced by COpenWithDialog::AddApp(), and COpenWithMenu::AddApp().

◆ GetList()

SApp * COpenWithList::GetList ( )
inline

Definition at line 175 of file COpenWithMenu.cpp.

175{ return m_pApp; }

Referenced by COpenWithDialog::Init(), and COpenWithMenu::QueryContextMenu().

◆ GetName()

LPCWSTR COpenWithList::GetName ( SApp pApp)
static

Definition at line 323 of file COpenWithMenu.cpp.

324{
325 if (!pApp->wszName[0])
326 {
327 if (!LoadInfo(pApp))
328 {
329 WARN("Failed to load %ls info\n", pApp->wszFilename);
330 StringCbCopyW(pApp->wszName, sizeof(pApp->wszName), pApp->wszFilename);
331
332 WCHAR wszPath[MAX_PATH];
333 if (!GetPathFromCmd(wszPath, pApp->wszCmd))
334 {
335 return NULL;
336 }
337 }
338 }
339
340 TRACE("%ls name: %ls\n", pApp->wszFilename, pApp->wszName);
341 return pApp->wszName;
342}
#define WARN(fmt,...)
Definition: precomp.h:61
static BOOL LoadInfo(SApp *pApp)
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166

Referenced by COpenWithDialog::AddApp(), and COpenWithMenu::AddApp().

◆ GetPathFromCmd()

BOOL COpenWithList::GetPathFromCmd ( LPWSTR  pwszAppPath,
LPCWSTR  pwszCmd 
)
staticprivate

Definition at line 508 of file COpenWithMenu.cpp.

509{
510 WCHAR wszBuf[MAX_PATH];
511
512 /* Remove arguments */
513 if (!PathGetAppFromCommandLine(pwszCmd, wszBuf, _countof(wszBuf)))
514 return FALSE;
515
516 /* Replace rundll32.exe with the dll path */
517 SHELL32_GetDllFromRundll32CommandLine(pwszCmd, wszBuf, _countof(wszBuf));
518
519 /* Expand env. vars and optionally search for path */
520 ExpandEnvironmentStrings(wszBuf, pwszAppPath, MAX_PATH);
521 if (!PathFileExists(pwszAppPath))
522 {
523 UINT cch = SearchPathW(NULL, pwszAppPath, NULL, MAX_PATH, pwszAppPath, NULL);
524 if (!cch || cch >= MAX_PATH)
525 return FALSE;
526 }
527 return TRUE;
528}
static SIZE_T PathGetAppFromCommandLine(LPCWSTR pszIn, LPWSTR pszOut, SIZE_T cchMax)
HRESULT SHELL32_GetDllFromRundll32CommandLine(LPCWSTR pszCmd, LPWSTR pszOut, SIZE_T cchMax)
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1298
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
#define PathFileExists
Definition: shlwapi.h:942
#define _countof(array)
Definition: sndvol32.h:70
#define ExpandEnvironmentStrings
Definition: winbase.h:3815

Referenced by GetIcon(), GetName(), LoadFromProgIdKey(), and LoadInfo().

◆ GetRecommendedCount()

UINT COpenWithList::GetRecommendedCount ( )
inline

Definition at line 177 of file COpenWithMenu.cpp.

177{ return m_cRecommended; }

Referenced by COpenWithDialog::Init(), and COpenWithMenu::QueryContextMenu().

◆ IsHidden()

BOOL COpenWithList::IsHidden ( SApp pApp)
static

Definition at line 398 of file COpenWithMenu.cpp.

399{
400 WCHAR wszBuf[100];
401 DWORD dwSize = 0;
402
403 if (pApp->bHidden)
404 return pApp->bHidden;
405
406 if (FAILED(StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename)))
407 {
408 ERR("insufficient buffer\n");
409 return FALSE;
410 }
411
412 if (RegGetValueW(HKEY_CLASSES_ROOT, wszBuf, L"NoOpenWith", RRF_RT_REG_SZ, NULL, NULL, &dwSize) != ERROR_SUCCESS)
413 return FALSE;
414
415 pApp->bHidden = TRUE;
416 return TRUE;
417}
LSTATUS WINAPI RegGetValueW(HKEY hKey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
Definition: reg.c:1931
#define RRF_RT_REG_SZ
Definition: driver.c:575
unsigned long DWORD
Definition: ntddk_ex.h:95
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by COpenWithDialog::Init().

◆ IsNoOpen()

BOOL COpenWithList::IsNoOpen ( VOID  )
inline

Definition at line 171 of file COpenWithMenu.cpp.

171{ return m_bNoOpen; }

Referenced by COpenWithDialog::Init().

◆ Load()

BOOL COpenWithList::Load ( )

Definition at line 222 of file COpenWithMenu.cpp.

223{
224 HKEY hKey, hKeyApp;
225 WCHAR wszName[256], wszBuf[100];
226 DWORD i = 0, cchName, dwSize;
227 SApp *pApp;
228
229 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"Applications", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
230 {
231 ERR("RegOpenKeyEx HKCR\\Applications failed!\n");
232 return FALSE;
233 }
234
235 while (TRUE)
236 {
237 cchName = _countof(wszName);
238 if (RegEnumKeyEx(hKey, i++, wszName, &cchName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
239 break;
240
241 pApp = AddInternal(wszName);
242
243 if (pApp)
244 {
245 if (RegOpenKeyW(hKey, wszName, &hKeyApp) == ERROR_SUCCESS)
246 {
247 if ((RegQueryValueExW(hKeyApp, L"NoOpenWith", NULL, NULL, NULL, NULL) != ERROR_SUCCESS) &&
248 (RegQueryValueExW(hKeyApp, L"NoStartPage", NULL, NULL, NULL, NULL) != ERROR_SUCCESS))
249 {
250 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\shell\\open\\command", wszName);
251 dwSize = sizeof(pApp->wszCmd);
252 if (RegGetValueW(hKey, wszBuf, L"", RRF_RT_REG_SZ, NULL, pApp->wszCmd, &dwSize) != ERROR_SUCCESS)
253 {
254 ERR("Failed to add app %ls\n", wszName);
255 pApp->bHidden = TRUE;
256 }
257 else
258 {
259 TRACE("App added %ls\n", pApp->wszCmd);
260 }
261 }
262 else
263 {
264 pApp->bHidden = TRUE;
265 }
266 RegCloseKey(hKeyApp);
267 }
268 else
269 {
270 pApp->bHidden = TRUE;
271 }
272 }
273 else
274 {
275 ERR("AddInternal failed\n");
276 }
277 }
278
280 return TRUE;
281}
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2808
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegEnumKeyEx
Definition: winreg.h:510

Referenced by COpenWithDialog::Init(), and COpenWithMenu::QueryContextMenu().

◆ LoadAppList()

BOOL COpenWithList::LoadAppList ( HKEY  hKey)
private

Definition at line 629 of file COpenWithMenu.cpp.

630{
631 WCHAR wszAppFilename[MAX_PATH];
632 HKEY hSubkey;
633 DWORD i = 0, cchAppFilename;
634
635 if (RegOpenKeyExW(hKey, L"OpenWithList", 0, KEY_READ, &hSubkey) != ERROR_SUCCESS)
636 return FALSE;
637
638 while (TRUE)
639 {
640 /* Enum registry keys - each of them is app name */
641 cchAppFilename = _countof(wszAppFilename);
642 if (RegEnumKeyExW(hSubkey, i++, wszAppFilename, &cchAppFilename, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
643 break;
644
645 /* Set application as recommended */
646 SApp *pApp = Find(wszAppFilename);
647
648 TRACE("Recommended app %ls: %p\n", wszAppFilename, pApp);
649 if (pApp)
650 SetRecommended(pApp);
651 }
652
653 RegCloseKey(hSubkey);
654 return TRUE;
655}
VOID SetRecommended(SApp *pApp)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504

Referenced by LoadRecommendedFromHKCR().

◆ LoadFromProgIdKey()

VOID COpenWithList::LoadFromProgIdKey ( HKEY  hKey,
LPCWSTR  pwszExt 
)
private

Definition at line 657 of file COpenWithMenu.cpp.

658{
659 WCHAR wszCmd[MAX_PATH], wszPath[MAX_PATH];
660 DWORD dwSize = 0;
661
662 /* Check if NoOpen value exists */
664 {
665 /* Display warning dialog */
666 m_bNoOpen = TRUE;
667 }
668
669 /* Check if there is a directly available execute key */
670 dwSize = sizeof(wszCmd);
671 if (RegGetValueW(hKey, L"shell\\open\\command", NULL, RRF_RT_REG_SZ, NULL, (PVOID)wszCmd, &dwSize) == ERROR_SUCCESS)
672 {
673 /* Erase extra arguments */
674 GetPathFromCmd(wszPath, wszCmd);
675
676 /* Add application */
677 SApp *pApp = AddInternal(PathFindFileNameW(wszPath));
678 TRACE("Add app %ls: %p\n", wszPath, pApp);
679
680 if (pApp)
681 {
682 StringCbCopyW(pApp->wszCmd, sizeof(pApp->wszCmd), wszCmd);
683 SetRecommended(pApp);
684 }
685 }
686}

Referenced by LoadProgIdList(), and LoadRecommendedFromHKCR().

◆ LoadInfo()

BOOL COpenWithList::LoadInfo ( COpenWithList::SApp pApp)
staticprivate

Definition at line 442 of file COpenWithMenu.cpp.

443{
444 UINT cbSize, cchLen;
445 LPVOID pBuf;
446 WORD wLang = 0, wCode = 0;
447 LPLANGANDCODEPAGE lpLangCode;
448 WCHAR wszBuf[100];
449 WCHAR *pResult;
450 WCHAR wszPath[MAX_PATH];
452
453 GetPathFromCmd(wszPath, pApp->wszCmd);
454 TRACE("LoadInfo %ls\n", wszPath);
455
456 /* query version info size */
457 cbSize = GetFileVersionInfoSizeW(wszPath, NULL);
458 if (!cbSize)
459 {
460 ERR("GetFileVersionInfoSizeW %ls failed: %lu\n", wszPath, GetLastError());
461 return FALSE;
462 }
463
464 /* allocate buffer */
465 pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbSize + 200);
466 if (!pBuf)
467 {
468 ERR("HeapAlloc failed\n");
469 return FALSE;
470 }
471
472 /* query version info */
473 if (!GetFileVersionInfoW(wszPath, 0, cbSize, pBuf))
474 {
475 ERR("GetFileVersionInfoW %ls failed: %lu\n", wszPath, GetLastError());
476 HeapFree(GetProcessHeap(), 0, pBuf);
477 return FALSE;
478 }
479
480 /* query lang code */
481 if (VerQueryValueW(pBuf, L"VarFileInfo\\Translation", (LPVOID*)&lpLangCode, &cbSize))
482 {
483 /* FIXME: find language from current locale / if not available,
484 * default to english
485 * for now default to first available language
486 */
487 wLang = lpLangCode->lang;
488 wCode = lpLangCode->code;
489 }
490
491 /* Query name */
492 swprintf(wszBuf, L"\\StringFileInfo\\%04x%04x\\FileDescription", wLang, wCode);
493 success = VerQueryValueW(pBuf, wszBuf, (LPVOID *)&pResult, &cchLen) && (cchLen > 1);
494 if (success)
495 StringCchCopyNW(pApp->wszName, _countof(pApp->wszName), pResult, cchLen);
496 else
497 ERR("Cannot get app name\n");
498
499 /* Query manufacturer */
500 /*swprintf(wszBuf, L"\\StringFileInfo\\%04x%04x\\CompanyName", wLang, wCode);
501
502 if (VerQueryValueW(pBuf, wszBuf, (LPVOID *)&pResult, &cchLen))
503 StringCchCopyNW(pApp->wszManufacturer, _countof(pApp->wszManufacturer), pResult, cchLen);*/
504 HeapFree(GetProcessHeap(), 0, pBuf);
505 return success;
506}
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:967
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1171
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:738
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned short WORD
Definition: ntddk_ex.h:93
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
WCHAR wszCmd[MAX_PATH]
#define success(from, fromstr, to, tostr)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by GetName().

◆ LoadMRUList()

BOOL COpenWithList::LoadMRUList ( HKEY  hKey)
private

Definition at line 590 of file COpenWithMenu.cpp.

591{
593 int nItem, nCount, nResult;
594 WCHAR wszAppFilename[MAX_PATH];
595
596 /* Open MRU list */
598 if (!hList)
599 {
600 TRACE("OpenMRUList failed\n");
601 return FALSE;
602 }
603
604 /* Get list count */
605 nCount = EnumMRUListW(hList, -1, NULL, 0);
606
607 for(nItem = 0; nItem < nCount; nItem++)
608 {
609 nResult = EnumMRUListW(hList, nItem, wszAppFilename, _countof(wszAppFilename));
610 if (nResult <= 0)
611 continue;
612
613 /* Insert item */
614 SApp *pApp = Find(wszAppFilename);
615
616 TRACE("Recommended app %ls: %p\n", wszAppFilename, pApp);
617 if (pApp)
618 {
619 pApp->bMRUList = TRUE;
620 SetRecommended(pApp);
621 }
622 }
623
624 /* Free the MRU list */
626 return TRUE;
627}
INT WINAPI EnumMRUListW(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize)

Referenced by LoadRecommendedFromHKCU().

◆ LoadProgIdList()

BOOL COpenWithList::LoadProgIdList ( HKEY  hKey,
LPCWSTR  pwszExt 
)
private

Definition at line 547 of file COpenWithMenu.cpp.

548{
549 HKEY hSubkey, hSubkey2;
550 WCHAR wszProgId[256];
551 DWORD i = 0, cchProgId;
552
553 if (RegOpenKeyExW(hKey, L"OpenWithProgIDs", 0, KEY_READ, &hSubkey) != ERROR_SUCCESS)
554 return FALSE;
555
556 while (TRUE)
557 {
558 /* Enumerate values - value name is ProgId */
559 cchProgId = _countof(wszProgId);
560 if (RegEnumValue(hSubkey, i++, wszProgId, &cchProgId, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
561 break;
562
563 /* If ProgId exists load it */
564 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszProgId, 0, KEY_READ, &hSubkey2) == ERROR_SUCCESS)
565 {
566 LoadFromProgIdKey(hSubkey2, pwszExt);
567 RegCloseKey(hSubkey2);
568 }
569 }
570
571 RegCloseKey(hSubkey);
572 return TRUE;
573}
VOID LoadFromProgIdKey(HKEY hKey, LPCWSTR pwszExt)
#define RegEnumValue
Definition: winreg.h:511

Referenced by LoadRecommendedFromHKCR(), and LoadRecommendedFromHKCU().

◆ LoadRecommended()

BOOL COpenWithList::LoadRecommended ( LPCWSTR  pwszFilePath)

Definition at line 530 of file COpenWithMenu.cpp.

531{
532 LPCWSTR pwszExt;
533
534 pwszExt = PathFindExtensionW(pwszFilePath);
535 if (!pwszExt[0])
536 return FALSE;
537
538 /* load programs directly associated from HKCU */
540
541 /* load programs associated from HKCR\Extension */
543
544 return TRUE;
545}
VOID LoadRecommendedFromHKCR(LPCWSTR pwszExt)
VOID LoadRecommendedFromHKCU(LPCWSTR pwszExt)

Referenced by COpenWithDialog::Init(), and COpenWithMenu::QueryContextMenu().

◆ LoadRecommendedFromHKCR()

VOID COpenWithList::LoadRecommendedFromHKCR ( LPCWSTR  pwszExt)
private

Definition at line 688 of file COpenWithMenu.cpp.

689{
690 HKEY hKey, hSubkey;
691 WCHAR wszBuf[MAX_PATH], wszBuf2[MAX_PATH];
693
694 /* Check if extension exists */
696 {
697 /* Load items from SystemFileAssociations\Ext key */
698 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"SystemFileAssociations\\%s", pwszExt);
700 return;
701 }
702
703 /* Load programs referenced from HKCR\ProgId */
704 dwSize = sizeof(wszBuf);
705 if (RegGetValueW(hKey, NULL, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS &&
706 RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hSubkey) == ERROR_SUCCESS)
707 {
708 LoadFromProgIdKey(hSubkey, pwszExt);
709 RegCloseKey(hSubkey);
710 }
711 else
712 LoadFromProgIdKey(hKey, pwszExt);
713
714 /* Load items from HKCR\Ext\OpenWithList */
716
717 /* Load items from HKCR\Ext\OpenWithProgIDs */
718 if (RegOpenKeyExW(hKey, L"OpenWithProgIDs", 0, KEY_READ, &hSubkey) == ERROR_SUCCESS)
719 {
720 LoadProgIdList(hSubkey, pwszExt);
721 RegCloseKey(hSubkey);
722 }
723
724 /* Load additional items from referenced PerceivedType */
725 dwSize = sizeof(wszBuf);
726 if (RegGetValueW(hKey, NULL, L"PerceivedType", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS)
727 {
728 StringCbPrintfW(wszBuf2, sizeof(wszBuf2), L"SystemFileAssociations\\%s", wszBuf);
729 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf2, 0, KEY_READ | KEY_WRITE, &hSubkey) == ERROR_SUCCESS)
730 {
731 /* Load from OpenWithList key */
732 LoadAppList(hSubkey);
733 RegCloseKey(hSubkey);
734 }
735 }
736
737 /* Close the key */
739}
BOOL LoadAppList(HKEY hKey)
BOOL LoadProgIdList(HKEY hKey, LPCWSTR pwszExt)

Referenced by LoadRecommended().

◆ LoadRecommendedFromHKCU()

VOID COpenWithList::LoadRecommendedFromHKCU ( LPCWSTR  pwszExt)
private

Definition at line 741 of file COpenWithMenu.cpp.

742{
743 WCHAR wszBuf[MAX_PATH];
744 HKEY hKey;
745
746 StringCbPrintfW(wszBuf, sizeof(wszBuf),
747 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",
748 pwszExt);
750 {
751 /* Load MRU and ProgId lists */
753 LoadProgIdList(hKey, pwszExt);
754
755 /* Handle "Application" value */
756 DWORD cbBuf = sizeof(wszBuf);
757 if (RegGetValueW(hKey, NULL, L"Application", RRF_RT_REG_SZ, NULL, wszBuf, &cbBuf) == ERROR_SUCCESS)
758 {
759 SApp *pApp = Find(wszBuf);
760 if (pApp)
761 SetRecommended(pApp);
762 }
763
764 /* Close the key */
766 }
767}
BOOL LoadMRUList(HKEY hKey)

Referenced by LoadRecommended().

◆ OpenMRUList()

HANDLE COpenWithList::OpenMRUList ( HKEY  hKey)
staticprivate

Definition at line 575 of file COpenWithMenu.cpp.

576{
578
579 /* Initialize mru list info */
580 Info.cbSize = sizeof(Info);
581 Info.uMax = 32;
582 Info.fFlags = MRU_STRING;
583 Info.hKey = hKey;
584 Info.lpszSubKey = L"OpenWithList";
585 Info.lpfnCompare = NULL;
586
587 return CreateMRUListW(&Info);
588}
HANDLE WINAPI CreateMRUListW(const MRUINFOW *infoW)
#define MRU_STRING
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by AddAppToMRUList(), and LoadMRUList().

◆ SaveApp()

BOOL COpenWithList::SaveApp ( SApp pApp)
static

Definition at line 296 of file COpenWithMenu.cpp.

297{
298 WCHAR wszBuf[256];
299 HKEY hKey;
300
301 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s\\shell\\open\\command", pApp->wszFilename);
303 {
304 ERR("RegOpenKeyEx failed\n");
305 return FALSE;
306 }
307
308 if (RegSetValueEx(hKey, L"", 0, REG_SZ, (PBYTE)pApp->wszCmd, (wcslen(pApp->wszCmd)+1)*sizeof(WCHAR)) != ERROR_SUCCESS)
309 ERR("Cannot add app to registry\n");
310
312 return TRUE;
313}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
BYTE * PBYTE
Definition: pedump.c:66
#define RegSetValueEx
Definition: winreg.h:533

Referenced by Add(), and Execute().

◆ SetDefaultHandler()

BOOL COpenWithList::SetDefaultHandler ( SApp pApp,
LPCWSTR  pwszFilename 
)

Definition at line 812 of file COpenWithMenu.cpp.

813{
814 HKEY hKey, hSrcKey, hDestKey;
815 WCHAR wszBuf[256];
816
817 TRACE("SetDefaultHandler %ls %ls\n", pApp->wszFilename, pwszFilename);
818
819 /* Extract file extension */
820 LPCWSTR pwszExt = PathFindExtensionW(pwszFilename);
821 if (!pwszExt[0] || !pwszExt[1])
822 return FALSE;
823
824 /* Create file extension key */
826 {
827 ERR("Can't open ext key\n");
828 return FALSE;
829 }
830
831 DWORD dwSize = sizeof(wszBuf);
832 LONG lResult = RegGetValueW(hKey, NULL, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize);
833
834 if (lResult == ERROR_FILE_NOT_FOUND)
835 {
836 /* A new entry was created or the default key is not set: set the prog key id */
837 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s_auto_file", pwszExt + 1);
838 if (RegSetValueExW(hKey, L"", 0, REG_SZ, (const BYTE*)wszBuf, (wcslen(wszBuf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
839 {
841 ERR("RegSetValueExW failed\n");
842 return FALSE;
843 }
844 }
845 else if (lResult != ERROR_SUCCESS)
846 {
848 ERR("RegGetValueExW failed: 0x%08x\n", lResult);
849 return FALSE;
850 }
851
852 /* Close file extension key */
854
855 /* Create prog id key */
857 {
858 ERR("RegCreateKeyExW failed\n");
859 return FALSE;
860 }
861
862 /* Check if there already verbs existing for that app */
863 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s\\shell", pApp->wszFilename);
864 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hSrcKey) != ERROR_SUCCESS)
865 {
866 ERR("RegOpenKeyExW %ls failed\n", wszBuf);
868 return FALSE;
869 }
870
871 /* Open destination key */
872 if (RegCreateKeyExW(hKey, L"shell", 0, NULL, 0, KEY_WRITE, NULL, &hDestKey, NULL) != ERROR_SUCCESS)
873 {
874 ERR("RegCreateKeyExW failed\n");
875 RegCloseKey(hSrcKey);
877 return FALSE;
878 }
879
880 /* Copy static verbs from Classes\Applications key */
881 /* FIXME: SHCopyKey does not copy the security attributes of the keys */
882 /* FIXME: Windows does not actually copy the verb keys */
883 /* FIXME: Should probably delete any existing DelegateExecute/DropTarget/DDE verb information first */
884 LSTATUS Result = SHCopyKeyW(hSrcKey, NULL, hDestKey, 0);
885#ifdef __REACTOS__
886 // FIXME: When OpenWith is used to set a new default on Windows, the FileExts key
887 // is changed to force this association. ROS does not support this. The best
888 // we can do is to try to set the verb we (incorrectly) copied as the new default.
889 HKEY hAppKey;
890 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename);
891 if (Result == ERROR_SUCCESS && !RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hAppKey))
892 {
893 if (HCR_GetDefaultVerbW(hAppKey, NULL, wszBuf, _countof(wszBuf)) && *wszBuf)
894 RegSetString(hDestKey, NULL, wszBuf, REG_SZ);
895 RegCloseKey(hAppKey);
896 }
897#endif // __REACTOS__
898 RegCloseKey(hDestKey);
899 RegCloseKey(hSrcKey);
901
902 if (Result != ERROR_SUCCESS)
903 {
904 ERR("SHCopyKeyW failed\n");
905 return FALSE;
906 }
907
908 return TRUE;
909}
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
static DWORD RegSetString(HKEY hKey, LPCWSTR Name, LPCWSTR Str, DWORD Type OPTIONAL_(REG_SZ))
Definition: utils.h:81
DWORD WINAPI SHCopyKeyW(HKEY hKeySrc, LPCWSTR lpszSrcSubKey, HKEY hKeyDst, DWORD dwReserved)
Definition: reg.c:2261
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
long LONG
Definition: pedump.c:60
BOOL HCR_GetDefaultVerbW(HKEY hkeyClass, LPCWSTR szVerb, LPWSTR szDest, DWORD len)
Definition: classes.c:152
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char BYTE
Definition: xxhash.c:193

Referenced by COpenWithDialog::Accept().

◆ SetRecommended()

VOID COpenWithList::SetRecommended ( SApp pApp)
inlineprivate

Definition at line 202 of file COpenWithMenu.cpp.

203 {
204 if (!pApp->bRecommended)
206 pApp->bRecommended = TRUE;
207 }

Referenced by LoadAppList(), LoadFromProgIdKey(), LoadMRUList(), and LoadRecommendedFromHKCU().

Member Data Documentation

◆ m_bNoOpen

BOOL COpenWithList::m_bNoOpen
private

Definition at line 188 of file COpenWithMenu.cpp.

Referenced by IsNoOpen(), and LoadFromProgIdKey().

◆ m_cApp

UINT COpenWithList::m_cApp
private

Definition at line 187 of file COpenWithMenu.cpp.

Referenced by AddInternal(), Find(), GetCount(), and ~COpenWithList().

◆ m_cRecommended

UINT COpenWithList::m_cRecommended
private

Definition at line 187 of file COpenWithMenu.cpp.

Referenced by GetRecommendedCount(), and SetRecommended().

◆ m_pApp

SApp* COpenWithList::m_pApp
private

Definition at line 186 of file COpenWithMenu.cpp.

Referenced by AddInternal(), Find(), GetList(), and ~COpenWithList().


The documentation for this class was generated from the following file: