ReactOS 0.4.15-dev-8219-ge8b88cf
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 34 of file COpenWithMenu.cpp.

Member Typedef Documentation

◆ LANGANDCODEPAGE

◆ LPLANGANDCODEPAGE

Constructor & Destructor Documentation

◆ COpenWithList()

COpenWithList::COpenWithList ( )

Definition at line 99 of file COpenWithMenu.cpp.

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

◆ ~COpenWithList()

COpenWithList::~COpenWithList ( )

Definition at line 102 of file COpenWithMenu.cpp.

103{
104 for (UINT i = 0; i < m_cApp; ++i)
105 if (m_pApp[i].hIcon)
107
109}
#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:2084

Member Function Documentation

◆ Add()

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

Definition at line 172 of file COpenWithMenu.cpp.

173{
174 SApp *pApp = AddInternal(PathFindFileNameW(pwszPath));
175
176 if (pApp)
177 {
178 StringCbPrintfW(pApp->wszCmd, sizeof(pApp->wszCmd), L"\"%s\" \"%%1\"", pwszPath);
179 SaveApp(pApp);
180 }
181
182 return pApp;
183}
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 661 of file COpenWithMenu.cpp.

662{
663 WCHAR wszBuf[100];
664 LPCWSTR pwszExt;
665 HKEY hKey;
667
668 /* Get file extension */
669 pwszExt = PathFindExtensionW(pwszFilename);
670 if (!pwszExt[0])
671 return FALSE;
672
673 /* Build registry key */
674 if (FAILED(StringCbPrintfW(wszBuf, sizeof(wszBuf),
675 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",
676 pwszExt)))
677 {
678 ERR("insufficient buffer\n");
679 return FALSE;
680 }
681
682 /* Open base key for this file extension */
684 return FALSE;
685
686 /* Open MRU list */
688 if (hList)
689 {
690 /* Insert the entry */
691 AddMRUStringW(hList, pApp->wszFilename);
692
693 /* Set MRU presence */
694 pApp->bMRUList = TRUE;
695
696 /* Close MRU list */
698 }
699
701 return TRUE;
702}
#define ERR(fmt,...)
Definition: debug.h:113
#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 308 of file COpenWithMenu.cpp.

309{
310 /* Check for duplicate */
311 SApp *pApp = Find(pwszFilename);
312 if (pApp)
313 return pApp;
314
315 /* Create new item */
316 if (!m_pApp)
317 m_pApp = static_cast<SApp *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(m_pApp[0])));
318 else
319 m_pApp = static_cast<SApp *>(HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, m_pApp, (m_cApp + 1)*sizeof(m_pApp[0])));
320 if (!m_pApp)
321 {
322 ERR("Allocation failed\n");
323 return NULL;
324 }
325
326 pApp = &m_pApp[m_cApp++];
327 wcscpy(pApp->wszFilename, pwszFilename);
328 return pApp;
329}
SApp * Find(LPCWSTR pwszFilename)
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

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

◆ Execute()

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

Definition at line 258 of file COpenWithMenu.cpp.

259{
260 WCHAR wszBuf[256];
261 HKEY hKey;
262
263 /* Add app to registry if it wasnt there before */
264 SaveApp(pApp);
265 if (!pApp->bMRUList)
266 AddAppToMRUList(pApp, pwszFilePath);
267
268 /* Get a handle to the reg key */
269 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename);
271 {
272 ERR("RegOpenKeyEx failed\n");
273 return FALSE;
274 }
275
276 /* Let ShellExecuteExW do the work */
278 sei.nShow = SW_SHOWNORMAL;
279 sei.hkeyClass = hKey;
280 sei.lpFile = pwszFilePath;
281
282 ShellExecuteExW(&sei);
283
284 return TRUE;
285}
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:2428
WCHAR wszFilename[MAX_PATH]
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define SW_SHOWNORMAL
Definition: winuser.h:770

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

◆ Find()

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

Definition at line 204 of file COpenWithMenu.cpp.

205{
206 for (UINT i = 0; i < m_cApp; ++i)
207 if (wcsicmp(m_pApp[i].wszFilename, pwszFilename) == 0)
208 return &m_pApp[i];
209 return NULL;
210}
#define wcsicmp
Definition: compat.h:15

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

◆ GetCount()

UINT COpenWithList::GetCount ( )
inline

Definition at line 65 of file COpenWithMenu.cpp.

65{ return m_cApp; }

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

◆ GetIcon()

