├── CBXManager ├── About.h ├── CBXManager.cpp ├── CBXManager.h ├── CBXManager.ico ├── CBXManager.rc ├── CBXManager.vcproj ├── MainDlg.cpp ├── MainDlg.h ├── RegManager.h ├── resource.h ├── stdafx.cpp ├── stdafx.h └── tools.h ├── CBXShell ├── CBXShell.cpp ├── CBXShell.def ├── CBXShell.idl ├── CBXShell.rc ├── CBXShell.rgs ├── CBXShell.vcproj ├── CBXShellClass.cpp ├── CBXShellClass.h ├── StdAfx.cpp ├── StdAfx.h ├── cbxArchive.h ├── resource.h ├── targetver.h ├── unrar.h ├── unrar.lib ├── unrar64.lib ├── unzip.cpp └── unzip.h ├── README.md └── The Code Project Open License (CPOL) 1.02.md /CBXManager/About.h: -------------------------------------------------------------------------------- 1 | #ifndef _ABOUT_0D23B3C4_9FA8_49E8_880D_5B596CC1EB28_ 2 | #define _ABOUT_0D23B3C4_9FA8_49E8_880D_5B596CC1EB28_ 3 | #pragma once 4 | #include "resource.h" 5 | 6 | class CAboutDlg : public CDialogImpl 7 | { 8 | public: 9 | enum { IDD = IDD_ABOUTBOX }; 10 | 11 | BEGIN_MSG_MAP(CAboutDlg) 12 | MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) 13 | MESSAGE_HANDLER(WM_LBUTTONDOWN, OnClick) 14 | MESSAGE_HANDLER(WM_CTLCOLORDLG, OnDlgColor) 15 | MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnDlgColor) 16 | COMMAND_ID_HANDLER(IDOK, OnCloseCmd) 17 | COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd) 18 | END_MSG_MAP() 19 | 20 | LRESULT OnDlgColor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) 21 | { 22 | return (LRESULT)GetStockObject(WHITE_BRUSH); 23 | } 24 | LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 25 | { 26 | CenterWindow(GetParent()); 27 | SetWindowLongW(GWL_STYLE, WS_BORDER); 28 | return TRUE; 29 | } 30 | LRESULT OnClick(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/){EndDialog(IDOK);return 0;} 31 | LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/){EndDialog(wID);return 0;} 32 | }; 33 | #endif//_ABOUT_0D23B3C4_9FA8_49E8_880D_5B596CC1EB28_ 34 | -------------------------------------------------------------------------------- /CBXManager/CBXManager.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "resource.h" 3 | 4 | #include "tools.h" 5 | #include "MainDlg.h" 6 | 7 | CAppModule _Module; 8 | 9 | int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT) 10 | { 11 | CMessageLoop theLoop; 12 | _Module.AddMessageLoop(&theLoop); 13 | 14 | CMainDlg dlgMain; 15 | 16 | if(dlgMain.Create(NULL) == NULL) 17 | { 18 | ATLTRACE(_T("Main dialog creation failed!\n")); 19 | return 0; 20 | } 21 | 22 | dlgMain.ShowWindow(nCmdShow); 23 | 24 | int nRet = theLoop.Run(); 25 | 26 | _Module.RemoveMessageLoop(); 27 | return nRet; 28 | } 29 | 30 | 31 | int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) 32 | { 33 | // one manager instance per user 34 | CHandle mtx(CreateMutex(NULL, FALSE, CBX_MGRMUTEX)); 35 | if (GetLastError()==ERROR_ALREADY_EXISTS) 36 | { 37 | MessageBox(HWND_DESKTOP, _T("CBX Shell Manager is already running\n"), _T("Warning"), 38 | MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL); 39 | return 0; 40 | } 41 | 42 | 43 | HRESULT hRes = ::CoInitialize(NULL); 44 | // If you are running on NT 4.0 or higher you can use the following call instead to 45 | // make the EXE free threaded. This means that calls come in on a random RPC thread. 46 | // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); 47 | ATLASSERT(SUCCEEDED(hRes)); 48 | 49 | // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used 50 | ::DefWindowProc(NULL, 0, 0, 0L); 51 | 52 | AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls 53 | 54 | hRes = _Module.Init(NULL, hInstance); 55 | ATLASSERT(SUCCEEDED(hRes)); 56 | 57 | int nRet = Run(lpstrCmdLine, nCmdShow); 58 | 59 | _Module.Term(); 60 | ::CoUninitialize(); 61 | 62 | return nRet; 63 | } 64 | -------------------------------------------------------------------------------- /CBXManager/CBXManager.h: -------------------------------------------------------------------------------- 1 | // CBXManager.h 2 | -------------------------------------------------------------------------------- /CBXManager/CBXManager.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/T800G/CBXShell/de61b6c3308384967f5b79ec01ffb8ba2f528bd6/CBXManager/CBXManager.ico -------------------------------------------------------------------------------- /CBXManager/CBXManager.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/T800G/CBXShell/de61b6c3308384967f5b79ec01ffb8ba2f528bd6/CBXManager/CBXManager.rc -------------------------------------------------------------------------------- /CBXManager/CBXManager.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 14 | 17 | 18 | 19 | 20 | 21 | 29 | 32 | 35 | 38 | 41 | 53 | 64 | 67 | 73 | 76 | 83 | 86 | 89 | 92 | 95 | 98 | 101 | 104 | 105 | 113 | 116 | 119 | 122 | 125 | 137 | 148 | 151 | 157 | 160 | 167 | 170 | 173 | 176 | 179 | 182 | 185 | 188 | 189 | 198 | 201 | 204 | 207 | 210 | 222 | 238 | 241 | 247 | 250 | 258 | 261 | 264 | 267 | 270 | 273 | 276 | 279 | 280 | 289 | 292 | 295 | 298 | 301 | 313 | 329 | 332 | 338 | 341 | 349 | 352 | 355 | 358 | 361 | 364 | 367 | 370 | 371 | 372 | 373 | 374 | 375 | 379 | 382 | 383 | 386 | 389 | 393 | 394 | 397 | 401 | 402 | 405 | 409 | 410 | 413 | 417 | 418 | 419 | 422 | 423 | 426 | 427 | 428 | 432 | 435 | 436 | 439 | 440 | 443 | 444 | 447 | 448 | 449 | 453 | 456 | 457 | 460 | 461 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | -------------------------------------------------------------------------------- /CBXManager/MainDlg.cpp: -------------------------------------------------------------------------------- 1 | // MainDlg.cpp : implementation of the CMainDlg class 2 | // 3 | ///////////////////////////////////////////////////////////////////////////// 4 | 5 | #include "stdafx.h" 6 | #include "resource.h" 7 | 8 | #include "about.h" 9 | #include "MainDlg.h" 10 | 11 | 12 | BOOL CMainDlg::PreTranslateMessage(MSG* pMsg) { return CWindow::IsDialogMessage(pMsg); } 13 | BOOL CMainDlg::OnIdle() { return FALSE;} 14 | 15 | LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 16 | { 17 | // center the dialog on the screen 18 | CenterWindow(); 19 | 20 | // set icons 21 | HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 22 | IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR); 23 | SetIcon(hIcon, TRUE); 24 | HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 25 | IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); 26 | SetIcon(hIconSmall, FALSE); 27 | 28 | // register object for message filtering and idle updates 29 | CMessageLoop* pLoop = _Module.GetMessageLoop(); 30 | ATLASSERT(pLoop != NULL); 31 | pLoop->AddMessageFilter(this); 32 | pLoop->AddIdleHandler(this); 33 | 34 | UIAddChildWindowContainer(m_hWnd); 35 | 36 | //add 'About' item to sys menu 37 | ATLASSERT(IDC_APPABOUT < 0xF000); 38 | CMenu pSysMenu=GetSystemMenu(FALSE); 39 | if (!pSysMenu.IsNull()) 40 | { 41 | pSysMenu.AppendMenu(MF_SEPARATOR); 42 | pSysMenu.AppendMenu(MF_STRING, IDC_APPABOUT, _T("About")); 43 | } 44 | 45 | InitUI(); 46 | 47 | //set focus to Cancel btn 48 | GotoDlgCtrl(GetDlgItem(IDCANCEL)); 49 | return FALSE; 50 | } 51 | 52 | void CMainDlg::InitUI() 53 | { 54 | //Button_GetCheck BST_CHECKED : BST_UNCHECKED equals TRUE: FALSE 55 | Button_SetCheck(GetDlgItem(IDC_CB_ZIP), m_reg.HasTH(CBX_ZIP)); 56 | Button_SetCheck(GetDlgItem(IDC_CB_CBZ), m_reg.HasTH(CBX_CBZ)); 57 | Button_SetCheck(GetDlgItem(IDC_CB_RAR), m_reg.HasTH(CBX_RAR)); 58 | Button_SetCheck(GetDlgItem(IDC_CB_CBR), m_reg.HasTH(CBX_CBR)); 59 | Button_SetCheck(GetDlgItem(IDC_CB_SORT), m_reg.IsSortOpt());//CBX_SORT 60 | } 61 | 62 | //check ui state,compare to registry state->if!= refresh 63 | void CMainDlg::OnApplyImpl() 64 | { 65 | BOOL bRet, bRefresh=FALSE; 66 | 67 | //sort option 68 | bRet=(BST_CHECKED==Button_GetCheck(GetDlgItem(IDC_CB_SORT))); 69 | if (bRet!=m_reg.IsSortOpt()) 70 | { 71 | bRefresh=TRUE; 72 | m_reg.SetSortOpt(bRet); 73 | } 74 | 75 | //thumbnail handlers 76 | bRet=(BST_CHECKED==Button_GetCheck(GetDlgItem(IDC_CB_ZIP))); 77 | if (bRet!=m_reg.HasTH(CBX_ZIP)) 78 | { 79 | bRefresh=TRUE; 80 | m_reg.SetHandlers(CBX_ZIP, bRet); 81 | } 82 | bRet=(BST_CHECKED==Button_GetCheck(GetDlgItem(IDC_CB_CBZ))); 83 | if (bRet!=m_reg.HasTH(CBX_CBZ)) 84 | { 85 | bRefresh=TRUE; 86 | m_reg.SetHandlers(CBX_CBZ, bRet); 87 | } 88 | bRet=(BST_CHECKED==Button_GetCheck(GetDlgItem(IDC_CB_RAR))); 89 | if (bRet!=m_reg.HasTH(CBX_RAR)) 90 | { 91 | bRefresh=TRUE; 92 | m_reg.SetHandlers(CBX_RAR, bRet); 93 | } 94 | bRet=(BST_CHECKED==Button_GetCheck(GetDlgItem(IDC_CB_CBR))); 95 | if (bRet!=m_reg.HasTH(CBX_CBR)) 96 | { 97 | bRefresh=TRUE; 98 | m_reg.SetHandlers(CBX_CBR, bRet); 99 | } 100 | 101 | if (bRefresh) 102 | { 103 | ATLTRACE("refreshing FS\n"); 104 | SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT | SHCNF_NOTIFYRECURSIVE, NULL, NULL); 105 | } 106 | 107 | InitUI();//reload 108 | } 109 | 110 | LRESULT CMainDlg::OnApply(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 111 | { 112 | OnApplyImpl(); 113 | return 0; 114 | } 115 | 116 | LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 117 | { 118 | OnApplyImpl(); 119 | CloseDialog(wID); 120 | return 0; 121 | } 122 | 123 | 124 | LRESULT CMainDlg::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 125 | { 126 | if (wParam!=IDC_APPABOUT) return ::DefWindowProc(m_hWnd, uMsg, wParam, lParam); 127 | CAboutDlg _a; 128 | _a.DoModal(m_hWnd); 129 | return 0; 130 | } 131 | 132 | LRESULT CMainDlg::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 133 | { 134 | // unregister message filtering and idle updates 135 | CMessageLoop* pLoop = _Module.GetMessageLoop(); 136 | ATLASSERT(pLoop != NULL); 137 | pLoop->RemoveMessageFilter(this); 138 | pLoop->RemoveIdleHandler(this); 139 | return 0; 140 | } 141 | 142 | LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 143 | { 144 | CloseDialog(wID); 145 | return 0; 146 | } 147 | 148 | void CMainDlg::CloseDialog(int nVal) 149 | { 150 | DestroyWindow(); 151 | ::PostQuitMessage(nVal); 152 | } 153 | 154 | LRESULT CMainDlg::OnAppHelp(LPHELPINFO lphi) 155 | { 156 | switch (lphi->iCtrlId) 157 | { 158 | case IDC_TH_GROUP: 159 | case IDC_CB_CBZ: 160 | case IDC_CB_CBR: 161 | case IDC_CB_ZIP: 162 | case IDC_CB_RAR: 163 | // '#' anchors must use id attribute 164 | HtmlHelp(m_hWnd, _T("CBXShellHelp.chm::manager.html#optth"), HH_DISPLAY_TOPIC, NULL); 165 | break; 166 | 167 | case IDC_SORT_ADVOPTGROUP: 168 | HtmlHelp(m_hWnd, _T("CBXShellHelp.chm::manager.html#advopt"), HH_DISPLAY_TOPIC, NULL); 169 | break; 170 | 171 | case IDC_CB_SORT: 172 | case IDC_SORT_DESC: 173 | ATLTRACE("HH sort opt\n"); 174 | HtmlHelp(m_hWnd, _T("CBXShellHelp.chm::FAQ.html#custth"), HH_DISPLAY_TOPIC, NULL); 175 | break; 176 | 177 | default: 178 | ATLTRACE("HH default\n"); 179 | HtmlHelp(m_hWnd, _T("CBXShellHelp.chm::manager.html"), HH_DISPLAY_TOPIC, NULL);//about? 180 | break; 181 | } 182 | return 0; 183 | } 184 | -------------------------------------------------------------------------------- /CBXManager/MainDlg.h: -------------------------------------------------------------------------------- 1 | #ifndef _MAINDLG_A8394D0D_EE2B_4A00_9FAC_AB8D3B03F078_ 2 | #define _MAINDLG_A8394D0D_EE2B_4A00_9FAC_AB8D3B03F078_ 3 | 4 | #include "tools.h" 5 | #include "regmanager.h" 6 | 7 | #include 8 | #pragma comment(lib,"Htmlhelp.lib") 9 | 10 | class CMainDlg : public CDialogImpl, public CUpdateUI, public CDialogDrag, 11 | public CMessageFilter, public CIdleHandler, public CSnapWindow, public CDialogHelp 12 | { 13 | public: 14 | enum { IDD = IDD_MAINDLG }; 15 | 16 | virtual BOOL PreTranslateMessage(MSG* pMsg); 17 | virtual BOOL OnIdle(); 18 | 19 | BEGIN_UPDATE_UI_MAP(CMainDlg) 20 | END_UPDATE_UI_MAP() 21 | 22 | BEGIN_MSG_MAP(CMainDlg) 23 | MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog) 24 | MESSAGE_HANDLER(WM_DESTROY, OnDestroy) 25 | MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand) 26 | COMMAND_ID_HANDLER(IDOK, OnOK) 27 | COMMAND_ID_HANDLER(IDC_APPLY, OnApply) 28 | COMMAND_ID_HANDLER(IDCANCEL, OnCancel) 29 | CHAIN_MSG_MAP(CDialogDrag) 30 | CHAIN_MSG_MAP(CSnapWindow) 31 | CHAIN_MSG_MAP(CDialogHelp) 32 | END_MSG_MAP() 33 | 34 | // Handler prototypes (uncomment arguments if needed): 35 | // LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) 36 | // LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) 37 | // LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/) 38 | 39 | LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 40 | LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 41 | 42 | LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 43 | 44 | LRESULT OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 45 | LRESULT OnApply(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 46 | void InitUI(); 47 | void OnApplyImpl(); 48 | LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); 49 | 50 | void CloseDialog(int nVal); 51 | 52 | LRESULT OnAppHelp(LPHELPINFO lphi); 53 | 54 | private: 55 | CRegManager m_reg; 56 | }; 57 | #endif//_MAINDLG_A8394D0D_EE2B_4A00_9FAC_AB8D3B03F078_ 58 | -------------------------------------------------------------------------------- /CBXManager/RegManager.h: -------------------------------------------------------------------------------- 1 | #ifndef _REGMANAGER_79AE66E4_84E2_45A1_BF4F_43AA714BE55F_ 2 | #define _REGMANAGER_79AE66E4_84E2_45A1_BF4F_43AA714BE55F_ 3 | #pragma once 4 | 5 | #include 6 | #pragma comment(lib,"advapi32.lib") 7 | #include 8 | #pragma comment(lib,"shlwapi.lib") 9 | 10 | 11 | #define CBX_MUTEX_GLOBAL L"Global\\{64DEE47D-9669-4430-9D5C-304867F87B51}" 12 | #define CBX_MGRMUTEX L"Local\\{50D9CBE6-C168-4901-8CC9-2A7C97E558F7}" 13 | 14 | 15 | #define CBX_GUID_KEY _T("{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}") //38+1 TCHAR 16 | #define CBX_GUID_KEY_SLEN 39 17 | #define CBX_APP_KEY _T("Software\\T800 Productions\\{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}") 18 | 19 | // per-user settings (HKCU) 20 | // thumbnail handler keys 21 | #define CBX_ZIPTH_KEY _T("SOFTWARE\\Classes\\.ZIP\\shellex\\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}") 22 | #define CBX_CBZTH_KEY _T("SOFTWARE\\Classes\\.CBZ\\shellex\\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}") 23 | #define CBX_RARTH_KEY _T("SOFTWARE\\Classes\\.RAR\\shellex\\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}") 24 | #define CBX_CBRTH_KEY _T("SOFTWARE\\Classes\\.CBR\\shellex\\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}") 25 | // infotip handler keys 26 | #define CBX_ZIPIH_KEY _T("SOFTWARE\\Classes\\.ZIP\\shellex\\{00021500-0000-0000-C000-000000000046}") 27 | #define CBX_CBZIH_KEY _T("SOFTWARE\\Classes\\.CBZ\\shellex\\{00021500-0000-0000-C000-000000000046}") 28 | #define CBX_RARIH_KEY _T("SOFTWARE\\Classes\\.RAR\\shellex\\{00021500-0000-0000-C000-000000000046}") 29 | #define CBX_CBRIH_KEY _T("SOFTWARE\\Classes\\.CBR\\shellex\\{00021500-0000-0000-C000-000000000046}") 30 | 31 | // cbx types 32 | #define CBX_NONE 0 33 | #define CBX_ZIP 1 34 | #define CBX_CBZ 2 35 | #define CBX_RAR 3 36 | #define CBX_CBR 4 37 | //#define CBX_SORT 5 38 | 39 | 40 | class CRegManager 41 | { 42 | public: 43 | //CRegManager(void){} 44 | //virtual ~CRegManager(void){} 45 | public: 46 | 47 | /////////////// 48 | // sort option 49 | BOOL IsSortOpt() 50 | { 51 | DWORD d; 52 | CRegKey rk; 53 | if (ERROR_SUCCESS==rk.Open(HKEY_CURRENT_USER, CBX_APP_KEY, KEY_READ)) 54 | { 55 | if (ERROR_SUCCESS==rk.QueryDWORDValue(_T("NoSort"), d)) 56 | return (d==FALSE); 57 | } 58 | return TRUE; 59 | } 60 | 61 | void SetSortOpt(BOOL bSort) 62 | { 63 | CRegKey rk; 64 | if (ERROR_SUCCESS==rk.Create(HKEY_CURRENT_USER, CBX_APP_KEY, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) 65 | rk.SetDWORDValue(_T("NoSort"), (DWORD)(bSort ? FALSE : TRUE)); 66 | } 67 | 68 | /////////////////////////////// 69 | // check for thumbnail handlers 70 | BOOL HasTH(int cbxType) 71 | { 72 | ATLASSERT(cbxType>CBX_NONE); 73 | ULONG n=CBX_GUID_KEY_SLEN; 74 | TCHAR s[CBX_GUID_KEY_SLEN]; 75 | 76 | CRegKey rk; 77 | if (ERROR_SUCCESS==rk.Open(HKEY_CURRENT_USER, GetTHKeyName(cbxType), KEY_READ)) 78 | { 79 | if (ERROR_SUCCESS==rk.QueryStringValue(NULL, s, &n)) 80 | { 81 | if (0==StrCmpI(s, CBX_GUID_KEY)) 82 | return TRUE; 83 | } 84 | } 85 | return FALSE; 86 | } 87 | 88 | ///////////////////////////// 89 | // check for infotip handlers 90 | BOOL HasIH(int cbxType) 91 | { 92 | ATLASSERT(cbxType>CBX_NONE); 93 | ULONG n=CBX_GUID_KEY_SLEN; 94 | TCHAR s[CBX_GUID_KEY_SLEN]; 95 | 96 | CRegKey rk; 97 | if (ERROR_SUCCESS==rk.Open(HKEY_CURRENT_USER, GetIHKeyName(cbxType), KEY_READ)) 98 | { 99 | if (ERROR_SUCCESS==rk.QueryStringValue(NULL, s, &n)) 100 | { 101 | if (StrCmpI(s, CBX_GUID_KEY)==0) 102 | return TRUE; 103 | } 104 | } 105 | return FALSE; 106 | } 107 | 108 | ///////////////////////// 109 | // set thumbnail / infotip handlers 110 | void SetHandlers(int cbxType, BOOL bSet) 111 | { 112 | ATLASSERT(cbxType>CBX_NONE); 113 | 114 | if (bSet) 115 | { 116 | //thumbnail 117 | CRegKey rkt, rki; 118 | if (ERROR_SUCCESS==rkt.Create(HKEY_CURRENT_USER, GetTHKeyName(cbxType), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) 119 | rkt.SetStringValue(NULL, CBX_GUID_KEY); 120 | //infotip 121 | if (ERROR_SUCCESS==rki.Create(HKEY_CURRENT_USER, GetIHKeyName(cbxType), NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE)) 122 | rki.SetStringValue(NULL, CBX_GUID_KEY); 123 | } 124 | else 125 | { 126 | //thumbnail 127 | if (HasTH(cbxType)) RegDeleteKey(HKEY_CURRENT_USER, GetTHKeyName(cbxType)); 128 | //infotip 129 | if (HasIH(cbxType)) RegDeleteKey(HKEY_CURRENT_USER, GetIHKeyName(cbxType)); 130 | } 131 | } 132 | 133 | //get handler reg key names 134 | LPCTSTR GetTHKeyName(int cbxType) 135 | { 136 | ATLASSERT(cbxType>CBX_NONE); 137 | switch (cbxType) 138 | { 139 | case CBX_ZIP: return CBX_ZIPTH_KEY; 140 | case CBX_CBZ: return CBX_CBZTH_KEY; 141 | 142 | case CBX_RAR: return CBX_RARTH_KEY; 143 | case CBX_CBR: return CBX_CBRTH_KEY; 144 | default:break; 145 | } 146 | return NULL; 147 | } 148 | LPCTSTR GetIHKeyName(int cbxType) 149 | { 150 | ATLASSERT(cbxType>CBX_NONE); 151 | switch (cbxType) 152 | { 153 | case CBX_ZIP: return CBX_ZIPIH_KEY; 154 | case CBX_CBZ: return CBX_CBZIH_KEY; 155 | 156 | case CBX_RAR: return CBX_RARIH_KEY; 157 | case CBX_CBR: return CBX_CBRIH_KEY; 158 | default:break; 159 | } 160 | return NULL; 161 | } 162 | }; 163 | 164 | #endif//_REGMANAGER_79AE66E4_84E2_45A1_BF4F_43AA714BE55F_ 165 | -------------------------------------------------------------------------------- /CBXManager/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef IDC_STATIC 2 | #define IDC_STATIC (-1) 3 | #endif 4 | 5 | #define IDR_MAINFRAME 128 6 | #define IDD_MAINDLG 129 7 | #define IDD_ABOUTBOX 130 8 | #define IDC_SORT_DESC 1000 9 | #define IDC_APPABOUT 1001 10 | #define IDC_APPLY 1002 11 | #define IDC_SORT_ADVOPTGROUP 1003 12 | #define IDC_CB_CBZ 1004 13 | #define IDC_TH_GROUP 1005 14 | #define IDC_CB_RAR 57681 15 | #define IDC_CB_ZIP 57682 16 | #define IDC_CB_SORT 57683 17 | #define IDC_CB_CBR 57684 18 | -------------------------------------------------------------------------------- /CBXManager/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // CBXManager.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | #if (_ATL_VER < 0x0700) 8 | #include 9 | #endif //(_ATL_VER < 0x0700) 10 | -------------------------------------------------------------------------------- /CBXManager/stdafx.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDAFX_2AA16305_D8E3_4296_9A26_5407C9BF9DEC_ 2 | #define _STDAFX_2AA16305_D8E3_4296_9A26_5407C9BF9DEC_ 3 | #pragma once 4 | 5 | #ifndef UNICODE 6 | #define UNICODE// UNICODE-only project 7 | #endif 8 | 9 | //runs on min win2k 10 | #define _WIN32_WINNT _WIN32_WINNT_WIN2K 11 | 12 | 13 | //#define _WTL_SUPPORT_SDK_ATL3 14 | #pragma comment(linker, "/NODEFAULTLIB:atlthunk.lib") 15 | 16 | 17 | #include 18 | #include 19 | 20 | 21 | namespace ATL 22 | { 23 | inline void * __stdcall __AllocStdCallThunk() 24 | { 25 | return ::VirtualAlloc(0, sizeof(_stdcallthunk), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); 26 | } 27 | 28 | inline void __stdcall __FreeStdCallThunk(void *p) 29 | { 30 | if (p!=NULL) ::VirtualFree(p, 0, MEM_RELEASE); 31 | } 32 | }; 33 | 34 | #include 35 | 36 | extern CAppModule _Module; 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | 46 | #if defined _M_IX86 47 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 48 | #elif defined _M_IA64 49 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") 50 | #elif defined _M_X64 51 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 52 | #else 53 | #pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 54 | #endif 55 | 56 | #endif//_STDAFX_2AA16305_D8E3_4296_9A26_5407C9BF9DEC_ 57 | -------------------------------------------------------------------------------- /CBXManager/tools.h: -------------------------------------------------------------------------------- 1 | #ifndef _TOOLS_C804F48E_5335_49D0_B277_FAB445845DF3_ 2 | #define _TOOLS_C804F48E_5335_49D0_B277_FAB445845DF3_ 3 | 4 | #include 5 | #include 6 | 7 | //dialog drag support 8 | template class CDialogDrag 9 | { 10 | public: 11 | BEGIN_MSG_MAP(CDialogDrag) 12 | MESSAGE_HANDLER(WM_NCHITTEST, OnNCHitTest) 13 | END_MSG_MAP() 14 | 15 | LRESULT OnNCHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 16 | { 17 | T* pT=static_cast(this); 18 | m_lHitTest = ::DefWindowProcW(pT->m_hWnd, uMsg, wParam, lParam); 19 | if (m_lHitTest == HTCLIENT) return HTCAPTION; 20 | return m_lHitTest; 21 | } 22 | private: 23 | LRESULT m_lHitTest; 24 | }; 25 | #define CDragDialog CDialogDrag; 26 | 27 | //************************************************************************ 28 | #include 29 | #pragma comment(lib, "shell32.lib") 30 | template class CDropFileTarget // implements dropfile target window 31 | { 32 | public: 33 | BEGIN_MSG_MAP(CDropFileTarget) 34 | MESSAGE_HANDLER(WM_DROPFILES, OnDropFiles) 35 | END_MSG_MAP() 36 | 37 | void RegisterDropTarget(BOOL bAccept = TRUE) 38 | { 39 | T* pT=static_cast(this); 40 | ATLASSERT(::IsWindow(pT->m_hWnd)); 41 | ::DragAcceptFiles(pT->m_hWnd, bAccept); 42 | } 43 | 44 | //override in inherited class 45 | protected: 46 | virtual BOOL StartDropFile(UINT uNumFiles){ATLTRACE("CDropFileTarget::StartDropFile NumFiles: %d\n",uNumFiles);return TRUE;} 47 | virtual BOOL ProcessDropFile(LPCTSTR szDropFile, UINT nFile){ATLTRACE(_T("CDropFileTarget::ProcessDropFile: %s\n"),szDropFile);return TRUE;} 48 | virtual void FinishDropFile(){ATLTRACE("CDropFileTarget::FinishDropFile\n");} 49 | 50 | private: 51 | virtual LRESULT OnDropFiles(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 52 | { 53 | UINT i; 54 | UINT uMaxLen=0; 55 | UINT uNumFiles = ::DragQueryFile((HDROP)wParam, 0xFFFFFFFF, NULL, 0); 56 | if (!StartDropFile(uNumFiles)) return 0; 57 | 58 | for (i=0; i class CSnapWindow 106 | #else 107 | class CSnapWindow 108 | #endif 109 | { 110 | public: 111 | int snap_Margin, snap_ModifierKey; 112 | 113 | #ifdef __ATLBASE_H__ 114 | BEGIN_MSG_MAP(CSnapWindow) 115 | MESSAGE_HANDLER(WM_MOVING, OnSnapMoving) 116 | MESSAGE_HANDLER(WM_ENTERSIZEMOVE, OnSnapEnterSizeMove) 117 | END_MSG_MAP() 118 | #endif 119 | 120 | #ifdef __ATLBASE_H__ 121 | virtual LRESULT OnSnapEnterSizeMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 122 | #else 123 | virtual LRESULT OnSnapEnterSizeMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 124 | #endif 125 | { 126 | snap_cur_pos.x=0; 127 | snap_cur_pos.y=0; 128 | snap_rcWindow.bottom=0; 129 | snap_rcWindow.left=0; 130 | snap_rcWindow.right=0; 131 | snap_rcWindow.top=0; 132 | 133 | #ifdef __ATLBASE_H__ 134 | T* pT = static_cast(this); 135 | GetWindowRect(pT->m_hWnd, &snap_rcWindow ); 136 | #else 137 | GetWindowRect(hWnd, &snap_rcWindow ); 138 | #endif 139 | 140 | GetCursorPos( &snap_cur_pos ); 141 | snap_x = snap_cur_pos.x - snap_rcWindow.left; 142 | snap_y = snap_cur_pos.y - snap_rcWindow.top; 143 | return 0; 144 | } 145 | 146 | #ifdef __ATLBASE_H__ 147 | virtual LRESULT OnSnapMoving(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) 148 | #else 149 | virtual LRESULT OnSnapMoving(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 150 | #endif 151 | { 152 | //no snap if shift key pressed 153 | if (GetAsyncKeyState(snap_ModifierKey) < 0) return FALSE; 154 | snap_prc = (LPRECT)lParam; 155 | snap_cur_pos.x=0; 156 | snap_cur_pos.y=0; 157 | snap_rcWindow.bottom=0; 158 | snap_rcWindow.left=0; 159 | snap_rcWindow.right=0; 160 | snap_rcWindow.top=0; 161 | 162 | GetCursorPos( &snap_cur_pos ); 163 | OffsetRect( snap_prc, 164 | snap_cur_pos.x - (snap_prc->left + snap_x) , 165 | snap_cur_pos.y - (snap_prc->top + snap_y) ); 166 | //it may change during app lifetime 167 | SystemParametersInfo( SPI_GETWORKAREA, 0, &snap_wa, 0 ); 168 | 169 | if (isSnapClose( snap_prc->left, snap_wa.left )) 170 | OffsetRect( snap_prc, snap_wa.left - snap_prc->left, 0); 171 | else 172 | if (isSnapClose( snap_wa.right, snap_prc->right )) 173 | OffsetRect( snap_prc, snap_wa.right - snap_prc->right, 0); 174 | 175 | if (isSnapClose( snap_prc->top, snap_wa.top )) 176 | OffsetRect( snap_prc, 0, snap_wa.top - snap_prc->top ); 177 | else 178 | if (isSnapClose( snap_wa.bottom, snap_prc->bottom )) 179 | OffsetRect( snap_prc, 0, snap_wa.bottom - snap_prc->bottom ); 180 | return TRUE; 181 | } 182 | 183 | virtual BOOL isSnapClose( int a, int b ) { return (::abs( a - b ) < snap_Margin);} 184 | 185 | CSnapWindow() 186 | { 187 | snap_ModifierKey=VK_SHIFT; 188 | NONCLIENTMETRICS ncm; 189 | SecureZeroMemory(&ncm, sizeof(NONCLIENTMETRICS)); 190 | ncm.cbSize = sizeof ncm; 191 | SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); 192 | snap_Margin=ncm.iCaptionHeight; 193 | } 194 | private: 195 | POINT snap_cur_pos; 196 | RECT snap_rcWindow, snap_wa, *snap_prc; 197 | int snap_x, snap_y; 198 | }; 199 | //************************************************************************ 200 | 201 | //hi-res timer class 202 | class CTimer 203 | { 204 | public: 205 | virtual ~CTimer(){} 206 | CTimer() 207 | { 208 | m_msSystemUpTime=0; 209 | m_ticksPerSecond.QuadPart=-1; 210 | m_startTick.QuadPart=0; 211 | m_count.QuadPart=0; 212 | ::QueryPerformanceFrequency(&m_ticksPerSecond); 213 | ::QueryPerformanceCounter(&m_startTick); 214 | m_msSystemUpTime = 1000*m_startTick.QuadPart/m_ticksPerSecond.QuadPart; 215 | } 216 | 217 | __int64 msElapsed()//elapsed time in milliseconds 218 | { 219 | ::QueryPerformanceCounter(&m_count); 220 | __int64 m_elapsed=1000*(m_count.QuadPart - m_startTick.QuadPart)/m_ticksPerSecond.QuadPart; 221 | return m_elapsed; 222 | } 223 | 224 | BOOL resetTimer(){ return ::QueryPerformanceCounter(&m_startTick); } 225 | 226 | private: 227 | __int64 m_msSystemUpTime; 228 | LARGE_INTEGER m_ticksPerSecond; 229 | LARGE_INTEGER m_startTick; 230 | LARGE_INTEGER m_count; 231 | }; 232 | //************************************************************************ 233 | 234 | //#ifdef USES_HTMLHELP 235 | // handles F1 or dialog context help 236 | //#include "resource.h" 237 | //#include "Htmlhelp.h" 238 | //#pragma comment(lib,"Htmlhelp.lib") 239 | template class CDialogHelp 240 | { 241 | public: 242 | BEGIN_MSG_MAP(CDialogHelp) 243 | MESSAGE_HANDLER(WM_HELP, OnAppHelpImpl) 244 | END_MSG_MAP() 245 | 246 | LRESULT OnAppHelpImpl(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) 247 | { 248 | T* pT=static_cast(this); 249 | return pT->OnAppHelp((HELPINFO *)lParam); 250 | } 251 | 252 | virtual LRESULT OnAppHelp(LPHELPINFO lphi) 253 | { 254 | ATLTRACE("CDialogHelp::OnAppHelp\n"); 255 | return 0; 256 | } 257 | }; 258 | //#endif 259 | 260 | 261 | #endif//_TOOLS_C804F48E_5335_49D0_B277_FAB445845DF3_ 262 | -------------------------------------------------------------------------------- /CBXShell/CBXShell.cpp: -------------------------------------------------------------------------------- 1 | // CBXshell.cpp : Implementation of DLL Exports. 2 | 3 | #include "stdafx.h" 4 | #include "resource.h" 5 | #include 6 | #include "CBXshell.h" 7 | 8 | #include "CBXShell_i.c" 9 | #include "CBXShellClass.h" 10 | 11 | 12 | CComModule _Module; 13 | 14 | BEGIN_OBJECT_MAP(ObjectMap) 15 | OBJECT_ENTRY(CLSID_CBXShell, CCBXShell) 16 | END_OBJECT_MAP() 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | // DLL Entry Point 20 | extern "C" 21 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 22 | { 23 | if (dwReason == DLL_PROCESS_ATTACH) 24 | { 25 | _Module.Init(ObjectMap, hInstance, &LIBID_CBXSHELLLib); 26 | DisableThreadLibraryCalls(hInstance); 27 | } 28 | else 29 | if (dwReason == DLL_PROCESS_DETACH) 30 | { 31 | _Module.Term(); 32 | } 33 | return TRUE; 34 | } 35 | 36 | ///////////////////////////////////////////////////////////////////////////// 37 | // Returns a class factory to create an object of the requested type 38 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) 39 | { 40 | return _Module.GetClassObject(rclsid, riid, ppv); 41 | } 42 | 43 | ///////////////////////////////////////////////////////////////////////////// 44 | // Used to determine whether the DLL can be unloaded by OLE 45 | STDAPI DllCanUnloadNow(void) 46 | { 47 | return (_Module.GetLockCount()==0) ? S_OK : S_FALSE; 48 | } 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // Adds entries to the system registry 52 | STDAPI DllRegisterServer(void) 53 | { 54 | // registers object, typelib and all interfaces in typelib 55 | return _Module.RegisterServer(TRUE); 56 | } 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // Removes entries from the system registry 60 | STDAPI DllUnregisterServer(void) 61 | { 62 | return _Module.UnregisterServer(TRUE); 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /CBXShell/CBXShell.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | DllCanUnloadNow PRIVATE 3 | DllGetClassObject PRIVATE 4 | DllRegisterServer PRIVATE 5 | DllUnregisterServer PRIVATE 6 | -------------------------------------------------------------------------------- /CBXShell/CBXShell.idl: -------------------------------------------------------------------------------- 1 | // CBXShell.idl : IDL source for CBXShell.dll 2 | // 3 | 4 | // This file will be processed by the MIDL tool to 5 | // produce the type library (CBXShell.tlb) and marshalling code. 6 | 7 | import "oaidl.idl"; 8 | import "ocidl.idl"; 9 | 10 | [ 11 | object, 12 | uuid(677D0B3B-E0A8-4ECC-BD7E-1BCC96E388EA), 13 | dual, 14 | helpstring("ICBXShell Interface"), 15 | pointer_default(unique) 16 | ] 17 | interface ICBXShell : IDispatch 18 | { 19 | }; 20 | 21 | [ 22 | uuid(FC1558B6-3992-4ACE-B032-EB3273751A1B), 23 | version(1.0), 24 | helpstring("CBXShell 1.0 Type Library") 25 | ] 26 | library CBXSHELLLib 27 | { 28 | importlib("stdole32.tlb"); 29 | importlib("stdole2.tlb"); 30 | 31 | 32 | [ 33 | uuid(9E6ECB90-5A61-42BD-B851-D3297D9C7F39), 34 | helpstring("CBXShell Class") 35 | ] 36 | coclass CBXShell 37 | { 38 | [default] interface ICBXShell; 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /CBXShell/CBXShell.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/T800G/CBXShell/de61b6c3308384967f5b79ec01ffb8ba2f528bd6/CBXShell/CBXShell.rc -------------------------------------------------------------------------------- /CBXShell/CBXShell.rgs: -------------------------------------------------------------------------------- 1 | HKCU 2 | { 3 | NoRemove Software 4 | { 5 | NoRemove Classes 6 | { 7 | NoRemove .cbz 8 | { 9 | shellex 10 | { 11 | {BB2E617C-0920-11d1-9A0B-00C04FC2D6C1} = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 12 | {00021500-0000-0000-C000-000000000046} = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 13 | } 14 | } 15 | NoRemove .cbr 16 | { 17 | shellex 18 | { 19 | {BB2E617C-0920-11d1-9A0B-00C04FC2D6C1} = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 20 | {00021500-0000-0000-C000-000000000046} = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 21 | } 22 | } 23 | } 24 | } 25 | } 26 | 27 | 28 | HKLM 29 | { 30 | NoRemove Software 31 | { 32 | 33 | 34 | NoRemove Classes 35 | { 36 | CBXShell.CBXShell.1 = s 'CBXShell Class' 37 | { 38 | CLSID = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 39 | } 40 | CBXShell.CBXShell = s 'CBXShell Class' 41 | { 42 | CLSID = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 43 | CurVer = s 'CBXShell.CBXShell.1' 44 | } 45 | NoRemove CLSID 46 | { 47 | ForceRemove {9E6ECB90-5A61-42BD-B851-D3297D9C7F39} = s 'CBXShell Class' 48 | { 49 | ProgID = s 'CBXShell.CBXShell.1' 50 | VersionIndependentProgID = s 'CBXShell.CBXShell' 51 | ForceRemove 'Programmable' 52 | InprocServer32 = s '%MODULE%' 53 | { 54 | val ThreadingModel = s 'Apartment' 55 | } 56 | 'TypeLib' = s '{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}' 57 | } 58 | } 59 | } 60 | 61 | NoRemove Microsoft 62 | { 63 | NoRemove Windows 64 | { 65 | NoRemove CurrentVersion 66 | { 67 | NoRemove 'Shell Extensions' 68 | { 69 | NoRemove Approved 70 | { 71 | val {9E6ECB90-5A61-42BD-B851-D3297D9C7F39} = s 'CBXShell Class' 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /CBXShell/CBXShell.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | 22 | 31 | 34 | 37 | 40 | 43 | 47 | 59 | 62 | 67 | 70 | 80 | 83 | 86 | 89 | 94 | 97 | 100 | 103 | 104 | 113 | 116 | 119 | 122 | 125 | 130 | 143 | 146 | 151 | 154 | 164 | 167 | 170 | 173 | 178 | 181 | 184 | 187 | 188 | 199 | 202 | 205 | 208 | 211 | 215 | 231 | 234 | 239 | 242 | 253 | 256 | 259 | 262 | 267 | 270 | 273 | 276 | 277 | 288 | 291 | 294 | 297 | 300 | 305 | 321 | 324 | 329 | 332 | 343 | 346 | 349 | 352 | 357 | 360 | 363 | 366 | 367 | 368 | 369 | 370 | 371 | 375 | 378 | 381 | 385 | 386 | 389 | 393 | 394 | 397 | 401 | 402 | 405 | 409 | 410 | 411 | 414 | 417 | 422 | 423 | 426 | 431 | 432 | 435 | 440 | 441 | 444 | 449 | 450 | 451 | 454 | 455 | 458 | 459 | 460 | 464 | 467 | 470 | 475 | 476 | 479 | 484 | 485 | 488 | 493 | 494 | 497 | 502 | 503 | 504 | 507 | 508 | 509 | 512 | 515 | 516 | 519 | 522 | 529 | 530 | 533 | 540 | 541 | 544 | 551 | 552 | 555 | 562 | 563 | 564 | 567 | 568 | 571 | 574 | 578 | 579 | 582 | 586 | 587 | 590 | 594 | 595 | 598 | 602 | 603 | 604 | 607 | 608 | 609 | 612 | 615 | 616 | 619 | 620 | 623 | 624 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | -------------------------------------------------------------------------------- /CBXShell/CBXShellClass.cpp: -------------------------------------------------------------------------------- 1 | // CBXShellClass.cpp : Implementation of CCBXshellApp and DLL registration. 2 | 3 | #include "stdafx.h" 4 | #include "CBXShell.h" 5 | #include "CBXShellClass.h" 6 | 7 | 8 | HRESULT CCBXShell::FinalConstruct(void) 9 | { 10 | ATLTRACE("CCBXShell::FinalConstruct\n"); 11 | m_cbx.LoadRegistrySettings(); 12 | 13 | return S_OK; 14 | } 15 | 16 | void CCBXShell::FinalRelease(void) 17 | { 18 | ATLTRACE("CCBXShell::FinalRelease\n"); 19 | } 20 | -------------------------------------------------------------------------------- /CBXShell/CBXShellClass.h: -------------------------------------------------------------------------------- 1 | #ifndef _CBXSHELLCLASS_541926D5_D807_4CCB_9F35_8464657CC196_ 2 | #define _CBXSHELLCLASS_541926D5_D807_4CCB_9F35_8464657CC196_ 3 | #pragma once 4 | 5 | #include "resource.h" // main symbols 6 | 7 | #include "cbxArchive.h" 8 | 9 | ///////////////////////////////////////////////////////////////////////////// 10 | // CCBXShell 11 | 12 | class ATL_NO_VTABLE CCBXShell : 13 | public CComObjectRootEx, 14 | public CComCoClass, 15 | public IDispatchImpl, 16 | public IPersistFile, 17 | public IExtractImage2, 18 | public IQueryInfo 19 | { 20 | public: 21 | HRESULT FinalConstruct(void); 22 | void FinalRelease(void); 23 | 24 | BEGIN_COM_MAP(CCBXShell) 25 | COM_INTERFACE_ENTRY(ICBXShell) 26 | COM_INTERFACE_ENTRY(IPersistFile) 27 | COM_INTERFACE_ENTRY(IQueryInfo) 28 | COM_INTERFACE_ENTRY(IExtractImage) 29 | COM_INTERFACE_ENTRY(IExtractImage2) 30 | COM_INTERFACE_ENTRY(IDispatch) 31 | END_COM_MAP() 32 | 33 | 34 | DECLARE_REGISTRY_RESOURCEID(IDR_CBXShell) 35 | DECLARE_PROTECT_FINAL_CONSTRUCT() 36 | 37 | // IPersistFile 38 | STDMETHOD(Load)(LPCOLESTR wszFile, DWORD dwMode) { return m_cbx.OnLoad(wszFile); } 39 | STDMETHOD(GetClassID)(LPCLSID clsid){return E_NOTIMPL;} 40 | STDMETHOD(IsDirty)(VOID){return E_NOTIMPL;} 41 | STDMETHOD(Save)(LPCOLESTR, BOOL){return E_NOTIMPL;} 42 | STDMETHOD(SaveCompleted)(LPCOLESTR){return E_NOTIMPL;} 43 | STDMETHOD(GetCurFile)(LPOLESTR FAR*){return E_NOTIMPL;} 44 | 45 | // IExtractImage/IExtractImage2 46 | STDMETHOD(GetLocation)(LPWSTR pszPathBuffer, DWORD cchMax, 47 | DWORD *pdwPriority, const SIZE *prgSize, 48 | DWORD dwRecClrDepth, DWORD *pdwFlags) { return m_cbx.OnGetLocation(prgSize, pdwFlags); } 49 | STDMETHOD(Extract)(HBITMAP* phBmpThumbnail) { return m_cbx.OnExtract(phBmpThumbnail); } 50 | // IExtractImage2 51 | STDMETHOD(GetDateStamp)(FILETIME *pDateStamp) { return m_cbx.OnGetDateStamp(pDateStamp);} 52 | 53 | // IQueryInfo 54 | STDMETHOD(GetInfoTip)(DWORD dwFlags, LPWSTR* ppwszTip) { return m_cbx.OnGetInfoTip(ppwszTip);} 55 | STDMETHOD(GetInfoFlags)(LPDWORD pdwFlags) { *pdwFlags = 0; return E_NOTIMPL;} 56 | 57 | private: 58 | __cbx::CCBXArchive m_cbx; 59 | }; 60 | 61 | 62 | #endif//_CBXSHELLCLASS_541926D5_D807_4CCB_9F35_8464657CC196_ 63 | -------------------------------------------------------------------------------- /CBXShell/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // stdafx.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | #ifdef _ATL_STATIC_REGISTRY 8 | #include 9 | #include 10 | #endif 11 | 12 | #include 13 | -------------------------------------------------------------------------------- /CBXShell/StdAfx.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDAFX_C5E3BAAB_1D97_4C7F_AB90_2D4397D95F13_ 2 | #define _STDAFX_C5E3BAAB_1D97_4C7F_AB90_2D4397D95F13_ 3 | #pragma once 4 | 5 | #ifndef UNICODE 6 | #define UNICODE// UNICODE-only project 7 | #endif 8 | 9 | #define STRICT 10 | 11 | #include "targetver.h" 12 | 13 | #define _ATL_APARTMENT_THREADED 14 | 15 | #include 16 | #include // WTL project 17 | 18 | extern CComModule _Module; 19 | 20 | #include 21 | 22 | 23 | #endif//_STDAFX_C5E3BAAB_1D97_4C7F_AB90_2D4397D95F13_ 24 | -------------------------------------------------------------------------------- /CBXShell/cbxArchive.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////// 2 | // v4.6 3 | ////////////////////////////////////////////// 4 | // CCBXShell functionality implementation 5 | 6 | #ifndef _CBXARCHIVE_442B998D_B9C0_4AB0_BB2A_BC9C0AA10053_ 7 | #define _CBXARCHIVE_442B998D_B9C0_4AB0_BB2A_BC9C0AA10053_ 8 | 9 | #ifndef STRICT 10 | #define STRICT 11 | #endif 12 | 13 | #include 14 | #include 15 | #pragma comment(lib,"shlwapi.lib") 16 | 17 | //#include "gdiplus.h" // uncomment if needed 18 | //#pragma comment(lib,"gdiplus.lib") 19 | 20 | //ATL headers 21 | //#include // uncomment if needed 22 | #include 23 | #include 24 | 25 | // WTL headers 26 | #include 27 | 28 | #include "unrar.h" 29 | #ifdef _WIN64 30 | #pragma comment(lib,"unrar64.lib") 31 | #else 32 | #pragma comment(lib,"unrar.lib") 33 | #endif 34 | #include "unzip.h" 35 | 36 | #define CBXMEM_MAXBUFFER_SIZE 33554432 //32mb 37 | #define CBXTYPE int 38 | #define CBXTYPE_NONE 0 39 | #define CBXTYPE_ZIP 1 40 | #define CBXTYPE_CBZ 2 41 | #define CBXTYPE_RAR 3 42 | #define CBXTYPE_CBR 4 43 | 44 | #define CBX_APP_KEY _T("Software\\T800 Productions\\{9E6ECB90-5A61-42BD-B851-D3297D9C7F39}") 45 | 46 | 47 | namespace __cbx { 48 | 49 | // unused 50 | //template class CBuffer 51 | //{ 52 | //public: 53 | // CBuffer(){m_buf=NULL;} 54 | // virtual ~CBuffer(){ ::CoTaskMemFree(m_buf); m_buf=NULL;} 55 | //public: 56 | // T* Allocate(SIZE_T s, BOOL bAutozero=FALSE) 57 | // { 58 | // m_buf=::CoTaskMemAlloc(s*sizeof(T));//COM compatible //'new' throws 59 | // if (m_buf && bAutozero) SecureZeroMemory(m_buf, s*sizeof(T)); 60 | // return (T*)m_buf; 61 | // } 62 | // operator LPVOID () {return m_buf;} 63 | // operator T* () {return (T*)m_buf;} 64 | //private: 65 | // LPVOID m_buf; 66 | //}; 67 | //typedef CBuffer CByteBuffer; 68 | 69 | 70 | 71 | class CUnzip 72 | { 73 | public: 74 | CUnzip() { hz=NULL; } 75 | virtual ~CUnzip(){::CloseZip(hz);} 76 | 77 | public: 78 | bool Open(LPCTSTR zfile) 79 | { 80 | if (zfile==NULL) return false; 81 | HZIP temp_hz=::OpenZip(zfile, NULL);//try new 82 | if (temp_hz==NULL) return false; 83 | Close();//close old 84 | hz=temp_hz; 85 | if (ZR_OK!=::GetZipItem(hz,-1, &maindirEntry)) return false; 86 | return true; 87 | } 88 | 89 | bool GetItem(int zi) 90 | { 91 | zr=::GetZipItem(hz, zi, &ZipEntry); 92 | return (ZR_OK==zr); 93 | } 94 | 95 | bool UnzipItemToMembuffer(int index, void *z,unsigned int len) 96 | { 97 | zr=::UnzipItem(hz, index, z, len); 98 | return (ZR_OK==zr); 99 | } 100 | 101 | void Close() 102 | { 103 | CloseZip(hz); 104 | hz=NULL;//critical! 105 | } 106 | 107 | inline BOOL ItemIsDirectory() {return (BOOL)(CUnzip::GetItemAttributes() & 0x0010);} 108 | int GetItemCount() const {return maindirEntry.index;} 109 | long GetItemPackedSize() const {return ZipEntry.comp_size;} 110 | long GetItemUnpackedSize() const {return ZipEntry.unc_size;} 111 | DWORD GetItemAttributes() const {return ZipEntry.attr;} 112 | LPCTSTR GetItemName() {return ZipEntry.name;} 113 | 114 | private: 115 | ZIPENTRY ZipEntry, maindirEntry; 116 | HZIP hz; 117 | ZRESULT zr; 118 | }; 119 | 120 | 121 | // unrar wrapper 122 | typedef const RARHeaderDataEx* LPCRARHeaderDataEx; 123 | typedef const RAROpenArchiveDataEx* LPCRAROpenArchiveDataEx; 124 | 125 | class CUnRar 126 | { 127 | public: 128 | CUnRar() { if (RAR_DLL_VERSION>RARGetDllVersion()) throw RAR_DLL_VERSION; _init(); } 129 | virtual ~CUnRar(){Close();_init();} 130 | 131 | public: 132 | BOOL Open(LPCTSTR rarfile, BOOL bListingOnly=TRUE, char* cmtBuf=NULL, UINT cmtBufSize=0, char* password=NULL) 133 | { 134 | if (m_harc) return FALSE;//must close old first 135 | 136 | SecureZeroMemory(&m_arcinfo, sizeof(RAROpenArchiveDataEx)); 137 | #ifndef UNICODE 138 | m_arcinfo.ArcName=(PTCHAR)rarfile; 139 | #else 140 | m_arcinfo.ArcNameW=(PTCHAR)rarfile; 141 | #endif 142 | m_arcinfo.OpenMode=bListingOnly ? RAR_OM_LIST : RAR_OM_EXTRACT; 143 | m_arcinfo.CmtBuf=cmtBuf; 144 | m_arcinfo.CmtBufSize=cmtBufSize; 145 | 146 | m_harc=RAROpenArchiveEx(&m_arcinfo); 147 | if (m_harc==NULL || m_arcinfo.OpenResult!=0) return FALSE; 148 | 149 | if (password) RARSetPassword(m_harc,password); 150 | RARSetCallback(m_harc, __rarCallbackProc, (LPARAM)this); 151 | return TRUE; 152 | } 153 | 154 | BOOL Close() { if (m_harc) m_ret=RARCloseArchive(m_harc); return (m_ret!=0);} 155 | 156 | inline LPCRAROpenArchiveDataEx GetArchiveInfo() {return &m_arcinfo;} 157 | inline LPCRARHeaderDataEx GetItemInfo() {return &m_iteminfo;} 158 | inline void SetPassword(char* password) {RARSetPassword(m_harc, password);} 159 | inline int GetLastError() {return m_ret;} 160 | 161 | //inline UINT GetArchiveFlags() {return m_arcinfo.Flags;} 162 | //inline UINT GetItemFlags(){return m_iteminfo.Flags;} 163 | inline BOOL IsArchiveVolume() {return (BOOL)(m_arcinfo.Flags & 0x0001);} 164 | inline BOOL IsArchiveComment() {return (BOOL)(m_arcinfo.Flags & 0x0002);} 165 | inline BOOL IsArchiveLocked() {return (BOOL)(m_arcinfo.Flags & 0x0004);} 166 | inline BOOL IsArchiveSolid() {return (BOOL)(m_arcinfo.Flags & 0x0008);} 167 | inline BOOL IsArchivePartN() {return (BOOL)(m_arcinfo.Flags & 0x0010);} 168 | inline BOOL IsArchiveSigned() {return (BOOL)(m_arcinfo.Flags & 0x0020);} 169 | inline BOOL IsArchiveRecoveryRecord() {return (BOOL)(m_arcinfo.Flags & 0x0040);} 170 | inline BOOL IsArchiveEncryptedHeaders() {return (BOOL)(m_arcinfo.Flags & 0x0080);} 171 | inline BOOL IsArchiveFirstVolume() {return (BOOL)(m_arcinfo.Flags & 0x0100);} 172 | 173 | BOOL ReadItemInfo() 174 | { 175 | SecureZeroMemory(&m_iteminfo, sizeof(RARHeaderDataEx)); 176 | m_ret=RARReadHeaderEx(m_harc, &m_iteminfo); 177 | return (m_ret==0); 178 | } 179 | 180 | inline BOOL IsItemDirectory() {return ((m_iteminfo.Flags & 0x00E0)==0x00E0);} 181 | 182 | inline LPCTSTR GetItemName() 183 | { 184 | #ifdef UNICODE 185 | return (LPCTSTR)(GetItemInfo()->FileNameW); 186 | #else 187 | return (LPCTSTR)CUnRar::GetItemInfo()->FileName; 188 | #endif 189 | } 190 | 191 | //MAKEUINT64 192 | inline UINT64 GetItemPackedSize64() {return ((((UINT64)m_iteminfo.PackSizeHigh)<<32) | m_iteminfo.PackSize);} 193 | inline UINT64 GetItemUnpackedSize64() {return ((((UINT64)m_iteminfo.UnpSizeHigh)<<32) | m_iteminfo.UnpSize);} 194 | 195 | virtual BOOL ProcessItem() 196 | { 197 | m_ret=RARProcessFileW(m_harc,RAR_TEST,NULL,NULL); 198 | if (m_ret!=0) return FALSE; 199 | return TRUE; 200 | } 201 | 202 | virtual BOOL SkipItem() 203 | { 204 | m_ret=RARProcessFile(m_harc,RAR_SKIP,NULL,NULL); 205 | return (m_ret==0); 206 | } 207 | 208 | virtual BOOL SkipItems(UINT64 si) 209 | { 210 | UINT64 _i;//0 skips? 211 | for (_i=0; _iWrite(pBuf, dwBufSize, &br)) 227 | if (br==dwBufSize) return 1; 228 | } 229 | return -1; 230 | } 231 | 232 | void SetIStream(IStream* pIs){_ASSERTE(pIs);m_pIs=pIs;} 233 | 234 | private: 235 | HANDLE m_harc; 236 | RARHeaderDataEx m_iteminfo; 237 | RAROpenArchiveDataEx m_arcinfo; 238 | int m_ret; 239 | IStream* m_pIs; 240 | void _init() 241 | { 242 | m_harc=NULL; 243 | m_pIs=NULL; 244 | m_ret=0; 245 | SecureZeroMemory(&m_arcinfo, sizeof(RAROpenArchiveDataEx)); 246 | SecureZeroMemory(&m_iteminfo, sizeof(RARHeaderDataEx)); 247 | } 248 | 249 | //raw callback function 250 | public: 251 | static int PASCAL __rarCallbackProc(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2) 252 | { 253 | CUnRar* _pc=(CUnRar*)UserData; 254 | return _pc->CallbackProc(msg,UserData,P1,P2); 255 | } 256 | }; 257 | 258 | 259 | class CCBXArchive 260 | { 261 | public: 262 | CCBXArchive() 263 | { 264 | m_bSort=TRUE;//default 265 | //GetRegSettings(); 266 | m_thumbSize.cx=m_thumbSize.cy=0; 267 | m_cbxType=CBXTYPE_NONE; 268 | m_pIs=NULL; 269 | } 270 | 271 | virtual ~CCBXArchive() 272 | { 273 | if (m_pIs) {m_pIs->Release(); m_pIs=NULL;} 274 | } 275 | 276 | public: 277 | //////////////////////////////////////// 278 | // IPersistFile::Load 279 | HRESULT OnLoad(LPCOLESTR wszFile) 280 | { 281 | //ATLTRACE("IPersistFile::Load\n"); 282 | #ifndef UNICODE 283 | USES_CONVERSION; 284 | m_cbxFile=OLE2T((WCHAR*)wszFile); 285 | #else 286 | m_cbxFile=wszFile; 287 | #endif 288 | m_cbxType=GetCBXType(PathFindExtension(m_cbxFile)); 289 | return S_OK; 290 | } 291 | 292 | //////////////////////////////////// 293 | // IExtractImage::GetLocation(LPWSTR pszPathBuffer, DWORD cchMax, DWORD *pdwPriority, const SIZE *prgSize, DWORD dwRecClrDepth, DWORD *pdwFlags) 294 | HRESULT OnGetLocation(const SIZE *prgSize, DWORD *pdwFlags) 295 | { 296 | //ATLTRACE("IExtractImage2::GetLocation\n"); 297 | m_thumbSize.cx=prgSize->cx; 298 | m_thumbSize.cy=prgSize->cy; 299 | *pdwFlags |= (IEIFLAG_CACHE | IEIFLAG_REFRESH);//cache thumbnails 300 | //if (*pdwFlags & IEIFLAG_ASYNC) return E_PENDING;//Windows XP and earlier 301 | #ifdef _DEBUG 302 | if (*pdwFlags & IEIFLAG_ASYNC) ATLTRACE("\nIExtractImage::GetLocation : IEIFLAG_ASYNC flag set\n"); 303 | #endif 304 | return NOERROR; 305 | } 306 | 307 | //////////////////////////////////// 308 | // IExtractImage2::GetDateStamp(FILETIME *pDateStamp) 309 | HRESULT OnGetDateStamp(FILETIME *pDateStamp) 310 | { 311 | //ATLTRACE("IExtractImage2::GetDateStamp\n"); 312 | FILETIME ftCreationTime, ftLastAccessTime, ftLastWriteTime; 313 | CAtlFile _f; 314 | if (S_OK!=_f.Create(m_cbxFile,GENERIC_READ,FILE_SHARE_READ,OPEN_EXISTING,0)) return E_FAIL; 315 | //alternatively GetFileInformationByHandle? 316 | if (!GetFileTime(_f, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime)) return E_FAIL; 317 | *pDateStamp = ftLastWriteTime; 318 | return NOERROR; 319 | } 320 | 321 | //////////////////////////////////// 322 | //IExtractImage::Extract(HBITMAP* phBmpThumbnail) 323 | HRESULT OnExtract(HBITMAP* phBmpThumbnail) 324 | { 325 | *phBmpThumbnail=NULL; 326 | //ATLTRACE("IExtractImage::Extract\n"); 327 | try { 328 | switch (m_cbxType) 329 | { 330 | case CBXTYPE_ZIP: 331 | case CBXTYPE_CBZ: 332 | { 333 | CUnzip _z; 334 | if (!_z.Open(m_cbxFile)) return E_FAIL; 335 | j=_z.GetItemCount(); 336 | if (j==0) return E_FAIL; 337 | 338 | CString prevname;//helper vars 339 | int thumbindex=-1; 340 | 341 | for (i=0; i CBXMEM_MAXBUFFER_SIZE)) continue; 345 | if ((_z.GetItemPackedSize()==0) || (_z.GetItemUnpackedSize()==0)) continue; 346 | 347 | if (IsImage(_z.GetItemName())) 348 | { 349 | if (thumbindex<0) thumbindex=i;// assign thumbindex if already sorted 350 | 351 | if (!m_bSort) break;//if NoSort 352 | 353 | if (prevname.IsEmpty()) prevname=_z.GetItemName();//can't compare empty string 354 | //take only first alphabetical name 355 | if (-1==StrCmpLogicalW(_z.GetItemName(), prevname)) 356 | { 357 | thumbindex=i; 358 | prevname=_z.GetItemName(); 359 | } 360 | } 361 | }//for loop 362 | 363 | if (thumbindex<0) return E_FAIL; 364 | //go to thumb index 365 | if (!_z.GetItem(thumbindex)) return E_FAIL; 366 | 367 | //create thumb //GHND 368 | HGLOBAL hG = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (SIZE_T)_z.GetItemUnpackedSize()); 369 | if (hG) 370 | { 371 | bool b=false; 372 | LPVOID pBuf=::GlobalLock(hG); 373 | if (pBuf) 374 | b=_z.UnzipItemToMembuffer(thumbindex, pBuf, _z.GetItemUnpackedSize()); 375 | 376 | if (::GlobalUnlock(hG)==0 && GetLastError()==NO_ERROR) 377 | { 378 | if (b) 379 | { 380 | IStream* pIs=NULL; 381 | if (S_OK==CreateStreamOnHGlobal(hG, TRUE, (LPSTREAM*)&pIs))//autofree hG 382 | { 383 | *phBmpThumbnail= ThumbnailFromIStream(pIs, &m_thumbSize); 384 | pIs->Release(); 385 | pIs=NULL; 386 | } 387 | } 388 | } 389 | //GlobalFree(hG);//autofreed 390 | } 391 | 392 | return ((*phBmpThumbnail) ? S_OK : E_FAIL); 393 | }//dtors! 394 | break; 395 | 396 | case CBXTYPE_RAR: 397 | case CBXTYPE_CBR: 398 | { 399 | CUnRar _r; 400 | __int64 thumbindex=-1; 401 | 402 | if (m_bSort) 403 | { 404 | thumbindex=FindThumbnailSortRAR(m_cbxFile); 405 | if (thumbindex<0) return E_FAIL; 406 | } 407 | 408 | if (!_r.Open(m_cbxFile, FALSE)) return E_FAIL; 409 | 410 | if (m_bSort) 411 | { 412 | //archive flags already checked, go to thumbindex 413 | if (!_r.SkipItems(thumbindex)) return E_FAIL; 414 | if (!_r.ReadItemInfo()) return E_FAIL; 415 | } 416 | else 417 | { 418 | //skip solid (long processing time), volumes or encrypted file headers 419 | if (_r.IsArchiveSolid() || _r.IsArchiveVolume() || _r.IsArchiveEncryptedHeaders()) return E_FAIL; 420 | 421 | while (_r.ReadItemInfo()) 422 | { 423 | //skip directory/empty/ file bigger than 32mb 424 | if (!(_r.IsItemDirectory() || (_r.GetItemPackedSize64()==0) || 425 | (_r.GetItemUnpackedSize64()==0) || (_r.GetItemUnpackedSize64() > CBXMEM_MAXBUFFER_SIZE))) 426 | { 427 | if (IsImage(_r.GetItemName())) {thumbindex=TRUE; break;} 428 | } 429 | 430 | _r.SkipItem();//don't forget 431 | } 432 | }//else 433 | 434 | if (thumbindex<0) return E_FAIL; 435 | 436 | //create thumb 437 | IStream* pIs = NULL; 438 | HGLOBAL hG = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, (SIZE_T)_r.GetItemUnpackedSize64()); 439 | if (hG) 440 | { 441 | if (S_OK==CreateStreamOnHGlobal(hG, TRUE, (LPSTREAM*)&pIs)) 442 | { 443 | _r.SetIStream(pIs); 444 | if (_r.ProcessItem()) *phBmpThumbnail= ThumbnailFromIStream(pIs, &m_thumbSize); 445 | } 446 | } 447 | GlobalFree(hG); 448 | pIs->Release(); 449 | return ((*phBmpThumbnail) ? S_OK : E_FAIL ); 450 | }//dtors! 451 | break; 452 | default:return E_FAIL; 453 | } 454 | } 455 | catch (...){ ATLTRACE("exception in IExtractImage::Extract\n"); return S_FALSE;} 456 | return S_OK; 457 | } 458 | 459 | 460 | ////////////////////////////// 461 | //IQueryInfo::GetInfoTip(DWORD dwFlags, LPWSTR *ppwszTip) 462 | HRESULT OnGetInfoTip(LPWSTR *ppwszTip) 463 | { 464 | //ATLTRACE("IQueryInfo::GetInfoTip\n"); 465 | try 466 | { 467 | CString tip; 468 | 469 | __int64 _fs; 470 | if (!GetFileSizeCrt(m_cbxFile, _fs)) return E_FAIL; 471 | 472 | TCHAR _tf[16];// SecureZeroMemory? 473 | 474 | switch (m_cbxType) 475 | { 476 | case CBXTYPE_ZIP: 477 | if (_fs==0) tip=_T("ZIP Archive\nSize: 0 bytes"); 478 | else 479 | { 480 | if (GetImageCountZIP(m_cbxFile, i,j)) 481 | tip.Format(_T("ZIP Archive\n%d Images\n%d Files\nSize: %s"), 482 | i, j, StrFormatByteSize64(_fs, _tf, 16)); 483 | else tip.Format(_T("ZIP Archive\nSize: %s"), StrFormatByteSize64(_fs, _tf, 16)); 484 | } 485 | break; 486 | case CBXTYPE_CBZ: 487 | if (_fs==0) tip=_T("ZIP Image Archive\nSize: 0 bytes"); 488 | else 489 | { 490 | if (GetImageCountZIP(m_cbxFile, i,j)) 491 | tip.Format(_T("ZIP Image Archive\n%d Images\n%d Files\nSize: %s"), 492 | i, j, StrFormatByteSize64(_fs, _tf, 16)); 493 | else tip.Format(_T("ZIP Image Archive\nSize: %s"), StrFormatByteSize64(_fs, _tf, 16)); 494 | } 495 | break; 496 | case CBXTYPE_RAR: 497 | if (_fs==0) tip=_T("RAR Archive\nSize: 0 bytes"); 498 | else 499 | { 500 | if (GetImageCountRAR(m_cbxFile, i,j)) 501 | tip.Format(_T("RAR Archive\n%d Images\n%d Files\nSize: %s"), 502 | i, j, StrFormatByteSize64(_fs, _tf, 16)); 503 | else tip.Format(_T("RAR Archive\nSize: %s"), StrFormatByteSize64(_fs, _tf, 16)); 504 | } 505 | break; 506 | case CBXTYPE_CBR: 507 | if (_fs==0) tip=_T("RAR Image Archive\nSize: 0 bytes"); 508 | else 509 | { 510 | if (GetImageCountRAR(m_cbxFile, i,j)) 511 | tip.Format(_T("RAR Image Archive\n%d Images\n%d Files\nSize: %s"), 512 | i, j, StrFormatByteSize64(_fs, _tf, 16)); 513 | else tip.Format(_T("RAR Image Archive\nSize: %s"), StrFormatByteSize64(_fs, _tf, 16)); 514 | } 515 | break; 516 | 517 | default: ATLTRACE("IQueryInfo::GetInfoTip : CBXTYPE_NONE\n");return E_FAIL; 518 | } 519 | 520 | *ppwszTip = (WCHAR*) ::CoTaskMemAlloc( (tip.GetLength()+1)*sizeof(WCHAR) );//caller must call CoTaskMemFree 521 | if (*ppwszTip==NULL) return E_FAIL; 522 | if (0!=::wcscpy_s(*ppwszTip, tip.GetLength()+1, tip)) return E_FAIL; 523 | 524 | return S_OK; 525 | } 526 | catch (...){ ATLTRACE("exception in IQueryInfo::GetInfoTip\n"); return S_FALSE;} 527 | 528 | return S_FALSE; 529 | } 530 | 531 | 532 | private: 533 | CString m_cbxFile;//overcome MAX_PATH limit? 534 | SIZE m_thumbSize; 535 | int i,j;//helpers 536 | CBXTYPE m_cbxType; 537 | IStream* m_pIs; 538 | BOOL m_bSort; 539 | 540 | 541 | private: 542 | inline BOOL GetFileSizeCrt(LPCTSTR pszFile, __int64 &fsize) 543 | { 544 | _stat64 _s; 545 | _s.st_size=0; 546 | if (0!=::_tstat64(pszFile, &_s)) return FALSE; 547 | fsize=_s.st_size; 548 | return TRUE; 549 | } 550 | 551 | inline BOOL StrEqual(LPCTSTR psz1,LPCTSTR psz2) {return (::StrCmpI(psz1, psz2)==0);} 552 | 553 | BOOL IsImage(LPCTSTR szFile) 554 | { 555 | LPWSTR _e=PathFindExtension(szFile); 556 | if (StrEqual(_e, _T(".bmp"))) return TRUE; 557 | if (StrEqual(_e, _T(".ico"))) return TRUE; 558 | if (StrEqual(_e, _T(".gif"))) return TRUE; 559 | if (StrEqual(_e, _T(".jpg"))) return TRUE; 560 | if (StrEqual(_e, _T(".jpe"))) return TRUE; 561 | if (StrEqual(_e, _T(".jfif"))) return TRUE; 562 | if (StrEqual(_e, _T(".jpeg"))) return TRUE; 563 | if (StrEqual(_e, _T(".png"))) return TRUE; 564 | if (StrEqual(_e, _T(".tif"))) return TRUE; 565 | if (StrEqual(_e, _T(".tiff"))) return TRUE; 566 | return FALSE; 567 | } 568 | 569 | inline CBXTYPE GetCBXType(LPCTSTR szExt) 570 | { 571 | if (StrEqual(szExt, _T(".cbz"))) return CBXTYPE_CBZ; 572 | if (StrEqual(szExt, _T(".zip"))) return CBXTYPE_ZIP; 573 | if (StrEqual(szExt, _T(".cbr"))) return CBXTYPE_CBR; 574 | if (StrEqual(szExt, _T(".rar"))) return CBXTYPE_RAR; 575 | //by popular demand 576 | if (StrEqual(szExt, _T(".epub"))) return CBXTYPE_CBZ; 577 | if (StrEqual(szExt, _T(".phz"))) return CBXTYPE_CBZ; 578 | return CBXTYPE_NONE; 579 | } 580 | 581 | BOOL GetImageCountZIP(LPCTSTR cbzFile, int &imagecount, int &filecount) 582 | { 583 | imagecount=0; 584 | filecount=0; 585 | 586 | CUnzip _z; 587 | if (!_z.Open(cbzFile)) return FALSE; 588 | //empty zip is still valid 589 | if (_z.GetItemCount()==0) return TRUE; 590 | 591 | int _i; 592 | for (_i=0; _i<_z.GetItemCount(); _i++) 593 | { 594 | if (!_z.GetItem(_i)) return FALSE; 595 | //skip dirs 596 | if (_z.ItemIsDirectory()) continue; 597 | if (IsImage(_z.GetItemName())) imagecount+=1; 598 | filecount+=1; 599 | } 600 | return TRUE; 601 | } 602 | 603 | BOOL GetImageCountRAR(LPCTSTR cbrFile, int &imagecount, int &filecount) 604 | { 605 | imagecount=0; 606 | filecount=0; 607 | 608 | CUnRar cr; 609 | if (!cr.Open(cbrFile)) return FALSE; 610 | 611 | //enum solid / skip volumes or encrypted file header archives 612 | if (cr.IsArchiveVolume() || cr.IsArchiveEncryptedHeaders()) return FALSE; 613 | 614 | while (cr.ReadItemInfo()) 615 | { 616 | //skip dirs 617 | if (!cr.IsItemDirectory()) 618 | { 619 | if (IsImage(cr.GetItemName())) imagecount+=1; 620 | filecount+=1; 621 | } 622 | if (!cr.SkipItem()) return FALSE; 623 | } 624 | return TRUE; 625 | } 626 | 627 | 628 | HBITMAP ThumbnailFromIStream(IStream* pIs, const LPSIZE pThumbSize) 629 | { 630 | ATLASSERT(pIs); 631 | CImage ci;//uses gdi+ internally 632 | if (S_OK!=ci.Load(pIs)) return NULL; 633 | 634 | //check size 635 | int tw=ci.GetWidth(); 636 | int th=ci.GetHeight(); 637 | float rx=(float)pThumbSize->cx/(float)tw; 638 | float ry=(float)pThumbSize->cy/(float)th; 639 | 640 | //if bigger size 641 | if ((rx<1) || (ry<1)) 642 | { 643 | CDC hdcNew=::CreateCompatibleDC(NULL); 644 | if (hdcNew.IsNull()) return NULL; 645 | 646 | hdcNew.SetStretchBltMode(HALFTONE); 647 | hdcNew.SetBrushOrg(0,0, NULL); 648 | //variables retain values until assignment 649 | tw=(int)(min(rx,ry)*tw);//C424 warning workaround 650 | th=(int)(min(rx,ry)*th); 651 | 652 | CBitmap hbmpNew; 653 | hbmpNew.CreateCompatibleBitmap(ci.GetDC(), tw,th); 654 | ci.ReleaseDC();//don't forget! 655 | if (hbmpNew.IsNull()) return NULL; 656 | 657 | HBITMAP hbmpOld=hdcNew.SelectBitmap(hbmpNew); 658 | hdcNew.FillSolidRect(0,0, tw,th, RGB(255,255,255));//white background 659 | ci.Draw(hdcNew, 0,0, tw,th, 0,0, ci.GetWidth(),ci.GetHeight());//too late for error checks 660 | hdcNew.SelectBitmap(hbmpOld); 661 | 662 | return hbmpNew.Detach(); 663 | } 664 | 665 | return ci.Detach(); 666 | } 667 | 668 | ////unused 669 | //HBITMAP ThumbnailFromBuffer(LPCBYTE pBuf, const ULONG dwBufSize, const LPSIZE pThumbSize) 670 | //{ 671 | // HBITMAP hBmp = NULL; 672 | // IStream* pIs = NULL; 673 | // HGLOBAL hG = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, dwBufSize); 674 | // if (hG) 675 | // { 676 | // if (S_OK==CreateStreamOnHGlobal(hG, TRUE, (LPSTREAM*)&pIs)) 677 | // { 678 | // ULONG br; 679 | // if (S_OK==pIs->Write(pBuf, dwBufSize, &br))//transfer buffer data 680 | // { 681 | // if (br==dwBufSize) hBmp=ThumbnailFromIStream(pIs, pThumbSize); 682 | // } 683 | // } 684 | // } 685 | // GlobalFree(hG); 686 | // pIs->Release(); 687 | //return hBmp; 688 | //} 689 | 690 | 691 | __int64 FindThumbnailSortRAR(LPCTSTR pszFile) 692 | { 693 | CUnRar _r; 694 | if (!_r.Open(pszFile)) return -1; 695 | //skip solid (long processing time), volumes or encrypted file headers 696 | if (_r.IsArchiveSolid() || _r.IsArchiveVolume() || _r.IsArchiveEncryptedHeaders()) return -1; 697 | 698 | UINT64 _ps,_us;//my speed optimization? 699 | CString prevname; 700 | __int64 thumbindex=-1; 701 | __int64 i=-1;//start at none (-1) 702 | 703 | while (_r.ReadItemInfo()) 704 | { 705 | i+=1; 706 | _ps=_r.GetItemPackedSize64(); 707 | _us=_r.GetItemUnpackedSize64(); 708 | 709 | //skip directory/emtpy file/bigger than 32mb 710 | if (_r.IsItemDirectory() || (_us>CBXMEM_MAXBUFFER_SIZE) || (_ps==0) || (_us==0)) 711 | {_r.SkipItem();continue;} 712 | 713 | //take only index of first alphabetical name 714 | if (IsImage(_r.GetItemName())) 715 | { 716 | //can't compare empty string 717 | if (prevname.IsEmpty()) prevname=_r.GetItemName(); 718 | if (thumbindex<0) thumbindex=i;// assign thumbindex if already sorted 719 | //sort by name 720 | if (-1==StrCmpLogicalW(_r.GetItemName(), prevname)) 721 | { 722 | thumbindex=i; 723 | prevname=_r.GetItemName(); 724 | } 725 | } 726 | _r.SkipItem();//don't forget 727 | } 728 | 729 | return thumbindex; 730 | } 731 | 732 | public: 733 | void LoadRegistrySettings() 734 | { 735 | DWORD _d; 736 | CRegKey _rk; 737 | if (ERROR_SUCCESS==_rk.Open(HKEY_CURRENT_USER, CBX_APP_KEY, KEY_READ)) 738 | { 739 | if (ERROR_SUCCESS==_rk.QueryDWORDValue(_T("NoSort"), _d)) 740 | m_bSort=(_d==FALSE); 741 | } 742 | } 743 | 744 | #ifdef _DEBUG 745 | public: 746 | void debug_SetSort(BOOL bS=TRUE) {m_bSort=bS;} 747 | #endif 748 | 749 | };//class _CCBXArchive 750 | 751 | }//namespace __cbx 752 | 753 | #endif//_CBXARCHIVE_442B998D_B9C0_4AB0_BB2A_BC9C0AA10053_ 754 | -------------------------------------------------------------------------------- /CBXShell/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef IDC_STATIC 2 | #define IDC_STATIC (-1) 3 | #endif 4 | 5 | #define IDR_CBXShell 102 6 | #define IDS_PROJNAME 40000 7 | #define IDS_CBXSHELL_DESC 40001 8 | -------------------------------------------------------------------------------- /CBXShell/targetver.h: -------------------------------------------------------------------------------- 1 | #ifndef _TARGETVER_E445D0B7_6F75_4678_BE5E_274C8455B5A4_ 2 | #define _TARGETVER_E445D0B7_6F75_4678_BE5E_274C8455B5A4_ 3 | 4 | 5 | //#define WINVER 0x0500 6 | #define _WIN32_WINNT _WIN32_WINNT_WINXP 7 | //#define _WIN32_IE _WIN32_IE_IE55 // StrCmpLogicalW needs 5.5 min 8 | //#define _RICHEDIT_VER 0x0200 9 | 10 | 11 | #endif//_TARGETVER_E445D0B7_6F75_4678_BE5E_274C8455B5A4_ 12 | -------------------------------------------------------------------------------- /CBXShell/unrar.h: -------------------------------------------------------------------------------- 1 | #ifndef _UNRAR_DLL_ 2 | #define _UNRAR_DLL_ 3 | 4 | #pragma pack(1) 5 | 6 | #define ERAR_END_ARCHIVE 10 7 | #define ERAR_NO_MEMORY 11 8 | #define ERAR_BAD_DATA 12 9 | #define ERAR_BAD_ARCHIVE 13 10 | #define ERAR_UNKNOWN_FORMAT 14 11 | #define ERAR_EOPEN 15 12 | #define ERAR_ECREATE 16 13 | #define ERAR_ECLOSE 17 14 | #define ERAR_EREAD 18 15 | #define ERAR_EWRITE 19 16 | #define ERAR_SMALL_BUF 20 17 | #define ERAR_UNKNOWN 21 18 | #define ERAR_MISSING_PASSWORD 22 19 | 20 | #define RAR_OM_LIST 0 21 | #define RAR_OM_EXTRACT 1 22 | #define RAR_OM_LIST_INCSPLIT 2 23 | 24 | #define RAR_SKIP 0 25 | #define RAR_TEST 1 26 | #define RAR_EXTRACT 2 27 | 28 | #define RAR_VOL_ASK 0 29 | #define RAR_VOL_NOTIFY 1 30 | 31 | #define RAR_DLL_VERSION 5 32 | 33 | #ifdef _UNIX 34 | #define CALLBACK 35 | #define PASCAL 36 | #define LONG long 37 | #define HANDLE void * 38 | #define LPARAM long 39 | #define UINT unsigned int 40 | #endif 41 | 42 | struct RARHeaderData 43 | { 44 | char ArcName[260]; 45 | char FileName[260]; 46 | unsigned int Flags; 47 | unsigned int PackSize; 48 | unsigned int UnpSize; 49 | unsigned int HostOS; 50 | unsigned int FileCRC; 51 | unsigned int FileTime; 52 | unsigned int UnpVer; 53 | unsigned int Method; 54 | unsigned int FileAttr; 55 | char *CmtBuf; 56 | unsigned int CmtBufSize; 57 | unsigned int CmtSize; 58 | unsigned int CmtState; 59 | }; 60 | 61 | 62 | struct RARHeaderDataEx 63 | { 64 | char ArcName[1024]; 65 | wchar_t ArcNameW[1024]; 66 | char FileName[1024]; 67 | wchar_t FileNameW[1024]; 68 | unsigned int Flags; 69 | unsigned int PackSize; 70 | unsigned int PackSizeHigh; 71 | unsigned int UnpSize; 72 | unsigned int UnpSizeHigh; 73 | unsigned int HostOS; 74 | unsigned int FileCRC; 75 | unsigned int FileTime; 76 | unsigned int UnpVer; 77 | unsigned int Method; 78 | unsigned int FileAttr; 79 | char *CmtBuf; 80 | unsigned int CmtBufSize; 81 | unsigned int CmtSize; 82 | unsigned int CmtState; 83 | unsigned int Reserved[1024]; 84 | }; 85 | 86 | 87 | struct RAROpenArchiveData 88 | { 89 | char *ArcName; 90 | unsigned int OpenMode; 91 | unsigned int OpenResult; 92 | char *CmtBuf; 93 | unsigned int CmtBufSize; 94 | unsigned int CmtSize; 95 | unsigned int CmtState; 96 | }; 97 | 98 | typedef int (CALLBACK *UNRARCALLBACK)(UINT msg,LPARAM UserData,LPARAM P1,LPARAM P2); 99 | 100 | struct RAROpenArchiveDataEx 101 | { 102 | char *ArcName; 103 | wchar_t *ArcNameW; 104 | unsigned int OpenMode; 105 | unsigned int OpenResult; 106 | char *CmtBuf; 107 | unsigned int CmtBufSize; 108 | unsigned int CmtSize; 109 | unsigned int CmtState; 110 | unsigned int Flags; 111 | UNRARCALLBACK Callback; 112 | LPARAM UserData; 113 | unsigned int Reserved[28]; 114 | }; 115 | 116 | enum UNRARCALLBACK_MESSAGES { 117 | UCM_CHANGEVOLUME,UCM_PROCESSDATA,UCM_NEEDPASSWORD 118 | }; 119 | 120 | typedef int (PASCAL *CHANGEVOLPROC)(char *ArcName,int Mode); 121 | typedef int (PASCAL *PROCESSDATAPROC)(unsigned char *Addr,int Size); 122 | 123 | #ifdef __cplusplus 124 | extern "C" { 125 | #endif 126 | 127 | HANDLE PASCAL RAROpenArchive(struct RAROpenArchiveData *ArchiveData); 128 | HANDLE PASCAL RAROpenArchiveEx(struct RAROpenArchiveDataEx *ArchiveData); 129 | int PASCAL RARCloseArchive(HANDLE hArcData); 130 | int PASCAL RARReadHeader(HANDLE hArcData,struct RARHeaderData *HeaderData); 131 | int PASCAL RARReadHeaderEx(HANDLE hArcData,struct RARHeaderDataEx *HeaderData); 132 | int PASCAL RARProcessFile(HANDLE hArcData,int Operation,char *DestPath,char *DestName); 133 | int PASCAL RARProcessFileW(HANDLE hArcData,int Operation,wchar_t *DestPath,wchar_t *DestName); 134 | void PASCAL RARSetCallback(HANDLE hArcData,UNRARCALLBACK Callback,LPARAM UserData); 135 | void PASCAL RARSetChangeVolProc(HANDLE hArcData,CHANGEVOLPROC ChangeVolProc); 136 | void PASCAL RARSetProcessDataProc(HANDLE hArcData,PROCESSDATAPROC ProcessDataProc); 137 | void PASCAL RARSetPassword(HANDLE hArcData,char *Password); 138 | int PASCAL RARGetDllVersion(); 139 | 140 | #ifdef __cplusplus 141 | } 142 | #endif 143 | 144 | #pragma pack() 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /CBXShell/unrar.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/T800G/CBXShell/de61b6c3308384967f5b79ec01ffb8ba2f528bd6/CBXShell/unrar.lib -------------------------------------------------------------------------------- /CBXShell/unrar64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/T800G/CBXShell/de61b6c3308384967f5b79ec01ffb8ba2f528bd6/CBXShell/unrar64.lib -------------------------------------------------------------------------------- /CBXShell/unzip.h: -------------------------------------------------------------------------------- 1 | #ifndef _unzip_H 2 | #define _unzip_H 3 | // 4 | #ifdef ZIP_STD 5 | #include 6 | #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name 7 | #ifndef MAX_PATH 8 | #define MAX_PATH 1024 9 | #endif 10 | typedef unsigned long DWORD; 11 | typedef char TCHAR; 12 | typedef FILE* HANDLE; 13 | typedef time_t FILETIME; 14 | #endif 15 | 16 | // UNZIPPING functions -- for unzipping. 17 | // This file is a repackaged form of extracts from the zlib code available 18 | // at www.gzip.org/zlib, by Jean-Loup Gailly and Mark Adler. The original 19 | // copyright notice may be found in unzip.cpp. The repackaging was done 20 | // by Lucian Wischik to simplify and extend its use in Windows/C++. Also 21 | // encryption and unicode filenames have been added. 22 | 23 | 24 | #ifndef _zip_H 25 | DECLARE_HANDLE(HZIP); 26 | #endif 27 | // An HZIP identifies a zip file that has been opened 28 | 29 | typedef DWORD ZRESULT; 30 | // return codes from any of the zip functions. Listed later. 31 | 32 | typedef struct 33 | { int index; // index of this file within the zip 34 | TCHAR name[MAX_PATH]; // filename within the zip 35 | DWORD attr; // attributes, as in GetFileAttributes. 36 | FILETIME atime,ctime,mtime;// access, create, modify filetimes 37 | long comp_size; // sizes of item, compressed and uncompressed. These 38 | long unc_size; // may be -1 if not yet known (e.g. being streamed in) 39 | } ZIPENTRY; 40 | 41 | 42 | HZIP OpenZip(const TCHAR *fn, const char *password); 43 | HZIP OpenZip(void *z,unsigned int len, const char *password); 44 | HZIP OpenZipHandle(HANDLE h, const char *password); 45 | // OpenZip - opens a zip file and returns a handle with which you can 46 | // subsequently examine its contents. You can open a zip file from: 47 | // from a pipe: OpenZipHandle(hpipe_read,0); 48 | // from a file (by handle): OpenZipHandle(hfile,0); 49 | // from a file (by name): OpenZip("c:\\test.zip","password"); 50 | // from a memory block: OpenZip(bufstart, buflen,0); 51 | // If the file is opened through a pipe, then items may only be 52 | // accessed in increasing order, and an item may only be unzipped once, 53 | // although GetZipItem can be called immediately before and after unzipping 54 | // it. If it's opened in any other way, then full random access is possible. 55 | // Note: pipe input is not yet implemented. 56 | // Note: zip passwords are ascii, not unicode. 57 | // Note: for windows-ce, you cannot close the handle until after CloseZip. 58 | // but for real windows, the zip makes its own copy of your handle, so you 59 | // can close yours anytime. 60 | 61 | ZRESULT GetZipItem(HZIP hz, int index, ZIPENTRY *ze); 62 | // GetZipItem - call this to get information about an item in the zip. 63 | // If index is -1 and the file wasn't opened through a pipe, 64 | // then it returns information about the whole zipfile 65 | // (and in particular ze.index returns the number of index items). 66 | // Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY) 67 | // See below for notes on what happens when you unzip such an item. 68 | // Note: if you are opening the zip through a pipe, then random access 69 | // is not possible and GetZipItem(-1) fails and you can't discover the number 70 | // of items except by calling GetZipItem on each one of them in turn, 71 | // starting at 0, until eventually the call fails. Also, in the event that 72 | // you are opening through a pipe and the zip was itself created into a pipe, 73 | // then then comp_size and sometimes unc_size as well may not be known until 74 | // after the item has been unzipped. 75 | 76 | ZRESULT FindZipItem(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze); 77 | // FindZipItem - finds an item by name. ic means 'insensitive to case'. 78 | // It returns the index of the item, and returns information about it. 79 | // If nothing was found, then index is set to -1 and the function returns 80 | // an error code. 81 | 82 | ZRESULT UnzipItem(HZIP hz, int index, const TCHAR *fn); 83 | ZRESULT UnzipItem(HZIP hz, int index, void *z,unsigned int len); 84 | ZRESULT UnzipItemHandle(HZIP hz, int index, HANDLE h); 85 | // UnzipItem - given an index to an item, unzips it. You can unzip to: 86 | // to a pipe: UnzipItemHandle(hz,i, hpipe_write); 87 | // to a file (by handle): UnzipItemHandle(hz,i, hfile); 88 | // to a file (by name): UnzipItem(hz,i, ze.name); 89 | // to a memory block: UnzipItem(hz,i, buf,buflen); 90 | // In the final case, if the buffer isn't large enough to hold it all, 91 | // then the return code indicates that more is yet to come. If it was 92 | // large enough, and you want to know precisely how big, GetZipItem. 93 | // Note: zip files are normally stored with relative pathnames. If you 94 | // unzip with ZIP_FILENAME a relative pathname then the item gets created 95 | // relative to the current directory - it first ensures that all necessary 96 | // subdirectories have been created. Also, the item may itself be a directory. 97 | // If you unzip a directory with ZIP_FILENAME, then the directory gets created. 98 | // If you unzip it to a handle or a memory block, then nothing gets created 99 | // and it emits 0 bytes. 100 | ZRESULT SetUnzipBaseDir(HZIP hz, const TCHAR *dir); 101 | // if unzipping to a filename, and it's a relative filename, then it will be relative to here. 102 | // (defaults to current-directory). 103 | 104 | 105 | ZRESULT CloseZip(HZIP hz); 106 | // CloseZip - the zip handle must be closed with this function. 107 | 108 | unsigned int FormatZipMessage(ZRESULT code, TCHAR *buf,unsigned int len); 109 | // FormatZipMessage - given an error code, formats it as a string. 110 | // It returns the length of the error message. If buf/len points 111 | // to a real buffer, then it also writes as much as possible into there. 112 | 113 | 114 | // These are the result codes: 115 | #define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned, 116 | #define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage. 117 | // The following come from general system stuff (e.g. files not openable) 118 | #define ZR_GENMASK 0x0000FF00 119 | #define ZR_NODUPH 0x00000100 // couldn't duplicate the handle 120 | #define ZR_NOFILE 0x00000200 // couldn't create/open the file 121 | #define ZR_NOALLOC 0x00000300 // failed to allocate some resource 122 | #define ZR_WRITE 0x00000400 // a general error writing to the file 123 | #define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip 124 | #define ZR_MORE 0x00000600 // there's still more data to be unzipped 125 | #define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile 126 | #define ZR_READ 0x00000800 // a general error reading the file 127 | #define ZR_PASSWORD 0x00001000 // we didn't get the right password to unzip the file 128 | // The following come from mistakes on the part of the caller 129 | #define ZR_CALLERMASK 0x00FF0000 130 | #define ZR_ARGS 0x00010000 // general mistake with the arguments 131 | #define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't 132 | #define ZR_MEMSIZE 0x00030000 // the memory size is too small 133 | #define ZR_FAILED 0x00040000 // the thing was already failed when you called this function 134 | #define ZR_ENDED 0x00050000 // the zip creation has already been closed 135 | #define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken 136 | #define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped 137 | #define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip 138 | // The following come from bugs within the zip library itself 139 | #define ZR_BUGMASK 0xFF000000 140 | #define ZR_NOTINITED 0x01000000 // initialisation didn't work 141 | #define ZR_SEEK 0x02000000 // trying to seek in an unseekable file 142 | #define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed 143 | #define ZR_FLATE 0x05000000 // an internal error in the de/inflation code 144 | 145 | 146 | 147 | 148 | 149 | // e.g. 150 | // 151 | // SetCurrentDirectory("c:\\docs\\stuff"); 152 | // HZIP hz = OpenZip("c:\\stuff.zip",0); 153 | // ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index; 154 | // for (int i=0; iInternet Explorer 6 or later 7 | -------------------------------------------------------------------------------- /The Code Project Open License (CPOL) 1.02.md: -------------------------------------------------------------------------------- 1 |

