ReactOS 0.4.16-dev-927-g467dec4
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 84 of file COpenWithMenu.cpp.

Member Typedef Documentation

◆ LANGANDCODEPAGE

◆ LPLANGANDCODEPAGE

Constructor & Destructor Documentation

◆ COpenWithList()

COpenWithList::COpenWithList ( )

Definition at line 149 of file COpenWithMenu.cpp.

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

◆ ~COpenWithList()

COpenWithList::~COpenWithList ( )

Definition at line 152 of file COpenWithMenu.cpp.

153{
154 for (UINT i = 0; i < m_cApp; ++i)
155 if (m_pApp[i].hIcon)
157
159}
#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:2139

Member Function Documentation

◆ Add()

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

Definition at line 222 of file COpenWithMenu.cpp.

223{
224 SApp *pApp = AddInternal(PathFindFileNameW(pwszPath));
225
226 if (pApp)
227 {
228 StringCbPrintfW(pApp->wszCmd, sizeof(pApp->wszCmd), L"\"%s\" \"%%1\"", pwszPath);
229 SaveApp(pApp);
230 }
231
232 return pApp;
233}
static BOOL SaveApp(SApp *pApp)
SApp * AddInternal(LPCWSTR pwszFilename)
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
#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 708 of file COpenWithMenu.cpp.

709{
710 WCHAR wszBuf[100];
711 LPCWSTR pwszExt;
712 HKEY hKey;
714
715 /* Get file extension */
716 pwszExt = PathFindExtensionW(pwszFilename);
717 if (!pwszExt[0])
718 return FALSE;
719
720 /* Build registry key */
721 if (FAILED(StringCbPrintfW(wszBuf, sizeof(wszBuf),
722 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",
723 pwszExt)))
724 {
725 ERR("insufficient buffer\n");
726 return FALSE;
727 }
728
729 /* Open base key for this file extension */
731 return FALSE;
732
733 /* Open MRU list */
735 if (hList)
736 {
737 /* Insert the entry */
738 AddMRUStringW(hList, pApp->wszFilename);
739
740 /* Set MRU presence */
741 pApp->bMRUList = TRUE;
742
743 /* Close MRU list */
745 }
746
748 return TRUE;
749}
#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(LPCWSTR lpszPath)
Definition: path.c:447
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 358 of file COpenWithMenu.cpp.

359{
360 /* Check for duplicate */
361 SApp *pApp = Find(pwszFilename);
362 if (pApp)
363 return pApp;
364
365 /* Create new item */
366 if (!m_pApp)
367 m_pApp = static_cast<SApp *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(m_pApp[0])));
368 else
369 m_pApp = static_cast<SApp *>(HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, m_pApp, (m_cApp + 1)*sizeof(m_pApp[0])));
370 if (!m_pApp)
371 {
372 ERR("Allocation failed\n");
373 return NULL;
374 }
375
376 pApp = &m_pApp[m_cApp++];
377 wcscpy(pApp->wszFilename, pwszFilename);
378 return pApp;
379}
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 308 of file COpenWithMenu.cpp.

309{
310 WCHAR wszBuf[256];
311 HKEY hKey;
312
313 /* Add app to registry if it wasnt there before */
314 SaveApp(pApp);
315 if (!pApp->bMRUList)
316 AddAppToMRUList(pApp, pwszFilePath);
317
318 /* Get a handle to the reg key */
319 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename);
321 {
322 ERR("RegOpenKeyEx failed\n");
323 return FALSE;
324 }
325
326 /* Let ShellExecuteExW do the work */
328 sei.nShow = SW_SHOWNORMAL;
329 sei.hkeyClass = hKey;
330 sei.lpFile = pwszFilePath;
331
332 ShellExecuteExW(&sei);
333
334 return TRUE;
335}
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:2452
WCHAR wszFilename[MAX_PATH]
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SW_SHOWNORMAL
Definition: winuser.h:773

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

◆ Find()

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

Definition at line 254 of file COpenWithMenu.cpp.

255{
256 for (UINT i = 0; i < m_cApp; ++i)
257 if (_wcsicmp(m_pApp[i].wszFilename, pwszFilename) == 0)
258 return &m_pApp[i];
259 return NULL;
260}
_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 115 of file COpenWithMenu.cpp.

115{ return m_cApp; }

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

◆ GetIcon()

HICON COpenWithList::GetIcon ( SApp pApp)
static

Definition at line 283 of file COpenWithMenu.cpp.