HICON COpenWithList::GetIcon ( SApp pApp)
static

Definition at line 233 of file COpenWithMenu.cpp.

234{
235 if (!pApp->hIcon)
236 {
237 WCHAR wszPath[MAX_PATH];
238
239 GetPathFromCmd(wszPath, pApp->wszCmd);
240 if (!ExtractIconExW(wszPath, 0, NULL, &pApp->hIcon, 1))
241 {
242 SHFILEINFO fi;
243 /* FIXME: Ideally we should include SHGFI_USEFILEATTRIBUTES because we already
244 ** know the file has no icons but SHGetFileInfo is broken in that case (CORE-19122).
245 ** Without SHGFI_USEFILEATTRIBUTES we needlessly hit the disk again but it will
246 ** return the correct default .exe icon.
247 */
248 SHGetFileInfoW(wszPath, 0, &fi, sizeof(fi), SHGFI_ICON|SHGFI_SMALLICON|SHGFI_SHELLICONSIZE);
249 pApp->hIcon = fi.hIcon;
250 }
251 }
252
253 TRACE("%ls icon: %p\n", pApp->wszFilename, pApp->hIcon);
254
255 return pApp->hIcon;
256}
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:849
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:415
#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:365

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

◆ GetList()

SApp * COpenWithList::GetList ( )
inline

Definition at line 64 of file COpenWithMenu.cpp.

64{ return m_pApp; }

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

◆ GetName()

LPCWSTR COpenWithList::GetName ( SApp pApp)
static

Definition at line 212 of file COpenWithMenu.cpp.

213{
214 if (!pApp->wszName[0])
215 {
216 if (!LoadInfo(pApp))
217 {
218 WARN("Failed to load %ls info\n", pApp->wszFilename);
219 StringCbCopyW(pApp->wszName, sizeof(pApp->wszName), pApp->wszFilename);
220
221 WCHAR wszPath[MAX_PATH];
222 if (!GetPathFromCmd(wszPath, pApp->wszCmd))
223 {
224 return NULL;
225 }
226 }
227 }
228
229 TRACE("%ls name: %ls\n", pApp->wszFilename, pApp->wszName);
230 return pApp->wszName;
231}
#define WARN(fmt,...)
Definition: debug.h:115
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 397 of file COpenWithMenu.cpp.

398{
399 WCHAR wszBuf[MAX_PATH], *pwszDest = wszBuf;
400
401 /* Remove arguments */
402 if (pwszCmd[0] == '"')
403 {
404 for(LPCWSTR pwszSrc = pwszCmd + 1; *pwszSrc && *pwszSrc != '"'; ++pwszSrc)
405 *(pwszDest++) = *pwszSrc;
406 }
407 else
408 {
409 for(LPCWSTR pwszSrc = pwszCmd; *pwszSrc && *pwszSrc != ' '; ++pwszSrc)
410 *(pwszDest++) = *pwszSrc;
411 }
412
413 *pwszDest = 0;
414
415 /* Expand evn vers and optionally search for path */
416 ExpandEnvironmentStrings(wszBuf, pwszAppPath, MAX_PATH);
417 if (!PathFileExists(pwszAppPath))
418 return SearchPath(NULL, pwszAppPath, NULL, MAX_PATH, pwszAppPath, NULL);
419 return TRUE;
420}
#define PathFileExists
Definition: shlwapi.h:899
#define ExpandEnvironmentStrings
Definition: winbase.h:3774
#define SearchPath
Definition: winbase.h:3900

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

◆ GetRecommendedCount()

UINT COpenWithList::GetRecommendedCount ( )
inline

Definition at line 66 of file COpenWithMenu.cpp.

66{ return m_cRecommended; }

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

◆ IsHidden()

BOOL COpenWithList::IsHidden ( SApp pApp)
static

Definition at line 287 of file COpenWithMenu.cpp.