The Code Project Open License (CPOL) 1.02

2 |
3 | 4 |
5 |
6 | 7 |

Preamble

8 |

9 | This License governs Your use of the Work. This License is intended to allow developers 10 | to use the Source Code and Executable Files provided as part of the Work in any 11 | application in any form. 12 |

13 |

14 | The main points subject to the terms of the License are:

15 |
    16 |
  • Source Code and Executable Files can be used in commercial applications;
  • 17 |
  • Source Code and Executable Files can be redistributed; and
  • 18 |
  • Source Code can be modified to create derivative works.
  • 19 |
  • No claim of suitability, guarantee, or any warranty whatsoever is provided. The software is 20 | provided "as-is".
  • 21 |
  • The Article accompanying the Work may not be distributed or republished without the 22 | Author's consent
  • 23 |
24 | 25 |

26 | This License is entered between You, the individual or other entity reading or otherwise 27 | making use of the Work licensed pursuant to this License and the individual or other 28 | entity which offers the Work under the terms of this License ("Author").

29 | 30 |

License

31 |

32 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CODE PROJECT OPEN 33 | LICENSE ("LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE 34 | LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT 35 | LAW IS PROHIBITED.

36 |

37 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HEREIN, YOU ACCEPT AND AGREE TO BE 38 | BOUND BY THE TERMS OF THIS LICENSE. THE AUTHOR GRANTS YOU THE RIGHTS CONTAINED HEREIN 39 | IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. IF YOU DO NOT 40 | AGREE TO ACCEPT AND BE BOUND BY THE TERMS OF THIS LICENSE, YOU CANNOT MAKE ANY 41 | USE OF THE WORK.

42 | 43 |
    44 |
  1. Definitions. 45 | 46 |
      47 |
    1. "Articles" means, collectively, all articles written by Author 48 | which describes how the Source Code and Executable Files for the Work may be used 49 | by a user.
    2. 50 |
    3. "Author" means the individual or entity that offers the Work under the terms 51 | of this License.
    4. 52 |
    5. "Derivative Work" means a work based upon the Work or upon the 53 | Work and other pre-existing works.
    6. 54 |
    7. "Executable Files" refer to the executables, binary files, configuration 55 | and any required data files included in the Work.
    8. 56 |
    9. "Publisher" means the provider of the website, magazine, CD-ROM, DVD or other 57 | medium from or by which the Work is obtained by You.
    10. 58 |
    11. "Source Code" refers to the collection of source code and configuration files 59 | used to create the Executable Files.
    12. 60 |
    13. "Standard Version" refers to such a Work if it has not been modified, or 61 | has been modified in accordance with the consent of the Author, such consent being 62 | in the full discretion of the Author.
    14. 63 |
    15. "Work" refers to the collection of files distributed by the Publisher, including 64 | the Source Code, Executable Files, binaries, data files, documentation, whitepapers 65 | and the Articles.
    16. 66 |
    17. "You" is you, an individual or entity wishing to use the Work and exercise 67 | your rights under this License. 68 |
    18. 69 |
    70 |
  2. 71 | 72 |
  3. Fair Use/Fair Use Rights. Nothing in this License is intended to 73 | reduce, limit, or restrict any rights arising from fair use, fair dealing, first 74 | sale or other limitations on the exclusive rights of the copyright owner under copyright 75 | law or other applicable laws. 76 |
  4. 77 | 78 |
  5. License Grant. Subject to the terms and conditions of this License, 79 | the Author hereby grants You a worldwide, royalty-free, non-exclusive, perpetual 80 | (for the duration of the applicable copyright) license to exercise the rights in 81 | the Work as stated below: 82 | 83 |
      84 |
    1. You may use the standard version of the Source Code or Executable Files in Your 85 | own applications.
    2. 86 |
    3. You may apply bug fixes, portability fixes and other modifications obtained from 87 | the Public Domain or from the Author. A Work modified in such a way shall still 88 | be considered the standard version and will be subject to this License.
    4. 89 |
    5. You may otherwise modify Your copy of this Work (excluding the Articles) in any 90 | way to create a Derivative Work, provided that You insert a prominent notice in 91 | each changed file stating how, when and where You changed that file.
    6. 92 |
    7. You may distribute the standard version of the Executable Files and Source Code 93 | or Derivative Work in aggregate with other (possibly commercial) programs as part 94 | of a larger (possibly commercial) software distribution.
    8. 95 |
    9. The Articles discussing the Work published in any form by the author may not be 96 | distributed or republished without the Author's consent. The author retains 97 | copyright to any such Articles. You may use the Executable Files and Source Code 98 | pursuant to this License but you may not repost or republish or otherwise distribute 99 | or make available the Articles, without the prior written consent of the Author.
    10. 100 |
    101 | 102 | Any subroutines or modules supplied by You and linked into the Source Code or Executable 103 | Files of this Work shall not be considered part of this Work and will not be subject 104 | to the terms of this License. 105 |
  6. 106 | 107 |
  7. Patent License. Subject to the terms and conditions of this License, 108 | each Author hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 109 | irrevocable (except as stated in this section) patent license to make, have made, use, import, 110 | and otherwise transfer the Work.
  8. 111 | 112 |
  9. Restrictions. The license granted in Section 3 above is expressly 113 | made subject to and limited by the following restrictions: 114 | 115 |
      116 |
    1. You agree not to remove any of the original copyright, patent, trademark, and 117 | attribution notices and associated disclaimers that may appear in the Source Code 118 | or Executable Files.
    2. 119 |
    3. You agree not to advertise or in any way imply that this Work is a product of Your 120 | own.
    4. 121 |
    5. The name of the Author may not be used to endorse or promote products derived from 122 | the Work without the prior written consent of the Author.
    6. 123 |
    7. You agree not to sell, lease, or rent any part of the Work. This does not restrict 124 | you from including the Work or any part of the Work inside a larger software 125 | distribution that itself is being sold. The Work by itself, though, cannot be sold, 126 | leased or rented.
    8. 127 |
    9. You may distribute the Executable Files and Source Code only under the terms of 128 | this License, and You must include a copy of, or the Uniform Resource Identifier 129 | for, this License with every copy of the Executable Files or Source Code You distribute 130 | and ensure that anyone receiving such Executable Files and Source Code agrees that 131 | the terms of this License apply to such Executable Files and/or Source Code. You 132 | may not offer or impose any terms on the Work that alter or restrict the terms of 133 | this License or the recipients' exercise of the rights granted hereunder. You 134 | may not sublicense the Work. You must keep intact all notices that refer to this 135 | License and to the disclaimer of warranties. You may not distribute the Executable 136 | Files or Source Code with any technological measures that control access or use 137 | of the Work in a manner inconsistent with the terms of this License.
    10. 138 |
    11. You agree not to use the Work for illegal, immoral or improper purposes, or on pages 139 | containing illegal, immoral or improper material. The Work is subject to applicable 140 | export laws. You agree to comply with all such laws and regulations that may apply 141 | to the Work after Your receipt of the Work. 142 |
    12. 143 |
    144 |
  10. 145 | 146 |
  11. Representations, Warranties and Disclaimer. THIS WORK IS PROVIDED 147 | "AS IS", "WHERE IS" AND "AS AVAILABLE", WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES 148 | OR CONDITIONS OR GUARANTEES. YOU, THE USER, ASSUME ALL RISK IN ITS USE, INCLUDING 149 | COPYRIGHT INFRINGEMENT, PATENT INFRINGEMENT, SUITABILITY, ETC. AUTHOR EXPRESSLY 150 | DISCLAIMS ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES OR CONDITIONS, INCLUDING 151 | WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF MERCHANTABILITY, MERCHANTABLE QUALITY 152 | OR FITNESS FOR A PARTICULAR PURPOSE, OR ANY WARRANTY OF TITLE OR NON-INFRINGEMENT, 153 | OR THAT THE WORK (OR ANY PORTION THEREOF) IS CORRECT, USEFUL, BUG-FREE OR FREE OF 154 | VIRUSES. YOU MUST PASS THIS DISCLAIMER ON WHENEVER YOU DISTRIBUTE THE WORK OR DERIVATIVE 155 | WORKS. 156 |
  12. 157 | 158 |
  13. Indemnity. You agree to defend, indemnify and hold harmless the Author and 159 | the Publisher from and against any claims, suits, losses, damages, liabilities, 160 | costs, and expenses (including reasonable legal or attorneys fees) resulting from 161 | or relating to any use of the Work by You. 162 |
  14. 163 | 164 |
  15. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE 165 | LAW, IN NO EVENT WILL THE AUTHOR OR THE PUBLISHER BE LIABLE TO YOU ON ANY LEGAL 166 | THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES 167 | ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK OR OTHERWISE, EVEN IF THE AUTHOR 168 | OR THE PUBLISHER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 169 |
  16. 170 | 171 |
  17. Termination. 172 | 173 |
      174 |
    1. This License and the rights granted hereunder will terminate automatically upon 175 | any breach by You of any term of this License. Individuals or entities who have 176 | received Derivative Works from You under this License, however, will not have their 177 | licenses terminated provided such individuals or entities remain in full compliance 178 | with those licenses. Sections 1, 2, 6, 7, 8, 9, 10 and 11 will survive any termination 179 | of this License.
    2. 180 | 181 |
    3. If You bring a copyright, trademark, patent or any other infringement claim against 182 | any contributor over infringements You claim are made by the Work, your License 183 | from such contributor to the Work ends automatically.
    4. 184 | 185 |
    5. Subject to the above terms and conditions, this License is perpetual (for the duration 186 | of the applicable copyright in the Work). Notwithstanding the above, the Author 187 | reserves the right to release the Work under different license terms or to stop 188 | distributing the Work at any time; provided, however that any such election will 189 | not serve to withdraw this License (or any other license that has been, or is required 190 | to be, granted under the terms of this License), and this License will continue 191 | in full force and effect unless terminated as stated above. 192 |
    6. 193 |
    194 |
  18. 195 | 196 |
  19. Publisher. The parties hereby confirm that the Publisher shall 197 | not, under any circumstances, be responsible for and shall not have any liability 198 | in respect of the subject matter of this License. The Publisher makes no warranty 199 | whatsoever in connection with the Work and shall not be liable to You or any party 200 | on any legal theory for any damages whatsoever, including without limitation any 201 | general, special, incidental or consequential damages arising in connection to this 202 | license. The Publisher reserves the right to cease making the Work available to 203 | You at any time without notice
  20. 204 | 205 |
  21. Miscellaneous 206 | 207 |
      208 |
    1. This License shall be governed by the laws of the location of the head office of 209 | the Author or if the Author is an individual, the laws of location of the principal 210 | place of residence of the Author.
    2. 211 |
    3. If any provision of this License is invalid or unenforceable under applicable law, 212 | it shall not affect the validity or enforceability of the remainder of the terms 213 | of this License, and without further action by the parties to this License, such 214 | provision shall be reformed to the minimum extent necessary to make such provision 215 | valid and enforceable.
    4. 216 |
    5. No term or provision of this License shall be deemed waived and no breach consented 217 | to unless such waiver or consent shall be in writing and signed by the party to 218 | be charged with such waiver or consent.
    6. 219 |
    7. This License constitutes the entire agreement between the parties with respect to 220 | the Work licensed herein. There are no understandings, agreements or representations 221 | with respect to the Work not specified herein. The Author shall not be bound by 222 | any additional provisions that may appear in any communication from You. This License 223 | may not be modified without the mutual written agreement of the Author and You. 224 |
    8. 225 |
    226 | 227 |
  22. 228 |
229 | 230 |
231 |
232 | 233 | 234 | 235 | --------------------------------------------------------------------------------