284{
285 if (!pApp->hIcon)
286 {
287 WCHAR wszPath[MAX_PATH];
288
289 GetPathFromCmd(wszPath, pApp->wszCmd);
290 if (!ExtractIconExW(wszPath, 0, NULL, &pApp->hIcon, 1))
291 {
292 SHFILEINFO fi;
293 /* FIXME: Ideally we should include SHGFI_USEFILEATTRIBUTES because we already
294 ** know the file has no icons but SHGetFileInfo is broken in that case (CORE-19122).
295 ** Without SHGFI_USEFILEATTRIBUTES we needlessly hit the disk again but it will
296 ** return the correct default .exe icon.
297 */
298 SHGetFileInfoW(wszPath, 0, &fi, sizeof(fi), SHGFI_ICON|SHGFI_SMALLICON|SHGFI_SHELLICONSIZE);
299 pApp->hIcon = fi.hIcon;
300 }
301 }
302
303 TRACE("%ls icon: %p\n", pApp->wszFilename, pApp->hIcon);
304
305 return pApp->hIcon;
306}
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:165
#define SHGFI_SMALLICON
Definition: shellapi.h:177
#define SHGFI_SHELLICONSIZE
Definition: shellapi.h:180
#define TRACE(s)
Definition: solgame.cpp:4
HICON hIcon
Definition: shellapi.h:366

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

◆ GetList()

SApp * COpenWithList::GetList ( )
inline

Definition at line 114 of file COpenWithMenu.cpp.

114{ return m_pApp; }

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

◆ GetName()

LPCWSTR COpenWithList::GetName ( SApp pApp)
static

Definition at line 262 of file COpenWithMenu.cpp.

263{
264 if (!pApp->wszName[0])
265 {
266 if (!LoadInfo(pApp))
267 {
268 WARN("Failed to load %ls info\n", pApp->wszFilename);
269 StringCbCopyW(pApp->wszName, sizeof(pApp->wszName), pApp->wszFilename);
270
271 WCHAR wszPath[MAX_PATH];
272 if (!GetPathFromCmd(wszPath, pApp->wszCmd))
273 {
274 return NULL;
275 }
276 }
277 }
278
279 TRACE("%ls name: %ls\n", pApp->wszFilename, pApp->wszName);
280 return pApp->wszName;
281}
#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 447 of file COpenWithMenu.cpp.

448{
449 WCHAR wszBuf[MAX_PATH];
450
451 /* Remove arguments */
452 if (!PathGetAppFromCommandLine(pwszCmd, wszBuf, _countof(wszBuf)))
453 return FALSE;
454
455 /* Replace rundll32.exe with the dll path */
456 SHELL32_GetDllFromRundll32CommandLine(pwszCmd, wszBuf, _countof(wszBuf));
457
458 /* Expand env. vars and optionally search for path */
459 ExpandEnvironmentStrings(wszBuf, pwszAppPath, MAX_PATH);
460 if (!PathFileExists(pwszAppPath))
461 {
462 UINT cch = SearchPathW(NULL, pwszAppPath, NULL, MAX_PATH, pwszAppPath, NULL);
463 if (!cch || cch >= MAX_PATH)
464 return FALSE;
465 }
466 return TRUE;
467}
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:934
#define _countof(array)
Definition: sndvol32.h:70
#define ExpandEnvironmentStrings
Definition: winbase.h:3805

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

◆ GetRecommendedCount()

UINT COpenWithList::GetRecommendedCount ( )
inline

Definition at line 116 of file COpenWithMenu.cpp.

116{ return m_cRecommended; }

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

◆ IsHidden()

BOOL COpenWithList::IsHidden ( SApp pApp)
static

Definition at line 337 of file COpenWithMenu.cpp.

338{
339 WCHAR wszBuf[100];
340 DWORD dwSize = 0;
341
342 if (pApp->bHidden)
343 return pApp->bHidden;
344
345 if (FAILED(StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename)))
346 {
347 ERR("insufficient buffer\n");
348 return FALSE;
349 }
350
351 if (RegGetValueW(HKEY_CLASSES_ROOT, wszBuf, L"NoOpenWith", RRF_RT_REG_SZ, NULL, NULL, &dwSize) != ERROR_SUCCESS)
352 return FALSE;
353
354 pApp->bHidden = TRUE;
355 return TRUE;
356}
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 110 of file COpenWithMenu.cpp.

110{ return m_bNoOpen; }

Referenced by COpenWithDialog::Init().

◆ Load()

BOOL COpenWithList::Load ( )

