Reactos
at master 154 lines 5.2 kB view raw
1/* 2 * Provides default file shell extension 3 * 4 * Copyright 2012 Rafal Harabien 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21#ifndef _FILE_DEF_EXT_H_ 22#define _FILE_DEF_EXT_H_ 23 24class CFileVersionInfo 25{ 26 private: 27 PVOID m_pInfo; 28 WORD m_wLang, m_wCode; 29 WCHAR m_wszLang[64]; 30 31 typedef struct _LANGANDCODEPAGE_ 32 { 33 WORD wLang; 34 WORD wCode; 35 } LANGANDCODEPAGE, *LPLANGANDCODEPAGE; 36 37 public: 38 inline CFileVersionInfo(): 39 m_pInfo(NULL), m_wLang(0), m_wCode(0) 40 { 41 m_wszLang[0] = L'\0'; 42 } 43 44 inline ~CFileVersionInfo() 45 { 46 if (m_pInfo) 47 HeapFree(GetProcessHeap(), 0, m_pInfo); 48 } 49 50 BOOL Load(LPCWSTR pwszPath); 51 LPCWSTR GetString(LPCWSTR pwszName); 52 VS_FIXEDFILEINFO *GetFixedInfo(); 53 LPCWSTR GetLangName(); 54}; 55 56class CFileDefExt : 57 public CComCoClass<CFileDefExt, &CLSID_ShellFileDefExt>, 58 public CComObjectRootEx<CComMultiThreadModelNoCS>, 59 public IShellExtInit, 60 public IContextMenu, 61 public IShellPropSheetExt, 62 public CObjectWithSiteBase 63{ 64private: 65 VOID InitOpensWithField(HWND hwndDlg); 66 BOOL InitFileType(HWND hwndDlg); 67 BOOL InitFilePath(HWND hwndDlg); 68 static BOOL GetFileTimeString(LPFILETIME lpFileTime, LPWSTR pwszResult, UINT cchResult); 69 BOOL InitFileAttr(HWND hwndDlg); 70 BOOL InitGeneralPage(HWND hwndDlg); 71 BOOL SetVersionLabel(HWND hwndDlg, DWORD idCtrl, LPCWSTR pwszName); 72 BOOL AddVersionString(HWND hwndDlg, LPCWSTR pwszName); 73 BOOL InitVersionPage(HWND hwndDlg); 74 BOOL InitFolderCustomizePage(HWND hwndDlg); 75 void InitMultifilePage(HWND hwndDlg); 76 void InitMultifilePageThread(); 77 void CountFolderAndFiles(); 78 static INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 79 static INT_PTR CALLBACK VersionPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 80 static INT_PTR CALLBACK FolderCustomizePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 81 static INT_PTR CALLBACK MultifilePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 82 83 WCHAR m_wszPath[MAX_PATH]; 84 CFileVersionInfo m_VerInfo; 85 BOOL m_bDir; 86 BOOL m_bMultifile; 87 88 LPITEMIDLIST m_pidlFolder = NULL; 89 LPITEMIDLIST *m_pidls = NULL; 90 UINT m_cidl = 0; 91 DWORD m_cFiles; 92 DWORD m_cFolders; 93 ULARGE_INTEGER m_DirSize; 94 ULARGE_INTEGER m_DirSizeOnDisc; 95 enum { WM_UPDATEDIRSTATS = WM_APP }; 96 HWND m_hWndDirStatsDlg; 97 void InitDirStats(struct DIRTREESTATS *pStats); 98 BOOL WalkDirTree(PCWSTR pszPath, struct DIRTREESTATS *pStats, WIN32_FIND_DATAW *pWFD); 99 void UpdateDirStatsResults(); 100 101 LONG volatile m_Destroyed = 0; 102 BOOL IsDestroyed() const { return m_Destroyed; } 103 104 static DWORD WINAPI _CountFolderAndFilesThreadProc(LPVOID lpParameter); 105 static DWORD WINAPI _InitializeMultifileThreadProc(LPVOID lpParameter); 106 107 // FolderCustomize 108 WCHAR m_szFolderIconPath[MAX_PATH]; 109 INT m_nFolderIconIndex; 110 HICON m_hFolderIcon; 111 BOOL m_bFolderIconIsSet; 112 113public: 114 CFileDefExt(); 115 ~CFileDefExt(); 116 117 // FolderCustomize 118 BOOL OnFolderCustApply(HWND hwndDlg); 119 void OnFolderCustChangeIcon(HWND hwndDlg); 120 void OnFolderCustDestroy(HWND hwndDlg); 121 void UpdateFolderIcon(HWND hwndDlg); 122 123 // IShellExtInit 124 STDMETHOD(Initialize)(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID) override; 125 126 // IContextMenu 127 STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) override; 128 STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici) override; 129 STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uType, UINT *pwReserved, LPSTR pszName, UINT cchMax) override; 130 131 // IShellPropSheetExt 132 STDMETHOD(AddPages)(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) override; 133 STDMETHOD(ReplacePage)(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam) override; 134 135DECLARE_REGISTRY_RESOURCEID(IDR_FILEDEFEXT) 136DECLARE_NOT_AGGREGATABLE(CFileDefExt) 137 138DECLARE_PROTECT_FINAL_CONSTRUCT() 139 140BEGIN_COM_MAP(CFileDefExt) 141 COM_INTERFACE_ENTRY_IID(IID_IShellExtInit, IShellExtInit) 142 COM_INTERFACE_ENTRY_IID(IID_IContextMenu, IContextMenu) 143 COM_INTERFACE_ENTRY_IID(IID_IShellPropSheetExt, IShellPropSheetExt) 144 COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite) 145END_COM_MAP() 146}; 147 148struct _CountFolderAndFilesData { 149 CFileDefExt *This; 150 HWND hwndDlg; 151 LPWSTR pwszBuf; 152}; 153 154#endif /* _FILE_DEF_EXT_H_ */