288{
289 WCHAR wszBuf[100];
290 DWORD dwSize = 0;
291
292 if (pApp->bHidden)
293 return pApp->bHidden;
294
295 if (FAILED(StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s", pApp->wszFilename)))
296 {
297 ERR("insufficient buffer\n");
298 return FALSE;
299 }
300
301 if (RegGetValueW(HKEY_CLASSES_ROOT, wszBuf, L"NoOpenWith", RRF_RT_REG_SZ, NULL, NULL, &dwSize) != ERROR_SUCCESS)
302 return FALSE;
303
304 pApp->bHidden = TRUE;
305 return TRUE;
306}
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 60 of file COpenWithMenu.cpp.

60{ return m_bNoOpen; }

Referenced by COpenWithDialog::Init().

◆ Load()

BOOL COpenWithList::Load ( )

Definition at line 111 of file COpenWithMenu.cpp.

112{
113 HKEY hKey, hKeyApp;
114 WCHAR wszName[256], wszBuf[100];
115 DWORD i = 0, cchName, dwSize;
116 SApp *pApp;
117
118 if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"Applications", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
119 {
120 ERR("RegOpenKeyEx HKCR\\Applications failed!\n");
121 return FALSE;
122 }
123
124 while (TRUE)
125 {
126 cchName = _countof(wszName);
127 if (RegEnumKeyEx(hKey, i++, wszName, &cchName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
128 break;
129
130 pApp = AddInternal(wszName);
131
132 if (pApp)
133 {
134 if (RegOpenKeyW(hKey, wszName, &hKeyApp) == ERROR_SUCCESS)
135 {
136 if ((RegQueryValueExW(hKeyApp, L"NoOpenWith", NULL, NULL, NULL, NULL) != ERROR_SUCCESS) &&
137 (RegQueryValueExW(hKeyApp, L"NoStartPage", NULL, NULL, NULL, NULL) != ERROR_SUCCESS))
138 {
139 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s\\shell\\open\\command", wszName);
140 dwSize = sizeof(pApp->wszCmd);
141 if (RegGetValueW(hKey, wszBuf, L"", RRF_RT_REG_SZ, NULL, pApp->wszCmd, &dwSize) != ERROR_SUCCESS)
142 {
143 ERR("Failed to add app %ls\n", wszName);
144 pApp->bHidden = TRUE;
145 }
146 else
147 {
148 TRACE("App added %ls\n", pApp->wszCmd);
149 }
150 }
151 else
152 {
153 pApp->bHidden = TRUE;
154 }
155 RegCloseKey(hKeyApp);
156 }
157 else
158 {
159 pApp->bHidden = TRUE;
160 }
161 }
162 else
163 {
164 ERR("AddInternal failed\n");
165 }
166 }
167
169 return TRUE;
170}
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
#define _countof(array)
Definition: sndvol32.h:70
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2767
#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 521 of file COpenWithMenu.cpp.

522{
523 WCHAR wszAppFilename[MAX_PATH];
524 HKEY hSubkey;
525 DWORD i = 0, cchAppFilename;
526
527 if (RegOpenKeyExW(hKey, L"OpenWithList", 0, KEY_READ, &hSubkey) != ERROR_SUCCESS)
528 return FALSE;
529
530 while (TRUE)
531 {
532 /* Enum registry keys - each of them is app name */
533 cchAppFilename = _countof(wszAppFilename);
534 if (RegEnumKeyExW(hSubkey, i++, wszAppFilename, &cchAppFilename, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
535 break;
536
537 /* Set application as recommended */
538 SApp *pApp = Find(wszAppFilename);
539
540 TRACE("Recommended app %ls: %p\n", wszAppFilename, pApp);
541 if (pApp)
542 SetRecommended(pApp);
543 }
544
545 RegCloseKey(hSubkey);
546 return TRUE;
547}
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 549 of file COpenWithMenu.cpp.

550{
551 WCHAR wszCmd[MAX_PATH], wszPath[MAX_PATH];
552 DWORD dwSize = 0;
553
554 /* Check if NoOpen value exists */
556 {
557 /* Display warning dialog */
558 m_bNoOpen = TRUE;
559 }
560
561 /* Check if there is a directly available execute key */
562 dwSize = sizeof(wszCmd);
563 if (RegGetValueW(hKey, L"shell\\open\\command", NULL, RRF_RT_REG_SZ, NULL, (PVOID)wszCmd, &dwSize) == ERROR_SUCCESS)
564 {
565 /* Erase extra arguments */
566 GetPathFromCmd(wszPath, wszCmd);
567
568 /* Add application */
569 SApp *pApp = AddInternal(PathFindFileNameW(wszPath));
570 TRACE("Add app %ls: %p\n", wszPath, pApp);
571
572 if (pApp)
573 {
574 StringCbCopyW(pApp->wszCmd, sizeof(pApp->wszCmd), wszCmd);
575 SetRecommended(pApp);
576 }
577 }
578}

Referenced by LoadProgIdList(), and LoadRecommendedFromHKCR().

◆ LoadInfo()

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

Definition at line 331 of file COpenWithMenu.cpp.

332{
333 UINT cbSize, cchLen;
334 LPVOID pBuf;
335 WORD wLang = 0, wCode = 0;
336 LPLANGANDCODEPAGE lpLangCode;
337 WCHAR wszBuf[100];
338 WCHAR *pResult;
339 WCHAR wszPath[MAX_PATH];
341
342 GetPathFromCmd(wszPath, pApp->wszCmd);
343 TRACE("LoadInfo %ls\n", wszPath);
344
345 /* query version info size */
346 cbSize = GetFileVersionInfoSizeW(wszPath, NULL);
347 if (!cbSize)
348 {
349 ERR("GetFileVersionInfoSizeW %ls failed: %lu\n", wszPath, GetLastError());
350 return FALSE;
351 }
352
353 /* allocate buffer */
354 pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbSize + 200);
355 if (!pBuf)
356 {
357 ERR("HeapAlloc failed\n");
358 return FALSE;
359 }
360
361 /* query version info */
362 if (!GetFileVersionInfoW(wszPath, 0, cbSize, pBuf))
363 {
364 ERR("GetFileVersionInfoW %ls failed: %lu\n", wszPath, GetLastError());
365 HeapFree(GetProcessHeap(), 0, pBuf);
366 return FALSE;
367 }
368
369 /* query lang code */
370 if (VerQueryValueW(pBuf, L"VarFileInfo\\Translation", (LPVOID*)&lpLangCode, &cbSize))
371 {
372 /* FIXME: find language from current locale / if not available,
373 * default to english
374 * for now default to first available language
375 */
376 wLang = lpLangCode->lang;
377 wCode = lpLangCode->code;
378 }
379
380 /* Query name */
381 swprintf(wszBuf, L"\\StringFileInfo\\%04x%04x\\FileDescription", wLang, wCode);
382 success = VerQueryValueW(pBuf, wszBuf, (LPVOID *)&pResult, &cchLen) && (cchLen > 1);
383 if (success)
384 StringCchCopyNW(pApp->wszName, _countof(pApp->wszName), pResult, cchLen);
385 else
386 ERR("Cannot get app name\n");
387
388 /* Query manufacturer */
389 /*swprintf(wszBuf, L"\\StringFileInfo\\%04x%04x\\CompanyName", wLang, wCode);
390
391 if (VerQueryValueW(pBuf, wszBuf, (LPVOID *)&pResult, &cchLen))
392 StringCchCopyNW(pApp->wszManufacturer, _countof(pApp->wszManufacturer), pResult, cchLen);*/
393 HeapFree(GetProcessHeap(), 0, pBuf);
394 return success;
395}
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:1049
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 482 of file COpenWithMenu.cpp.

483{
485 int nItem, nCount, nResult;
486 WCHAR wszAppFilename[MAX_PATH];
487
488 /* Open MRU list */
490 if (!hList)
491 {
492 TRACE("OpenMRUList failed\n");
493 return FALSE;
494 }
495
496 /* Get list count */
497 nCount = EnumMRUListW(hList, -1, NULL, 0);
498
499 for(nItem = 0; nItem < nCount; nItem++)
500 {
501 nResult = EnumMRUListW(hList, nItem, wszAppFilename, _countof(wszAppFilename));
502 if (nResult <= 0)
503 continue;
504
505 /* Insert item */
506 SApp *pApp = Find(wszAppFilename);
507
508 TRACE("Recommended app %ls: %p\n", wszAppFilename, pApp);
509 if (pApp)
510 {
511 pApp->bMRUList = TRUE;
512 SetRecommended(pApp);
513 }
514 }
515
516 /* Free the MRU list */
518 return TRUE;
519}
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 439 of file COpenWithMenu.cpp.

440{
441 HKEY hSubkey, hSubkey2;
442 WCHAR wszProgId[256];
443 DWORD i = 0, cchProgId;
444
445 if (RegOpenKeyExW(hKey, L"OpenWithProgIDs", 0, KEY_READ, &hSubkey) != ERROR_SUCCESS)
446 return FALSE;
447
448 while (TRUE)
449 {
450 /* Enumerate values - value name is ProgId */
451 cchProgId = _countof(wszProgId);
452 if (RegEnumValue(hSubkey, i++, wszProgId, &cchProgId, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
453 break;
454
455 /* If ProgId exists load it */
456 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszProgId, 0, KEY_READ, &hSubkey2) == ERROR_SUCCESS)
457 {
458 LoadFromProgIdKey(hSubkey2, pwszExt);
459 RegCloseKey(hSubkey2);
460 }
461 }
462
463 RegCloseKey(hSubkey);
464 return TRUE;
465}
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 422 of file COpenWithMenu.cpp.

423{
424 LPCWSTR pwszExt;
425
426 pwszExt = PathFindExtensionW(pwszFilePath);
427 if (!pwszExt[0])
428 return FALSE;
429
430 /* load programs directly associated from HKCU */
432
433 /* load programs associated from HKCR\Extension */
435
436 return TRUE;
437}
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 580 of file COpenWithMenu.cpp.

581{
582 HKEY hKey, hSubkey;
583 WCHAR wszBuf[MAX_PATH], wszBuf2[MAX_PATH];
585
586 /* Check if extension exists */
588 {
589 /* Load items from SystemFileAssociations\Ext key */
590 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"SystemFileAssociations\\%s", pwszExt);
592 return;
593 }
594
595 /* Load programs referenced from HKCR\ProgId */
596 dwSize = sizeof(wszBuf);
597 if (RegGetValueW(hKey, NULL, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS &&
598 RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hSubkey) == ERROR_SUCCESS)
599 {
600 LoadFromProgIdKey(hSubkey, pwszExt);
601 RegCloseKey(hSubkey);
602 }
603 else
604 LoadFromProgIdKey(hKey, pwszExt);
605
606 /* Load items from HKCR\Ext\OpenWithList */
608
609 /* Load items from HKCR\Ext\OpenWithProgIDs */
610 if (RegOpenKeyExW(hKey, L"OpenWithProgIDs", 0, KEY_READ, &hSubkey) == ERROR_SUCCESS)
611 {
612 LoadProgIdList(hSubkey, pwszExt);
613 RegCloseKey(hSubkey);
614 }
615
616 /* Load additional items from referenced PerceivedType */
617 dwSize = sizeof(wszBuf);
618 if (RegGetValueW(hKey, NULL, L"PerceivedType", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize) == ERROR_SUCCESS)
619 {
620 StringCbPrintfW(wszBuf2, sizeof(wszBuf2), L"SystemFileAssociations\\%s", wszBuf);
621 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf2, 0, KEY_READ | KEY_WRITE, &hSubkey) == ERROR_SUCCESS)
622 {
623 /* Load from OpenWithList key */
624 LoadAppList(hSubkey);
625 RegCloseKey(hSubkey);
626 }
627 }
628
629 /* Close the key */
631}
BOOL LoadAppList(HKEY hKey)
BOOL LoadProgIdList(HKEY hKey, LPCWSTR pwszExt)

Referenced by LoadRecommended().

◆ LoadRecommendedFromHKCU()

VOID COpenWithList::LoadRecommendedFromHKCU ( LPCWSTR  pwszExt)
private

Definition at line 633 of file COpenWithMenu.cpp.

634{
635 WCHAR wszBuf[MAX_PATH];
636 HKEY hKey;
637
638 StringCbPrintfW(wszBuf, sizeof(wszBuf),
639 L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\%s",
640 pwszExt);
642 {
643 /* Load MRU and ProgId lists */
645 LoadProgIdList(hKey, pwszExt);
646
647 /* Handle "Aplication" value */
648 DWORD cbBuf = sizeof(wszBuf);
649 if (RegGetValueW(hKey, NULL, L"Application", RRF_RT_REG_SZ, NULL, wszBuf, &cbBuf) == ERROR_SUCCESS)
650 {
651 SApp *pApp = Find(wszBuf);
652 if (pApp)
653 SetRecommended(pApp);
654 }
655
656 /* Close the key */
658 }
659}
BOOL LoadMRUList(HKEY hKey)

Referenced by LoadRecommended().

◆ OpenMRUList()

HANDLE COpenWithList::OpenMRUList ( HKEY  hKey)
staticprivate

Definition at line 467 of file COpenWithMenu.cpp.

468{
470
471 /* Initialize mru list info */
472 Info.cbSize = sizeof(Info);
473 Info.uMax = 32;
474 Info.fFlags = MRU_STRING;
475 Info.hKey = hKey;
476 Info.lpszSubKey = L"OpenWithList";
477 Info.lpfnCompare = NULL;
478
479 return CreateMRUListW(&Info);
480}
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 185 of file COpenWithMenu.cpp.

186{
187 WCHAR wszBuf[256];
188 HKEY hKey;
189
190 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s\\shell\\open\\command", pApp->wszFilename);
192 {
193 ERR("RegOpenKeyEx failed\n");
194 return FALSE;
195 }
196
197 if (RegSetValueEx(hKey, L"", 0, REG_SZ, (PBYTE)pApp->wszCmd, (wcslen(pApp->wszCmd)+1)*sizeof(WCHAR)) != ERROR_SUCCESS)
198 ERR("Cannot add app to registry\n");
199
201 return TRUE;
202}
_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 704 of file COpenWithMenu.cpp.

705{
706 HKEY hKey, hSrcKey, hDestKey;
707 WCHAR wszBuf[256];
708
709 TRACE("SetDefaultHandler %ls %ls\n", pApp->wszFilename, pwszFilename);
710
711 /* Extract file extension */
712 LPCWSTR pwszExt = PathFindExtensionW(pwszFilename);
713 if (!pwszExt[0] || !pwszExt[1])
714 return FALSE;
715
716 /* Create file extension key */
718 {
719 ERR("Can't open ext key\n");
720 return FALSE;
721 }
722
723 DWORD dwSize = sizeof(wszBuf);
724 LONG lResult = RegGetValueW(hKey, NULL, L"", RRF_RT_REG_SZ, NULL, wszBuf, &dwSize);
725
726 if (lResult == ERROR_FILE_NOT_FOUND)
727 {
728 /* A new entry was created or the default key is not set: set the prog key id */
729 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"%s_auto_file", pwszExt + 1);
730 if (RegSetValueExW(hKey, L"", 0, REG_SZ, (const BYTE*)wszBuf, (wcslen(wszBuf) + 1) * sizeof(WCHAR)) != ERROR_SUCCESS)
731 {
733 ERR("RegSetValueExW failed\n");
734 return FALSE;
735 }
736 }
737 else if (lResult != ERROR_SUCCESS)
738 {
740 ERR("RegGetValueExW failed: 0x%08x\n", lResult);
741 return FALSE;
742 }
743
744 /* Close file extension key */
746
747 /* Create prog id key */
749 {
750 ERR("RegCreateKeyExW failed\n");
751 return FALSE;
752 }
753
754 /* Check if there already verbs existing for that app */
755 StringCbPrintfW(wszBuf, sizeof(wszBuf), L"Applications\\%s\\shell", pApp->wszFilename);
756 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, wszBuf, 0, KEY_READ, &hSrcKey) != ERROR_SUCCESS)
757 {
758 ERR("RegOpenKeyExW %ls failed\n", wszBuf);
760 return FALSE;
761 }
762
763 /* Open destination key */
764 if (RegCreateKeyExW(hKey, L"shell", 0, NULL, 0, KEY_WRITE, NULL, &hDestKey, NULL) != ERROR_SUCCESS)
765 {
766 ERR("RegCreateKeyExW failed\n");
767 RegCloseKey(hSrcKey);
769 return FALSE;
770 }
771
772 /* Copy static verbs from Classes\Applications key */
773 /* FIXME: SHCopyKey does not copy the security attributes of the keys */
774 LSTATUS Result = SHCopyKeyW(hSrcKey, NULL, hDestKey, 0);
775 RegCloseKey(hDestKey);
776 RegCloseKey(hSrcKey);
778
779 if (Result != ERROR_SUCCESS)
780 {
781 ERR("SHCopyKeyW failed\n");
782 return FALSE;
783 }
784
785 return TRUE;
786}
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
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
_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 91 of file COpenWithMenu.cpp.

92 {
93 if (!pApp->bRecommended)
95 pApp->bRecommended = TRUE;
96 }

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

Member Data Documentation

◆ m_bNoOpen

BOOL COpenWithList::m_bNoOpen
private

Definition at line 77 of file COpenWithMenu.cpp.

Referenced by IsNoOpen(), and LoadFromProgIdKey().

◆ m_cApp

UINT COpenWithList::m_cApp
private

Definition at line 76 of file COpenWithMenu.cpp.

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

◆ m_cRecommended

UINT COpenWithList::m_cRecommended
private

Definition at line 76 of file COpenWithMenu.cpp.

Referenced by GetRecommendedCount(), and SetRecommended().

◆ m_pApp

SApp* COpenWithList::m_pApp
private

Definition at line 75 of file COpenWithMenu.cpp.

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


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