Definition at line 161 of file COpenWithMenu.cpp.

162{
163 HKEY hKey, hKeyApp;
164 WCHAR wszName[256], wszBuf[100];
165 DWORD i = 0, cchName, dwSize;
166 SApp *pApp;
167
168 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"Applications", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
169 {
170 ERR("RegOpenKeyEx HKCR\\Applications failed!\n");
171 return FALSE;
172 }
173
174 while (TRUE)
175 {
176 cchName = _countof(wszName);
177 if (RegEnumKeyEx(hKey, i++, wszName, &cchName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
178 break;
179
180 pApp = AddInternal(wszName);
181
182 if (pApp)
183 {
184 if (RegOpenKeyW(hKey, wszName, &hKeyApp) == ERROR_SUCCESS)
185 {
186 if ((RegQueryValueExW(hKeyApp, L"NoOpenWith", NULL, NULL, NULL, NULL) != ERROR_SUCCESS) &&
187 (RegQueryValueExW(hKeyApp, L"NoStartPage", NULL, NULL, NULL, NULL) != ERROR_SUCCESS))
188 {
189 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\shell\\open\\command", wszName);
190 dwSize = sizeof(pApp->wszCmd);
191 if (RegGetValueW(hKey, wszBuf, L"", RRF_RT_REG_SZ, NULL, pApp->wszCmd, &dwSize) != ERROR_SUCCESS)
192 {
193 ERR("Failed to add app %ls\n", wszName);
194 pApp->bHidden = TRUE;
195 }
196 else
197 {
198 TRACE("App added %ls\n", pApp->wszCmd);
199 }
200 }
201 else
202 {
203 pApp->bHidden = TRUE;
204 }
205 RegCloseKey(hKeyApp);
206 }
207 else
208 {
209 pApp->bHidden = TRUE;
210 }
211 }
212 else
213 {
214 ERR("AddInternal failed\n");
215 }
216 }
217
219 return TRUE;
220}
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:2798
#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 568 of file COpenWithMenu.cpp.

569{
570 WCHAR wszAppFilename[MAX_PATH];
571 HKEY hSubkey;
572 DWORD i = 0, cchAppFilename;
573
574 if (RegOpenKeyExW(hKey, L"OpenWithList", 0, KEY_READ, &hSubkey) != ERROR_SUCCESS)
575 return FALSE;
576
577 while (TRUE)
578 {
579 /* Enum registry keys - each of them is app name */
580 cchAppFilename = _countof(wszAppFilename);
581 if (RegEnumKeyExW(hSubkey, i++, wszAppFilename, &cchAppFilename, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
582 break;
583
584 /* Set application as recommended */
585 SApp *pApp = Find(wszAppFilename);
586
587 TRACE("Recommended app %ls: %p\n", wszAppFilename, pApp);
588 if (pApp)
589 SetRecommended(pApp);
590 }
591
592 RegCloseKey(hSubkey);
593 return TRUE;
594}
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 596 of file COpenWithMenu.cpp.

597{
598 WCHAR wszCmd[MAX_PATH], wszPath[MAX_PATH];
599 DWORD dwSize = 0;
600
601 /* Check if NoOpen value exists */
603 {
604 /* Display warning dialog */
605 m_bNoOpen = TRUE;
606 }
607
608 /* Check if there is a directly available execute key */
609 dwSize = sizeof(wszCmd);
610 if (RegGetValueW(hKey, L"shell\\open\\command", NULL, RRF_RT_REG_SZ, NULL, (PVOID)wszCmd, &dwSize) == ERROR_SUCCESS)
611 {
612 /* Erase extra arguments */
613 GetPathFromCmd(wszPath, wszCmd);
614
615 /* Add application */
616 SApp *pApp = AddInternal(PathFindFileNameW(wszPath));
617 TRACE("Add app %ls: %p\n", wszPath, pApp);
618
619 if (pApp)
620 {
621 StringCbCopyW(pApp->wszCmd, sizeof(pApp->wszCmd), wszCmd);
622 SetRecommended(pApp);
623 }
624 }
625}

Referenced by LoadProgIdList(), and LoadRecommendedFromHKCR().

◆ LoadInfo()

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

Definition at line 381 of file COpenWithMenu.cpp.

382{
383 UINT cbSize, cchLen;
384 LPVOID pBuf;
385 WORD wLang = 0, wCode = 0;
386 LPLANGANDCODEPAGE lpLangCode;
387 WCHAR wszBuf[100];
388 WCHAR *pResult;
389 WCHAR wszPath[MAX_PATH];
391
392 GetPathFromCmd(wszPath, pApp->wszCmd);
393 TRACE("LoadInfo %ls\n", wszPath);
394
395 /* query version info size */
396 cbSize = GetFileVersionInfoSizeW(wszPath, NULL);
397 if (!cbSize)
398 {
399 ERR("GetFileVersionInfoSizeW %ls failed: %lu\n", wszPath, GetLastError());
400 return FALSE;
401 }
402
403 /* allocate buffer */
404 pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbSize + 200);
405 if (!pBuf)
406 {
407 ERR("HeapAlloc failed\n");
408 return FALSE;
409 }
410
411 /* query version info */
412 if (!GetFileVersionInfoW(wszPath, 0, cbSize, pBuf))
413 {
414 ERR("GetFileVersionInfoW %ls failed: %lu\n", wszPath, GetLastError());
415 HeapFree(GetProcessHeap(), 0, pBuf);
416 return FALSE;
417 }
418
419 /* query lang code */
420 if (VerQueryValueW(pBuf, L"VarFileInfo\\Translation", (LPVOID*)&lpLangCode, &cbSize))
421 {
422 /* FIXME: find language from current locale / if not available,
423 * default to english
424 * for now default to first available language
425 */
426 wLang = lpLangCode->lang;
427 wCode = lpLangCode->code;
428 }
429
430 /* Query name */
431 swprintf(wszBuf, L"\\StringFileInfo\\%04x%04x\\FileDescription", wLang, wCode);
432 success = VerQueryValueW(pBuf, wszBuf, (LPVOID *)&pResult, &cchLen) && (cchLen > 1);
433 if (success)
434 StringCchCopyNW(pApp->wszName, _countof(pApp->wszName), pResult, cchLen);
435 else
436 ERR("Cannot get app name\n");
437
438 /* Query manufacturer */
439 /*swprintf(wszBuf, L"\\StringFileInfo\\%04x%04x\\CompanyName", wLang, wCode);
440
441 if (VerQueryValueW(pBuf, wszBuf, (LPVOID *)&pResult, &cchLen))
442 StringCchCopyNW(pApp->wszManufacturer, _countof(pApp->wszManufacturer), pResult, cchLen);*/
443 HeapFree(GetProcessHeap(), 0, pBuf);
444 return success;
445}
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:845
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1057
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:611
#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 529 of file COpenWithMenu.cpp.

530{
532 int nItem, nCount, nResult;
533 WCHAR wszAppFilename[MAX_PATH];
534
535 /* Open MRU list */
537 if (!hList)
538 {
539 TRACE("OpenMRUList failed\n");
540 return FALSE;
541 }
542
543 /* Get list count */
544 nCount = EnumMRUListW(hList, -1, NULL, 0);
545
546 for(nItem = 0; nItem < nCount; nItem++)
547 {
548 nResult = EnumMRUListW(hList, nItem, wszAppFilename, _countof(wszAppFilename));
549 if (nResult <= 0)
550 continue;
551
552 /* Insert item */
553 SApp *pApp = Find(wszAppFilename);
554
555 TRACE("Recommended app %ls: %p\n", wszAppFilename, pApp);
556 if (pApp)
557 {
558 pApp->bMRUList = TRUE;
559 SetRecommended(pApp);
560 }
561 }
562
563 /* Free the MRU list */
565 return TRUE;
566}
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 486 of file COpenWithMenu.cpp.

487{
488 HKEY hSubkey, hSubkey2;
489 WCHAR wszProgId[256];
490 DWORD i = 0, cchProgId;
491
492 if (RegOpenKeyExW(hKey, L"OpenWithProgIDs", 0, KEY_READ, &hSubkey) != ERROR_SUCCESS)
493 return FALSE;
494
495 while (TRUE)
496 {
497 /* Enumerate values - value name is ProgId */
498 cchProgId = _countof(wszProgId);
499 if (RegEnumValue(hSubkey, i++, wszProgId, &cchProgId, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
500 break;
501
502 /* If ProgId exists load it */
503 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszProgId, 0, KEY_READ, &hSubkey2) == ERROR_SUCCESS)
504 {
505 LoadFromProgIdKey(hSubkey2, pwszExt);
506 RegCloseKey(hSubkey2);
507 }
508 }
509
510 RegCloseKey(hSubkey);
511 return TRUE;
512}
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 469 of file COpenWithMenu.cpp.

470{
471 LPCWSTR pwszExt;
472
473 pwszExt = PathFindExtensionW(pwszFilePath);
474 if (!pwszExt[0])
475 return FALSE;
476
477 /* load programs directly associated from HKCU */
479
480 /* load programs associated from HKCR\Extension */
482
483 return TRUE;
484}
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 627 of file COpenWithMenu.cpp.

628{
629 HKEY hKey, hSubkey;
630 WCHAR wszBuf[MAX_PATH], wszBuf2[MAX_PATH];
632
633 /* Check if extension exists */
635 {
636 /* Load items from SystemFileAssociations\Ext key */
637 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"SystemFileAssociations\\%s", pwszExt);
639 return;
640 }
641
642 /* Load programs referenced from HKCR\ProgId */
643 dwSize = sizeof(wszBuf);
644 if (RegGetValueW(hKey, NULL, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS &&
645 RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hSubkey) == ERROR_SUCCESS)
646 {
647 LoadFromProgIdKey(hSubkey, pwszExt);
648 RegCloseKey(hSubkey);
649 }
650 else
651 LoadFromProgIdKey(hKey, pwszExt);
652
653 /* Load items from HKCR\Ext\OpenWithList */
655
656 /* Load items from HKCR\Ext\OpenWithProgIDs */
657 if (RegOpenKeyExW(hKey, L"OpenWithProgIDs", 0, KEY_READ, &hSubkey) == ERROR_SUCCESS)
658 {
659 LoadProgIdList(hSubkey, pwszExt);
660 RegCloseKey(hSubkey);
661 }
662
663 /* Load additional items from referenced PerceivedType */
664 dwSize = sizeof(wszBuf);
665 if (RegGetValueW(hKey, NULL, L"PerceivedType", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS)
666 {
667 StringCbPrintfW(wszBuf2, sizeof(wszBuf2), L"SystemFileAssociations\\%s", wszBuf);
668 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf2, 0, KEY_READ | KEY_WRITE, &hSubkey) == ERROR_SUCCESS)
669 {
670 /* Load from OpenWithList key */
671 LoadAppList(hSubkey);
672 RegCloseKey(hSubkey);
673 }
674 }
675
676 /* Close the key */
678}
BOOL LoadAppList(HKEY hKey)
BOOL LoadProgIdList(HKEY hKey, LPCWSTR pwszExt)

Referenced by LoadRecommended().

◆ LoadRecommendedFromHKCU()

VOID COpenWithList::LoadRecommendedFromHKCU ( LPCWSTR  pwszExt)
private

Definition at line 680 of file COpenWithMenu.cpp.

681{
682 WCHAR wszBuf[MAX_PATH];
683 HKEY hKey;
684
685 StringCbPrintfW(wszBuf, sizeof(wszBuf),
686 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",
687 pwszExt);
689 {
690 /* Load MRU and ProgId lists */
692 LoadProgIdList(hKey, pwszExt);
693
694 /* Handle "Application" value */
695 DWORD cbBuf = sizeof(wszBuf);
696 if (RegGetValueW(hKey, NULL, L"Application", RRF_RT_REG_SZ, NULL, wszBuf, &cbBuf) == ERROR_SUCCESS)
697 {
698 SApp *pApp = Find(wszBuf);
699 if (pApp)
700 SetRecommended(pApp);
701 }
702
703 /* Close the key */
705 }
706}
BOOL LoadMRUList(HKEY hKey)

Referenced by LoadRecommended().

◆ OpenMRUList()

HANDLE COpenWithList::OpenMRUList ( HKEY  hKey)
staticprivate

Definition at line 514 of file COpenWithMenu.cpp.

515{
517
518 /* Initialize mru list info */
519 Info.cbSize = sizeof(Info);
520 Info.uMax = 32;
521 Info.fFlags = MRU_STRING;
522 Info.hKey = hKey;
523 Info.lpszSubKey = L"OpenWithList";
524 Info.lpfnCompare = NULL;
525
526 return CreateMRUListW(&Info);
527}
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 235 of file COpenWithMenu.cpp.

236{
237 WCHAR wszBuf[256];
238 HKEY hKey;
239
240 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s\\shell\\open\\command", pApp->wszFilename);
242 {
243 ERR("RegOpenKeyEx failed\n");
244 return FALSE;
245 }
246
247 if (RegSetValueEx(hKey, L"", 0, REG_SZ, (PBYTE)pApp->wszCmd, (wcslen(pApp->wszCmd)+1)*sizeof(WCHAR)) != ERROR_SUCCESS)
248 ERR("Cannot add app to registry\n");
249
251 return TRUE;
252}
_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 751 of file COpenWithMenu.cpp.

752{
753 HKEY hKey, hSrcKey, hDestKey;
754 WCHAR wszBuf[256];
755
756 TRACE("SetDefaultHandler %ls %ls\n", pApp->wszFilename, pwszFilename);
757
758 /* Extract file extension */
759 LPCWSTR pwszExt = PathFindExtensionW(pwszFilename);
760 if (!pwszExt[0] || !pwszExt[1])
761 return FALSE;
762
763 /* Create file extension key */
765 {
766 ERR("Can't open ext key\n");
767 return FALSE;
768 }
769
770 DWORD dwSize = sizeof(wszBuf);
771 LONG lResult = RegGetValueW(hKey, NULL, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize);
772
773 if (lResult == ERROR_FILE_NOT_FOUND)
774 {
775 /* A new entry was created or the default key is not set: set the prog key id */
776 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s_auto_file", pwszExt + 1);
777 if (RegSetValueExW(hKey, L"", 0, REG_SZ, (const BYTE*)wszBuf, (wcslen(wszBuf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
778 {
780 ERR("RegSetValueExW failed\n");
781 return FALSE;
782 }
783 }
784 else if (lResult != ERROR_SUCCESS)
785 {
787 ERR("RegGetValueExW failed: 0x%08x\n", lResult);
788 return FALSE;
789 }
790
791 /* Close file extension key */
793
794 /* Create prog id key */
796 {
797 ERR("RegCreateKeyExW failed\n");
798 return FALSE;
799 }
800
801 /* Check if there already verbs existing for that app */
802 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s\\shell", pApp->wszFilename);
803 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hSrcKey) != ERROR_SUCCESS)
804 {
805 ERR("RegOpenKeyExW %ls failed\n", wszBuf);
807 return FALSE;
808 }
809
810 /* Open destination key */
811 if (RegCreateKeyExW(hKey, L"shell", 0, NULL, 0, KEY_WRITE, NULL, &hDestKey, NULL) != ERROR_SUCCESS)
812 {
813 ERR("RegCreateKeyExW failed\n");
814 RegCloseKey(hSrcKey);
816 return FALSE;
817 }
818
819 /* Copy static verbs from Classes\Applications key */
820 /* FIXME: SHCopyKey does not copy the security attributes of the keys */
821 /* FIXME: Windows does not actually copy the verb keys */
822 /* FIXME: Should probably delete any existing DelegateExecute/DropTarget/DDE verb information first */
823 LSTATUS Result = SHCopyKeyW(hSrcKey, NULL, hDestKey, 0);
824#ifdef __REACTOS__
825 // FIXME: When OpenWith is used to set a new default on Windows, the FileExts key
826 // is changed to force this association. ROS does not support this. The best
827 // we can do is to try to set the verb we (incorrectly) copied as the new default.
828 HKEY hAppKey;
829 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename);
830 if (Result == ERROR_SUCCESS && !RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hAppKey))
831 {
832 if (HCR_GetDefaultVerbW(hAppKey, NULL, wszBuf, _countof(wszBuf)) && *wszBuf)
833 RegSetString(hDestKey, NULL, wszBuf, REG_SZ);
834 RegCloseKey(hAppKey);
835 }
836#endif // __REACTOS__
837 RegCloseKey(hDestKey);
838 RegCloseKey(hSrcKey);
840
841 if (Result != ERROR_SUCCESS)
842 {
843 ERR("SHCopyKeyW failed\n");
844 return FALSE;
845 }
846
847 return TRUE;
848}
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=REG_SZ)
Definition: utils.h:59
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 141 of file COpenWithMenu.cpp.

142 {
143 if (!pApp->bRecommended)
145 pApp->bRecommended = TRUE;
146 }

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

Member Data Documentation

◆ m_bNoOpen

BOOL COpenWithList::m_bNoOpen
private

Definition at line 127 of file COpenWithMenu.cpp.

Referenced by IsNoOpen(), and LoadFromProgIdKey().

◆ m_cApp

UINT COpenWithList::m_cApp
private

Definition at line 126 of file COpenWithMenu.cpp.

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

◆ m_cRecommended

UINT COpenWithList::m_cRecommended
private

Definition at line 126 of file COpenWithMenu.cpp.

Referenced by GetRecommendedCount(), and SetRecommended().

◆ m_pApp

SApp* COpenWithList::m_pApp
private

Definition at line 125 of file COpenWithMenu.cpp.

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


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