Index: src/ch/AboutDlg.cpp =================================================================== diff -u -r9795c1ee9cf5ac865a61c12d0196a8ba5d9758c6 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/AboutDlg.cpp (.../AboutDlg.cpp) (revision 9795c1ee9cf5ac865a61c12d0196a8ba5d9758c6) +++ src/ch/AboutDlg.cpp (.../AboutDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,123 +1,123 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "resource.h" -#include "AboutDlg.h" -#include "StaticEx.h" -#include "../common/version.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -bool CAboutDlg::m_bLock=false; - -CAboutDlg::CAboutDlg() :ictranslate::CLanguageDialog(CAboutDlg::IDD, NULL, &m_bLock) -{ - //{{AFX_DATA_INIT(CAboutDlg) - //}}AFX_DATA_INIT - RegisterStaticExControl(AfxGetInstanceHandle()); -} - -CAboutDlg::~CAboutDlg() -{ -} - -BEGIN_MESSAGE_MAP(CAboutDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CAboutDlg) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -void CAboutDlg::UpdateProgramVersion() -{ - CWnd* pCtl = GetDlgItem(IDC_PROGRAM_STATICEX); - CWnd* pCtl2 = GetDlgItem(IDC_FULLVERSION_STATICEX); - CWnd* pWndCopyright = GetDlgItem(IDC_COPYRIGHT_STATIC); - CWnd* pctlSite = GetDlgItem(IDC_HOMEPAGELINK_STATIC); - CWnd* pctlLanguage = GetDlgItem(IDC_LANGUAGE_STATIC); - CWnd* pctlContact = GetDlgItem(IDC_CONTACT1LINK_STATIC); - - if (!pCtl || !pCtl2 || !pWndCopyright || !pctlSite || !pctlLanguage || !pctlContact) - return; - - // Readable version - pCtl->SetWindowText(GetApp()->GetAppNameVer()); - - // full version - CString strText; - strText.Format(_T("%s: %ld.%ld.%ld.%ld"), GetResManager()->LoadString(IDS_ABOUTVERSION_STRING), - PRODUCT_VERSION1, PRODUCT_VERSION2, PRODUCT_VERSION3, PRODUCT_VERSION4); - pCtl2->SetWindowText(strText); - // Copyright information - pWndCopyright->SetWindowText(_T(COPYRIGHT_INFO)); - - // web page link - pctlSite->SetWindowText(_T(PRODUCT_SITE) _T("|") _T(PRODUCT_SITE)); - pctlContact->SetWindowText(_T(CONTACT_INFO) _T("|mailto:") _T(CONTACT_INFO)); - - // language information - ictranslate::CResourceManager* pResManager = GetResManager(); - if(pResManager) - { - const ictranslate::CLangData* pLangData = pResManager->GetLanguageData(); - if(pLangData) - { - ictranslate::CFormat fmt(pResManager->LoadString(IDS_ABOUT_LANGUAGE_STRING)); - fmt.SetParam(_t("%langname"), pLangData->GetLangName()); - fmt.SetParam(_t("%authors"), pLangData->GetAuthor()); - - pctlLanguage->SetWindowText(fmt); - } - } -} - -BOOL CAboutDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - UpdateProgramVersion(); - - return TRUE; -} - -void CAboutDlg::OnLanguageChanged() -{ - UpdateProgramVersion(); -} - -BOOL CAboutDlg::OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip) -{ - switch(uiID) - { - case IDC_HOMEPAGELINK_STATIC: - case IDC_CONTACT1LINK_STATIC: - case IDC_CONTACT2LINK_STATIC: - { - HWND hWnd=::GetDlgItem(this->m_hWnd, uiID); - if (!hWnd) - return FALSE; - ::SendMessage(hWnd, SEM_GETLINK, (WPARAM)79, (LPARAM)pTip->szText); - pTip->szText[79]=_T('\0'); - return TRUE; - } - default: - return FALSE; - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "resource.h" +#include "AboutDlg.h" +#include "StaticEx.h" +#include "../common/version.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +bool CAboutDlg::m_bLock=false; + +CAboutDlg::CAboutDlg() :ictranslate::CLanguageDialog(CAboutDlg::IDD, NULL, &m_bLock) +{ + //{{AFX_DATA_INIT(CAboutDlg) + //}}AFX_DATA_INIT + RegisterStaticExControl(AfxGetInstanceHandle()); +} + +CAboutDlg::~CAboutDlg() +{ +} + +BEGIN_MESSAGE_MAP(CAboutDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CAboutDlg) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +void CAboutDlg::UpdateProgramVersion() +{ + CWnd* pCtl = GetDlgItem(IDC_PROGRAM_STATICEX); + CWnd* pCtl2 = GetDlgItem(IDC_FULLVERSION_STATICEX); + CWnd* pWndCopyright = GetDlgItem(IDC_COPYRIGHT_STATIC); + CWnd* pctlSite = GetDlgItem(IDC_HOMEPAGELINK_STATIC); + CWnd* pctlLanguage = GetDlgItem(IDC_LANGUAGE_STATIC); + CWnd* pctlContact = GetDlgItem(IDC_CONTACT1LINK_STATIC); + + if (!pCtl || !pCtl2 || !pWndCopyright || !pctlSite || !pctlLanguage || !pctlContact) + return; + + // Readable version + pCtl->SetWindowText(GetApp()->GetAppNameVer()); + + // full version + CString strText; + strText.Format(_T("%s: %ld.%ld.%ld.%ld"), GetResManager()->LoadString(IDS_ABOUTVERSION_STRING), + PRODUCT_VERSION1, PRODUCT_VERSION2, PRODUCT_VERSION3, PRODUCT_VERSION4); + pCtl2->SetWindowText(strText); + // Copyright information + pWndCopyright->SetWindowText(_T(COPYRIGHT_INFO)); + + // web page link + pctlSite->SetWindowText(_T(PRODUCT_SITE) _T("|") _T(PRODUCT_SITE)); + pctlContact->SetWindowText(_T(CONTACT_INFO) _T("|mailto:") _T(CONTACT_INFO)); + + // language information + ictranslate::CResourceManager* pResManager = GetResManager(); + if(pResManager) + { + const ictranslate::CLangData* pLangData = pResManager->GetLanguageData(); + if(pLangData) + { + ictranslate::CFormat fmt(pResManager->LoadString(IDS_ABOUT_LANGUAGE_STRING)); + fmt.SetParam(_t("%langname"), pLangData->GetLangName()); + fmt.SetParam(_t("%authors"), pLangData->GetAuthor()); + + pctlLanguage->SetWindowText(fmt); + } + } +} + +BOOL CAboutDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + UpdateProgramVersion(); + + return TRUE; +} + +void CAboutDlg::OnLanguageChanged() +{ + UpdateProgramVersion(); +} + +BOOL CAboutDlg::OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip) +{ + switch(uiID) + { + case IDC_HOMEPAGELINK_STATIC: + case IDC_CONTACT1LINK_STATIC: + case IDC_CONTACT2LINK_STATIC: + { + HWND hWnd=::GetDlgItem(this->m_hWnd, uiID); + if (!hWnd) + return FALSE; + ::SendMessage(hWnd, SEM_GETLINK, (WPARAM)79, (LPARAM)pTip->szText); + pTip->szText[79]=_T('\0'); + return TRUE; + } + default: + return FALSE; + } +} Index: src/ch/AboutDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/AboutDlg.h (.../AboutDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/AboutDlg.h (.../AboutDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -15,40 +15,40 @@ * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ - -#ifndef __ABOUTDLG_H__ -#define __ABOUTDLG_H__ - -class CAboutDlg : public ictranslate::CLanguageDialog -{ -public: - CAboutDlg(); - ~CAboutDlg(); - - void UpdateProgramVersion(); - - virtual void OnLanguageChanged(); - virtual BOOL OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip); - -// Dialog Data - //{{AFX_DATA(CAboutDlg) - enum { IDD = IDD_ABOUTBOX }; - //}}AFX_DATA - - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CAboutDlg) - protected: - //}}AFX_VIRTUAL - static bool m_bLock; // locker - -// Implementation -protected: - //{{AFX_MSG(CAboutDlg) - afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); - virtual BOOL OnInitDialog(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -#endif +***************************************************************************/ + +#ifndef __ABOUTDLG_H__ +#define __ABOUTDLG_H__ + +class CAboutDlg : public ictranslate::CLanguageDialog +{ +public: + CAboutDlg(); + ~CAboutDlg(); + + void UpdateProgramVersion(); + + virtual void OnLanguageChanged(); + virtual BOOL OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip); + +// Dialog Data + //{{AFX_DATA(CAboutDlg) + enum { IDD = IDD_ABOUTBOX }; + //}}AFX_DATA + + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CAboutDlg) + protected: + //}}AFX_VIRTUAL + static bool m_bLock; // locker + +// Implementation +protected: + //{{AFX_MSG(CAboutDlg) + afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); + virtual BOOL OnInitDialog(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +#endif Index: src/ch/AppHelper.cpp =================================================================== diff -u -rf6c4389122d92e5f84a509e9be0facebac429151 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/AppHelper.cpp (.../AppHelper.cpp) (revision f6c4389122d92e5f84a509e9be0facebac429151) +++ src/ch/AppHelper.cpp (.../AppHelper.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,258 +1,258 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "AppHelper.h" -#include "shlobj.h" -#include "../common/version.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#define CH_MUTEX_NAME _T("_Copy handler_ instance") - -CAppHelper::CAppHelper() -{ - // read program paths - RetrievePaths(); - - // retrieve VERSION-based info - RetrieveAppInfo(); - - // single-instance protection - m_bFirstInstance=true; - m_hMutex=NULL; -} - -CAppHelper::~CAppHelper() -{ - if (m_hMutex) - ReleaseMutex(m_hMutex); - - delete [] m_pszProgramPath; - delete [] m_pszProgramName; -} - -// inits mutex app protection -void CAppHelper::InitProtection() -{ - m_hMutex=CreateMutex(NULL, TRUE, CH_MUTEX_NAME); - m_bFirstInstance=(m_hMutex != NULL && GetLastError() != ERROR_ALREADY_EXISTS); -} - -// retrieves application path -void CAppHelper::RetrievePaths() -{ - // try to find '\\' in path to see if this is only exe name or fully qualified path -#ifdef _UNICODE - TCHAR* pszArgv = __wargv[0]; -#else - TCHAR* pszArgv = __argv[0]; -#endif - - TCHAR* pszName=_tcsrchr(pszArgv, _T('\\')); - if (pszName != NULL) - { - // copy name - m_pszProgramName=new TCHAR[_tcslen(pszName+1)+1]; - _tcscpy(m_pszProgramName, pszName+1); - - // path - UINT uiSize=(UINT)(pszName-pszArgv); - m_pszProgramPath=new TCHAR[uiSize+1]; - _tcsncpy(m_pszProgramPath, pszArgv, uiSize); - m_pszProgramPath[uiSize]=_T('\0'); - } - else - { - // copy name - m_pszProgramName=new TCHAR[_tcslen(pszArgv)+1]; - _tcscpy(m_pszProgramName, pszArgv); - - // path - TCHAR szPath[_MAX_PATH]; - UINT uiSize=GetCurrentDirectory(_MAX_PATH, szPath); - _tcscat(szPath, _T("\\")); - m_pszProgramPath=new TCHAR[uiSize+2]; - _tcsncpy(m_pszProgramPath, szPath, uiSize+2); - } -} - -void CAppHelper::RetrieveAppInfo() -{ - m_pszAppName = _T(PRODUCT_NAME); - m_pszAppNameVer = PRODUCT_FULL_VERSION_T; - m_pszAppVersion = _T(PRODUCT_VERSION); -} - -// internal func - safe getting special folder locations -UINT CAppHelper::GetFolderLocation(int iFolder, PTSTR pszBuffer) -{ - LPITEMIDLIST piid; - HRESULT h=SHGetSpecialFolderLocation(NULL, iFolder, &piid); - if (!SUCCEEDED(h)) - return false; - - // get path - BOOL bRes=SHGetPathFromIDList(piid, pszBuffer); - - // free piid - LPMALLOC lpm; - if (!SUCCEEDED(SHGetMalloc(&lpm))) - return 0; - - lpm->Free((void*)piid); - lpm->Release(); - - // check for error - if (!bRes) - return 0; - - // strip the last '\\' - UINT uiLen=(UINT)_tcslen(pszBuffer); - if (pszBuffer[uiLen-1] == _T('\\')) - { - pszBuffer[uiLen-1]=_T('\0'); - return uiLen-1; - } - else - return uiLen; -} - -// expands given path -PTSTR CAppHelper::ExpandPath(PTSTR pszString) -{ - // check if there is need to perform all these checkings - if (pszString[0] != _T('<')) - return pszString; - - TCHAR szStr[_MAX_PATH]; - szStr[0]=_T('\0'); - - // search for string to replace - // _T(""), _T(""), _T(""), _T(""), _T(""), - // _T(""), _T("") - if (_tcsnicmp(pszString, _T(""), 9) == 0) - { - // get windows path - _tcscpy(szStr, m_pszProgramPath ? m_pszProgramPath : _t("")); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 9) == 0) - { - // get windows path - UINT uiSize=GetWindowsDirectory(szStr, _MAX_PATH); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 6) == 0) // temp dir - { - // get windows path - UINT uiSize=GetTempPath(_MAX_PATH, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+6); - } - else if (_tcsnicmp(pszString, _T(""), 8) == 0) // system - { - // get windows path - UINT uiSize=GetSystemDirectory(szStr, _MAX_PATH); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+8); - } - else if (_tcsnicmp(pszString, _T(""), 9) == 0) // app data - { - // get windows path - UINT uiSize=GetFolderLocation(CSIDL_LOCAL_APPDATA, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 9) == 0) // desktop - { - // get windows path - UINT uiSize=GetFolderLocation(CSIDL_DESKTOPDIRECTORY, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+9); - } - else if (_tcsnicmp(pszString, _T(""), 10) == 0) // personal... - { - // get windows path - UINT uiSize=GetFolderLocation(CSIDL_PERSONAL, szStr); - if (szStr[uiSize-1] == _T('\\')) - szStr[uiSize-1]=_T('\0'); - _tcscat(szStr, pszString+10); - } - - // copy to src string - if (szStr[0] != _T('\0')) - _tcscpy(pszString, szStr); - - return pszString; -} - -bool CAppHelper::GetProgramDataPath(CString& rStrPath) -{ - HRESULT hResult = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, rStrPath.GetBufferSetLength(_MAX_PATH)); - rStrPath.ReleaseBuffer(); - if(FAILED(hResult)) - return false; - - if(rStrPath.Right(1) != _T('\\')) - rStrPath += _T('\\'); - - // make sure to create the required directories if they does not exist - rStrPath += _T("\\Copy Handler"); - if(!CreateDirectory(rStrPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) - return false; - - // create directory for tasks - rStrPath += _T("\\Tasks"); - if(!CreateDirectory(rStrPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) - return false; - - return true; -} - -void CAppHelper::SetAutorun(bool bState) -{ - // storing key in registry - HKEY hkeyRun; - if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hkeyRun) != ERROR_SUCCESS) - return; - - if (bState) - { - TCHAR *pszPath=new TCHAR[_tcslen(m_pszProgramPath)+_tcslen(m_pszProgramName)+2]; - _tcscpy(pszPath, m_pszProgramPath); - _tcscat(pszPath, _T("\\")); - _tcscat(pszPath, m_pszProgramName); - - RegSetValueEx(hkeyRun, m_pszAppName, 0, REG_SZ, (BYTE*)pszPath, (DWORD)(_tcslen(pszPath)+1)*sizeof(TCHAR)); - - delete [] pszPath; - } - else - RegDeleteValue(hkeyRun, m_pszAppName); - - RegCloseKey(hkeyRun); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "AppHelper.h" +#include "shlobj.h" +#include "../common/version.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#define CH_MUTEX_NAME _T("_Copy handler_ instance") + +CAppHelper::CAppHelper() +{ + // read program paths + RetrievePaths(); + + // retrieve VERSION-based info + RetrieveAppInfo(); + + // single-instance protection + m_bFirstInstance=true; + m_hMutex=NULL; +} + +CAppHelper::~CAppHelper() +{ + if (m_hMutex) + ReleaseMutex(m_hMutex); + + delete [] m_pszProgramPath; + delete [] m_pszProgramName; +} + +// inits mutex app protection +void CAppHelper::InitProtection() +{ + m_hMutex=CreateMutex(NULL, TRUE, CH_MUTEX_NAME); + m_bFirstInstance=(m_hMutex != NULL && GetLastError() != ERROR_ALREADY_EXISTS); +} + +// retrieves application path +void CAppHelper::RetrievePaths() +{ + // try to find '\\' in path to see if this is only exe name or fully qualified path +#ifdef _UNICODE + TCHAR* pszArgv = __wargv[0]; +#else + TCHAR* pszArgv = __argv[0]; +#endif + + TCHAR* pszName=_tcsrchr(pszArgv, _T('\\')); + if (pszName != NULL) + { + // copy name + m_pszProgramName=new TCHAR[_tcslen(pszName+1)+1]; + _tcscpy(m_pszProgramName, pszName+1); + + // path + UINT uiSize=(UINT)(pszName-pszArgv); + m_pszProgramPath=new TCHAR[uiSize+1]; + _tcsncpy(m_pszProgramPath, pszArgv, uiSize); + m_pszProgramPath[uiSize]=_T('\0'); + } + else + { + // copy name + m_pszProgramName=new TCHAR[_tcslen(pszArgv)+1]; + _tcscpy(m_pszProgramName, pszArgv); + + // path + TCHAR szPath[_MAX_PATH]; + UINT uiSize=GetCurrentDirectory(_MAX_PATH, szPath); + _tcscat(szPath, _T("\\")); + m_pszProgramPath=new TCHAR[uiSize+2]; + _tcsncpy(m_pszProgramPath, szPath, uiSize+2); + } +} + +void CAppHelper::RetrieveAppInfo() +{ + m_pszAppName = _T(PRODUCT_NAME); + m_pszAppNameVer = PRODUCT_FULL_VERSION_T; + m_pszAppVersion = _T(PRODUCT_VERSION); +} + +// internal func - safe getting special folder locations +UINT CAppHelper::GetFolderLocation(int iFolder, PTSTR pszBuffer) +{ + LPITEMIDLIST piid; + HRESULT h=SHGetSpecialFolderLocation(NULL, iFolder, &piid); + if (!SUCCEEDED(h)) + return false; + + // get path + BOOL bRes=SHGetPathFromIDList(piid, pszBuffer); + + // free piid + LPMALLOC lpm; + if (!SUCCEEDED(SHGetMalloc(&lpm))) + return 0; + + lpm->Free((void*)piid); + lpm->Release(); + + // check for error + if (!bRes) + return 0; + + // strip the last '\\' + UINT uiLen=(UINT)_tcslen(pszBuffer); + if (pszBuffer[uiLen-1] == _T('\\')) + { + pszBuffer[uiLen-1]=_T('\0'); + return uiLen-1; + } + else + return uiLen; +} + +// expands given path +PTSTR CAppHelper::ExpandPath(PTSTR pszString) +{ + // check if there is need to perform all these checkings + if (pszString[0] != _T('<')) + return pszString; + + TCHAR szStr[_MAX_PATH]; + szStr[0]=_T('\0'); + + // search for string to replace + // _T(""), _T(""), _T(""), _T(""), _T(""), + // _T(""), _T("") + if (_tcsnicmp(pszString, _T(""), 9) == 0) + { + // get windows path + _tcscpy(szStr, m_pszProgramPath ? m_pszProgramPath : _t("")); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 9) == 0) + { + // get windows path + UINT uiSize=GetWindowsDirectory(szStr, _MAX_PATH); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 6) == 0) // temp dir + { + // get windows path + UINT uiSize=GetTempPath(_MAX_PATH, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+6); + } + else if (_tcsnicmp(pszString, _T(""), 8) == 0) // system + { + // get windows path + UINT uiSize=GetSystemDirectory(szStr, _MAX_PATH); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+8); + } + else if (_tcsnicmp(pszString, _T(""), 9) == 0) // app data + { + // get windows path + UINT uiSize=GetFolderLocation(CSIDL_LOCAL_APPDATA, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 9) == 0) // desktop + { + // get windows path + UINT uiSize=GetFolderLocation(CSIDL_DESKTOPDIRECTORY, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+9); + } + else if (_tcsnicmp(pszString, _T(""), 10) == 0) // personal... + { + // get windows path + UINT uiSize=GetFolderLocation(CSIDL_PERSONAL, szStr); + if (szStr[uiSize-1] == _T('\\')) + szStr[uiSize-1]=_T('\0'); + _tcscat(szStr, pszString+10); + } + + // copy to src string + if (szStr[0] != _T('\0')) + _tcscpy(pszString, szStr); + + return pszString; +} + +bool CAppHelper::GetProgramDataPath(CString& rStrPath) +{ + HRESULT hResult = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, rStrPath.GetBufferSetLength(_MAX_PATH)); + rStrPath.ReleaseBuffer(); + if(FAILED(hResult)) + return false; + + if(rStrPath.Right(1) != _T('\\')) + rStrPath += _T('\\'); + + // make sure to create the required directories if they does not exist + rStrPath += _T("\\Copy Handler"); + if(!CreateDirectory(rStrPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) + return false; + + // create directory for tasks + rStrPath += _T("\\Tasks"); + if(!CreateDirectory(rStrPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) + return false; + + return true; +} + +void CAppHelper::SetAutorun(bool bState) +{ + // storing key in registry + HKEY hkeyRun; + if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_ALL_ACCESS, &hkeyRun) != ERROR_SUCCESS) + return; + + if (bState) + { + TCHAR *pszPath=new TCHAR[_tcslen(m_pszProgramPath)+_tcslen(m_pszProgramName)+2]; + _tcscpy(pszPath, m_pszProgramPath); + _tcscat(pszPath, _T("\\")); + _tcscat(pszPath, m_pszProgramName); + + RegSetValueEx(hkeyRun, m_pszAppName, 0, REG_SZ, (BYTE*)pszPath, (DWORD)(_tcslen(pszPath)+1)*sizeof(TCHAR)); + + delete [] pszPath; + } + else + RegDeleteValue(hkeyRun, m_pszAppName); + + RegCloseKey(hkeyRun); +} Index: src/ch/AppHelper.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/AppHelper.h (.../AppHelper.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/AppHelper.h (.../AppHelper.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -15,47 +15,47 @@ * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __APPHELPER_H__ -#define __APPHELPER_H__ - -class CAppHelper -{ -public: - CAppHelper(); - ~CAppHelper(); - - void SetAutorun(bool bState); // changes state of "run with system" option - PTSTR ExpandPath(PTSTR pszString); // expands path string - ie. into c:\windows - - bool IsFirstInstance() const { return m_bFirstInstance; }; - - PCTSTR GetAppName() const { return m_pszAppName; }; - PCTSTR GetAppNameVer() const { return m_pszAppNameVer; }; - PCTSTR GetAppVersion() const { return m_pszAppVersion; }; - - PCTSTR GetProgramPath() const { return m_pszProgramPath; }; - PCTSTR GetProgramName() const { return m_pszProgramName; }; - - static bool GetProgramDataPath(CString& rStrPath); - -protected: - void InitProtection(); // optional call - protects from running multiple instance - void RetrievePaths(); // reads program's path and name - void RetrieveAppInfo(); // reads app name and version from VERSION resource - UINT GetFolderLocation(int iFolder, PTSTR pszBuffer); - -protected: - HANDLE m_hMutex; - bool m_bFirstInstance; // tells if it is first instance(true) or second(or third, ...) - - // program placement - TCHAR* m_pszProgramPath; // path from which this program was run - TCHAR* m_pszProgramName; // name of this program (ie. CH.exe) - - TCHAR* m_pszAppName; // app-name string of this app - TCHAR* m_pszAppNameVer; // extended app-name-with small version - TCHAR* m_pszAppVersion; // app-version string of this app (VERSION based) -}; - +***************************************************************************/ +#ifndef __APPHELPER_H__ +#define __APPHELPER_H__ + +class CAppHelper +{ +public: + CAppHelper(); + ~CAppHelper(); + + void SetAutorun(bool bState); // changes state of "run with system" option + PTSTR ExpandPath(PTSTR pszString); // expands path string - ie. into c:\windows + + bool IsFirstInstance() const { return m_bFirstInstance; }; + + PCTSTR GetAppName() const { return m_pszAppName; }; + PCTSTR GetAppNameVer() const { return m_pszAppNameVer; }; + PCTSTR GetAppVersion() const { return m_pszAppVersion; }; + + PCTSTR GetProgramPath() const { return m_pszProgramPath; }; + PCTSTR GetProgramName() const { return m_pszProgramName; }; + + static bool GetProgramDataPath(CString& rStrPath); + +protected: + void InitProtection(); // optional call - protects from running multiple instance + void RetrievePaths(); // reads program's path and name + void RetrieveAppInfo(); // reads app name and version from VERSION resource + UINT GetFolderLocation(int iFolder, PTSTR pszBuffer); + +protected: + HANDLE m_hMutex; + bool m_bFirstInstance; // tells if it is first instance(true) or second(or third, ...) + + // program placement + TCHAR* m_pszProgramPath; // path from which this program was run + TCHAR* m_pszProgramName; // name of this program (ie. CH.exe) + + TCHAR* m_pszAppName; // app-name string of this app + TCHAR* m_pszAppNameVer; // extended app-name-with small version + TCHAR* m_pszAppVersion; // app-version string of this app (VERSION based) +}; + #endif \ No newline at end of file Index: src/ch/BufferSizeDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/BufferSizeDlg.cpp (.../BufferSizeDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/BufferSizeDlg.cpp (.../BufferSizeDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,332 +1,332 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "resource.h" -#include "BufferSizeDlg.h" -#include "ch.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CBufferSizeDlg dialog - -CBufferSizeDlg::CBufferSizeDlg() - : ictranslate::CLanguageDialog(CBufferSizeDlg::IDD) -{ - //{{AFX_DATA_INIT(CBufferSizeDlg) - m_uiDefaultSize = 0; - m_uiLANSize = 0; - m_uiCDROMSize = 0; - m_uiOneDiskSize = 0; - m_uiTwoDisksSize = 0; - m_bOnlyDefaultCheck = FALSE; - //}}AFX_DATA_INIT - m_iActiveIndex=BI_DEFAULT; -} - -void CBufferSizeDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CBufferSizeDlg) - DDX_Control(pDX, IDC_TWODISKSMULTIPLIER_COMBO, m_ctlTwoDisksMulti); - DDX_Control(pDX, IDC_ONEDISKMULTIPLIER_COMBO, m_ctlOneDiskMulti); - DDX_Control(pDX, IDC_LANMULTIPLIER_COMBO, m_ctlLANMulti); - DDX_Control(pDX, IDC_DEFAULTMULTIPLIER_COMBO, m_ctlDefaultMulti); - DDX_Control(pDX, IDC_CDROMMULTIPLIER_COMBO, m_ctlCDROMMulti); - DDX_Text(pDX, IDC_DEFAULTSIZE_EDIT, m_uiDefaultSize); - DDX_Text(pDX, IDC_LANSIZE_EDIT, m_uiLANSize); - DDX_Text(pDX, IDC_CDROMSIZE_EDIT, m_uiCDROMSize); - DDX_Text(pDX, IDC_ONEDISKSIZE_EDIT, m_uiOneDiskSize); - DDX_Text(pDX, IDC_TWODISKSSIZE_EDIT, m_uiTwoDisksSize); - DDX_Check(pDX, IDC_ONLYDEFAULT_CHECK, m_bOnlyDefaultCheck); - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(CBufferSizeDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CBufferSizeDlg) - ON_BN_CLICKED(IDC_ONLYDEFAULT_CHECK, OnOnlydefaultCheck) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CBufferSizeDlg message handlers - -BOOL CBufferSizeDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // set all the combos - m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - - m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - - m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - - m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - - m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - - // fill edit controls and set multipliers - SetDefaultSize(m_bsSizes.m_uiDefaultSize); - SetOneDiskSize(m_bsSizes.m_uiOneDiskSize); - SetTwoDisksSize(m_bsSizes.m_uiTwoDisksSize); - SetCDSize(m_bsSizes.m_uiCDSize); - SetLANSize(m_bsSizes.m_uiLANSize); - m_bOnlyDefaultCheck=m_bsSizes.m_bOnlyDefault; - - EnableControls(!m_bsSizes.m_bOnlyDefault); - - UpdateData(FALSE); - - // set focus to the requested control - switch (m_iActiveIndex) - { - case BI_DEFAULT: - GetDlgItem(IDC_DEFAULTSIZE_EDIT)->SetFocus(); - static_cast(GetDlgItem(IDC_DEFAULTSIZE_EDIT))->SetSel(0, -1); - break; - case BI_ONEDISK: - GetDlgItem(IDC_ONEDISKSIZE_EDIT)->SetFocus(); - static_cast(GetDlgItem(IDC_ONEDISKSIZE_EDIT))->SetSel(0, -1); - break; - case BI_TWODISKS: - GetDlgItem(IDC_TWODISKSSIZE_EDIT)->SetFocus(); - static_cast(GetDlgItem(IDC_TWODISKSSIZE_EDIT))->SetSel(0, -1); - break; - case BI_CD: - GetDlgItem(IDC_CDROMSIZE_EDIT)->SetFocus(); - static_cast(GetDlgItem(IDC_CDROMSIZE_EDIT))->SetSel(0, -1); - break; - case BI_LAN: - GetDlgItem(IDC_LANSIZE_EDIT)->SetFocus(); - static_cast(GetDlgItem(IDC_LANSIZE_EDIT))->SetSel(0, -1); - break; - } - - return FALSE; -} - -void CBufferSizeDlg::OnLanguageChanged() -{ - UpdateData(TRUE); - - // set all the combos - int iSel=m_ctlDefaultMulti.GetCurSel(); - m_ctlDefaultMulti.ResetContent(); - m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - m_ctlDefaultMulti.SetCurSel(iSel); - - iSel=m_ctlOneDiskMulti.GetCurSel(); - m_ctlOneDiskMulti.ResetContent(); - m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - m_ctlOneDiskMulti.SetCurSel(iSel); - - iSel=m_ctlTwoDisksMulti.GetCurSel(); - m_ctlTwoDisksMulti.ResetContent(); - m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - m_ctlTwoDisksMulti.SetCurSel(iSel); - - iSel=m_ctlCDROMMulti.GetCurSel(); - m_ctlCDROMMulti.ResetContent(); - m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - m_ctlCDROMMulti.SetCurSel(iSel); - - iSel=m_ctlLANMulti.GetCurSel(); - m_ctlLANMulti.ResetContent(); - m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); - m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); - m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); - m_ctlLANMulti.SetCurSel(iSel); - - UpdateData(FALSE); -} - -UINT CBufferSizeDlg::IndexToValue(int iIndex) -{ - switch (iIndex) - { - case 0: - return 1; - case 1: - return 1024; - case 2: - return 1048576; - default: - ASSERT(true); // bad index - return 1; - } -} - -void CBufferSizeDlg::OnOK() -{ - if (!UpdateData(TRUE)) - return; - - // no buffer could be 0 - if (m_uiDefaultSize == 0 || m_uiOneDiskSize == 0 || m_uiTwoDisksSize == 0 || m_uiCDROMSize == 0 || m_uiLANSize == 0) - { - MsgBox(IDS_BUFFERSIZEZERO_STRING); - return; - } - - // assign values - m_bsSizes.m_bOnlyDefault=m_bOnlyDefaultCheck != 0; - m_bsSizes.m_uiDefaultSize=m_uiDefaultSize*IndexToValue(m_ctlDefaultMulti.GetCurSel()); - m_bsSizes.m_uiOneDiskSize=m_uiOneDiskSize*IndexToValue(m_ctlOneDiskMulti.GetCurSel()); - m_bsSizes.m_uiTwoDisksSize=m_uiTwoDisksSize*IndexToValue(m_ctlTwoDisksMulti.GetCurSel()); - m_bsSizes.m_uiCDSize=m_uiCDROMSize*IndexToValue(m_ctlCDROMMulti.GetCurSel()); - m_bsSizes.m_uiLANSize=m_uiLANSize*IndexToValue(m_ctlLANMulti.GetCurSel()); - - CLanguageDialog::OnOK(); -} - -void CBufferSizeDlg::SetDefaultSize(UINT uiSize) -{ - if ((uiSize % 1048576) == 0) - { - m_uiDefaultSize=static_cast(uiSize/1048576); - m_ctlDefaultMulti.SetCurSel(2); - } - else if ((uiSize % 1024) == 0) - { - m_uiDefaultSize=static_cast(uiSize/1024); - m_ctlDefaultMulti.SetCurSel(1); - } - else - { - m_uiDefaultSize=uiSize; - m_ctlDefaultMulti.SetCurSel(0); - } -} - -void CBufferSizeDlg::SetOneDiskSize(UINT uiSize) -{ - if ((uiSize % 1048576) == 0) - { - m_uiOneDiskSize=static_cast(uiSize/1048576); - m_ctlOneDiskMulti.SetCurSel(2); - } - else if ((uiSize % 1024) == 0) - { - m_uiOneDiskSize=static_cast(uiSize/1024); - m_ctlOneDiskMulti.SetCurSel(1); - } - else - { - m_uiOneDiskSize=uiSize; - m_ctlOneDiskMulti.SetCurSel(0); - } -} - -void CBufferSizeDlg::SetTwoDisksSize(UINT uiSize) -{ - if ((uiSize % 1048576) == 0) - { - m_uiTwoDisksSize=static_cast(uiSize/1048576); - m_ctlTwoDisksMulti.SetCurSel(2); - } - else if ((uiSize % 1024) == 0) - { - m_uiTwoDisksSize=static_cast(uiSize/1024); - m_ctlTwoDisksMulti.SetCurSel(1); - } - else - { - m_uiTwoDisksSize=uiSize; - m_ctlTwoDisksMulti.SetCurSel(0); - } -} - -void CBufferSizeDlg::SetCDSize(UINT uiSize) -{ - if ((uiSize % 1048576) == 0) - { - m_uiCDROMSize=static_cast(uiSize/1048576); - m_ctlCDROMMulti.SetCurSel(2); - } - else if ((uiSize % 1024) == 0) - { - m_uiCDROMSize=static_cast(uiSize/1024); - m_ctlCDROMMulti.SetCurSel(1); - } - else - { - m_uiCDROMSize=uiSize; - m_ctlCDROMMulti.SetCurSel(0); - } -} - -void CBufferSizeDlg::SetLANSize(UINT uiSize) -{ - if ((uiSize % 1048576) == 0) - { - m_uiLANSize=static_cast(uiSize/1048576); - m_ctlLANMulti.SetCurSel(2); - } - else if ((uiSize % 1024) == 0) - { - m_uiLANSize=static_cast(uiSize/1024); - m_ctlLANMulti.SetCurSel(1); - } - else - { - m_uiLANSize=uiSize; - m_ctlLANMulti.SetCurSel(0); - } -} - -void CBufferSizeDlg::EnableControls(bool bEnable) -{ - GetDlgItem(IDC_ONEDISKSIZE_EDIT)->EnableWindow(bEnable); - m_ctlOneDiskMulti.EnableWindow(bEnable); - GetDlgItem(IDC_TWODISKSSIZE_EDIT)->EnableWindow(bEnable); - m_ctlTwoDisksMulti.EnableWindow(bEnable); - GetDlgItem(IDC_CDROMSIZE_EDIT)->EnableWindow(bEnable); - m_ctlCDROMMulti.EnableWindow(bEnable); - GetDlgItem(IDC_LANSIZE_EDIT)->EnableWindow(bEnable); - m_ctlLANMulti.EnableWindow(bEnable); -} - -void CBufferSizeDlg::OnOnlydefaultCheck() -{ - UpdateData(TRUE); - EnableControls(m_bOnlyDefaultCheck == 0); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "resource.h" +#include "BufferSizeDlg.h" +#include "ch.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CBufferSizeDlg dialog + +CBufferSizeDlg::CBufferSizeDlg() + : ictranslate::CLanguageDialog(CBufferSizeDlg::IDD) +{ + //{{AFX_DATA_INIT(CBufferSizeDlg) + m_uiDefaultSize = 0; + m_uiLANSize = 0; + m_uiCDROMSize = 0; + m_uiOneDiskSize = 0; + m_uiTwoDisksSize = 0; + m_bOnlyDefaultCheck = FALSE; + //}}AFX_DATA_INIT + m_iActiveIndex=BI_DEFAULT; +} + +void CBufferSizeDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CBufferSizeDlg) + DDX_Control(pDX, IDC_TWODISKSMULTIPLIER_COMBO, m_ctlTwoDisksMulti); + DDX_Control(pDX, IDC_ONEDISKMULTIPLIER_COMBO, m_ctlOneDiskMulti); + DDX_Control(pDX, IDC_LANMULTIPLIER_COMBO, m_ctlLANMulti); + DDX_Control(pDX, IDC_DEFAULTMULTIPLIER_COMBO, m_ctlDefaultMulti); + DDX_Control(pDX, IDC_CDROMMULTIPLIER_COMBO, m_ctlCDROMMulti); + DDX_Text(pDX, IDC_DEFAULTSIZE_EDIT, m_uiDefaultSize); + DDX_Text(pDX, IDC_LANSIZE_EDIT, m_uiLANSize); + DDX_Text(pDX, IDC_CDROMSIZE_EDIT, m_uiCDROMSize); + DDX_Text(pDX, IDC_ONEDISKSIZE_EDIT, m_uiOneDiskSize); + DDX_Text(pDX, IDC_TWODISKSSIZE_EDIT, m_uiTwoDisksSize); + DDX_Check(pDX, IDC_ONLYDEFAULT_CHECK, m_bOnlyDefaultCheck); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CBufferSizeDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CBufferSizeDlg) + ON_BN_CLICKED(IDC_ONLYDEFAULT_CHECK, OnOnlydefaultCheck) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CBufferSizeDlg message handlers + +BOOL CBufferSizeDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // set all the combos + m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + + m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + + m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + + m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + + m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + + // fill edit controls and set multipliers + SetDefaultSize(m_bsSizes.m_uiDefaultSize); + SetOneDiskSize(m_bsSizes.m_uiOneDiskSize); + SetTwoDisksSize(m_bsSizes.m_uiTwoDisksSize); + SetCDSize(m_bsSizes.m_uiCDSize); + SetLANSize(m_bsSizes.m_uiLANSize); + m_bOnlyDefaultCheck=m_bsSizes.m_bOnlyDefault; + + EnableControls(!m_bsSizes.m_bOnlyDefault); + + UpdateData(FALSE); + + // set focus to the requested control + switch (m_iActiveIndex) + { + case BI_DEFAULT: + GetDlgItem(IDC_DEFAULTSIZE_EDIT)->SetFocus(); + static_cast(GetDlgItem(IDC_DEFAULTSIZE_EDIT))->SetSel(0, -1); + break; + case BI_ONEDISK: + GetDlgItem(IDC_ONEDISKSIZE_EDIT)->SetFocus(); + static_cast(GetDlgItem(IDC_ONEDISKSIZE_EDIT))->SetSel(0, -1); + break; + case BI_TWODISKS: + GetDlgItem(IDC_TWODISKSSIZE_EDIT)->SetFocus(); + static_cast(GetDlgItem(IDC_TWODISKSSIZE_EDIT))->SetSel(0, -1); + break; + case BI_CD: + GetDlgItem(IDC_CDROMSIZE_EDIT)->SetFocus(); + static_cast(GetDlgItem(IDC_CDROMSIZE_EDIT))->SetSel(0, -1); + break; + case BI_LAN: + GetDlgItem(IDC_LANSIZE_EDIT)->SetFocus(); + static_cast(GetDlgItem(IDC_LANSIZE_EDIT))->SetSel(0, -1); + break; + } + + return FALSE; +} + +void CBufferSizeDlg::OnLanguageChanged() +{ + UpdateData(TRUE); + + // set all the combos + int iSel=m_ctlDefaultMulti.GetCurSel(); + m_ctlDefaultMulti.ResetContent(); + m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlDefaultMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + m_ctlDefaultMulti.SetCurSel(iSel); + + iSel=m_ctlOneDiskMulti.GetCurSel(); + m_ctlOneDiskMulti.ResetContent(); + m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlOneDiskMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + m_ctlOneDiskMulti.SetCurSel(iSel); + + iSel=m_ctlTwoDisksMulti.GetCurSel(); + m_ctlTwoDisksMulti.ResetContent(); + m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlTwoDisksMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + m_ctlTwoDisksMulti.SetCurSel(iSel); + + iSel=m_ctlCDROMMulti.GetCurSel(); + m_ctlCDROMMulti.ResetContent(); + m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlCDROMMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + m_ctlCDROMMulti.SetCurSel(iSel); + + iSel=m_ctlLANMulti.GetCurSel(); + m_ctlLANMulti.ResetContent(); + m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_BYTE_STRING)); + m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_KBYTE_STRING)); + m_ctlLANMulti.AddString(GetResManager()->LoadString(IDS_MBYTE_STRING)); + m_ctlLANMulti.SetCurSel(iSel); + + UpdateData(FALSE); +} + +UINT CBufferSizeDlg::IndexToValue(int iIndex) +{ + switch (iIndex) + { + case 0: + return 1; + case 1: + return 1024; + case 2: + return 1048576; + default: + ASSERT(true); // bad index + return 1; + } +} + +void CBufferSizeDlg::OnOK() +{ + if (!UpdateData(TRUE)) + return; + + // no buffer could be 0 + if (m_uiDefaultSize == 0 || m_uiOneDiskSize == 0 || m_uiTwoDisksSize == 0 || m_uiCDROMSize == 0 || m_uiLANSize == 0) + { + MsgBox(IDS_BUFFERSIZEZERO_STRING); + return; + } + + // assign values + m_bsSizes.m_bOnlyDefault=m_bOnlyDefaultCheck != 0; + m_bsSizes.m_uiDefaultSize=m_uiDefaultSize*IndexToValue(m_ctlDefaultMulti.GetCurSel()); + m_bsSizes.m_uiOneDiskSize=m_uiOneDiskSize*IndexToValue(m_ctlOneDiskMulti.GetCurSel()); + m_bsSizes.m_uiTwoDisksSize=m_uiTwoDisksSize*IndexToValue(m_ctlTwoDisksMulti.GetCurSel()); + m_bsSizes.m_uiCDSize=m_uiCDROMSize*IndexToValue(m_ctlCDROMMulti.GetCurSel()); + m_bsSizes.m_uiLANSize=m_uiLANSize*IndexToValue(m_ctlLANMulti.GetCurSel()); + + CLanguageDialog::OnOK(); +} + +void CBufferSizeDlg::SetDefaultSize(UINT uiSize) +{ + if ((uiSize % 1048576) == 0) + { + m_uiDefaultSize=static_cast(uiSize/1048576); + m_ctlDefaultMulti.SetCurSel(2); + } + else if ((uiSize % 1024) == 0) + { + m_uiDefaultSize=static_cast(uiSize/1024); + m_ctlDefaultMulti.SetCurSel(1); + } + else + { + m_uiDefaultSize=uiSize; + m_ctlDefaultMulti.SetCurSel(0); + } +} + +void CBufferSizeDlg::SetOneDiskSize(UINT uiSize) +{ + if ((uiSize % 1048576) == 0) + { + m_uiOneDiskSize=static_cast(uiSize/1048576); + m_ctlOneDiskMulti.SetCurSel(2); + } + else if ((uiSize % 1024) == 0) + { + m_uiOneDiskSize=static_cast(uiSize/1024); + m_ctlOneDiskMulti.SetCurSel(1); + } + else + { + m_uiOneDiskSize=uiSize; + m_ctlOneDiskMulti.SetCurSel(0); + } +} + +void CBufferSizeDlg::SetTwoDisksSize(UINT uiSize) +{ + if ((uiSize % 1048576) == 0) + { + m_uiTwoDisksSize=static_cast(uiSize/1048576); + m_ctlTwoDisksMulti.SetCurSel(2); + } + else if ((uiSize % 1024) == 0) + { + m_uiTwoDisksSize=static_cast(uiSize/1024); + m_ctlTwoDisksMulti.SetCurSel(1); + } + else + { + m_uiTwoDisksSize=uiSize; + m_ctlTwoDisksMulti.SetCurSel(0); + } +} + +void CBufferSizeDlg::SetCDSize(UINT uiSize) +{ + if ((uiSize % 1048576) == 0) + { + m_uiCDROMSize=static_cast(uiSize/1048576); + m_ctlCDROMMulti.SetCurSel(2); + } + else if ((uiSize % 1024) == 0) + { + m_uiCDROMSize=static_cast(uiSize/1024); + m_ctlCDROMMulti.SetCurSel(1); + } + else + { + m_uiCDROMSize=uiSize; + m_ctlCDROMMulti.SetCurSel(0); + } +} + +void CBufferSizeDlg::SetLANSize(UINT uiSize) +{ + if ((uiSize % 1048576) == 0) + { + m_uiLANSize=static_cast(uiSize/1048576); + m_ctlLANMulti.SetCurSel(2); + } + else if ((uiSize % 1024) == 0) + { + m_uiLANSize=static_cast(uiSize/1024); + m_ctlLANMulti.SetCurSel(1); + } + else + { + m_uiLANSize=uiSize; + m_ctlLANMulti.SetCurSel(0); + } +} + +void CBufferSizeDlg::EnableControls(bool bEnable) +{ + GetDlgItem(IDC_ONEDISKSIZE_EDIT)->EnableWindow(bEnable); + m_ctlOneDiskMulti.EnableWindow(bEnable); + GetDlgItem(IDC_TWODISKSSIZE_EDIT)->EnableWindow(bEnable); + m_ctlTwoDisksMulti.EnableWindow(bEnable); + GetDlgItem(IDC_CDROMSIZE_EDIT)->EnableWindow(bEnable); + m_ctlCDROMMulti.EnableWindow(bEnable); + GetDlgItem(IDC_LANSIZE_EDIT)->EnableWindow(bEnable); + m_ctlLANMulti.EnableWindow(bEnable); +} + +void CBufferSizeDlg::OnOnlydefaultCheck() +{ + UpdateData(TRUE); + EnableControls(m_bOnlyDefaultCheck == 0); +} Index: src/ch/BufferSizeDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/BufferSizeDlg.h (.../BufferSizeDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/BufferSizeDlg.h (.../BufferSizeDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,84 +1,84 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __BUFFERSIZEDLG_H__ -#define __BUFFERSIZEDLG_H__ - -#include "DataBuffer.h" - -///////////////////////////////////////////////////////////////////////////// -// CBufferSizeDlg dialog - -class CBufferSizeDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CBufferSizeDlg(); // standard constructor - - void SetLANSize(UINT uiSize); - void SetCDSize(UINT uiSize); - void SetTwoDisksSize(UINT uiSize); - void SetOneDiskSize(UINT uiSize); - void SetDefaultSize(UINT uiSize); - UINT IndexToValue(int iIndex); - - int m_iActiveIndex; - BUFFERSIZES m_bsSizes; - -// Dialog Data - //{{AFX_DATA(CBufferSizeDlg) - enum { IDD = IDD_BUFFERSIZE_DIALOG }; - CComboBox m_ctlTwoDisksMulti; - CComboBox m_ctlOneDiskMulti; - CComboBox m_ctlLANMulti; - CComboBox m_ctlDefaultMulti; - CComboBox m_ctlCDROMMulti; - UINT m_uiDefaultSize; - UINT m_uiLANSize; - UINT m_uiCDROMSize; - UINT m_uiOneDiskSize; - UINT m_uiTwoDisksSize; - BOOL m_bOnlyDefaultCheck; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CBufferSizeDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - virtual void OnLanguageChanged(); - - void EnableControls(bool bEnable=true); - // Generated message map functions - //{{AFX_MSG(CBufferSizeDlg) - virtual BOOL OnInitDialog(); - virtual void OnOK(); - afx_msg void OnOnlydefaultCheck(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __BUFFERSIZEDLG_H__ +#define __BUFFERSIZEDLG_H__ + +#include "DataBuffer.h" + +///////////////////////////////////////////////////////////////////////////// +// CBufferSizeDlg dialog + +class CBufferSizeDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CBufferSizeDlg(); // standard constructor + + void SetLANSize(UINT uiSize); + void SetCDSize(UINT uiSize); + void SetTwoDisksSize(UINT uiSize); + void SetOneDiskSize(UINT uiSize); + void SetDefaultSize(UINT uiSize); + UINT IndexToValue(int iIndex); + + int m_iActiveIndex; + BUFFERSIZES m_bsSizes; + +// Dialog Data + //{{AFX_DATA(CBufferSizeDlg) + enum { IDD = IDD_BUFFERSIZE_DIALOG }; + CComboBox m_ctlTwoDisksMulti; + CComboBox m_ctlOneDiskMulti; + CComboBox m_ctlLANMulti; + CComboBox m_ctlDefaultMulti; + CComboBox m_ctlCDROMMulti; + UINT m_uiDefaultSize; + UINT m_uiLANSize; + UINT m_uiCDROMSize; + UINT m_uiOneDiskSize; + UINT m_uiTwoDisksSize; + BOOL m_bOnlyDefaultCheck; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CBufferSizeDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + virtual void OnLanguageChanged(); + + void EnableControls(bool bEnable=true); + // Generated message map functions + //{{AFX_MSG(CBufferSizeDlg) + virtual BOOL OnInitDialog(); + virtual void OnOK(); + afx_msg void OnOnlydefaultCheck(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/CfgProperties.cpp =================================================================== diff -u -rf6c4389122d92e5f84a509e9be0facebac429151 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/CfgProperties.cpp (.../CfgProperties.cpp) (revision f6c4389122d92e5f84a509e9be0facebac429151) +++ src/ch/CfgProperties.cpp (.../CfgProperties.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,114 +1,114 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "CfgProperties.h" -#include "../libicpf/config_property.h" - -#ifdef DEBUG -#define new DEBUG NEW -#endif - -bool RegisterProperties(icpf::config* pManager) -{ - const long long llHour = 3600UL*1000UL; -// const long long llMinute = 60UL*1000UL; - const long long llSecond = 1000UL; - - pManager->register_bool(_t("Program/Enabled clipboard monitoring"), false); - pManager->register_signed_num(_t("Program/Monitor scan interval"), 1000, 0, llHour); - pManager->register_bool(_t("Program/Reload after restart"), false); - pManager->register_bool(_t("Program/Shutdown system after finished"), false); - pManager->register_signed_num(_t("Program/Time before shutdown"), 10000, 0, 24*llHour); - pManager->register_bool(_t("Program/Force shutdown"), false); - pManager->register_signed_num(_t("Program/Autosave interval"), 30*llSecond, 0, 24*llHour); - pManager->register_signed_num(_t("Program/Process priority class"), NORMAL_PRIORITY_CLASS, 0, 0xffffffff); -// pManager->register_string(_t("Program/Autosave directory"), _t("\\"), icpf::property::flag_path); - pManager->register_string(_t("Program/Language"), _t("\\Langs\\English.lng")); - - pManager->register_signed_num(_t("Status dialog/Status refresh interval"), 1000, 0, 24*llHour); - pManager->register_bool(_t("Status dialog/Show details"), true); - pManager->register_bool(_t("Status dialog/Auto remove finished"), false); - - pManager->register_signed_num(_t("Folder dialog/Dialog width"), -1, -1, 32767); - pManager->register_signed_num(_t("Folder dialog/Dialog height"), -1, -1, 32767); - pManager->register_signed_num(_t("Folder dialog/Shortcut list style"), 1, 0, 3); - pManager->register_bool(_t("Folder dialog/Extended view"), true); - pManager->register_bool(_t("Folder dialog/Ignore shell dialogs"), false); - - pManager->register_bool(_t("Mini view/Show filenames"), true); - pManager->register_bool(_t("Mini view/Show single tasks"), true); - pManager->register_signed_num(_t("Mini view/Miniview refresh interval"), 200, 0, 24*llHour); - pManager->register_bool(_t("Mini view/Autoshow when run"), true); - pManager->register_bool(_t("Mini view/Autohide when empty"), true); - pManager->register_bool(_t("Mini view/Use smooth progress"), true); - - pManager->register_bool(_t("Copying/Use auto-complete files"), true); - pManager->register_bool(_t("Copying/Always set destination attributes"), true); - pManager->register_bool(_t("Copying/Always set destination time"), true); - pManager->register_bool(_t("Copying/Protect read-only files"), false); - pManager->register_signed_num(_t("Copying/Limit max operations"), 1, 0, 0xffffffff); - pManager->register_bool(_t("Copying/Read tasks size before blocking"), true); - pManager->register_signed_num(_t("Copying/Show visual feedback"), 2, 0, 2); - pManager->register_bool(_t("Copying/Use timed feedback dialogs"), false); - pManager->register_signed_num(_t("Copying/Feedback time"), 60*llSecond, 0, 24*llHour); - pManager->register_bool(_t("Copying/Auto retry on error"), true); - pManager->register_signed_num(_t("Copying/Auto retry interval"), 10*llSecond, 0, 24*llHour); - pManager->register_signed_num(_t("Copying/Default priority"), THREAD_PRIORITY_NORMAL, 0, 0xffffffff); - pManager->register_bool(_t("Copying/Disable priority boost"), false); - pManager->register_bool(_t("Copying/Delete files after finished"), true); - pManager->register_bool(_t("Copying/Create log file"), true); - - pManager->register_bool(_t("Shell/Show 'Copy' command"), true); - pManager->register_bool(_t("Shell/Show 'Move' command"), true); - pManager->register_bool(_t("Shell/Show 'Copy,move special' command"), true); - pManager->register_bool(_t("Shell/Show 'Paste' command"), true); - pManager->register_bool(_t("Shell/Show 'Paste special' command"), true); - pManager->register_bool(_t("Shell/Show 'Copy to' command"), true); - pManager->register_bool(_t("Shell/Show 'Move to' command"), true); - pManager->register_bool(_t("Shell/Show 'Copy to,Move to special' command"), true); - pManager->register_bool(_t("Shell/Show free space along with shortcut"), true); - pManager->register_bool(_t("Shell/Show shell icons in shortcuts menu"), false); - pManager->register_bool(_t("Shell/Use drag&drop default menu item override"), true); - pManager->register_signed_num(_t("Shell/Default action when dragging"), 3, 0, 0xffffffff); - - pManager->register_bool(_t("Buffer/Use only default buffer"), false); - pManager->register_signed_num(_t("Buffer/Default buffer size"), 2097152, 1, 0xffffffff); - pManager->register_signed_num(_t("Buffer/One physical disk buffer size"), 4194304, 1, 0xffffffff); - pManager->register_signed_num(_t("Buffer/Two different hard disks buffer size"), 524288, 1, 0xffffffff); - pManager->register_signed_num(_t("Buffer/CD buffer size"), 262144, 1, 0xffffffff); - pManager->register_signed_num(_t("Buffer/LAN buffer size"), 131072, 1, 0xffffffff); - pManager->register_bool(_t("Buffer/Use no buffering for large files"), true); - pManager->register_signed_num(_t("Buffer/Large files lower boundary limit"), 2097152, 1, 0xffffffff); - - pManager->register_string(_t("Log file/Path to main log file"), _t("\\ch.log")); - pManager->register_bool(_t("Log file/Enable logging"), true); - pManager->register_bool(_t("Log file/Enable log size limitation"), true); - pManager->register_signed_num(_t("Log file/Max log size limit"), 65535, 1024, 0xffffffff); - pManager->register_bool(_t("Log file/Precise log size limiting"), false); - pManager->register_signed_num(_t("Log file/Truncation buffer size"), 65535, 1024, 0xffffffff); - - pManager->register_bool(_t("Sounds/Play sounds"), true); - pManager->register_string(_t("Sounds/Error sound path"), _t("\\media\\chord.wav"), icpf::property::flag_path); - pManager->register_string(_t("Sounds/Finished sound path"), _t("\\media\\ding.wav"), icpf::property::flag_path); - - pManager->register_string(_t("Shortcuts/Shortcut"), _t(""), icpf::property::flag_array); - pManager->register_string(_t("Recent paths/Path"), _t(""), icpf::property::flag_array); - - return true; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "CfgProperties.h" +#include "../libicpf/config_property.h" + +#ifdef DEBUG +#define new DEBUG NEW +#endif + +bool RegisterProperties(icpf::config* pManager) +{ + const long long llHour = 3600UL*1000UL; +// const long long llMinute = 60UL*1000UL; + const long long llSecond = 1000UL; + + pManager->register_bool(_t("Program/Enabled clipboard monitoring"), false); + pManager->register_signed_num(_t("Program/Monitor scan interval"), 1000, 0, llHour); + pManager->register_bool(_t("Program/Reload after restart"), false); + pManager->register_bool(_t("Program/Shutdown system after finished"), false); + pManager->register_signed_num(_t("Program/Time before shutdown"), 10000, 0, 24*llHour); + pManager->register_bool(_t("Program/Force shutdown"), false); + pManager->register_signed_num(_t("Program/Autosave interval"), 30*llSecond, 0, 24*llHour); + pManager->register_signed_num(_t("Program/Process priority class"), NORMAL_PRIORITY_CLASS, 0, 0xffffffff); +// pManager->register_string(_t("Program/Autosave directory"), _t("\\"), icpf::property::flag_path); + pManager->register_string(_t("Program/Language"), _t("\\Langs\\English.lng")); + + pManager->register_signed_num(_t("Status dialog/Status refresh interval"), 1000, 0, 24*llHour); + pManager->register_bool(_t("Status dialog/Show details"), true); + pManager->register_bool(_t("Status dialog/Auto remove finished"), false); + + pManager->register_signed_num(_t("Folder dialog/Dialog width"), -1, -1, 32767); + pManager->register_signed_num(_t("Folder dialog/Dialog height"), -1, -1, 32767); + pManager->register_signed_num(_t("Folder dialog/Shortcut list style"), 1, 0, 3); + pManager->register_bool(_t("Folder dialog/Extended view"), true); + pManager->register_bool(_t("Folder dialog/Ignore shell dialogs"), false); + + pManager->register_bool(_t("Mini view/Show filenames"), true); + pManager->register_bool(_t("Mini view/Show single tasks"), true); + pManager->register_signed_num(_t("Mini view/Miniview refresh interval"), 200, 0, 24*llHour); + pManager->register_bool(_t("Mini view/Autoshow when run"), true); + pManager->register_bool(_t("Mini view/Autohide when empty"), true); + pManager->register_bool(_t("Mini view/Use smooth progress"), true); + + pManager->register_bool(_t("Copying/Use auto-complete files"), true); + pManager->register_bool(_t("Copying/Always set destination attributes"), true); + pManager->register_bool(_t("Copying/Always set destination time"), true); + pManager->register_bool(_t("Copying/Protect read-only files"), false); + pManager->register_signed_num(_t("Copying/Limit max operations"), 1, 0, 0xffffffff); + pManager->register_bool(_t("Copying/Read tasks size before blocking"), true); + pManager->register_signed_num(_t("Copying/Show visual feedback"), 2, 0, 2); + pManager->register_bool(_t("Copying/Use timed feedback dialogs"), false); + pManager->register_signed_num(_t("Copying/Feedback time"), 60*llSecond, 0, 24*llHour); + pManager->register_bool(_t("Copying/Auto retry on error"), true); + pManager->register_signed_num(_t("Copying/Auto retry interval"), 10*llSecond, 0, 24*llHour); + pManager->register_signed_num(_t("Copying/Default priority"), THREAD_PRIORITY_NORMAL, 0, 0xffffffff); + pManager->register_bool(_t("Copying/Disable priority boost"), false); + pManager->register_bool(_t("Copying/Delete files after finished"), true); + pManager->register_bool(_t("Copying/Create log file"), true); + + pManager->register_bool(_t("Shell/Show 'Copy' command"), true); + pManager->register_bool(_t("Shell/Show 'Move' command"), true); + pManager->register_bool(_t("Shell/Show 'Copy,move special' command"), true); + pManager->register_bool(_t("Shell/Show 'Paste' command"), true); + pManager->register_bool(_t("Shell/Show 'Paste special' command"), true); + pManager->register_bool(_t("Shell/Show 'Copy to' command"), true); + pManager->register_bool(_t("Shell/Show 'Move to' command"), true); + pManager->register_bool(_t("Shell/Show 'Copy to,Move to special' command"), true); + pManager->register_bool(_t("Shell/Show free space along with shortcut"), true); + pManager->register_bool(_t("Shell/Show shell icons in shortcuts menu"), false); + pManager->register_bool(_t("Shell/Use drag&drop default menu item override"), true); + pManager->register_signed_num(_t("Shell/Default action when dragging"), 3, 0, 0xffffffff); + + pManager->register_bool(_t("Buffer/Use only default buffer"), false); + pManager->register_signed_num(_t("Buffer/Default buffer size"), 2097152, 1, 0xffffffff); + pManager->register_signed_num(_t("Buffer/One physical disk buffer size"), 4194304, 1, 0xffffffff); + pManager->register_signed_num(_t("Buffer/Two different hard disks buffer size"), 524288, 1, 0xffffffff); + pManager->register_signed_num(_t("Buffer/CD buffer size"), 262144, 1, 0xffffffff); + pManager->register_signed_num(_t("Buffer/LAN buffer size"), 131072, 1, 0xffffffff); + pManager->register_bool(_t("Buffer/Use no buffering for large files"), true); + pManager->register_signed_num(_t("Buffer/Large files lower boundary limit"), 2097152, 1, 0xffffffff); + + pManager->register_string(_t("Log file/Path to main log file"), _t("\\ch.log")); + pManager->register_bool(_t("Log file/Enable logging"), true); + pManager->register_bool(_t("Log file/Enable log size limitation"), true); + pManager->register_signed_num(_t("Log file/Max log size limit"), 65535, 1024, 0xffffffff); + pManager->register_bool(_t("Log file/Precise log size limiting"), false); + pManager->register_signed_num(_t("Log file/Truncation buffer size"), 65535, 1024, 0xffffffff); + + pManager->register_bool(_t("Sounds/Play sounds"), true); + pManager->register_string(_t("Sounds/Error sound path"), _t("\\media\\chord.wav"), icpf::property::flag_path); + pManager->register_string(_t("Sounds/Finished sound path"), _t("\\media\\ding.wav"), icpf::property::flag_path); + + pManager->register_string(_t("Shortcuts/Shortcut"), _t(""), icpf::property::flag_array); + pManager->register_string(_t("Recent paths/Path"), _t(""), icpf::property::flag_array); + + return true; +} Index: src/ch/CfgProperties.h =================================================================== diff -u -rf6c4389122d92e5f84a509e9be0facebac429151 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/CfgProperties.h (.../CfgProperties.h) (revision f6c4389122d92e5f84a509e9be0facebac429151) +++ src/ch/CfgProperties.h (.../CfgProperties.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,113 +1,113 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __PROPERTYTYPES_H__ -#define __PROPERTYTYPES_H__ - -#pragma once - -#include "../libicpf/cfg.h" - -// properties definitions -enum CHProperties -{ - PP_PCLIPBOARDMONITORING = 0, - PP_PMONITORSCANINTERVAL, - PP_PRELOADAFTERRESTART, - PP_PSHUTDOWNAFTREFINISHED, - PP_PTIMEBEFORESHUTDOWN, - PP_PFORCESHUTDOWN, - PP_PAUTOSAVEINTERVAL, - PP_PPROCESSPRIORITYCLASS, -// PP_PAUTOSAVEDIRECTORY, - PP_PLANGUAGE, - - PP_STATUSREFRESHINTERVAL, - PP_STATUSSHOWDETAILS, - PP_STATUSAUTOREMOVEFINISHED, - - PP_FDWIDTH, - PP_FDHEIGHT, - PP_FDSHORTCUTLISTSTYLE, - PP_FDEXTENDEDVIEW, - PP_FDIGNORESHELLDIALOGS, - - PP_MVSHOWFILENAMES, - PP_MVSHOWSINGLETASKS, - PP_MVREFRESHINTERVAL, - PP_MVAUTOSHOWWHENRUN, - PP_MVAUTOHIDEWHENEMPTY, - PP_MVUSESMOOTHPROGRESS, - - PP_CMUSEAUTOCOMPLETEFILES, - PP_CMSETDESTATTRIBUTES, - PP_CMSETDESTDATE, - PP_CMPROTECTROFILES, - PP_CMLIMITMAXOPERATIONS, - PP_CMREADSIZEBEFOREBLOCKING, - PP_CMSHOWVISUALFEEDBACK, - PP_CMUSETIMEDFEEDBACK, - PP_CMFEEDBACKTIME, - PP_CMAUTORETRYONERROR, - PP_CMAUTORETRYINTERVAL, - PP_CMDEFAULTPRIORITY, - PP_CMDISABLEPRIORITYBOOST, - PP_CMDELETEAFTERFINISHED, - PP_CMCREATELOG, - - PP_SHSHOWCOPY, - PP_SHSHOWMOVE, - PP_SHSHOWCOPYMOVE, - PP_SHSHOWPASTE, - PP_SHSHOWPASTESPECIAL, - PP_SHSHOWCOPYTO, - PP_SHSHOWMOVETO, - PP_SHSHOWCOPYMOVETO, - PP_SHSHOWFREESPACE, - PP_SHSHOWSHELLICONS, - PP_SHUSEDRAGDROP, - PP_SHDEFAULTACTION, - - PP_BFUSEONLYDEFAULT, - PP_BFDEFAULT, - PP_BFONEDISK, - PP_BFTWODISKS, - PP_BFCD, - PP_BFLAN, - PP_BFUSENOBUFFERING, - PP_BFBOUNDARYLIMIT, - - PP_LOGPATH, - PP_LOGENABLELOGGING, - PP_LOGLIMITATION, - PP_LOGMAXLIMIT, - PP_LOGPRECISELIMITING, - PP_LOGTRUNCBUFFERSIZE, - - PP_SNDPLAYSOUNDS, - PP_SNDERRORSOUNDPATH, - PP_SNDFINISHEDSOUNDPATH, - - PP_SHORTCUTS, - PP_RECENTPATHS -}; - -// register function -bool RegisterProperties(icpf::config* pManager); - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __PROPERTYTYPES_H__ +#define __PROPERTYTYPES_H__ + +#pragma once + +#include "../libicpf/cfg.h" + +// properties definitions +enum CHProperties +{ + PP_PCLIPBOARDMONITORING = 0, + PP_PMONITORSCANINTERVAL, + PP_PRELOADAFTERRESTART, + PP_PSHUTDOWNAFTREFINISHED, + PP_PTIMEBEFORESHUTDOWN, + PP_PFORCESHUTDOWN, + PP_PAUTOSAVEINTERVAL, + PP_PPROCESSPRIORITYCLASS, +// PP_PAUTOSAVEDIRECTORY, + PP_PLANGUAGE, + + PP_STATUSREFRESHINTERVAL, + PP_STATUSSHOWDETAILS, + PP_STATUSAUTOREMOVEFINISHED, + + PP_FDWIDTH, + PP_FDHEIGHT, + PP_FDSHORTCUTLISTSTYLE, + PP_FDEXTENDEDVIEW, + PP_FDIGNORESHELLDIALOGS, + + PP_MVSHOWFILENAMES, + PP_MVSHOWSINGLETASKS, + PP_MVREFRESHINTERVAL, + PP_MVAUTOSHOWWHENRUN, + PP_MVAUTOHIDEWHENEMPTY, + PP_MVUSESMOOTHPROGRESS, + + PP_CMUSEAUTOCOMPLETEFILES, + PP_CMSETDESTATTRIBUTES, + PP_CMSETDESTDATE, + PP_CMPROTECTROFILES, + PP_CMLIMITMAXOPERATIONS, + PP_CMREADSIZEBEFOREBLOCKING, + PP_CMSHOWVISUALFEEDBACK, + PP_CMUSETIMEDFEEDBACK, + PP_CMFEEDBACKTIME, + PP_CMAUTORETRYONERROR, + PP_CMAUTORETRYINTERVAL, + PP_CMDEFAULTPRIORITY, + PP_CMDISABLEPRIORITYBOOST, + PP_CMDELETEAFTERFINISHED, + PP_CMCREATELOG, + + PP_SHSHOWCOPY, + PP_SHSHOWMOVE, + PP_SHSHOWCOPYMOVE, + PP_SHSHOWPASTE, + PP_SHSHOWPASTESPECIAL, + PP_SHSHOWCOPYTO, + PP_SHSHOWMOVETO, + PP_SHSHOWCOPYMOVETO, + PP_SHSHOWFREESPACE, + PP_SHSHOWSHELLICONS, + PP_SHUSEDRAGDROP, + PP_SHDEFAULTACTION, + + PP_BFUSEONLYDEFAULT, + PP_BFDEFAULT, + PP_BFONEDISK, + PP_BFTWODISKS, + PP_BFCD, + PP_BFLAN, + PP_BFUSENOBUFFERING, + PP_BFBOUNDARYLIMIT, + + PP_LOGPATH, + PP_LOGENABLELOGGING, + PP_LOGLIMITATION, + PP_LOGMAXLIMIT, + PP_LOGPRECISELIMITING, + PP_LOGTRUNCBUFFERSIZE, + + PP_SNDPLAYSOUNDS, + PP_SNDERRORSOUNDPATH, + PP_SNDFINISHEDSOUNDPATH, + + PP_SHORTCUTS, + PP_RECENTPATHS +}; + +// register function +bool RegisterProperties(icpf::config* pManager); + #endif \ No newline at end of file Index: src/ch/CrashDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/CrashDlg.cpp (.../CrashDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/CrashDlg.cpp (.../CrashDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,86 +1,86 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -// CrashDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "ch.h" -#include "CrashDlg.h" -#include "../common/version.h" - -#define IDS_CRASH_TITLE _T("Application crashed") -#define IDS_STATIC_INFO _T("Copy Handler encountered an internal problem and will be closed.\n\nIf you want to help correct this problem in the future releases of program you can send the crash information to the author of this program (e-mail it to ixen@copyhandler.com).") -#define IDS_VERSIONINFO_STATIC _T("Program version:") -#define IDS_LOCATIONINFO_STATIC _T("Crash dump location:") -#define IDS_LOCATION_STATIC _T("Error encountered while trying to create crash dump") -#define IDS_OK _T("&Close") - -// CCrashDlg dialog - -IMPLEMENT_DYNAMIC(CCrashDlg,ictranslate::CLanguageDialog) - -CCrashDlg::CCrashDlg(bool bResult, PCTSTR pszFilename, CWnd* pParent /*=NULL*/) - : CDialog(CCrashDlg::IDD, pParent), - m_bResult(bResult), - m_strFilename(pszFilename) -{ -} - -CCrashDlg::~CCrashDlg() -{ -} - -void CCrashDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - DDX_Control(pDX, IDC_VERSION_STATIC, m_ctlVersion); - DDX_Control(pDX, IDC_LOCATION_EDIT, m_ctlLocation); - DDX_Control(pDX, IDOK, m_ctlOKButton); - DDX_Control(pDX, IDC_STATIC_INFO, m_ctlInfo); - DDX_Control(pDX, IDC_VERSIONINFO_STATIC, m_ctlVersionInfo); - DDX_Control(pDX, IDC_LOCATIONINFO_STATIC, m_ctlLocationInfo); -} - - -BEGIN_MESSAGE_MAP(CCrashDlg, CDialog) -END_MESSAGE_MAP() - - -// CCrashDlg message handlers - -BOOL CCrashDlg::OnInitDialog() -{ - CDialog::OnInitDialog(); - - SetWindowText(IDS_CRASH_TITLE); - m_ctlInfo.SetWindowText(IDS_STATIC_INFO); - m_ctlVersionInfo.SetWindowText(IDS_VERSIONINFO_STATIC); - m_ctlVersion.SetWindowText(PRODUCT_FULL_VERSION_T); - m_ctlLocationInfo.SetWindowText(IDS_LOCATIONINFO_STATIC); - if(m_bResult) - m_ctlLocation.SetWindowText(m_strFilename); - else - m_ctlLocation.SetWindowText(IDS_LOCATION_STATIC); - - m_ctlOKButton.SetWindowText(IDS_OK); - m_ctlOKButton.EnableWindow(m_bResult); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +// CrashDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "ch.h" +#include "CrashDlg.h" +#include "../common/version.h" + +#define IDS_CRASH_TITLE _T("Application crashed") +#define IDS_STATIC_INFO _T("Copy Handler encountered an internal problem and will be closed.\n\nIf you want to help correct this problem in the future releases of program you can send the crash information to the author of this program (e-mail it to ixen@copyhandler.com).") +#define IDS_VERSIONINFO_STATIC _T("Program version:") +#define IDS_LOCATIONINFO_STATIC _T("Crash dump location:") +#define IDS_LOCATION_STATIC _T("Error encountered while trying to create crash dump") +#define IDS_OK _T("&Close") + +// CCrashDlg dialog + +IMPLEMENT_DYNAMIC(CCrashDlg,ictranslate::CLanguageDialog) + +CCrashDlg::CCrashDlg(bool bResult, PCTSTR pszFilename, CWnd* pParent /*=NULL*/) + : CDialog(CCrashDlg::IDD, pParent), + m_bResult(bResult), + m_strFilename(pszFilename) +{ +} + +CCrashDlg::~CCrashDlg() +{ +} + +void CCrashDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + DDX_Control(pDX, IDC_VERSION_STATIC, m_ctlVersion); + DDX_Control(pDX, IDC_LOCATION_EDIT, m_ctlLocation); + DDX_Control(pDX, IDOK, m_ctlOKButton); + DDX_Control(pDX, IDC_STATIC_INFO, m_ctlInfo); + DDX_Control(pDX, IDC_VERSIONINFO_STATIC, m_ctlVersionInfo); + DDX_Control(pDX, IDC_LOCATIONINFO_STATIC, m_ctlLocationInfo); +} + + +BEGIN_MESSAGE_MAP(CCrashDlg, CDialog) +END_MESSAGE_MAP() + + +// CCrashDlg message handlers + +BOOL CCrashDlg::OnInitDialog() +{ + CDialog::OnInitDialog(); + + SetWindowText(IDS_CRASH_TITLE); + m_ctlInfo.SetWindowText(IDS_STATIC_INFO); + m_ctlVersionInfo.SetWindowText(IDS_VERSIONINFO_STATIC); + m_ctlVersion.SetWindowText(PRODUCT_FULL_VERSION_T); + m_ctlLocationInfo.SetWindowText(IDS_LOCATIONINFO_STATIC); + if(m_bResult) + m_ctlLocation.SetWindowText(m_strFilename); + else + m_ctlLocation.SetWindowText(IDS_LOCATION_STATIC); + + m_ctlOKButton.SetWindowText(IDS_OK); + m_ctlOKButton.EnableWindow(m_bResult); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} Index: src/ch/CrashDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/CrashDlg.h (.../CrashDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/CrashDlg.h (.../CrashDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,53 +1,53 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#pragma once -#include "afxwin.h" - - -// CCrashDlg dialog - -class CCrashDlg : public CDialog -{ - DECLARE_DYNAMIC(CCrashDlg) - -public: - CCrashDlg(bool bResult, PCTSTR pszFilename, CWnd* pParent = NULL); // standard constructor - virtual ~CCrashDlg(); - - virtual BOOL OnInitDialog(); - -// Dialog Data - enum { IDD = IDD_CRASH_DIALOG }; - -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - - DECLARE_MESSAGE_MAP() - -protected: - bool m_bResult; - CString m_strFilename; -public: - CStatic m_ctlVersion; - CEdit m_ctlLocation; - CButton m_ctlOKButton; - CStatic m_ctlInfo; - CStatic m_ctlVersionInfo; - CStatic m_ctlLocationInfo; -}; +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#pragma once +#include "afxwin.h" + + +// CCrashDlg dialog + +class CCrashDlg : public CDialog +{ + DECLARE_DYNAMIC(CCrashDlg) + +public: + CCrashDlg(bool bResult, PCTSTR pszFilename, CWnd* pParent = NULL); // standard constructor + virtual ~CCrashDlg(); + + virtual BOOL OnInitDialog(); + +// Dialog Data + enum { IDD = IDD_CRASH_DIALOG }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + DECLARE_MESSAGE_MAP() + +protected: + bool m_bResult; + CString m_strFilename; +public: + CStatic m_ctlVersion; + CEdit m_ctlLocation; + CButton m_ctlOKButton; + CStatic m_ctlInfo; + CStatic m_ctlVersionInfo; + CStatic m_ctlLocationInfo; +}; Index: src/ch/CustomCopyDlg.cpp =================================================================== diff -u -rd6da900f71c2fb7f65e7443baf279c7f626d057d -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision d6da900f71c2fb7f65e7443baf279c7f626d057d) +++ src/ch/CustomCopyDlg.cpp (.../CustomCopyDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,934 +1,934 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "resource.h" -#include "CustomCopyDlg.h" -#include "structs.h" -#include "dialogs.h" -#include "BufferSizeDlg.h" -#include "FilterDlg.h" -#include "StringHelpers.h" -#include "ch.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CCustomCopyDlg dialog - - -CCustomCopyDlg::CCustomCopyDlg() :ictranslate::CLanguageDialog(CCustomCopyDlg::IDD) -{ - //{{AFX_DATA_INIT(CCustomCopyDlg) - m_ucCount = 1; - m_bOnlyCreate = FALSE; - m_bIgnoreFolders = FALSE; - m_bFilters = FALSE; - m_bAdvanced = FALSE; - m_bForceDirectories = FALSE; - //}}AFX_DATA_INIT - -// m_ccData.m_astrPaths.RemoveAll(); // unneeded -// m_ccData.m_strDestPath.Empty(); - - m_ccData.m_iOperation=0; - m_ccData.m_iPriority=THREAD_PRIORITY_NORMAL; - m_ccData.m_ucCount=1; - - // m_ccData.m_bsSizes stays uninitialized - // m_ccData.m_afFilters - this too - - m_ccData.m_bIgnoreFolders=false; - m_ccData.m_bForceDirectories=false; - m_ccData.m_bCreateStructure=false; - - m_bActualisation=false; -} - -void CCustomCopyDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CCustomCopyDlg) - DDX_Control(pDX, IDC_DESTPATH_COMBOBOXEX, m_ctlDstPath); - DDX_Control(pDX, IDC_COUNT_SPIN, m_ctlCountSpin); - DDX_Control(pDX, IDC_FILTERS_LIST, m_ctlFilters); - DDX_Control(pDX, IDC_BUFFERSIZES_LIST, m_ctlBufferSizes); - DDX_Control(pDX, IDC_OPERATION_COMBO, m_ctlOperation); - DDX_Control(pDX, IDC_PRIORITY_COMBO, m_ctlPriority); - DDX_Control(pDX, IDC_FILES_LIST, m_ctlFiles); - DDX_Text(pDX, IDC_COUNT_EDIT, m_ucCount); - DDV_MinMaxByte(pDX, m_ucCount, 1, 255); - DDX_Check(pDX, IDC_ONLYSTRUCTURE_CHECK, m_bOnlyCreate); - DDX_Check(pDX, IDC_IGNOREFOLDERS_CHECK, m_bIgnoreFolders); - DDX_Check(pDX, IDC_FORCEDIRECTORIES_CHECK, m_bForceDirectories); - DDX_Check(pDX, IDC_FILTERS_CHECK, m_bFilters); - DDX_Check(pDX, IDC_ADVANCED_CHECK, m_bAdvanced); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CCustomCopyDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CCustomCopyDlg) - ON_BN_CLICKED(IDC_ADDDIR_BUTTON, OnAddDirectoryButton) - ON_BN_CLICKED(IDC_ADDFILE_BUTTON, OnAddFilesButton) - ON_BN_CLICKED(IDC_REMOVEFILEFOLDER_BUTTON, OnRemoveButton) - ON_BN_CLICKED(IDC_DESTBROWSE_BUTTON, OnBrowseButton) - ON_BN_CLICKED(IDC_BUFFERSIZES_BUTTON, OnChangebufferButton) - ON_BN_CLICKED(IDC_ADDFILTER_BUTTON, OnAddfilterButton) - ON_BN_CLICKED(IDC_REMOVEFILTER_BUTTON, OnRemovefilterButton) - ON_WM_DESTROY() - ON_BN_CLICKED(IDC_FILTERS_CHECK, OnFiltersCheck) - ON_BN_CLICKED(IDC_STANDARD_CHECK, OnStandardCheck) - ON_BN_CLICKED(IDC_ADVANCED_CHECK, OnAdvancedCheck) - ON_NOTIFY(NM_DBLCLK, IDC_FILTERS_LIST, OnDblclkFiltersList) - ON_LBN_DBLCLK(IDC_BUFFERSIZES_LIST, OnDblclkBuffersizesList) - ON_CBN_EDITCHANGE(IDC_DESTPATH_COMBOBOXEX, OnEditchangeDestpathComboboxex) - ON_BN_CLICKED(IDC_IMPORT_BUTTON, OnImportButton) - ON_BN_CLICKED(IDC_IGNOREFOLDERS_CHECK, OnIgnorefoldersCheck) - ON_BN_CLICKED(IDC_FORCEDIRECTORIES_CHECK, OnForcedirectoriesCheck) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CCustomCopyDlg message handlers -BOOL CCustomCopyDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // make this dialog on top - SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); - - // paths' listbox - init images - system image list - SHFILEINFO sfi; - HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - - m_ilImages.Attach(hImageList); - m_ctlFiles.SetImageList(&m_ilImages, LVSIL_SMALL); - - // calc list width - CRect rc; - m_ctlFiles.GetWindowRect(&rc); - rc.right-=GetSystemMetrics(SM_CXEDGE)*2; - - // some styles - m_ctlFiles.SetExtendedStyle(m_ctlFiles.GetExtendedStyle() | LVS_EX_FULLROWSELECT); - m_ctlFilters.SetExtendedStyle(m_ctlFiles.GetExtendedStyle() | LVS_EX_FULLROWSELECT); - - // paths' listbox - add one column - LVCOLUMN lvc; - lvc.mask=LVCF_FMT | LVCF_WIDTH; - lvc.fmt=LVCFMT_LEFT; - lvc.cx=rc.Width(); - m_ctlFiles.InsertColumn(1, &lvc); - - // fill paths' listbox - for (int i=0;iLoadString(IDS_CCDCOPY_STRING)); - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDMOVE_STRING)); - - // copying/moving - m_ctlOperation.SetCurSel(m_ccData.m_iOperation); - - // fill priority combo - for (int i=0;i<7;i++) - { - m_ctlPriority.AddString(GetResManager()->LoadString(IDS_PRIORITY0_STRING+i)); - } - - m_ctlPriority.SetCurSel(PriorityToIndex(m_ccData.m_iPriority)); - - // count of copies - m_ucCount=m_ccData.m_ucCount; - m_ctlCountSpin.SetRange(1, 255); - - // fill buffer sizes listbox - SetBuffersizesString(); - - // list width - m_ctlFilters.GetWindowRect(&rc); - rc.right-=GetSystemMetrics(SM_CXEDGE)*2; - - // filter - some columns in a header - lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; - lvc.fmt=LVCFMT_LEFT; - - // mask - lvc.iSubItem=-1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRMASK_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.15*rc.Width()); - m_ctlFilters.InsertColumn(1, &lvc); - - // exclude mask - lvc.iSubItem=0; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEMASK_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.15*rc.Width()); - m_ctlFilters.InsertColumn(2, &lvc); - - // size - lvc.iSubItem=1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRSIZE_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.3*rc.Width()); - m_ctlFilters.InsertColumn(3, &lvc); - - // time - lvc.iSubItem=2; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRDATE_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.3*rc.Width()); - m_ctlFilters.InsertColumn(4, &lvc); - - // attributes - lvc.iSubItem=3; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRATTRIB_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.1*rc.Width()); - m_ctlFilters.InsertColumn(5, &lvc); - - // -attributes - lvc.iSubItem=4; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEATTRIB_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.1*rc.Width()); - m_ctlFilters.InsertColumn(6, &lvc); - - m_bFilters = !m_ccData.m_afFilters.IsEmpty(); - - // other custom flags - m_bAdvanced=(m_ccData.m_bIgnoreFolders | m_ccData.m_bCreateStructure); - m_bIgnoreFolders=m_ccData.m_bIgnoreFolders; - m_bForceDirectories=m_ccData.m_bForceDirectories; - m_bOnlyCreate=m_ccData.m_bCreateStructure; - - UpdateData(FALSE); - - EnableControls(); - - return TRUE; -} - -void CCustomCopyDlg::OnLanguageChanged() -{ - UpdateData(TRUE); - - // count the width of a list - CRect rc; - m_ctlFiles.GetWindowRect(&rc); - rc.right-=GetSystemMetrics(SM_CXEDGE)*2; - - // change the width of a column - LVCOLUMN lvc; - lvc.mask=LVCF_WIDTH; - lvc.cx=rc.Width(); - m_ctlFiles.SetColumn(0, &lvc); - - // operation - int iPos=m_ctlOperation.GetCurSel(); - m_ctlOperation.ResetContent(); - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDCOPY_STRING)); - m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDMOVE_STRING)); - m_ctlOperation.SetCurSel(iPos); - - // priority combo - iPos=m_ctlPriority.GetCurSel(); - m_ctlPriority.ResetContent(); - for (int i=0;i<7;i++) - { - m_ctlPriority.AddString(GetResManager()->LoadString(IDS_PRIORITY0_STRING+i)); - } - m_ctlPriority.SetCurSel(iPos); - - // fill the listbox with buffers - SetBuffersizesString(); - - // filter section (filter, size, date, attributes) - while(m_ctlFilters.DeleteColumn(0)); // delete all columns - - lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; - lvc.fmt=LVCFMT_LEFT; - - // mask - lvc.iSubItem=-1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRMASK_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.15*rc.Width()); - m_ctlFilters.InsertColumn(1, &lvc); - - // exclude mask - lvc.iSubItem=0; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEMASK_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.15*rc.Width()); - m_ctlFilters.InsertColumn(2, &lvc); - - // size - lvc.iSubItem=1; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRSIZE_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.3*rc.Width()); - m_ctlFilters.InsertColumn(3, &lvc); - - // time - lvc.iSubItem=2; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRDATE_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.3*rc.Width()); - m_ctlFilters.InsertColumn(4, &lvc); - - // attributes - lvc.iSubItem=3; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRATTRIB_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.1*rc.Width()); - m_ctlFilters.InsertColumn(5, &lvc); - - // -attributes - lvc.iSubItem=4; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEATTRIB_STRING); - lvc.cchTextMax=lstrlen(lvc.pszText); - lvc.cx=static_cast(0.1*rc.Width()); - m_ctlFilters.InsertColumn(6, &lvc); - - // refresh the entries in filters' list - m_ctlFilters.DeleteAllItems(); - for (size_t i=0;iLoadString(IDS_BROWSE_STRING), &strPath)) - AddPath(strPath); -} - -void CCustomCopyDlg::OnAddFilesButton() -{ - CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager()->LoadString(IDS_FILEDLGALLFILTER_STRING), this); - - TCHAR *pszBuffer=new TCHAR[65535]; - memset(pszBuffer, 0, 65535*sizeof(TCHAR)); - dlg.m_ofn.lpstrFile=pszBuffer; - dlg.m_ofn.nMaxFile=65535; - - if (dlg.DoModal() == IDOK) - { - // first element is the path - CString strPath=pszBuffer; - - int iOffset=_tcslen(pszBuffer)+1; - - // get filenames - if (pszBuffer[iOffset] == _T('\0')) - AddPath(strPath); - else - { - if (strPath.Right(1) != _T("\\")) - strPath+=_T("\\"); - while (pszBuffer[iOffset] != _T('\0')) - { - AddPath(strPath+CString(pszBuffer+iOffset)); - iOffset+=_tcslen(pszBuffer+iOffset)+1; - } - } - } - - // delete buffer - delete [] pszBuffer; -} - -void CCustomCopyDlg::OnRemoveButton() -{ - POSITION pos; - int iItem; - while (true) - { - pos = m_ctlFiles.GetFirstSelectedItemPosition(); - if (pos == NULL) - break; - else - { - iItem=m_ctlFiles.GetNextSelectedItem(pos); - m_ctlFiles.DeleteItem(iItem); - } - } -} - -void CCustomCopyDlg::OnBrowseButton() -{ - CString strPath; - if (BrowseForFolder(GetResManager()->LoadString(IDS_DSTFOLDERBROWSE_STRING), &strPath)) - { - SetComboPath(strPath); -// m_strDest=strPath; //** - } -} - -void CCustomCopyDlg::OnOK() -{ - UpdateData(TRUE); - - // copy files from listctrl to an array - m_ccData.m_astrPaths.RemoveAll(); - CString strPath; - - for (int i=0;iLoadString(IDS_BSEDEFAULT_STRING)); - fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiDefaultSize, szSize, 64, true)); - m_ctlBufferSizes.AddString(fmt); - - if (!m_ccData.m_bsSizes.m_bOnlyDefault) - { - fmt.SetFormat(GetResManager()->LoadString(IDS_BSEONEDISK_STRING)); - fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiOneDiskSize, szSize, 64, true)); - m_ctlBufferSizes.AddString(fmt); - - fmt.SetFormat(GetResManager()->LoadString(IDS_BSETWODISKS_STRING)); - fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiTwoDisksSize, szSize, 64, true)); - m_ctlBufferSizes.AddString(fmt); - - fmt.SetFormat(GetResManager()->LoadString(IDS_BSECD_STRING)); - fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiCDSize, szSize, 64, true)); - m_ctlBufferSizes.AddString(fmt); - - fmt.SetFormat(GetResManager()->LoadString(IDS_BSELAN_STRING)); - fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiLANSize, szSize, 64, true)); - m_ctlBufferSizes.AddString(fmt); - } -} - -void CCustomCopyDlg::OnChangebufferButton() -{ - CBufferSizeDlg dlg; - dlg.m_bsSizes=m_ccData.m_bsSizes; - if (dlg.DoModal() == IDOK) - { - m_ccData.m_bsSizes=dlg.m_bsSizes; - SetBuffersizesString(); - } -} - -void CCustomCopyDlg::AddPath(CString strPath) -{ - // fill listbox with paths - LVITEM lvi; - lvi.mask=LVIF_TEXT | LVIF_IMAGE; - lvi.iItem=m_ctlFiles.GetItemCount(); - lvi.iSubItem=0; - - // there's no need for a high speed so get the images - SHFILEINFO sfi; - SHGetFileInfo(strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON/* | SHGFI_USEFILEATTRIBUTES*/); - - // fill the list - lvi.pszText=strPath.GetBuffer(0); - strPath.ReleaseBuffer(); - lvi.cchTextMax=lstrlen(lvi.pszText); - lvi.iImage=sfi.iIcon; - m_ctlFiles.InsertItem(&lvi); -} - -void CCustomCopyDlg::OnAddfilterButton() -{ - CFilterDlg dlg; - CString strData; - for (size_t i=0;im_bUseMask) - dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); - if(pFilter->m_bUseExcludeMask) - dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); - } - } - - if (dlg.DoModal() == IDOK) - { - if (dlg.m_ffFilter.m_bUseMask || dlg.m_ffFilter.m_bUseExcludeMask || dlg.m_ffFilter.m_bUseSize - || dlg.m_ffFilter.m_bUseDate || dlg.m_ffFilter.m_bUseAttributes) - { - m_ccData.m_afFilters.Add(dlg.m_ffFilter); - AddFilter(dlg.m_ffFilter); - } - else - MsgBox(IDS_EMPTYFILTER_STRING, MB_OK | MB_ICONINFORMATION); - } -} - -void CCustomCopyDlg::AddFilter(const CFileFilter &rFilter, int iPos) -{ - LVITEM lvi; - TCHAR szLoaded[1024]; - TCHAR szData[64]; - - lvi.mask=LVIF_TEXT; - lvi.iItem=(iPos == -1) ? m_ctlFilters.GetItemCount() : iPos; - - ///////////////////// - lvi.iSubItem=0; - - if (rFilter.m_bUseMask) - { - CString strData; - rFilter.GetCombinedMask(strData); - _tcscpy(szLoaded, strData); - } - else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERMASKEMPTY_STRING)); - - lvi.pszText=szLoaded; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlFilters.InsertItem(&lvi); - - ///////////////////// - lvi.iSubItem=1; - - if (rFilter.m_bUseExcludeMask) - { - CString strData; - rFilter.GetCombinedExcludeMask(strData); - _tcscpy(szLoaded, strData); - } - else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERMASKEMPTY_STRING)); - - lvi.pszText=szLoaded; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlFilters.SetItem(&lvi); - - ///////////////// - lvi.iSubItem=2; - - if (rFilter.m_bUseSize) - { - _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iSizeType1), GetSizeString(rFilter.m_ullSize1, szData, 64, true)); - szLoaded[1023] = _T('\0'); - if (rFilter.m_bUseSize2) - { - _tcscat(szLoaded, GetResManager()->LoadString(IDS_AND_STRING)); - CString strLoaded2; - strLoaded2.Format(_T("%s %s"), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iSizeType2), GetSizeString(rFilter.m_ullSize2, szData, 64, true)); - _tcscat(szLoaded, strLoaded2); - } - } - else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERSIZE_STRING)); - - lvi.pszText=szLoaded; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlFilters.SetItem(&lvi); - - /////////////////// - lvi.iSubItem=3; - - if (rFilter.m_bUseDate) - { - _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager()->LoadString(IDS_DATECREATED_STRING+rFilter.m_iDateType), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iDateType1)); - szLoaded[1023] = _T('\0'); - if (rFilter.m_bDate1) - _tcscat(szLoaded, rFilter.m_tDate1.Format(_T(" %x"))); - if (rFilter.m_bTime1) - _tcscat(szLoaded, rFilter.m_tTime1.Format(_T(" %X"))); - - if (rFilter.m_bUseDate2) - { - _tcscat(szLoaded, GetResManager()->LoadString(IDS_AND_STRING)); - _tcscat(szLoaded, GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iDateType2)); - if (rFilter.m_bDate2) - _tcscat(szLoaded, rFilter.m_tDate2.Format(_T(" %x"))); - if (rFilter.m_bTime2) - _tcscat(szLoaded, rFilter.m_tTime2.Format(_T(" %X"))); - } - } - else - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERDATE_STRING)); - - lvi.pszText=szLoaded; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlFilters.SetItem(&lvi); - - ///////////////////// - lvi.iSubItem=4; - szLoaded[0]=_T('\0'); - if (rFilter.m_bUseAttributes) - { - if (rFilter.m_iArchive == 1) - _tcscat(szLoaded, _T("A")); - if (rFilter.m_iReadOnly == 1) - _tcscat(szLoaded, _T("R")); - if (rFilter.m_iHidden == 1) - _tcscat(szLoaded, _T("H")); - if (rFilter.m_iSystem == 1) - _tcscat(szLoaded, _T("S")); - if (rFilter.m_iDirectory == 1) - _tcscat(szLoaded, _T("D")); - } - - if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('\0')) - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERATTRIB_STRING)); - - lvi.pszText=szLoaded; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlFilters.SetItem(&lvi); - - ///////////////////// - lvi.iSubItem=5; - szLoaded[0]=_T('\0'); - if (rFilter.m_bUseAttributes) - { - if (rFilter.m_iArchive == 0) - _tcscat(szLoaded, _T("A")); - if (rFilter.m_iReadOnly == 0) - _tcscat(szLoaded, _T("R")); - if (rFilter.m_iHidden == 0) - _tcscat(szLoaded, _T("H")); - if (rFilter.m_iSystem == 0) - _tcscat(szLoaded, _T("S")); - if (rFilter.m_iDirectory == 0) - _tcscat(szLoaded, _T("D")); - } - - if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('0')) - _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERATTRIB_STRING)); - - lvi.pszText=szLoaded; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlFilters.SetItem(&lvi); -} - -void CCustomCopyDlg::OnRemovefilterButton() -{ - POSITION pos; - int iItem; - while (true) - { - pos=m_ctlFilters.GetFirstSelectedItemPosition(); - if (pos == NULL) - break; - else - { - iItem=m_ctlFilters.GetNextSelectedItem(pos); - m_ctlFilters.DeleteItem(iItem); - m_ccData.m_afFilters.RemoveAt(iItem); - } - } -} - -void CCustomCopyDlg::OnDestroy() -{ - m_ctlFiles.SetImageList(NULL, LVSIL_SMALL); - m_ilImages.Detach(); - - CLanguageDialog::OnDestroy(); -} - -void CCustomCopyDlg::EnableControls() -{ - UpdateData(TRUE); - - m_ctlFilters.EnableWindow(m_bFilters); - GetDlgItem(IDC_ADDFILTER_BUTTON)->EnableWindow(m_bFilters); - GetDlgItem(IDC_REMOVEFILTER_BUTTON)->EnableWindow(m_bFilters); - - GetDlgItem(IDC_IGNOREFOLDERS_CHECK)->EnableWindow(m_bAdvanced && !m_bForceDirectories); - GetDlgItem(IDC_FORCEDIRECTORIES_CHECK)->EnableWindow(m_bAdvanced && !m_bIgnoreFolders); - GetDlgItem(IDC_ONLYSTRUCTURE_CHECK)->EnableWindow(m_bAdvanced); -} - -void CCustomCopyDlg::OnFiltersCheck() -{ - EnableControls(); -} - -void CCustomCopyDlg::OnStandardCheck() -{ - EnableControls(); -} - -void CCustomCopyDlg::OnAdvancedCheck() -{ - EnableControls(); -} - -void CCustomCopyDlg::OnDblclkFiltersList(NMHDR* /*pNMHDR*/, LRESULT* pResult) -{ - POSITION pos=m_ctlFilters.GetFirstSelectedItemPosition(); - if (pos != NULL) - { - int iItem=m_ctlFilters.GetNextSelectedItem(pos); - CFilterDlg dlg; - const CFileFilter* pFilter = m_ccData.m_afFilters.GetAt(iItem); - BOOST_ASSERT(pFilter); - if(pFilter) - dlg.m_ffFilter = *pFilter; - - CString strData; - for (size_t i=0;im_bUseMask && i != iItem) - dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); - if (pFilter->m_bUseExcludeMask && i != iItem) - dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); - } - } - - if (dlg.DoModal() == IDOK) - { - // delete old element - m_ctlFilters.DeleteItem(iItem); - //m_ccData.m_afFilters.RemoveAt(iItem); - - // insert new if needed - if (dlg.m_ffFilter.m_bUseMask || dlg.m_ffFilter.m_bUseExcludeMask || dlg.m_ffFilter.m_bUseSize - || dlg.m_ffFilter.m_bUseDate || dlg.m_ffFilter.m_bUseAttributes) - { - m_ccData.m_afFilters.SetAt(iItem, dlg.m_ffFilter); - AddFilter(dlg.m_ffFilter, iItem); - } - } - } - - *pResult = 0; -} - -void CCustomCopyDlg::OnDblclkBuffersizesList() -{ - int iItem=m_ctlBufferSizes.GetCurSel(); - if (iItem != LB_ERR) - { - CBufferSizeDlg dlg; - dlg.m_bsSizes=m_ccData.m_bsSizes; - dlg.m_iActiveIndex=iItem; - if (dlg.DoModal() == IDOK) - { - m_ccData.m_bsSizes=dlg.m_bsSizes; - SetBuffersizesString(); - } - } -} - -void CCustomCopyDlg::SetComboPath(LPCTSTR lpszText) -{ - _ASSERTE(lpszText); - if(!lpszText) - return; - - // set current select to -1 - m_ctlDstPath.SetCurSel(-1); - - SHFILEINFO sfi; - sfi.iIcon=-1; - - COMBOBOXEXITEM cbi; - TCHAR szPath[_MAX_PATH]; - - cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; - cbi.iItem=-1; - _tcscpy(szPath, lpszText); - cbi.pszText=szPath; - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - cbi.iImage=sfi.iIcon; - m_ctlDstPath.SetItem(&cbi); -} - -void CCustomCopyDlg::UpdateComboIcon() -{ - // get text from combo - COMBOBOXEXITEM cbi; - TCHAR szPath[_MAX_PATH]; - memset(szPath, 0, _MAX_PATH); - cbi.mask=CBEIF_TEXT; - cbi.iItem=m_ctlDstPath.GetCurSel()/*-1*/; - cbi.pszText=szPath; - cbi.cchTextMax=_MAX_PATH; - - if (!m_ctlDstPath.GetItem(&cbi)) - return; - - // select no item - m_ctlDstPath.SetCurSel(-1); - - // icon update - SHFILEINFO sfi; - sfi.iIcon=-1; - - cbi.mask |= CBEIF_IMAGE; - cbi.iItem=-1; - - CString str=(LPCTSTR)szPath; - if (str.Left(2) != _T("\\\\") || str.Find(_T('\\'), 2) != -1) - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - - cbi.iImage=sfi.iIcon; - m_ctlDstPath.SetItem(&cbi); - - // unselect text in combo's edit - CEdit* pEdit=m_ctlDstPath.GetEditCtrl(); - if (!pEdit) - return; - - pEdit->SetSel(-1, -1); -} - -void CCustomCopyDlg::OnEditchangeDestpathComboboxex() -{ - if (m_bActualisation) - return; - m_bActualisation=true; - UpdateComboIcon(); - m_bActualisation=false; -} - -void CCustomCopyDlg::OnImportButton() -{ - CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager()->LoadString(IDS_FLTALLFILTER_STRING)); - if (dlg.DoModal() == IDOK) - { - UINT uiCount=0; - CString strData; - try - { - CFile file(dlg.GetPathName(), CFile::modeRead); - CArchive ar(&file, CArchive::load); - - while (ar.ReadString(strData)) - { - strData.TrimLeft(_T("\" \t")); - strData.TrimRight(_T("\" \t")); - AddPath(strData); - uiCount++; - } - - ar.Close(); - file.Close(); - } - catch(CException* e) - { - e->Delete(); - } - - // report - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_IMPORTREPORT_STRING)); - fmt.SetParam(_t("%count"), uiCount); - AfxMessageBox(fmt); - } -} - -void CCustomCopyDlg::OnForcedirectoriesCheck() -{ - UpdateData(TRUE); - - GetDlgItem(IDC_IGNOREFOLDERS_CHECK)->EnableWindow(!m_bForceDirectories); -} - -void CCustomCopyDlg::OnIgnorefoldersCheck() -{ - UpdateData(TRUE); - - GetDlgItem(IDC_FORCEDIRECTORIES_CHECK)->EnableWindow(!m_bIgnoreFolders); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "resource.h" +#include "CustomCopyDlg.h" +#include "structs.h" +#include "dialogs.h" +#include "BufferSizeDlg.h" +#include "FilterDlg.h" +#include "StringHelpers.h" +#include "ch.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CCustomCopyDlg dialog + + +CCustomCopyDlg::CCustomCopyDlg() :ictranslate::CLanguageDialog(CCustomCopyDlg::IDD) +{ + //{{AFX_DATA_INIT(CCustomCopyDlg) + m_ucCount = 1; + m_bOnlyCreate = FALSE; + m_bIgnoreFolders = FALSE; + m_bFilters = FALSE; + m_bAdvanced = FALSE; + m_bForceDirectories = FALSE; + //}}AFX_DATA_INIT + +// m_ccData.m_astrPaths.RemoveAll(); // unneeded +// m_ccData.m_strDestPath.Empty(); + + m_ccData.m_iOperation=0; + m_ccData.m_iPriority=THREAD_PRIORITY_NORMAL; + m_ccData.m_ucCount=1; + + // m_ccData.m_bsSizes stays uninitialized + // m_ccData.m_afFilters - this too + + m_ccData.m_bIgnoreFolders=false; + m_ccData.m_bForceDirectories=false; + m_ccData.m_bCreateStructure=false; + + m_bActualisation=false; +} + +void CCustomCopyDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CCustomCopyDlg) + DDX_Control(pDX, IDC_DESTPATH_COMBOBOXEX, m_ctlDstPath); + DDX_Control(pDX, IDC_COUNT_SPIN, m_ctlCountSpin); + DDX_Control(pDX, IDC_FILTERS_LIST, m_ctlFilters); + DDX_Control(pDX, IDC_BUFFERSIZES_LIST, m_ctlBufferSizes); + DDX_Control(pDX, IDC_OPERATION_COMBO, m_ctlOperation); + DDX_Control(pDX, IDC_PRIORITY_COMBO, m_ctlPriority); + DDX_Control(pDX, IDC_FILES_LIST, m_ctlFiles); + DDX_Text(pDX, IDC_COUNT_EDIT, m_ucCount); + DDV_MinMaxByte(pDX, m_ucCount, 1, 255); + DDX_Check(pDX, IDC_ONLYSTRUCTURE_CHECK, m_bOnlyCreate); + DDX_Check(pDX, IDC_IGNOREFOLDERS_CHECK, m_bIgnoreFolders); + DDX_Check(pDX, IDC_FORCEDIRECTORIES_CHECK, m_bForceDirectories); + DDX_Check(pDX, IDC_FILTERS_CHECK, m_bFilters); + DDX_Check(pDX, IDC_ADVANCED_CHECK, m_bAdvanced); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CCustomCopyDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CCustomCopyDlg) + ON_BN_CLICKED(IDC_ADDDIR_BUTTON, OnAddDirectoryButton) + ON_BN_CLICKED(IDC_ADDFILE_BUTTON, OnAddFilesButton) + ON_BN_CLICKED(IDC_REMOVEFILEFOLDER_BUTTON, OnRemoveButton) + ON_BN_CLICKED(IDC_DESTBROWSE_BUTTON, OnBrowseButton) + ON_BN_CLICKED(IDC_BUFFERSIZES_BUTTON, OnChangebufferButton) + ON_BN_CLICKED(IDC_ADDFILTER_BUTTON, OnAddfilterButton) + ON_BN_CLICKED(IDC_REMOVEFILTER_BUTTON, OnRemovefilterButton) + ON_WM_DESTROY() + ON_BN_CLICKED(IDC_FILTERS_CHECK, OnFiltersCheck) + ON_BN_CLICKED(IDC_STANDARD_CHECK, OnStandardCheck) + ON_BN_CLICKED(IDC_ADVANCED_CHECK, OnAdvancedCheck) + ON_NOTIFY(NM_DBLCLK, IDC_FILTERS_LIST, OnDblclkFiltersList) + ON_LBN_DBLCLK(IDC_BUFFERSIZES_LIST, OnDblclkBuffersizesList) + ON_CBN_EDITCHANGE(IDC_DESTPATH_COMBOBOXEX, OnEditchangeDestpathComboboxex) + ON_BN_CLICKED(IDC_IMPORT_BUTTON, OnImportButton) + ON_BN_CLICKED(IDC_IGNOREFOLDERS_CHECK, OnIgnorefoldersCheck) + ON_BN_CLICKED(IDC_FORCEDIRECTORIES_CHECK, OnForcedirectoriesCheck) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CCustomCopyDlg message handlers +BOOL CCustomCopyDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // make this dialog on top + SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); + + // paths' listbox - init images - system image list + SHFILEINFO sfi; + HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + + m_ilImages.Attach(hImageList); + m_ctlFiles.SetImageList(&m_ilImages, LVSIL_SMALL); + + // calc list width + CRect rc; + m_ctlFiles.GetWindowRect(&rc); + rc.right-=GetSystemMetrics(SM_CXEDGE)*2; + + // some styles + m_ctlFiles.SetExtendedStyle(m_ctlFiles.GetExtendedStyle() | LVS_EX_FULLROWSELECT); + m_ctlFilters.SetExtendedStyle(m_ctlFiles.GetExtendedStyle() | LVS_EX_FULLROWSELECT); + + // paths' listbox - add one column + LVCOLUMN lvc; + lvc.mask=LVCF_FMT | LVCF_WIDTH; + lvc.fmt=LVCFMT_LEFT; + lvc.cx=rc.Width(); + m_ctlFiles.InsertColumn(1, &lvc); + + // fill paths' listbox + for (int i=0;iLoadString(IDS_CCDCOPY_STRING)); + m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDMOVE_STRING)); + + // copying/moving + m_ctlOperation.SetCurSel(m_ccData.m_iOperation); + + // fill priority combo + for (int i=0;i<7;i++) + { + m_ctlPriority.AddString(GetResManager()->LoadString(IDS_PRIORITY0_STRING+i)); + } + + m_ctlPriority.SetCurSel(PriorityToIndex(m_ccData.m_iPriority)); + + // count of copies + m_ucCount=m_ccData.m_ucCount; + m_ctlCountSpin.SetRange(1, 255); + + // fill buffer sizes listbox + SetBuffersizesString(); + + // list width + m_ctlFilters.GetWindowRect(&rc); + rc.right-=GetSystemMetrics(SM_CXEDGE)*2; + + // filter - some columns in a header + lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt=LVCFMT_LEFT; + + // mask + lvc.iSubItem=-1; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRMASK_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.15*rc.Width()); + m_ctlFilters.InsertColumn(1, &lvc); + + // exclude mask + lvc.iSubItem=0; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEMASK_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.15*rc.Width()); + m_ctlFilters.InsertColumn(2, &lvc); + + // size + lvc.iSubItem=1; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRSIZE_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.3*rc.Width()); + m_ctlFilters.InsertColumn(3, &lvc); + + // time + lvc.iSubItem=2; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRDATE_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.3*rc.Width()); + m_ctlFilters.InsertColumn(4, &lvc); + + // attributes + lvc.iSubItem=3; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRATTRIB_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.1*rc.Width()); + m_ctlFilters.InsertColumn(5, &lvc); + + // -attributes + lvc.iSubItem=4; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEATTRIB_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.1*rc.Width()); + m_ctlFilters.InsertColumn(6, &lvc); + + m_bFilters = !m_ccData.m_afFilters.IsEmpty(); + + // other custom flags + m_bAdvanced=(m_ccData.m_bIgnoreFolders | m_ccData.m_bCreateStructure); + m_bIgnoreFolders=m_ccData.m_bIgnoreFolders; + m_bForceDirectories=m_ccData.m_bForceDirectories; + m_bOnlyCreate=m_ccData.m_bCreateStructure; + + UpdateData(FALSE); + + EnableControls(); + + return TRUE; +} + +void CCustomCopyDlg::OnLanguageChanged() +{ + UpdateData(TRUE); + + // count the width of a list + CRect rc; + m_ctlFiles.GetWindowRect(&rc); + rc.right-=GetSystemMetrics(SM_CXEDGE)*2; + + // change the width of a column + LVCOLUMN lvc; + lvc.mask=LVCF_WIDTH; + lvc.cx=rc.Width(); + m_ctlFiles.SetColumn(0, &lvc); + + // operation + int iPos=m_ctlOperation.GetCurSel(); + m_ctlOperation.ResetContent(); + m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDCOPY_STRING)); + m_ctlOperation.AddString(GetResManager()->LoadString(IDS_CCDMOVE_STRING)); + m_ctlOperation.SetCurSel(iPos); + + // priority combo + iPos=m_ctlPriority.GetCurSel(); + m_ctlPriority.ResetContent(); + for (int i=0;i<7;i++) + { + m_ctlPriority.AddString(GetResManager()->LoadString(IDS_PRIORITY0_STRING+i)); + } + m_ctlPriority.SetCurSel(iPos); + + // fill the listbox with buffers + SetBuffersizesString(); + + // filter section (filter, size, date, attributes) + while(m_ctlFilters.DeleteColumn(0)); // delete all columns + + lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt=LVCFMT_LEFT; + + // mask + lvc.iSubItem=-1; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRMASK_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.15*rc.Width()); + m_ctlFilters.InsertColumn(1, &lvc); + + // exclude mask + lvc.iSubItem=0; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEMASK_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.15*rc.Width()); + m_ctlFilters.InsertColumn(2, &lvc); + + // size + lvc.iSubItem=1; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRSIZE_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.3*rc.Width()); + m_ctlFilters.InsertColumn(3, &lvc); + + // time + lvc.iSubItem=2; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRDATE_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.3*rc.Width()); + m_ctlFilters.InsertColumn(4, &lvc); + + // attributes + lvc.iSubItem=3; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDRATTRIB_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.1*rc.Width()); + m_ctlFilters.InsertColumn(5, &lvc); + + // -attributes + lvc.iSubItem=4; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_HDREXCLUDEATTRIB_STRING); + lvc.cchTextMax=lstrlen(lvc.pszText); + lvc.cx=static_cast(0.1*rc.Width()); + m_ctlFilters.InsertColumn(6, &lvc); + + // refresh the entries in filters' list + m_ctlFilters.DeleteAllItems(); + for (size_t i=0;iLoadString(IDS_BROWSE_STRING), &strPath)) + AddPath(strPath); +} + +void CCustomCopyDlg::OnAddFilesButton() +{ + CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NODEREFERENCELINKS | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager()->LoadString(IDS_FILEDLGALLFILTER_STRING), this); + + TCHAR *pszBuffer=new TCHAR[65535]; + memset(pszBuffer, 0, 65535*sizeof(TCHAR)); + dlg.m_ofn.lpstrFile=pszBuffer; + dlg.m_ofn.nMaxFile=65535; + + if (dlg.DoModal() == IDOK) + { + // first element is the path + CString strPath=pszBuffer; + + int iOffset=_tcslen(pszBuffer)+1; + + // get filenames + if (pszBuffer[iOffset] == _T('\0')) + AddPath(strPath); + else + { + if (strPath.Right(1) != _T("\\")) + strPath+=_T("\\"); + while (pszBuffer[iOffset] != _T('\0')) + { + AddPath(strPath+CString(pszBuffer+iOffset)); + iOffset+=_tcslen(pszBuffer+iOffset)+1; + } + } + } + + // delete buffer + delete [] pszBuffer; +} + +void CCustomCopyDlg::OnRemoveButton() +{ + POSITION pos; + int iItem; + while (true) + { + pos = m_ctlFiles.GetFirstSelectedItemPosition(); + if (pos == NULL) + break; + else + { + iItem=m_ctlFiles.GetNextSelectedItem(pos); + m_ctlFiles.DeleteItem(iItem); + } + } +} + +void CCustomCopyDlg::OnBrowseButton() +{ + CString strPath; + if (BrowseForFolder(GetResManager()->LoadString(IDS_DSTFOLDERBROWSE_STRING), &strPath)) + { + SetComboPath(strPath); +// m_strDest=strPath; //** + } +} + +void CCustomCopyDlg::OnOK() +{ + UpdateData(TRUE); + + // copy files from listctrl to an array + m_ccData.m_astrPaths.RemoveAll(); + CString strPath; + + for (int i=0;iLoadString(IDS_BSEDEFAULT_STRING)); + fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiDefaultSize, szSize, 64, true)); + m_ctlBufferSizes.AddString(fmt); + + if (!m_ccData.m_bsSizes.m_bOnlyDefault) + { + fmt.SetFormat(GetResManager()->LoadString(IDS_BSEONEDISK_STRING)); + fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiOneDiskSize, szSize, 64, true)); + m_ctlBufferSizes.AddString(fmt); + + fmt.SetFormat(GetResManager()->LoadString(IDS_BSETWODISKS_STRING)); + fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiTwoDisksSize, szSize, 64, true)); + m_ctlBufferSizes.AddString(fmt); + + fmt.SetFormat(GetResManager()->LoadString(IDS_BSECD_STRING)); + fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiCDSize, szSize, 64, true)); + m_ctlBufferSizes.AddString(fmt); + + fmt.SetFormat(GetResManager()->LoadString(IDS_BSELAN_STRING)); + fmt.SetParam(_t("%size"), GetSizeString(m_ccData.m_bsSizes.m_uiLANSize, szSize, 64, true)); + m_ctlBufferSizes.AddString(fmt); + } +} + +void CCustomCopyDlg::OnChangebufferButton() +{ + CBufferSizeDlg dlg; + dlg.m_bsSizes=m_ccData.m_bsSizes; + if (dlg.DoModal() == IDOK) + { + m_ccData.m_bsSizes=dlg.m_bsSizes; + SetBuffersizesString(); + } +} + +void CCustomCopyDlg::AddPath(CString strPath) +{ + // fill listbox with paths + LVITEM lvi; + lvi.mask=LVIF_TEXT | LVIF_IMAGE; + lvi.iItem=m_ctlFiles.GetItemCount(); + lvi.iSubItem=0; + + // there's no need for a high speed so get the images + SHFILEINFO sfi; + SHGetFileInfo(strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON/* | SHGFI_USEFILEATTRIBUTES*/); + + // fill the list + lvi.pszText=strPath.GetBuffer(0); + strPath.ReleaseBuffer(); + lvi.cchTextMax=lstrlen(lvi.pszText); + lvi.iImage=sfi.iIcon; + m_ctlFiles.InsertItem(&lvi); +} + +void CCustomCopyDlg::OnAddfilterButton() +{ + CFilterDlg dlg; + CString strData; + for (size_t i=0;im_bUseMask) + dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); + if(pFilter->m_bUseExcludeMask) + dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); + } + } + + if (dlg.DoModal() == IDOK) + { + if (dlg.m_ffFilter.m_bUseMask || dlg.m_ffFilter.m_bUseExcludeMask || dlg.m_ffFilter.m_bUseSize + || dlg.m_ffFilter.m_bUseDate || dlg.m_ffFilter.m_bUseAttributes) + { + m_ccData.m_afFilters.Add(dlg.m_ffFilter); + AddFilter(dlg.m_ffFilter); + } + else + MsgBox(IDS_EMPTYFILTER_STRING, MB_OK | MB_ICONINFORMATION); + } +} + +void CCustomCopyDlg::AddFilter(const CFileFilter &rFilter, int iPos) +{ + LVITEM lvi; + TCHAR szLoaded[1024]; + TCHAR szData[64]; + + lvi.mask=LVIF_TEXT; + lvi.iItem=(iPos == -1) ? m_ctlFilters.GetItemCount() : iPos; + + ///////////////////// + lvi.iSubItem=0; + + if (rFilter.m_bUseMask) + { + CString strData; + rFilter.GetCombinedMask(strData); + _tcscpy(szLoaded, strData); + } + else + _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERMASKEMPTY_STRING)); + + lvi.pszText=szLoaded; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlFilters.InsertItem(&lvi); + + ///////////////////// + lvi.iSubItem=1; + + if (rFilter.m_bUseExcludeMask) + { + CString strData; + rFilter.GetCombinedExcludeMask(strData); + _tcscpy(szLoaded, strData); + } + else + _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERMASKEMPTY_STRING)); + + lvi.pszText=szLoaded; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlFilters.SetItem(&lvi); + + ///////////////// + lvi.iSubItem=2; + + if (rFilter.m_bUseSize) + { + _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iSizeType1), GetSizeString(rFilter.m_ullSize1, szData, 64, true)); + szLoaded[1023] = _T('\0'); + if (rFilter.m_bUseSize2) + { + _tcscat(szLoaded, GetResManager()->LoadString(IDS_AND_STRING)); + CString strLoaded2; + strLoaded2.Format(_T("%s %s"), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iSizeType2), GetSizeString(rFilter.m_ullSize2, szData, 64, true)); + _tcscat(szLoaded, strLoaded2); + } + } + else + _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERSIZE_STRING)); + + lvi.pszText=szLoaded; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlFilters.SetItem(&lvi); + + /////////////////// + lvi.iSubItem=3; + + if (rFilter.m_bUseDate) + { + _sntprintf(szLoaded, 1024, _T("%s %s"), GetResManager()->LoadString(IDS_DATECREATED_STRING+rFilter.m_iDateType), GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iDateType1)); + szLoaded[1023] = _T('\0'); + if (rFilter.m_bDate1) + _tcscat(szLoaded, rFilter.m_tDate1.Format(_T(" %x"))); + if (rFilter.m_bTime1) + _tcscat(szLoaded, rFilter.m_tTime1.Format(_T(" %X"))); + + if (rFilter.m_bUseDate2) + { + _tcscat(szLoaded, GetResManager()->LoadString(IDS_AND_STRING)); + _tcscat(szLoaded, GetResManager()->LoadString(IDS_LT_STRING+rFilter.m_iDateType2)); + if (rFilter.m_bDate2) + _tcscat(szLoaded, rFilter.m_tDate2.Format(_T(" %x"))); + if (rFilter.m_bTime2) + _tcscat(szLoaded, rFilter.m_tTime2.Format(_T(" %X"))); + } + } + else + _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERDATE_STRING)); + + lvi.pszText=szLoaded; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlFilters.SetItem(&lvi); + + ///////////////////// + lvi.iSubItem=4; + szLoaded[0]=_T('\0'); + if (rFilter.m_bUseAttributes) + { + if (rFilter.m_iArchive == 1) + _tcscat(szLoaded, _T("A")); + if (rFilter.m_iReadOnly == 1) + _tcscat(szLoaded, _T("R")); + if (rFilter.m_iHidden == 1) + _tcscat(szLoaded, _T("H")); + if (rFilter.m_iSystem == 1) + _tcscat(szLoaded, _T("S")); + if (rFilter.m_iDirectory == 1) + _tcscat(szLoaded, _T("D")); + } + + if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('\0')) + _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERATTRIB_STRING)); + + lvi.pszText=szLoaded; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlFilters.SetItem(&lvi); + + ///////////////////// + lvi.iSubItem=5; + szLoaded[0]=_T('\0'); + if (rFilter.m_bUseAttributes) + { + if (rFilter.m_iArchive == 0) + _tcscat(szLoaded, _T("A")); + if (rFilter.m_iReadOnly == 0) + _tcscat(szLoaded, _T("R")); + if (rFilter.m_iHidden == 0) + _tcscat(szLoaded, _T("H")); + if (rFilter.m_iSystem == 0) + _tcscat(szLoaded, _T("S")); + if (rFilter.m_iDirectory == 0) + _tcscat(szLoaded, _T("D")); + } + + if (!rFilter.m_bUseAttributes || szLoaded[0] == _T('0')) + _tcscpy(szLoaded, GetResManager()->LoadString(IDS_FILTERATTRIB_STRING)); + + lvi.pszText=szLoaded; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlFilters.SetItem(&lvi); +} + +void CCustomCopyDlg::OnRemovefilterButton() +{ + POSITION pos; + int iItem; + while (true) + { + pos=m_ctlFilters.GetFirstSelectedItemPosition(); + if (pos == NULL) + break; + else + { + iItem=m_ctlFilters.GetNextSelectedItem(pos); + m_ctlFilters.DeleteItem(iItem); + m_ccData.m_afFilters.RemoveAt(iItem); + } + } +} + +void CCustomCopyDlg::OnDestroy() +{ + m_ctlFiles.SetImageList(NULL, LVSIL_SMALL); + m_ilImages.Detach(); + + CLanguageDialog::OnDestroy(); +} + +void CCustomCopyDlg::EnableControls() +{ + UpdateData(TRUE); + + m_ctlFilters.EnableWindow(m_bFilters); + GetDlgItem(IDC_ADDFILTER_BUTTON)->EnableWindow(m_bFilters); + GetDlgItem(IDC_REMOVEFILTER_BUTTON)->EnableWindow(m_bFilters); + + GetDlgItem(IDC_IGNOREFOLDERS_CHECK)->EnableWindow(m_bAdvanced && !m_bForceDirectories); + GetDlgItem(IDC_FORCEDIRECTORIES_CHECK)->EnableWindow(m_bAdvanced && !m_bIgnoreFolders); + GetDlgItem(IDC_ONLYSTRUCTURE_CHECK)->EnableWindow(m_bAdvanced); +} + +void CCustomCopyDlg::OnFiltersCheck() +{ + EnableControls(); +} + +void CCustomCopyDlg::OnStandardCheck() +{ + EnableControls(); +} + +void CCustomCopyDlg::OnAdvancedCheck() +{ + EnableControls(); +} + +void CCustomCopyDlg::OnDblclkFiltersList(NMHDR* /*pNMHDR*/, LRESULT* pResult) +{ + POSITION pos=m_ctlFilters.GetFirstSelectedItemPosition(); + if (pos != NULL) + { + int iItem=m_ctlFilters.GetNextSelectedItem(pos); + CFilterDlg dlg; + const CFileFilter* pFilter = m_ccData.m_afFilters.GetAt(iItem); + BOOST_ASSERT(pFilter); + if(pFilter) + dlg.m_ffFilter = *pFilter; + + CString strData; + for (size_t i=0;im_bUseMask && i != iItem) + dlg.m_astrAddMask.Add(pFilter->GetCombinedMask(strData)); + if (pFilter->m_bUseExcludeMask && i != iItem) + dlg.m_astrAddExcludeMask.Add(pFilter->GetCombinedExcludeMask(strData)); + } + } + + if (dlg.DoModal() == IDOK) + { + // delete old element + m_ctlFilters.DeleteItem(iItem); + //m_ccData.m_afFilters.RemoveAt(iItem); + + // insert new if needed + if (dlg.m_ffFilter.m_bUseMask || dlg.m_ffFilter.m_bUseExcludeMask || dlg.m_ffFilter.m_bUseSize + || dlg.m_ffFilter.m_bUseDate || dlg.m_ffFilter.m_bUseAttributes) + { + m_ccData.m_afFilters.SetAt(iItem, dlg.m_ffFilter); + AddFilter(dlg.m_ffFilter, iItem); + } + } + } + + *pResult = 0; +} + +void CCustomCopyDlg::OnDblclkBuffersizesList() +{ + int iItem=m_ctlBufferSizes.GetCurSel(); + if (iItem != LB_ERR) + { + CBufferSizeDlg dlg; + dlg.m_bsSizes=m_ccData.m_bsSizes; + dlg.m_iActiveIndex=iItem; + if (dlg.DoModal() == IDOK) + { + m_ccData.m_bsSizes=dlg.m_bsSizes; + SetBuffersizesString(); + } + } +} + +void CCustomCopyDlg::SetComboPath(LPCTSTR lpszText) +{ + _ASSERTE(lpszText); + if(!lpszText) + return; + + // set current select to -1 + m_ctlDstPath.SetCurSel(-1); + + SHFILEINFO sfi; + sfi.iIcon=-1; + + COMBOBOXEXITEM cbi; + TCHAR szPath[_MAX_PATH]; + + cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; + cbi.iItem=-1; + _tcscpy(szPath, lpszText); + cbi.pszText=szPath; + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + cbi.iImage=sfi.iIcon; + m_ctlDstPath.SetItem(&cbi); +} + +void CCustomCopyDlg::UpdateComboIcon() +{ + // get text from combo + COMBOBOXEXITEM cbi; + TCHAR szPath[_MAX_PATH]; + memset(szPath, 0, _MAX_PATH); + cbi.mask=CBEIF_TEXT; + cbi.iItem=m_ctlDstPath.GetCurSel()/*-1*/; + cbi.pszText=szPath; + cbi.cchTextMax=_MAX_PATH; + + if (!m_ctlDstPath.GetItem(&cbi)) + return; + + // select no item + m_ctlDstPath.SetCurSel(-1); + + // icon update + SHFILEINFO sfi; + sfi.iIcon=-1; + + cbi.mask |= CBEIF_IMAGE; + cbi.iItem=-1; + + CString str=(LPCTSTR)szPath; + if (str.Left(2) != _T("\\\\") || str.Find(_T('\\'), 2) != -1) + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + + cbi.iImage=sfi.iIcon; + m_ctlDstPath.SetItem(&cbi); + + // unselect text in combo's edit + CEdit* pEdit=m_ctlDstPath.GetEditCtrl(); + if (!pEdit) + return; + + pEdit->SetSel(-1, -1); +} + +void CCustomCopyDlg::OnEditchangeDestpathComboboxex() +{ + if (m_bActualisation) + return; + m_bActualisation=true; + UpdateComboIcon(); + m_bActualisation=false; +} + +void CCustomCopyDlg::OnImportButton() +{ + CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, GetResManager()->LoadString(IDS_FLTALLFILTER_STRING)); + if (dlg.DoModal() == IDOK) + { + UINT uiCount=0; + CString strData; + try + { + CFile file(dlg.GetPathName(), CFile::modeRead); + CArchive ar(&file, CArchive::load); + + while (ar.ReadString(strData)) + { + strData.TrimLeft(_T("\" \t")); + strData.TrimRight(_T("\" \t")); + AddPath(strData); + uiCount++; + } + + ar.Close(); + file.Close(); + } + catch(CException* e) + { + e->Delete(); + } + + // report + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_IMPORTREPORT_STRING)); + fmt.SetParam(_t("%count"), uiCount); + AfxMessageBox(fmt); + } +} + +void CCustomCopyDlg::OnForcedirectoriesCheck() +{ + UpdateData(TRUE); + + GetDlgItem(IDC_IGNOREFOLDERS_CHECK)->EnableWindow(!m_bForceDirectories); +} + +void CCustomCopyDlg::OnIgnorefoldersCheck() +{ + UpdateData(TRUE); + + GetDlgItem(IDC_FORCEDIRECTORIES_CHECK)->EnableWindow(!m_bIgnoreFolders); +} Index: src/ch/CustomCopyDlg.h =================================================================== diff -u -r52e4374b1e7044f77439e34581780750675125a7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/CustomCopyDlg.h (.../CustomCopyDlg.h) (revision 52e4374b1e7044f77439e34581780750675125a7) +++ src/ch/CustomCopyDlg.h (.../CustomCopyDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,119 +1,119 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __CUSTOMCOPYDLG_H__ -#define __CUSTOMCOPYDLG_H__ - -#include "DataBuffer.h" -#include "FileFilter.h" -#include "charvect.h" - -///////////////////////////////////////////////////////////////////////////// -// CCustomCopyDlg dialog - -class CCustomCopyDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CCustomCopyDlg(); // standard constructor - - void SetBuffersizesString(); - - struct _CCDATA - { - CStringArray m_astrPaths; // source paths to copy/move - CString m_strDestPath; // currently selected destination path - char_vector m_vRecent; // recently selected paths - int m_iOperation; // copy || move - int m_iPriority; // operation priority - BYTE m_ucCount; // count of copys - BUFFERSIZES m_bsSizes; // buffer sizes selected for this task - - CFiltersArray m_afFilters; // list of filters to select from combos - - bool m_bIgnoreFolders; - bool m_bForceDirectories; - bool m_bCreateStructure; - } m_ccData; - - bool m_bActualisation; // is this dialog processing the combo text changing ? -// Dialog Data - //{{AFX_DATA(CCustomCopyDlg) - enum { IDD = IDD_CUSTOM_COPY_DIALOG }; - CComboBoxEx m_ctlDstPath; - CSpinButtonCtrl m_ctlCountSpin; - CListCtrl m_ctlFilters; - CListBox m_ctlBufferSizes; - CComboBox m_ctlOperation; - CComboBox m_ctlPriority; - CListCtrl m_ctlFiles; - BYTE m_ucCount; - BOOL m_bOnlyCreate; - BOOL m_bIgnoreFolders; - BOOL m_bForceDirectories; - BOOL m_bFilters; - BOOL m_bAdvanced; - //}}AFX_DATA - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CCustomCopyDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - virtual void OnLanguageChanged(); - void UpdateDialog(); - void UpdateComboIcon(); - void SetComboPath(LPCTSTR lpszText); - void EnableControls(); - void AddFilter(const CFileFilter& rFilter, int iPos=-1); - void AddPath(CString strPath); - CImageList m_ilImages; - - // Generated message map functions - //{{AFX_MSG(CCustomCopyDlg) - virtual BOOL OnInitDialog(); - afx_msg void OnAddDirectoryButton(); - afx_msg void OnAddFilesButton(); - afx_msg void OnRemoveButton(); - afx_msg void OnBrowseButton(); - virtual void OnOK(); - afx_msg void OnChangebufferButton(); - afx_msg void OnAddfilterButton(); - afx_msg void OnRemovefilterButton(); - afx_msg void OnDestroy(); - afx_msg void OnFiltersCheck(); - afx_msg void OnStandardCheck(); - afx_msg void OnAdvancedCheck(); - afx_msg void OnDblclkFiltersList(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnDblclkBuffersizesList(); - afx_msg void OnEditchangeDestpathComboboxex(); - afx_msg void OnImportButton(); - afx_msg void OnIgnorefoldersCheck(); - afx_msg void OnForcedirectoriesCheck(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __CUSTOMCOPYDLG_H__ +#define __CUSTOMCOPYDLG_H__ + +#include "DataBuffer.h" +#include "FileFilter.h" +#include "charvect.h" + +///////////////////////////////////////////////////////////////////////////// +// CCustomCopyDlg dialog + +class CCustomCopyDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CCustomCopyDlg(); // standard constructor + + void SetBuffersizesString(); + + struct _CCDATA + { + CStringArray m_astrPaths; // source paths to copy/move + CString m_strDestPath; // currently selected destination path + char_vector m_vRecent; // recently selected paths + int m_iOperation; // copy || move + int m_iPriority; // operation priority + BYTE m_ucCount; // count of copys + BUFFERSIZES m_bsSizes; // buffer sizes selected for this task + + CFiltersArray m_afFilters; // list of filters to select from combos + + bool m_bIgnoreFolders; + bool m_bForceDirectories; + bool m_bCreateStructure; + } m_ccData; + + bool m_bActualisation; // is this dialog processing the combo text changing ? +// Dialog Data + //{{AFX_DATA(CCustomCopyDlg) + enum { IDD = IDD_CUSTOM_COPY_DIALOG }; + CComboBoxEx m_ctlDstPath; + CSpinButtonCtrl m_ctlCountSpin; + CListCtrl m_ctlFilters; + CListBox m_ctlBufferSizes; + CComboBox m_ctlOperation; + CComboBox m_ctlPriority; + CListCtrl m_ctlFiles; + BYTE m_ucCount; + BOOL m_bOnlyCreate; + BOOL m_bIgnoreFolders; + BOOL m_bForceDirectories; + BOOL m_bFilters; + BOOL m_bAdvanced; + //}}AFX_DATA + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CCustomCopyDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + virtual void OnLanguageChanged(); + void UpdateDialog(); + void UpdateComboIcon(); + void SetComboPath(LPCTSTR lpszText); + void EnableControls(); + void AddFilter(const CFileFilter& rFilter, int iPos=-1); + void AddPath(CString strPath); + CImageList m_ilImages; + + // Generated message map functions + //{{AFX_MSG(CCustomCopyDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnAddDirectoryButton(); + afx_msg void OnAddFilesButton(); + afx_msg void OnRemoveButton(); + afx_msg void OnBrowseButton(); + virtual void OnOK(); + afx_msg void OnChangebufferButton(); + afx_msg void OnAddfilterButton(); + afx_msg void OnRemovefilterButton(); + afx_msg void OnDestroy(); + afx_msg void OnFiltersCheck(); + afx_msg void OnStandardCheck(); + afx_msg void OnAdvancedCheck(); + afx_msg void OnDblclkFiltersList(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnDblclkBuffersizesList(); + afx_msg void OnEditchangeDestpathComboboxex(); + afx_msg void OnImportButton(); + afx_msg void OnIgnorefoldersCheck(); + afx_msg void OnForcedirectoriesCheck(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/DataBuffer.cpp =================================================================== diff -u -r6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DataBuffer.cpp (.../DataBuffer.cpp) (revision 6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8) +++ src/ch/DataBuffer.cpp (.../DataBuffer.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,161 +1,161 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "DataBuffer.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -bool BUFFERSIZES::operator==(const BUFFERSIZES& bsSizes) const -{ - return (m_uiDefaultSize == bsSizes.m_uiDefaultSize - && m_uiOneDiskSize == bsSizes.m_uiOneDiskSize - && m_uiTwoDisksSize == bsSizes.m_uiTwoDisksSize - && m_uiCDSize == bsSizes.m_uiCDSize - && m_uiLANSize == bsSizes.m_uiLANSize); -} - -void BUFFERSIZES::Serialize(icpf::archive& ar) -{ - if (ar.is_storing()) - { - ar<(m_bOnlyDefault); - } - else - { - ar>>m_uiDefaultSize; - ar>>m_uiOneDiskSize; - ar>>m_uiTwoDisksSize; - ar>>m_uiCDSize; - ar>>m_uiLANSize; - unsigned char ucTemp; - ar>>ucTemp; - m_bOnlyDefault=(ucTemp != 0); - } -} - -const BUFFERSIZES* CDataBuffer::Create(const BUFFERSIZES* pbsSizes) -{ - // if trying to set 0-size buffer - BUFFERSIZES bsSizes=*pbsSizes; // copy - not to mix in the def. param - - if (bsSizes.m_uiDefaultSize == 0) - bsSizes.m_uiDefaultSize=DEFAULT_SIZE; - if (bsSizes.m_uiOneDiskSize == 0) - bsSizes.m_uiOneDiskSize=DEFAULT_SIZE; - if (bsSizes.m_uiTwoDisksSize == 0) - bsSizes.m_uiTwoDisksSize=DEFAULT_SIZE; - if (bsSizes.m_uiCDSize == 0) - bsSizes.m_uiCDSize=DEFAULT_SIZE; - if (bsSizes.m_uiLANSize == 0) - bsSizes.m_uiLANSize=DEFAULT_SIZE; - - // max value from the all - UINT uiLargest; - if (bsSizes.m_bOnlyDefault) - uiLargest=bsSizes.m_uiDefaultSize; - else - { - uiLargest=(bsSizes.m_uiDefaultSize > bsSizes.m_uiOneDiskSize ? bsSizes.m_uiDefaultSize : bsSizes.m_uiOneDiskSize); - if (uiLargest < bsSizes.m_uiTwoDisksSize) - uiLargest=bsSizes.m_uiTwoDisksSize; - if (uiLargest < bsSizes.m_uiCDSize) - uiLargest=bsSizes.m_uiCDSize; - if (uiLargest < bsSizes.m_uiLANSize) - uiLargest=bsSizes.m_uiLANSize; - } - - // modify buffer size to the next 64k boundary - UINT uiRealSize=ROUNDTODS(uiLargest); - TRACE("Size: %lu, rounded: %lu\n", uiLargest, uiRealSize); - - if (m_uiRealSize == uiRealSize) - { - // real buffersize doesn't changed - m_bsSizes=bsSizes; - - return &m_bsSizes; - } - - // try to allocate - LPVOID pBuffer=VirtualAlloc(NULL, uiRealSize, MEM_COMMIT, PAGE_READWRITE); - if (pBuffer == NULL) - { - if (m_pBuffer == NULL) - { - // try safe buffesize - pBuffer=VirtualAlloc(NULL, DEFAULT_SIZE, MEM_COMMIT, PAGE_READWRITE); - if (pBuffer == NULL) - return &m_bsSizes; // do not change anything - - // delete old buffer - Delete(); - - // store data - m_pBuffer=static_cast(pBuffer); - m_uiRealSize=DEFAULT_SIZE; - m_bsSizes.m_bOnlyDefault=bsSizes.m_bOnlyDefault; - m_bsSizes.m_uiDefaultSize=DEFAULT_SIZE; - m_bsSizes.m_uiOneDiskSize=DEFAULT_SIZE; - m_bsSizes.m_uiTwoDisksSize=DEFAULT_SIZE; - m_bsSizes.m_uiCDSize=DEFAULT_SIZE; - m_bsSizes.m_uiLANSize=DEFAULT_SIZE; - - return &m_bsSizes; - } - else - { - // no new buffer could be created - leave the old one - return &m_bsSizes; - } - } - else - { - // succeeded - Delete(); // get rid of old buffer - - // store data - m_pBuffer=static_cast(pBuffer); - m_uiRealSize=uiRealSize; - m_bsSizes=bsSizes; - - return &m_bsSizes; - } -} - -void CDataBuffer::Delete() -{ - if (m_pBuffer != NULL) - { - VirtualFree(static_cast(m_pBuffer), 0, MEM_RELEASE); - m_pBuffer=NULL; - m_uiRealSize=0; - m_bsSizes.m_uiDefaultSize=0; - m_bsSizes.m_uiOneDiskSize=0; - m_bsSizes.m_uiTwoDisksSize=0; - m_bsSizes.m_uiCDSize=0; - m_bsSizes.m_uiLANSize=0; - } +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "DataBuffer.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +bool BUFFERSIZES::operator==(const BUFFERSIZES& bsSizes) const +{ + return (m_uiDefaultSize == bsSizes.m_uiDefaultSize + && m_uiOneDiskSize == bsSizes.m_uiOneDiskSize + && m_uiTwoDisksSize == bsSizes.m_uiTwoDisksSize + && m_uiCDSize == bsSizes.m_uiCDSize + && m_uiLANSize == bsSizes.m_uiLANSize); +} + +void BUFFERSIZES::Serialize(icpf::archive& ar) +{ + if (ar.is_storing()) + { + ar<(m_bOnlyDefault); + } + else + { + ar>>m_uiDefaultSize; + ar>>m_uiOneDiskSize; + ar>>m_uiTwoDisksSize; + ar>>m_uiCDSize; + ar>>m_uiLANSize; + unsigned char ucTemp; + ar>>ucTemp; + m_bOnlyDefault=(ucTemp != 0); + } +} + +const BUFFERSIZES* CDataBuffer::Create(const BUFFERSIZES* pbsSizes) +{ + // if trying to set 0-size buffer + BUFFERSIZES bsSizes=*pbsSizes; // copy - not to mix in the def. param + + if (bsSizes.m_uiDefaultSize == 0) + bsSizes.m_uiDefaultSize=DEFAULT_SIZE; + if (bsSizes.m_uiOneDiskSize == 0) + bsSizes.m_uiOneDiskSize=DEFAULT_SIZE; + if (bsSizes.m_uiTwoDisksSize == 0) + bsSizes.m_uiTwoDisksSize=DEFAULT_SIZE; + if (bsSizes.m_uiCDSize == 0) + bsSizes.m_uiCDSize=DEFAULT_SIZE; + if (bsSizes.m_uiLANSize == 0) + bsSizes.m_uiLANSize=DEFAULT_SIZE; + + // max value from the all + UINT uiLargest; + if (bsSizes.m_bOnlyDefault) + uiLargest=bsSizes.m_uiDefaultSize; + else + { + uiLargest=(bsSizes.m_uiDefaultSize > bsSizes.m_uiOneDiskSize ? bsSizes.m_uiDefaultSize : bsSizes.m_uiOneDiskSize); + if (uiLargest < bsSizes.m_uiTwoDisksSize) + uiLargest=bsSizes.m_uiTwoDisksSize; + if (uiLargest < bsSizes.m_uiCDSize) + uiLargest=bsSizes.m_uiCDSize; + if (uiLargest < bsSizes.m_uiLANSize) + uiLargest=bsSizes.m_uiLANSize; + } + + // modify buffer size to the next 64k boundary + UINT uiRealSize=ROUNDTODS(uiLargest); + TRACE("Size: %lu, rounded: %lu\n", uiLargest, uiRealSize); + + if (m_uiRealSize == uiRealSize) + { + // real buffersize doesn't changed + m_bsSizes=bsSizes; + + return &m_bsSizes; + } + + // try to allocate + LPVOID pBuffer=VirtualAlloc(NULL, uiRealSize, MEM_COMMIT, PAGE_READWRITE); + if (pBuffer == NULL) + { + if (m_pBuffer == NULL) + { + // try safe buffesize + pBuffer=VirtualAlloc(NULL, DEFAULT_SIZE, MEM_COMMIT, PAGE_READWRITE); + if (pBuffer == NULL) + return &m_bsSizes; // do not change anything + + // delete old buffer + Delete(); + + // store data + m_pBuffer=static_cast(pBuffer); + m_uiRealSize=DEFAULT_SIZE; + m_bsSizes.m_bOnlyDefault=bsSizes.m_bOnlyDefault; + m_bsSizes.m_uiDefaultSize=DEFAULT_SIZE; + m_bsSizes.m_uiOneDiskSize=DEFAULT_SIZE; + m_bsSizes.m_uiTwoDisksSize=DEFAULT_SIZE; + m_bsSizes.m_uiCDSize=DEFAULT_SIZE; + m_bsSizes.m_uiLANSize=DEFAULT_SIZE; + + return &m_bsSizes; + } + else + { + // no new buffer could be created - leave the old one + return &m_bsSizes; + } + } + else + { + // succeeded + Delete(); // get rid of old buffer + + // store data + m_pBuffer=static_cast(pBuffer); + m_uiRealSize=uiRealSize; + m_bsSizes=bsSizes; + + return &m_bsSizes; + } +} + +void CDataBuffer::Delete() +{ + if (m_pBuffer != NULL) + { + VirtualFree(static_cast(m_pBuffer), 0, MEM_RELEASE); + m_pBuffer=NULL; + m_uiRealSize=0; + m_bsSizes.m_uiDefaultSize=0; + m_bsSizes.m_uiOneDiskSize=0; + m_bsSizes.m_uiTwoDisksSize=0; + m_bsSizes.m_uiCDSize=0; + m_bsSizes.m_uiLANSize=0; + } } \ No newline at end of file Index: src/ch/DataBuffer.h =================================================================== diff -u -r6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DataBuffer.h (.../DataBuffer.h) (revision 6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8) +++ src/ch/DataBuffer.h (.../DataBuffer.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,87 +1,87 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __DATABUFFER_H__ -#define __DATABUFFER_H__ - -#include "../libicpf/file.h" - -#define DEFAULT_SIZE 65536 - -#define ROUNDTODS(number)\ - ((number + DEFAULT_SIZE - 1) & ~(DEFAULT_SIZE-1)) - -#define ROUNDUP(number, to)\ - ((number + to - 1) & ~(to-1)) - -#define ROUNDDOWN(number, to)\ - (number & ~(to-1)) - -#define BI_DEFAULT 0 -#define BI_ONEDISK 1 -#define BI_TWODISKS 2 -#define BI_CD 3 -#define BI_LAN 4 - -#pragma warning (disable: 4201) -struct BUFFERSIZES -{ - void Serialize(icpf::archive& ar); - bool operator==(const BUFFERSIZES& bsSizes) const; - union - { - struct - { - UINT m_uiDefaultSize; // default buffer size - UINT m_uiOneDiskSize; // inside one disk boundary - UINT m_uiTwoDisksSize; // two disks - UINT m_uiCDSize; // CD<->anything - UINT m_uiLANSize; // LAN<->anything - }; - UINT m_auiSizes[5]; - }; - bool m_bOnlyDefault; -}; -#pragma warning (default: 4201) - -class CDataBuffer -{ -public: - CDataBuffer() { m_pBuffer=NULL; m_uiRealSize=0; m_bsSizes.m_uiDefaultSize=0; m_bsSizes.m_uiOneDiskSize=0; m_bsSizes.m_uiTwoDisksSize=0; m_bsSizes.m_uiCDSize=0; m_bsSizes.m_uiLANSize=0; m_bsSizes.m_bOnlyDefault=false; }; - ~CDataBuffer() { Delete(); }; - - const BUFFERSIZES* Create(const BUFFERSIZES* pbsSizes); // (re)allocates the buffer; if there's an error - restores previous buffer size - void Delete(); // deletes buffer - - UINT GetRealSize() { return m_uiRealSize; }; - UINT GetDefaultSize() { return m_bsSizes.m_uiDefaultSize; }; - UINT GetOneDiskSize() { return m_bsSizes.m_uiOneDiskSize; }; - UINT GetTwoDisksSize() { return m_bsSizes.m_uiTwoDisksSize; }; - UINT GetCDSize() { return m_bsSizes.m_uiCDSize; }; - UINT GetLANSize() { return m_bsSizes.m_uiLANSize; }; - const BUFFERSIZES* GetSizes() { return &m_bsSizes; }; - - // operators - operator unsigned char*() { return m_pBuffer; }; -protected: - unsigned char *m_pBuffer; // buffer address - UINT m_uiRealSize; // real buffer size - BUFFERSIZES m_bsSizes; -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __DATABUFFER_H__ +#define __DATABUFFER_H__ + +#include "../libicpf/file.h" + +#define DEFAULT_SIZE 65536 + +#define ROUNDTODS(number)\ + ((number + DEFAULT_SIZE - 1) & ~(DEFAULT_SIZE-1)) + +#define ROUNDUP(number, to)\ + ((number + to - 1) & ~(to-1)) + +#define ROUNDDOWN(number, to)\ + (number & ~(to-1)) + +#define BI_DEFAULT 0 +#define BI_ONEDISK 1 +#define BI_TWODISKS 2 +#define BI_CD 3 +#define BI_LAN 4 + +#pragma warning (disable: 4201) +struct BUFFERSIZES +{ + void Serialize(icpf::archive& ar); + bool operator==(const BUFFERSIZES& bsSizes) const; + union + { + struct + { + UINT m_uiDefaultSize; // default buffer size + UINT m_uiOneDiskSize; // inside one disk boundary + UINT m_uiTwoDisksSize; // two disks + UINT m_uiCDSize; // CD<->anything + UINT m_uiLANSize; // LAN<->anything + }; + UINT m_auiSizes[5]; + }; + bool m_bOnlyDefault; +}; +#pragma warning (default: 4201) + +class CDataBuffer +{ +public: + CDataBuffer() { m_pBuffer=NULL; m_uiRealSize=0; m_bsSizes.m_uiDefaultSize=0; m_bsSizes.m_uiOneDiskSize=0; m_bsSizes.m_uiTwoDisksSize=0; m_bsSizes.m_uiCDSize=0; m_bsSizes.m_uiLANSize=0; m_bsSizes.m_bOnlyDefault=false; }; + ~CDataBuffer() { Delete(); }; + + const BUFFERSIZES* Create(const BUFFERSIZES* pbsSizes); // (re)allocates the buffer; if there's an error - restores previous buffer size + void Delete(); // deletes buffer + + UINT GetRealSize() { return m_uiRealSize; }; + UINT GetDefaultSize() { return m_bsSizes.m_uiDefaultSize; }; + UINT GetOneDiskSize() { return m_bsSizes.m_uiOneDiskSize; }; + UINT GetTwoDisksSize() { return m_bsSizes.m_uiTwoDisksSize; }; + UINT GetCDSize() { return m_bsSizes.m_uiCDSize; }; + UINT GetLANSize() { return m_bsSizes.m_uiLANSize; }; + const BUFFERSIZES* GetSizes() { return &m_bsSizes; }; + + // operators + operator unsigned char*() { return m_pBuffer; }; +protected: + unsigned char *m_pBuffer; // buffer address + UINT m_uiRealSize; // real buffer size + BUFFERSIZES m_bsSizes; +}; + #endif \ No newline at end of file Index: src/ch/DestPath.cpp =================================================================== diff -u -r6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DestPath.cpp (.../DestPath.cpp) (revision 6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8) +++ src/ch/DestPath.cpp (.../DestPath.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,92 +1,92 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "DestPath.h" -//#include "../libicpf/file.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -void GetDriveData(LPCTSTR lpszPath, int* piDrvNum, UINT* puiDrvType) -{ - TCHAR drv[_MAX_DRIVE+1]; - - _tsplitpath(lpszPath, drv, NULL, NULL, NULL); - if(lstrlen(drv) != 0) - { - // add '\\' - lstrcat(drv, _T("\\")); - _tcsupr(drv); - - // disk number - if (piDrvNum) - *piDrvNum=drv[0]-_T('A'); - - // disk type - if (puiDrvType) - { - *puiDrvType=GetDriveType(drv); - if (*puiDrvType == DRIVE_NO_ROOT_DIR) - *puiDrvType=DRIVE_UNKNOWN; - } - } - else - { - // there's no disk in a path - if (piDrvNum) - *piDrvNum=-1; - - if (puiDrvType) - { - // check for unc path - if (_tcsncmp(lpszPath, _T("\\\\"), 2) == 0) - *puiDrvType=DRIVE_REMOTE; - else - *puiDrvType=DRIVE_UNKNOWN; - } - } -} - -void CDestPath::SetPath(LPCTSTR lpszPath) -{ - m_strPath=lpszPath; - - // make sure '\\' has been added - if (m_strPath.Right(1) != _T('\\')) - m_strPath+=_T('\\'); - - GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType); -} - -void CDestPath::Serialize(icpf::archive& ar) -{ - if (ar.is_storing()) - { - ar<>m_strPath; - ar>>m_iDriveNumber; - ar>>m_uiDriveType; - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "DestPath.h" +//#include "../libicpf/file.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +void GetDriveData(LPCTSTR lpszPath, int* piDrvNum, UINT* puiDrvType) +{ + TCHAR drv[_MAX_DRIVE+1]; + + _tsplitpath(lpszPath, drv, NULL, NULL, NULL); + if(lstrlen(drv) != 0) + { + // add '\\' + lstrcat(drv, _T("\\")); + _tcsupr(drv); + + // disk number + if (piDrvNum) + *piDrvNum=drv[0]-_T('A'); + + // disk type + if (puiDrvType) + { + *puiDrvType=GetDriveType(drv); + if (*puiDrvType == DRIVE_NO_ROOT_DIR) + *puiDrvType=DRIVE_UNKNOWN; + } + } + else + { + // there's no disk in a path + if (piDrvNum) + *piDrvNum=-1; + + if (puiDrvType) + { + // check for unc path + if (_tcsncmp(lpszPath, _T("\\\\"), 2) == 0) + *puiDrvType=DRIVE_REMOTE; + else + *puiDrvType=DRIVE_UNKNOWN; + } + } +} + +void CDestPath::SetPath(LPCTSTR lpszPath) +{ + m_strPath=lpszPath; + + // make sure '\\' has been added + if (m_strPath.Right(1) != _T('\\')) + m_strPath+=_T('\\'); + + GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType); +} + +void CDestPath::Serialize(icpf::archive& ar) +{ + if (ar.is_storing()) + { + ar<>m_strPath; + ar>>m_iDriveNumber; + ar>>m_uiDriveType; + } +} Index: src/ch/DestPath.h =================================================================== diff -u -r6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DestPath.h (.../DestPath.h) (revision 6ae1d95bf7dd071fd2b65b8f7aabca1c887bdff8) +++ src/ch/DestPath.h (.../DestPath.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,42 +1,42 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __DESTPATH_H__ -#define __DESTPATH_H__ - -#include "../libicpf/file.h" - -class CDestPath -{ -public: - CDestPath() { m_iDriveNumber=-1; m_uiDriveType=static_cast(-1); }; - void SetPath(LPCTSTR lpszPath); - const CString& GetPath() const { return m_strPath; }; - - int GetDriveNumber() const { return m_iDriveNumber; }; - UINT GetDriveType() const { return m_uiDriveType; }; - - void Serialize(icpf::archive& ar); - -protected: - CString m_strPath; // always with ending '\\' - int m_iDriveNumber; // initialized within setpath (std -1) - UINT m_uiDriveType; // disk type - -1 if none, the rest like in GetDriveType -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __DESTPATH_H__ +#define __DESTPATH_H__ + +#include "../libicpf/file.h" + +class CDestPath +{ +public: + CDestPath() { m_iDriveNumber=-1; m_uiDriveType=static_cast(-1); }; + void SetPath(LPCTSTR lpszPath); + const CString& GetPath() const { return m_strPath; }; + + int GetDriveNumber() const { return m_iDriveNumber; }; + UINT GetDriveType() const { return m_uiDriveType; }; + + void Serialize(icpf::archive& ar); + +protected: + CString m_strPath; // always with ending '\\' + int m_iDriveNumber; // initialized within setpath (std -1) + UINT m_uiDriveType; // disk type - -1 if none, the rest like in GetDriveType +}; + #endif \ No newline at end of file Index: src/ch/Device IO.h =================================================================== diff -u -r7e88d1bbb47944b6a26a0a59414cf9f9a30589bc -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Device IO.h (.../Device IO.h) (revision 7e88d1bbb47944b6a26a0a59414cf9f9a30589bc) +++ src/ch/Device IO.h (.../Device IO.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,187 +1,187 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#define VWIN32_DIOC_DOS_IOCTL 1 - -typedef struct _DEVIOCTL_REGISTERS -{ - DWORD reg_EBX; - DWORD reg_EDX; - DWORD reg_ECX; - DWORD reg_EAX; - DWORD reg_EDI; - DWORD reg_ESI; - DWORD reg_Flags; -} DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS; - -#pragma pack(1) -typedef struct _DRIVE_MAP_INFO -{ - BYTE dmiAllocationLength; - BYTE dmiInfoLength; - BYTE dmiFlags; - BYTE dmiInt13Unit; - DWORD dmiAssociatedDriveMap; - ULONGLONG dmiPartitionStartRBA; -} DRIVE_MAP_INFO, *PDRIVE_MAP_INFO; -#pragma pack() - -// only 9x -BOOL GetDriveMapInfo(UINT nDrive, PDRIVE_MAP_INFO pdmi) -{ - DEVIOCTL_REGISTERS reg, *preg; - reg.reg_EAX = 0x440D; // IOCTL for block devices - reg.reg_EBX = nDrive; // zero-based drive ID - reg.reg_ECX = 0x086f; // Get Media ID command - reg.reg_EDX = (DWORD)pdmi; // receives media ID info - preg=® - - preg->reg_Flags = 0x8000; // assume error (carry flag set) - - HANDLE hDevice = CreateFile(_T("\\\\.\\vwin32"), - GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); - - if (hDevice == (HANDLE)INVALID_HANDLE_VALUE) - { - return FALSE; - } - else - { - DWORD cb; - BOOL fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL, - preg, sizeof(*preg), preg, sizeof(*preg), &cb, 0); - - if (!fResult) - { - CloseHandle(hDevice); - return FALSE; - } - } - - CloseHandle(hDevice); - - return TRUE; -} - -// only NT -bool GetSignature(LPCTSTR lpszDrive, LPTSTR lpszBuffer, int iSize) -{ - TCHAR szMapping[1024], szQuery[16384], szSymbolic[1024]; - - // read mappings - if (QueryDosDevice(lpszDrive, szMapping, 1024) == 0) - return false; - - // search for all, to find out in which string is the signature - int iCount, iCount2; - if ((iCount=QueryDosDevice(NULL, szQuery, 16384)) == 0) - { - TRACE("Encountered error #%lu @QueryDosDevice\n", GetLastError()); - return false; - } - - int iOffset=0, iOffset2=0; - TCHAR* pszSignature = NULL; - TCHAR* pszOffset = NULL; - while(iOffset < iCount) - { - if(_tcsncmp(szQuery+iOffset, _T("STORAGE#Volume#"), _tcslen(_T("STORAGE#Volume#"))) == 0) - { - if((iCount2 = QueryDosDevice(szQuery+iOffset, szSymbolic, 1024)) == 0) - return false; - - // now search for 'Signature' and extract (from szQuery+iOffset) - pszSignature=_tcsstr(szQuery+iOffset, _T("Signature")); - if (pszSignature == NULL) - { - iOffset+=_tcslen(szQuery+iOffset)+1; - continue; - } - pszOffset=_tcsstr(pszSignature, _T("Offset")); - if (pszOffset == NULL) - { - iOffset+=_tcslen(szQuery+iOffset)+1; - continue; - } - - // for better string copying - pszOffset[0]=_T('\0'); - - // read values from szSymbolic and compare with szMapping - iOffset2=0; - while (iOffset2 < iCount2) - { - // compare szSymbolic+iOffset2 with szMapping - if (_tcscmp(szMapping, szSymbolic+iOffset2) == 0) - { - // found Signature & Offset - copy - int iCnt=reinterpret_cast(pszOffset)-reinterpret_cast(pszSignature)+1; - _tcsncpy(lpszBuffer, pszSignature, (iCnt > iSize) ? iSize : iCnt); - return true; - } - - iOffset2+=_tcslen(szSymbolic)+1; - } - } - - iOffset+=_tcslen(szQuery+iOffset)+1; - } - - return false; -} - -// at 9x function checks int13h devices and at NT within symbolic links -bool IsSamePhysicalDisk(int iDrvNum1, int iDrvNum2) -{ - OSVERSIONINFO osvi; - osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); - - GetVersionEx(&osvi); - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) - { - DRIVE_MAP_INFO dmi1, dmi2; - dmi1.dmiAllocationLength=sizeof(DRIVE_MAP_INFO); - dmi1.dmiInt13Unit=0xff; - dmi2.dmiAllocationLength=sizeof(DRIVE_MAP_INFO); - dmi2.dmiInt13Unit=0xff; - - // iDrvNum is 0-based, and we need 1-based - if (!GetDriveMapInfo(iDrvNum1+1, &dmi1) || !GetDriveMapInfo(iDrvNum2+1, &dmi2) || dmi1.dmiInt13Unit != dmi2.dmiInt13Unit || dmi1.dmiInt13Unit == 0xff) - return false; - else - return true; - } - else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) - { - TCHAR drv1[3], drv2[3]; - - drv1[0]=static_cast(iDrvNum1+_T('A')); - drv1[1]=_T(':'); - drv1[2]=_T('\0'); - drv2[0]=static_cast(iDrvNum2+_T('A')); - drv2[1]=_T(':'); - drv2[2]=_T('\0'); - - TCHAR szSign1[512], szSign2[512]; - return (GetSignature(drv1, szSign1, 512) && GetSignature(drv2, szSign2, 512) && _tcscmp(szSign1, szSign2) == 0); - } - - return false; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#define VWIN32_DIOC_DOS_IOCTL 1 + +typedef struct _DEVIOCTL_REGISTERS +{ + DWORD reg_EBX; + DWORD reg_EDX; + DWORD reg_ECX; + DWORD reg_EAX; + DWORD reg_EDI; + DWORD reg_ESI; + DWORD reg_Flags; +} DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS; + +#pragma pack(1) +typedef struct _DRIVE_MAP_INFO +{ + BYTE dmiAllocationLength; + BYTE dmiInfoLength; + BYTE dmiFlags; + BYTE dmiInt13Unit; + DWORD dmiAssociatedDriveMap; + ULONGLONG dmiPartitionStartRBA; +} DRIVE_MAP_INFO, *PDRIVE_MAP_INFO; +#pragma pack() + +// only 9x +BOOL GetDriveMapInfo(UINT nDrive, PDRIVE_MAP_INFO pdmi) +{ + DEVIOCTL_REGISTERS reg, *preg; + reg.reg_EAX = 0x440D; // IOCTL for block devices + reg.reg_EBX = nDrive; // zero-based drive ID + reg.reg_ECX = 0x086f; // Get Media ID command + reg.reg_EDX = (DWORD)pdmi; // receives media ID info + preg=® + + preg->reg_Flags = 0x8000; // assume error (carry flag set) + + HANDLE hDevice = CreateFile(_T("\\\\.\\vwin32"), + GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); + + if (hDevice == (HANDLE)INVALID_HANDLE_VALUE) + { + return FALSE; + } + else + { + DWORD cb; + BOOL fResult = DeviceIoControl(hDevice, VWIN32_DIOC_DOS_IOCTL, + preg, sizeof(*preg), preg, sizeof(*preg), &cb, 0); + + if (!fResult) + { + CloseHandle(hDevice); + return FALSE; + } + } + + CloseHandle(hDevice); + + return TRUE; +} + +// only NT +bool GetSignature(LPCTSTR lpszDrive, LPTSTR lpszBuffer, int iSize) +{ + TCHAR szMapping[1024], szQuery[16384], szSymbolic[1024]; + + // read mappings + if (QueryDosDevice(lpszDrive, szMapping, 1024) == 0) + return false; + + // search for all, to find out in which string is the signature + int iCount, iCount2; + if ((iCount=QueryDosDevice(NULL, szQuery, 16384)) == 0) + { + TRACE("Encountered error #%lu @QueryDosDevice\n", GetLastError()); + return false; + } + + int iOffset=0, iOffset2=0; + TCHAR* pszSignature = NULL; + TCHAR* pszOffset = NULL; + while(iOffset < iCount) + { + if(_tcsncmp(szQuery+iOffset, _T("STORAGE#Volume#"), _tcslen(_T("STORAGE#Volume#"))) == 0) + { + if((iCount2 = QueryDosDevice(szQuery+iOffset, szSymbolic, 1024)) == 0) + return false; + + // now search for 'Signature' and extract (from szQuery+iOffset) + pszSignature=_tcsstr(szQuery+iOffset, _T("Signature")); + if (pszSignature == NULL) + { + iOffset+=_tcslen(szQuery+iOffset)+1; + continue; + } + pszOffset=_tcsstr(pszSignature, _T("Offset")); + if (pszOffset == NULL) + { + iOffset+=_tcslen(szQuery+iOffset)+1; + continue; + } + + // for better string copying + pszOffset[0]=_T('\0'); + + // read values from szSymbolic and compare with szMapping + iOffset2=0; + while (iOffset2 < iCount2) + { + // compare szSymbolic+iOffset2 with szMapping + if (_tcscmp(szMapping, szSymbolic+iOffset2) == 0) + { + // found Signature & Offset - copy + int iCnt=reinterpret_cast(pszOffset)-reinterpret_cast(pszSignature)+1; + _tcsncpy(lpszBuffer, pszSignature, (iCnt > iSize) ? iSize : iCnt); + return true; + } + + iOffset2+=_tcslen(szSymbolic)+1; + } + } + + iOffset+=_tcslen(szQuery+iOffset)+1; + } + + return false; +} + +// at 9x function checks int13h devices and at NT within symbolic links +bool IsSamePhysicalDisk(int iDrvNum1, int iDrvNum2) +{ + OSVERSIONINFO osvi; + osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO); + + GetVersionEx(&osvi); + if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) + { + DRIVE_MAP_INFO dmi1, dmi2; + dmi1.dmiAllocationLength=sizeof(DRIVE_MAP_INFO); + dmi1.dmiInt13Unit=0xff; + dmi2.dmiAllocationLength=sizeof(DRIVE_MAP_INFO); + dmi2.dmiInt13Unit=0xff; + + // iDrvNum is 0-based, and we need 1-based + if (!GetDriveMapInfo(iDrvNum1+1, &dmi1) || !GetDriveMapInfo(iDrvNum2+1, &dmi2) || dmi1.dmiInt13Unit != dmi2.dmiInt13Unit || dmi1.dmiInt13Unit == 0xff) + return false; + else + return true; + } + else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + TCHAR drv1[3], drv2[3]; + + drv1[0]=static_cast(iDrvNum1+_T('A')); + drv1[1]=_T(':'); + drv1[2]=_T('\0'); + drv2[0]=static_cast(iDrvNum2+_T('A')); + drv2[1]=_T(':'); + drv2[2]=_T('\0'); + + TCHAR szSign1[512], szSign2[512]; + return (GetSignature(drv1, szSign1, 512) && GetSignature(drv2, szSign2, 512) && _tcscmp(szSign1, szSign2) == 0); + } + + return false; +} Index: src/ch/Dialogs.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Dialogs.cpp (.../Dialogs.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/Dialogs.cpp (.../Dialogs.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,66 +1,66 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "dialogs.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -bool BrowseForFolder(LPCTSTR lpszTitle, CString* pResult) -{ - // code allows browsing on all disks - LPMALLOC pMalloc; - TCHAR pszBuffer[MAX_PATH]; - _sntprintf(pszBuffer, _MAX_PATH, _T("c:\\windows\\system")); - bool retval=false; - - /* Gets the Shell's default allocator */ - if (::SHGetMalloc(&pMalloc) == NOERROR) - { - BROWSEINFO bi; - LPITEMIDLIST pidl; - - // Get help on BROWSEINFO struct - it's got all the bit settings. - bi.hwndOwner = NULL; - bi.pidlRoot = NULL; - bi.pszDisplayName = pszBuffer; - bi.lpszTitle = lpszTitle; - bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; - bi.lpfn = NULL; - bi.lParam = 0; - - // This next call issues the dialog box. - if ((pidl = ::SHBrowseForFolder(&bi)) != NULL) - { - if (::SHGetPathFromIDList(pidl, pszBuffer)) - { - *pResult=pszBuffer; - retval=true; - } - - // Free the PIDL allocated by SHBrowseForFolder. - pMalloc->Free(pidl); - } - // Release the shell's allocator. - pMalloc->Release(); - } - - return retval; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "dialogs.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +bool BrowseForFolder(LPCTSTR lpszTitle, CString* pResult) +{ + // code allows browsing on all disks + LPMALLOC pMalloc; + TCHAR pszBuffer[MAX_PATH]; + _sntprintf(pszBuffer, _MAX_PATH, _T("c:\\windows\\system")); + bool retval=false; + + /* Gets the Shell's default allocator */ + if (::SHGetMalloc(&pMalloc) == NOERROR) + { + BROWSEINFO bi; + LPITEMIDLIST pidl; + + // Get help on BROWSEINFO struct - it's got all the bit settings. + bi.hwndOwner = NULL; + bi.pidlRoot = NULL; + bi.pszDisplayName = pszBuffer; + bi.lpszTitle = lpszTitle; + bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; + bi.lpfn = NULL; + bi.lParam = 0; + + // This next call issues the dialog box. + if ((pidl = ::SHBrowseForFolder(&bi)) != NULL) + { + if (::SHGetPathFromIDList(pidl, pszBuffer)) + { + *pResult=pszBuffer; + retval=true; + } + + // Free the PIDL allocated by SHBrowseForFolder. + pMalloc->Free(pidl); + } + // Release the shell's allocator. + pMalloc->Release(); + } + + return retval; +} Index: src/ch/Dialogs.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Dialogs.h (.../Dialogs.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/Dialogs.h (.../Dialogs.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,26 +1,26 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __DIALOGS_H__ -#define __DIALOGS_H__ - -#include "shlobj.h" - -bool BrowseForFolder(LPCTSTR lpszTitle, CString* pResult); - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __DIALOGS_H__ +#define __DIALOGS_H__ + +#include "shlobj.h" + +bool BrowseForFolder(LPCTSTR lpszTitle, CString* pResult); + #endif \ No newline at end of file Index: src/ch/DirTreeCtrl.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DirTreeCtrl.cpp (.../DirTreeCtrl.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/DirTreeCtrl.cpp (.../DirTreeCtrl.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,1140 +1,1140 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "DirTreeCtrl.h" -#include "afxtempl.h" -#include "memdc.h" -#include "shlobj.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -#define WM_INITCONTROL WM_USER+7 - -LPITEMIDLIST Next(LPCITEMIDLIST pidl) -{ - LPSTR lpMem=(LPSTR)pidl; - - lpMem+=pidl->mkid.cb; - - return (LPITEMIDLIST)lpMem; -} - -UINT GetSize(LPCITEMIDLIST pidl) -{ - UINT cbTotal = 0; - if (pidl) - { - cbTotal += sizeof(pidl->mkid.cb); // Null terminator - while (pidl->mkid.cb) - { - cbTotal += pidl->mkid.cb; - pidl = Next(pidl); - } - } - - return cbTotal; -} - -LPITEMIDLIST CreatePidl(UINT cbSize) -{ - LPMALLOC lpMalloc; - HRESULT hr; - LPITEMIDLIST pidl=NULL; - - hr=SHGetMalloc(&lpMalloc); - - if (FAILED(hr)) - return 0; - - pidl=(LPITEMIDLIST)lpMalloc->Alloc(cbSize); - - if (pidl) - memset(pidl, 0, cbSize); // zero-init for external task alloc - - if (lpMalloc) lpMalloc->Release(); - - return pidl; -} - -void FreePidl(LPITEMIDLIST lpiidl) -{ - LPMALLOC lpMalloc; - HRESULT hr; - - hr=SHGetMalloc(&lpMalloc); - - if (FAILED(hr)) - return; - - lpMalloc->Free(lpiidl); - - if (lpMalloc) lpMalloc->Release(); -} - -LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) -{ - LPITEMIDLIST pidlNew; - UINT cb1; - UINT cb2; - - if (pidl1) //May be NULL - cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb); - else - cb1 = 0; - - cb2 = GetSize(pidl2); - - pidlNew = CreatePidl(cb1 + cb2); - if (pidlNew) - { - if (pidl1) - memcpy(pidlNew, pidl1, cb1); - memcpy(((LPSTR)pidlNew) + cb1, pidl2, cb2); - } - return pidlNew; -} - -LPITEMIDLIST CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi) -{ - LPITEMIDLIST lpiTemp; - - lpiTemp=(LPITEMIDLIST)lpMalloc->Alloc(lpi->mkid.cb+sizeof(lpi->mkid.cb)); - CopyMemory((PVOID)lpiTemp, (CONST VOID *)lpi, lpi->mkid.cb+sizeof(lpi->mkid.cb)); - - return lpiTemp; -} - -BOOL GetName(LPSHELLFOLDER lpsf, - LPITEMIDLIST lpi, - DWORD dwFlags, - LPTSTR lpFriendlyName) -{ - BOOL bSuccess=TRUE; - STRRET str; - - if (NOERROR==lpsf->GetDisplayNameOf(lpi,dwFlags, &str)) - { - switch (str.uType) - { - case STRRET_WSTR: - { - CW2T cw2t(str.pOleStr); - lstrcpy(lpFriendlyName, cw2t); - break; - } - case STRRET_OFFSET: - { - lstrcpy(lpFriendlyName, (LPTSTR)lpi+str.uOffset); - break; - } - - case STRRET_CSTR: - { - CA2T ca2t(str.cStr); - lstrcpy(lpFriendlyName, ca2t); - break; - } - - default: - bSuccess = FALSE; - break; - } - } - else - bSuccess = FALSE; - - return bSuccess; -} - -LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi) -{ - TCHAR szBuff[MAX_PATH]; - LPSHELLFOLDER lpsfDeskTop; - LPITEMIDLIST lpifq; - ULONG ulEaten, ulAttribs; - HRESULT hr; - - if (!GetName(lpsf, lpi, SHGDN_FORPARSING, szBuff)) - return NULL; - - hr=SHGetDesktopFolder(&lpsfDeskTop); - - if (FAILED(hr)) - return NULL; - - CT2W ct2w(szBuff); - hr=lpsfDeskTop->ParseDisplayName(NULL, - NULL, - ct2w, - &ulEaten, - &lpifq, - &ulAttribs); - - lpsfDeskTop->Release(); - - if (FAILED(hr)) - return NULL; - - return lpifq; -} - -///////////////////////////////////////////////////////////////////////////// -// CDirTreeCtrl - -CDirTreeCtrl::CDirTreeCtrl() -{ - m_hDrives=NULL; - m_hNetwork=NULL; - m_hImageList=NULL; - m_bIgnore=false; - m_iEditType=0; -// RegisterWindowClass(); -} -/* -bool CDirTreeCtrl::RegisterWindowClass() -{ - WNDCLASS wndcls; - HINSTANCE hInst = AfxGetInstanceHandle(); - - if (!(::GetClassInfo(hInst, DIRTREECTRL_CLASSNAME, &wndcls))) - { - // otherwise we need to register a new class - wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; - wndcls.lpfnWndProc = ::DefWindowProc; - wndcls.cbClsExtra = wndcls.cbWndExtra = 0; - wndcls.hInstance = hInst; - wndcls.hIcon = NULL; - wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); - wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1); - wndcls.lpszMenuName = NULL; - wndcls.lpszClassName = DIRTREECTRL_CLASSNAME; - - if (!AfxRegisterClass(&wndcls)) - { - AfxThrowResourceException(); - return false; - } - } - - return true; -} -*/ -CDirTreeCtrl::~CDirTreeCtrl() -{ -} - - -BEGIN_MESSAGE_MAP(CDirTreeCtrl, CTreeCtrl) - //{{AFX_MSG_MAP(CDirTreeCtrl) - ON_WM_DESTROY() - ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding) - ON_NOTIFY_REFLECT(TVN_DELETEITEM, OnDeleteitem) - ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded) - ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit) - ON_NOTIFY_REFLECT(TVN_BEGINLABELEDIT, OnBeginLabelEdit) - ON_WM_ERASEBKGND() - ON_WM_PAINT() - ON_WM_CREATE() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CDirTreeCtrl message handlers - -///////////////////////////////////////////////////////////////////////////// -// inicjalizacja -void CDirTreeCtrl::PreSubclassWindow() -{ -// InitControl(); // here's not needed (strange ??) - CTreeCtrl::PreSubclassWindow(); -} - -int CDirTreeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) -{ - if (CTreeCtrl::OnCreate(lpCreateStruct) == -1) - return -1; - - InitControl(); - - return 0; -} - -void CDirTreeCtrl::InitControl() -{ - // prepare image list - SHFILEINFO sfi; - m_hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - - TreeView_SetImageList(this->m_hWnd, m_hImageList, TVSIL_NORMAL); - - // insert desktop icon - InsertDesktopItem(); - - // expanding, ... - PostMessage(WM_INITCONTROL); -} - -///////////////////////////////////////////////////////////////////////////// -// wstawia ikon� pulpitu -HTREEITEM CDirTreeCtrl::InsertDesktopItem() -{ - // clear treectrl - it shouldn't be more than 1 desktop - if (!DeleteAllItems()) - return NULL; - - // clear vars - m_hDrives=NULL; - m_hNetwork=NULL; - - // fill with items - SHFILEINFO sfi; - LPSHELLFOLDER lpsfDesktop; - LPITEMIDLIST lpiidlDesktop; - if (FAILED(SHGetDesktopFolder(&lpsfDesktop))) - return NULL; - if (SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_DESKTOP, &lpiidlDesktop) != NOERROR) - return NULL; - - // add desktop - TVITEM tvi; - TVINSERTSTRUCT tvis; - TCHAR szText[_MAX_PATH]; - _SHELLITEMDATA *psid=new _SHELLITEMDATA; - psid->lpiidl=lpiidlDesktop; - psid->lpsf=lpsfDesktop; - psid->lpiidlRelative=NULL; - psid->lpsfParent=NULL; - - tvi.mask=TVIF_CHILDREN | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM; - if (!GetName(lpsfDesktop, lpiidlDesktop, 0/*SHGDN_INCLUDE_NONFILESYS*/, szText)) - lstrcpy(szText, _T("???")); - tvi.pszText=szText; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)lpiidlDesktop, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - tvi.iImage=sfi.iIcon; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)lpiidlDesktop, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); - tvi.iSelectedImage=sfi.iIcon; - tvi.cChildren=1; - tvi.lParam=reinterpret_cast(psid); - - tvis.hParent=TVI_ROOT; - tvis.item=tvi; - return InsertItem(&tvis); -} - -////////////////////////////////////////////////////////////////////////////// -// processes WM_INITCONTROL -LRESULT CDirTreeCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - switch(message) - { - case WM_INITCONTROL: - ExpandItem(GetRootItem(), TVE_EXPAND); - break; - case WM_SETPATH: - SetPath((LPCTSTR)lParam); - break; - } - - return CTreeCtrl::WindowProc(message, wParam, lParam); -} - -//////////////////////////////////////////////////////////////////////////// -// enables image list, ... -void CDirTreeCtrl::OnDestroy() -{ - SetImageList(NULL, LVSIL_SMALL); - CTreeCtrl::OnDestroy(); -} - -//////////////////////////////////////////////////////////////////////////// -// compares two items -int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM/* lParamSort*/) -{ - // je�li si� nie da - if (lParam1 == NULL || lParam2 == NULL) - return 0; - - // normalne przetwarzanie - SHELLITEMDATA* psidl1=(SHELLITEMDATA*)lParam1, *psidl2=(SHELLITEMDATA*)lParam2; - - LPSHELLFOLDER lpsf; - if (SHGetDesktopFolder(&lpsf) != NOERROR) - return 0; - - HRESULT hRes=lpsf->CompareIDs(0, psidl1->lpiidl, psidl2->lpiidl); - if (!SUCCEEDED(hRes)) - return 0; - - lpsf->Release(); - - return (short)SCODE_CODE(GetScode(hRes)); -} - -///////////////////////////////////////////////////////////////////////////// -// fills a hParent node with items starting with lpsf and lpdil for this item -HRESULT CDirTreeCtrl::FillNode(HTREEITEM hParent, LPSHELLFOLDER lpsf, LPITEMIDLIST lpidl, bool bSilent) -{ - // get the global flag under consideration - if (m_bIgnoreShellDialogs) - bSilent=m_bIgnoreShellDialogs; - - // get the desktop interface and id's of list for net neigh. and my computer - LPSHELLFOLDER lpsfDesktop=NULL; - LPITEMIDLIST lpiidlDrives=NULL; - LPITEMIDLIST lpiidlNetwork=NULL; - HRESULT hResult = S_OK; - if (hParent == GetRootItem()) - { - hResult = SHGetDesktopFolder(&lpsfDesktop); - if(SUCCEEDED(hResult)) - hResult = SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_DRIVES, &lpiidlDrives); - if(SUCCEEDED(hResult)) - hResult = SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_NETWORK, &lpiidlNetwork); - } - - // shell allocator - LPMALLOC lpm = NULL; - if(SUCCEEDED(hResult)) - hResult = SHGetMalloc(&lpm); - - // enumerate child items for lpsf - LPENUMIDLIST lpeid = NULL; - if(SUCCEEDED(hResult)) - hResult = lpsf->EnumObjects(bSilent ? NULL : GetParent()->GetSafeHwnd(), SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN, &lpeid); - - bool bFound=false; - if(SUCCEEDED(hResult)) - { - LPITEMIDLIST lpiidl; - SHFILEINFO sfi; - ULONG ulAttrib; - TVITEM tvi; - TVINSERTSTRUCT tvis; - _SHELLITEMDATA *psid; - TCHAR szText[_MAX_PATH]; - HTREEITEM hCurrent=NULL; - while (lpeid->Next(1, &lpiidl, NULL) == NOERROR) - { - // filer what has been found - ulAttrib=SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM; - lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lpiidl, &ulAttrib); - if (ulAttrib & SFGAO_FOLDER && (ulAttrib & SFGAO_FILESYSANCESTOR || ulAttrib & SFGAO_FILESYSTEM) ) - { - // there's something to add so set bFound - bFound=true; - - // it's time to add everything - psid=new _SHELLITEMDATA; - lpsf->BindToObject(lpiidl, NULL, IID_IShellFolder, (void**)&psid->lpsf); - psid->lpiidl=ConcatPidls(lpidl, lpiidl); - psid->lpiidlRelative=CopyITEMID(lpm, lpiidl); - psid->lpsfParent=lpsf; - - tvi.mask=TVIF_CHILDREN | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM; - if (!GetName(lpsf, lpiidl, SHGDN_INFOLDER/* | SHGDN_INCLUDE_NONFILESYS*/, szText)) - lstrcpy(szText, _T("???")); - tvi.pszText=szText; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)psid->lpiidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - tvi.iImage=sfi.iIcon; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)psid->lpiidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); - tvi.iSelectedImage=sfi.iIcon; - tvi.cChildren=(ulAttrib & SFGAO_HASSUBFOLDER); - tvi.lParam=reinterpret_cast(psid); - - tvis.hParent=hParent; - tvis.item=tvi; - hCurrent=InsertItem(&tvis); - - if (hParent == GetRootItem()) - { - // if this is My computer or net. neigh. - it's better to remember the handles - // compare psid->lpiidl and (lpiidlDrives & lpiidlNetwork) - if (SCODE_CODE(lpsfDesktop->CompareIDs(0, psid->lpiidl, lpiidlDrives)) == 0) - m_hDrives=hCurrent; - else if (SCODE_CODE(lpsfDesktop->CompareIDs(0, psid->lpiidl, lpiidlNetwork)) == 0) - m_hNetwork=hCurrent; - } - - FreePidl(lpiidl); // free found pidl - it was copied already - } - } - } - - if(lpeid) - lpeid->Release(); - if(lpsfDesktop) - lpsfDesktop->Release(); - if(lpm) - lpm->Release(); - - // sortuj - if(SUCCEEDED(hResult)) - { - if(bFound) - { - TVSORTCB tvscb; - tvscb.hParent=hParent; - tvscb.lpfnCompare=&CompareFunc; - tvscb.lParam=NULL; - if (!SortChildrenCB(&tvscb)) - TRACE("SortChildren failed\n"); - } - else - { - // some items has + and some not - correction - TVITEM tvi; - tvi.mask=TVIF_HANDLE | TVIF_CHILDREN; - tvi.hItem=hParent; - if (GetItem(&tvi) && tvi.cChildren == 1) - { - tvi.cChildren=0; - SetItem(&tvi); - } - } - } - - return hResult; -} - -//////////////////////////////////////////////////////////////////////////// -// alternate function for Expand(), makes additional processing -bool CDirTreeCtrl::ExpandItem(HTREEITEM hItem, UINT nCode) -{ - switch(nCode) - { - case TVE_EXPAND: - { - // get the item's data - TVITEM tvi; - tvi.mask=TVIF_PARAM | TVIF_STATE; - tvi.hItem=hItem; - tvi.stateMask=TVIS_EXPANDEDONCE | TVIS_SELECTED | TVIS_EXPANDED; - if (!GetItem(&tvi)) - return false; - - if (tvi.state & TVIS_EXPANDED) - return true; - - // Fill node before normal expanding - SHELLITEMDATA* psid; - if (GetItemStruct(hItem, &psid)) - { - if(FAILED(FillNode(hItem, psid->lpsf, psid->lpiidl, true))) - TRACE("FillNode in ExpandItem failed...\n"); - - // ignore fillnode in onitemexpanding - m_bIgnore=true; - } - - // normal expand - EnsureVisible(hItem); - SelectItem(hItem); - return Expand(hItem, TVE_EXPAND) != 0; - - break; - } - default: - return Expand(hItem, nCode) != 0; - } -} - -///////////////////////////////////////////////////////////////////////////// -// node expand handling - calls FillNode -void CDirTreeCtrl::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; - _SHELLITEMDATA* psid=reinterpret_cast<_SHELLITEMDATA*>(pNMTreeView->itemNew.lParam); - - switch (pNMTreeView->action) - { - case TVE_EXPAND: - if (!m_bIgnore) - { - // fill - if (FAILED(FillNode(pNMTreeView->itemNew.hItem, psid->lpsf, psid->lpiidl))) - TRACE("FillNode failed...\n"); - } - else - { - // now refresh normally - m_bIgnore=false; - } - break; - } - - *pResult = 0; -} - -//////////////////////////////////////////////////////////////////////////// -// deleting items after node collapses -void CDirTreeCtrl::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; - - switch (pNMTreeView->action) - { - case TVE_COLLAPSE: - if (ItemHasChildren(pNMTreeView->itemNew.hItem)) - { - HTREEITEM hItem; - while ((hItem=GetChildItem(pNMTreeView->itemNew.hItem)) != NULL) - DeleteItem(hItem); - } - - break; - } - - *pResult = 0; -} - -////////////////////////////////////////////////////////////////////////////// -// deletes everything what has been allocated for an item -void CDirTreeCtrl::OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; - _SHELLITEMDATA *psid=reinterpret_cast<_SHELLITEMDATA*>(pNMTreeView->itemOld.lParam); - - if(psid) - { - if(psid->lpsf) - psid->lpsf->Release(); - FreePidl(psid->lpiidl); - FreePidl(psid->lpiidlRelative); - delete psid; - } - - *pResult = 0; -} - -/////////////////////////////////////////////////////////////////////////// -// returns path associated with an item -bool CDirTreeCtrl::GetPath(HTREEITEM hItem, LPTSTR pszPath) -{ - TVITEM tvi; - tvi.mask=TVIF_HANDLE | TVIF_PARAM; - tvi.hItem=hItem; - - if (GetItem(&tvi)) - { - // item data - _SHELLITEMDATA* psid=reinterpret_cast<_SHELLITEMDATA*>(tvi.lParam); - if (psid == NULL) - return false; - - // desktop interface - LPSHELLFOLDER lpsf; - if (SHGetDesktopFolder(&lpsf) != NOERROR) - return false; - - if (!SHGetPathFromIDList(psid->lpiidl, pszPath)) - { - lpsf->Release(); - return false; - } - - lpsf->Release(); - return true; - } - else - return false; -} - -//////////////////////////////////////////////////////////////////////////// -// finds the item that is nearest to a given path - returns true if find -// even a part of a path -bool CDirTreeCtrl::SetPath(LPCTSTR lpszPath) -{ - ASSERT(lpszPath); - if(!lpszPath) - return false; - - // if path is empty - if (_tcscmp(lpszPath, _T("")) == 0) - return false; - - // type of path - bool bNetwork=_tcsncmp(lpszPath, _T("\\\\"), 2) == 0; - - if (!bNetwork) - return SetLocalPath(lpszPath); - else - { - // we don't look in net neighbourhood for speed reasons - EnsureVisible(m_hNetwork); -// SelectItem(m_hNetwork); -// ExpandItem(m_hNetwork, TVE_EXPAND); - return true; - } -} - - -/////////////////////////////////////////////////////////////////////////// -// sets the local path - not network -bool CDirTreeCtrl::SetLocalPath(LPCTSTR lpszPath) -{ - // expand desktop and my computer - HTREEITEM hItem=GetRootItem(); - ExpandItem(hItem, TVE_EXPAND); - ExpandItem(m_hDrives, TVE_EXPAND); - - HTREEITEM hFound=RegularSelect(m_hDrives, lpszPath); - if (hFound) - { - EnsureVisible(hFound); - SelectItem(hFound); - ExpandItem(hFound, TVE_EXPAND); - } - - return hFound != NULL; -} - -///////////////////////////////////////////////////////////////////////////// -// sets network path -/* -bool CDirTreeCtrl::SetRemotePath(LPCTSTR lpszPath) -{ - // expand desktop and net neigh - HTREEITEM hItem=GetRootItem(); - ExpandItem(hItem, TVE_EXPAND); - ExpandItem(m_hNetwork, TVE_EXPAND); - - // find root - TCHAR szBuffer[2048]; - NETRESOURCE* pnr; - CArray m_ahRoots; // root's list - bool bSkipRootChecks=false; - HTREEITEM hRoot=GetChildItem(m_hNetwork); - while(hRoot) - { - if (!GetItemShellData(hRoot, SHGDFIL_NETRESOURCE, szBuffer, 2048)) - { - // problem with NETRESOURCE - find next - hRoot=GetNextSiblingItem(hRoot); - continue; - } - - // got NETRESOURCE - pnr=(NETRESOURCE*)szBuffer; - if (pnr->dwDisplayType == RESOURCEDISPLAYTYPE_ROOT) - m_ahRoots.Add(hRoot); - else if (pnr->dwDisplayType == RESOURCEDISPLAYTYPE_SHARE) - { - if (ComparePaths(lpszPath, pnr->lpRemoteName)) - { - bSkipRootChecks=true; // skip II phase - break; // hRoot contains handle to an item from which we need to start searching from - } - } - - // next to check - hRoot=GetNextSiblingItem(hRoot); - } - - // II phase: net neigh tree traversation - if (!bSkipRootChecks) - { - hRoot=NULL; - HTREEITEM hNode; - TCHAR szBuffer[2048]; - for (int i=0;i(tvi.lParam); - - if (SHGetPathFromIDList(psid->lpiidl, szPath)) - { - if (ComparePaths(lpszPath, szPath)) - { - // it's contained - expand - ExpandItem(hItem, TVE_EXPAND); - hLast=hItem; // remember last that matches path - - hItem=GetChildItem(hItem); // another 'zoom' - continue; - } - } - } - - // next folder - hItem=GetNextSiblingItem(hItem); - } - - // return what has been found - return hLast; -} -//////////////////////////////////////////////////////////////////////////// -// helper - finds comp in a network that matches the path. Skips all the -// workgroups, network names, ... -/* -HTREEITEM CDirTreeCtrl::TraverseNetNode(HTREEITEM hItem, LPCTSTR lpszPath, LPTSTR lpszBuffer) -{ - // start with 1st chil item - HTREEITEM hNext=GetChildItem(hItem); - NETRESOURCE *pnet; - - while (hNext) - { - // get NETRESOURCE structure - is this a server ? - if (GetItemShellData(hNext, SHGDFIL_NETRESOURCE, lpszBuffer, 2048)) - { - // got NETRESOURCE - pnet=(NETRESOURCE*)lpszBuffer; - - // is the path contained - if (ComparePaths(lpszPath, pnet->lpRemoteName)) - return hNext; // found what's needed - - if (pnet->dwDisplayType != RESOURCEDISPLAYTYPE_SERVER) - { - // expand - if (!ExpandItem(hNext, TVE_EXPAND)) - return NULL; - - // recurse - HTREEITEM hFound; - if ( (hFound=TraverseNetNode(hNext, lpszPath, lpszBuffer)) != NULL) - return hFound; // if found - return, if not - continue search - } - } - - // next item to check. - hNext=GetNextSiblingItem(hNext); - } - - return NULL; // nothing has been found -} -*/ -//////////////////////////////////////////////////////////////////////////// -// compares two paths - if one is contained in another (to the first '\\' or '/' -bool CDirTreeCtrl::ComparePaths(LPCTSTR lpszFull, LPCTSTR lpszPartial) -{ - CString strSrc=lpszFull, strFnd=lpszPartial; - strFnd.MakeUpper(); - strFnd.TrimRight(_T("\\/")); - - // make uppercas the source string, cut before nearest \\ or / after strFnd.GetLength - strSrc.MakeUpper(); - - // find out the position of a nearest / lub '\\' - int iLen=strFnd.GetLength(), iPos; - if (strSrc.GetLength() >= iLen) - { - iPos=strSrc.Mid(iLen).FindOneOf(_T("\\/")); - if (iPos != -1) - strSrc=strSrc.Left(iPos+iLen); - - return strSrc == strFnd; - } - else - return false; -} - -//////////////////////////////////////////////////////////////////////////// -// returns shell description for an item (like in explorer). -bool CDirTreeCtrl::GetItemInfoTip(HTREEITEM hItem, CString* pTip) -{ - _SHELLITEMDATA* psid=(_SHELLITEMDATA*)GetItemData(hItem); - if (psid == NULL || psid->lpiidlRelative == NULL || psid->lpsfParent == NULL) - return false; - - // get interface - IQueryInfo *pqi; - if (psid->lpsfParent->GetUIObjectOf(this->GetSafeHwnd(), 1, (const struct _ITEMIDLIST**)&psid->lpiidlRelative, IID_IQueryInfo, 0, (void**)&pqi) != NOERROR) - return false; - - // get tip - WCHAR *pszTip; - if (pqi->GetInfoTip(0, &pszTip) != NOERROR) - { - pqi->Release(); - return false; - } - - // copy with a conversion - *pTip=(const WCHAR *)pszTip; - - // uwolnij pami�� skojarzon� z pszTip - LPMALLOC lpm; - if (SHGetMalloc(&lpm) == NOERROR) - { - lpm->Free(pszTip); - lpm->Release(); - } - - pqi->Release(); - - return true; -} - -//////////////////////////////////////////////////////////////////////////// -// better exchange for SHGetDataFromIDList -bool CDirTreeCtrl::GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize) -{ - PSHELLITEMDATA psid; - if (!GetItemStruct(hItem, &psid) || psid->lpsfParent == NULL || psid->lpiidlRelative == NULL) - return false; - - return SHGetDataFromIDList(psid->lpsfParent, psid->lpiidlRelative, nFormat, pBuffer, iSize) == NOERROR; -} - -///////////////////////////////////////////////////////////////////////////// -// returns SHELLITEMDATA associated with an item -bool CDirTreeCtrl::GetItemStruct(HTREEITEM hItem, PSHELLITEMDATA *ppsid) -{ - ASSERT(ppsid); - if(!ppsid) - return false; - *ppsid=(PSHELLITEMDATA)GetItemData(hItem); - return *ppsid != NULL; -} - -HTREEITEM CDirTreeCtrl::InsertNewFolder(HTREEITEM hParent, LPCTSTR /*lpszNewFolder*/) -{ - // check if HTREEITEM has an associated path - TCHAR szPath[_MAX_PATH]; - if (!GetPath(hParent, szPath)) - return NULL; - - // focus - SetFocus(); - - // if has child items - enumerate - TVITEM tvi; - tvi.mask=TVIF_HANDLE | TVIF_STATE | TVIF_CHILDREN; - tvi.hItem=hParent; - tvi.stateMask=TVIS_EXPANDED; - if (GetItem(&tvi)) - { - if (!(tvi.state & TVIS_EXPANDED)) - TRACE("InsertNewFolder's expanditem returned %u\n", ExpandItem(hParent, TVE_EXPAND)); - TRACE("%lu child items\n", tvi.cChildren); - } - - // if hParent doesn't have any chilren - add + to make it look like it hastak, aby wydawa�o si�, �e ma - if (!ItemHasChildren(hParent)) - { - tvi.mask=TVIF_HANDLE | TVIF_CHILDREN; - tvi.hItem=hParent; - tvi.cChildren=1; - if (!SetItem(&tvi)) - TRACE("SetItem failed...\n"); - } - - // temp buffer for a name - TCHAR *pszPath=new TCHAR[1]; - pszPath[0]=_T('\0'); - - // insert new item with an empty lParam - TVINSERTSTRUCT tvis; - tvis.hParent=hParent; - tvis.hInsertAfter=TVI_SORT; - tvis.item.mask=TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; - tvis.item.iImage=-1; - tvis.item.iSelectedImage=-1; - tvis.item.pszText=pszPath; - tvis.item.cchTextMax=lstrlen(tvis.item.pszText); - tvis.item.lParam=NULL; - - HTREEITEM hRes=InsertItem(&tvis); - - delete [] pszPath; - - // now make sure hParent is expanded - Expand(hParent, TVE_EXPAND); - - // edit an item - if (hRes) - { - m_iEditType=1; - CEdit *pctlEdit=EditLabel(hRes); - if (pctlEdit == NULL) - return NULL; - } - - return hRes; -} - -void CDirTreeCtrl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) -{ - NMTVDISPINFO* pdi = (NMTVDISPINFO*)pNMHDR; - - if (m_iEditType == 1) // for a new folder - { - if (pdi->item.pszText && _tcslen(pdi->item.pszText) != 0) - { - // no success at beginning - int iResult=0; - - // item - parent - HTREEITEM hParent=GetParentItem(pdi->item.hItem); - - // get parent folder name - TCHAR szPath[_MAX_PATH]; - if (!GetPath(hParent, szPath)) - { - // there's no path - skip - *pResult=0; - m_iEditType=0; - - // delete item - DeleteItem(pdi->item.hItem); - GetParent()->SendMessage(WM_CREATEFOLDERRESULT, 0, iResult); - return; - } - - // try to create folder - CString strPath=szPath; - if (strPath.Right(1) != _T('\\')) - strPath+=_T('\\'); - - // full path to the new folder - strPath+=pdi->item.pszText; - - // new folder - if (CreateDirectory(strPath, NULL)) - iResult = 1; - - // refresh - delete all from hParent and fill node - HTREEITEM hChild; - while ((hChild=GetChildItem(hParent)) != NULL) - DeleteItem(hChild); - - // now fillnode - SHELLITEMDATA* psid; - if (GetItemStruct(hParent, &psid)) - { - if (FAILED(FillNode(hParent, psid->lpsf, psid->lpiidl))) - TRACE("FillNode in EndEditLabel failed...\n"); - } - - hChild=GetChildItem(hParent); - while(hChild) - { - if (!GetPath(hChild, szPath)) - { - hChild=GetNextSiblingItem(hChild); - continue; - } - - if (_tcscmp(strPath, szPath) == 0) - { - // zaznacz - ExpandItem(hChild, TVE_EXPAND); - break; - } - - hChild=GetNextSiblingItem(hChild); - } - - - // another members - *pResult=1; - m_iEditType=0; - - GetParent()->SendMessage(WM_CREATEFOLDERRESULT, 0, iResult); - } - else - { - // no path - skip - *pResult=0; - m_iEditType=0; - - // delete an item - DeleteItem(pdi->item.hItem); - } - } - - *pResult = 0; -} - -void CDirTreeCtrl::OnBeginLabelEdit(NMHDR* /*pNMHDR*/, LRESULT* pResult) -{ - if (m_iEditType == 1) - *pResult=0; - else - *pResult=1; -} - -BOOL CDirTreeCtrl::OnEraseBkgnd(CDC* /*pDC*/) -{ - return FALSE; -} - -void CDirTreeCtrl::OnPaint() -{ - CPaintDC dc(this); // device context for painting - CMemDC memdc(&dc, &dc.m_ps.rcPaint); - - DefWindowProc(WM_PAINT, (WPARAM)memdc.GetSafeHdc(), 0); -} - -void CDirTreeCtrl::SetIgnoreShellDialogs(bool bFlag) -{ - m_bIgnoreShellDialogs=bFlag; -} - -bool CDirTreeCtrl::GetIgnoreShellDialogs() -{ - return m_bIgnoreShellDialogs; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "DirTreeCtrl.h" +#include "afxtempl.h" +#include "memdc.h" +#include "shlobj.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#define WM_INITCONTROL WM_USER+7 + +LPITEMIDLIST Next(LPCITEMIDLIST pidl) +{ + LPSTR lpMem=(LPSTR)pidl; + + lpMem+=pidl->mkid.cb; + + return (LPITEMIDLIST)lpMem; +} + +UINT GetSize(LPCITEMIDLIST pidl) +{ + UINT cbTotal = 0; + if (pidl) + { + cbTotal += sizeof(pidl->mkid.cb); // Null terminator + while (pidl->mkid.cb) + { + cbTotal += pidl->mkid.cb; + pidl = Next(pidl); + } + } + + return cbTotal; +} + +LPITEMIDLIST CreatePidl(UINT cbSize) +{ + LPMALLOC lpMalloc; + HRESULT hr; + LPITEMIDLIST pidl=NULL; + + hr=SHGetMalloc(&lpMalloc); + + if (FAILED(hr)) + return 0; + + pidl=(LPITEMIDLIST)lpMalloc->Alloc(cbSize); + + if (pidl) + memset(pidl, 0, cbSize); // zero-init for external task alloc + + if (lpMalloc) lpMalloc->Release(); + + return pidl; +} + +void FreePidl(LPITEMIDLIST lpiidl) +{ + LPMALLOC lpMalloc; + HRESULT hr; + + hr=SHGetMalloc(&lpMalloc); + + if (FAILED(hr)) + return; + + lpMalloc->Free(lpiidl); + + if (lpMalloc) lpMalloc->Release(); +} + +LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) +{ + LPITEMIDLIST pidlNew; + UINT cb1; + UINT cb2; + + if (pidl1) //May be NULL + cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb); + else + cb1 = 0; + + cb2 = GetSize(pidl2); + + pidlNew = CreatePidl(cb1 + cb2); + if (pidlNew) + { + if (pidl1) + memcpy(pidlNew, pidl1, cb1); + memcpy(((LPSTR)pidlNew) + cb1, pidl2, cb2); + } + return pidlNew; +} + +LPITEMIDLIST CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi) +{ + LPITEMIDLIST lpiTemp; + + lpiTemp=(LPITEMIDLIST)lpMalloc->Alloc(lpi->mkid.cb+sizeof(lpi->mkid.cb)); + CopyMemory((PVOID)lpiTemp, (CONST VOID *)lpi, lpi->mkid.cb+sizeof(lpi->mkid.cb)); + + return lpiTemp; +} + +BOOL GetName(LPSHELLFOLDER lpsf, + LPITEMIDLIST lpi, + DWORD dwFlags, + LPTSTR lpFriendlyName) +{ + BOOL bSuccess=TRUE; + STRRET str; + + if (NOERROR==lpsf->GetDisplayNameOf(lpi,dwFlags, &str)) + { + switch (str.uType) + { + case STRRET_WSTR: + { + CW2T cw2t(str.pOleStr); + lstrcpy(lpFriendlyName, cw2t); + break; + } + case STRRET_OFFSET: + { + lstrcpy(lpFriendlyName, (LPTSTR)lpi+str.uOffset); + break; + } + + case STRRET_CSTR: + { + CA2T ca2t(str.cStr); + lstrcpy(lpFriendlyName, ca2t); + break; + } + + default: + bSuccess = FALSE; + break; + } + } + else + bSuccess = FALSE; + + return bSuccess; +} + +LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi) +{ + TCHAR szBuff[MAX_PATH]; + LPSHELLFOLDER lpsfDeskTop; + LPITEMIDLIST lpifq; + ULONG ulEaten, ulAttribs; + HRESULT hr; + + if (!GetName(lpsf, lpi, SHGDN_FORPARSING, szBuff)) + return NULL; + + hr=SHGetDesktopFolder(&lpsfDeskTop); + + if (FAILED(hr)) + return NULL; + + CT2W ct2w(szBuff); + hr=lpsfDeskTop->ParseDisplayName(NULL, + NULL, + ct2w, + &ulEaten, + &lpifq, + &ulAttribs); + + lpsfDeskTop->Release(); + + if (FAILED(hr)) + return NULL; + + return lpifq; +} + +///////////////////////////////////////////////////////////////////////////// +// CDirTreeCtrl + +CDirTreeCtrl::CDirTreeCtrl() +{ + m_hDrives=NULL; + m_hNetwork=NULL; + m_hImageList=NULL; + m_bIgnore=false; + m_iEditType=0; +// RegisterWindowClass(); +} +/* +bool CDirTreeCtrl::RegisterWindowClass() +{ + WNDCLASS wndcls; + HINSTANCE hInst = AfxGetInstanceHandle(); + + if (!(::GetClassInfo(hInst, DIRTREECTRL_CLASSNAME, &wndcls))) + { + // otherwise we need to register a new class + wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; + wndcls.lpfnWndProc = ::DefWindowProc; + wndcls.cbClsExtra = wndcls.cbWndExtra = 0; + wndcls.hInstance = hInst; + wndcls.hIcon = NULL; + wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); + wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1); + wndcls.lpszMenuName = NULL; + wndcls.lpszClassName = DIRTREECTRL_CLASSNAME; + + if (!AfxRegisterClass(&wndcls)) + { + AfxThrowResourceException(); + return false; + } + } + + return true; +} +*/ +CDirTreeCtrl::~CDirTreeCtrl() +{ +} + + +BEGIN_MESSAGE_MAP(CDirTreeCtrl, CTreeCtrl) + //{{AFX_MSG_MAP(CDirTreeCtrl) + ON_WM_DESTROY() + ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding) + ON_NOTIFY_REFLECT(TVN_DELETEITEM, OnDeleteitem) + ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded) + ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit) + ON_NOTIFY_REFLECT(TVN_BEGINLABELEDIT, OnBeginLabelEdit) + ON_WM_ERASEBKGND() + ON_WM_PAINT() + ON_WM_CREATE() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CDirTreeCtrl message handlers + +///////////////////////////////////////////////////////////////////////////// +// inicjalizacja +void CDirTreeCtrl::PreSubclassWindow() +{ +// InitControl(); // here's not needed (strange ??) + CTreeCtrl::PreSubclassWindow(); +} + +int CDirTreeCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + if (CTreeCtrl::OnCreate(lpCreateStruct) == -1) + return -1; + + InitControl(); + + return 0; +} + +void CDirTreeCtrl::InitControl() +{ + // prepare image list + SHFILEINFO sfi; + m_hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + + TreeView_SetImageList(this->m_hWnd, m_hImageList, TVSIL_NORMAL); + + // insert desktop icon + InsertDesktopItem(); + + // expanding, ... + PostMessage(WM_INITCONTROL); +} + +///////////////////////////////////////////////////////////////////////////// +// wstawia ikon� pulpitu +HTREEITEM CDirTreeCtrl::InsertDesktopItem() +{ + // clear treectrl - it shouldn't be more than 1 desktop + if (!DeleteAllItems()) + return NULL; + + // clear vars + m_hDrives=NULL; + m_hNetwork=NULL; + + // fill with items + SHFILEINFO sfi; + LPSHELLFOLDER lpsfDesktop; + LPITEMIDLIST lpiidlDesktop; + if (FAILED(SHGetDesktopFolder(&lpsfDesktop))) + return NULL; + if (SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_DESKTOP, &lpiidlDesktop) != NOERROR) + return NULL; + + // add desktop + TVITEM tvi; + TVINSERTSTRUCT tvis; + TCHAR szText[_MAX_PATH]; + _SHELLITEMDATA *psid=new _SHELLITEMDATA; + psid->lpiidl=lpiidlDesktop; + psid->lpsf=lpsfDesktop; + psid->lpiidlRelative=NULL; + psid->lpsfParent=NULL; + + tvi.mask=TVIF_CHILDREN | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM; + if (!GetName(lpsfDesktop, lpiidlDesktop, 0/*SHGDN_INCLUDE_NONFILESYS*/, szText)) + lstrcpy(szText, _T("???")); + tvi.pszText=szText; + sfi.iIcon=-1; + SHGetFileInfo((LPCTSTR)lpiidlDesktop, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + tvi.iImage=sfi.iIcon; + sfi.iIcon=-1; + SHGetFileInfo((LPCTSTR)lpiidlDesktop, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); + tvi.iSelectedImage=sfi.iIcon; + tvi.cChildren=1; + tvi.lParam=reinterpret_cast(psid); + + tvis.hParent=TVI_ROOT; + tvis.item=tvi; + return InsertItem(&tvis); +} + +////////////////////////////////////////////////////////////////////////////// +// processes WM_INITCONTROL +LRESULT CDirTreeCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_INITCONTROL: + ExpandItem(GetRootItem(), TVE_EXPAND); + break; + case WM_SETPATH: + SetPath((LPCTSTR)lParam); + break; + } + + return CTreeCtrl::WindowProc(message, wParam, lParam); +} + +//////////////////////////////////////////////////////////////////////////// +// enables image list, ... +void CDirTreeCtrl::OnDestroy() +{ + SetImageList(NULL, LVSIL_SMALL); + CTreeCtrl::OnDestroy(); +} + +//////////////////////////////////////////////////////////////////////////// +// compares two items +int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM/* lParamSort*/) +{ + // je�li si� nie da + if (lParam1 == NULL || lParam2 == NULL) + return 0; + + // normalne przetwarzanie + SHELLITEMDATA* psidl1=(SHELLITEMDATA*)lParam1, *psidl2=(SHELLITEMDATA*)lParam2; + + LPSHELLFOLDER lpsf; + if (SHGetDesktopFolder(&lpsf) != NOERROR) + return 0; + + HRESULT hRes=lpsf->CompareIDs(0, psidl1->lpiidl, psidl2->lpiidl); + if (!SUCCEEDED(hRes)) + return 0; + + lpsf->Release(); + + return (short)SCODE_CODE(GetScode(hRes)); +} + +///////////////////////////////////////////////////////////////////////////// +// fills a hParent node with items starting with lpsf and lpdil for this item +HRESULT CDirTreeCtrl::FillNode(HTREEITEM hParent, LPSHELLFOLDER lpsf, LPITEMIDLIST lpidl, bool bSilent) +{ + // get the global flag under consideration + if (m_bIgnoreShellDialogs) + bSilent=m_bIgnoreShellDialogs; + + // get the desktop interface and id's of list for net neigh. and my computer + LPSHELLFOLDER lpsfDesktop=NULL; + LPITEMIDLIST lpiidlDrives=NULL; + LPITEMIDLIST lpiidlNetwork=NULL; + HRESULT hResult = S_OK; + if (hParent == GetRootItem()) + { + hResult = SHGetDesktopFolder(&lpsfDesktop); + if(SUCCEEDED(hResult)) + hResult = SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_DRIVES, &lpiidlDrives); + if(SUCCEEDED(hResult)) + hResult = SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_NETWORK, &lpiidlNetwork); + } + + // shell allocator + LPMALLOC lpm = NULL; + if(SUCCEEDED(hResult)) + hResult = SHGetMalloc(&lpm); + + // enumerate child items for lpsf + LPENUMIDLIST lpeid = NULL; + if(SUCCEEDED(hResult)) + hResult = lpsf->EnumObjects(bSilent ? NULL : GetParent()->GetSafeHwnd(), SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN, &lpeid); + + bool bFound=false; + if(SUCCEEDED(hResult)) + { + LPITEMIDLIST lpiidl; + SHFILEINFO sfi; + ULONG ulAttrib; + TVITEM tvi; + TVINSERTSTRUCT tvis; + _SHELLITEMDATA *psid; + TCHAR szText[_MAX_PATH]; + HTREEITEM hCurrent=NULL; + while (lpeid->Next(1, &lpiidl, NULL) == NOERROR) + { + // filer what has been found + ulAttrib=SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM; + lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lpiidl, &ulAttrib); + if (ulAttrib & SFGAO_FOLDER && (ulAttrib & SFGAO_FILESYSANCESTOR || ulAttrib & SFGAO_FILESYSTEM) ) + { + // there's something to add so set bFound + bFound=true; + + // it's time to add everything + psid=new _SHELLITEMDATA; + lpsf->BindToObject(lpiidl, NULL, IID_IShellFolder, (void**)&psid->lpsf); + psid->lpiidl=ConcatPidls(lpidl, lpiidl); + psid->lpiidlRelative=CopyITEMID(lpm, lpiidl); + psid->lpsfParent=lpsf; + + tvi.mask=TVIF_CHILDREN | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM; + if (!GetName(lpsf, lpiidl, SHGDN_INFOLDER/* | SHGDN_INCLUDE_NONFILESYS*/, szText)) + lstrcpy(szText, _T("???")); + tvi.pszText=szText; + sfi.iIcon=-1; + SHGetFileInfo((LPCTSTR)psid->lpiidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + tvi.iImage=sfi.iIcon; + sfi.iIcon=-1; + SHGetFileInfo((LPCTSTR)psid->lpiidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); + tvi.iSelectedImage=sfi.iIcon; + tvi.cChildren=(ulAttrib & SFGAO_HASSUBFOLDER); + tvi.lParam=reinterpret_cast(psid); + + tvis.hParent=hParent; + tvis.item=tvi; + hCurrent=InsertItem(&tvis); + + if (hParent == GetRootItem()) + { + // if this is My computer or net. neigh. - it's better to remember the handles + // compare psid->lpiidl and (lpiidlDrives & lpiidlNetwork) + if (SCODE_CODE(lpsfDesktop->CompareIDs(0, psid->lpiidl, lpiidlDrives)) == 0) + m_hDrives=hCurrent; + else if (SCODE_CODE(lpsfDesktop->CompareIDs(0, psid->lpiidl, lpiidlNetwork)) == 0) + m_hNetwork=hCurrent; + } + + FreePidl(lpiidl); // free found pidl - it was copied already + } + } + } + + if(lpeid) + lpeid->Release(); + if(lpsfDesktop) + lpsfDesktop->Release(); + if(lpm) + lpm->Release(); + + // sortuj + if(SUCCEEDED(hResult)) + { + if(bFound) + { + TVSORTCB tvscb; + tvscb.hParent=hParent; + tvscb.lpfnCompare=&CompareFunc; + tvscb.lParam=NULL; + if (!SortChildrenCB(&tvscb)) + TRACE("SortChildren failed\n"); + } + else + { + // some items has + and some not - correction + TVITEM tvi; + tvi.mask=TVIF_HANDLE | TVIF_CHILDREN; + tvi.hItem=hParent; + if (GetItem(&tvi) && tvi.cChildren == 1) + { + tvi.cChildren=0; + SetItem(&tvi); + } + } + } + + return hResult; +} + +//////////////////////////////////////////////////////////////////////////// +// alternate function for Expand(), makes additional processing +bool CDirTreeCtrl::ExpandItem(HTREEITEM hItem, UINT nCode) +{ + switch(nCode) + { + case TVE_EXPAND: + { + // get the item's data + TVITEM tvi; + tvi.mask=TVIF_PARAM | TVIF_STATE; + tvi.hItem=hItem; + tvi.stateMask=TVIS_EXPANDEDONCE | TVIS_SELECTED | TVIS_EXPANDED; + if (!GetItem(&tvi)) + return false; + + if (tvi.state & TVIS_EXPANDED) + return true; + + // Fill node before normal expanding + SHELLITEMDATA* psid; + if (GetItemStruct(hItem, &psid)) + { + if(FAILED(FillNode(hItem, psid->lpsf, psid->lpiidl, true))) + TRACE("FillNode in ExpandItem failed...\n"); + + // ignore fillnode in onitemexpanding + m_bIgnore=true; + } + + // normal expand + EnsureVisible(hItem); + SelectItem(hItem); + return Expand(hItem, TVE_EXPAND) != 0; + + break; + } + default: + return Expand(hItem, nCode) != 0; + } +} + +///////////////////////////////////////////////////////////////////////////// +// node expand handling - calls FillNode +void CDirTreeCtrl::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; + _SHELLITEMDATA* psid=reinterpret_cast<_SHELLITEMDATA*>(pNMTreeView->itemNew.lParam); + + switch (pNMTreeView->action) + { + case TVE_EXPAND: + if (!m_bIgnore) + { + // fill + if (FAILED(FillNode(pNMTreeView->itemNew.hItem, psid->lpsf, psid->lpiidl))) + TRACE("FillNode failed...\n"); + } + else + { + // now refresh normally + m_bIgnore=false; + } + break; + } + + *pResult = 0; +} + +//////////////////////////////////////////////////////////////////////////// +// deleting items after node collapses +void CDirTreeCtrl::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; + + switch (pNMTreeView->action) + { + case TVE_COLLAPSE: + if (ItemHasChildren(pNMTreeView->itemNew.hItem)) + { + HTREEITEM hItem; + while ((hItem=GetChildItem(pNMTreeView->itemNew.hItem)) != NULL) + DeleteItem(hItem); + } + + break; + } + + *pResult = 0; +} + +////////////////////////////////////////////////////////////////////////////// +// deletes everything what has been allocated for an item +void CDirTreeCtrl::OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; + _SHELLITEMDATA *psid=reinterpret_cast<_SHELLITEMDATA*>(pNMTreeView->itemOld.lParam); + + if(psid) + { + if(psid->lpsf) + psid->lpsf->Release(); + FreePidl(psid->lpiidl); + FreePidl(psid->lpiidlRelative); + delete psid; + } + + *pResult = 0; +} + +/////////////////////////////////////////////////////////////////////////// +// returns path associated with an item +bool CDirTreeCtrl::GetPath(HTREEITEM hItem, LPTSTR pszPath) +{ + TVITEM tvi; + tvi.mask=TVIF_HANDLE | TVIF_PARAM; + tvi.hItem=hItem; + + if (GetItem(&tvi)) + { + // item data + _SHELLITEMDATA* psid=reinterpret_cast<_SHELLITEMDATA*>(tvi.lParam); + if (psid == NULL) + return false; + + // desktop interface + LPSHELLFOLDER lpsf; + if (SHGetDesktopFolder(&lpsf) != NOERROR) + return false; + + if (!SHGetPathFromIDList(psid->lpiidl, pszPath)) + { + lpsf->Release(); + return false; + } + + lpsf->Release(); + return true; + } + else + return false; +} + +//////////////////////////////////////////////////////////////////////////// +// finds the item that is nearest to a given path - returns true if find +// even a part of a path +bool CDirTreeCtrl::SetPath(LPCTSTR lpszPath) +{ + ASSERT(lpszPath); + if(!lpszPath) + return false; + + // if path is empty + if (_tcscmp(lpszPath, _T("")) == 0) + return false; + + // type of path + bool bNetwork=_tcsncmp(lpszPath, _T("\\\\"), 2) == 0; + + if (!bNetwork) + return SetLocalPath(lpszPath); + else + { + // we don't look in net neighbourhood for speed reasons + EnsureVisible(m_hNetwork); +// SelectItem(m_hNetwork); +// ExpandItem(m_hNetwork, TVE_EXPAND); + return true; + } +} + + +/////////////////////////////////////////////////////////////////////////// +// sets the local path - not network +bool CDirTreeCtrl::SetLocalPath(LPCTSTR lpszPath) +{ + // expand desktop and my computer + HTREEITEM hItem=GetRootItem(); + ExpandItem(hItem, TVE_EXPAND); + ExpandItem(m_hDrives, TVE_EXPAND); + + HTREEITEM hFound=RegularSelect(m_hDrives, lpszPath); + if (hFound) + { + EnsureVisible(hFound); + SelectItem(hFound); + ExpandItem(hFound, TVE_EXPAND); + } + + return hFound != NULL; +} + +///////////////////////////////////////////////////////////////////////////// +// sets network path +/* +bool CDirTreeCtrl::SetRemotePath(LPCTSTR lpszPath) +{ + // expand desktop and net neigh + HTREEITEM hItem=GetRootItem(); + ExpandItem(hItem, TVE_EXPAND); + ExpandItem(m_hNetwork, TVE_EXPAND); + + // find root + TCHAR szBuffer[2048]; + NETRESOURCE* pnr; + CArray m_ahRoots; // root's list + bool bSkipRootChecks=false; + HTREEITEM hRoot=GetChildItem(m_hNetwork); + while(hRoot) + { + if (!GetItemShellData(hRoot, SHGDFIL_NETRESOURCE, szBuffer, 2048)) + { + // problem with NETRESOURCE - find next + hRoot=GetNextSiblingItem(hRoot); + continue; + } + + // got NETRESOURCE + pnr=(NETRESOURCE*)szBuffer; + if (pnr->dwDisplayType == RESOURCEDISPLAYTYPE_ROOT) + m_ahRoots.Add(hRoot); + else if (pnr->dwDisplayType == RESOURCEDISPLAYTYPE_SHARE) + { + if (ComparePaths(lpszPath, pnr->lpRemoteName)) + { + bSkipRootChecks=true; // skip II phase + break; // hRoot contains handle to an item from which we need to start searching from + } + } + + // next to check + hRoot=GetNextSiblingItem(hRoot); + } + + // II phase: net neigh tree traversation + if (!bSkipRootChecks) + { + hRoot=NULL; + HTREEITEM hNode; + TCHAR szBuffer[2048]; + for (int i=0;i(tvi.lParam); + + if (SHGetPathFromIDList(psid->lpiidl, szPath)) + { + if (ComparePaths(lpszPath, szPath)) + { + // it's contained - expand + ExpandItem(hItem, TVE_EXPAND); + hLast=hItem; // remember last that matches path + + hItem=GetChildItem(hItem); // another 'zoom' + continue; + } + } + } + + // next folder + hItem=GetNextSiblingItem(hItem); + } + + // return what has been found + return hLast; +} +//////////////////////////////////////////////////////////////////////////// +// helper - finds comp in a network that matches the path. Skips all the +// workgroups, network names, ... +/* +HTREEITEM CDirTreeCtrl::TraverseNetNode(HTREEITEM hItem, LPCTSTR lpszPath, LPTSTR lpszBuffer) +{ + // start with 1st chil item + HTREEITEM hNext=GetChildItem(hItem); + NETRESOURCE *pnet; + + while (hNext) + { + // get NETRESOURCE structure - is this a server ? + if (GetItemShellData(hNext, SHGDFIL_NETRESOURCE, lpszBuffer, 2048)) + { + // got NETRESOURCE + pnet=(NETRESOURCE*)lpszBuffer; + + // is the path contained + if (ComparePaths(lpszPath, pnet->lpRemoteName)) + return hNext; // found what's needed + + if (pnet->dwDisplayType != RESOURCEDISPLAYTYPE_SERVER) + { + // expand + if (!ExpandItem(hNext, TVE_EXPAND)) + return NULL; + + // recurse + HTREEITEM hFound; + if ( (hFound=TraverseNetNode(hNext, lpszPath, lpszBuffer)) != NULL) + return hFound; // if found - return, if not - continue search + } + } + + // next item to check. + hNext=GetNextSiblingItem(hNext); + } + + return NULL; // nothing has been found +} +*/ +//////////////////////////////////////////////////////////////////////////// +// compares two paths - if one is contained in another (to the first '\\' or '/' +bool CDirTreeCtrl::ComparePaths(LPCTSTR lpszFull, LPCTSTR lpszPartial) +{ + CString strSrc=lpszFull, strFnd=lpszPartial; + strFnd.MakeUpper(); + strFnd.TrimRight(_T("\\/")); + + // make uppercas the source string, cut before nearest \\ or / after strFnd.GetLength + strSrc.MakeUpper(); + + // find out the position of a nearest / lub '\\' + int iLen=strFnd.GetLength(), iPos; + if (strSrc.GetLength() >= iLen) + { + iPos=strSrc.Mid(iLen).FindOneOf(_T("\\/")); + if (iPos != -1) + strSrc=strSrc.Left(iPos+iLen); + + return strSrc == strFnd; + } + else + return false; +} + +//////////////////////////////////////////////////////////////////////////// +// returns shell description for an item (like in explorer). +bool CDirTreeCtrl::GetItemInfoTip(HTREEITEM hItem, CString* pTip) +{ + _SHELLITEMDATA* psid=(_SHELLITEMDATA*)GetItemData(hItem); + if (psid == NULL || psid->lpiidlRelative == NULL || psid->lpsfParent == NULL) + return false; + + // get interface + IQueryInfo *pqi; + if (psid->lpsfParent->GetUIObjectOf(this->GetSafeHwnd(), 1, (const struct _ITEMIDLIST**)&psid->lpiidlRelative, IID_IQueryInfo, 0, (void**)&pqi) != NOERROR) + return false; + + // get tip + WCHAR *pszTip; + if (pqi->GetInfoTip(0, &pszTip) != NOERROR) + { + pqi->Release(); + return false; + } + + // copy with a conversion + *pTip=(const WCHAR *)pszTip; + + // uwolnij pami�� skojarzon� z pszTip + LPMALLOC lpm; + if (SHGetMalloc(&lpm) == NOERROR) + { + lpm->Free(pszTip); + lpm->Release(); + } + + pqi->Release(); + + return true; +} + +//////////////////////////////////////////////////////////////////////////// +// better exchange for SHGetDataFromIDList +bool CDirTreeCtrl::GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize) +{ + PSHELLITEMDATA psid; + if (!GetItemStruct(hItem, &psid) || psid->lpsfParent == NULL || psid->lpiidlRelative == NULL) + return false; + + return SHGetDataFromIDList(psid->lpsfParent, psid->lpiidlRelative, nFormat, pBuffer, iSize) == NOERROR; +} + +///////////////////////////////////////////////////////////////////////////// +// returns SHELLITEMDATA associated with an item +bool CDirTreeCtrl::GetItemStruct(HTREEITEM hItem, PSHELLITEMDATA *ppsid) +{ + ASSERT(ppsid); + if(!ppsid) + return false; + *ppsid=(PSHELLITEMDATA)GetItemData(hItem); + return *ppsid != NULL; +} + +HTREEITEM CDirTreeCtrl::InsertNewFolder(HTREEITEM hParent, LPCTSTR /*lpszNewFolder*/) +{ + // check if HTREEITEM has an associated path + TCHAR szPath[_MAX_PATH]; + if (!GetPath(hParent, szPath)) + return NULL; + + // focus + SetFocus(); + + // if has child items - enumerate + TVITEM tvi; + tvi.mask=TVIF_HANDLE | TVIF_STATE | TVIF_CHILDREN; + tvi.hItem=hParent; + tvi.stateMask=TVIS_EXPANDED; + if (GetItem(&tvi)) + { + if (!(tvi.state & TVIS_EXPANDED)) + TRACE("InsertNewFolder's expanditem returned %u\n", ExpandItem(hParent, TVE_EXPAND)); + TRACE("%lu child items\n", tvi.cChildren); + } + + // if hParent doesn't have any chilren - add + to make it look like it hastak, aby wydawa�o si�, �e ma + if (!ItemHasChildren(hParent)) + { + tvi.mask=TVIF_HANDLE | TVIF_CHILDREN; + tvi.hItem=hParent; + tvi.cChildren=1; + if (!SetItem(&tvi)) + TRACE("SetItem failed...\n"); + } + + // temp buffer for a name + TCHAR *pszPath=new TCHAR[1]; + pszPath[0]=_T('\0'); + + // insert new item with an empty lParam + TVINSERTSTRUCT tvis; + tvis.hParent=hParent; + tvis.hInsertAfter=TVI_SORT; + tvis.item.mask=TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvis.item.iImage=-1; + tvis.item.iSelectedImage=-1; + tvis.item.pszText=pszPath; + tvis.item.cchTextMax=lstrlen(tvis.item.pszText); + tvis.item.lParam=NULL; + + HTREEITEM hRes=InsertItem(&tvis); + + delete [] pszPath; + + // now make sure hParent is expanded + Expand(hParent, TVE_EXPAND); + + // edit an item + if (hRes) + { + m_iEditType=1; + CEdit *pctlEdit=EditLabel(hRes); + if (pctlEdit == NULL) + return NULL; + } + + return hRes; +} + +void CDirTreeCtrl::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) +{ + NMTVDISPINFO* pdi = (NMTVDISPINFO*)pNMHDR; + + if (m_iEditType == 1) // for a new folder + { + if (pdi->item.pszText && _tcslen(pdi->item.pszText) != 0) + { + // no success at beginning + int iResult=0; + + // item - parent + HTREEITEM hParent=GetParentItem(pdi->item.hItem); + + // get parent folder name + TCHAR szPath[_MAX_PATH]; + if (!GetPath(hParent, szPath)) + { + // there's no path - skip + *pResult=0; + m_iEditType=0; + + // delete item + DeleteItem(pdi->item.hItem); + GetParent()->SendMessage(WM_CREATEFOLDERRESULT, 0, iResult); + return; + } + + // try to create folder + CString strPath=szPath; + if (strPath.Right(1) != _T('\\')) + strPath+=_T('\\'); + + // full path to the new folder + strPath+=pdi->item.pszText; + + // new folder + if (CreateDirectory(strPath, NULL)) + iResult = 1; + + // refresh - delete all from hParent and fill node + HTREEITEM hChild; + while ((hChild=GetChildItem(hParent)) != NULL) + DeleteItem(hChild); + + // now fillnode + SHELLITEMDATA* psid; + if (GetItemStruct(hParent, &psid)) + { + if (FAILED(FillNode(hParent, psid->lpsf, psid->lpiidl))) + TRACE("FillNode in EndEditLabel failed...\n"); + } + + hChild=GetChildItem(hParent); + while(hChild) + { + if (!GetPath(hChild, szPath)) + { + hChild=GetNextSiblingItem(hChild); + continue; + } + + if (_tcscmp(strPath, szPath) == 0) + { + // zaznacz + ExpandItem(hChild, TVE_EXPAND); + break; + } + + hChild=GetNextSiblingItem(hChild); + } + + + // another members + *pResult=1; + m_iEditType=0; + + GetParent()->SendMessage(WM_CREATEFOLDERRESULT, 0, iResult); + } + else + { + // no path - skip + *pResult=0; + m_iEditType=0; + + // delete an item + DeleteItem(pdi->item.hItem); + } + } + + *pResult = 0; +} + +void CDirTreeCtrl::OnBeginLabelEdit(NMHDR* /*pNMHDR*/, LRESULT* pResult) +{ + if (m_iEditType == 1) + *pResult=0; + else + *pResult=1; +} + +BOOL CDirTreeCtrl::OnEraseBkgnd(CDC* /*pDC*/) +{ + return FALSE; +} + +void CDirTreeCtrl::OnPaint() +{ + CPaintDC dc(this); // device context for painting + CMemDC memdc(&dc, &dc.m_ps.rcPaint); + + DefWindowProc(WM_PAINT, (WPARAM)memdc.GetSafeHdc(), 0); +} + +void CDirTreeCtrl::SetIgnoreShellDialogs(bool bFlag) +{ + m_bIgnoreShellDialogs=bFlag; +} + +bool CDirTreeCtrl::GetIgnoreShellDialogs() +{ + return m_bIgnoreShellDialogs; +} Index: src/ch/DirTreeCtrl.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DirTreeCtrl.h (.../DirTreeCtrl.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/DirTreeCtrl.h (.../DirTreeCtrl.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,172 +1,172 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/************************************************************************* - CDirTreeCtrl tree control - - Files: DirTreeCtrl.h, DirTreeCtrl.cpp - Author: Ixen Gerthannes - Usage: - Use it just as normal controls - place tree ctrl on your dialog and - subclass it. - Members: - Functions: - HTREEITEM InsertDesktopItem(); - initialisation - deletes - all items in a list, and inserts desktop root icon - bool ExpandItem(HTREEITEM hItem, UINT nCode); - replacement - for function Expand - does more processing - better; - UINT nCode just as in Expand(...) - bool GetPath(HTREEITEM hItem, LPTSTR pszPath); - returns file - system path (into pszPath) given HTREEITEM. - bool SetPath(LPCTSTR lpszPath); - try to select given path in - a directory tree. Returns true if whole path or a part of it - was selected. - bool GetItemInfoTip(HTREEITEM hItem, CString* pTip); - try to - get an explorer's tool tip text for a given HTREEITEM. - It uses IQueryInfo interface on IShellFolder. Cannot use it - for top-level item (root). Note: function may return true - with empty *pTip. - bool GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize); - functions gets data as in SHGetDataFromIDList - bool GetItemStruct(HTREEITEM hItem, PSHELLITEMDATA *ppsid); - function returns address of struct associated whith a given - item (just as GetItemData, but type-casted to SHELLITEMDATA) - Structs: - SHELLITEMDATA - struct that is associated as lParam with every - item inserted into this tree control (with new operator). - Members: - LPSHELLFOLDER lpsf; - address of IShellFolder interface - associated with this item - LPITEMIDLIST lpiidl; - this's item id list relative to - desktop folder - LPSHELLFOLDER lpsfParent; - address of IShellFolder - associated with a parent's item of this item - LPITEMIDLIST lpiidlRelative; - this's item id list - relative to lpsfParent - -*************************************************************************/ - -#ifndef __DIRTREECTRL_H__ -#define __DIRTREECTRL_H__ - -#include "shlobj.h" - -// Functions that deal with PIDLs -LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2); -LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi); -LPITEMIDLIST CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi); -BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPTSTR lpFriendlyName); -LPITEMIDLIST CreatePidl(UINT cbSize); -void FreePidl(LPITEMIDLIST lpiidl); -UINT GetSize(LPCITEMIDLIST pidl); -LPITEMIDLIST Next(LPCITEMIDLIST pidl); - -///////////////////////////////////////////////////////////////////////////// -// CDirTreeCtrl window -#define WM_SETPATH WM_USER+8 -#define WM_CREATEFOLDERRESULT WM_USER+9 - -#define SHELLITEMDATA _SHELLITEMDATA -#define PSHELLITEMDATA _SHELLITEMDATA* - -struct _SHELLITEMDATA -{ - LPSHELLFOLDER lpsf; // this shell folder (always exists) - LPITEMIDLIST lpiidl; // this item id list relative to desktop (always exists) - - LPSHELLFOLDER lpsfParent; // parent shell folder (may be NULL) - LPITEMIDLIST lpiidlRelative; // this item id list relative to the parent's lpsf (may be NULL) -}; - -class CDirTreeCtrl : public CTreeCtrl -{ -// Construction -public: - CDirTreeCtrl(); - -// Attributes -public: - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CDirTreeCtrl) - protected: - virtual void PreSubclassWindow(); - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - //}}AFX_VIRTUAL - - // Implementation -public: - void SetIgnoreShellDialogs(bool bFlag); - bool GetIgnoreShellDialogs(); - HTREEITEM InsertDesktopItem(); - HTREEITEM InsertNewFolder(HTREEITEM hParent, LPCTSTR lpszNewFolder); - bool ExpandItem(HTREEITEM hItem, UINT nCode); - bool GetPath(HTREEITEM hItem, LPTSTR pszPath); - bool SetPath(LPCTSTR lpszPath); - bool GetItemInfoTip(HTREEITEM hItem, CString* pTip); - bool GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize); - bool GetItemStruct(HTREEITEM hItem, PSHELLITEMDATA *ppsid); - bool IsEditing() const { return m_iEditType != 0; }; - virtual ~CDirTreeCtrl(); - - // Generated message map functions -protected: - bool RegisterWindowClass(); - friend int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM/* lParamSort*/); - - //{{AFX_MSG(CDirTreeCtrl) - afx_msg void OnDestroy(); - afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - afx_msg void OnPaint(); - afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() - -// members -protected: - void InitControl(); - HTREEITEM RegularSelect(HTREEITEM hStart, LPCTSTR lpszPath); -// HTREEITEM TraverseNetNode(HTREEITEM hItem, LPCTSTR lpszPath, LPTSTR lpszBuffer); - bool ComparePaths(LPCTSTR lpszFull, LPCTSTR lpszPartial); -// bool SetRemotePath(LPCTSTR lpszPath); - bool SetLocalPath(LPCTSTR lpszPath); - HRESULT FillNode(HTREEITEM hParent, LPSHELLFOLDER lpsf, LPITEMIDLIST lpidl, bool bSilent=false); - - bool m_bIgnoreShellDialogs; // ignore dialogs of type 'insert floppy disk' - HIMAGELIST m_hImageList; // system img list - HTREEITEM m_hDrives, m_hNetwork; // my computer's and net neighbourhood's handles - bool m_bIgnore; // ignore the nearest adding of items in OnItemexpanding - int m_iEditType; // type of item editing (0-doesn't exist (nothing for edit), 1-new folder) -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +/************************************************************************* + CDirTreeCtrl tree control + + Files: DirTreeCtrl.h, DirTreeCtrl.cpp + Author: Ixen Gerthannes + Usage: + Use it just as normal controls - place tree ctrl on your dialog and + subclass it. + Members: + Functions: + HTREEITEM InsertDesktopItem(); - initialisation - deletes + all items in a list, and inserts desktop root icon + bool ExpandItem(HTREEITEM hItem, UINT nCode); - replacement + for function Expand - does more processing - better; + UINT nCode just as in Expand(...) + bool GetPath(HTREEITEM hItem, LPTSTR pszPath); - returns file + system path (into pszPath) given HTREEITEM. + bool SetPath(LPCTSTR lpszPath); - try to select given path in + a directory tree. Returns true if whole path or a part of it + was selected. + bool GetItemInfoTip(HTREEITEM hItem, CString* pTip); - try to + get an explorer's tool tip text for a given HTREEITEM. + It uses IQueryInfo interface on IShellFolder. Cannot use it + for top-level item (root). Note: function may return true + with empty *pTip. + bool GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize); + functions gets data as in SHGetDataFromIDList + bool GetItemStruct(HTREEITEM hItem, PSHELLITEMDATA *ppsid); + function returns address of struct associated whith a given + item (just as GetItemData, but type-casted to SHELLITEMDATA) + Structs: + SHELLITEMDATA - struct that is associated as lParam with every + item inserted into this tree control (with new operator). + Members: + LPSHELLFOLDER lpsf; - address of IShellFolder interface + associated with this item + LPITEMIDLIST lpiidl; - this's item id list relative to + desktop folder + LPSHELLFOLDER lpsfParent; - address of IShellFolder + associated with a parent's item of this item + LPITEMIDLIST lpiidlRelative; - this's item id list + relative to lpsfParent + +*************************************************************************/ + +#ifndef __DIRTREECTRL_H__ +#define __DIRTREECTRL_H__ + +#include "shlobj.h" + +// Functions that deal with PIDLs +LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2); +LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi); +LPITEMIDLIST CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi); +BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPTSTR lpFriendlyName); +LPITEMIDLIST CreatePidl(UINT cbSize); +void FreePidl(LPITEMIDLIST lpiidl); +UINT GetSize(LPCITEMIDLIST pidl); +LPITEMIDLIST Next(LPCITEMIDLIST pidl); + +///////////////////////////////////////////////////////////////////////////// +// CDirTreeCtrl window +#define WM_SETPATH WM_USER+8 +#define WM_CREATEFOLDERRESULT WM_USER+9 + +#define SHELLITEMDATA _SHELLITEMDATA +#define PSHELLITEMDATA _SHELLITEMDATA* + +struct _SHELLITEMDATA +{ + LPSHELLFOLDER lpsf; // this shell folder (always exists) + LPITEMIDLIST lpiidl; // this item id list relative to desktop (always exists) + + LPSHELLFOLDER lpsfParent; // parent shell folder (may be NULL) + LPITEMIDLIST lpiidlRelative; // this item id list relative to the parent's lpsf (may be NULL) +}; + +class CDirTreeCtrl : public CTreeCtrl +{ +// Construction +public: + CDirTreeCtrl(); + +// Attributes +public: + +// Operations +public: + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CDirTreeCtrl) + protected: + virtual void PreSubclassWindow(); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + //}}AFX_VIRTUAL + + // Implementation +public: + void SetIgnoreShellDialogs(bool bFlag); + bool GetIgnoreShellDialogs(); + HTREEITEM InsertDesktopItem(); + HTREEITEM InsertNewFolder(HTREEITEM hParent, LPCTSTR lpszNewFolder); + bool ExpandItem(HTREEITEM hItem, UINT nCode); + bool GetPath(HTREEITEM hItem, LPTSTR pszPath); + bool SetPath(LPCTSTR lpszPath); + bool GetItemInfoTip(HTREEITEM hItem, CString* pTip); + bool GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize); + bool GetItemStruct(HTREEITEM hItem, PSHELLITEMDATA *ppsid); + bool IsEditing() const { return m_iEditType != 0; }; + virtual ~CDirTreeCtrl(); + + // Generated message map functions +protected: + bool RegisterWindowClass(); + friend int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM/* lParamSort*/); + + //{{AFX_MSG(CDirTreeCtrl) + afx_msg void OnDestroy(); + afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnDeleteitem(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + afx_msg void OnPaint(); + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() + +// members +protected: + void InitControl(); + HTREEITEM RegularSelect(HTREEITEM hStart, LPCTSTR lpszPath); +// HTREEITEM TraverseNetNode(HTREEITEM hItem, LPCTSTR lpszPath, LPTSTR lpszBuffer); + bool ComparePaths(LPCTSTR lpszFull, LPCTSTR lpszPartial); +// bool SetRemotePath(LPCTSTR lpszPath); + bool SetLocalPath(LPCTSTR lpszPath); + HRESULT FillNode(HTREEITEM hParent, LPSHELLFOLDER lpsf, LPITEMIDLIST lpidl, bool bSilent=false); + + bool m_bIgnoreShellDialogs; // ignore dialogs of type 'insert floppy disk' + HIMAGELIST m_hImageList; // system img list + HTREEITEM m_hDrives, m_hNetwork; // my computer's and net neighbourhood's handles + bool m_bIgnore; // ignore the nearest adding of items in OnItemexpanding + int m_iEditType; // type of item editing (0-doesn't exist (nothing for edit), 1-new folder) +}; + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/DstFileErrorDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/DstFileErrorDlg.h (.../DstFileErrorDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/DstFileErrorDlg.h (.../DstFileErrorDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,69 +1,69 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __DSTFILEERRORDLG_H__ -#define __DSTFILEERRORDLG_H__ - -///////////////////////////////////////////////////////////////////////////// -// CDstFileErrorDlg dialog - -class CDstFileErrorDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CDstFileErrorDlg(); // standard constructor - - CString m_strTitle; - bool m_bEnableTimer; - int m_iTime; - int m_iDefaultOption; - -// Dialog Data - //{{AFX_DATA(CDstFileErrorDlg) - enum { IDD = IDD_FEEDBACK_DSTFILE_DIALOG }; - CString m_strMessage; - CString m_strFilename; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CDstFileErrorDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(CDstFileErrorDlg) - afx_msg void OnRetryButton(); - afx_msg void OnIgnoreButton(); - afx_msg void OnWaitButton(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - virtual BOOL OnInitDialog(); - afx_msg void OnIgnoreAllButton(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __DSTFILEERRORDLG_H__ +#define __DSTFILEERRORDLG_H__ + +///////////////////////////////////////////////////////////////////////////// +// CDstFileErrorDlg dialog + +class CDstFileErrorDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CDstFileErrorDlg(); // standard constructor + + CString m_strTitle; + bool m_bEnableTimer; + int m_iTime; + int m_iDefaultOption; + +// Dialog Data + //{{AFX_DATA(CDstFileErrorDlg) + enum { IDD = IDD_FEEDBACK_DSTFILE_DIALOG }; + CString m_strMessage; + CString m_strFilename; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CDstFileErrorDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CDstFileErrorDlg) + afx_msg void OnRetryButton(); + afx_msg void OnIgnoreButton(); + afx_msg void OnWaitButton(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + virtual BOOL OnInitDialog(); + afx_msg void OnIgnoreAllButton(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/ExceptionEx.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ExceptionEx.h (.../ExceptionEx.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ExceptionEx.h (.../ExceptionEx.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,219 +1,219 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/************************************************************************* - File: Exception.h - Version: 1.0 - Author: Ixen Gerthannes (ixen@interia.pl) - File description: - Contain CException class - a base for any other exception - types. - Classes: - CException - - provides basic exception functionality. - - when used with MFC class name is CExceptionEx (it's - not based on MFC CException!). -*************************************************************************/ -#ifndef __EXCEPTION_H__ -#define __EXCEPTION_H__ - -#include "stdio.h" - -#define THROW_EXCEPTIONEX(str_reason, app_code, last_error) throw new CExceptionEx(__FILE__, __LINE__, __FUNCTION__, str_reason, app_code, last_error) - -// not too specific - use specialised classes based on this one (this also could be used) -class CExceptionEx -{ -protected: - enum PropType { dtString, dtPtrToString, dtDword, dtSysError }; - - struct __EXCPROPINFO - { - TCHAR szName[64]; // name of the property (ie."Source file") - PropType eType; // type of the property (string, dword, bool, ...) - void* pData; // pointer to the value of the property - }; - -public: - CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, PCTSTR pszReason, DWORD dwReason, DWORD dwLastError=0) - { - // init the object with a given values - _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); - m_szSourceFile[_MAX_PATH-1]=_T('\0'); - m_dwSourceLine=dwLine; - _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); - m_szFunction[_MAX_PATH-1]=_T('\0'); - SetReason(pszReason); - m_dwReason=dwReason; - m_dwError=dwLastError; - }; - CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, TCHAR* pszReason, DWORD dwReason, DWORD dwLastError=0) - { - _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); - m_szSourceFile[_MAX_PATH-1]=_T('\0'); - m_dwSourceLine=dwLine; - _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); - m_szFunction[_MAX_PATH-1]=_T('\0'); - m_pszReason=pszReason; - m_dwReason=dwReason; - m_dwError=dwLastError; - }; - - virtual ~CExceptionEx() { delete [] m_pszReason; }; - - virtual int RegisterInfo(__EXCPROPINFO* pInfo) - { - // if the pInfo is null - return count of a needed props - if (pInfo == NULL) - return 6; // +baseClass::RegisterInfo - - // call base class RegisterInfo - - // function has to register the info to be displayed (called from within GetInfo) - RegisterProp(pInfo+0, _T("Source file"), dtString, &m_szSourceFile); - RegisterProp(pInfo+1, _T("Line"), dtDword, &m_dwSourceLine); - RegisterProp(pInfo+2, _T("Function"), dtString, &m_szFunction); - RegisterProp(pInfo+3, _T("Reason"), dtPtrToString, &m_pszReason); - RegisterProp(pInfo+4, _T("App error"), dtDword, &m_dwReason); - RegisterProp(pInfo+5, _T("System error"), dtSysError, &m_dwError); - - return 6; - }; - -public: - // helpers - static TCHAR* FormatReason(PCTSTR pszReason, ...) - { - const size_t stMaxReason = 1024; - TCHAR szBuf[stMaxReason]; - - va_list marker; - va_start(marker, pszReason); - _vsntprintf(szBuf, stMaxReason - 1, pszReason, marker); - szBuf[stMaxReason - 1] = _T('\0'); - va_end(marker); - - TCHAR *pszData=new TCHAR[_tcslen(szBuf)+1]; - _tcscpy(pszData, szBuf); - return pszData; - }; - - // formats max info about this exception - virtual TCHAR* GetInfo(LPCTSTR pszDesc, TCHAR* pszStr, DWORD dwMaxLen) - { - const size_t stMaxData = 1024; - - // get the properties - int iCount=RegisterInfo(NULL); - __EXCPROPINFO *pepi=new __EXCPROPINFO[iCount]; - RegisterInfo(pepi); // register all the properties - - // add the desc to the out - if (pszDesc) - { - _tcsncpy(pszStr, pszDesc, dwMaxLen-1); - pszStr[dwMaxLen-1]=_T('\0'); - } - else - pszStr[0]=_T('\0'); - - size_t tIndex=_tcslen(pszStr); - - // format the info accordingly - TCHAR szData[stMaxData]; - for (int i=0;iszName, pszName, 63); - pInfo->szName[63]=_T('\0'); - pInfo->eType=type; - pInfo->pData=pData; - }; - -public: - // exception information - TCHAR m_szSourceFile[_MAX_PATH]; // source file from where the exception is being thrown - DWORD m_dwSourceLine; // line in the source file from where exception has been thrown - TCHAR m_szFunction[_MAX_PATH]; // name of the function in which the exception occured - TCHAR *m_pszReason; // description of this error (in english - internal error code - description - human readable) - DWORD m_dwReason; // numerical value that states app-level error number - DWORD m_dwError; // in most cases GetLastError() when it has any sense -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +/************************************************************************* + File: Exception.h + Version: 1.0 + Author: Ixen Gerthannes (ixen@interia.pl) + File description: + Contain CException class - a base for any other exception + types. + Classes: + CException + - provides basic exception functionality. + - when used with MFC class name is CExceptionEx (it's + not based on MFC CException!). +*************************************************************************/ +#ifndef __EXCEPTION_H__ +#define __EXCEPTION_H__ + +#include "stdio.h" + +#define THROW_EXCEPTIONEX(str_reason, app_code, last_error) throw new CExceptionEx(__FILE__, __LINE__, __FUNCTION__, str_reason, app_code, last_error) + +// not too specific - use specialised classes based on this one (this also could be used) +class CExceptionEx +{ +protected: + enum PropType { dtString, dtPtrToString, dtDword, dtSysError }; + + struct __EXCPROPINFO + { + TCHAR szName[64]; // name of the property (ie."Source file") + PropType eType; // type of the property (string, dword, bool, ...) + void* pData; // pointer to the value of the property + }; + +public: + CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, PCTSTR pszReason, DWORD dwReason, DWORD dwLastError=0) + { + // init the object with a given values + _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); + m_szSourceFile[_MAX_PATH-1]=_T('\0'); + m_dwSourceLine=dwLine; + _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); + m_szFunction[_MAX_PATH-1]=_T('\0'); + SetReason(pszReason); + m_dwReason=dwReason; + m_dwError=dwLastError; + }; + CExceptionEx(PCTSTR pszSrcFile, DWORD dwLine, PCTSTR pszFunc, TCHAR* pszReason, DWORD dwReason, DWORD dwLastError=0) + { + _tcsncpy(m_szSourceFile, pszSrcFile, _MAX_PATH); + m_szSourceFile[_MAX_PATH-1]=_T('\0'); + m_dwSourceLine=dwLine; + _tcsncpy(m_szFunction, pszFunc, _MAX_PATH); + m_szFunction[_MAX_PATH-1]=_T('\0'); + m_pszReason=pszReason; + m_dwReason=dwReason; + m_dwError=dwLastError; + }; + + virtual ~CExceptionEx() { delete [] m_pszReason; }; + + virtual int RegisterInfo(__EXCPROPINFO* pInfo) + { + // if the pInfo is null - return count of a needed props + if (pInfo == NULL) + return 6; // +baseClass::RegisterInfo + + // call base class RegisterInfo + + // function has to register the info to be displayed (called from within GetInfo) + RegisterProp(pInfo+0, _T("Source file"), dtString, &m_szSourceFile); + RegisterProp(pInfo+1, _T("Line"), dtDword, &m_dwSourceLine); + RegisterProp(pInfo+2, _T("Function"), dtString, &m_szFunction); + RegisterProp(pInfo+3, _T("Reason"), dtPtrToString, &m_pszReason); + RegisterProp(pInfo+4, _T("App error"), dtDword, &m_dwReason); + RegisterProp(pInfo+5, _T("System error"), dtSysError, &m_dwError); + + return 6; + }; + +public: + // helpers + static TCHAR* FormatReason(PCTSTR pszReason, ...) + { + const size_t stMaxReason = 1024; + TCHAR szBuf[stMaxReason]; + + va_list marker; + va_start(marker, pszReason); + _vsntprintf(szBuf, stMaxReason - 1, pszReason, marker); + szBuf[stMaxReason - 1] = _T('\0'); + va_end(marker); + + TCHAR *pszData=new TCHAR[_tcslen(szBuf)+1]; + _tcscpy(pszData, szBuf); + return pszData; + }; + + // formats max info about this exception + virtual TCHAR* GetInfo(LPCTSTR pszDesc, TCHAR* pszStr, DWORD dwMaxLen) + { + const size_t stMaxData = 1024; + + // get the properties + int iCount=RegisterInfo(NULL); + __EXCPROPINFO *pepi=new __EXCPROPINFO[iCount]; + RegisterInfo(pepi); // register all the properties + + // add the desc to the out + if (pszDesc) + { + _tcsncpy(pszStr, pszDesc, dwMaxLen-1); + pszStr[dwMaxLen-1]=_T('\0'); + } + else + pszStr[0]=_T('\0'); + + size_t tIndex=_tcslen(pszStr); + + // format the info accordingly + TCHAR szData[stMaxData]; + for (int i=0;iszName, pszName, 63); + pInfo->szName[63]=_T('\0'); + pInfo->eType=type; + pInfo->pData=pData; + }; + +public: + // exception information + TCHAR m_szSourceFile[_MAX_PATH]; // source file from where the exception is being thrown + DWORD m_dwSourceLine; // line in the source file from where exception has been thrown + TCHAR m_szFunction[_MAX_PATH]; // name of the function in which the exception occured + TCHAR *m_pszReason; // description of this error (in english - internal error code - description - human readable) + DWORD m_dwReason; // numerical value that states app-level error number + DWORD m_dwError; // in most cases GetLastError() when it has any sense +}; + #endif \ No newline at end of file Index: src/ch/FFListCtrl.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FFListCtrl.cpp (.../FFListCtrl.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/FFListCtrl.cpp (.../FFListCtrl.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,104 +1,104 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "FFListCtrl.h" -#include "MemDC.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CFFListCtrl - -CFFListCtrl::CFFListCtrl() -{ -} - -CFFListCtrl::~CFFListCtrl() -{ -} - - -BEGIN_MESSAGE_MAP(CFFListCtrl, CListCtrl) - //{{AFX_MSG_MAP(CFFListCtrl) - ON_WM_ERASEBKGND() - ON_WM_PAINT() - ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnItemchanged) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CFFListCtrl message handlers - -BOOL CFFListCtrl::OnEraseBkgnd(CDC*) -{ - return FALSE;/*CListCtrl::OnEraseBkgnd(pDC);*/ -} - -void CFFListCtrl::OnPaint() -{ - CPaintDC dc(this); // device context for painting - - CRect headerRect; - GetHeaderCtrl()->GetWindowRect(&headerRect); - ScreenToClient(&headerRect); - dc.ExcludeClipRect(&headerRect); - - CRect rect; - GetClientRect(&rect); - CMemDC memDC(&dc, rect); - - CRect clip; - memDC.GetClipBox(&clip); - memDC.FillSolidRect(clip, GetSysColor(COLOR_WINDOW)); - - DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, (LPARAM)0); -} - -void CFFListCtrl::LimitItems(int iLimit) -{ - if (GetItemCount() > iLimit) - { - while (GetItemCount() > iLimit) - DeleteItem(iLimit); - } -} - -void CFFListCtrl::OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; - - if ( /*((pNMListView->uOldState & LVIS_SELECTED) && !(pNMListView->uNewState & LVIS_SELECTED)) - ||*/ (!(pNMListView->uOldState & LVIS_SELECTED) && (pNMListView->uNewState & LVIS_SELECTED)) ) - SendSelChangedToParent(); - - *pResult = 0; -} - -void CFFListCtrl::SendSelChangedToParent() -{ - NMHDR nmhdr; - nmhdr.hwndFrom=m_hWnd; - nmhdr.idFrom=GetDlgCtrlID(); - nmhdr.code=LVN_CHANGEDSELECTION; - GetParent()->SendMessage(WM_NOTIFY, static_cast(nmhdr.idFrom), reinterpret_cast(&nmhdr)); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "FFListCtrl.h" +#include "MemDC.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CFFListCtrl + +CFFListCtrl::CFFListCtrl() +{ +} + +CFFListCtrl::~CFFListCtrl() +{ +} + + +BEGIN_MESSAGE_MAP(CFFListCtrl, CListCtrl) + //{{AFX_MSG_MAP(CFFListCtrl) + ON_WM_ERASEBKGND() + ON_WM_PAINT() + ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnItemchanged) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CFFListCtrl message handlers + +BOOL CFFListCtrl::OnEraseBkgnd(CDC*) +{ + return FALSE;/*CListCtrl::OnEraseBkgnd(pDC);*/ +} + +void CFFListCtrl::OnPaint() +{ + CPaintDC dc(this); // device context for painting + + CRect headerRect; + GetHeaderCtrl()->GetWindowRect(&headerRect); + ScreenToClient(&headerRect); + dc.ExcludeClipRect(&headerRect); + + CRect rect; + GetClientRect(&rect); + CMemDC memDC(&dc, rect); + + CRect clip; + memDC.GetClipBox(&clip); + memDC.FillSolidRect(clip, GetSysColor(COLOR_WINDOW)); + + DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, (LPARAM)0); +} + +void CFFListCtrl::LimitItems(int iLimit) +{ + if (GetItemCount() > iLimit) + { + while (GetItemCount() > iLimit) + DeleteItem(iLimit); + } +} + +void CFFListCtrl::OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; + + if ( /*((pNMListView->uOldState & LVIS_SELECTED) && !(pNMListView->uNewState & LVIS_SELECTED)) + ||*/ (!(pNMListView->uOldState & LVIS_SELECTED) && (pNMListView->uNewState & LVIS_SELECTED)) ) + SendSelChangedToParent(); + + *pResult = 0; +} + +void CFFListCtrl::SendSelChangedToParent() +{ + NMHDR nmhdr; + nmhdr.hwndFrom=m_hWnd; + nmhdr.idFrom=GetDlgCtrlID(); + nmhdr.code=LVN_CHANGEDSELECTION; + GetParent()->SendMessage(WM_NOTIFY, static_cast(nmhdr.idFrom), reinterpret_cast(&nmhdr)); +} Index: src/ch/FFListCtrl.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FFListCtrl.h (.../FFListCtrl.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/FFListCtrl.h (.../FFListCtrl.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,65 +1,65 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __FFLISTCTRL_H__ -#define __FFLISTCTRL_H__ - -///////////////////////////////////////////////////////////////////////////// -// CFFListCtrl window -#define LVN_CHANGEDSELECTION WM_USER+10 - -class CFFListCtrl : public CListCtrl -{ -// Construction -public: - CFFListCtrl(); - -// Attributes -public: - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CFFListCtrl) - //}}AFX_VIRTUAL - -// Implementation -public: - void SendSelChangedToParent(); - void LimitItems(int iLimit); - virtual ~CFFListCtrl(); - - // Generated message map functions -protected: - //{{AFX_MSG(CFFListCtrl) - afx_msg BOOL OnEraseBkgnd(CDC*); - afx_msg void OnPaint(); - afx_msg void OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult); - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __FFLISTCTRL_H__ +#define __FFLISTCTRL_H__ + +///////////////////////////////////////////////////////////////////////////// +// CFFListCtrl window +#define LVN_CHANGEDSELECTION WM_USER+10 + +class CFFListCtrl : public CListCtrl +{ +// Construction +public: + CFFListCtrl(); + +// Attributes +public: + +// Operations +public: + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CFFListCtrl) + //}}AFX_VIRTUAL + +// Implementation +public: + void SendSelChangedToParent(); + void LimitItems(int iLimit); + virtual ~CFFListCtrl(); + + // Generated message map functions +protected: + //{{AFX_MSG(CFFListCtrl) + afx_msg BOOL OnEraseBkgnd(CDC*); + afx_msg void OnPaint(); + afx_msg void OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult); + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() +}; + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/FeedbackFileErrorDlg.cpp =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackFileErrorDlg.cpp (.../FeedbackFileErrorDlg.cpp) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackFileErrorDlg.cpp (.../FeedbackFileErrorDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,94 +1,94 @@ -// FeedbackOpenFileErrorDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "ch.h" -#include "FeedbackFileErrorDlg.h" -#include "FeedbackHandler.h" - -// CFeedbackFileErrorDlg dialog - -IMPLEMENT_DYNAMIC(CFeedbackFileErrorDlg, ictranslate::CLanguageDialog) - -CFeedbackFileErrorDlg::CFeedbackFileErrorDlg(const tchar_t* pszPath, ulong_t ulSysError, CWnd* pParent /*=NULL*/) - : ictranslate::CLanguageDialog(CFeedbackFileErrorDlg::IDD, pParent), - m_bAllItems(FALSE), - m_strPath(pszPath), - m_ulSysError(ulSysError) -{ - -} - -CFeedbackFileErrorDlg::~CFeedbackFileErrorDlg() -{ -} - -void CFeedbackFileErrorDlg::DoDataExchange(CDataExchange* pDX) -{ - ictranslate::CLanguageDialog::DoDataExchange(pDX); - DDX_Check(pDX, IDC_ALL_ITEMS_CHECK, m_bAllItems); - DDX_Control(pDX, IDC_INFO_STATIC, m_ctlErrorInfo); -} - - -BEGIN_MESSAGE_MAP(CFeedbackFileErrorDlg, ictranslate::CLanguageDialog) - ON_BN_CLICKED(IDC_RETRY_BUTTON, &CFeedbackFileErrorDlg::OnBnClickedRetryButton) - ON_BN_CLICKED(IDC_SKIP_BUTTON, &CFeedbackFileErrorDlg::OnBnClickedSkipButton) - ON_BN_CLICKED(IDC_PAUSE_BUTTON, &CFeedbackFileErrorDlg::OnBnClickedPauseButton) - ON_BN_CLICKED(IDCANCEL, &CFeedbackFileErrorDlg::OnBnClickedCancel) -END_MESSAGE_MAP() - - -// CFeedbackFileErrorDlg message handlers -BOOL CFeedbackFileErrorDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - ictranslate::CResourceManager* pResManager = GetResManager(); - BOOST_ASSERT(pResManager); - if(pResManager) - { - CString strFmt; - strFmt = pResManager->LoadString(IDS_INFO_FILE_STRING); - strFmt += _T("\r\n"); - strFmt += pResManager->LoadString(IDS_INFO_REASON_STRING); - - // get system error string - TCHAR szSystem[1024]; - DWORD dwPos=FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, m_ulSysError, 0, szSystem, 1023, NULL); - szSystem[1023] = _T('\0'); - - // get rid of \r\n at the end of szSystem - while(--dwPos && (szSystem[dwPos] == 0x0a || szSystem[dwPos] == 0x0d)) - szSystem[dwPos]=_T('\0'); - - ictranslate::CFormat fmt(strFmt); - fmt.SetParam(_t("%filename"), m_strPath); - fmt.SetParam(_t("%reason"), szSystem); - - m_ctlErrorInfo.SetWindowText(fmt); - } - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void CFeedbackFileErrorDlg::OnBnClickedRetryButton() -{ - EndDialog(CFeedbackHandler::eResult_Retry); -} - -void CFeedbackFileErrorDlg::OnBnClickedSkipButton() -{ - EndDialog(CFeedbackHandler::eResult_Skip); -} - -void CFeedbackFileErrorDlg::OnBnClickedPauseButton() -{ - EndDialog(CFeedbackHandler::eResult_Pause); -} - -void CFeedbackFileErrorDlg::OnBnClickedCancel() -{ - EndDialog(CFeedbackHandler::eResult_Cancel); -} +// FeedbackOpenFileErrorDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "ch.h" +#include "FeedbackFileErrorDlg.h" +#include "FeedbackHandler.h" + +// CFeedbackFileErrorDlg dialog + +IMPLEMENT_DYNAMIC(CFeedbackFileErrorDlg, ictranslate::CLanguageDialog) + +CFeedbackFileErrorDlg::CFeedbackFileErrorDlg(const tchar_t* pszPath, ulong_t ulSysError, CWnd* pParent /*=NULL*/) + : ictranslate::CLanguageDialog(CFeedbackFileErrorDlg::IDD, pParent), + m_bAllItems(FALSE), + m_strPath(pszPath), + m_ulSysError(ulSysError) +{ + +} + +CFeedbackFileErrorDlg::~CFeedbackFileErrorDlg() +{ +} + +void CFeedbackFileErrorDlg::DoDataExchange(CDataExchange* pDX) +{ + ictranslate::CLanguageDialog::DoDataExchange(pDX); + DDX_Check(pDX, IDC_ALL_ITEMS_CHECK, m_bAllItems); + DDX_Control(pDX, IDC_INFO_STATIC, m_ctlErrorInfo); +} + + +BEGIN_MESSAGE_MAP(CFeedbackFileErrorDlg, ictranslate::CLanguageDialog) + ON_BN_CLICKED(IDC_RETRY_BUTTON, &CFeedbackFileErrorDlg::OnBnClickedRetryButton) + ON_BN_CLICKED(IDC_SKIP_BUTTON, &CFeedbackFileErrorDlg::OnBnClickedSkipButton) + ON_BN_CLICKED(IDC_PAUSE_BUTTON, &CFeedbackFileErrorDlg::OnBnClickedPauseButton) + ON_BN_CLICKED(IDCANCEL, &CFeedbackFileErrorDlg::OnBnClickedCancel) +END_MESSAGE_MAP() + + +// CFeedbackFileErrorDlg message handlers +BOOL CFeedbackFileErrorDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + ictranslate::CResourceManager* pResManager = GetResManager(); + BOOST_ASSERT(pResManager); + if(pResManager) + { + CString strFmt; + strFmt = pResManager->LoadString(IDS_INFO_FILE_STRING); + strFmt += _T("\r\n"); + strFmt += pResManager->LoadString(IDS_INFO_REASON_STRING); + + // get system error string + TCHAR szSystem[1024]; + DWORD dwPos=FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, m_ulSysError, 0, szSystem, 1023, NULL); + szSystem[1023] = _T('\0'); + + // get rid of \r\n at the end of szSystem + while(--dwPos && (szSystem[dwPos] == 0x0a || szSystem[dwPos] == 0x0d)) + szSystem[dwPos]=_T('\0'); + + ictranslate::CFormat fmt(strFmt); + fmt.SetParam(_t("%filename"), m_strPath); + fmt.SetParam(_t("%reason"), szSystem); + + m_ctlErrorInfo.SetWindowText(fmt); + } + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void CFeedbackFileErrorDlg::OnBnClickedRetryButton() +{ + EndDialog(CFeedbackHandler::eResult_Retry); +} + +void CFeedbackFileErrorDlg::OnBnClickedSkipButton() +{ + EndDialog(CFeedbackHandler::eResult_Skip); +} + +void CFeedbackFileErrorDlg::OnBnClickedPauseButton() +{ + EndDialog(CFeedbackHandler::eResult_Pause); +} + +void CFeedbackFileErrorDlg::OnBnClickedCancel() +{ + EndDialog(CFeedbackHandler::eResult_Cancel); +} Index: src/ch/FeedbackFileErrorDlg.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackFileErrorDlg.h (.../FeedbackFileErrorDlg.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackFileErrorDlg.h (.../FeedbackFileErrorDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,52 +1,52 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef __FEEDBACKFILEERRORDLG_H__ -#define __FEEDBACKFILEERRORDLG_H__ -#include "afxwin.h" - -// CFeedbackFileErrorDlg dialog -class CFeedbackFileErrorDlg : public ictranslate::CLanguageDialog -{ - DECLARE_DYNAMIC(CFeedbackFileErrorDlg) - -public: - CFeedbackFileErrorDlg(const tchar_t* pszPath, ulong_t ulSysError, CWnd* pParent = NULL); // standard constructor - virtual ~CFeedbackFileErrorDlg(); - -// Dialog Data - enum { IDD = IDD_FEEDBACK_FILE_ERROR_DIALOG }; - - afx_msg void OnBnClickedRetryButton(); - afx_msg void OnBnClickedSkipButton(); - afx_msg void OnBnClickedPauseButton(); - afx_msg void OnBnClickedCancel(); - -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - - DECLARE_MESSAGE_MAP() -public: - BOOL m_bAllItems; - CStatic m_ctlErrorInfo; - CString m_strPath; - ulong_t m_ulSysError; - virtual BOOL OnInitDialog(); -}; - -#endif +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __FEEDBACKFILEERRORDLG_H__ +#define __FEEDBACKFILEERRORDLG_H__ +#include "afxwin.h" + +// CFeedbackFileErrorDlg dialog +class CFeedbackFileErrorDlg : public ictranslate::CLanguageDialog +{ + DECLARE_DYNAMIC(CFeedbackFileErrorDlg) + +public: + CFeedbackFileErrorDlg(const tchar_t* pszPath, ulong_t ulSysError, CWnd* pParent = NULL); // standard constructor + virtual ~CFeedbackFileErrorDlg(); + +// Dialog Data + enum { IDD = IDD_FEEDBACK_FILE_ERROR_DIALOG }; + + afx_msg void OnBnClickedRetryButton(); + afx_msg void OnBnClickedSkipButton(); + afx_msg void OnBnClickedPauseButton(); + afx_msg void OnBnClickedCancel(); + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + DECLARE_MESSAGE_MAP() +public: + BOOL m_bAllItems; + CStatic m_ctlErrorInfo; + CString m_strPath; + ulong_t m_ulSysError; + virtual BOOL OnInitDialog(); +}; + +#endif Index: src/ch/FeedbackHandler.cpp =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackHandler.cpp (.../FeedbackHandler.cpp) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackHandler.cpp (.../FeedbackHandler.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,108 +1,108 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#include "stdafx.h" -#include "FeedbackHandler.h" -#include "FeedbackReplaceDlg.h" -#include "FeedbackFileErrorDlg.h" -#include "FeedbackNotEnoughSpaceDlg.h" - -CFeedbackHandler::CFeedbackHandler() : - chcore::IFeedbackHandler() -{ - memset(m_aeFeedbackTypeStatus, 0, sizeof(m_aeFeedbackTypeStatus)); -} - -CFeedbackHandler::~CFeedbackHandler() -{ - -} - -ull_t CFeedbackHandler::RequestFeedback(ull_t ullFeedbackID, ptr_t pFeedbackParam) -{ - BOOST_ASSERT(pFeedbackParam && ullFeedbackID < eFT_LastType); - if(!pFeedbackParam || ullFeedbackID >= eFT_LastType) - return eResult_Unknown; - - // if we have an action selected for this type (e.g. by selecting 'use for all items') - if(m_aeFeedbackTypeStatus[ullFeedbackID] != eResult_Unknown) - return m_aeFeedbackTypeStatus[ullFeedbackID]; - - // standard processing of feedback - EFeedbackResult eFeedbackResult = eResult_Unknown; - BOOL bUseForAllItems = FALSE; - switch(ullFeedbackID) - { - case eFT_FileAlreadyExists: - { - FEEDBACK_ALREADYEXISTS* pData = (FEEDBACK_ALREADYEXISTS*)pFeedbackParam; - CFeedbackReplaceDlg dlg(pData->pfiSrc, pData->pfiDst); - eFeedbackResult = (EFeedbackResult)dlg.DoModal(); - bUseForAllItems = dlg.m_bAllItems; - - break; - } - case eFT_FileError: - { - FEEDBACK_FILEERROR* pData = (FEEDBACK_FILEERROR*)pFeedbackParam; - CFeedbackFileErrorDlg dlg(pData->pszPath, pData->ulError); - eFeedbackResult = (EFeedbackResult)dlg.DoModal(); - bUseForAllItems = dlg.m_bAllItems; - - break; - } - case eFT_NotEnoughSpace: - { - FEEDBACK_NOTENOUGHSPACE* pData = (FEEDBACK_NOTENOUGHSPACE*)pFeedbackParam; - CFeedbackNotEnoughSpaceDlg dlg(pData->ullRequiredSize, pData->pszSrcPath, pData->pszDstPath); - eFeedbackResult = (EFeedbackResult)dlg.DoModal(); - bUseForAllItems = dlg.m_bAllItems; - - break; - } - default: - BOOST_ASSERT(false); - return eResult_Unknown; - } - - // remember feedback option for next time - if(bUseForAllItems) - m_aeFeedbackTypeStatus[ullFeedbackID] = eFeedbackResult; - - return eFeedbackResult; -} - -void CFeedbackHandler::Delete() -{ - delete this; -} - -chcore::IFeedbackHandler* CFeedbackHandlerFactory::Create() -{ - return new CFeedbackHandler; -} - -chcore::IFeedbackHandlerFactory* CFeedbackHandlerFactory::CreateFactory() -{ - return new CFeedbackHandlerFactory; -} - -void CFeedbackHandlerFactory::Delete() -{ - delete this; -} +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "stdafx.h" +#include "FeedbackHandler.h" +#include "FeedbackReplaceDlg.h" +#include "FeedbackFileErrorDlg.h" +#include "FeedbackNotEnoughSpaceDlg.h" + +CFeedbackHandler::CFeedbackHandler() : + chcore::IFeedbackHandler() +{ + memset(m_aeFeedbackTypeStatus, 0, sizeof(m_aeFeedbackTypeStatus)); +} + +CFeedbackHandler::~CFeedbackHandler() +{ + +} + +ull_t CFeedbackHandler::RequestFeedback(ull_t ullFeedbackID, ptr_t pFeedbackParam) +{ + BOOST_ASSERT(pFeedbackParam && ullFeedbackID < eFT_LastType); + if(!pFeedbackParam || ullFeedbackID >= eFT_LastType) + return eResult_Unknown; + + // if we have an action selected for this type (e.g. by selecting 'use for all items') + if(m_aeFeedbackTypeStatus[ullFeedbackID] != eResult_Unknown) + return m_aeFeedbackTypeStatus[ullFeedbackID]; + + // standard processing of feedback + EFeedbackResult eFeedbackResult = eResult_Unknown; + BOOL bUseForAllItems = FALSE; + switch(ullFeedbackID) + { + case eFT_FileAlreadyExists: + { + FEEDBACK_ALREADYEXISTS* pData = (FEEDBACK_ALREADYEXISTS*)pFeedbackParam; + CFeedbackReplaceDlg dlg(pData->pfiSrc, pData->pfiDst); + eFeedbackResult = (EFeedbackResult)dlg.DoModal(); + bUseForAllItems = dlg.m_bAllItems; + + break; + } + case eFT_FileError: + { + FEEDBACK_FILEERROR* pData = (FEEDBACK_FILEERROR*)pFeedbackParam; + CFeedbackFileErrorDlg dlg(pData->pszPath, pData->ulError); + eFeedbackResult = (EFeedbackResult)dlg.DoModal(); + bUseForAllItems = dlg.m_bAllItems; + + break; + } + case eFT_NotEnoughSpace: + { + FEEDBACK_NOTENOUGHSPACE* pData = (FEEDBACK_NOTENOUGHSPACE*)pFeedbackParam; + CFeedbackNotEnoughSpaceDlg dlg(pData->ullRequiredSize, pData->pszSrcPath, pData->pszDstPath); + eFeedbackResult = (EFeedbackResult)dlg.DoModal(); + bUseForAllItems = dlg.m_bAllItems; + + break; + } + default: + BOOST_ASSERT(false); + return eResult_Unknown; + } + + // remember feedback option for next time + if(bUseForAllItems) + m_aeFeedbackTypeStatus[ullFeedbackID] = eFeedbackResult; + + return eFeedbackResult; +} + +void CFeedbackHandler::Delete() +{ + delete this; +} + +chcore::IFeedbackHandler* CFeedbackHandlerFactory::Create() +{ + return new CFeedbackHandler; +} + +chcore::IFeedbackHandlerFactory* CFeedbackHandlerFactory::CreateFactory() +{ + return new CFeedbackHandlerFactory; +} + +void CFeedbackHandlerFactory::Delete() +{ + delete this; +} Index: src/ch/FeedbackHandler.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackHandler.h (.../FeedbackHandler.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackHandler.h (.../FeedbackHandler.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,94 +1,94 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef __FEEDBACKHANDLER_H__ -#define __FEEDBACKHANDLER_H__ - -#include "../libchcore/FeedbackHandlerBase.h" -#include "FileInfo.h" - -struct FEEDBACK_ALREADYEXISTS -{ - CFileInfo* pfiSrc; - CFileInfo* pfiDst; -}; - -struct FEEDBACK_FILEERROR -{ - const tchar_t* pszPath; - ulong_t ulError; -}; - -struct FEEDBACK_NOTENOUGHSPACE -{ - ull_t ullRequiredSize; - const tchar_t* pszSrcPath; - const tchar_t* pszDstPath; -}; - -class CFeedbackHandler : public chcore::IFeedbackHandler -{ -public: - enum EFeedbackType - { - eFT_Unknown = 0, - eFT_FileAlreadyExists, - eFT_FileError, - eFT_NotEnoughSpace, - eFT_LastType - }; - - enum EFeedbackResult - { - eResult_Unknown = 0, - eResult_Overwrite, - eResult_CopyRest, - eResult_Skip, - eResult_Cancel, - eResult_Pause, - eResult_Retry - }; - -protected: - CFeedbackHandler(); - ~CFeedbackHandler(); - -public: - virtual ull_t RequestFeedback(ull_t ullFeedbackID, ptr_t pFeedbackParam); - virtual void Delete(); - -protected: - EFeedbackResult m_aeFeedbackTypeStatus[eFT_LastType]; - - friend class CFeedbackHandlerFactory; -}; - -class CFeedbackHandlerFactory : public chcore::IFeedbackHandlerFactory -{ -protected: - CFeedbackHandlerFactory() {} - ~CFeedbackHandlerFactory() {} - -public: - chcore::IFeedbackHandler* Create(); - virtual void Delete(); - - static IFeedbackHandlerFactory* CreateFactory(); -}; - -#endif +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __FEEDBACKHANDLER_H__ +#define __FEEDBACKHANDLER_H__ + +#include "../libchcore/FeedbackHandlerBase.h" +#include "FileInfo.h" + +struct FEEDBACK_ALREADYEXISTS +{ + CFileInfo* pfiSrc; + CFileInfo* pfiDst; +}; + +struct FEEDBACK_FILEERROR +{ + const tchar_t* pszPath; + ulong_t ulError; +}; + +struct FEEDBACK_NOTENOUGHSPACE +{ + ull_t ullRequiredSize; + const tchar_t* pszSrcPath; + const tchar_t* pszDstPath; +}; + +class CFeedbackHandler : public chcore::IFeedbackHandler +{ +public: + enum EFeedbackType + { + eFT_Unknown = 0, + eFT_FileAlreadyExists, + eFT_FileError, + eFT_NotEnoughSpace, + eFT_LastType + }; + + enum EFeedbackResult + { + eResult_Unknown = 0, + eResult_Overwrite, + eResult_CopyRest, + eResult_Skip, + eResult_Cancel, + eResult_Pause, + eResult_Retry + }; + +protected: + CFeedbackHandler(); + ~CFeedbackHandler(); + +public: + virtual ull_t RequestFeedback(ull_t ullFeedbackID, ptr_t pFeedbackParam); + virtual void Delete(); + +protected: + EFeedbackResult m_aeFeedbackTypeStatus[eFT_LastType]; + + friend class CFeedbackHandlerFactory; +}; + +class CFeedbackHandlerFactory : public chcore::IFeedbackHandlerFactory +{ +protected: + CFeedbackHandlerFactory() {} + ~CFeedbackHandlerFactory() {} + +public: + chcore::IFeedbackHandler* Create(); + virtual void Delete(); + + static IFeedbackHandlerFactory* CreateFactory(); +}; + +#endif Index: src/ch/FeedbackNotEnoughSpaceDlg.cpp =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackNotEnoughSpaceDlg.cpp (.../FeedbackNotEnoughSpaceDlg.cpp) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackNotEnoughSpaceDlg.cpp (.../FeedbackNotEnoughSpaceDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,149 +1,149 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "FeedbackNotEnoughSpaceDlg.h" -#include "btnIDs.h" -#include "StringHelpers.h" -#include "..\Common\FileSupport.h" -#include "FeedbackHandler.h" -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CFeedbackNotEnoughSpaceDlg dialog - - -CFeedbackNotEnoughSpaceDlg::CFeedbackNotEnoughSpaceDlg(ull_t ullSizeRequired, const tchar_t* pszSrcPath, const tchar_t* pszDstPath) - :ictranslate::CLanguageDialog(CFeedbackNotEnoughSpaceDlg::IDD), - m_bAllItems(FALSE), - m_ullRequired(ullSizeRequired), - m_strDisk(pszDstPath) -{ - m_vstrFiles.push_back(pszSrcPath); -} - - -void CFeedbackNotEnoughSpaceDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CFeedbackNotEnoughSpaceDlg) - DDX_Control(pDX, IDC_FILES_LIST, m_ctlFiles); - //}}AFX_DATA_MAP - DDX_Check(pDX, IDC_ALL_ITEMS_CHECK, m_bAllItems); -} - - -BEGIN_MESSAGE_MAP(CFeedbackNotEnoughSpaceDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CFeedbackNotEnoughSpaceDlg) - ON_WM_TIMER() - ON_BN_CLICKED(IDC_RETRY_BUTTON, OnRetryButton) - ON_BN_CLICKED(IDC_IGNORE_BUTTON, OnIgnoreButton) - //}}AFX_MSG_MAP - ON_BN_CLICKED(IDCANCEL, &CFeedbackNotEnoughSpaceDlg::OnBnClickedCancel) -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CFeedbackNotEnoughSpaceDlg message handlers -void CFeedbackNotEnoughSpaceDlg::UpdateDialog() -{ - // format needed text - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_NERPATH_STRING)); - fmt.SetParam(_t("%path"), m_strDisk); - - CWnd* pWnd=GetDlgItem(IDC_HEADER_STATIC); - if (pWnd) - pWnd->SetWindowText(fmt); - - // now the sizes - TCHAR szData[128]; - pWnd=GetDlgItem(IDC_REQUIRED_STATIC); - if (pWnd) - pWnd->SetWindowText(GetSizeString(m_ullRequired, szData, 128)); - ull_t ullFree; - pWnd=GetDlgItem(IDC_AVAILABLE_STATIC); - if (pWnd && GetDynamicFreeSpace(m_strDisk, &ullFree, NULL)) - pWnd->SetWindowText(GetSizeString(ullFree, szData, 128)); -} - -BOOL CFeedbackNotEnoughSpaceDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // set to top - SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); - - // needed data - for (size_t i=0;iSetWindowText(GetSizeString(ullFree, szData, 128)); - - // end dialog if this is enough - if (m_ullRequired <= ullFree) - { - CLanguageDialog::OnTimer(nIDEvent); - EndDialog(ID_RETRY); - } - } - } - - CLanguageDialog::OnTimer(nIDEvent); -} - -void CFeedbackNotEnoughSpaceDlg::OnRetryButton() -{ - EndDialog(CFeedbackHandler::eResult_Retry); -} - -void CFeedbackNotEnoughSpaceDlg::OnIgnoreButton() -{ - EndDialog(CFeedbackHandler::eResult_Skip); -} - -void CFeedbackNotEnoughSpaceDlg::OnLanguageChanged() -{ - UpdateDialog(); -} - -void CFeedbackNotEnoughSpaceDlg::OnBnClickedCancel() -{ - EndDialog(CFeedbackHandler::eResult_Cancel); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "FeedbackNotEnoughSpaceDlg.h" +#include "btnIDs.h" +#include "StringHelpers.h" +#include "..\Common\FileSupport.h" +#include "FeedbackHandler.h" +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CFeedbackNotEnoughSpaceDlg dialog + + +CFeedbackNotEnoughSpaceDlg::CFeedbackNotEnoughSpaceDlg(ull_t ullSizeRequired, const tchar_t* pszSrcPath, const tchar_t* pszDstPath) + :ictranslate::CLanguageDialog(CFeedbackNotEnoughSpaceDlg::IDD), + m_bAllItems(FALSE), + m_ullRequired(ullSizeRequired), + m_strDisk(pszDstPath) +{ + m_vstrFiles.push_back(pszSrcPath); +} + + +void CFeedbackNotEnoughSpaceDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CFeedbackNotEnoughSpaceDlg) + DDX_Control(pDX, IDC_FILES_LIST, m_ctlFiles); + //}}AFX_DATA_MAP + DDX_Check(pDX, IDC_ALL_ITEMS_CHECK, m_bAllItems); +} + + +BEGIN_MESSAGE_MAP(CFeedbackNotEnoughSpaceDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CFeedbackNotEnoughSpaceDlg) + ON_WM_TIMER() + ON_BN_CLICKED(IDC_RETRY_BUTTON, OnRetryButton) + ON_BN_CLICKED(IDC_IGNORE_BUTTON, OnIgnoreButton) + //}}AFX_MSG_MAP + ON_BN_CLICKED(IDCANCEL, &CFeedbackNotEnoughSpaceDlg::OnBnClickedCancel) +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CFeedbackNotEnoughSpaceDlg message handlers +void CFeedbackNotEnoughSpaceDlg::UpdateDialog() +{ + // format needed text + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_NERPATH_STRING)); + fmt.SetParam(_t("%path"), m_strDisk); + + CWnd* pWnd=GetDlgItem(IDC_HEADER_STATIC); + if (pWnd) + pWnd->SetWindowText(fmt); + + // now the sizes + TCHAR szData[128]; + pWnd=GetDlgItem(IDC_REQUIRED_STATIC); + if (pWnd) + pWnd->SetWindowText(GetSizeString(m_ullRequired, szData, 128)); + ull_t ullFree; + pWnd=GetDlgItem(IDC_AVAILABLE_STATIC); + if (pWnd && GetDynamicFreeSpace(m_strDisk, &ullFree, NULL)) + pWnd->SetWindowText(GetSizeString(ullFree, szData, 128)); +} + +BOOL CFeedbackNotEnoughSpaceDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // set to top + SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); + + // needed data + for (size_t i=0;iSetWindowText(GetSizeString(ullFree, szData, 128)); + + // end dialog if this is enough + if (m_ullRequired <= ullFree) + { + CLanguageDialog::OnTimer(nIDEvent); + EndDialog(ID_RETRY); + } + } + } + + CLanguageDialog::OnTimer(nIDEvent); +} + +void CFeedbackNotEnoughSpaceDlg::OnRetryButton() +{ + EndDialog(CFeedbackHandler::eResult_Retry); +} + +void CFeedbackNotEnoughSpaceDlg::OnIgnoreButton() +{ + EndDialog(CFeedbackHandler::eResult_Skip); +} + +void CFeedbackNotEnoughSpaceDlg::OnLanguageChanged() +{ + UpdateDialog(); +} + +void CFeedbackNotEnoughSpaceDlg::OnBnClickedCancel() +{ + EndDialog(CFeedbackHandler::eResult_Cancel); +} Index: src/ch/FeedbackNotEnoughSpaceDlg.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackNotEnoughSpaceDlg.h (.../FeedbackNotEnoughSpaceDlg.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackNotEnoughSpaceDlg.h (.../FeedbackNotEnoughSpaceDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,62 +1,62 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __FEEDBACKNOTENOUGHSPACEDLG_H__ -#define __FEEDBACKNOTENOUGHSPACEDLG_H__ - -///////////////////////////////////////////////////////////////////////////// -// CFeedbackNotEnoughSpaceDlg dialog - -class CFeedbackNotEnoughSpaceDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CFeedbackNotEnoughSpaceDlg(ull_t ullSizeRequired, const tchar_t* pszSrcPath, const tchar_t* pszDstPath); // standard constructor - -// Dialog Data - //{{AFX_DATA(CFeedbackNotEnoughSpaceDlg) - enum { IDD = IDD_FEEDBACK_NOTENOUGHSPACE_DIALOG }; - CListBox m_ctlFiles; - //}}AFX_DATA - -// Overrides -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - -// Implementation -public: - CString m_strDisk; - ull_t m_ullRequired; - std::vector m_vstrFiles; - -protected: - void UpdateDialog(); - virtual void OnLanguageChanged(); - - virtual BOOL OnInitDialog(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - afx_msg void OnRetryButton(); - afx_msg void OnIgnoreButton(); - - DECLARE_MESSAGE_MAP() -public: - BOOL m_bAllItems; - afx_msg void OnBnClickedCancel(); -}; - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __FEEDBACKNOTENOUGHSPACEDLG_H__ +#define __FEEDBACKNOTENOUGHSPACEDLG_H__ + +///////////////////////////////////////////////////////////////////////////// +// CFeedbackNotEnoughSpaceDlg dialog + +class CFeedbackNotEnoughSpaceDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CFeedbackNotEnoughSpaceDlg(ull_t ullSizeRequired, const tchar_t* pszSrcPath, const tchar_t* pszDstPath); // standard constructor + +// Dialog Data + //{{AFX_DATA(CFeedbackNotEnoughSpaceDlg) + enum { IDD = IDD_FEEDBACK_NOTENOUGHSPACE_DIALOG }; + CListBox m_ctlFiles; + //}}AFX_DATA + +// Overrides +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + +// Implementation +public: + CString m_strDisk; + ull_t m_ullRequired; + std::vector m_vstrFiles; + +protected: + void UpdateDialog(); + virtual void OnLanguageChanged(); + + virtual BOOL OnInitDialog(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + afx_msg void OnRetryButton(); + afx_msg void OnIgnoreButton(); + + DECLARE_MESSAGE_MAP() +public: + BOOL m_bAllItems; + afx_msg void OnBnClickedCancel(); +}; + +#endif Index: src/ch/FeedbackReplaceDlg.cpp =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackReplaceDlg.cpp (.../FeedbackReplaceDlg.cpp) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackReplaceDlg.cpp (.../FeedbackReplaceDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,135 +1,135 @@ -// FeedbackReplaceDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "ch.h" -#include "FeedbackReplaceDlg.h" -#include "../libictranslate/ResourceManager.h" -#include "FileInfo.h" -#include "FeedbackHandler.h" - -// CFeedbackReplaceDlg dialog - -IMPLEMENT_DYNAMIC(CFeedbackReplaceDlg, ictranslate::CLanguageDialog) - -CFeedbackReplaceDlg::CFeedbackReplaceDlg(const CFileInfo* pfiSrcFile, const CFileInfo* pfiDstFile, CWnd* pParent /*=NULL*/) - : ictranslate::CLanguageDialog(CFeedbackReplaceDlg::IDD, pParent), - m_pfiSrcFile(pfiSrcFile), - m_pfiDstFile(pfiDstFile) - , m_bAllItems(FALSE) -{ - -} - -CFeedbackReplaceDlg::~CFeedbackReplaceDlg() -{ -} - -void CFeedbackReplaceDlg::DoDataExchange(CDataExchange* pDX) -{ - ictranslate::CLanguageDialog::DoDataExchange(pDX); - DDX_Control(pDX, IDC_SRC_ICON_STATIC, m_ctlSrcIcon); - DDX_Control(pDX, IDC_DST_ICON_STATIC, m_ctlDstIcon); - DDX_Control(pDX, IDC_SRC_INFO_STATIC, m_ctlSrcInfo); - DDX_Control(pDX, IDC_DST_INFO_STATIC, m_ctlDstInfo); - DDX_Check(pDX, IDC_ALL_ITEMS_CHECK, m_bAllItems); -} - - -BEGIN_MESSAGE_MAP(CFeedbackReplaceDlg, ictranslate::CLanguageDialog) - ON_BN_CLICKED(IDC_REPLACE_BUTTON, &CFeedbackReplaceDlg::OnBnClickedReplaceButton) - ON_BN_CLICKED(IDC_COPY_REST_BUTTON, &CFeedbackReplaceDlg::OnBnClickedCopyRestButton) - ON_BN_CLICKED(IDC_SKIP_BUTTON, &CFeedbackReplaceDlg::OnBnClickedSkipButton) - ON_BN_CLICKED(IDC_PAUSE_BUTTON, &CFeedbackReplaceDlg::OnBnClickedPauseButton) - ON_BN_CLICKED(IDC_CANCEL_BUTTON, &CFeedbackReplaceDlg::OnBnClickedCancelButton) -END_MESSAGE_MAP() - - -// CFeedbackReplaceDlg message handlers - -BOOL CFeedbackReplaceDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // load the informations about files - RefreshFilesInfo(); - RefreshImages(); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void CFeedbackReplaceDlg::RefreshFilesInfo() -{ - BOOST_ASSERT(m_pfiSrcFile && m_pfiDstFile); - if(!m_pfiSrcFile || !m_pfiDstFile) - return; - - // load template - ictranslate::CResourceManager* pManager = GetResManager(); - BOOST_ASSERT(pManager); - if(!pManager) - return; - - CString strTemplate; - strTemplate += pManager->LoadString(IDS_INFO_FILE_STRING); - strTemplate += _T("\r\n"); - strTemplate += pManager->LoadString(IDS_INFO_SIZE_STRING); - strTemplate += _T("\r\n"); - strTemplate += pManager->LoadString(IDS_INFO_MODIFIED_STRING); - - ictranslate::CFormat fmt(strTemplate); - fmt.SetParam(_T("%filename"), m_pfiSrcFile->GetFullFilePath()); - fmt.SetParam(_T("%size"), m_pfiSrcFile->GetLength64()); - fmt.SetParam(_T("%datemod"), m_pfiSrcFile->GetLastWriteTime().Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT)); - - m_ctlSrcInfo.SetWindowText(fmt); - - fmt.SetFormat(strTemplate); - fmt.SetParam(_T("%filename"), m_pfiDstFile->GetFullFilePath()); - fmt.SetParam(_T("%size"), m_pfiDstFile->GetLength64()); - fmt.SetParam(_T("%datemod"), m_pfiDstFile->GetLastWriteTime().Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT)); - - m_ctlDstInfo.SetWindowText(fmt); -} - -void CFeedbackReplaceDlg::RefreshImages() -{ - BOOST_ASSERT(m_pfiSrcFile && m_pfiDstFile); - if(!m_pfiSrcFile || !m_pfiDstFile) - return; - - SHFILEINFO shfi; - DWORD_PTR dwRes = SHGetFileInfo(m_pfiSrcFile->GetFullFilePath(), 0, &shfi, sizeof(shfi), SHGFI_ICON); - if(dwRes) - m_ctlSrcIcon.SetIcon(shfi.hIcon); - - dwRes = SHGetFileInfo(m_pfiDstFile->GetFullFilePath(), 0, &shfi, sizeof(shfi), SHGFI_ICON); - if(dwRes) - m_ctlDstIcon.SetIcon(shfi.hIcon); -} - -void CFeedbackReplaceDlg::OnBnClickedReplaceButton() -{ - EndDialog(CFeedbackHandler::eResult_Overwrite); -} - -void CFeedbackReplaceDlg::OnBnClickedCopyRestButton() -{ - EndDialog(CFeedbackHandler::eResult_CopyRest); -} - -void CFeedbackReplaceDlg::OnBnClickedSkipButton() -{ - EndDialog(CFeedbackHandler::eResult_Skip); -} - -void CFeedbackReplaceDlg::OnBnClickedPauseButton() -{ - EndDialog(CFeedbackHandler::eResult_Pause); -} - -void CFeedbackReplaceDlg::OnBnClickedCancelButton() -{ - EndDialog(CFeedbackHandler::eResult_Cancel); -} +// FeedbackReplaceDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "ch.h" +#include "FeedbackReplaceDlg.h" +#include "../libictranslate/ResourceManager.h" +#include "FileInfo.h" +#include "FeedbackHandler.h" + +// CFeedbackReplaceDlg dialog + +IMPLEMENT_DYNAMIC(CFeedbackReplaceDlg, ictranslate::CLanguageDialog) + +CFeedbackReplaceDlg::CFeedbackReplaceDlg(const CFileInfo* pfiSrcFile, const CFileInfo* pfiDstFile, CWnd* pParent /*=NULL*/) + : ictranslate::CLanguageDialog(CFeedbackReplaceDlg::IDD, pParent), + m_pfiSrcFile(pfiSrcFile), + m_pfiDstFile(pfiDstFile) + , m_bAllItems(FALSE) +{ + +} + +CFeedbackReplaceDlg::~CFeedbackReplaceDlg() +{ +} + +void CFeedbackReplaceDlg::DoDataExchange(CDataExchange* pDX) +{ + ictranslate::CLanguageDialog::DoDataExchange(pDX); + DDX_Control(pDX, IDC_SRC_ICON_STATIC, m_ctlSrcIcon); + DDX_Control(pDX, IDC_DST_ICON_STATIC, m_ctlDstIcon); + DDX_Control(pDX, IDC_SRC_INFO_STATIC, m_ctlSrcInfo); + DDX_Control(pDX, IDC_DST_INFO_STATIC, m_ctlDstInfo); + DDX_Check(pDX, IDC_ALL_ITEMS_CHECK, m_bAllItems); +} + + +BEGIN_MESSAGE_MAP(CFeedbackReplaceDlg, ictranslate::CLanguageDialog) + ON_BN_CLICKED(IDC_REPLACE_BUTTON, &CFeedbackReplaceDlg::OnBnClickedReplaceButton) + ON_BN_CLICKED(IDC_COPY_REST_BUTTON, &CFeedbackReplaceDlg::OnBnClickedCopyRestButton) + ON_BN_CLICKED(IDC_SKIP_BUTTON, &CFeedbackReplaceDlg::OnBnClickedSkipButton) + ON_BN_CLICKED(IDC_PAUSE_BUTTON, &CFeedbackReplaceDlg::OnBnClickedPauseButton) + ON_BN_CLICKED(IDC_CANCEL_BUTTON, &CFeedbackReplaceDlg::OnBnClickedCancelButton) +END_MESSAGE_MAP() + + +// CFeedbackReplaceDlg message handlers + +BOOL CFeedbackReplaceDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // load the informations about files + RefreshFilesInfo(); + RefreshImages(); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void CFeedbackReplaceDlg::RefreshFilesInfo() +{ + BOOST_ASSERT(m_pfiSrcFile && m_pfiDstFile); + if(!m_pfiSrcFile || !m_pfiDstFile) + return; + + // load template + ictranslate::CResourceManager* pManager = GetResManager(); + BOOST_ASSERT(pManager); + if(!pManager) + return; + + CString strTemplate; + strTemplate += pManager->LoadString(IDS_INFO_FILE_STRING); + strTemplate += _T("\r\n"); + strTemplate += pManager->LoadString(IDS_INFO_SIZE_STRING); + strTemplate += _T("\r\n"); + strTemplate += pManager->LoadString(IDS_INFO_MODIFIED_STRING); + + ictranslate::CFormat fmt(strTemplate); + fmt.SetParam(_T("%filename"), m_pfiSrcFile->GetFullFilePath()); + fmt.SetParam(_T("%size"), m_pfiSrcFile->GetLength64()); + fmt.SetParam(_T("%datemod"), m_pfiSrcFile->GetLastWriteTime().Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT)); + + m_ctlSrcInfo.SetWindowText(fmt); + + fmt.SetFormat(strTemplate); + fmt.SetParam(_T("%filename"), m_pfiDstFile->GetFullFilePath()); + fmt.SetParam(_T("%size"), m_pfiDstFile->GetLength64()); + fmt.SetParam(_T("%datemod"), m_pfiDstFile->GetLastWriteTime().Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT)); + + m_ctlDstInfo.SetWindowText(fmt); +} + +void CFeedbackReplaceDlg::RefreshImages() +{ + BOOST_ASSERT(m_pfiSrcFile && m_pfiDstFile); + if(!m_pfiSrcFile || !m_pfiDstFile) + return; + + SHFILEINFO shfi; + DWORD_PTR dwRes = SHGetFileInfo(m_pfiSrcFile->GetFullFilePath(), 0, &shfi, sizeof(shfi), SHGFI_ICON); + if(dwRes) + m_ctlSrcIcon.SetIcon(shfi.hIcon); + + dwRes = SHGetFileInfo(m_pfiDstFile->GetFullFilePath(), 0, &shfi, sizeof(shfi), SHGFI_ICON); + if(dwRes) + m_ctlDstIcon.SetIcon(shfi.hIcon); +} + +void CFeedbackReplaceDlg::OnBnClickedReplaceButton() +{ + EndDialog(CFeedbackHandler::eResult_Overwrite); +} + +void CFeedbackReplaceDlg::OnBnClickedCopyRestButton() +{ + EndDialog(CFeedbackHandler::eResult_CopyRest); +} + +void CFeedbackReplaceDlg::OnBnClickedSkipButton() +{ + EndDialog(CFeedbackHandler::eResult_Skip); +} + +void CFeedbackReplaceDlg::OnBnClickedPauseButton() +{ + EndDialog(CFeedbackHandler::eResult_Pause); +} + +void CFeedbackReplaceDlg::OnBnClickedCancelButton() +{ + EndDialog(CFeedbackHandler::eResult_Cancel); +} Index: src/ch/FeedbackReplaceDlg.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FeedbackReplaceDlg.h (.../FeedbackReplaceDlg.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/FeedbackReplaceDlg.h (.../FeedbackReplaceDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,64 +1,64 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef __FEEDBACKREPLACEDLG_H__ -#define __FEEDBACKREPLACEDLG_H__ - -#include "afxwin.h" -#include "resource.h" -class CFileInfo; - -class CFeedbackReplaceDlg : public ictranslate::CLanguageDialog -{ - DECLARE_DYNAMIC(CFeedbackReplaceDlg) -public: - // Dialog Data - enum { IDD = IDD_FEEDBACK_REPLACE_DIALOG }; - -public: - CFeedbackReplaceDlg(const CFileInfo* pfiSrcFile, const CFileInfo* pfiDstFile, CWnd* pParent = NULL); // standard constructor - virtual ~CFeedbackReplaceDlg(); - - virtual BOOL OnInitDialog(); - -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - - void RefreshFilesInfo(); - void RefreshImages(); - - DECLARE_MESSAGE_MAP() -public: - CStatic m_ctlSrcIcon; - CStatic m_ctlDstIcon; - CStatic m_ctlSrcInfo; - CStatic m_ctlDstInfo; - BOOL m_bAllItems; - -protected: - const CFileInfo* m_pfiSrcFile; - const CFileInfo* m_pfiDstFile; -public: - afx_msg void OnBnClickedReplaceButton(); - afx_msg void OnBnClickedCopyRestButton(); - afx_msg void OnBnClickedSkipButton(); - afx_msg void OnBnClickedPauseButton(); - afx_msg void OnBnClickedCancelButton(); -}; - -#endif +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __FEEDBACKREPLACEDLG_H__ +#define __FEEDBACKREPLACEDLG_H__ + +#include "afxwin.h" +#include "resource.h" +class CFileInfo; + +class CFeedbackReplaceDlg : public ictranslate::CLanguageDialog +{ + DECLARE_DYNAMIC(CFeedbackReplaceDlg) +public: + // Dialog Data + enum { IDD = IDD_FEEDBACK_REPLACE_DIALOG }; + +public: + CFeedbackReplaceDlg(const CFileInfo* pfiSrcFile, const CFileInfo* pfiDstFile, CWnd* pParent = NULL); // standard constructor + virtual ~CFeedbackReplaceDlg(); + + virtual BOOL OnInitDialog(); + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + void RefreshFilesInfo(); + void RefreshImages(); + + DECLARE_MESSAGE_MAP() +public: + CStatic m_ctlSrcIcon; + CStatic m_ctlDstIcon; + CStatic m_ctlSrcInfo; + CStatic m_ctlDstInfo; + BOOL m_bAllItems; + +protected: + const CFileInfo* m_pfiSrcFile; + const CFileInfo* m_pfiDstFile; +public: + afx_msg void OnBnClickedReplaceButton(); + afx_msg void OnBnClickedCopyRestButton(); + afx_msg void OnBnClickedSkipButton(); + afx_msg void OnBnClickedPauseButton(); + afx_msg void OnBnClickedCancelButton(); +}; + +#endif Index: src/ch/FileFilter.cpp =================================================================== diff -u -r09d557ffefb1dd57e7606695e16c3151e42285f2 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision 09d557ffefb1dd57e7606695e16c3151e42285f2) +++ src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,654 +1,654 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#include "stdafx.h" -#include "FileInfo.h" -#include "FileFilter.h" - -//////////////////////////////////////////////////////////////////////////// -bool _tcicmp(TCHAR c1, TCHAR c2) -{ - TCHAR ch1[2]={c1, 0}, ch2[2]={c2, 0}; - return (_tcsicmp(ch1, ch2) == 0); -} - -CFileFilter::CFileFilter() -{ - // files mask - m_bUseMask=false; - m_astrMask.RemoveAll(); - - m_bUseExcludeMask=false; - m_astrExcludeMask.RemoveAll(); - - // size filtering - m_bUseSize=false; - m_iSizeType1=GT; - m_ullSize1=0; - m_bUseSize2=false; - m_iSizeType2=LT; - m_ullSize2=0; - - // date filtering - m_bUseDate=false; - m_iDateType=DATE_CREATED; - m_iDateType1=GT; - m_bDate1=false; - m_tDate1=CTime::GetCurrentTime(); - m_bTime1=false; - m_tTime1=CTime::GetCurrentTime(); - - m_bUseDate2=false; - m_iDateType2=LT; - m_bDate2=false; - m_tDate2=CTime::GetCurrentTime(); - m_bTime2=false; - m_tTime2=CTime::GetCurrentTime(); - - // attribute filtering - m_bUseAttributes=false; - m_iArchive=2; - m_iReadOnly=2; - m_iHidden=2; - m_iSystem=2; - m_iDirectory=2; -} - -CFileFilter::CFileFilter(const CFileFilter& rFilter) -{ - *this=rFilter; -} - -CFileFilter& CFileFilter::operator=(const CFileFilter& rFilter) -{ - // files mask - m_bUseMask=rFilter.m_bUseMask; - m_astrMask.Copy(rFilter.m_astrMask); - - m_bUseExcludeMask=rFilter.m_bUseExcludeMask; - m_astrExcludeMask.Copy(rFilter.m_astrExcludeMask); - - // size filtering - m_bUseSize=rFilter.m_bUseSize; - m_iSizeType1=rFilter.m_iSizeType1; - m_ullSize1=rFilter.m_ullSize1; - m_bUseSize2=rFilter.m_bUseSize2; - m_iSizeType2=rFilter.m_iSizeType2; - m_ullSize2=rFilter.m_ullSize2; - - // date filtering - m_bUseDate=rFilter.m_bUseDate; - m_iDateType=rFilter.m_iDateType; - m_iDateType1=rFilter.m_iDateType1; - m_bDate1=rFilter.m_bDate1; - m_tDate1=rFilter.m_tDate1; - m_bTime1=rFilter.m_bTime1; - m_tTime1=rFilter.m_tTime1; - - m_bUseDate2=rFilter.m_bUseDate2; - m_iDateType2=rFilter.m_iDateType2; - m_bDate2=rFilter.m_bDate2; - m_tDate2=rFilter.m_tDate2; - m_bTime2=rFilter.m_bTime2; - m_tTime2=rFilter.m_tTime2; - - // attribute filtering - m_bUseAttributes=rFilter.m_bUseAttributes; - m_iArchive=rFilter.m_iArchive; - m_iReadOnly=rFilter.m_iReadOnly; - m_iHidden=rFilter.m_iHidden; - m_iSystem=rFilter.m_iSystem; - m_iDirectory=rFilter.m_iDirectory; - - return *this; -} - -void CFileFilter::Serialize(icpf::archive& ar) -{ - ULARGE_INTEGER li; - if (ar.is_storing()) - { - // store - // files mask - ar<(m_bUseMask); - ar<(m_bUseExcludeMask); - // ar<(m_bUseSize); - ar<(m_bUseSize2); - ar<(m_bUseDate); - ar<(m_bDate1); - ar<(m_bTime1); - ar<(m_bUseDate2); - ar<(m_bDate2); - ar<(m_bTime2); - ar<(m_bUseAttributes); - ar<>tmp; - m_bUseMask=(tmp != 0); - ar>>m_astrMask; - - ar>>tmp; - m_bUseExcludeMask=(tmp != 0); - ar>>m_astrExcludeMask; - - // size - ar>>tmp; - m_bUseSize=(tmp != 0); - ar>>m_iSizeType1; - ar>>li.LowPart; - ar>>li.HighPart; - m_ullSize1=li.QuadPart; - ar>>tmp; - m_bUseSize2=(tmp != 0); - ar>>m_iSizeType2; - ar>>li.LowPart; - ar>>li.HighPart; - m_ullSize2=li.QuadPart; - - // date - ar>>tmp; - m_bUseDate=(tmp != 0); - ar>>m_iDateType; - ar>>m_iDateType1; - ar>>tmp; - m_bDate1=(tmp != 0); - ar>>m_tDate1; - ar>>tmp; - m_bTime1=(tmp != 0); - ar>>m_tTime1; - - ar>>tmp; - m_bUseDate2=(tmp != 0); - ar>>m_iDateType2; - ar>>tmp; - m_bDate2=(tmp != 0); - ar>>m_tDate2; - ar>>tmp; - m_bTime2=(tmp != 0); - ar>>m_tTime2; - - // attributes - ar>>tmp; - m_bUseAttributes=(tmp != 0); - ar>>m_iArchive; - ar>>m_iReadOnly; - ar>>m_iHidden; - ar>>m_iSystem; - ar>>m_iDirectory; - } -} - -CString& CFileFilter::GetCombinedMask(CString& pMask) const -{ - pMask.Empty(); - if (m_astrMask.GetSize() > 0) - { - pMask=m_astrMask.GetAt(0); - for (int i=1;i 0) - { - pMask=m_astrExcludeMask.GetAt(0); - for (int i=1;i rInfo.GetLength64()) - return false; - break; - case GT: - if (m_ullSize1 >= rInfo.GetLength64()) - return false; - break; - } - - // second part - if (m_bUseSize2) - { - switch (m_iSizeType2) - { - case LT: - if (m_ullSize2 <= rInfo.GetLength64()) - return false; - break; - case LE: - if (m_ullSize2 < rInfo.GetLength64()) - return false; - break; - case EQ: - if (m_ullSize2 != rInfo.GetLength64()) - return false; - break; - case GE: - if (m_ullSize2 > rInfo.GetLength64()) - return false; - break; - case GT: - if (m_ullSize2 >= rInfo.GetLength64()) - return false; - break; - } - } - } - - // date - get the time from rInfo - if (m_bUseDate) - { - COleDateTime tm; - switch (m_iDateType) - { - case DATE_CREATED: - tm=rInfo.GetCreationTime(); - break; - case DATE_MODIFIED: - tm=rInfo.GetLastWriteTime(); - break; - case DATE_LASTACCESSED: - tm=rInfo.GetLastAccessTime(); - break; - } - - // counting... - unsigned long ulInfo=0, ulCheck=0; - if (m_bDate1) - { - ulInfo=(tm.GetYear()-1970)*32140800+tm.GetMonth()*2678400+tm.GetDay()*86400; - ulCheck=(m_tDate1.GetYear()-1970)*32140800+m_tDate1.GetMonth()*2678400+m_tDate1.GetDay()*86400; - } - - if (m_bTime1) - { - ulInfo+=tm.GetHour()*3600+tm.GetMinute()*60+tm.GetSecond(); - ulCheck+=m_tTime1.GetHour()*3600+m_tTime1.GetMinute()*60+m_tTime1.GetSecond(); - } - - // ... and comparing - switch (m_iDateType1) - { - case LT: - if (ulInfo >= ulCheck) - return false; - break; - case LE: - if (ulInfo > ulCheck) - return false; - break; - case EQ: - if (ulInfo != ulCheck) - return false; - break; - case GE: - if (ulInfo < ulCheck) - return false; - break; - case GT: - if (ulInfo <= ulCheck) - return false; - break; - } - - if (m_bUseDate2) - { - // counting... - ulInfo=0, ulCheck=0; - if (m_bDate2) - { - ulInfo=(tm.GetYear()-1970)*32140800+tm.GetMonth()*2678400+tm.GetDay()*86400; - ulCheck=(m_tDate2.GetYear()-1970)*32140800+m_tDate2.GetMonth()*2678400+m_tDate2.GetDay()*86400; - } - - if (m_bTime2) - { - ulInfo+=tm.GetHour()*3600+tm.GetMinute()*60+tm.GetSecond(); - ulCheck+=m_tTime2.GetHour()*3600+m_tTime2.GetMinute()*60+m_tTime2.GetSecond(); - } - - // ... comparing - switch (m_iDateType2) - { - case LT: - if (ulInfo >= ulCheck) - return false; - break; - case LE: - if (ulInfo > ulCheck) - return false; - break; - case EQ: - if (ulInfo != ulCheck) - return false; - break; - case GE: - if (ulInfo < ulCheck) - return false; - break; - case GT: - if (ulInfo <= ulCheck) - return false; - break; - } - } - } // of m_bUseDate - - // attributes - if (m_bUseAttributes) - { - if ( (m_iArchive == 1 && !rInfo.IsArchived()) || (m_iArchive == 0 && rInfo.IsArchived())) - return false; - if ( (m_iReadOnly == 1 && !rInfo.IsReadOnly()) || (m_iReadOnly == 0 && rInfo.IsReadOnly())) - return false; - if ( (m_iHidden == 1 && !rInfo.IsHidden()) || (m_iHidden == 0 && rInfo.IsHidden())) - return false; - if ( (m_iSystem == 1 && !rInfo.IsSystem()) || (m_iSystem == 0 && rInfo.IsSystem())) - return false; - if ( (m_iDirectory == 1 && !rInfo.IsDirectory()) || (m_iDirectory == 0 && rInfo.IsDirectory())) - return false; - } - - return true; -} - -bool CFileFilter::MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const -{ - bool bMatch = 1; - - //iterate and delete '?' and '*' one by one - while(*lpszMask != _T('\0') && bMatch && *lpszString != _T('\0')) - { - if (*lpszMask == _T('?')) lpszString++; - else if (*lpszMask == _T('*')) - { - bMatch = Scan(lpszMask, lpszString); - lpszMask--; - } - else - { - bMatch = _tcicmp(*lpszMask, *lpszString); - lpszString++; - } - lpszMask++; - } - while (*lpszMask == _T('*') && bMatch) lpszMask++; - - return bMatch && *lpszString == _T('\0') && *lpszMask == _T('\0'); -} - -// scan '?' and '*' -bool CFileFilter::Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const -{ - // remove the '?' and '*' - for(lpszMask++; *lpszString != _T('\0') && (*lpszMask == _T('?') || *lpszMask == _T('*')); lpszMask++) - if (*lpszMask == _T('?')) lpszString++; - while ( *lpszMask == _T('*')) lpszMask++; - - // if lpszString is empty and lpszMask has more characters or, - // lpszMask is empty, return - if (*lpszString == _T('\0') && *lpszMask != _T('\0')) return false; - if (*lpszString == _T('\0') && *lpszMask == _T('\0')) return true; - // else search substring - else - { - LPCTSTR wdsCopy = lpszMask; - LPCTSTR lpszStringCopy = lpszString; - bool bMatch = true; - do - { - if (!MatchMask(lpszMask, lpszString)) lpszStringCopy++; - lpszMask = wdsCopy; - lpszString = lpszStringCopy; - while (!(_tcicmp(*lpszMask, *lpszString)) && (*lpszString != '\0')) lpszString++; - wdsCopy = lpszMask; - lpszStringCopy = lpszString; - } - while ((*lpszString != _T('\0')) ? !MatchMask(lpszMask, lpszString) : (bMatch = false) != false); - - if (*lpszString == _T('\0') && *lpszMask == _T('\0')) return true; - - return bMatch; - } -} - -CFiltersArray& CFiltersArray::operator=(const CFiltersArray& rSrc) -{ - if(this != &rSrc) - { - m_vFilters = rSrc.m_vFilters; - } - - return *this; -} - -bool CFiltersArray::Match(const CFileInfo& rInfo) const -{ - if(m_vFilters.empty()) - return true; - - // if only one of the filters matches - return true - for(std::vector::const_iterator iterFilter = m_vFilters.begin(); iterFilter != m_vFilters.end(); iterFilter++) - { - if((*iterFilter).Match(rInfo)) - return true; - } - - return false; -} - -void CFiltersArray::Serialize(icpf::archive& ar) -{ - if (ar.is_storing()) - { - ar<< m_vFilters.size(); - for(std::vector::iterator iterFilter = m_vFilters.begin(); iterFilter != m_vFilters.end(); iterFilter++) - { - (*iterFilter).Serialize(ar); - } - } - else - { - m_vFilters.clear(); - - size_t stSize; - CFileFilter ff; - - ar >> stSize; - m_vFilters.reserve(stSize); - while(stSize--) - { - ff.Serialize(ar); - m_vFilters.push_back(ff); - } - } -} - -bool CFiltersArray::IsEmpty() const -{ - return m_vFilters.empty(); -} - -void CFiltersArray::Add(const CFileFilter& rFilter) -{ - m_vFilters.push_back(rFilter); -} - -bool CFiltersArray::SetAt(size_t stIndex, const CFileFilter& rNewFilter) -{ - BOOST_ASSERT(stIndex < m_vFilters.size()); - if(stIndex < m_vFilters.size()) - { - CFileFilter& rFilter = m_vFilters.at(stIndex); - rFilter = rNewFilter; - return true; - } - else - return false; -} - -const CFileFilter* CFiltersArray::GetAt(size_t stIndex) const -{ - BOOST_ASSERT(stIndex < m_vFilters.size()); - if(stIndex < m_vFilters.size()) - return &m_vFilters.at(stIndex); - else - return NULL; -} - -bool CFiltersArray::RemoveAt(size_t stIndex) -{ - BOOST_ASSERT(stIndex < m_vFilters.size()); - if(stIndex < m_vFilters.size()) - { - m_vFilters.erase(m_vFilters.begin() + stIndex); - return true; - } - else - return false; -} - -size_t CFiltersArray::GetSize() const -{ - return m_vFilters.size(); -} +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "stdafx.h" +#include "FileInfo.h" +#include "FileFilter.h" + +//////////////////////////////////////////////////////////////////////////// +bool _tcicmp(TCHAR c1, TCHAR c2) +{ + TCHAR ch1[2]={c1, 0}, ch2[2]={c2, 0}; + return (_tcsicmp(ch1, ch2) == 0); +} + +CFileFilter::CFileFilter() +{ + // files mask + m_bUseMask=false; + m_astrMask.RemoveAll(); + + m_bUseExcludeMask=false; + m_astrExcludeMask.RemoveAll(); + + // size filtering + m_bUseSize=false; + m_iSizeType1=GT; + m_ullSize1=0; + m_bUseSize2=false; + m_iSizeType2=LT; + m_ullSize2=0; + + // date filtering + m_bUseDate=false; + m_iDateType=DATE_CREATED; + m_iDateType1=GT; + m_bDate1=false; + m_tDate1=CTime::GetCurrentTime(); + m_bTime1=false; + m_tTime1=CTime::GetCurrentTime(); + + m_bUseDate2=false; + m_iDateType2=LT; + m_bDate2=false; + m_tDate2=CTime::GetCurrentTime(); + m_bTime2=false; + m_tTime2=CTime::GetCurrentTime(); + + // attribute filtering + m_bUseAttributes=false; + m_iArchive=2; + m_iReadOnly=2; + m_iHidden=2; + m_iSystem=2; + m_iDirectory=2; +} + +CFileFilter::CFileFilter(const CFileFilter& rFilter) +{ + *this=rFilter; +} + +CFileFilter& CFileFilter::operator=(const CFileFilter& rFilter) +{ + // files mask + m_bUseMask=rFilter.m_bUseMask; + m_astrMask.Copy(rFilter.m_astrMask); + + m_bUseExcludeMask=rFilter.m_bUseExcludeMask; + m_astrExcludeMask.Copy(rFilter.m_astrExcludeMask); + + // size filtering + m_bUseSize=rFilter.m_bUseSize; + m_iSizeType1=rFilter.m_iSizeType1; + m_ullSize1=rFilter.m_ullSize1; + m_bUseSize2=rFilter.m_bUseSize2; + m_iSizeType2=rFilter.m_iSizeType2; + m_ullSize2=rFilter.m_ullSize2; + + // date filtering + m_bUseDate=rFilter.m_bUseDate; + m_iDateType=rFilter.m_iDateType; + m_iDateType1=rFilter.m_iDateType1; + m_bDate1=rFilter.m_bDate1; + m_tDate1=rFilter.m_tDate1; + m_bTime1=rFilter.m_bTime1; + m_tTime1=rFilter.m_tTime1; + + m_bUseDate2=rFilter.m_bUseDate2; + m_iDateType2=rFilter.m_iDateType2; + m_bDate2=rFilter.m_bDate2; + m_tDate2=rFilter.m_tDate2; + m_bTime2=rFilter.m_bTime2; + m_tTime2=rFilter.m_tTime2; + + // attribute filtering + m_bUseAttributes=rFilter.m_bUseAttributes; + m_iArchive=rFilter.m_iArchive; + m_iReadOnly=rFilter.m_iReadOnly; + m_iHidden=rFilter.m_iHidden; + m_iSystem=rFilter.m_iSystem; + m_iDirectory=rFilter.m_iDirectory; + + return *this; +} + +void CFileFilter::Serialize(icpf::archive& ar) +{ + ULARGE_INTEGER li; + if (ar.is_storing()) + { + // store + // files mask + ar<(m_bUseMask); + ar<(m_bUseExcludeMask); + // ar<(m_bUseSize); + ar<(m_bUseSize2); + ar<(m_bUseDate); + ar<(m_bDate1); + ar<(m_bTime1); + ar<(m_bUseDate2); + ar<(m_bDate2); + ar<(m_bTime2); + ar<(m_bUseAttributes); + ar<>tmp; + m_bUseMask=(tmp != 0); + ar>>m_astrMask; + + ar>>tmp; + m_bUseExcludeMask=(tmp != 0); + ar>>m_astrExcludeMask; + + // size + ar>>tmp; + m_bUseSize=(tmp != 0); + ar>>m_iSizeType1; + ar>>li.LowPart; + ar>>li.HighPart; + m_ullSize1=li.QuadPart; + ar>>tmp; + m_bUseSize2=(tmp != 0); + ar>>m_iSizeType2; + ar>>li.LowPart; + ar>>li.HighPart; + m_ullSize2=li.QuadPart; + + // date + ar>>tmp; + m_bUseDate=(tmp != 0); + ar>>m_iDateType; + ar>>m_iDateType1; + ar>>tmp; + m_bDate1=(tmp != 0); + ar>>m_tDate1; + ar>>tmp; + m_bTime1=(tmp != 0); + ar>>m_tTime1; + + ar>>tmp; + m_bUseDate2=(tmp != 0); + ar>>m_iDateType2; + ar>>tmp; + m_bDate2=(tmp != 0); + ar>>m_tDate2; + ar>>tmp; + m_bTime2=(tmp != 0); + ar>>m_tTime2; + + // attributes + ar>>tmp; + m_bUseAttributes=(tmp != 0); + ar>>m_iArchive; + ar>>m_iReadOnly; + ar>>m_iHidden; + ar>>m_iSystem; + ar>>m_iDirectory; + } +} + +CString& CFileFilter::GetCombinedMask(CString& pMask) const +{ + pMask.Empty(); + if (m_astrMask.GetSize() > 0) + { + pMask=m_astrMask.GetAt(0); + for (int i=1;i 0) + { + pMask=m_astrExcludeMask.GetAt(0); + for (int i=1;i rInfo.GetLength64()) + return false; + break; + case GT: + if (m_ullSize1 >= rInfo.GetLength64()) + return false; + break; + } + + // second part + if (m_bUseSize2) + { + switch (m_iSizeType2) + { + case LT: + if (m_ullSize2 <= rInfo.GetLength64()) + return false; + break; + case LE: + if (m_ullSize2 < rInfo.GetLength64()) + return false; + break; + case EQ: + if (m_ullSize2 != rInfo.GetLength64()) + return false; + break; + case GE: + if (m_ullSize2 > rInfo.GetLength64()) + return false; + break; + case GT: + if (m_ullSize2 >= rInfo.GetLength64()) + return false; + break; + } + } + } + + // date - get the time from rInfo + if (m_bUseDate) + { + COleDateTime tm; + switch (m_iDateType) + { + case DATE_CREATED: + tm=rInfo.GetCreationTime(); + break; + case DATE_MODIFIED: + tm=rInfo.GetLastWriteTime(); + break; + case DATE_LASTACCESSED: + tm=rInfo.GetLastAccessTime(); + break; + } + + // counting... + unsigned long ulInfo=0, ulCheck=0; + if (m_bDate1) + { + ulInfo=(tm.GetYear()-1970)*32140800+tm.GetMonth()*2678400+tm.GetDay()*86400; + ulCheck=(m_tDate1.GetYear()-1970)*32140800+m_tDate1.GetMonth()*2678400+m_tDate1.GetDay()*86400; + } + + if (m_bTime1) + { + ulInfo+=tm.GetHour()*3600+tm.GetMinute()*60+tm.GetSecond(); + ulCheck+=m_tTime1.GetHour()*3600+m_tTime1.GetMinute()*60+m_tTime1.GetSecond(); + } + + // ... and comparing + switch (m_iDateType1) + { + case LT: + if (ulInfo >= ulCheck) + return false; + break; + case LE: + if (ulInfo > ulCheck) + return false; + break; + case EQ: + if (ulInfo != ulCheck) + return false; + break; + case GE: + if (ulInfo < ulCheck) + return false; + break; + case GT: + if (ulInfo <= ulCheck) + return false; + break; + } + + if (m_bUseDate2) + { + // counting... + ulInfo=0, ulCheck=0; + if (m_bDate2) + { + ulInfo=(tm.GetYear()-1970)*32140800+tm.GetMonth()*2678400+tm.GetDay()*86400; + ulCheck=(m_tDate2.GetYear()-1970)*32140800+m_tDate2.GetMonth()*2678400+m_tDate2.GetDay()*86400; + } + + if (m_bTime2) + { + ulInfo+=tm.GetHour()*3600+tm.GetMinute()*60+tm.GetSecond(); + ulCheck+=m_tTime2.GetHour()*3600+m_tTime2.GetMinute()*60+m_tTime2.GetSecond(); + } + + // ... comparing + switch (m_iDateType2) + { + case LT: + if (ulInfo >= ulCheck) + return false; + break; + case LE: + if (ulInfo > ulCheck) + return false; + break; + case EQ: + if (ulInfo != ulCheck) + return false; + break; + case GE: + if (ulInfo < ulCheck) + return false; + break; + case GT: + if (ulInfo <= ulCheck) + return false; + break; + } + } + } // of m_bUseDate + + // attributes + if (m_bUseAttributes) + { + if ( (m_iArchive == 1 && !rInfo.IsArchived()) || (m_iArchive == 0 && rInfo.IsArchived())) + return false; + if ( (m_iReadOnly == 1 && !rInfo.IsReadOnly()) || (m_iReadOnly == 0 && rInfo.IsReadOnly())) + return false; + if ( (m_iHidden == 1 && !rInfo.IsHidden()) || (m_iHidden == 0 && rInfo.IsHidden())) + return false; + if ( (m_iSystem == 1 && !rInfo.IsSystem()) || (m_iSystem == 0 && rInfo.IsSystem())) + return false; + if ( (m_iDirectory == 1 && !rInfo.IsDirectory()) || (m_iDirectory == 0 && rInfo.IsDirectory())) + return false; + } + + return true; +} + +bool CFileFilter::MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const +{ + bool bMatch = 1; + + //iterate and delete '?' and '*' one by one + while(*lpszMask != _T('\0') && bMatch && *lpszString != _T('\0')) + { + if (*lpszMask == _T('?')) lpszString++; + else if (*lpszMask == _T('*')) + { + bMatch = Scan(lpszMask, lpszString); + lpszMask--; + } + else + { + bMatch = _tcicmp(*lpszMask, *lpszString); + lpszString++; + } + lpszMask++; + } + while (*lpszMask == _T('*') && bMatch) lpszMask++; + + return bMatch && *lpszString == _T('\0') && *lpszMask == _T('\0'); +} + +// scan '?' and '*' +bool CFileFilter::Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const +{ + // remove the '?' and '*' + for(lpszMask++; *lpszString != _T('\0') && (*lpszMask == _T('?') || *lpszMask == _T('*')); lpszMask++) + if (*lpszMask == _T('?')) lpszString++; + while ( *lpszMask == _T('*')) lpszMask++; + + // if lpszString is empty and lpszMask has more characters or, + // lpszMask is empty, return + if (*lpszString == _T('\0') && *lpszMask != _T('\0')) return false; + if (*lpszString == _T('\0') && *lpszMask == _T('\0')) return true; + // else search substring + else + { + LPCTSTR wdsCopy = lpszMask; + LPCTSTR lpszStringCopy = lpszString; + bool bMatch = true; + do + { + if (!MatchMask(lpszMask, lpszString)) lpszStringCopy++; + lpszMask = wdsCopy; + lpszString = lpszStringCopy; + while (!(_tcicmp(*lpszMask, *lpszString)) && (*lpszString != '\0')) lpszString++; + wdsCopy = lpszMask; + lpszStringCopy = lpszString; + } + while ((*lpszString != _T('\0')) ? !MatchMask(lpszMask, lpszString) : (bMatch = false) != false); + + if (*lpszString == _T('\0') && *lpszMask == _T('\0')) return true; + + return bMatch; + } +} + +CFiltersArray& CFiltersArray::operator=(const CFiltersArray& rSrc) +{ + if(this != &rSrc) + { + m_vFilters = rSrc.m_vFilters; + } + + return *this; +} + +bool CFiltersArray::Match(const CFileInfo& rInfo) const +{ + if(m_vFilters.empty()) + return true; + + // if only one of the filters matches - return true + for(std::vector::const_iterator iterFilter = m_vFilters.begin(); iterFilter != m_vFilters.end(); iterFilter++) + { + if((*iterFilter).Match(rInfo)) + return true; + } + + return false; +} + +void CFiltersArray::Serialize(icpf::archive& ar) +{ + if (ar.is_storing()) + { + ar<< m_vFilters.size(); + for(std::vector::iterator iterFilter = m_vFilters.begin(); iterFilter != m_vFilters.end(); iterFilter++) + { + (*iterFilter).Serialize(ar); + } + } + else + { + m_vFilters.clear(); + + size_t stSize; + CFileFilter ff; + + ar >> stSize; + m_vFilters.reserve(stSize); + while(stSize--) + { + ff.Serialize(ar); + m_vFilters.push_back(ff); + } + } +} + +bool CFiltersArray::IsEmpty() const +{ + return m_vFilters.empty(); +} + +void CFiltersArray::Add(const CFileFilter& rFilter) +{ + m_vFilters.push_back(rFilter); +} + +bool CFiltersArray::SetAt(size_t stIndex, const CFileFilter& rNewFilter) +{ + BOOST_ASSERT(stIndex < m_vFilters.size()); + if(stIndex < m_vFilters.size()) + { + CFileFilter& rFilter = m_vFilters.at(stIndex); + rFilter = rNewFilter; + return true; + } + else + return false; +} + +const CFileFilter* CFiltersArray::GetAt(size_t stIndex) const +{ + BOOST_ASSERT(stIndex < m_vFilters.size()); + if(stIndex < m_vFilters.size()) + return &m_vFilters.at(stIndex); + else + return NULL; +} + +bool CFiltersArray::RemoveAt(size_t stIndex) +{ + BOOST_ASSERT(stIndex < m_vFilters.size()); + if(stIndex < m_vFilters.size()) + { + m_vFilters.erase(m_vFilters.begin() + stIndex); + return true; + } + else + return false; +} + +size_t CFiltersArray::GetSize() const +{ + return m_vFilters.size(); +} Index: src/ch/FileFilter.h =================================================================== diff -u -r09d557ffefb1dd57e7606695e16c3151e42285f2 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FileFilter.h (.../FileFilter.h) (revision 09d557ffefb1dd57e7606695e16c3151e42285f2) +++ src/ch/FileFilter.h (.../FileFilter.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,122 +1,122 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef __FILEFILTER_H__ -#define __FILEFILTER_H__ - -#include - -// definitions for comparing sizes and dates -#define LT 0 -#define LE 1 -#define EQ 2 -#define GE 3 -#define GT 4 - -// date type defs -#define DATE_CREATED 0 -#define DATE_MODIFIED 1 -#define DATE_LASTACCESSED 2 - -class CFileInfo; - -class CFileFilter -{ -public: - CFileFilter(); - CFileFilter(const CFileFilter& rFilter); - CFileFilter& operator=(const CFileFilter& rFilter); - - bool Match(const CFileInfo& rInfo) const; - - CString& GetCombinedMask(CString& pMask) const; - void SetCombinedMask(const CString& pMask); - - CString& GetCombinedExcludeMask(CString& pMask) const; - void SetCombinedExcludeMask(const CString& pMask); - - void Serialize(icpf::archive& ar); - -protected: - bool MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const; - bool Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const; - -public: - // files mask - bool m_bUseMask; - CStringArray m_astrMask; - - // files mask- - bool m_bUseExcludeMask; - CStringArray m_astrExcludeMask; - - // size filtering - bool m_bUseSize; - int m_iSizeType1; - unsigned __int64 m_ullSize1; - bool m_bUseSize2; - int m_iSizeType2; - unsigned __int64 m_ullSize2; - - // date filtering - bool m_bUseDate; - int m_iDateType; // created/last modified/last accessed - int m_iDateType1; // before/after - bool m_bDate1; - CTime m_tDate1; - bool m_bTime1; - CTime m_tTime1; - - bool m_bUseDate2; - int m_iDateType2; - bool m_bDate2; - CTime m_tDate2; - bool m_bTime2; - CTime m_tTime2; - - // attribute filtering - bool m_bUseAttributes; - int m_iArchive; - int m_iReadOnly; - int m_iHidden; - int m_iSystem; - int m_iDirectory; -}; - -class CFiltersArray -{ -public: - CFiltersArray() {} - ~CFiltersArray() {} - - CFiltersArray& operator=(const CFiltersArray& rSrc); - bool Match(const CFileInfo& rInfo) const; - void Serialize(icpf::archive& ar); - bool IsEmpty() const; - - void Add(const CFileFilter& rFilter); - bool SetAt(size_t stIndex, const CFileFilter& rNewFilter); - const CFileFilter* GetAt(size_t stIndex) const; - bool RemoveAt(size_t stIndex); - size_t GetSize() const; - -protected: - std::vector m_vFilters; -}; - +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __FILEFILTER_H__ +#define __FILEFILTER_H__ + +#include + +// definitions for comparing sizes and dates +#define LT 0 +#define LE 1 +#define EQ 2 +#define GE 3 +#define GT 4 + +// date type defs +#define DATE_CREATED 0 +#define DATE_MODIFIED 1 +#define DATE_LASTACCESSED 2 + +class CFileInfo; + +class CFileFilter +{ +public: + CFileFilter(); + CFileFilter(const CFileFilter& rFilter); + CFileFilter& operator=(const CFileFilter& rFilter); + + bool Match(const CFileInfo& rInfo) const; + + CString& GetCombinedMask(CString& pMask) const; + void SetCombinedMask(const CString& pMask); + + CString& GetCombinedExcludeMask(CString& pMask) const; + void SetCombinedExcludeMask(const CString& pMask); + + void Serialize(icpf::archive& ar); + +protected: + bool MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const; + bool Scan(LPCTSTR& lpszMask, LPCTSTR& lpszString) const; + +public: + // files mask + bool m_bUseMask; + CStringArray m_astrMask; + + // files mask- + bool m_bUseExcludeMask; + CStringArray m_astrExcludeMask; + + // size filtering + bool m_bUseSize; + int m_iSizeType1; + unsigned __int64 m_ullSize1; + bool m_bUseSize2; + int m_iSizeType2; + unsigned __int64 m_ullSize2; + + // date filtering + bool m_bUseDate; + int m_iDateType; // created/last modified/last accessed + int m_iDateType1; // before/after + bool m_bDate1; + CTime m_tDate1; + bool m_bTime1; + CTime m_tTime1; + + bool m_bUseDate2; + int m_iDateType2; + bool m_bDate2; + CTime m_tDate2; + bool m_bTime2; + CTime m_tTime2; + + // attribute filtering + bool m_bUseAttributes; + int m_iArchive; + int m_iReadOnly; + int m_iHidden; + int m_iSystem; + int m_iDirectory; +}; + +class CFiltersArray +{ +public: + CFiltersArray() {} + ~CFiltersArray() {} + + CFiltersArray& operator=(const CFiltersArray& rSrc); + bool Match(const CFileInfo& rInfo) const; + void Serialize(icpf::archive& ar); + bool IsEmpty() const; + + void Add(const CFileFilter& rFilter); + bool SetAt(size_t stIndex, const CFileFilter& rNewFilter); + const CFileFilter* GetAt(size_t stIndex) const; + bool RemoveAt(size_t stIndex); + size_t GetSize() const; + +protected: + std::vector m_vFilters; +}; + #endif \ No newline at end of file Index: src/ch/FileInfo.cpp =================================================================== diff -u -r8df12c14c1cced6286c8fbeb69b13abedca97c86 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 8df12c14c1cced6286c8fbeb69b13abedca97c86) +++ src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,543 +1,543 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/************************************************************************* - FileInfo.cpp: implementation of the CFileInfo class. - (c) Codeguru & friends - Coded by Antonio Tejada Lacaci. 1999, modified by Ixen Gerthannes - atejada@espanet.com -*************************************************************************/ - -#include "stdafx.h" -#include "FileInfo.h" -#include "FileFilter.h" -#include "resource.h" -#include "DataBuffer.h" -#include "Device IO.h" -#include "imagehlp.h" -#include "ch.h" -#include -#include "../libicpf/exception.h" - -#ifdef _DEBUG -#undef THIS_FILE -static char THIS_FILE[]=__FILE__; -#define new DEBUG_NEW -#endif - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// -// finds another name for a copy of src file(folder) in dest location -void FindFreeSubstituteName(CString strSrcPath, CString strDstPath, CString* pstrResult) -{ - // get the name from srcpath - if (strSrcPath.Right(1) == _T("\\")) - strSrcPath=strSrcPath.Left(strSrcPath.GetLength()-1); - - int iBarPos=strSrcPath.ReverseFind(_T('\\')); - CString strFolderName; - if (iBarPos != -1) - strFolderName=strSrcPath.Mid(iBarPos+1); - else - strFolderName=strSrcPath; // it shouldn't happen at all - - if (strDstPath.Right(1) != _T("\\")) - strDstPath+=_T("\\"); - - // set the dest path - CString strCheckPath; - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_FIRSTCOPY_STRING)); - fmt.SetParam(_t("%name"), strFolderName); - strCheckPath = fmt; - if (strCheckPath.GetLength() > _MAX_PATH) - strCheckPath=strCheckPath.Left(_MAX_PATH); // max - 260 chars - - // when adding to strDstPath check if the path already exists - if so - try again - int iCounter=1; - CString strFmt = GetResManager()->LoadString(IDS_NEXTCOPY_STRING); - while (CFileInfo::Exist(strDstPath+strCheckPath)) - { - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%name"), strFolderName); - fmt.SetParam(_t("%count"), ++iCounter); - strCheckPath = fmt; - } - - *pstrResult=strCheckPath; -} - -//////////////////////////////////////////////////////////////////////////// -CFileInfo::CFileInfo() -{ -} - -CFileInfo::CFileInfo(const CFileInfo& finf) -{ - m_strFilePath = finf.m_strFilePath; - m_iSrcIndex=finf.m_iSrcIndex; - m_dwAttributes = finf.m_dwAttributes; - m_uhFileSize = finf.m_uhFileSize; - m_timCreation = finf.m_timCreation; - m_timLastAccess = finf.m_timLastAccess; - m_timLastWrite = finf.m_timLastWrite; - m_uiFlags = finf.m_uiFlags; - - m_pClipboard=finf.m_pClipboard; -} - -CFileInfo::~CFileInfo() -{ -} - -bool CFileInfo::Exist(CString strPath) -{ - WIN32_FIND_DATA fd; - - // search by exact name - HANDLE hFind = FindFirstFile(strPath, &fd); - if (hFind != INVALID_HANDLE_VALUE) - return true; - - // another try (add '\\' if needed and '*' for marking that we look for ie. c:\* - // instead of c:\, which would never be found prev. way) - if (strPath.Right(1) != _T("\\")) - strPath+=_T("\\*"); - else - strPath+=_T("*"); - - hFind = FindFirstFile(strPath, &fd); - if (hFind != INVALID_HANDLE_VALUE) - return true; - else - return false; -} - -void CFileInfo::Create(const WIN32_FIND_DATA* pwfd, LPCTSTR pszFilePath, int iSrcIndex) -{ - BOOST_ASSERT(iSrcIndex == -1 || m_pClipboard); - if(iSrcIndex != -1 && !m_pClipboard) - THROW(_t("Internal error: pointer not initialized."), 0, 0, 0); - - // copy data from W32_F_D - m_strFilePath = CString(pszFilePath) + pwfd->cFileName; - - // if proper index has been passed - reduce the path - if(m_pClipboard && iSrcIndex >= 0) - m_strFilePath=m_strFilePath.Mid(m_pClipboard->GetAt(iSrcIndex)->GetPath().GetLength()); // wytnij �cie�k� z clipboarda - - m_iSrcIndex=iSrcIndex; - m_dwAttributes = pwfd->dwFileAttributes; - m_uhFileSize = (((ULONGLONG) pwfd->nFileSizeHigh) << 32) + pwfd->nFileSizeLow; - m_timCreation = pwfd->ftCreationTime; - m_timLastAccess = pwfd->ftLastAccessTime; - m_timLastWrite = pwfd->ftLastWriteTime; - m_uiFlags = 0; -} - -bool CFileInfo::Create(CString strFilePath, int iSrcIndex) -{ - WIN32_FIND_DATA wfd; - HANDLE hFind; - int nBarPos; - - hFind = FindFirstFile(strFilePath, &wfd); - if (hFind != INVALID_HANDLE_VALUE) - { - FindClose(hFind); - - // add data to members - nBarPos = strFilePath.ReverseFind(TCHAR('\\')); - Create(&wfd, strFilePath.Left(nBarPos+1), iSrcIndex); - - return true; - } - else - { - m_strFilePath=GetResManager()->LoadString(IDS_NOTFOUND_STRING); - m_iSrcIndex=-1; - m_dwAttributes = (DWORD)-1; - m_uhFileSize = (unsigned __int64)-1; - m_timCreation.SetDateTime(1900, 1, 1, 0, 0, 0); - m_timLastAccess.SetDateTime(1900, 1, 1, 0, 0, 0); - m_timLastWrite.SetDateTime(1900, 1, 1, 0, 0, 0); - m_uiFlags = 0; - return false; - } -} - -CString CFileInfo::GetFileDrive(void) const -{ - ASSERT(m_pClipboard); - - CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; - TCHAR szDrive[_MAX_DRIVE]; - _tsplitpath(strPath, szDrive, NULL, NULL, NULL); - return CString(szDrive); -} - -int CFileInfo::GetDriveNumber() const -{ - ASSERT(m_pClipboard); - - if (m_iSrcIndex != -1) - { - // read data stored in CClipboardEntry - return m_pClipboard->GetAt(m_iSrcIndex)->GetDriveNumber(); - } - else - { - // manually - int iNum; - GetDriveData(m_strFilePath, &iNum, NULL); - return iNum; - } -} - -UINT CFileInfo::GetDriveType() const -{ - ASSERT(m_pClipboard); - - if (m_iSrcIndex != -1) - { - // read data contained in CClipboardEntry - return m_pClipboard->GetAt(m_iSrcIndex)->GetDriveType(); - } - else - { - // manually - UINT uiType; - GetDriveData(m_strFilePath, NULL, &uiType); - return uiType; - } -} - -CString CFileInfo::GetFileDir(void) const -{ - ASSERT(m_pClipboard); - - CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; - TCHAR szDir[_MAX_DIR]; - _tsplitpath(strPath, NULL, szDir,NULL, NULL); - return CString(szDir); -} - -CString CFileInfo::GetFileTitle(void) const -{ - ASSERT(m_pClipboard); - - CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; - TCHAR szName[_MAX_FNAME]; - _tsplitpath(strPath, NULL, NULL, szName, NULL); - return CString(szName); -} - -CString CFileInfo::GetFileExt(void) const -{ - ASSERT(m_pClipboard); - - CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; - TCHAR szExt[_MAX_EXT]; - _tsplitpath(strPath, NULL, NULL, NULL, szExt); - return CString(szExt); -} - -CString CFileInfo::GetFileRoot(void) const -{ - ASSERT(m_pClipboard); - - CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; - - TCHAR szDrive[_MAX_DRIVE]; - TCHAR szDir[_MAX_DIR]; - _tsplitpath(strPath, szDrive, szDir, NULL, NULL); - return CString(szDrive)+szDir; -} - -CString CFileInfo::GetFileName(void) const -{ - ASSERT(m_pClipboard); - - CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; - - TCHAR szName[_MAX_FNAME]; - TCHAR szExt[_MAX_EXT]; - _tsplitpath(strPath, NULL, NULL, szName, szExt); - return CString(szName)+szExt; -} - -void CFileInfo::Store(icpf::archive& ar) -{ - ar<((m_uhFileSize & 0xFFFFFFFF00000000) >> 32); - ar<(m_uhFileSize & 0x00000000FFFFFFFF); - ar<>m_strFilePath; - ar>>m_iSrcIndex; - ar>>m_dwAttributes; - unsigned long part; - ar>>part; - m_uhFileSize=(static_cast(part) << 32); - ar>>part; - m_uhFileSize+=part; - ar>>m_timCreation; - ar>>m_timLastAccess; - ar>>m_timLastWrite; - m_uiFlags = 0; -} - -bool CFileInfo::operator==(const CFileInfo& rInfo) -{ - return (rInfo.m_dwAttributes == m_dwAttributes && rInfo.m_timCreation == m_timCreation - && rInfo.m_timLastWrite == m_timLastWrite && rInfo.m_uhFileSize == m_uhFileSize); -} - -CString CFileInfo::GetDestinationPath(CString strPath, unsigned char ucCopyNumber, int iFlags) -{ - // add '\\' - if (strPath.Right(1) != _T("\\")) - strPath+=_T("\\"); - - // iFlags: bit 0-ignore folders; bit 1-force creating directories - if (iFlags & 0x02) - { - // force create directories - TCHAR dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; - _tsplitpath(GetFullFilePath(), NULL, dir, fname, ext); - - CString str=dir; - str.TrimLeft(_T("\\")); - - // force create directory -// AfxMessageBox("Created multiple level of paths for %s"+strPath+str); - SHCreateDirectoryEx(NULL, strPath+str, NULL); -// MakeSureDirectoryPathExists(strPath+str); - -// AfxMessageBox(strPath+str+fname+CString(ext)); - return strPath+str+fname+CString(ext); - } - else - { - if (!(iFlags & 0x01) && m_iSrcIndex != -1) - { - // generate new dest name - while (ucCopyNumber >= m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.GetSize()) - { - CString strNewPath; - FindFreeSubstituteName(GetFullFilePath(), strPath, &strNewPath); - m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.Add(strNewPath); - } - - return strPath+m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.GetAt(ucCopyNumber)+m_strFilePath; - } - else - return strPath+GetFileName(); - } -} - -CString CFileInfo::GetFullFilePath() const -{ - CString strPath; - if (m_iSrcIndex >= 0) - { - ASSERT(m_pClipboard); - strPath+=m_pClipboard->GetAt(m_iSrcIndex)->GetPath(); - } - strPath+=m_strFilePath; - - return strPath; -} - -int CFileInfo::GetBufferIndex() const -{ - if (m_iSrcIndex != -1) - return m_pClipboard->GetAt(m_iSrcIndex)->GetBufferIndex(); - else - return BI_DEFAULT; -} - -/////////////////////////////////////////////////////////////////////// -// Array - -void CFileInfoArray::AddDir(CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, - const bool bRecurse, const bool bIncludeDirs, - const volatile bool* pbAbort) -{ - WIN32_FIND_DATA wfd; - CString strText; - - // init CFileInfo - CFileInfo finf; - finf.SetClipboard(m_pClipboard); // this is the link table (CClipboardArray) - - // append '\\' at the end of path if needed - if (strDirName.Right(1) != _T("\\")) - strDirName+=_T("\\"); - - strText = strDirName + _T("*"); - // Iterate through dirs & files - HANDLE hFind = FindFirstFile(strText, &wfd); - if (hFind != INVALID_HANDLE_VALUE) - { - do - { - if ( !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) - { - finf.Create(&wfd, strDirName, iSrcIndex); - if (pFilters->Match(finf)) - Add(finf); - } - else if ( _tcscmp(wfd.cFileName, _T(".")) != 0 && _tcscmp(wfd.cFileName, _T("..")) != 0) - { - if (bIncludeDirs) - { - // Add directory itself - finf.Create(&wfd, strDirName, iSrcIndex); - Add(finf); - } - if (bRecurse) - { - strText = strDirName + wfd.cFileName+_T("\\"); - // Recurse Dirs - AddDir(strText, pFilters, iSrcIndex, bRecurse, bIncludeDirs, pbAbort); - } - } - } - while (((pbAbort == NULL) || (!*pbAbort)) && (FindNextFile(hFind, &wfd))); - - FindClose(hFind); - } -} - -int CFileInfoArray::AddFile(CString strFilePath, int iSrcIndex) -{ - CFileInfo finf; - - // CUSTOMIZATION3 - cut '\\' at the end of strFilePath, set relative path - if (strFilePath.Right(1) == _T("\\")) - strFilePath=strFilePath.Left(strFilePath.GetLength()-1); - - finf.Create(strFilePath, iSrcIndex); - return Add(finf); -} - - -////////////////////////////////////////////////////////////////////////////// -// CClipboardArray - -void CClipboardArray::Serialize(icpf::archive& ar, bool bData) -{ - if (ar.is_storing()) - { - // write data - int iSize=GetSize(); - ar<Serialize(ar, bData); - } - else - { - int iSize; - ar>>iSize; - - CClipboardEntry* pEntry; - for (int i=0;iSerialize(ar, bData); - } - } -} - -///////////////////////////////////////////////////////////////////////////// -// CClipboardEntry - -void CClipboardEntry::SetPath(const CString& strPath) -{ - m_strPath=strPath; // guaranteed without ending '\\' - if (m_strPath.Right(1) == _T('\\')) - m_strPath=m_strPath.Left(m_strPath.GetLength()-1); - - GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType); -} - -void CClipboardEntry::CalcBufferIndex(const CDestPath& dpDestPath) -{ - // what kind of buffer - if (m_uiDriveType == DRIVE_REMOTE || dpDestPath.GetDriveType() == DRIVE_REMOTE) - m_iBufferIndex=BI_LAN; - else if (m_uiDriveType == DRIVE_CDROM || dpDestPath.GetDriveType() == DRIVE_CDROM) - m_iBufferIndex=BI_CD; - else if (m_uiDriveType == DRIVE_FIXED && dpDestPath.GetDriveType() == DRIVE_FIXED) - { - // two hdd's - is this the same physical disk ? - if (m_iDriveNumber == dpDestPath.GetDriveNumber() || IsSamePhysicalDisk(m_iDriveNumber, dpDestPath.GetDriveNumber())) - m_iBufferIndex=BI_ONEDISK; - else - m_iBufferIndex=BI_TWODISKS; - } - else - m_iBufferIndex=BI_DEFAULT; -} - -void CClipboardEntry::Serialize(icpf::archive& ar, bool bData) -{ - if (bData) - { - if(ar.is_storing()) - { - ar<(m_bMove); - ar<>m_strPath; - unsigned char ucData; - ar>>ucData; - m_bMove=ucData != 0; - ar>>m_iDriveNumber; - ar>>m_uiDriveType; - ar>>m_iBufferIndex; - } - } - else - { - if(ar.is_storing()) - ar<>m_astrDstPaths; - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +/************************************************************************* + FileInfo.cpp: implementation of the CFileInfo class. + (c) Codeguru & friends + Coded by Antonio Tejada Lacaci. 1999, modified by Ixen Gerthannes + atejada@espanet.com +*************************************************************************/ + +#include "stdafx.h" +#include "FileInfo.h" +#include "FileFilter.h" +#include "resource.h" +#include "DataBuffer.h" +#include "Device IO.h" +#include "imagehlp.h" +#include "ch.h" +#include +#include "../libicpf/exception.h" + +#ifdef _DEBUG +#undef THIS_FILE +static char THIS_FILE[]=__FILE__; +#define new DEBUG_NEW +#endif + +////////////////////////////////////////////////////////////////////// +// Construction/Destruction +////////////////////////////////////////////////////////////////////// +// finds another name for a copy of src file(folder) in dest location +void FindFreeSubstituteName(CString strSrcPath, CString strDstPath, CString* pstrResult) +{ + // get the name from srcpath + if (strSrcPath.Right(1) == _T("\\")) + strSrcPath=strSrcPath.Left(strSrcPath.GetLength()-1); + + int iBarPos=strSrcPath.ReverseFind(_T('\\')); + CString strFolderName; + if (iBarPos != -1) + strFolderName=strSrcPath.Mid(iBarPos+1); + else + strFolderName=strSrcPath; // it shouldn't happen at all + + if (strDstPath.Right(1) != _T("\\")) + strDstPath+=_T("\\"); + + // set the dest path + CString strCheckPath; + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_FIRSTCOPY_STRING)); + fmt.SetParam(_t("%name"), strFolderName); + strCheckPath = fmt; + if (strCheckPath.GetLength() > _MAX_PATH) + strCheckPath=strCheckPath.Left(_MAX_PATH); // max - 260 chars + + // when adding to strDstPath check if the path already exists - if so - try again + int iCounter=1; + CString strFmt = GetResManager()->LoadString(IDS_NEXTCOPY_STRING); + while (CFileInfo::Exist(strDstPath+strCheckPath)) + { + fmt.SetFormat(strFmt); + fmt.SetParam(_t("%name"), strFolderName); + fmt.SetParam(_t("%count"), ++iCounter); + strCheckPath = fmt; + } + + *pstrResult=strCheckPath; +} + +//////////////////////////////////////////////////////////////////////////// +CFileInfo::CFileInfo() +{ +} + +CFileInfo::CFileInfo(const CFileInfo& finf) +{ + m_strFilePath = finf.m_strFilePath; + m_iSrcIndex=finf.m_iSrcIndex; + m_dwAttributes = finf.m_dwAttributes; + m_uhFileSize = finf.m_uhFileSize; + m_timCreation = finf.m_timCreation; + m_timLastAccess = finf.m_timLastAccess; + m_timLastWrite = finf.m_timLastWrite; + m_uiFlags = finf.m_uiFlags; + + m_pClipboard=finf.m_pClipboard; +} + +CFileInfo::~CFileInfo() +{ +} + +bool CFileInfo::Exist(CString strPath) +{ + WIN32_FIND_DATA fd; + + // search by exact name + HANDLE hFind = FindFirstFile(strPath, &fd); + if (hFind != INVALID_HANDLE_VALUE) + return true; + + // another try (add '\\' if needed and '*' for marking that we look for ie. c:\* + // instead of c:\, which would never be found prev. way) + if (strPath.Right(1) != _T("\\")) + strPath+=_T("\\*"); + else + strPath+=_T("*"); + + hFind = FindFirstFile(strPath, &fd); + if (hFind != INVALID_HANDLE_VALUE) + return true; + else + return false; +} + +void CFileInfo::Create(const WIN32_FIND_DATA* pwfd, LPCTSTR pszFilePath, int iSrcIndex) +{ + BOOST_ASSERT(iSrcIndex == -1 || m_pClipboard); + if(iSrcIndex != -1 && !m_pClipboard) + THROW(_t("Internal error: pointer not initialized."), 0, 0, 0); + + // copy data from W32_F_D + m_strFilePath = CString(pszFilePath) + pwfd->cFileName; + + // if proper index has been passed - reduce the path + if(m_pClipboard && iSrcIndex >= 0) + m_strFilePath=m_strFilePath.Mid(m_pClipboard->GetAt(iSrcIndex)->GetPath().GetLength()); // wytnij �cie�k� z clipboarda + + m_iSrcIndex=iSrcIndex; + m_dwAttributes = pwfd->dwFileAttributes; + m_uhFileSize = (((ULONGLONG) pwfd->nFileSizeHigh) << 32) + pwfd->nFileSizeLow; + m_timCreation = pwfd->ftCreationTime; + m_timLastAccess = pwfd->ftLastAccessTime; + m_timLastWrite = pwfd->ftLastWriteTime; + m_uiFlags = 0; +} + +bool CFileInfo::Create(CString strFilePath, int iSrcIndex) +{ + WIN32_FIND_DATA wfd; + HANDLE hFind; + int nBarPos; + + hFind = FindFirstFile(strFilePath, &wfd); + if (hFind != INVALID_HANDLE_VALUE) + { + FindClose(hFind); + + // add data to members + nBarPos = strFilePath.ReverseFind(TCHAR('\\')); + Create(&wfd, strFilePath.Left(nBarPos+1), iSrcIndex); + + return true; + } + else + { + m_strFilePath=GetResManager()->LoadString(IDS_NOTFOUND_STRING); + m_iSrcIndex=-1; + m_dwAttributes = (DWORD)-1; + m_uhFileSize = (unsigned __int64)-1; + m_timCreation.SetDateTime(1900, 1, 1, 0, 0, 0); + m_timLastAccess.SetDateTime(1900, 1, 1, 0, 0, 0); + m_timLastWrite.SetDateTime(1900, 1, 1, 0, 0, 0); + m_uiFlags = 0; + return false; + } +} + +CString CFileInfo::GetFileDrive(void) const +{ + ASSERT(m_pClipboard); + + CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + TCHAR szDrive[_MAX_DRIVE]; + _tsplitpath(strPath, szDrive, NULL, NULL, NULL); + return CString(szDrive); +} + +int CFileInfo::GetDriveNumber() const +{ + ASSERT(m_pClipboard); + + if (m_iSrcIndex != -1) + { + // read data stored in CClipboardEntry + return m_pClipboard->GetAt(m_iSrcIndex)->GetDriveNumber(); + } + else + { + // manually + int iNum; + GetDriveData(m_strFilePath, &iNum, NULL); + return iNum; + } +} + +UINT CFileInfo::GetDriveType() const +{ + ASSERT(m_pClipboard); + + if (m_iSrcIndex != -1) + { + // read data contained in CClipboardEntry + return m_pClipboard->GetAt(m_iSrcIndex)->GetDriveType(); + } + else + { + // manually + UINT uiType; + GetDriveData(m_strFilePath, NULL, &uiType); + return uiType; + } +} + +CString CFileInfo::GetFileDir(void) const +{ + ASSERT(m_pClipboard); + + CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + TCHAR szDir[_MAX_DIR]; + _tsplitpath(strPath, NULL, szDir,NULL, NULL); + return CString(szDir); +} + +CString CFileInfo::GetFileTitle(void) const +{ + ASSERT(m_pClipboard); + + CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + TCHAR szName[_MAX_FNAME]; + _tsplitpath(strPath, NULL, NULL, szName, NULL); + return CString(szName); +} + +CString CFileInfo::GetFileExt(void) const +{ + ASSERT(m_pClipboard); + + CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + TCHAR szExt[_MAX_EXT]; + _tsplitpath(strPath, NULL, NULL, NULL, szExt); + return CString(szExt); +} + +CString CFileInfo::GetFileRoot(void) const +{ + ASSERT(m_pClipboard); + + CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + + TCHAR szDrive[_MAX_DRIVE]; + TCHAR szDir[_MAX_DIR]; + _tsplitpath(strPath, szDrive, szDir, NULL, NULL); + return CString(szDrive)+szDir; +} + +CString CFileInfo::GetFileName(void) const +{ + ASSERT(m_pClipboard); + + CString strPath=(m_iSrcIndex != -1) ? m_pClipboard->GetAt(m_iSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + + TCHAR szName[_MAX_FNAME]; + TCHAR szExt[_MAX_EXT]; + _tsplitpath(strPath, NULL, NULL, szName, szExt); + return CString(szName)+szExt; +} + +void CFileInfo::Store(icpf::archive& ar) +{ + ar<((m_uhFileSize & 0xFFFFFFFF00000000) >> 32); + ar<(m_uhFileSize & 0x00000000FFFFFFFF); + ar<>m_strFilePath; + ar>>m_iSrcIndex; + ar>>m_dwAttributes; + unsigned long part; + ar>>part; + m_uhFileSize=(static_cast(part) << 32); + ar>>part; + m_uhFileSize+=part; + ar>>m_timCreation; + ar>>m_timLastAccess; + ar>>m_timLastWrite; + m_uiFlags = 0; +} + +bool CFileInfo::operator==(const CFileInfo& rInfo) +{ + return (rInfo.m_dwAttributes == m_dwAttributes && rInfo.m_timCreation == m_timCreation + && rInfo.m_timLastWrite == m_timLastWrite && rInfo.m_uhFileSize == m_uhFileSize); +} + +CString CFileInfo::GetDestinationPath(CString strPath, unsigned char ucCopyNumber, int iFlags) +{ + // add '\\' + if (strPath.Right(1) != _T("\\")) + strPath+=_T("\\"); + + // iFlags: bit 0-ignore folders; bit 1-force creating directories + if (iFlags & 0x02) + { + // force create directories + TCHAR dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; + _tsplitpath(GetFullFilePath(), NULL, dir, fname, ext); + + CString str=dir; + str.TrimLeft(_T("\\")); + + // force create directory +// AfxMessageBox("Created multiple level of paths for %s"+strPath+str); + SHCreateDirectoryEx(NULL, strPath+str, NULL); +// MakeSureDirectoryPathExists(strPath+str); + +// AfxMessageBox(strPath+str+fname+CString(ext)); + return strPath+str+fname+CString(ext); + } + else + { + if (!(iFlags & 0x01) && m_iSrcIndex != -1) + { + // generate new dest name + while (ucCopyNumber >= m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.GetSize()) + { + CString strNewPath; + FindFreeSubstituteName(GetFullFilePath(), strPath, &strNewPath); + m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.Add(strNewPath); + } + + return strPath+m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.GetAt(ucCopyNumber)+m_strFilePath; + } + else + return strPath+GetFileName(); + } +} + +CString CFileInfo::GetFullFilePath() const +{ + CString strPath; + if (m_iSrcIndex >= 0) + { + ASSERT(m_pClipboard); + strPath+=m_pClipboard->GetAt(m_iSrcIndex)->GetPath(); + } + strPath+=m_strFilePath; + + return strPath; +} + +int CFileInfo::GetBufferIndex() const +{ + if (m_iSrcIndex != -1) + return m_pClipboard->GetAt(m_iSrcIndex)->GetBufferIndex(); + else + return BI_DEFAULT; +} + +/////////////////////////////////////////////////////////////////////// +// Array + +void CFileInfoArray::AddDir(CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, + const bool bRecurse, const bool bIncludeDirs, + const volatile bool* pbAbort) +{ + WIN32_FIND_DATA wfd; + CString strText; + + // init CFileInfo + CFileInfo finf; + finf.SetClipboard(m_pClipboard); // this is the link table (CClipboardArray) + + // append '\\' at the end of path if needed + if (strDirName.Right(1) != _T("\\")) + strDirName+=_T("\\"); + + strText = strDirName + _T("*"); + // Iterate through dirs & files + HANDLE hFind = FindFirstFile(strText, &wfd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + if ( !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) + { + finf.Create(&wfd, strDirName, iSrcIndex); + if (pFilters->Match(finf)) + Add(finf); + } + else if ( _tcscmp(wfd.cFileName, _T(".")) != 0 && _tcscmp(wfd.cFileName, _T("..")) != 0) + { + if (bIncludeDirs) + { + // Add directory itself + finf.Create(&wfd, strDirName, iSrcIndex); + Add(finf); + } + if (bRecurse) + { + strText = strDirName + wfd.cFileName+_T("\\"); + // Recurse Dirs + AddDir(strText, pFilters, iSrcIndex, bRecurse, bIncludeDirs, pbAbort); + } + } + } + while (((pbAbort == NULL) || (!*pbAbort)) && (FindNextFile(hFind, &wfd))); + + FindClose(hFind); + } +} + +int CFileInfoArray::AddFile(CString strFilePath, int iSrcIndex) +{ + CFileInfo finf; + + // CUSTOMIZATION3 - cut '\\' at the end of strFilePath, set relative path + if (strFilePath.Right(1) == _T("\\")) + strFilePath=strFilePath.Left(strFilePath.GetLength()-1); + + finf.Create(strFilePath, iSrcIndex); + return Add(finf); +} + + +////////////////////////////////////////////////////////////////////////////// +// CClipboardArray + +void CClipboardArray::Serialize(icpf::archive& ar, bool bData) +{ + if (ar.is_storing()) + { + // write data + int iSize=GetSize(); + ar<Serialize(ar, bData); + } + else + { + int iSize; + ar>>iSize; + + CClipboardEntry* pEntry; + for (int i=0;iSerialize(ar, bData); + } + } +} + +///////////////////////////////////////////////////////////////////////////// +// CClipboardEntry + +void CClipboardEntry::SetPath(const CString& strPath) +{ + m_strPath=strPath; // guaranteed without ending '\\' + if (m_strPath.Right(1) == _T('\\')) + m_strPath=m_strPath.Left(m_strPath.GetLength()-1); + + GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType); +} + +void CClipboardEntry::CalcBufferIndex(const CDestPath& dpDestPath) +{ + // what kind of buffer + if (m_uiDriveType == DRIVE_REMOTE || dpDestPath.GetDriveType() == DRIVE_REMOTE) + m_iBufferIndex=BI_LAN; + else if (m_uiDriveType == DRIVE_CDROM || dpDestPath.GetDriveType() == DRIVE_CDROM) + m_iBufferIndex=BI_CD; + else if (m_uiDriveType == DRIVE_FIXED && dpDestPath.GetDriveType() == DRIVE_FIXED) + { + // two hdd's - is this the same physical disk ? + if (m_iDriveNumber == dpDestPath.GetDriveNumber() || IsSamePhysicalDisk(m_iDriveNumber, dpDestPath.GetDriveNumber())) + m_iBufferIndex=BI_ONEDISK; + else + m_iBufferIndex=BI_TWODISKS; + } + else + m_iBufferIndex=BI_DEFAULT; +} + +void CClipboardEntry::Serialize(icpf::archive& ar, bool bData) +{ + if (bData) + { + if(ar.is_storing()) + { + ar<(m_bMove); + ar<>m_strPath; + unsigned char ucData; + ar>>ucData; + m_bMove=ucData != 0; + ar>>m_iDriveNumber; + ar>>m_uiDriveType; + ar>>m_iBufferIndex; + } + } + else + { + if(ar.is_storing()) + ar<>m_astrDstPaths; + } +} Index: src/ch/FileInfo.h =================================================================== diff -u -r52e4374b1e7044f77439e34581780750675125a7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FileInfo.h (.../FileInfo.h) (revision 52e4374b1e7044f77439e34581780750675125a7) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,338 +1,338 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/** - * @doc FILEINFO - * @module FileInfo.h 1.3 - Interface for the CFileInfo and CFileInfoArray classes | - * The classes contained in this file allow to gather recursively file information - * through directories. - * - * Codeguru & friends - * Coded by Antonio Tejada Lacaci. 1999 - * atejada@espanet.com - * CRC32 code by Floor A.C. Naaijkens - * - * Updates (aaaa-mm-dd): - * MANY CHANGES by Ixen Gerthannes... - * 1999-9-23 ATL: Opensource works! Again, Mr. Szucs (rszucs@cygron.hu) gets another bug: - * Missing "4-(dwRead & 0x3)" in the same lines as before, when calc'ing the padding mask. - * 1999-9-16 ATL: Corrected bug in GetCRC and GetChecksum as suggested by R�bert Szucs (rszucs@cygron.hu): - * There was a buffer overflow and checksum and crc for last dword +1 was calc'ed instead - * of the ones for last dword. Instead accessing buffer[dwRead +3...] it ought to access - * buffer[dwRead...] (shame on me! :'(). - * 1999-9-2 ATL: Corrected bug in AddFile(CString, LPARAM) as suggested by Nhycoh (Nhycoh44@yahoo.com): - * There was some weird stuff at CFileInfo::Create(strFilePath) - * stating strFilePath.GetLength()-nBarPos instead of nBarPos+1 - * (I'm quite sure I left my head on my pillow the day I did that %-#). - * 1999-6-27 ATL: Updated GetCRC & GetChecksum to avoid some bug cases - * 1999-4-7 ATL: Updated source code doc to conform Autoduck 2.0 standard - * 1999-4-7 ATL: Corrected bug in AddDir as suggested by Zhuang Yuyao (zhuangyy@koal.com): - * bIncludeDirs wasn't used if bRecurse was false. - * - * Keep this comment if you redistribute this file. And credit where credit's due! - */ - -#ifndef __FILEINFO_H__ -#define __FILEINFO_H__ - -#include -#include "afxdisp.h" -#include "DestPath.h" - -void FindFreeSubstituteName(CString strSrcPath, CString strDstPath, CString* pstrResult); -extern void GetDriveData(LPCTSTR lpszPath, int *piDrvNum, UINT *puiDrvType); - -// CFileInfo flags -// flag stating that file has been processed (used to determine if file can be deleted at the end of copying) -#define FIF_PROCESSED 0x00000001 - -class CFiltersArray; -///////////////////////////////////////////////////////////////////////////// -// CClipboardEntry -class CClipboardEntry -{ -public: - CClipboardEntry() { m_bMove=true; m_iDriveNumber=-1; m_uiDriveType=static_cast(-1); m_iBufferIndex=0; }; - CClipboardEntry(const CClipboardEntry& rEntry) { m_strPath=rEntry.m_strPath; m_bMove=rEntry.m_bMove; m_iDriveNumber=rEntry.m_iDriveNumber; m_uiDriveType=rEntry.m_uiDriveType; m_astrDstPaths.Copy(rEntry.m_astrDstPaths); }; - - void SetPath(const CString& strPath); - void CalcBufferIndex(const CDestPath& dpDestPath); - const CString& GetPath() const { return m_strPath; }; - - void SetMove(bool bValue) { m_bMove=bValue; }; - bool GetMove() { return m_bMove; }; - - int GetDriveNumber() const { return m_iDriveNumber; }; - UINT GetDriveType() const { return m_uiDriveType; }; - - int GetBufferIndex() const { return m_iBufferIndex; }; - - void Serialize(icpf::archive& ar, bool bData); - -private: - CString m_strPath; // path (ie. c:\\windows\\) - always with ending '\\' - bool m_bMove; // specifies if we can use MoveFile (if will be moved) - - int m_iDriveNumber; // disk number (-1 - none) - UINT m_uiDriveType; // path type - - int m_iBufferIndex; // buffer number, with which we'll copy this data - -public: - CStringArray m_astrDstPaths; // dest paths table for this group of paths -}; - -////////////////////////////////////////////////////////////////////////// -// CClipboardArray - -class CClipboardArray : public CArray -{ -public: - ~CClipboardArray() { RemoveAll(); }; - - void Serialize(icpf::archive& ar, bool bData); - - void SetAt(int nIndex, CClipboardEntry* pEntry) { delete [] GetAt(nIndex); SetAt(nIndex, pEntry); }; - void RemoveAt(int nIndex, int nCount = 1) { while (nCount--) { delete GetAt(nIndex); static_cast*>(this)->RemoveAt(nIndex, 1); } }; - void RemoveAll() { for (int i=0;i*>(this)->RemoveAll(); }; -}; - -class CFileInfo -{ -public: - CFileInfo(); - CFileInfo(const CFileInfo& finf); - ~CFileInfo(); - - // static member - static bool Exist(CString strPath); // check for file or folder existence - - void Create(const WIN32_FIND_DATA* pwfd, LPCTSTR pszFilePath, int iSrcIndex); - bool Create(CString strFilePath, int iSrcIndex); - - DWORD GetLength(void) const { return (DWORD) m_uhFileSize; }; - ULONGLONG GetLength64(void) const { return m_uhFileSize; }; - void SetLength64(ULONGLONG uhSize) { m_uhFileSize=uhSize; }; - - // disk - path and disk number (-1 if none - ie. net disk) - CString GetFileDrive(void) const; // returns string with src disk - int GetDriveNumber() const; // disk number A - 0, b-1, c-2, ... - UINT GetDriveType() const; // drive type - - CString GetFileDir(void) const; // @rdesc Returns \WINDOWS\ for C:\WINDOWS\WIN.INI - CString GetFileTitle(void) const; // @cmember returns WIN for C:\WINDOWS\WIN.INI - CString GetFileExt(void) const; /** @cmember returns INI for C:\WINDOWS\WIN.INI */ - CString GetFileRoot(void) const; /** @cmember returns C:\WINDOWS\ for C:\WINDOWS\WIN.INI */ - CString GetFileName(void) const; /** @cmember returns WIN.INI for C:\WINDOWS\WIN.INI */ - - const CString& GetFilePath(void) const { return m_strFilePath; } // returns path with m_strFilePath (probably not full) - CString GetFullFilePath() const; /** @cmember returns C:\WINDOWS\WIN.INI for C:\WINDOWS\WIN.INI */ - void SetFilePath(LPCTSTR lpszPath) { m_strFilePath=lpszPath; }; - - /* Get File times info (equivalent to CFindFile members) */ - const COleDateTime& GetCreationTime(void) const { return m_timCreation; }; /** @cmember returns creation time */ - const COleDateTime& GetLastAccessTime(void) const { return m_timLastAccess; }; /** @cmember returns last access time */ - const COleDateTime& GetLastWriteTime(void) const { return m_timLastWrite; }; /** @cmember returns las write time */ - - /* Get File attributes info (equivalent to CFindFile members) */ - DWORD GetAttributes(void) const { return m_dwAttributes; }; /** @cmember returns file attributes */ - bool IsDirectory(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }; /** @cmember returns TRUE if the file is a directory */ - bool IsArchived(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }; /** @cmember Returns TRUE if the file has archive bit set */ - bool IsReadOnly(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_READONLY) != 0; }; /** @cmember Returns TRUE if the file is read-only */ - bool IsCompressed(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }; /** @cmember Returns TRUE if the file is compressed */ - bool IsSystem(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_SYSTEM) != 0; }; /** @cmember Returns TRUE if the file is a system file */ - bool IsHidden(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_HIDDEN) != 0; }; /** @cmember Returns TRUE if the file is hidden */ - bool IsTemporary(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0; }; /** @cmember Returns TRUE if the file is temporary */ - bool IsNormal(void) const { return m_dwAttributes == 0; }; /** @cmember Returns TRUE if the file is a normal file */ - - uint_t GetFlags() const { return m_uiFlags; } - void SetFlags(uint_t uiFlags, uint_t uiMask = 0xffffffff) { m_uiFlags = (m_uiFlags & ~(uiFlags & uiMask)) | (uiFlags & uiMask); } - - // operations - void SetClipboard(CClipboardArray *pClipboard) { m_pClipboard=pClipboard; }; - CString GetDestinationPath(CString strPath, unsigned char ucCopyNumber, int iFlags); - - void SetSrcIndex(int iIndex) { m_iSrcIndex=iIndex; }; - int GetSrcIndex() const { return m_iSrcIndex; }; - - bool GetMove() { if (m_iSrcIndex != -1) return m_pClipboard->GetAt(m_iSrcIndex)->GetMove(); else return true; }; - - int GetBufferIndex() const; - - // operators - bool operator==(const CFileInfo& rInfo); - - // (re)/store data - void Store(icpf::archive& ar); - void Load(icpf::archive& ar); -private: - CString m_strFilePath; // contains relative path (first path is in CClipboardArray) - int m_iSrcIndex; // index in CClipboardArray table (which contains the first part of the path) - - DWORD m_dwAttributes; // attributes - ULONGLONG m_uhFileSize; /** @cmember File of size. (COM states LONGLONG as hyper, so "uh" means unsigned hyper) */ - COleDateTime m_timCreation; /** @cmember Creation time */ - COleDateTime m_timLastAccess; /** @cmember Last Access time */ - COleDateTime m_timLastWrite; /** @cmember Last write time */ - - uint_t m_uiFlags; - // ptrs to elements providing data - CClipboardArray *m_pClipboard; -}; - -/** -* @class Allows to retrieve s from files/directories in a directory -*/ -class CFileInfoArray : public CArray -{ -public: - /** @access Public members */ - - /** - * @cmember Default constructor - */ - CFileInfoArray() { m_pClipboard=NULL; SetSize(0, 5000); }; - void Init(CClipboardArray* pClipboard) { m_pClipboard=pClipboard; }; - - /** - * @cmember Adds a file or all contained in a directory to the CFileInfoArray - * Only "static" data for CFileInfo is filled (by default CRC and checksum are NOT - * calculated when inserting CFileInfos). Returns the number of s added to the array - * @parm Name of the directory, ended in backslash. - * @parm Mask of files to add in case that strDirName is a directory - * @parm Wether to recurse or not subdirectories - * @parmopt Parameter to pass to protected member function AddFileInfo - * @parmopt Wether to add or not CFileInfos for directories - * @parmopt Pointer to a variable to signal abort of directory retrieval - * (multithreaded apps). - * @parmopt pulCount Pointer to a variable incremented each time a CFileInfo is added to the - * array (multithreaded apps). - * @xref - */ - void AddDir(CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, - const bool bRecurse, const bool bIncludeDirs, const volatile bool* pbAbort=NULL); - - /** - * @cmember Adds a single file or directory to the CFileInfoArray. In case of directory, files - * contained in the directory are NOT added to the array. - * Returns the position in the array where the was added (-1 if - * wasn't added) - * @parm Name of the file or directory to add. NOT ended with backslash. - * @parm Parameter to pass to protected member function AddFileInfo. - * @xref - */ - int AddFile(CString strFilePath, int iSrcIndex); - - // store/restore - void Store(icpf::archive& ar, bool bOnlyFlags) - { - INT_PTR iSize = GetSize(); - ar << iSize; - for (INT_PTR i=0;i>iSize; - SetSize(iSize, 5000); - CFileInfo fi; - fi.SetClipboard(m_pClipboard); - uint_t uiFlags = 0; - for (INT_PTR i=0;i> uiFlags; - rInfo.SetFlags(uiFlags); - } - else - { - fi.Load(ar); - SetAt(i, fi); - } - } - } - -protected: - CClipboardArray* m_pClipboard; -}; - - -/** -@ex This code adds all files in root directory and its subdirectories (but not directories themselves) to the array and TRACEs them: | - - CFileInfoArray fia; - - fia.AddDir( - "C:\\", // Directory - "*.*", // Filemask (all files) - TRUE, // Recurse subdirs - fia::AP_SORTBYNAME | fia::AP_SORTASCENDING, // Sort by name and ascending - FALSE // Do not add array entries for directories (only for files) - ); - TRACE("Dumping directory contents\n"); - for (int i=0;i Codeguru & friends + * Coded by Antonio Tejada Lacaci. 1999 + * atejada@espanet.com + * CRC32 code by Floor A.C. Naaijkens + * + * Updates (aaaa-mm-dd): + * MANY CHANGES by Ixen Gerthannes... + * 1999-9-23 ATL: Opensource works! Again, Mr. Szucs (rszucs@cygron.hu) gets another bug: + * Missing "4-(dwRead & 0x3)" in the same lines as before, when calc'ing the padding mask. + * 1999-9-16 ATL: Corrected bug in GetCRC and GetChecksum as suggested by R�bert Szucs (rszucs@cygron.hu): + * There was a buffer overflow and checksum and crc for last dword +1 was calc'ed instead + * of the ones for last dword. Instead accessing buffer[dwRead +3...] it ought to access + * buffer[dwRead...] (shame on me! :'(). + * 1999-9-2 ATL: Corrected bug in AddFile(CString, LPARAM) as suggested by Nhycoh (Nhycoh44@yahoo.com): + * There was some weird stuff at CFileInfo::Create(strFilePath) + * stating strFilePath.GetLength()-nBarPos instead of nBarPos+1 + * (I'm quite sure I left my head on my pillow the day I did that %-#). + * 1999-6-27 ATL: Updated GetCRC & GetChecksum to avoid some bug cases + * 1999-4-7 ATL: Updated source code doc to conform Autoduck 2.0 standard + * 1999-4-7 ATL: Corrected bug in AddDir as suggested by Zhuang Yuyao (zhuangyy@koal.com): + * bIncludeDirs wasn't used if bRecurse was false. + * + * Keep this comment if you redistribute this file. And credit where credit's due! + */ + +#ifndef __FILEINFO_H__ +#define __FILEINFO_H__ + +#include +#include "afxdisp.h" +#include "DestPath.h" + +void FindFreeSubstituteName(CString strSrcPath, CString strDstPath, CString* pstrResult); +extern void GetDriveData(LPCTSTR lpszPath, int *piDrvNum, UINT *puiDrvType); + +// CFileInfo flags +// flag stating that file has been processed (used to determine if file can be deleted at the end of copying) +#define FIF_PROCESSED 0x00000001 + +class CFiltersArray; +///////////////////////////////////////////////////////////////////////////// +// CClipboardEntry +class CClipboardEntry +{ +public: + CClipboardEntry() { m_bMove=true; m_iDriveNumber=-1; m_uiDriveType=static_cast(-1); m_iBufferIndex=0; }; + CClipboardEntry(const CClipboardEntry& rEntry) { m_strPath=rEntry.m_strPath; m_bMove=rEntry.m_bMove; m_iDriveNumber=rEntry.m_iDriveNumber; m_uiDriveType=rEntry.m_uiDriveType; m_astrDstPaths.Copy(rEntry.m_astrDstPaths); }; + + void SetPath(const CString& strPath); + void CalcBufferIndex(const CDestPath& dpDestPath); + const CString& GetPath() const { return m_strPath; }; + + void SetMove(bool bValue) { m_bMove=bValue; }; + bool GetMove() { return m_bMove; }; + + int GetDriveNumber() const { return m_iDriveNumber; }; + UINT GetDriveType() const { return m_uiDriveType; }; + + int GetBufferIndex() const { return m_iBufferIndex; }; + + void Serialize(icpf::archive& ar, bool bData); + +private: + CString m_strPath; // path (ie. c:\\windows\\) - always with ending '\\' + bool m_bMove; // specifies if we can use MoveFile (if will be moved) + + int m_iDriveNumber; // disk number (-1 - none) + UINT m_uiDriveType; // path type + + int m_iBufferIndex; // buffer number, with which we'll copy this data + +public: + CStringArray m_astrDstPaths; // dest paths table for this group of paths +}; + +////////////////////////////////////////////////////////////////////////// +// CClipboardArray + +class CClipboardArray : public CArray +{ +public: + ~CClipboardArray() { RemoveAll(); }; + + void Serialize(icpf::archive& ar, bool bData); + + void SetAt(int nIndex, CClipboardEntry* pEntry) { delete [] GetAt(nIndex); SetAt(nIndex, pEntry); }; + void RemoveAt(int nIndex, int nCount = 1) { while (nCount--) { delete GetAt(nIndex); static_cast*>(this)->RemoveAt(nIndex, 1); } }; + void RemoveAll() { for (int i=0;i*>(this)->RemoveAll(); }; +}; + +class CFileInfo +{ +public: + CFileInfo(); + CFileInfo(const CFileInfo& finf); + ~CFileInfo(); + + // static member + static bool Exist(CString strPath); // check for file or folder existence + + void Create(const WIN32_FIND_DATA* pwfd, LPCTSTR pszFilePath, int iSrcIndex); + bool Create(CString strFilePath, int iSrcIndex); + + DWORD GetLength(void) const { return (DWORD) m_uhFileSize; }; + ULONGLONG GetLength64(void) const { return m_uhFileSize; }; + void SetLength64(ULONGLONG uhSize) { m_uhFileSize=uhSize; }; + + // disk - path and disk number (-1 if none - ie. net disk) + CString GetFileDrive(void) const; // returns string with src disk + int GetDriveNumber() const; // disk number A - 0, b-1, c-2, ... + UINT GetDriveType() const; // drive type + + CString GetFileDir(void) const; // @rdesc Returns \WINDOWS\ for C:\WINDOWS\WIN.INI + CString GetFileTitle(void) const; // @cmember returns WIN for C:\WINDOWS\WIN.INI + CString GetFileExt(void) const; /** @cmember returns INI for C:\WINDOWS\WIN.INI */ + CString GetFileRoot(void) const; /** @cmember returns C:\WINDOWS\ for C:\WINDOWS\WIN.INI */ + CString GetFileName(void) const; /** @cmember returns WIN.INI for C:\WINDOWS\WIN.INI */ + + const CString& GetFilePath(void) const { return m_strFilePath; } // returns path with m_strFilePath (probably not full) + CString GetFullFilePath() const; /** @cmember returns C:\WINDOWS\WIN.INI for C:\WINDOWS\WIN.INI */ + void SetFilePath(LPCTSTR lpszPath) { m_strFilePath=lpszPath; }; + + /* Get File times info (equivalent to CFindFile members) */ + const COleDateTime& GetCreationTime(void) const { return m_timCreation; }; /** @cmember returns creation time */ + const COleDateTime& GetLastAccessTime(void) const { return m_timLastAccess; }; /** @cmember returns last access time */ + const COleDateTime& GetLastWriteTime(void) const { return m_timLastWrite; }; /** @cmember returns las write time */ + + /* Get File attributes info (equivalent to CFindFile members) */ + DWORD GetAttributes(void) const { return m_dwAttributes; }; /** @cmember returns file attributes */ + bool IsDirectory(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }; /** @cmember returns TRUE if the file is a directory */ + bool IsArchived(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }; /** @cmember Returns TRUE if the file has archive bit set */ + bool IsReadOnly(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_READONLY) != 0; }; /** @cmember Returns TRUE if the file is read-only */ + bool IsCompressed(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }; /** @cmember Returns TRUE if the file is compressed */ + bool IsSystem(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_SYSTEM) != 0; }; /** @cmember Returns TRUE if the file is a system file */ + bool IsHidden(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_HIDDEN) != 0; }; /** @cmember Returns TRUE if the file is hidden */ + bool IsTemporary(void) const { return (m_dwAttributes & FILE_ATTRIBUTE_TEMPORARY) != 0; }; /** @cmember Returns TRUE if the file is temporary */ + bool IsNormal(void) const { return m_dwAttributes == 0; }; /** @cmember Returns TRUE if the file is a normal file */ + + uint_t GetFlags() const { return m_uiFlags; } + void SetFlags(uint_t uiFlags, uint_t uiMask = 0xffffffff) { m_uiFlags = (m_uiFlags & ~(uiFlags & uiMask)) | (uiFlags & uiMask); } + + // operations + void SetClipboard(CClipboardArray *pClipboard) { m_pClipboard=pClipboard; }; + CString GetDestinationPath(CString strPath, unsigned char ucCopyNumber, int iFlags); + + void SetSrcIndex(int iIndex) { m_iSrcIndex=iIndex; }; + int GetSrcIndex() const { return m_iSrcIndex; }; + + bool GetMove() { if (m_iSrcIndex != -1) return m_pClipboard->GetAt(m_iSrcIndex)->GetMove(); else return true; }; + + int GetBufferIndex() const; + + // operators + bool operator==(const CFileInfo& rInfo); + + // (re)/store data + void Store(icpf::archive& ar); + void Load(icpf::archive& ar); +private: + CString m_strFilePath; // contains relative path (first path is in CClipboardArray) + int m_iSrcIndex; // index in CClipboardArray table (which contains the first part of the path) + + DWORD m_dwAttributes; // attributes + ULONGLONG m_uhFileSize; /** @cmember File of size. (COM states LONGLONG as hyper, so "uh" means unsigned hyper) */ + COleDateTime m_timCreation; /** @cmember Creation time */ + COleDateTime m_timLastAccess; /** @cmember Last Access time */ + COleDateTime m_timLastWrite; /** @cmember Last write time */ + + uint_t m_uiFlags; + // ptrs to elements providing data + CClipboardArray *m_pClipboard; +}; + +/** +* @class Allows to retrieve s from files/directories in a directory +*/ +class CFileInfoArray : public CArray +{ +public: + /** @access Public members */ + + /** + * @cmember Default constructor + */ + CFileInfoArray() { m_pClipboard=NULL; SetSize(0, 5000); }; + void Init(CClipboardArray* pClipboard) { m_pClipboard=pClipboard; }; + + /** + * @cmember Adds a file or all contained in a directory to the CFileInfoArray + * Only "static" data for CFileInfo is filled (by default CRC and checksum are NOT + * calculated when inserting CFileInfos). Returns the number of s added to the array + * @parm Name of the directory, ended in backslash. + * @parm Mask of files to add in case that strDirName is a directory + * @parm Wether to recurse or not subdirectories + * @parmopt Parameter to pass to protected member function AddFileInfo + * @parmopt Wether to add or not CFileInfos for directories + * @parmopt Pointer to a variable to signal abort of directory retrieval + * (multithreaded apps). + * @parmopt pulCount Pointer to a variable incremented each time a CFileInfo is added to the + * array (multithreaded apps). + * @xref + */ + void AddDir(CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, + const bool bRecurse, const bool bIncludeDirs, const volatile bool* pbAbort=NULL); + + /** + * @cmember Adds a single file or directory to the CFileInfoArray. In case of directory, files + * contained in the directory are NOT added to the array. + * Returns the position in the array where the was added (-1 if + * wasn't added) + * @parm Name of the file or directory to add. NOT ended with backslash. + * @parm Parameter to pass to protected member function AddFileInfo. + * @xref + */ + int AddFile(CString strFilePath, int iSrcIndex); + + // store/restore + void Store(icpf::archive& ar, bool bOnlyFlags) + { + INT_PTR iSize = GetSize(); + ar << iSize; + for (INT_PTR i=0;i>iSize; + SetSize(iSize, 5000); + CFileInfo fi; + fi.SetClipboard(m_pClipboard); + uint_t uiFlags = 0; + for (INT_PTR i=0;i> uiFlags; + rInfo.SetFlags(uiFlags); + } + else + { + fi.Load(ar); + SetAt(i, fi); + } + } + } + +protected: + CClipboardArray* m_pClipboard; +}; + + +/** +@ex This code adds all files in root directory and its subdirectories (but not directories themselves) to the array and TRACEs them: | + + CFileInfoArray fia; + + fia.AddDir( + "C:\\", // Directory + "*.*", // Filemask (all files) + TRUE, // Recurse subdirs + fia::AP_SORTBYNAME | fia::AP_SORTASCENDING, // Sort by name and ascending + FALSE // Do not add array entries for directories (only for files) + ); + TRACE("Dumping directory contents\n"); + for (int i=0;iLoadString(IDS_BYTE_STRING+i); - m_ctlSize1Multi.AddString(pszData); - m_ctlSize2Multi.AddString(pszData); - } - - // strings <, <=, ... - for (int i=0;i<5;i++) - { - pszData=GetResManager()->LoadString(IDS_LT_STRING+i); - m_ctlSizeType1.AddString(pszData); - m_ctlSizeType2.AddString(pszData); - m_ctlDateType1.AddString(pszData); - m_ctlDateType2.AddString(pszData); - } - - for (int i=0;i<3;i++) - { - m_ctlDateType.AddString(GetResManager()->LoadString(IDS_DATECREATED_STRING+i)); - } - - // copy data from CFileFilter to a dialog - mask - m_bFilter=m_ffFilter.m_bUseMask; - - CString strData; - m_ctlFilter.SetCurSel(m_ctlFilter.AddString(m_ffFilter.GetCombinedMask(strData))); - for (int i=0;iLoadString(IDS_BYTE_STRING+i); - m_ctlSize1Multi.AddString(pszData); - m_ctlSize2Multi.AddString(pszData); - } - - // selection - m_ctlSize1Multi.SetCurSel(iPos[0]); - m_ctlSize2Multi.SetCurSel(iPos[1]); - - iPos[0]=m_ctlSizeType1.GetCurSel(); - iPos[1]=m_ctlSizeType2.GetCurSel(); - iPos[2]=m_ctlDateType1.GetCurSel(); - iPos[3]=m_ctlDateType2.GetCurSel(); - - m_ctlSizeType1.ResetContent(); - m_ctlSizeType2.ResetContent(); - m_ctlDateType1.ResetContent(); - m_ctlDateType2.ResetContent(); - - // strings <, <=, ... - for (int i=0;i<5;i++) - { - pszData=GetResManager()->LoadString(IDS_LT_STRING+i); - m_ctlSizeType1.AddString(pszData); - m_ctlSizeType2.AddString(pszData); - m_ctlDateType1.AddString(pszData); - m_ctlDateType2.AddString(pszData); - } - - m_ctlSizeType1.SetCurSel(iPos[0]); - m_ctlSizeType2.SetCurSel(iPos[1]); - m_ctlDateType1.SetCurSel(iPos[2]); - m_ctlDateType2.SetCurSel(iPos[3]); - - iPos[0]=m_ctlDateType.GetCurSel(); - m_ctlDateType.ResetContent(); - for (int i=0;i<3;i++) - { - m_ctlDateType.AddString(GetResManager()->LoadString(IDS_DATECREATED_STRING+i)); - } - m_ctlDateType.SetCurSel(iPos[0]); -} - -void CFilterDlg::SetSize1(unsigned __int64 ullSize) -{ - if ((ullSize % 1048576) == 0 && ullSize != 0) - { - m_uiSize1=static_cast(ullSize/1048576); - m_ctlSize1Multi.SetCurSel(2); - } - else if ((ullSize % 1024) == 0 && ullSize != 0) - { - m_uiSize1=static_cast(ullSize/1024); - m_ctlSize1Multi.SetCurSel(1); - } - else - { - m_uiSize1=static_cast(ullSize); - m_ctlSize1Multi.SetCurSel(0); - } -} - -void CFilterDlg::SetSize2(unsigned __int64 ullSize) -{ - if ((ullSize % 1048576) == 0 && ullSize != 0) - { - m_uiSize2=static_cast(ullSize/1048576); - m_ctlSize2Multi.SetCurSel(2); - } - else if ((ullSize % 1024) == 0 && ullSize != 0) - { - m_uiSize2=static_cast(ullSize/1024); - m_ctlSize2Multi.SetCurSel(1); - } - else - { - m_uiSize2=static_cast(ullSize); - m_ctlSize2Multi.SetCurSel(0); - } -} - -void CFilterDlg::EnableControls() -{ - UpdateData(TRUE); - // mask - m_ctlFilter.EnableWindow(m_bFilter); - - m_ctlExcludeMask.EnableWindow(m_bExclude); - - // size - m_ctlSizeType1.EnableWindow(m_bSize); - m_ctlSizeType2.EnableWindow(m_bSize && m_bSize2); - GetDlgItem(IDC_SIZE1_EDIT)->EnableWindow(m_bSize); - GetDlgItem(IDC_SIZE2_EDIT)->EnableWindow(m_bSize && m_bSize2); - GetDlgItem(IDC_SIZE1_SPIN)->EnableWindow(m_bSize); - GetDlgItem(IDC_SIZE2_SPIN)->EnableWindow(m_bSize && m_bSize2); - GetDlgItem(IDC_SIZE2_CHECK)->EnableWindow(m_bSize); - m_ctlSize1Multi.EnableWindow(m_bSize); - m_ctlSize2Multi.EnableWindow(m_bSize && m_bSize2); - - // date - CTime tmTemp; - bool bSecond=((m_ctlDate1.GetTime(tmTemp) == GDT_VALID) || (m_ctlTime1.GetTime(tmTemp) == GDT_VALID)); - m_ctlDateType.EnableWindow(m_bDate); - GetDlgItem(IDC_DATE2_CHECK)->EnableWindow(m_bDate && bSecond); - m_ctlDateType1.EnableWindow(m_bDate); - m_ctlDateType2.EnableWindow(m_bDate && m_bDate2 && bSecond); - m_ctlDate1.EnableWindow(m_bDate); - m_ctlDate2.EnableWindow(m_bDate && m_bDate2 && bSecond); - m_ctlTime1.EnableWindow(m_bDate); - m_ctlTime2.EnableWindow(m_bDate && m_bDate2 && bSecond); - - // attrib - GetDlgItem(IDC_ARCHIVE_CHECK)->EnableWindow(m_bAttributes); - GetDlgItem(IDC_READONLY_CHECK)->EnableWindow(m_bAttributes); - GetDlgItem(IDC_HIDDEN_CHECK)->EnableWindow(m_bAttributes); - GetDlgItem(IDC_SYSTEM_CHECK)->EnableWindow(m_bAttributes); - GetDlgItem(IDC_DIRECTORY_CHECK)->EnableWindow(m_bAttributes); -} - -void CFilterDlg::OnOK() -{ - UpdateData(TRUE); - - // CFileFilter --> dialogu - mask - CString strText; - m_ctlFilter.GetWindowText(strText); - m_ffFilter.m_bUseMask=((m_bFilter != 0) && !strText.IsEmpty()); - m_ffFilter.SetCombinedMask(strText); - - m_ctlExcludeMask.GetWindowText(strText); - m_ffFilter.m_bUseExcludeMask=(m_bExclude != 0) && !strText.IsEmpty(); - m_ffFilter.SetCombinedExcludeMask(strText); - - // size - m_ffFilter.m_bUseSize=(m_bSize != 0); - m_ffFilter.m_bUseSize2=(m_bSize2 != 0); - - m_ffFilter.m_iSizeType1=m_ctlSizeType1.GetCurSel(); - m_ffFilter.m_iSizeType2=m_ctlSizeType2.GetCurSel(); - - m_ffFilter.m_ullSize1=static_cast(m_uiSize1)*static_cast(GetMultiplier(m_ctlSize1Multi.GetCurSel())); - m_ffFilter.m_ullSize2=static_cast(m_uiSize2)*static_cast(GetMultiplier(m_ctlSize2Multi.GetCurSel())); - - // date - m_ffFilter.m_iDateType=m_ctlDateType.GetCurSel(); - - m_ffFilter.m_iDateType1=m_ctlDateType1.GetCurSel(); - m_ffFilter.m_iDateType2=m_ctlDateType2.GetCurSel(); - - m_ffFilter.m_bDate1=m_ctlDate1.GetTime(m_ffFilter.m_tDate1) == GDT_VALID; - m_ffFilter.m_bDate2=m_ctlDate2.GetTime(m_ffFilter.m_tDate2) == GDT_VALID; - m_ffFilter.m_bTime1=m_ctlTime1.GetTime(m_ffFilter.m_tTime1) == GDT_VALID; - m_ffFilter.m_bTime2=m_ctlTime2.GetTime(m_ffFilter.m_tTime2) == GDT_VALID; - - m_ffFilter.m_bUseDate=(m_bDate != 0) && (m_ffFilter.m_bDate1 || m_ffFilter.m_bTime1); - m_ffFilter.m_bUseDate2=(m_bDate2 != 0) && (m_ffFilter.m_bDate2 || m_ffFilter.m_bTime2); - - // attributes - m_ffFilter.m_bUseAttributes=(m_bAttributes != 0); - m_ffFilter.m_iArchive=m_iArchive; - m_ffFilter.m_iReadOnly=m_iReadOnly; - m_ffFilter.m_iHidden=m_iHidden; - m_ffFilter.m_iSystem=m_iSystem; - m_ffFilter.m_iDirectory=m_iDirectory; - - CLanguageDialog::OnOK(); -} - -int CFilterDlg::GetMultiplier(int iIndex) -{ - switch (iIndex) - { - case 0: - return 1; - case 1: - return 1024; - case 2: - return 1048576; - default: - ASSERT(true); // bad index - return 1; - } -} - -void CFilterDlg::OnAttributesCheck() -{ - EnableControls(); -} - -void CFilterDlg::OnDateCheck() -{ - EnableControls(); -} - -void CFilterDlg::OnDate2Check() -{ - EnableControls(); -} - -void CFilterDlg::OnFilterCheck() -{ - EnableControls(); -} - -void CFilterDlg::OnSizeCheck() -{ - EnableControls(); -} - -void CFilterDlg::OnSize2Check() -{ - EnableControls(); -} - -void CFilterDlg::OnExcludemaskCheck() -{ - EnableControls(); -} - -void CFilterDlg::OnDatetimechangeTime1Datetimepicker(NMHDR* /*pNMHDR*/, LRESULT* pResult) -{ - EnableControls(); - - *pResult = 0; -} - -void CFilterDlg::OnDatetimechangeDate1Datetimepicker(NMHDR* /*pNMHDR*/, LRESULT* pResult) -{ - EnableControls(); - - *pResult = 0; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "FilterDlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CFilterDlg dialog + +CFilterDlg::CFilterDlg() + :ictranslate::CLanguageDialog(CFilterDlg::IDD) +{ + //{{AFX_DATA_INIT(CFilterDlg) + m_iArchive = FALSE; + m_bAttributes = FALSE; + m_bDate = FALSE; + m_bDate2 = FALSE; + m_iDirectory = FALSE; + m_bFilter = FALSE; + m_iHidden = FALSE; + m_iReadOnly = FALSE; + m_bSize = FALSE; + m_uiSize1 = 0; + m_bSize2 = FALSE; + m_uiSize2 = 0; + m_iSystem = FALSE; + m_bExclude = FALSE; + //}}AFX_DATA_INIT +} + + +void CFilterDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CFilterDlg) + DDX_Control(pDX, IDC_FILTEREXCLUDE_COMBO, m_ctlExcludeMask); + DDX_Control(pDX, IDC_SIZE2_SPIN, m_ctlSpin2); + DDX_Control(pDX, IDC_SIZE1_SPIN, m_ctlSpin1); + DDX_Control(pDX, IDC_TIME2_DATETIMEPICKER, m_ctlTime2); + DDX_Control(pDX, IDC_TIME1_DATETIMEPICKER, m_ctlTime1); + DDX_Control(pDX, IDC_SIZETYPE2_COMBO, m_ctlSizeType2); + DDX_Control(pDX, IDC_SIZETYPE1_COMBO, m_ctlSizeType1); + DDX_Control(pDX, IDC_SIZE2MULTI_COMBO, m_ctlSize2Multi); + DDX_Control(pDX, IDC_SIZE1MULTI_COMBO, m_ctlSize1Multi); + DDX_Control(pDX, IDC_FILTER_COMBO, m_ctlFilter); + DDX_Control(pDX, IDC_DATETYPE_COMBO, m_ctlDateType); + DDX_Control(pDX, IDC_DATE2TYPE_COMBO, m_ctlDateType2); + DDX_Control(pDX, IDC_DATE2_DATETIMEPICKER, m_ctlDate2); + DDX_Control(pDX, IDC_DATE1TYPE_COMBO, m_ctlDateType1); + DDX_Control(pDX, IDC_DATE1_DATETIMEPICKER, m_ctlDate1); + DDX_Check(pDX, IDC_ARCHIVE_CHECK, m_iArchive); + DDX_Check(pDX, IDC_ATTRIBUTES_CHECK, m_bAttributes); + DDX_Check(pDX, IDC_DATE_CHECK, m_bDate); + DDX_Check(pDX, IDC_DATE2_CHECK, m_bDate2); + DDX_Check(pDX, IDC_DIRECTORY_CHECK, m_iDirectory); + DDX_Check(pDX, IDC_FILTER_CHECK, m_bFilter); + DDX_Check(pDX, IDC_HIDDEN_CHECK, m_iHidden); + DDX_Check(pDX, IDC_READONLY_CHECK, m_iReadOnly); + DDX_Check(pDX, IDC_SIZE_CHECK, m_bSize); + DDX_Text(pDX, IDC_SIZE1_EDIT, m_uiSize1); + DDX_Check(pDX, IDC_SIZE2_CHECK, m_bSize2); + DDX_Text(pDX, IDC_SIZE2_EDIT, m_uiSize2); + DDX_Check(pDX, IDC_SYSTEM_CHECK, m_iSystem); + DDX_Check(pDX, IDC_EXCLUDEMASK_CHECK, m_bExclude); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CFilterDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CFilterDlg) + ON_BN_CLICKED(IDC_ATTRIBUTES_CHECK, OnAttributesCheck) + ON_BN_CLICKED(IDC_DATE_CHECK, OnDateCheck) + ON_BN_CLICKED(IDC_DATE2_CHECK, OnDate2Check) + ON_BN_CLICKED(IDC_FILTER_CHECK, OnFilterCheck) + ON_BN_CLICKED(IDC_SIZE_CHECK, OnSizeCheck) + ON_BN_CLICKED(IDC_SIZE2_CHECK, OnSize2Check) + ON_BN_CLICKED(IDC_EXCLUDEMASK_CHECK, OnExcludemaskCheck) + ON_NOTIFY(DTN_DATETIMECHANGE, IDC_TIME1_DATETIMEPICKER, OnDatetimechangeTime1Datetimepicker) + ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATE1_DATETIMEPICKER, OnDatetimechangeDate1Datetimepicker) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CFilterDlg message handlers + +BOOL CFilterDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // fill the combos with data + const TCHAR *pszData; + for (int i=0;i<3;i++) + { + pszData=GetResManager()->LoadString(IDS_BYTE_STRING+i); + m_ctlSize1Multi.AddString(pszData); + m_ctlSize2Multi.AddString(pszData); + } + + // strings <, <=, ... + for (int i=0;i<5;i++) + { + pszData=GetResManager()->LoadString(IDS_LT_STRING+i); + m_ctlSizeType1.AddString(pszData); + m_ctlSizeType2.AddString(pszData); + m_ctlDateType1.AddString(pszData); + m_ctlDateType2.AddString(pszData); + } + + for (int i=0;i<3;i++) + { + m_ctlDateType.AddString(GetResManager()->LoadString(IDS_DATECREATED_STRING+i)); + } + + // copy data from CFileFilter to a dialog - mask + m_bFilter=m_ffFilter.m_bUseMask; + + CString strData; + m_ctlFilter.SetCurSel(m_ctlFilter.AddString(m_ffFilter.GetCombinedMask(strData))); + for (int i=0;iLoadString(IDS_BYTE_STRING+i); + m_ctlSize1Multi.AddString(pszData); + m_ctlSize2Multi.AddString(pszData); + } + + // selection + m_ctlSize1Multi.SetCurSel(iPos[0]); + m_ctlSize2Multi.SetCurSel(iPos[1]); + + iPos[0]=m_ctlSizeType1.GetCurSel(); + iPos[1]=m_ctlSizeType2.GetCurSel(); + iPos[2]=m_ctlDateType1.GetCurSel(); + iPos[3]=m_ctlDateType2.GetCurSel(); + + m_ctlSizeType1.ResetContent(); + m_ctlSizeType2.ResetContent(); + m_ctlDateType1.ResetContent(); + m_ctlDateType2.ResetContent(); + + // strings <, <=, ... + for (int i=0;i<5;i++) + { + pszData=GetResManager()->LoadString(IDS_LT_STRING+i); + m_ctlSizeType1.AddString(pszData); + m_ctlSizeType2.AddString(pszData); + m_ctlDateType1.AddString(pszData); + m_ctlDateType2.AddString(pszData); + } + + m_ctlSizeType1.SetCurSel(iPos[0]); + m_ctlSizeType2.SetCurSel(iPos[1]); + m_ctlDateType1.SetCurSel(iPos[2]); + m_ctlDateType2.SetCurSel(iPos[3]); + + iPos[0]=m_ctlDateType.GetCurSel(); + m_ctlDateType.ResetContent(); + for (int i=0;i<3;i++) + { + m_ctlDateType.AddString(GetResManager()->LoadString(IDS_DATECREATED_STRING+i)); + } + m_ctlDateType.SetCurSel(iPos[0]); +} + +void CFilterDlg::SetSize1(unsigned __int64 ullSize) +{ + if ((ullSize % 1048576) == 0 && ullSize != 0) + { + m_uiSize1=static_cast(ullSize/1048576); + m_ctlSize1Multi.SetCurSel(2); + } + else if ((ullSize % 1024) == 0 && ullSize != 0) + { + m_uiSize1=static_cast(ullSize/1024); + m_ctlSize1Multi.SetCurSel(1); + } + else + { + m_uiSize1=static_cast(ullSize); + m_ctlSize1Multi.SetCurSel(0); + } +} + +void CFilterDlg::SetSize2(unsigned __int64 ullSize) +{ + if ((ullSize % 1048576) == 0 && ullSize != 0) + { + m_uiSize2=static_cast(ullSize/1048576); + m_ctlSize2Multi.SetCurSel(2); + } + else if ((ullSize % 1024) == 0 && ullSize != 0) + { + m_uiSize2=static_cast(ullSize/1024); + m_ctlSize2Multi.SetCurSel(1); + } + else + { + m_uiSize2=static_cast(ullSize); + m_ctlSize2Multi.SetCurSel(0); + } +} + +void CFilterDlg::EnableControls() +{ + UpdateData(TRUE); + // mask + m_ctlFilter.EnableWindow(m_bFilter); + + m_ctlExcludeMask.EnableWindow(m_bExclude); + + // size + m_ctlSizeType1.EnableWindow(m_bSize); + m_ctlSizeType2.EnableWindow(m_bSize && m_bSize2); + GetDlgItem(IDC_SIZE1_EDIT)->EnableWindow(m_bSize); + GetDlgItem(IDC_SIZE2_EDIT)->EnableWindow(m_bSize && m_bSize2); + GetDlgItem(IDC_SIZE1_SPIN)->EnableWindow(m_bSize); + GetDlgItem(IDC_SIZE2_SPIN)->EnableWindow(m_bSize && m_bSize2); + GetDlgItem(IDC_SIZE2_CHECK)->EnableWindow(m_bSize); + m_ctlSize1Multi.EnableWindow(m_bSize); + m_ctlSize2Multi.EnableWindow(m_bSize && m_bSize2); + + // date + CTime tmTemp; + bool bSecond=((m_ctlDate1.GetTime(tmTemp) == GDT_VALID) || (m_ctlTime1.GetTime(tmTemp) == GDT_VALID)); + m_ctlDateType.EnableWindow(m_bDate); + GetDlgItem(IDC_DATE2_CHECK)->EnableWindow(m_bDate && bSecond); + m_ctlDateType1.EnableWindow(m_bDate); + m_ctlDateType2.EnableWindow(m_bDate && m_bDate2 && bSecond); + m_ctlDate1.EnableWindow(m_bDate); + m_ctlDate2.EnableWindow(m_bDate && m_bDate2 && bSecond); + m_ctlTime1.EnableWindow(m_bDate); + m_ctlTime2.EnableWindow(m_bDate && m_bDate2 && bSecond); + + // attrib + GetDlgItem(IDC_ARCHIVE_CHECK)->EnableWindow(m_bAttributes); + GetDlgItem(IDC_READONLY_CHECK)->EnableWindow(m_bAttributes); + GetDlgItem(IDC_HIDDEN_CHECK)->EnableWindow(m_bAttributes); + GetDlgItem(IDC_SYSTEM_CHECK)->EnableWindow(m_bAttributes); + GetDlgItem(IDC_DIRECTORY_CHECK)->EnableWindow(m_bAttributes); +} + +void CFilterDlg::OnOK() +{ + UpdateData(TRUE); + + // CFileFilter --> dialogu - mask + CString strText; + m_ctlFilter.GetWindowText(strText); + m_ffFilter.m_bUseMask=((m_bFilter != 0) && !strText.IsEmpty()); + m_ffFilter.SetCombinedMask(strText); + + m_ctlExcludeMask.GetWindowText(strText); + m_ffFilter.m_bUseExcludeMask=(m_bExclude != 0) && !strText.IsEmpty(); + m_ffFilter.SetCombinedExcludeMask(strText); + + // size + m_ffFilter.m_bUseSize=(m_bSize != 0); + m_ffFilter.m_bUseSize2=(m_bSize2 != 0); + + m_ffFilter.m_iSizeType1=m_ctlSizeType1.GetCurSel(); + m_ffFilter.m_iSizeType2=m_ctlSizeType2.GetCurSel(); + + m_ffFilter.m_ullSize1=static_cast(m_uiSize1)*static_cast(GetMultiplier(m_ctlSize1Multi.GetCurSel())); + m_ffFilter.m_ullSize2=static_cast(m_uiSize2)*static_cast(GetMultiplier(m_ctlSize2Multi.GetCurSel())); + + // date + m_ffFilter.m_iDateType=m_ctlDateType.GetCurSel(); + + m_ffFilter.m_iDateType1=m_ctlDateType1.GetCurSel(); + m_ffFilter.m_iDateType2=m_ctlDateType2.GetCurSel(); + + m_ffFilter.m_bDate1=m_ctlDate1.GetTime(m_ffFilter.m_tDate1) == GDT_VALID; + m_ffFilter.m_bDate2=m_ctlDate2.GetTime(m_ffFilter.m_tDate2) == GDT_VALID; + m_ffFilter.m_bTime1=m_ctlTime1.GetTime(m_ffFilter.m_tTime1) == GDT_VALID; + m_ffFilter.m_bTime2=m_ctlTime2.GetTime(m_ffFilter.m_tTime2) == GDT_VALID; + + m_ffFilter.m_bUseDate=(m_bDate != 0) && (m_ffFilter.m_bDate1 || m_ffFilter.m_bTime1); + m_ffFilter.m_bUseDate2=(m_bDate2 != 0) && (m_ffFilter.m_bDate2 || m_ffFilter.m_bTime2); + + // attributes + m_ffFilter.m_bUseAttributes=(m_bAttributes != 0); + m_ffFilter.m_iArchive=m_iArchive; + m_ffFilter.m_iReadOnly=m_iReadOnly; + m_ffFilter.m_iHidden=m_iHidden; + m_ffFilter.m_iSystem=m_iSystem; + m_ffFilter.m_iDirectory=m_iDirectory; + + CLanguageDialog::OnOK(); +} + +int CFilterDlg::GetMultiplier(int iIndex) +{ + switch (iIndex) + { + case 0: + return 1; + case 1: + return 1024; + case 2: + return 1048576; + default: + ASSERT(true); // bad index + return 1; + } +} + +void CFilterDlg::OnAttributesCheck() +{ + EnableControls(); +} + +void CFilterDlg::OnDateCheck() +{ + EnableControls(); +} + +void CFilterDlg::OnDate2Check() +{ + EnableControls(); +} + +void CFilterDlg::OnFilterCheck() +{ + EnableControls(); +} + +void CFilterDlg::OnSizeCheck() +{ + EnableControls(); +} + +void CFilterDlg::OnSize2Check() +{ + EnableControls(); +} + +void CFilterDlg::OnExcludemaskCheck() +{ + EnableControls(); +} + +void CFilterDlg::OnDatetimechangeTime1Datetimepicker(NMHDR* /*pNMHDR*/, LRESULT* pResult) +{ + EnableControls(); + + *pResult = 0; +} + +void CFilterDlg::OnDatetimechangeDate1Datetimepicker(NMHDR* /*pNMHDR*/, LRESULT* pResult) +{ + EnableControls(); + + *pResult = 0; +} Index: src/ch/FilterDlg.h =================================================================== diff -u -r52e4374b1e7044f77439e34581780750675125a7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FilterDlg.h (.../FilterDlg.h) (revision 52e4374b1e7044f77439e34581780750675125a7) +++ src/ch/FilterDlg.h (.../FilterDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,109 +1,109 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __FILTERDLG_H__ -#define __FILTERDLG_H__ - -#include "FileFilter.h" -#include - -///////////////////////////////////////////////////////////////////////////// -// CFilterDlg dialog - -class CFilterDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CFilterDlg(); // standard constructor - -// Dialog Data - //{{AFX_DATA(CFilterDlg) - enum { IDD = IDD_FILTER_DIALOG }; - CComboBox m_ctlExcludeMask; - CSpinButtonCtrl m_ctlSpin2; - CSpinButtonCtrl m_ctlSpin1; - CDateTimeCtrl m_ctlTime2; - CDateTimeCtrl m_ctlTime1; - CComboBox m_ctlSizeType2; - CComboBox m_ctlSizeType1; - CComboBox m_ctlSize2Multi; - CComboBox m_ctlSize1Multi; - CComboBox m_ctlFilter; - CComboBox m_ctlDateType; - CComboBox m_ctlDateType2; - CDateTimeCtrl m_ctlDate2; - CComboBox m_ctlDateType1; - CDateTimeCtrl m_ctlDate1; - int m_iArchive; - BOOL m_bAttributes; - BOOL m_bDate; - BOOL m_bDate2; - int m_iDirectory; - BOOL m_bFilter; - int m_iHidden; - int m_iReadOnly; - BOOL m_bSize; - UINT m_uiSize1; - BOOL m_bSize2; - UINT m_uiSize2; - int m_iSystem; - BOOL m_bExclude; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CFilterDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -public: - void SetSize2(unsigned __int64 ullSize); - CFileFilter m_ffFilter; - CStringArray m_astrAddMask; - CStringArray m_astrAddExcludeMask; - -protected: - virtual void OnLanguageChanged(); - int GetMultiplier(int iIndex); - void EnableControls(); - void SetSize1(unsigned __int64 ullSize); - - // Generated message map functions - //{{AFX_MSG(CFilterDlg) - virtual BOOL OnInitDialog(); - virtual void OnOK(); - afx_msg void OnAttributesCheck(); - afx_msg void OnDateCheck(); - afx_msg void OnDate2Check(); - afx_msg void OnFilterCheck(); - afx_msg void OnSizeCheck(); - afx_msg void OnSize2Check(); - afx_msg void OnExcludemaskCheck(); - afx_msg void OnDatetimechangeTime1Datetimepicker(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnDatetimechangeDate1Datetimepicker(NMHDR* pNMHDR, LRESULT* pResult); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __FILTERDLG_H__ +#define __FILTERDLG_H__ + +#include "FileFilter.h" +#include + +///////////////////////////////////////////////////////////////////////////// +// CFilterDlg dialog + +class CFilterDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CFilterDlg(); // standard constructor + +// Dialog Data + //{{AFX_DATA(CFilterDlg) + enum { IDD = IDD_FILTER_DIALOG }; + CComboBox m_ctlExcludeMask; + CSpinButtonCtrl m_ctlSpin2; + CSpinButtonCtrl m_ctlSpin1; + CDateTimeCtrl m_ctlTime2; + CDateTimeCtrl m_ctlTime1; + CComboBox m_ctlSizeType2; + CComboBox m_ctlSizeType1; + CComboBox m_ctlSize2Multi; + CComboBox m_ctlSize1Multi; + CComboBox m_ctlFilter; + CComboBox m_ctlDateType; + CComboBox m_ctlDateType2; + CDateTimeCtrl m_ctlDate2; + CComboBox m_ctlDateType1; + CDateTimeCtrl m_ctlDate1; + int m_iArchive; + BOOL m_bAttributes; + BOOL m_bDate; + BOOL m_bDate2; + int m_iDirectory; + BOOL m_bFilter; + int m_iHidden; + int m_iReadOnly; + BOOL m_bSize; + UINT m_uiSize1; + BOOL m_bSize2; + UINT m_uiSize2; + int m_iSystem; + BOOL m_bExclude; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CFilterDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +public: + void SetSize2(unsigned __int64 ullSize); + CFileFilter m_ffFilter; + CStringArray m_astrAddMask; + CStringArray m_astrAddExcludeMask; + +protected: + virtual void OnLanguageChanged(); + int GetMultiplier(int iIndex); + void EnableControls(); + void SetSize1(unsigned __int64 ullSize); + + // Generated message map functions + //{{AFX_MSG(CFilterDlg) + virtual BOOL OnInitDialog(); + virtual void OnOK(); + afx_msg void OnAttributesCheck(); + afx_msg void OnDateCheck(); + afx_msg void OnDate2Check(); + afx_msg void OnFilterCheck(); + afx_msg void OnSizeCheck(); + afx_msg void OnSize2Check(); + afx_msg void OnExcludemaskCheck(); + afx_msg void OnDatetimechangeTime1Datetimepicker(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnDatetimechangeDate1Datetimepicker(NMHDR* pNMHDR, LRESULT* pResult); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/FolderDialog.cpp =================================================================== diff -u -rd6da900f71c2fb7f65e7443baf279c7f626d057d -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FolderDialog.cpp (.../FolderDialog.cpp) (revision d6da900f71c2fb7f65e7443baf279c7f626d057d) +++ src/ch/FolderDialog.cpp (.../FolderDialog.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,1299 +1,1299 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "DirTreeCtrl.h" -#include "FolderDialog.h" -#include "memdc.h" -#include "Theme Helpers.h" -#include "shlobj.h" -#include "..\Common\FileSupport.h" -#include "StringHelpers.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -// dialog jako taki -const unsigned long __g_DlgTemplate[]={ - 0x82cf0040, 0x00000000, 0x00000000, 0x011b0000, 0x000000b4, 0x00000000, 0x00540008, 0x00680061, - 0x006d006f, 0x00000061 }; - -///////////////////////////////////////////////////////////////////////////// -// additional messages -#ifndef WM_THEMECHANGED -#define WM_THEMECHANGED 0x031A -#endif - -///////////////////////////////////////////////////////////////////////////// -// widow procedures - group subclassing for flicker free drawing -WNDPROC __g_pfButton; -WNDPROC __g_pfStatic; -WNDPROC __g_pfList; -WNDPROC __g_pfCombo; -WNDPROC __g_pfBaseCombo; -WNDPROC __g_pfEdit; - -///////////////////////////////////////////////////////////////////////////// -// Draws and calls the old window proc -LRESULT CALLBACK InternalWindowProc(WNDPROC pfWndProc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - switch (uMsg) - { - case WM_ERASEBKGND: - return (LRESULT)0; - break; - case WM_PAINT: - CWnd* pWnd=CWnd::FromHandle(hwnd); - CPaintDC dc(pWnd); - - // exclude header from update rect (only in report view) - int iID=GetDlgCtrlID(hwnd); - if (iID == IDC_SHORTCUT_LIST) - { - DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); - if ((dwStyle & LVS_TYPEMASK) == LVS_REPORT) - { - CRect headerRect; - HWND hHeader=ListView_GetHeader(hwnd); - GetWindowRect(hHeader, &headerRect); - CPoint pt=headerRect.TopLeft(); - ScreenToClient(hwnd, &pt); - headerRect.left=pt.x; - headerRect.top=pt.y; - pt=headerRect.BottomRight(); - ScreenToClient(hwnd, &pt); - headerRect.right=pt.x; - headerRect.bottom=pt.y; - dc.ExcludeClipRect(&headerRect); - } - } - - CMemDC memdc(&dc, &dc.m_ps.rcPaint); - - if (dc.m_ps.fErase) - memdc.FillSolidRect(&dc.m_ps.rcPaint, GetSysColor(COLOR_WINDOW)); - - CallWindowProc(pfWndProc, hwnd, WM_PAINT, (WPARAM)memdc.GetSafeHdc(), 0); - return 0; - break; - } - - return CallWindowProc(pfWndProc, hwnd, uMsg, wParam, lParam); -} - -//////////////////////////////////////////////////////////////////////////// -// window proc for edit ctrl contained in combo -LRESULT CALLBACK EditWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - return InternalWindowProc(__g_pfEdit, hwnd, uMsg, wParam, lParam); -}; - -//////////////////////////////////////////////////////////////////////////// -// procedure for combo box contained in comboboxex -LRESULT CALLBACK ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - return InternalWindowProc(__g_pfBaseCombo, hwnd, uMsg, wParam, lParam); -}; - -//////////////////////////////////////////////////////////////////////////// -// other visual elements' window proc -LRESULT CALLBACK CustomWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - int iID=GetDlgCtrlID(hwnd); - WNDPROC pfOld=NULL; - switch(iID) - { - case IDC_TOGGLE_BUTTON: - case IDOK: - case IDCANCEL: - pfOld=__g_pfButton; - break; - case IDC_TITLE_STATIC: - pfOld=__g_pfStatic; - break; - case IDC_PATH_COMBOBOXEX: - pfOld=__g_pfCombo; - break; - case IDC_SHORTCUT_LIST: - pfOld=__g_pfList; - break; - default: - ASSERT(false); // used CustomWindowProc, but no ID has been recognized - } - - return InternalWindowProc(pfOld, hwnd, uMsg, wParam, lParam); -} - -///////////////////////////////////////////////////////////////////////////// -// CFolderDialog dialog - -CFolderDialog::CFolderDialog(CWnd* /*pParent*/ /*=NULL*/) - :ictranslate::CLanguageDialog() -{ - //{{AFX_DATA_INIT(CFolderDialog) - //}}AFX_DATA_INIT - m_hImages=NULL; - m_hLargeImages=NULL; - m_bIgnoreUpdate=false; - m_bIgnoreTreeRefresh=false; -} - -CFolderDialog::~CFolderDialog() -{ -} - -BEGIN_MESSAGE_MAP(CFolderDialog,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CFolderDialog) - ON_NOTIFY(LVN_ENDLABELEDIT, IDC_SHORTCUT_LIST, OnEndLabelEditShortcutList) - ON_BN_CLICKED(IDC_ADDSHORTCUT_BUTTON, OnAddShortcut) - ON_BN_CLICKED(IDC_REMOVESHORTCUT_BUTTON, OnRemoveShortcut) - ON_BN_CLICKED(IDC_TOGGLE_BUTTON, OnToggleButton) - ON_NOTIFY(TVN_SELCHANGED, IDC_FOLDER_TREE, OnSelchangedFolderTree) - ON_NOTIFY(TVN_GETINFOTIP, IDC_FOLDER_TREE, OnGetInfoTipFolderTree) - ON_BN_CLICKED(IDC_NEWFOLDER_BUTTON, OnNewfolderButton) - ON_CBN_EDITCHANGE(IDC_PATH_COMBOBOXEX, OnPathChanging) - ON_BN_CLICKED(IDC_LARGEICONS_BUTTON, OnIconsRadio) - ON_BN_CLICKED(IDC_SMALLICONS_BUTTON, OnSmalliconsRadio) - ON_BN_CLICKED(IDC_LIST_BUTTON, OnListRadio) - ON_BN_CLICKED(IDC_REPORT_BUTTON, OnReportRadio) - ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHORTCUT_LIST, OnItemchangedShortcutList) - ON_NOTIFY(LVN_GETINFOTIP, IDC_SHORTCUT_LIST, OnGetShortcutInfoTip) - ON_NOTIFY(LVN_KEYDOWN, IDC_SHORTCUT_LIST, OnShortcutKeyDown) - ON_WM_PAINT() - ON_WM_NCHITTEST() - ON_WM_SIZE() - ON_WM_GETMINMAXINFO() - ON_WM_SYSCOLORCHANGE() - ON_WM_CREATE() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CFolderDialog message handlers - -///////////////////////////////////////////////////////////////////////////// -// creating all needed controls - -int CFolderDialog::CreateControls() -{ - // std rect - size doesn't matter for now - CRect rc(0, 0, 0, 0); - - if (!m_ctlTitle.Create(_T(""), WS_CHILD | WS_VISIBLE, rc, this, IDC_TITLE_STATIC) || - (__g_pfStatic=(WNDPROC)SetWindowLong(m_ctlTitle.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlTitle.SetFont(GetFont()); - - // buttons - small with bitmaps - if (!m_ctlLargeIcons.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_LARGEICONS_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlLargeIcons.SetImage(&m_ilList, 0); - - if (!m_ctlSmallIcons.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_SMALLICONS_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlSmallIcons.SetImage(&m_ilList, 1); - - if (!m_ctlList.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_LIST_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlList.SetImage(&m_ilList, 2); - - if (!m_ctlReport.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_REPORT_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlReport.SetImage(&m_ilList, 3); - - if (!m_ctlNewFolder.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_NEWFOLDER_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlNewFolder.SetImage(&m_ilList, 4); - - // listview - if (!m_ctlShortcuts.Create(WS_CHILD | WS_VISIBLE | LVS_SINGLESEL | LVS_SHAREIMAGELISTS | LVS_EDITLABELS | WS_TABSTOP | LVS_SMALLICON | LVS_SHOWSELALWAYS, rc, this, IDC_SHORTCUT_LIST) || - (__g_pfList=(WNDPROC)SetWindowLong(m_ctlShortcuts.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlShortcuts.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_INFOTIP | LVS_EX_UNDERLINEHOT); - m_ctlShortcuts.ModifyStyleEx(0, WS_EX_CLIENTEDGE); - - // dir tree ctrl - if (!m_ctlTree.Create(WS_CHILD | WS_VISIBLE | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS - | TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | TVS_TRACKSELECT | TVS_SINGLEEXPAND | TVS_INFOTIP | - WS_TABSTOP | WS_VSCROLL, rc, this, IDC_FOLDER_TREE) - || !m_ctlTree.ModifyStyleEx(0, WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE)) - { - TRACE("Error creating control..."); - return -1; - } - - // combobox - rc.bottom=rc.top+200; - if (!m_ctlPath.Create(WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWN | CBS_SORT | CBS_OWNERDRAWFIXED | CBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rc, this, IDC_PATH_COMBOBOXEX) || - (__g_pfCombo=(WNDPROC)SetWindowLong(m_ctlPath.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) - { - TRACE("Error creating control..."); - return -1; - } - HWND hCombo=(HWND)m_ctlPath.SendMessage(CBEM_GETCOMBOCONTROL, 0, 0); - if ((__g_pfBaseCombo=(WNDPROC)SetWindowLong(hCombo, GWLP_WNDPROC, (LONG)ComboWindowProc)) == 0) - return -1; - HWND hEdit=(HWND)m_ctlPath.SendMessage(CBEM_GETEDITCONTROL, 0, 0); - if ((__g_pfEdit=(WNDPROC)SetWindowLong(hEdit, GWLP_WNDPROC, (LONG)EditWindowProc)) == 0) - return -1; - - // buttons OK & Cancel - rc.bottom=rc.top; - if (!m_ctlOk.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, rc, this, IDOK) || - (__g_pfButton=(WNDPROC)SetWindowLong(m_ctlOk.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlOk.SetFont(GetFont()); - - if (!m_ctlCancel.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rc, this, IDCANCEL) || - !((WNDPROC)SetWindowLong(m_ctlCancel.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc))) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlCancel.SetFont(GetFont()); - - if (!m_ctlToggle.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rc, this, IDC_TOGGLE_BUTTON) || - !((WNDPROC)SetWindowLong(m_ctlToggle.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc))) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlToggle.SetFont(GetFont()); - - // add&remove shortcut - if (!m_ctlRemoveShortcut.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_REMOVESHORTCUT_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlRemoveShortcut.SetImage(&m_ilList, 6); - - if (!m_ctlAddShortcut.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_ADDSHORTCUT_BUTTON)) - { - TRACE("Error creating control..."); - return -1; - } - m_ctlAddShortcut.SetImage(&m_ilList, 5); - - return 0; -} - -/////////////////////////////////////////////////////////////////////////// -// tworzy image list� z wszystkimi potrzebnymi ikonami -void CFolderDialog::InitImageList() -{ - m_ilList.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1); - - HICON hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_LARGEICONS_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); - - hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_SMALLICONS_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); - - hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_LIST_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); - - hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_REPORT_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); - - hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_NEWFOLDER_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); - - hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_ADDSHORTCUT_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); - - hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_DELETESHORTCUT_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); - m_ilList.Add(hIcon); -} - -//////////////////////////////////////////////////////////////////////////// -// applies showing/hiding shortcuts list -void CFolderDialog::ApplyExpandState(bool bExpand) -{ - // change button text and hide/show needed elements - m_ctlToggle.SetWindowText(GetResManager()->LoadString(bExpand ? IDS_BDRIGHT_STRING : IDS_BDLEFT_STRING)); - m_ctlShortcuts.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); - m_ctlLargeIcons.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); - m_ctlSmallIcons.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); - m_ctlList.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); - m_ctlReport.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); - m_ctlAddShortcut.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); - m_ctlRemoveShortcut.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); -} - -//////////////////////////////////////////////////////////////////////////// -// toggle extended view -void CFolderDialog::OnToggleButton() -{ - m_bdData.bExtended=!m_bdData.bExtended; - ApplyExpandState(m_bdData.bExtended); - - CRect rcDialog; - GetClientRect(&rcDialog); - ResizeControls(rcDialog.Width(), rcDialog.Height()); -} - -///////////////////////////////////////////////////////////////////////////// -// initialization of most important params - reading text, bitmaps -BOOL CFolderDialog::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // image list - InitImageList(); - - if (CreateControls() == -1) - EndDialog(-1); - - // size of a dialog - CRect rcDialog; - GetClientRect(&rcDialog); - if (m_bdData.cx != 0) - rcDialog.right=rcDialog.left+m_bdData.cx; - if (m_bdData.cy != 0) - rcDialog.bottom=rcDialog.top+m_bdData.cy; - if (m_bdData.cy != 0 || m_bdData.cx != 0) - SetWindowPos(&wndTop, rcDialog.left, rcDialog.top, rcDialog.Width(), rcDialog.Height(), SWP_NOMOVE); - - // show needed text - SetWindowText(m_bdData.strCaption); - m_ctlTitle.SetWindowText(m_bdData.strText); - m_ctlTree.SetIgnoreShellDialogs(m_bdData.bIgnoreDialogs); - m_ctlTree.PostMessage(WM_SETPATH, 0, (LPARAM)((LPCTSTR)m_bdData.strInitialDir)); - - // buttons text - m_ctlOk.SetWindowText(GetResManager()->LoadString(IDS_BDOK_STRING)); - m_ctlCancel.SetWindowText(GetResManager()->LoadString(IDS_BDCANCEL_STRING)); - ApplyExpandState(m_bdData.bExtended); - - // sys img list - SHFILEINFO sfi; - m_hImages = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - m_hLargeImages=(HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX); - m_ctlPath.SendMessage(CBEM_SETIMAGELIST, 0, (LPARAM)m_hImages); - m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)m_hImages); - m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)m_hLargeImages); - - // add all the paths from m_bdData.astrRecent - COMBOBOXEXITEM cbi; - CString strText; - cbi.mask=CBEIF_IMAGE | CBEIF_TEXT; - - for (int i=0;i<(int)m_bdData.cvRecent.size();i++) - { - cbi.iItem=i; - cbi.pszText=m_bdData.cvRecent.at(i); - sfi.iIcon=-1; - SHGetFileInfo(m_bdData.cvRecent.at(i), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - cbi.iImage=sfi.iIcon; - - m_ctlPath.InsertItem(&cbi); - } - - // additional columns in a list - LVCOLUMN lvc; - lvc.mask=LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT; - lvc.iSubItem=-1; - lvc.cx=80; - lvc.pszText=(LPTSTR)GetResManager()->LoadString(IDS_BDNAME_STRING); - m_ctlShortcuts.InsertColumn(0, &lvc); - lvc.iSubItem=0; - lvc.cx=110; - lvc.pszText=(LPTSTR)GetResManager()->LoadString(IDS_BDPATH_STRING); - m_ctlShortcuts.InsertColumn(1, &lvc); - - // select view-style button - SetView(m_bdData.iView); - - // update shortcuts' list - CShortcut sc; - for (int i=0;i<(int)m_bdData.cvShortcuts.size();i++) - { - sc=CString(m_bdData.cvShortcuts.at(i)); - sfi.iIcon=-1; - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.InsertItem(i, sc.m_strName, sfi.iIcon); - m_ctlShortcuts.SetItem(i, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - } - - // now resize and ok. - GetClientRect(&rcDialog); - ResizeControls(rcDialog.Width(), rcDialog.Height()); - - // set to top - the strange way - SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); - SetFocus(); - SetForegroundWindow(); - - return TRUE; -} - -//////////////////////////////////////////////////////////////////////////// -// tooltip handling for controls in this dialog -BOOL CFolderDialog::OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip) -{ - switch (uiID) - { - case IDC_NEWFOLDER_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDNEWFOLDER_STRING); - break; - case IDC_LARGEICONS_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDLARGEICONS_STRING); - break; - case IDC_SMALLICONS_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDSMALLICONS_STRING); - break; - case IDC_LIST_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDLIST_STRING); - break; - case IDC_REPORT_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDREPORT_STRING); - break; - case IDC_TOGGLE_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDDETAILS_STRING); - break; - case IDC_ADDSHORTCUT_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDADDSHORTCUT_STRING); - break; - case IDC_REMOVESHORTCUT_BUTTON: - pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDREMOVESHORTCUT_STRING); - break; - default: - return FALSE; - } - return TRUE; -} - -///////////////////////////////////////////////////////////////////////////// -// cancels the dialog or cancels editing of an item -void CFolderDialog::OnCancel() -{ - if (m_ctlTree.IsEditing()) - { - TreeView_EndEditLabelNow(m_ctlTree.GetSafeHwnd(), TRUE); - return; - } - - CRect rcDlg; - GetWindowRect(&rcDlg); - m_bdData.cx=rcDlg.Width(); - m_bdData.cy=rcDlg.Height(); - - CLanguageDialog::OnCancel(); -} - -/////////////////////////////////////////////////////////////////////////// -// finishes dialog's work or finished editing of an item -void CFolderDialog::OnOK() -{ - // if we edit an item in m_ctlTree - if (m_ctlTree.IsEditing()) - { - TreeView_EndEditLabelNow(m_ctlTree.GetSafeHwnd(), FALSE); - return; - } - - // update path, get rid of '\\' - m_ctlPath.GetWindowText(m_strPath); - if (m_strPath.Right(1) == _T('\\') || m_strPath.Right(1) == _T('/')) - m_strPath=m_strPath.Left(m_strPath.GetLength()-1); - - // does it exist as a folder ? -/* CFileFind fnd; - BOOL bExist=fnd.FindFile(m_strPath+_T("\\*")); - fnd.Close();*/ -// WIN32_FIND_DATA wfd; -// HANDLE hFind; - -// if (!bExist) - if ( GetFileAttributes(m_strPath) == INVALID_FILE_ATTRIBUTES) - { - MsgBox(IDS_BDPATHDOESNTEXIST_STRING, MB_OK | MB_ICONERROR); - return; - } - - m_bdData.cvRecent.insert(m_bdData.cvRecent.begin(), (const PTSTR)(LPCTSTR)(m_strPath+_T('\\')), true); - - CRect rcDlg; - GetWindowRect(&rcDlg); - m_bdData.cx=rcDlg.Width(); - m_bdData.cy=rcDlg.Height(); - - CLanguageDialog::OnOK(); -} - -/////////////////////////////////////////////////////////////////////////// -// Displays dialog from __g_DlgTemplate -INT_PTR CFolderDialog::DoModal() -{ - if (!InitModalIndirect((LPCDLGTEMPLATE)__g_DlgTemplate)) - return -1; - else - return ictranslate::CLanguageDialog::DoModal(); -} - -/////////////////////////////////////////////////////////////////////////// -// handles creation of a new folder -void CFolderDialog::OnNewfolderButton() -{ - // currently selected item - HTREEITEM hItem=m_ctlTree.GetSelectedItem(); - if (hItem == NULL) - return; - - // insert child item - m_ctlTree.InsertNewFolder(hItem, _T("")); -} - -///////////////////////////////////////////////////////////////////////////// -// other messages -LRESULT CFolderDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - case WM_CREATEFOLDERRESULT: - if (((int)lParam) != 1) - MsgBox(IDS_BDCANNOTCREATEFOLDER_STRING); - break; - case WM_THEMECHANGED: - CRect rcDialog; - GetClientRect(&rcDialog); - ResizeControls(rcDialog.Width(), rcDialog.Height()); - break; - } - - return ictranslate::CLanguageDialog::WindowProc(message, wParam, lParam); -} - -////////////////////////////////////////////////////////////////////////////// -// tooltips for folder tree -void CFolderDialog::OnGetInfoTipFolderTree(NMHDR* pNMHDR, LRESULT* pResult) -{ - NMTVGETINFOTIP* pit = (NMTVGETINFOTIP*)pNMHDR; - *pResult = 0; - - // get rid of old tip - m_strTip.Empty(); - - // get type of an item - for floppy skip - SHDESCRIPTIONID shdi; - bool bSkipFreeSpace=false; - if (m_ctlTree.GetItemShellData(pit->hItem, SHGDFIL_DESCRIPTIONID, &shdi, sizeof(SHDESCRIPTIONID)) - && ( shdi.dwDescriptionId == SHDID_COMPUTER_DRIVE35 - || shdi.dwDescriptionId == SHDID_COMPUTER_DRIVE525 ) ) - bSkipFreeSpace=true; - - - // some about network - bool bNet; - CString strData; - NETRESOURCE* pnet=(NETRESOURCE*)m_szBuffer; - if ( (bNet=m_ctlTree.GetItemShellData(pit->hItem, SHGDFIL_NETRESOURCE, pnet, 2048)) == true) - { - if (pnet->lpRemoteName && _tcscmp(pnet->lpRemoteName, _T("")) != 0) - m_strTip+=GetResManager()->LoadString(IDS_BDREMOTENAME_STRING)+CString(pnet->lpRemoteName)+_T("\n"); - if ( pnet->lpLocalName && _tcscmp(pnet->lpLocalName, _T("")) != 0) - m_strTip+=GetResManager()->LoadString(IDS_BDLOCALNAME_STRING)+CString(pnet->lpLocalName)+_T("\n"); - if ( pnet->dwDisplayType != 0) - m_strTip+=GetResManager()->LoadString(IDS_BDTYPE_STRING)+CString(GetResManager()->LoadString(IDS_BDDOMAIN_STRING+pnet->dwDisplayType))+_T("\n"); - if ( pnet->lpProvider && _tcscmp(pnet->lpProvider, _T("")) != 0) - m_strTip+=GetResManager()->LoadString(IDS_BDNETTYPE_STRING)+CString(pnet->lpProvider)+_T("\n"); - if ( pnet->lpComment && _tcscmp(pnet->lpComment, _T("")) != 0) - m_strTip+=GetResManager()->LoadString(IDS_BDDESCRIPTION_STRING)+CString(pnet->lpComment)+_T("\n"); - } - - // try to get path - CString strPath, strMask; - TCHAR szSizeFree[32], szSizeTotal[32]; - bool bPath; - if ( (bPath=m_ctlTree.GetPath(pit->hItem, strPath.GetBuffer(_MAX_PATH))) == true ) - { - strPath.ReleaseBuffer(); - if (!bNet && !strPath.IsEmpty()) - m_strTip+=strPath+_T("\n"); - - if (!bSkipFreeSpace) - { - // get disk free space - ull_t ullFree, ullTotal; - if (GetDynamicFreeSpace(strPath, &ullFree, &ullTotal)) - { - m_strTip+=GetResManager()->LoadString(IDS_BDFREESPACE_STRING)+CString(GetSizeString(ullFree, szSizeFree, 32, false))+_T("\n"); - m_strTip+=GetResManager()->LoadString(IDS_BDCAPACITY_STRING)+CString(GetSizeString(ullTotal, szSizeTotal, 32, false))+_T("\n"); - } - } - } - - if (!bNet && !bPath) - { - // get std shell msg - m_ctlTree.GetItemInfoTip(pit->hItem, &m_strTip); - } - else - { - // get rid of '\n' - m_strTip=m_strTip.Left(m_strTip.GetLength()-1); - } - - // set - pit->pszText=m_strTip.GetBuffer(1); // tip doesn't change - skip RelaseBuffer - pit->cchTextMax=lstrlen(pit->pszText); -} - -///////////////////////////////////////////////////////////////////////////// -// tooltip support for shortcuts list -void CFolderDialog::OnGetShortcutInfoTip(NMHDR* pNMHDR, LRESULT* /*pResult*/) -{ - NMLVGETINFOTIP* pit=(NMLVGETINFOTIP*)pNMHDR; - m_strTip.Empty(); - - if (pit->iItem < 0 || pit->iItem >= (int)m_bdData.cvShortcuts.size()) - return; // out of range - - CShortcut sc=CString(m_bdData.cvShortcuts.at(pit->iItem)); - m_strTip=sc.m_strName+_T("\r\n")+CString(GetResManager()->LoadString(IDS_BDPATH2_STRING))+sc.m_strPath; - - // get disk free space - ull_t ullFree, ullTotal; - if (GetDynamicFreeSpace(sc.m_strPath, &ullFree, &ullTotal)) - { - m_strTip+=CString(_T("\r\n"))+GetResManager()->LoadString(IDS_BDFREESPACE_STRING)+CString(GetSizeString(ullFree, m_szBuffer, 2048, false))+_T("\n"); - m_strTip+=GetResManager()->LoadString(IDS_BDCAPACITY_STRING)+CString(GetSizeString(ullTotal, m_szBuffer, 2048, false)); - } - - pit->pszText=(LPTSTR)(LPCTSTR)m_strTip; - pit->cchTextMax=m_strTip.GetLength()+1; -} - -//////////////////////////////////////////////////////////////////////////// -// updates text in combo when the selection in a tree changes -void CFolderDialog::OnSelchangedFolderTree(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; - TCHAR szPath[_MAX_PATH]; - - if (m_bIgnoreUpdate) - return; - - if (m_ctlTree.GetPath(pNMTreeView->itemNew.hItem, szPath)) - SetComboPath(szPath); - - *pResult = 0; -} - -//////////////////////////////////////////////////////////////////////////// -// updates folder tree when combo text changes -void CFolderDialog::OnPathChanging() -{ - if (m_bIgnoreTreeRefresh) - return; - - COMBOBOXEXITEM cbi; - cbi.mask=CBEIF_TEXT; - cbi.iItem=-1; - cbi.pszText=m_szBuffer; - cbi.cchTextMax=_MAX_PATH; - - if (!m_ctlPath.GetItem(&cbi)) - return; - - UpdateComboIcon(); - - m_bIgnoreUpdate=true; - m_ctlTree.SetPath(cbi.pszText); - m_bIgnoreUpdate=false; -} - -///////////////////////////////////////////////////////////////////////// -// sets text in comboboxex edit and updates icon -void CFolderDialog::SetComboPath(LPCTSTR lpszPath) -{ - _ASSERTE(lpszPath); - if(!lpszPath) - return; - // set current select to -1 - m_bIgnoreTreeRefresh=true; - m_ctlPath.SetCurSel(-1); - m_bIgnoreTreeRefresh=false; - - SHFILEINFO sfi; - sfi.iIcon=-1; - - COMBOBOXEXITEM cbi; - - cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; - cbi.iItem=-1; - _tcscpy(m_szBuffer, lpszPath); - cbi.pszText=m_szBuffer; - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - cbi.iImage=sfi.iIcon; - m_bIgnoreTreeRefresh=true; - m_ctlPath.SetItem(&cbi); - m_bIgnoreTreeRefresh=false; -} - -////////////////////////////////////////////////////////////////////////// -// updates icon in comboex -void CFolderDialog::UpdateComboIcon() -{ - // get text from combo - COMBOBOXEXITEM cbi; - cbi.mask=CBEIF_TEXT; - cbi.iItem=m_ctlPath.GetCurSel()/*-1*/; - cbi.pszText=m_szBuffer; - cbi.cchTextMax=_MAX_PATH; - - if (!m_ctlPath.GetItem(&cbi)) - return; - - // select no item - m_bIgnoreTreeRefresh=true; - m_ctlPath.SetCurSel(-1); - m_bIgnoreTreeRefresh=false; - - // icon update - SHFILEINFO sfi; - sfi.iIcon=-1; - - cbi.mask |= CBEIF_IMAGE; - cbi.iItem=-1; - - CString str=(LPCTSTR)m_szBuffer; - if (str.Left(2) != _T("\\\\") || str.Find(_T('\\'), 2) != -1) - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - - cbi.iImage=sfi.iIcon; - - m_bIgnoreTreeRefresh=true; - m_ctlPath.SetItem(&cbi); - m_bIgnoreTreeRefresh=false; - - // unselect text in combo's edit - CEdit* pEdit=m_ctlPath.GetEditCtrl(); - if (!pEdit) - return; - - pEdit->SetSel(-1, -1); -} - -///////////////////////////////////////////////////////////////////////////// -// combo and treeview update -void CFolderDialog::OnItemchangedShortcutList(NMHDR* pNMHDR, LRESULT* pResult) -{ - NMLISTVIEW* plv=(NMLISTVIEW*)pNMHDR; - - // current selection - if (plv->iItem >= 0 && plv->iItem < (int)m_bdData.cvShortcuts.size()) - { - CShortcut sc=CString(m_bdData.cvShortcuts.at(plv->iItem)); - m_ctlTree.SetPath(sc.m_strPath); - SetComboPath(sc.m_strPath); - } - - *pResult = 0; -} - -///////////////////////////////////////////////////////////////////////////// -// adding shortcut -void CFolderDialog::OnAddShortcut() -{ - // get current text - COMBOBOXEXITEM cbi; - cbi.mask=CBEIF_TEXT; - cbi.iItem=m_ctlPath.GetCurSel()/*-1*/; - cbi.pszText=m_szBuffer; - cbi.cchTextMax=_MAX_PATH; - - if (!m_ctlPath.GetItem(&cbi)) - { - MsgBox(IDS_BDNOSHORTCUTPATH_STRING); - return; - } - - // create new item - update shortcut list - CShortcut sc; - sc.m_strPath=cbi.pszText; - SHFILEINFO sfi; - sfi.iIcon=-1; - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - - // add to an array and to shortcuts list - m_bdData.cvShortcuts.push_back((const PTSTR)(LPCTSTR)(CString)(sc), true); - int iIndex=m_bdData.cvShortcuts.size()-1; - m_ctlShortcuts.InsertItem(iIndex, sc.m_strName, sfi.iIcon); - m_ctlShortcuts.SetItem(iIndex, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - - // edit item - m_ctlShortcuts.SetFocus(); - if (m_ctlShortcuts.EditLabel(iIndex) == NULL) - { - TRACE("Couldn't edit shortcut list's item label\n"); - return; - } -} - -//////////////////////////////////////////////////////////////////////////// -// keyboard's delete button handling -void CFolderDialog::OnShortcutKeyDown(NMHDR* pNMHDR, LRESULT* /*pResult*/) -{ - LPNMLVKEYDOWN lpkd=(LPNMLVKEYDOWN)pNMHDR; - if (lpkd->wVKey == VK_DELETE) - OnRemoveShortcut(); -} - -//////////////////////////////////////////////////////////////////////////// -// deleting shortcut from list -void CFolderDialog::OnRemoveShortcut() -{ - POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); - if (pos) - { - int iSel=m_ctlShortcuts.GetNextSelectedItem(pos); - m_ctlShortcuts.DeleteItem(iSel); - m_bdData.cvShortcuts.erase(m_bdData.cvShortcuts.begin()+iSel, true); - - m_ctlShortcuts.Arrange(LVA_DEFAULT); - } -} - -/////////////////////////////////////////////////////////////////////////// -// finishing editing shortcut name -void CFolderDialog::OnEndLabelEditShortcutList(NMHDR* pNMHDR, LRESULT* pResult) -{ - NMLVDISPINFO* pdi = (NMLVDISPINFO*)pNMHDR; - - // editing has been cancelled - delete item - if (pdi->item.pszText == NULL) - { - m_ctlShortcuts.DeleteItem(pdi->item.iItem); - m_bdData.cvShortcuts.erase(m_bdData.cvShortcuts.begin()+pdi->item.iItem, true); - - *pResult=0; - return; - } - - // std editing - success - CShortcut sc=CString(m_bdData.cvShortcuts.at(pdi->item.iItem)); - sc.m_strName=pdi->item.pszText; - - m_bdData.cvShortcuts.replace(m_bdData.cvShortcuts.begin()+pdi->item.iItem, (const PTSTR)(LPCTSTR)(CString)sc, true, true); - - *pResult=1; -} - -//////////////////////////////////////////////////////////////////////////// -// sets the style of a shortcuts list -void CFolderDialog::SetView(int iView) -{ - DWORD dwView=0; - switch (iView) - { - case 0: - dwView=LVS_ICON; - break; - case 2: - dwView=LVS_SMALLICON; - break; - case 3: - dwView=LVS_REPORT; - break; - default: - dwView=LVS_LIST; - break; - } - - DWORD dwStyle = GetWindowLong(m_ctlShortcuts.GetSafeHwnd(), GWL_STYLE); - - // Only set the window style if the view bits have changed. - if ((dwStyle & LVS_TYPEMASK) != dwView) - SetWindowLong(m_ctlShortcuts.GetSafeHwnd(), GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | dwView); - m_ctlShortcuts.Arrange(LVA_ALIGNTOP); -} - -/////////////////////////////////////////////////////////////////////////// -// large icons -void CFolderDialog::OnIconsRadio() -{ - m_bdData.iView=0; - SetView(0); - m_ctlLargeIcons.Invalidate(); - m_ctlSmallIcons.Invalidate(); - m_ctlList.Invalidate(); - m_ctlReport.Invalidate(); -} - -/////////////////////////////////////////////////////////////////////////// -// small icons -void CFolderDialog::OnSmalliconsRadio() -{ - m_bdData.iView=1; - SetView(1); - m_ctlLargeIcons.Invalidate(); - m_ctlSmallIcons.Invalidate(); - m_ctlList.Invalidate(); - m_ctlReport.Invalidate(); -} - -/////////////////////////////////////////////////////////////////////////// -// list button -void CFolderDialog::OnListRadio() -{ - m_bdData.iView=2; - SetView(2); - m_ctlLargeIcons.Invalidate(); - m_ctlSmallIcons.Invalidate(); - m_ctlList.Invalidate(); - m_ctlReport.Invalidate(); -} - -/////////////////////////////////////////////////////////////////////////// -// report button -void CFolderDialog::OnReportRadio() -{ - m_bdData.iView=3; - SetView(3); - m_ctlLargeIcons.Invalidate(); - m_ctlSmallIcons.Invalidate(); - m_ctlList.Invalidate(); - m_ctlReport.Invalidate(); -} - -//////////////////////////////////////////////////////////////////////////// -// resize handling -void CFolderDialog::OnSize(UINT nType, int cx, int cy) -{ - CLanguageDialog::OnSize(nType, cx, cy); - - ResizeControls(cx, cy); - InvalidateRect(&m_rcGripper); -} - -//////////////////////////////////////////////////////////////////////////// -// repositions controls within the dialog -void CFolderDialog::ResizeControls(int cx, int cy) -{ - // is app themed ? - CUxThemeSupport uxt; - bool bThemed=uxt.IsThemeSupported() && uxt.IsAppThemed(); - - // settings - const int iMargin=7; // dialog units - const int iTextCount=3; // ilo�� linii textu w staticu - - // small buttons - const int iBmpMargin=1; // margin between button and a bitmap within - const int iButtonWidth=(bThemed ? 20 : 16)+2*GetSystemMetrics(SM_CXEDGE)+2*iBmpMargin; // fixed size - const int iButtonHeight=(bThemed ? 20 : 16)+2*GetSystemMetrics(SM_CYEDGE)+2*iBmpMargin; - - // large buttons - const int iLargeButtonHeight=14; // OK&Cancel buttons (dialog units) - const int iLargeButtonWidth=50; // width in DU - const int iToggleButtonWidth=18; // toggle size - - // combo - const int iComboHeight=12; - const int iComboExpandedHeight=100; - - // static text at the top of dialog - CRect rcStatic( iMargin, iMargin, 0, iMargin+iTextCount*8 ); - MapDialogRect(&rcStatic); - rcStatic.right=cx-rcStatic.left; - - CWnd* pWnd=GetDlgItem(IDC_TITLE_STATIC); - if (pWnd) - { - pWnd->MoveWindow(&rcStatic); - pWnd->Invalidate(); - } - - // 4*button (**********) - CRect rcButton(iMargin, iMargin+iTextCount*8+5, 0, 0); - MapDialogRect(&rcButton); - rcButton.right=rcButton.left+iButtonWidth; - rcButton.bottom=rcButton.top+iButtonHeight; - pWnd=GetDlgItem(IDC_LARGEICONS_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - rcButton.left+=iButtonWidth; - rcButton.right+=iButtonWidth; - pWnd=GetDlgItem(IDC_SMALLICONS_BUTTON); - if (pWnd) - pWnd->MoveWindow(&rcButton); - - rcButton.left+=iButtonWidth; - rcButton.right+=iButtonWidth; - pWnd=GetDlgItem(IDC_LIST_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - rcButton.left+=iButtonWidth; - rcButton.right+=iButtonWidth; - pWnd=GetDlgItem(IDC_REPORT_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - // new folder button - rcButton=CRect(iMargin, iMargin+iTextCount*8+5, iMargin, 0); - MapDialogRect(&rcButton); - rcButton.left=cx-rcButton.left-iButtonWidth-1; // off by 1 - better looks - rcButton.right=cx-rcButton.right-1; - rcButton.bottom=rcButton.top+iButtonHeight; - pWnd=GetDlgItem(IDC_NEWFOLDER_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - // shortcuts list (**********) - CRect rcShortcuts(iMargin, iMargin+iTextCount*8+5+1, 2*iMargin+5, iMargin+iLargeButtonHeight+5+iComboHeight+3); - MapDialogRect(&rcShortcuts); - rcShortcuts.top+=iButtonHeight; // small button size - rcShortcuts.right=MulDiv((cx-rcShortcuts.right), 35, 120); - rcShortcuts.bottom=cy-rcShortcuts.bottom; - pWnd=GetDlgItem(IDC_SHORTCUT_LIST); - if (pWnd) - { - pWnd->MoveWindow(&rcShortcuts); - pWnd->Invalidate(); - } - - // button toggle - rcButton=CRect(iMargin+(m_bdData.bExtended ? 5 : 0), iMargin+iTextCount*8+5, iToggleButtonWidth, iLargeButtonHeight); - MapDialogRect(&rcButton); - if (m_bdData.bExtended) - rcButton.left+=rcShortcuts.Width()+1; - rcButton.right+=rcButton.left; - rcButton.bottom+=rcButton.top; - pWnd=GetDlgItem(IDC_TOGGLE_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - // tree ctrl - CRect rcTree(iMargin+(m_bdData.bExtended ? 5 : 0), iMargin+iTextCount*8+5+1, iMargin, iMargin+iLargeButtonHeight+5+iComboHeight+3 ); - MapDialogRect(&rcTree); - rcTree.top+=iButtonHeight; - rcTree.bottom=cy-rcTree.bottom; - rcTree.right=cx-rcTree.right; - if (m_bdData.bExtended) - rcTree.left+=rcShortcuts.Width(); - pWnd=GetDlgItem(IDC_FOLDER_TREE); - if (pWnd) - { - pWnd->MoveWindow(&rcTree); - pWnd->Invalidate(); - } - - // combo - CRect rcCombo(iMargin+(m_bdData.bExtended ? 5 : 0), iMargin+iLargeButtonHeight+5+iComboHeight, iMargin, iComboExpandedHeight/*iMargin+iLargeButtonHeight+5*/); - MapDialogRect(&rcCombo); - if (m_bdData.bExtended) - rcCombo.left+=rcShortcuts.Width(); - rcCombo.top=cy-rcCombo.top; - rcCombo.right=cx-rcCombo.right; - rcCombo.bottom+=rcCombo.top; - pWnd=GetDlgItem(IDC_PATH_COMBOBOXEX); - if (pWnd) - { - pWnd->MoveWindow(&rcCombo); - pWnd->Invalidate(); - } - - // button - add shortcut/remove shortcut - rcButton=CRect(0, iMargin+iLargeButtonHeight+5+iComboHeight, 0, 0); - MapDialogRect(&rcButton); - rcButton.top=cy-rcButton.top; - rcButton.left=rcShortcuts.right-iButtonWidth; - rcButton.right=rcButton.left+iButtonWidth; - rcButton.bottom=rcButton.top+iButtonHeight; - pWnd=GetDlgItem(IDC_ADDSHORTCUT_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - rcButton.left-=iButtonWidth; - rcButton.right-=iButtonWidth; - pWnd=GetDlgItem(IDC_REMOVESHORTCUT_BUTTON); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - // buttony - ok & cancel - rcButton=CRect(iMargin+2*iLargeButtonWidth+3, iMargin+iLargeButtonHeight, iMargin+iLargeButtonWidth+3, iMargin); - MapDialogRect(&rcButton); - rcButton.left=cx-rcButton.left; - rcButton.top=cy-rcButton.top; - rcButton.right=cx-rcButton.right; - rcButton.bottom=cy-rcButton.bottom; - pWnd=GetDlgItem(IDOK); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } - - rcButton=CRect(iMargin+iLargeButtonWidth, iMargin+iLargeButtonHeight, iMargin, iMargin); - MapDialogRect(&rcButton); - rcButton.left=cx-rcButton.left; - rcButton.top=cy-rcButton.top; - rcButton.right=cx-rcButton.right; - rcButton.bottom=cy-rcButton.bottom; - pWnd=GetDlgItem(IDCANCEL); - if (pWnd) - { - pWnd->MoveWindow(&rcButton); - pWnd->Invalidate(); - } -} - -/////////////////////////////////////////////////////////////////////////// -// minimum size of a window -void CFolderDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) -{ - CRect rcMin(0, 0, 200, 160); - MapDialogRect(&rcMin); - lpMMI->ptMinTrackSize=rcMin.BottomRight(); -} - -///////////////////////////////////////////////////////////////////////////// -// paints a gripper -void CFolderDialog::OnPaint() -{ - if (!IsZoomed()) - { - CPaintDC dc(this); // device context for painting - - CRect rc; - GetClientRect(rc); - - rc.left = rc.right-GetSystemMetrics(SM_CXHSCROLL); - rc.top = rc.bottom-GetSystemMetrics(SM_CYVSCROLL); - m_rcGripper=rc; - dc.DrawFrameControl(rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP); - } - else - { - CPaintDC dc(this); - DefWindowProc(WM_PAINT, (WPARAM)dc.GetSafeHdc(), 0); - } -} - -//////////////////////////////////////////////////////////////////////////// -// hit testing in a gripper cause -LRESULT CFolderDialog::OnNcHitTest(CPoint point) -{ - UINT uiRes=CLanguageDialog::OnNcHitTest(point); - if (uiRes == HTCLIENT) - { - CRect rc; - GetWindowRect(&rc); - rc.left = rc.right-GetSystemMetrics(SM_CXHSCROLL); - rc.top = rc.bottom-GetSystemMetrics(SM_CYVSCROLL); - if (rc.PtInRect(point)) - uiRes = HTBOTTOMRIGHT; - } - - return uiRes; -} - -//////////////////////////////////////////////////////////////////////////// -// returns combo's path after dialog finishes -void CFolderDialog::GetPath(LPTSTR pszPath) -{ - _tcscpy(pszPath, m_strPath); -} - -//////////////////////////////////////////////////////////////////////////// -// returns combo's path after dialog finishes -void CFolderDialog::GetPath(CString &rstrPath) -{ - rstrPath=m_strPath; -} - -//////////////////////////////////////////////////////////////////////////// -// opens choose folder dialog -int BrowseForFolder(CFolderDialog::BROWSEDATA* pData, LPTSTR pszPath) -{ - _ASSERTE(pData && pszPath); - if(!pData || !pszPath) - return IDCANCEL; - ASSERT(pData); - ASSERT(pszPath); - CFolderDialog dlg; - dlg.m_bdData=*pData; - - int iResult=dlg.DoModal(); - if (iResult == IDOK) - { - dlg.GetPath(pszPath); // returned path - *pData=dlg.m_bdData; // future - } - else - _tcscpy(pszPath, _T("")); - - return iResult; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "DirTreeCtrl.h" +#include "FolderDialog.h" +#include "memdc.h" +#include "Theme Helpers.h" +#include "shlobj.h" +#include "..\Common\FileSupport.h" +#include "StringHelpers.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +// dialog jako taki +const unsigned long __g_DlgTemplate[]={ + 0x82cf0040, 0x00000000, 0x00000000, 0x011b0000, 0x000000b4, 0x00000000, 0x00540008, 0x00680061, + 0x006d006f, 0x00000061 }; + +///////////////////////////////////////////////////////////////////////////// +// additional messages +#ifndef WM_THEMECHANGED +#define WM_THEMECHANGED 0x031A +#endif + +///////////////////////////////////////////////////////////////////////////// +// widow procedures - group subclassing for flicker free drawing +WNDPROC __g_pfButton; +WNDPROC __g_pfStatic; +WNDPROC __g_pfList; +WNDPROC __g_pfCombo; +WNDPROC __g_pfBaseCombo; +WNDPROC __g_pfEdit; + +///////////////////////////////////////////////////////////////////////////// +// Draws and calls the old window proc +LRESULT CALLBACK InternalWindowProc(WNDPROC pfWndProc, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_ERASEBKGND: + return (LRESULT)0; + break; + case WM_PAINT: + CWnd* pWnd=CWnd::FromHandle(hwnd); + CPaintDC dc(pWnd); + + // exclude header from update rect (only in report view) + int iID=GetDlgCtrlID(hwnd); + if (iID == IDC_SHORTCUT_LIST) + { + DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE); + if ((dwStyle & LVS_TYPEMASK) == LVS_REPORT) + { + CRect headerRect; + HWND hHeader=ListView_GetHeader(hwnd); + GetWindowRect(hHeader, &headerRect); + CPoint pt=headerRect.TopLeft(); + ScreenToClient(hwnd, &pt); + headerRect.left=pt.x; + headerRect.top=pt.y; + pt=headerRect.BottomRight(); + ScreenToClient(hwnd, &pt); + headerRect.right=pt.x; + headerRect.bottom=pt.y; + dc.ExcludeClipRect(&headerRect); + } + } + + CMemDC memdc(&dc, &dc.m_ps.rcPaint); + + if (dc.m_ps.fErase) + memdc.FillSolidRect(&dc.m_ps.rcPaint, GetSysColor(COLOR_WINDOW)); + + CallWindowProc(pfWndProc, hwnd, WM_PAINT, (WPARAM)memdc.GetSafeHdc(), 0); + return 0; + break; + } + + return CallWindowProc(pfWndProc, hwnd, uMsg, wParam, lParam); +} + +//////////////////////////////////////////////////////////////////////////// +// window proc for edit ctrl contained in combo +LRESULT CALLBACK EditWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + return InternalWindowProc(__g_pfEdit, hwnd, uMsg, wParam, lParam); +}; + +//////////////////////////////////////////////////////////////////////////// +// procedure for combo box contained in comboboxex +LRESULT CALLBACK ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + return InternalWindowProc(__g_pfBaseCombo, hwnd, uMsg, wParam, lParam); +}; + +//////////////////////////////////////////////////////////////////////////// +// other visual elements' window proc +LRESULT CALLBACK CustomWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + int iID=GetDlgCtrlID(hwnd); + WNDPROC pfOld=NULL; + switch(iID) + { + case IDC_TOGGLE_BUTTON: + case IDOK: + case IDCANCEL: + pfOld=__g_pfButton; + break; + case IDC_TITLE_STATIC: + pfOld=__g_pfStatic; + break; + case IDC_PATH_COMBOBOXEX: + pfOld=__g_pfCombo; + break; + case IDC_SHORTCUT_LIST: + pfOld=__g_pfList; + break; + default: + ASSERT(false); // used CustomWindowProc, but no ID has been recognized + } + + return InternalWindowProc(pfOld, hwnd, uMsg, wParam, lParam); +} + +///////////////////////////////////////////////////////////////////////////// +// CFolderDialog dialog + +CFolderDialog::CFolderDialog(CWnd* /*pParent*/ /*=NULL*/) + :ictranslate::CLanguageDialog() +{ + //{{AFX_DATA_INIT(CFolderDialog) + //}}AFX_DATA_INIT + m_hImages=NULL; + m_hLargeImages=NULL; + m_bIgnoreUpdate=false; + m_bIgnoreTreeRefresh=false; +} + +CFolderDialog::~CFolderDialog() +{ +} + +BEGIN_MESSAGE_MAP(CFolderDialog,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CFolderDialog) + ON_NOTIFY(LVN_ENDLABELEDIT, IDC_SHORTCUT_LIST, OnEndLabelEditShortcutList) + ON_BN_CLICKED(IDC_ADDSHORTCUT_BUTTON, OnAddShortcut) + ON_BN_CLICKED(IDC_REMOVESHORTCUT_BUTTON, OnRemoveShortcut) + ON_BN_CLICKED(IDC_TOGGLE_BUTTON, OnToggleButton) + ON_NOTIFY(TVN_SELCHANGED, IDC_FOLDER_TREE, OnSelchangedFolderTree) + ON_NOTIFY(TVN_GETINFOTIP, IDC_FOLDER_TREE, OnGetInfoTipFolderTree) + ON_BN_CLICKED(IDC_NEWFOLDER_BUTTON, OnNewfolderButton) + ON_CBN_EDITCHANGE(IDC_PATH_COMBOBOXEX, OnPathChanging) + ON_BN_CLICKED(IDC_LARGEICONS_BUTTON, OnIconsRadio) + ON_BN_CLICKED(IDC_SMALLICONS_BUTTON, OnSmalliconsRadio) + ON_BN_CLICKED(IDC_LIST_BUTTON, OnListRadio) + ON_BN_CLICKED(IDC_REPORT_BUTTON, OnReportRadio) + ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHORTCUT_LIST, OnItemchangedShortcutList) + ON_NOTIFY(LVN_GETINFOTIP, IDC_SHORTCUT_LIST, OnGetShortcutInfoTip) + ON_NOTIFY(LVN_KEYDOWN, IDC_SHORTCUT_LIST, OnShortcutKeyDown) + ON_WM_PAINT() + ON_WM_NCHITTEST() + ON_WM_SIZE() + ON_WM_GETMINMAXINFO() + ON_WM_SYSCOLORCHANGE() + ON_WM_CREATE() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CFolderDialog message handlers + +///////////////////////////////////////////////////////////////////////////// +// creating all needed controls + +int CFolderDialog::CreateControls() +{ + // std rect - size doesn't matter for now + CRect rc(0, 0, 0, 0); + + if (!m_ctlTitle.Create(_T(""), WS_CHILD | WS_VISIBLE, rc, this, IDC_TITLE_STATIC) || + (__g_pfStatic=(WNDPROC)SetWindowLong(m_ctlTitle.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlTitle.SetFont(GetFont()); + + // buttons - small with bitmaps + if (!m_ctlLargeIcons.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_LARGEICONS_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlLargeIcons.SetImage(&m_ilList, 0); + + if (!m_ctlSmallIcons.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_SMALLICONS_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlSmallIcons.SetImage(&m_ilList, 1); + + if (!m_ctlList.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_LIST_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlList.SetImage(&m_ilList, 2); + + if (!m_ctlReport.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_REPORT_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlReport.SetImage(&m_ilList, 3); + + if (!m_ctlNewFolder.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_NEWFOLDER_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlNewFolder.SetImage(&m_ilList, 4); + + // listview + if (!m_ctlShortcuts.Create(WS_CHILD | WS_VISIBLE | LVS_SINGLESEL | LVS_SHAREIMAGELISTS | LVS_EDITLABELS | WS_TABSTOP | LVS_SMALLICON | LVS_SHOWSELALWAYS, rc, this, IDC_SHORTCUT_LIST) || + (__g_pfList=(WNDPROC)SetWindowLong(m_ctlShortcuts.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlShortcuts.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_INFOTIP | LVS_EX_UNDERLINEHOT); + m_ctlShortcuts.ModifyStyleEx(0, WS_EX_CLIENTEDGE); + + // dir tree ctrl + if (!m_ctlTree.Create(WS_CHILD | WS_VISIBLE | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS + | TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | TVS_TRACKSELECT | TVS_SINGLEEXPAND | TVS_INFOTIP | + WS_TABSTOP | WS_VSCROLL, rc, this, IDC_FOLDER_TREE) + || !m_ctlTree.ModifyStyleEx(0, WS_EX_NOPARENTNOTIFY | WS_EX_CLIENTEDGE)) + { + TRACE("Error creating control..."); + return -1; + } + + // combobox + rc.bottom=rc.top+200; + if (!m_ctlPath.Create(WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL | CBS_DROPDOWN | CBS_SORT | CBS_OWNERDRAWFIXED | CBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rc, this, IDC_PATH_COMBOBOXEX) || + (__g_pfCombo=(WNDPROC)SetWindowLong(m_ctlPath.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) + { + TRACE("Error creating control..."); + return -1; + } + HWND hCombo=(HWND)m_ctlPath.SendMessage(CBEM_GETCOMBOCONTROL, 0, 0); + if ((__g_pfBaseCombo=(WNDPROC)SetWindowLong(hCombo, GWLP_WNDPROC, (LONG)ComboWindowProc)) == 0) + return -1; + HWND hEdit=(HWND)m_ctlPath.SendMessage(CBEM_GETEDITCONTROL, 0, 0); + if ((__g_pfEdit=(WNDPROC)SetWindowLong(hEdit, GWLP_WNDPROC, (LONG)EditWindowProc)) == 0) + return -1; + + // buttons OK & Cancel + rc.bottom=rc.top; + if (!m_ctlOk.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, rc, this, IDOK) || + (__g_pfButton=(WNDPROC)SetWindowLong(m_ctlOk.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc)) == 0) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlOk.SetFont(GetFont()); + + if (!m_ctlCancel.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rc, this, IDCANCEL) || + !((WNDPROC)SetWindowLong(m_ctlCancel.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc))) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlCancel.SetFont(GetFont()); + + if (!m_ctlToggle.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rc, this, IDC_TOGGLE_BUTTON) || + !((WNDPROC)SetWindowLong(m_ctlToggle.GetSafeHwnd(), GWLP_WNDPROC, (LONG)CustomWindowProc))) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlToggle.SetFont(GetFont()); + + // add&remove shortcut + if (!m_ctlRemoveShortcut.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_REMOVESHORTCUT_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlRemoveShortcut.SetImage(&m_ilList, 6); + + if (!m_ctlAddShortcut.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, rc, this, IDC_ADDSHORTCUT_BUTTON)) + { + TRACE("Error creating control..."); + return -1; + } + m_ctlAddShortcut.SetImage(&m_ilList, 5); + + return 0; +} + +/////////////////////////////////////////////////////////////////////////// +// tworzy image list� z wszystkimi potrzebnymi ikonami +void CFolderDialog::InitImageList() +{ + m_ilList.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1); + + HICON hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_LARGEICONS_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); + + hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_SMALLICONS_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); + + hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_LIST_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); + + hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_REPORT_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); + + hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_NEWFOLDER_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); + + hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_ADDSHORTCUT_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); + + hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDI_DELETESHORTCUT_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR); + m_ilList.Add(hIcon); +} + +//////////////////////////////////////////////////////////////////////////// +// applies showing/hiding shortcuts list +void CFolderDialog::ApplyExpandState(bool bExpand) +{ + // change button text and hide/show needed elements + m_ctlToggle.SetWindowText(GetResManager()->LoadString(bExpand ? IDS_BDRIGHT_STRING : IDS_BDLEFT_STRING)); + m_ctlShortcuts.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); + m_ctlLargeIcons.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); + m_ctlSmallIcons.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); + m_ctlList.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); + m_ctlReport.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); + m_ctlAddShortcut.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); + m_ctlRemoveShortcut.ShowWindow(bExpand ? SW_SHOW : SW_HIDE); +} + +//////////////////////////////////////////////////////////////////////////// +// toggle extended view +void CFolderDialog::OnToggleButton() +{ + m_bdData.bExtended=!m_bdData.bExtended; + ApplyExpandState(m_bdData.bExtended); + + CRect rcDialog; + GetClientRect(&rcDialog); + ResizeControls(rcDialog.Width(), rcDialog.Height()); +} + +///////////////////////////////////////////////////////////////////////////// +// initialization of most important params - reading text, bitmaps +BOOL CFolderDialog::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // image list + InitImageList(); + + if (CreateControls() == -1) + EndDialog(-1); + + // size of a dialog + CRect rcDialog; + GetClientRect(&rcDialog); + if (m_bdData.cx != 0) + rcDialog.right=rcDialog.left+m_bdData.cx; + if (m_bdData.cy != 0) + rcDialog.bottom=rcDialog.top+m_bdData.cy; + if (m_bdData.cy != 0 || m_bdData.cx != 0) + SetWindowPos(&wndTop, rcDialog.left, rcDialog.top, rcDialog.Width(), rcDialog.Height(), SWP_NOMOVE); + + // show needed text + SetWindowText(m_bdData.strCaption); + m_ctlTitle.SetWindowText(m_bdData.strText); + m_ctlTree.SetIgnoreShellDialogs(m_bdData.bIgnoreDialogs); + m_ctlTree.PostMessage(WM_SETPATH, 0, (LPARAM)((LPCTSTR)m_bdData.strInitialDir)); + + // buttons text + m_ctlOk.SetWindowText(GetResManager()->LoadString(IDS_BDOK_STRING)); + m_ctlCancel.SetWindowText(GetResManager()->LoadString(IDS_BDCANCEL_STRING)); + ApplyExpandState(m_bdData.bExtended); + + // sys img list + SHFILEINFO sfi; + m_hImages = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + m_hLargeImages=(HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX); + m_ctlPath.SendMessage(CBEM_SETIMAGELIST, 0, (LPARAM)m_hImages); + m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)m_hImages); + m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)m_hLargeImages); + + // add all the paths from m_bdData.astrRecent + COMBOBOXEXITEM cbi; + CString strText; + cbi.mask=CBEIF_IMAGE | CBEIF_TEXT; + + for (int i=0;i<(int)m_bdData.cvRecent.size();i++) + { + cbi.iItem=i; + cbi.pszText=m_bdData.cvRecent.at(i); + sfi.iIcon=-1; + SHGetFileInfo(m_bdData.cvRecent.at(i), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + cbi.iImage=sfi.iIcon; + + m_ctlPath.InsertItem(&cbi); + } + + // additional columns in a list + LVCOLUMN lvc; + lvc.mask=LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT; + lvc.iSubItem=-1; + lvc.cx=80; + lvc.pszText=(LPTSTR)GetResManager()->LoadString(IDS_BDNAME_STRING); + m_ctlShortcuts.InsertColumn(0, &lvc); + lvc.iSubItem=0; + lvc.cx=110; + lvc.pszText=(LPTSTR)GetResManager()->LoadString(IDS_BDPATH_STRING); + m_ctlShortcuts.InsertColumn(1, &lvc); + + // select view-style button + SetView(m_bdData.iView); + + // update shortcuts' list + CShortcut sc; + for (int i=0;i<(int)m_bdData.cvShortcuts.size();i++) + { + sc=CString(m_bdData.cvShortcuts.at(i)); + sfi.iIcon=-1; + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.InsertItem(i, sc.m_strName, sfi.iIcon); + m_ctlShortcuts.SetItem(i, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + } + + // now resize and ok. + GetClientRect(&rcDialog); + ResizeControls(rcDialog.Width(), rcDialog.Height()); + + // set to top - the strange way + SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); + SetFocus(); + SetForegroundWindow(); + + return TRUE; +} + +//////////////////////////////////////////////////////////////////////////// +// tooltip handling for controls in this dialog +BOOL CFolderDialog::OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip) +{ + switch (uiID) + { + case IDC_NEWFOLDER_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDNEWFOLDER_STRING); + break; + case IDC_LARGEICONS_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDLARGEICONS_STRING); + break; + case IDC_SMALLICONS_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDSMALLICONS_STRING); + break; + case IDC_LIST_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDLIST_STRING); + break; + case IDC_REPORT_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDREPORT_STRING); + break; + case IDC_TOGGLE_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDDETAILS_STRING); + break; + case IDC_ADDSHORTCUT_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDADDSHORTCUT_STRING); + break; + case IDC_REMOVESHORTCUT_BUTTON: + pTip->lpszText=(LPTSTR)GetResManager()->LoadString(IDS_BDREMOVESHORTCUT_STRING); + break; + default: + return FALSE; + } + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////// +// cancels the dialog or cancels editing of an item +void CFolderDialog::OnCancel() +{ + if (m_ctlTree.IsEditing()) + { + TreeView_EndEditLabelNow(m_ctlTree.GetSafeHwnd(), TRUE); + return; + } + + CRect rcDlg; + GetWindowRect(&rcDlg); + m_bdData.cx=rcDlg.Width(); + m_bdData.cy=rcDlg.Height(); + + CLanguageDialog::OnCancel(); +} + +/////////////////////////////////////////////////////////////////////////// +// finishes dialog's work or finished editing of an item +void CFolderDialog::OnOK() +{ + // if we edit an item in m_ctlTree + if (m_ctlTree.IsEditing()) + { + TreeView_EndEditLabelNow(m_ctlTree.GetSafeHwnd(), FALSE); + return; + } + + // update path, get rid of '\\' + m_ctlPath.GetWindowText(m_strPath); + if (m_strPath.Right(1) == _T('\\') || m_strPath.Right(1) == _T('/')) + m_strPath=m_strPath.Left(m_strPath.GetLength()-1); + + // does it exist as a folder ? +/* CFileFind fnd; + BOOL bExist=fnd.FindFile(m_strPath+_T("\\*")); + fnd.Close();*/ +// WIN32_FIND_DATA wfd; +// HANDLE hFind; + +// if (!bExist) + if ( GetFileAttributes(m_strPath) == INVALID_FILE_ATTRIBUTES) + { + MsgBox(IDS_BDPATHDOESNTEXIST_STRING, MB_OK | MB_ICONERROR); + return; + } + + m_bdData.cvRecent.insert(m_bdData.cvRecent.begin(), (const PTSTR)(LPCTSTR)(m_strPath+_T('\\')), true); + + CRect rcDlg; + GetWindowRect(&rcDlg); + m_bdData.cx=rcDlg.Width(); + m_bdData.cy=rcDlg.Height(); + + CLanguageDialog::OnOK(); +} + +/////////////////////////////////////////////////////////////////////////// +// Displays dialog from __g_DlgTemplate +INT_PTR CFolderDialog::DoModal() +{ + if (!InitModalIndirect((LPCDLGTEMPLATE)__g_DlgTemplate)) + return -1; + else + return ictranslate::CLanguageDialog::DoModal(); +} + +/////////////////////////////////////////////////////////////////////////// +// handles creation of a new folder +void CFolderDialog::OnNewfolderButton() +{ + // currently selected item + HTREEITEM hItem=m_ctlTree.GetSelectedItem(); + if (hItem == NULL) + return; + + // insert child item + m_ctlTree.InsertNewFolder(hItem, _T("")); +} + +///////////////////////////////////////////////////////////////////////////// +// other messages +LRESULT CFolderDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_CREATEFOLDERRESULT: + if (((int)lParam) != 1) + MsgBox(IDS_BDCANNOTCREATEFOLDER_STRING); + break; + case WM_THEMECHANGED: + CRect rcDialog; + GetClientRect(&rcDialog); + ResizeControls(rcDialog.Width(), rcDialog.Height()); + break; + } + + return ictranslate::CLanguageDialog::WindowProc(message, wParam, lParam); +} + +////////////////////////////////////////////////////////////////////////////// +// tooltips for folder tree +void CFolderDialog::OnGetInfoTipFolderTree(NMHDR* pNMHDR, LRESULT* pResult) +{ + NMTVGETINFOTIP* pit = (NMTVGETINFOTIP*)pNMHDR; + *pResult = 0; + + // get rid of old tip + m_strTip.Empty(); + + // get type of an item - for floppy skip + SHDESCRIPTIONID shdi; + bool bSkipFreeSpace=false; + if (m_ctlTree.GetItemShellData(pit->hItem, SHGDFIL_DESCRIPTIONID, &shdi, sizeof(SHDESCRIPTIONID)) + && ( shdi.dwDescriptionId == SHDID_COMPUTER_DRIVE35 + || shdi.dwDescriptionId == SHDID_COMPUTER_DRIVE525 ) ) + bSkipFreeSpace=true; + + + // some about network + bool bNet; + CString strData; + NETRESOURCE* pnet=(NETRESOURCE*)m_szBuffer; + if ( (bNet=m_ctlTree.GetItemShellData(pit->hItem, SHGDFIL_NETRESOURCE, pnet, 2048)) == true) + { + if (pnet->lpRemoteName && _tcscmp(pnet->lpRemoteName, _T("")) != 0) + m_strTip+=GetResManager()->LoadString(IDS_BDREMOTENAME_STRING)+CString(pnet->lpRemoteName)+_T("\n"); + if ( pnet->lpLocalName && _tcscmp(pnet->lpLocalName, _T("")) != 0) + m_strTip+=GetResManager()->LoadString(IDS_BDLOCALNAME_STRING)+CString(pnet->lpLocalName)+_T("\n"); + if ( pnet->dwDisplayType != 0) + m_strTip+=GetResManager()->LoadString(IDS_BDTYPE_STRING)+CString(GetResManager()->LoadString(IDS_BDDOMAIN_STRING+pnet->dwDisplayType))+_T("\n"); + if ( pnet->lpProvider && _tcscmp(pnet->lpProvider, _T("")) != 0) + m_strTip+=GetResManager()->LoadString(IDS_BDNETTYPE_STRING)+CString(pnet->lpProvider)+_T("\n"); + if ( pnet->lpComment && _tcscmp(pnet->lpComment, _T("")) != 0) + m_strTip+=GetResManager()->LoadString(IDS_BDDESCRIPTION_STRING)+CString(pnet->lpComment)+_T("\n"); + } + + // try to get path + CString strPath, strMask; + TCHAR szSizeFree[32], szSizeTotal[32]; + bool bPath; + if ( (bPath=m_ctlTree.GetPath(pit->hItem, strPath.GetBuffer(_MAX_PATH))) == true ) + { + strPath.ReleaseBuffer(); + if (!bNet && !strPath.IsEmpty()) + m_strTip+=strPath+_T("\n"); + + if (!bSkipFreeSpace) + { + // get disk free space + ull_t ullFree, ullTotal; + if (GetDynamicFreeSpace(strPath, &ullFree, &ullTotal)) + { + m_strTip+=GetResManager()->LoadString(IDS_BDFREESPACE_STRING)+CString(GetSizeString(ullFree, szSizeFree, 32, false))+_T("\n"); + m_strTip+=GetResManager()->LoadString(IDS_BDCAPACITY_STRING)+CString(GetSizeString(ullTotal, szSizeTotal, 32, false))+_T("\n"); + } + } + } + + if (!bNet && !bPath) + { + // get std shell msg + m_ctlTree.GetItemInfoTip(pit->hItem, &m_strTip); + } + else + { + // get rid of '\n' + m_strTip=m_strTip.Left(m_strTip.GetLength()-1); + } + + // set + pit->pszText=m_strTip.GetBuffer(1); // tip doesn't change - skip RelaseBuffer + pit->cchTextMax=lstrlen(pit->pszText); +} + +///////////////////////////////////////////////////////////////////////////// +// tooltip support for shortcuts list +void CFolderDialog::OnGetShortcutInfoTip(NMHDR* pNMHDR, LRESULT* /*pResult*/) +{ + NMLVGETINFOTIP* pit=(NMLVGETINFOTIP*)pNMHDR; + m_strTip.Empty(); + + if (pit->iItem < 0 || pit->iItem >= (int)m_bdData.cvShortcuts.size()) + return; // out of range + + CShortcut sc=CString(m_bdData.cvShortcuts.at(pit->iItem)); + m_strTip=sc.m_strName+_T("\r\n")+CString(GetResManager()->LoadString(IDS_BDPATH2_STRING))+sc.m_strPath; + + // get disk free space + ull_t ullFree, ullTotal; + if (GetDynamicFreeSpace(sc.m_strPath, &ullFree, &ullTotal)) + { + m_strTip+=CString(_T("\r\n"))+GetResManager()->LoadString(IDS_BDFREESPACE_STRING)+CString(GetSizeString(ullFree, m_szBuffer, 2048, false))+_T("\n"); + m_strTip+=GetResManager()->LoadString(IDS_BDCAPACITY_STRING)+CString(GetSizeString(ullTotal, m_szBuffer, 2048, false)); + } + + pit->pszText=(LPTSTR)(LPCTSTR)m_strTip; + pit->cchTextMax=m_strTip.GetLength()+1; +} + +//////////////////////////////////////////////////////////////////////////// +// updates text in combo when the selection in a tree changes +void CFolderDialog::OnSelchangedFolderTree(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; + TCHAR szPath[_MAX_PATH]; + + if (m_bIgnoreUpdate) + return; + + if (m_ctlTree.GetPath(pNMTreeView->itemNew.hItem, szPath)) + SetComboPath(szPath); + + *pResult = 0; +} + +//////////////////////////////////////////////////////////////////////////// +// updates folder tree when combo text changes +void CFolderDialog::OnPathChanging() +{ + if (m_bIgnoreTreeRefresh) + return; + + COMBOBOXEXITEM cbi; + cbi.mask=CBEIF_TEXT; + cbi.iItem=-1; + cbi.pszText=m_szBuffer; + cbi.cchTextMax=_MAX_PATH; + + if (!m_ctlPath.GetItem(&cbi)) + return; + + UpdateComboIcon(); + + m_bIgnoreUpdate=true; + m_ctlTree.SetPath(cbi.pszText); + m_bIgnoreUpdate=false; +} + +///////////////////////////////////////////////////////////////////////// +// sets text in comboboxex edit and updates icon +void CFolderDialog::SetComboPath(LPCTSTR lpszPath) +{ + _ASSERTE(lpszPath); + if(!lpszPath) + return; + // set current select to -1 + m_bIgnoreTreeRefresh=true; + m_ctlPath.SetCurSel(-1); + m_bIgnoreTreeRefresh=false; + + SHFILEINFO sfi; + sfi.iIcon=-1; + + COMBOBOXEXITEM cbi; + + cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; + cbi.iItem=-1; + _tcscpy(m_szBuffer, lpszPath); + cbi.pszText=m_szBuffer; + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + cbi.iImage=sfi.iIcon; + m_bIgnoreTreeRefresh=true; + m_ctlPath.SetItem(&cbi); + m_bIgnoreTreeRefresh=false; +} + +////////////////////////////////////////////////////////////////////////// +// updates icon in comboex +void CFolderDialog::UpdateComboIcon() +{ + // get text from combo + COMBOBOXEXITEM cbi; + cbi.mask=CBEIF_TEXT; + cbi.iItem=m_ctlPath.GetCurSel()/*-1*/; + cbi.pszText=m_szBuffer; + cbi.cchTextMax=_MAX_PATH; + + if (!m_ctlPath.GetItem(&cbi)) + return; + + // select no item + m_bIgnoreTreeRefresh=true; + m_ctlPath.SetCurSel(-1); + m_bIgnoreTreeRefresh=false; + + // icon update + SHFILEINFO sfi; + sfi.iIcon=-1; + + cbi.mask |= CBEIF_IMAGE; + cbi.iItem=-1; + + CString str=(LPCTSTR)m_szBuffer; + if (str.Left(2) != _T("\\\\") || str.Find(_T('\\'), 2) != -1) + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + + cbi.iImage=sfi.iIcon; + + m_bIgnoreTreeRefresh=true; + m_ctlPath.SetItem(&cbi); + m_bIgnoreTreeRefresh=false; + + // unselect text in combo's edit + CEdit* pEdit=m_ctlPath.GetEditCtrl(); + if (!pEdit) + return; + + pEdit->SetSel(-1, -1); +} + +///////////////////////////////////////////////////////////////////////////// +// combo and treeview update +void CFolderDialog::OnItemchangedShortcutList(NMHDR* pNMHDR, LRESULT* pResult) +{ + NMLISTVIEW* plv=(NMLISTVIEW*)pNMHDR; + + // current selection + if (plv->iItem >= 0 && plv->iItem < (int)m_bdData.cvShortcuts.size()) + { + CShortcut sc=CString(m_bdData.cvShortcuts.at(plv->iItem)); + m_ctlTree.SetPath(sc.m_strPath); + SetComboPath(sc.m_strPath); + } + + *pResult = 0; +} + +///////////////////////////////////////////////////////////////////////////// +// adding shortcut +void CFolderDialog::OnAddShortcut() +{ + // get current text + COMBOBOXEXITEM cbi; + cbi.mask=CBEIF_TEXT; + cbi.iItem=m_ctlPath.GetCurSel()/*-1*/; + cbi.pszText=m_szBuffer; + cbi.cchTextMax=_MAX_PATH; + + if (!m_ctlPath.GetItem(&cbi)) + { + MsgBox(IDS_BDNOSHORTCUTPATH_STRING); + return; + } + + // create new item - update shortcut list + CShortcut sc; + sc.m_strPath=cbi.pszText; + SHFILEINFO sfi; + sfi.iIcon=-1; + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + + // add to an array and to shortcuts list + m_bdData.cvShortcuts.push_back((const PTSTR)(LPCTSTR)(CString)(sc), true); + int iIndex=m_bdData.cvShortcuts.size()-1; + m_ctlShortcuts.InsertItem(iIndex, sc.m_strName, sfi.iIcon); + m_ctlShortcuts.SetItem(iIndex, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + + // edit item + m_ctlShortcuts.SetFocus(); + if (m_ctlShortcuts.EditLabel(iIndex) == NULL) + { + TRACE("Couldn't edit shortcut list's item label\n"); + return; + } +} + +//////////////////////////////////////////////////////////////////////////// +// keyboard's delete button handling +void CFolderDialog::OnShortcutKeyDown(NMHDR* pNMHDR, LRESULT* /*pResult*/) +{ + LPNMLVKEYDOWN lpkd=(LPNMLVKEYDOWN)pNMHDR; + if (lpkd->wVKey == VK_DELETE) + OnRemoveShortcut(); +} + +//////////////////////////////////////////////////////////////////////////// +// deleting shortcut from list +void CFolderDialog::OnRemoveShortcut() +{ + POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); + if (pos) + { + int iSel=m_ctlShortcuts.GetNextSelectedItem(pos); + m_ctlShortcuts.DeleteItem(iSel); + m_bdData.cvShortcuts.erase(m_bdData.cvShortcuts.begin()+iSel, true); + + m_ctlShortcuts.Arrange(LVA_DEFAULT); + } +} + +/////////////////////////////////////////////////////////////////////////// +// finishing editing shortcut name +void CFolderDialog::OnEndLabelEditShortcutList(NMHDR* pNMHDR, LRESULT* pResult) +{ + NMLVDISPINFO* pdi = (NMLVDISPINFO*)pNMHDR; + + // editing has been cancelled - delete item + if (pdi->item.pszText == NULL) + { + m_ctlShortcuts.DeleteItem(pdi->item.iItem); + m_bdData.cvShortcuts.erase(m_bdData.cvShortcuts.begin()+pdi->item.iItem, true); + + *pResult=0; + return; + } + + // std editing - success + CShortcut sc=CString(m_bdData.cvShortcuts.at(pdi->item.iItem)); + sc.m_strName=pdi->item.pszText; + + m_bdData.cvShortcuts.replace(m_bdData.cvShortcuts.begin()+pdi->item.iItem, (const PTSTR)(LPCTSTR)(CString)sc, true, true); + + *pResult=1; +} + +//////////////////////////////////////////////////////////////////////////// +// sets the style of a shortcuts list +void CFolderDialog::SetView(int iView) +{ + DWORD dwView=0; + switch (iView) + { + case 0: + dwView=LVS_ICON; + break; + case 2: + dwView=LVS_SMALLICON; + break; + case 3: + dwView=LVS_REPORT; + break; + default: + dwView=LVS_LIST; + break; + } + + DWORD dwStyle = GetWindowLong(m_ctlShortcuts.GetSafeHwnd(), GWL_STYLE); + + // Only set the window style if the view bits have changed. + if ((dwStyle & LVS_TYPEMASK) != dwView) + SetWindowLong(m_ctlShortcuts.GetSafeHwnd(), GWL_STYLE, (dwStyle & ~LVS_TYPEMASK) | dwView); + m_ctlShortcuts.Arrange(LVA_ALIGNTOP); +} + +/////////////////////////////////////////////////////////////////////////// +// large icons +void CFolderDialog::OnIconsRadio() +{ + m_bdData.iView=0; + SetView(0); + m_ctlLargeIcons.Invalidate(); + m_ctlSmallIcons.Invalidate(); + m_ctlList.Invalidate(); + m_ctlReport.Invalidate(); +} + +/////////////////////////////////////////////////////////////////////////// +// small icons +void CFolderDialog::OnSmalliconsRadio() +{ + m_bdData.iView=1; + SetView(1); + m_ctlLargeIcons.Invalidate(); + m_ctlSmallIcons.Invalidate(); + m_ctlList.Invalidate(); + m_ctlReport.Invalidate(); +} + +/////////////////////////////////////////////////////////////////////////// +// list button +void CFolderDialog::OnListRadio() +{ + m_bdData.iView=2; + SetView(2); + m_ctlLargeIcons.Invalidate(); + m_ctlSmallIcons.Invalidate(); + m_ctlList.Invalidate(); + m_ctlReport.Invalidate(); +} + +/////////////////////////////////////////////////////////////////////////// +// report button +void CFolderDialog::OnReportRadio() +{ + m_bdData.iView=3; + SetView(3); + m_ctlLargeIcons.Invalidate(); + m_ctlSmallIcons.Invalidate(); + m_ctlList.Invalidate(); + m_ctlReport.Invalidate(); +} + +//////////////////////////////////////////////////////////////////////////// +// resize handling +void CFolderDialog::OnSize(UINT nType, int cx, int cy) +{ + CLanguageDialog::OnSize(nType, cx, cy); + + ResizeControls(cx, cy); + InvalidateRect(&m_rcGripper); +} + +//////////////////////////////////////////////////////////////////////////// +// repositions controls within the dialog +void CFolderDialog::ResizeControls(int cx, int cy) +{ + // is app themed ? + CUxThemeSupport uxt; + bool bThemed=uxt.IsThemeSupported() && uxt.IsAppThemed(); + + // settings + const int iMargin=7; // dialog units + const int iTextCount=3; // ilo�� linii textu w staticu + + // small buttons + const int iBmpMargin=1; // margin between button and a bitmap within + const int iButtonWidth=(bThemed ? 20 : 16)+2*GetSystemMetrics(SM_CXEDGE)+2*iBmpMargin; // fixed size + const int iButtonHeight=(bThemed ? 20 : 16)+2*GetSystemMetrics(SM_CYEDGE)+2*iBmpMargin; + + // large buttons + const int iLargeButtonHeight=14; // OK&Cancel buttons (dialog units) + const int iLargeButtonWidth=50; // width in DU + const int iToggleButtonWidth=18; // toggle size + + // combo + const int iComboHeight=12; + const int iComboExpandedHeight=100; + + // static text at the top of dialog + CRect rcStatic( iMargin, iMargin, 0, iMargin+iTextCount*8 ); + MapDialogRect(&rcStatic); + rcStatic.right=cx-rcStatic.left; + + CWnd* pWnd=GetDlgItem(IDC_TITLE_STATIC); + if (pWnd) + { + pWnd->MoveWindow(&rcStatic); + pWnd->Invalidate(); + } + + // 4*button (**********) + CRect rcButton(iMargin, iMargin+iTextCount*8+5, 0, 0); + MapDialogRect(&rcButton); + rcButton.right=rcButton.left+iButtonWidth; + rcButton.bottom=rcButton.top+iButtonHeight; + pWnd=GetDlgItem(IDC_LARGEICONS_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + rcButton.left+=iButtonWidth; + rcButton.right+=iButtonWidth; + pWnd=GetDlgItem(IDC_SMALLICONS_BUTTON); + if (pWnd) + pWnd->MoveWindow(&rcButton); + + rcButton.left+=iButtonWidth; + rcButton.right+=iButtonWidth; + pWnd=GetDlgItem(IDC_LIST_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + rcButton.left+=iButtonWidth; + rcButton.right+=iButtonWidth; + pWnd=GetDlgItem(IDC_REPORT_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + // new folder button + rcButton=CRect(iMargin, iMargin+iTextCount*8+5, iMargin, 0); + MapDialogRect(&rcButton); + rcButton.left=cx-rcButton.left-iButtonWidth-1; // off by 1 - better looks + rcButton.right=cx-rcButton.right-1; + rcButton.bottom=rcButton.top+iButtonHeight; + pWnd=GetDlgItem(IDC_NEWFOLDER_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + // shortcuts list (**********) + CRect rcShortcuts(iMargin, iMargin+iTextCount*8+5+1, 2*iMargin+5, iMargin+iLargeButtonHeight+5+iComboHeight+3); + MapDialogRect(&rcShortcuts); + rcShortcuts.top+=iButtonHeight; // small button size + rcShortcuts.right=MulDiv((cx-rcShortcuts.right), 35, 120); + rcShortcuts.bottom=cy-rcShortcuts.bottom; + pWnd=GetDlgItem(IDC_SHORTCUT_LIST); + if (pWnd) + { + pWnd->MoveWindow(&rcShortcuts); + pWnd->Invalidate(); + } + + // button toggle + rcButton=CRect(iMargin+(m_bdData.bExtended ? 5 : 0), iMargin+iTextCount*8+5, iToggleButtonWidth, iLargeButtonHeight); + MapDialogRect(&rcButton); + if (m_bdData.bExtended) + rcButton.left+=rcShortcuts.Width()+1; + rcButton.right+=rcButton.left; + rcButton.bottom+=rcButton.top; + pWnd=GetDlgItem(IDC_TOGGLE_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + // tree ctrl + CRect rcTree(iMargin+(m_bdData.bExtended ? 5 : 0), iMargin+iTextCount*8+5+1, iMargin, iMargin+iLargeButtonHeight+5+iComboHeight+3 ); + MapDialogRect(&rcTree); + rcTree.top+=iButtonHeight; + rcTree.bottom=cy-rcTree.bottom; + rcTree.right=cx-rcTree.right; + if (m_bdData.bExtended) + rcTree.left+=rcShortcuts.Width(); + pWnd=GetDlgItem(IDC_FOLDER_TREE); + if (pWnd) + { + pWnd->MoveWindow(&rcTree); + pWnd->Invalidate(); + } + + // combo + CRect rcCombo(iMargin+(m_bdData.bExtended ? 5 : 0), iMargin+iLargeButtonHeight+5+iComboHeight, iMargin, iComboExpandedHeight/*iMargin+iLargeButtonHeight+5*/); + MapDialogRect(&rcCombo); + if (m_bdData.bExtended) + rcCombo.left+=rcShortcuts.Width(); + rcCombo.top=cy-rcCombo.top; + rcCombo.right=cx-rcCombo.right; + rcCombo.bottom+=rcCombo.top; + pWnd=GetDlgItem(IDC_PATH_COMBOBOXEX); + if (pWnd) + { + pWnd->MoveWindow(&rcCombo); + pWnd->Invalidate(); + } + + // button - add shortcut/remove shortcut + rcButton=CRect(0, iMargin+iLargeButtonHeight+5+iComboHeight, 0, 0); + MapDialogRect(&rcButton); + rcButton.top=cy-rcButton.top; + rcButton.left=rcShortcuts.right-iButtonWidth; + rcButton.right=rcButton.left+iButtonWidth; + rcButton.bottom=rcButton.top+iButtonHeight; + pWnd=GetDlgItem(IDC_ADDSHORTCUT_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + rcButton.left-=iButtonWidth; + rcButton.right-=iButtonWidth; + pWnd=GetDlgItem(IDC_REMOVESHORTCUT_BUTTON); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + // buttony - ok & cancel + rcButton=CRect(iMargin+2*iLargeButtonWidth+3, iMargin+iLargeButtonHeight, iMargin+iLargeButtonWidth+3, iMargin); + MapDialogRect(&rcButton); + rcButton.left=cx-rcButton.left; + rcButton.top=cy-rcButton.top; + rcButton.right=cx-rcButton.right; + rcButton.bottom=cy-rcButton.bottom; + pWnd=GetDlgItem(IDOK); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } + + rcButton=CRect(iMargin+iLargeButtonWidth, iMargin+iLargeButtonHeight, iMargin, iMargin); + MapDialogRect(&rcButton); + rcButton.left=cx-rcButton.left; + rcButton.top=cy-rcButton.top; + rcButton.right=cx-rcButton.right; + rcButton.bottom=cy-rcButton.bottom; + pWnd=GetDlgItem(IDCANCEL); + if (pWnd) + { + pWnd->MoveWindow(&rcButton); + pWnd->Invalidate(); + } +} + +/////////////////////////////////////////////////////////////////////////// +// minimum size of a window +void CFolderDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) +{ + CRect rcMin(0, 0, 200, 160); + MapDialogRect(&rcMin); + lpMMI->ptMinTrackSize=rcMin.BottomRight(); +} + +///////////////////////////////////////////////////////////////////////////// +// paints a gripper +void CFolderDialog::OnPaint() +{ + if (!IsZoomed()) + { + CPaintDC dc(this); // device context for painting + + CRect rc; + GetClientRect(rc); + + rc.left = rc.right-GetSystemMetrics(SM_CXHSCROLL); + rc.top = rc.bottom-GetSystemMetrics(SM_CYVSCROLL); + m_rcGripper=rc; + dc.DrawFrameControl(rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP); + } + else + { + CPaintDC dc(this); + DefWindowProc(WM_PAINT, (WPARAM)dc.GetSafeHdc(), 0); + } +} + +//////////////////////////////////////////////////////////////////////////// +// hit testing in a gripper cause +LRESULT CFolderDialog::OnNcHitTest(CPoint point) +{ + UINT uiRes=CLanguageDialog::OnNcHitTest(point); + if (uiRes == HTCLIENT) + { + CRect rc; + GetWindowRect(&rc); + rc.left = rc.right-GetSystemMetrics(SM_CXHSCROLL); + rc.top = rc.bottom-GetSystemMetrics(SM_CYVSCROLL); + if (rc.PtInRect(point)) + uiRes = HTBOTTOMRIGHT; + } + + return uiRes; +} + +//////////////////////////////////////////////////////////////////////////// +// returns combo's path after dialog finishes +void CFolderDialog::GetPath(LPTSTR pszPath) +{ + _tcscpy(pszPath, m_strPath); +} + +//////////////////////////////////////////////////////////////////////////// +// returns combo's path after dialog finishes +void CFolderDialog::GetPath(CString &rstrPath) +{ + rstrPath=m_strPath; +} + +//////////////////////////////////////////////////////////////////////////// +// opens choose folder dialog +int BrowseForFolder(CFolderDialog::BROWSEDATA* pData, LPTSTR pszPath) +{ + _ASSERTE(pData && pszPath); + if(!pData || !pszPath) + return IDCANCEL; + ASSERT(pData); + ASSERT(pszPath); + CFolderDialog dlg; + dlg.m_bdData=*pData; + + int iResult=dlg.DoModal(); + if (iResult == IDOK) + { + dlg.GetPath(pszPath); // returned path + *pData=dlg.m_bdData; // future + } + else + _tcscpy(pszPath, _T("")); + + return iResult; +} Index: src/ch/FolderDialog.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/FolderDialog.h (.../FolderDialog.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/FolderDialog.h (.../FolderDialog.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,166 +1,166 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/************************************************************************* - CFolderDialog dialog control - - Files: FolderDialog.h, FolderDialog.cpp - Author: Ixen Gerthannes - Usage: - 1. Construct variable of type CFolderDialog - 2. Fill m_bdData member with appropriate information - 3. Call DoModal() - Functions: - void GetPath(CString& rstrPath); - returns chosen path - void GetPath(LPTSTR pszPath); - returns chosen path -*************************************************************************/ -#ifndef __FOLDERDIALOG_H__ -#define __FOLDERDIALOG_H__ - -#include "afxtempl.h" -#include "DirTreeCtrl.h" -#include "ThemedButton.h" -#include "shortcuts.h" -#include "charvect.h" -#include "../libictranslate/LanguageDialog.h" - -///////////////////////////////////////////////////////////////////////////// -// CFolderDialog dialog - -class CFolderDialog : public ictranslate::CLanguageDialog -{ -// Construction -public: - CFolderDialog(CWnd* pParent = NULL); // standard constructor - virtual ~CFolderDialog(); - -// Dialog Data - //{{AFX_DATA(CFolderDialog) - //}}AFX_DATA - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CFolderDialog) - public: - virtual INT_PTR DoModal(); - protected: - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - //}}AFX_VIRTUAL - -public: - virtual BOOL OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip); - - // structure used for passing parameters - struct BROWSEDATA - { - BROWSEDATA() { cx=0; cy=0; iView=2; bExtended=false; }; -// BROWSEDATA& operator=(const BROWSEDATA& data) { strCaption=data.strCaption; strText=data.strText; strInitialDir=data.strInitialDir; astrRecent.Copy(data.astrRecent); -// ascShortcuts.Copy(data.ascShortcuts); cx=data.cx; cy=data.cy; iView=data.iView; bExtended=data.bExtended; return *this;}; - - CString strCaption; - CString strText; - CString strInitialDir; - char_vector cvRecent; - char_vector cvShortcuts; - - int cx, cy; // pixels - int iView; // type of view (large icons, small icons, ...) - bool bExtended; // with the shortcuts or not - bool bIgnoreDialogs; // if tree ctrl should show shell dialogs in style 'insert floppy' - } m_bdData; - - // getting path - after dialog exits - void GetPath(CString& rstrPath); - void GetPath(LPTSTR pszPath); - - // function displays dialog with some parameters - friend int BrowseForFolder(BROWSEDATA* pData, LPTSTR pszPath); - -// Implementation -protected: - void InitImageList(); - void ApplyExpandState(bool bExpand); - int CreateControls(); - void SetView(int iView); - void UpdateComboIcon(); - void SetComboPath(LPCTSTR lpszPath); - void ResizeControls(int cx, int cy); - - CString m_strTip; // for tooltip storage - TCHAR m_szBuffer[2048]; // shell functions buffer - CString m_strPath; // for path after dialog exits - - bool m_bIgnoreUpdate; // ignores nearest edit update (with path) - bool m_bIgnoreTreeRefresh; // ignores nearest refreshing of tree ctrl - HIMAGELIST m_hImages, m_hLargeImages; // two system image lists - large and small icons - - // button bitmaps - CImageList m_ilList; // image list with buttons' images - - // last position in which gripper has been drawn - CRect m_rcGripper; - - // controls that'll be diaplyed in a dialog - CStatic m_ctlTitle; - CDirTreeCtrl m_ctlTree; - CComboBoxEx m_ctlPath; - CListCtrl m_ctlShortcuts; - CThemedButton m_ctlLargeIcons; - CThemedButton m_ctlSmallIcons; - CThemedButton m_ctlList; - CThemedButton m_ctlReport; - CThemedButton m_ctlNewFolder; - CButton m_ctlOk; - CButton m_ctlCancel; - CThemedButton m_ctlToggle; - CThemedButton m_ctlAddShortcut; - CThemedButton m_ctlRemoveShortcut; - - - // Generated message map functions - //{{AFX_MSG(CFolderDialog) - afx_msg void OnEndLabelEditShortcutList(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnAddShortcut(); - afx_msg void OnRemoveShortcut(); - afx_msg void OnToggleButton(); - afx_msg void OnSelchangedFolderTree(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnGetInfoTipFolderTree(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnShortcutKeyDown(NMHDR* pNMHDR, LRESULT* pResult); - virtual BOOL OnInitDialog(); - afx_msg void OnNewfolderButton(); - virtual void OnCancel(); - virtual void OnOK(); - afx_msg void OnPathChanging(); - afx_msg void OnIconsRadio(); - afx_msg void OnSmalliconsRadio(); - afx_msg void OnListRadio(); - afx_msg void OnReportRadio(); - afx_msg void OnItemchangedShortcutList(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnGetShortcutInfoTip(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnPaint(); - afx_msg LRESULT OnNcHitTest(CPoint point); - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +/************************************************************************* + CFolderDialog dialog control + + Files: FolderDialog.h, FolderDialog.cpp + Author: Ixen Gerthannes + Usage: + 1. Construct variable of type CFolderDialog + 2. Fill m_bdData member with appropriate information + 3. Call DoModal() + Functions: + void GetPath(CString& rstrPath); - returns chosen path + void GetPath(LPTSTR pszPath); - returns chosen path +*************************************************************************/ +#ifndef __FOLDERDIALOG_H__ +#define __FOLDERDIALOG_H__ + +#include "afxtempl.h" +#include "DirTreeCtrl.h" +#include "ThemedButton.h" +#include "shortcuts.h" +#include "charvect.h" +#include "../libictranslate/LanguageDialog.h" + +///////////////////////////////////////////////////////////////////////////// +// CFolderDialog dialog + +class CFolderDialog : public ictranslate::CLanguageDialog +{ +// Construction +public: + CFolderDialog(CWnd* pParent = NULL); // standard constructor + virtual ~CFolderDialog(); + +// Dialog Data + //{{AFX_DATA(CFolderDialog) + //}}AFX_DATA + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CFolderDialog) + public: + virtual INT_PTR DoModal(); + protected: + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + //}}AFX_VIRTUAL + +public: + virtual BOOL OnTooltipText(UINT uiID, TOOLTIPTEXT* pTip); + + // structure used for passing parameters + struct BROWSEDATA + { + BROWSEDATA() { cx=0; cy=0; iView=2; bExtended=false; }; +// BROWSEDATA& operator=(const BROWSEDATA& data) { strCaption=data.strCaption; strText=data.strText; strInitialDir=data.strInitialDir; astrRecent.Copy(data.astrRecent); +// ascShortcuts.Copy(data.ascShortcuts); cx=data.cx; cy=data.cy; iView=data.iView; bExtended=data.bExtended; return *this;}; + + CString strCaption; + CString strText; + CString strInitialDir; + char_vector cvRecent; + char_vector cvShortcuts; + + int cx, cy; // pixels + int iView; // type of view (large icons, small icons, ...) + bool bExtended; // with the shortcuts or not + bool bIgnoreDialogs; // if tree ctrl should show shell dialogs in style 'insert floppy' + } m_bdData; + + // getting path - after dialog exits + void GetPath(CString& rstrPath); + void GetPath(LPTSTR pszPath); + + // function displays dialog with some parameters + friend int BrowseForFolder(BROWSEDATA* pData, LPTSTR pszPath); + +// Implementation +protected: + void InitImageList(); + void ApplyExpandState(bool bExpand); + int CreateControls(); + void SetView(int iView); + void UpdateComboIcon(); + void SetComboPath(LPCTSTR lpszPath); + void ResizeControls(int cx, int cy); + + CString m_strTip; // for tooltip storage + TCHAR m_szBuffer[2048]; // shell functions buffer + CString m_strPath; // for path after dialog exits + + bool m_bIgnoreUpdate; // ignores nearest edit update (with path) + bool m_bIgnoreTreeRefresh; // ignores nearest refreshing of tree ctrl + HIMAGELIST m_hImages, m_hLargeImages; // two system image lists - large and small icons + + // button bitmaps + CImageList m_ilList; // image list with buttons' images + + // last position in which gripper has been drawn + CRect m_rcGripper; + + // controls that'll be diaplyed in a dialog + CStatic m_ctlTitle; + CDirTreeCtrl m_ctlTree; + CComboBoxEx m_ctlPath; + CListCtrl m_ctlShortcuts; + CThemedButton m_ctlLargeIcons; + CThemedButton m_ctlSmallIcons; + CThemedButton m_ctlList; + CThemedButton m_ctlReport; + CThemedButton m_ctlNewFolder; + CButton m_ctlOk; + CButton m_ctlCancel; + CThemedButton m_ctlToggle; + CThemedButton m_ctlAddShortcut; + CThemedButton m_ctlRemoveShortcut; + + + // Generated message map functions + //{{AFX_MSG(CFolderDialog) + afx_msg void OnEndLabelEditShortcutList(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnAddShortcut(); + afx_msg void OnRemoveShortcut(); + afx_msg void OnToggleButton(); + afx_msg void OnSelchangedFolderTree(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnGetInfoTipFolderTree(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnShortcutKeyDown(NMHDR* pNMHDR, LRESULT* pResult); + virtual BOOL OnInitDialog(); + afx_msg void OnNewfolderButton(); + virtual void OnCancel(); + virtual void OnOK(); + afx_msg void OnPathChanging(); + afx_msg void OnIconsRadio(); + afx_msg void OnSmalliconsRadio(); + afx_msg void OnListRadio(); + afx_msg void OnReportRadio(); + afx_msg void OnItemchangedShortcutList(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnGetShortcutInfoTip(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnPaint(); + afx_msg LRESULT OnNcHitTest(CPoint point); + afx_msg void OnSize(UINT nType, int cx, int cy); + afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/MainWnd.cpp =================================================================== diff -u -r96af155296defce0169a7c3d1414e8297b2dec05 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 96af155296defce0169a7c3d1414e8297b2dec05) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,2202 +1,2202 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" - -#include "MainWnd.h" -#include "OptionsDlg.h" - -#include "shlobj.h" -#include "tchar.h" -#include "structs.h" -#include "dialogs.h" - -#pragma warning (disable : 4201) -#include "mmsystem.h" -#pragma warning (default : 4201) - -#include "FolderDialog.h" - -#include "CustomCopyDlg.h" -#include "btnIDs.h" -#include "..\Common\FileSupport.h" -#include "AboutDlg.h" -#include "register.h" -#include "ShutdownDlg.h" -#include "StringHelpers.h" -#include "..\common\ipcstructs.h" -#include -#include "af_defs.h" -#include "UpdateChecker.h" -#include "UpdaterDlg.h" -#include - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -#define WM_ICON_NOTIFY WM_USER+4 -#define WM_SHOWMINIVIEW WM_USER+3 -#define WM_IDENTIFY WM_USER+11 - -#define TM_AUTOREMOVE 1000 -#define TM_AUTORESUME 1000 -#define TM_ACCEPTING 100 - -// assume max sectors of 4kB (for rounding) -#define MAXSECTORSIZE 4096 - -extern CSharedConfigStruct* g_pscsShared; - -extern int iCount; -extern unsigned short msg[]; - -extern int iOffCount; -extern unsigned char off[]; -extern unsigned short _hash[]; - - -///////////////////////////////////////////////////////////////////////////// -// CMainWnd -// registers main window class -ATOM CMainWnd::RegisterClass() -{ - WNDCLASS wc; - - wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = (WNDPROC)::DefWindowProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = AfxGetInstanceHandle(); - wc.hIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(AFX_IDI_STD_FRAME)); - wc.hCursor = ::LoadCursor(NULL, IDC_ARROW); - wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wc.lpszMenuName = NULL; - wc.lpszClassName = _T("Copy Handler Wnd Class"); - - return ::RegisterClass(&wc); -} - -// creates this window -BOOL CMainWnd::Create() -{ - ATOM at=RegisterClass(); - - return CreateEx(WS_EX_TOOLWINDOW, (LPCTSTR)at, _T("Copy Handler"), WS_OVERLAPPED, 10, 10, 10, 10, NULL, (HMENU)NULL, NULL); -} - -int CMainWnd::ShowTrayIcon() -{ - // create system tray icon - HICON hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR | LR_VGACOLOR); - PCTSTR pszAppVer = GetApp()->GetAppNameVer(); - bool bRes=m_ctlTray.CreateIcon(m_hWnd, WM_TRAYNOTIFY, pszAppVer, hIcon, 0); - if (!bRes) - { -// GetLog()->Log(_T("[CMainWnd] ... creating tray icon failed.")); - return -1; - } - -/* if (!m_ctlTray.ShowIcon()) - GetLog()->Log(_T("[CMainWnd] ... showing tray icon failed.")); - else - GetLog()->Log(_T("[CMainWnd] ... showing tray icon succeeded.")); -*/ - return 0; -} - -IMPLEMENT_DYNCREATE(CMainWnd, CWnd) - -BEGIN_MESSAGE_MAP(CMainWnd, CWnd) - //{{AFX_MSG_MAP(CMainWnd) - ON_COMMAND(ID_POPUP_SHOW_STATUS, OnPopupShowStatus) - ON_COMMAND(ID_POPUP_OPTIONS, OnPopupShowOptions) - ON_WM_CLOSE() - ON_WM_TIMER() - ON_WM_COPYDATA() - ON_WM_CREATE() - ON_COMMAND(ID_SHOW_MINI_VIEW, OnShowMiniView) - ON_COMMAND(ID_POPUP_CUSTOM_COPY, OnPopupCustomCopy) - ON_COMMAND(ID_APP_ABOUT, OnAppAbout) - ON_COMMAND(ID_POPUP_MONITORING, OnPopupMonitoring) - ON_COMMAND(ID_POPUP_SHUTAFTERFINISHED, OnPopupShutafterfinished) - ON_COMMAND(ID_POPUP_REGISTERDLL, OnPopupRegisterdll) - ON_COMMAND(ID_POPUP_UNREGISTERDLL, OnPopupUnregisterdll) - ON_COMMAND(ID_APP_EXIT, OnAppExit) - ON_COMMAND(ID_POPUP_HELP, OnPopupHelp) - //}}AFX_MSG_MAP - ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification) - ON_COMMAND(ID_POPUP_CHECKFORUPDATES, &CMainWnd::OnPopupCheckForUpdates) -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CMainWnd construction/destruction - -CMainWnd::CMainWnd() : - m_pFeedbackFactory(CFeedbackHandlerFactory::CreateFactory()) -{ - m_pdlgStatus=NULL; - m_pdlgMiniView=NULL; - m_dwLastTime=0; -} - -CMainWnd::~CMainWnd() -{ - if(m_pFeedbackFactory) - m_pFeedbackFactory->Delete(); -} - -// case insensitive replacement -inline void ReplaceNoCase(CString& rString, CString strOld, CString strNew) -{ - if (rString.Left(strOld.GetLength()).CompareNoCase(strOld) == 0) - rString=strNew+rString.Right(rString.GetLength()-strOld.GetLength()); -} - -bool TimeToFileTime(const COleDateTime& time, LPFILETIME pFileTime) -{ - SYSTEMTIME sysTime; - sysTime.wYear = (WORD)time.GetYear(); - sysTime.wMonth = (WORD)time.GetMonth(); - sysTime.wDay = (WORD)time.GetDay(); - sysTime.wHour = (WORD)time.GetHour(); - sysTime.wMinute = (WORD)time.GetMinute(); - sysTime.wSecond = (WORD)time.GetSecond(); - sysTime.wMilliseconds = 0; - - // convert system time to local file time - FILETIME localTime; - if (!SystemTimeToFileTime((LPSYSTEMTIME)&sysTime, &localTime)) - return false; - - // convert local file time to UTC file time - if (!LocalFileTimeToFileTime(&localTime, pFileTime)) - return false; - - return true; -} - -bool SetFileDirectoryTime(LPCTSTR lpszName, CFileInfo* pSrcInfo) -{ - FILETIME creation, lastAccess, lastWrite; - - if (!TimeToFileTime(pSrcInfo->GetCreationTime(), &creation) - || !TimeToFileTime(pSrcInfo->GetLastAccessTime(), &lastAccess) - || !TimeToFileTime(pSrcInfo->GetLastWriteTime(), &lastWrite) ) - return false; - - HANDLE handle=CreateFile(lpszName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (handle == INVALID_HANDLE_VALUE) - return false; - - if (!SetFileTime(handle, &creation, &lastAccess, &lastWrite)) - { - CloseHandle(handle); - return false; - } - - if (!CloseHandle(handle)) - return false; - - return true; -} - -// searching for files -inline void RecurseDirectories(CTask* pTask) -{ - TRACE("Searching for files...\n"); - - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFSEARCHINGFORFILES_STRING)); - - // update status - pTask->SetStatus(ST_SEARCHING, ST_STEP_MASK); - - // delete the content of m_files - pTask->FilesRemoveAll(); - - // enter some data to m_files - int nSize=pTask->GetClipboardDataSize(); // size of m_clipboard - const CFiltersArray* pFilters=pTask->GetFilters(); - int iDestDrvNumber=pTask->GetDestDriveNumber(); - bool bIgnoreDirs=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_DIRS) != 0; - bool bForceDirectories=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_FORCE_DIRS) != 0; - bool bMove=pTask->GetStatus(ST_OPERATION_MASK) == ST_MOVE; - CFileInfo fi; - fi.SetClipboard(pTask->GetClipboard()); - - // add everything - ictranslate::CFormat fmt; - for (int i=0;iGetClipboardData(i)->GetPath(), i)) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFMISSINGCLIPBOARDINPUT_STRING)); - fmt.SetParam(_t("%path"), pTask->GetClipboardData(i)->GetPath()); - pTask->m_log.logw(fmt); - continue; - } - else - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFADDINGCLIPBOARDFILE_STRING)); - fmt.SetParam(_t("%path"), pTask->GetClipboardData(i)->GetPath()); - pTask->m_log.logi(fmt); - } - - // found file/folder - check if the dest name has been generated - if (pTask->GetClipboardData(i)->m_astrDstPaths.GetSize() == 0) - { - // generate something - if dest folder == src folder - search for copy - if (pTask->GetDestPath().GetPath() == fi.GetFileRoot()) - { - CString strSubst; - FindFreeSubstituteName(fi.GetFullFilePath(), pTask->GetDestPath().GetPath(), &strSubst); - pTask->GetClipboardData(i)->m_astrDstPaths.Add(strSubst); - } - else - pTask->GetClipboardData(i)->m_astrDstPaths.Add(fi.GetFileName()); - } - - // add if needed - if (fi.IsDirectory()) - { - // add if folder's aren't ignored - if (!bIgnoreDirs && !bForceDirectories) - { - pTask->FilesAdd(fi); - - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFADDEDFOLDER_STRING)); - fmt.SetParam(_t("%path"), fi.GetFullFilePath()); - pTask->m_log.logi(fmt); - } - - // don't add folder contents when moving inside one disk boundary - if (bIgnoreDirs || !bMove || pTask->GetCopies() > 1 || iDestDrvNumber == -1 - || iDestDrvNumber != fi.GetDriveNumber() || CFileInfo::Exist(fi.GetDestinationPath(pTask->GetDestPath().GetPath(), 0, ((int)bForceDirectories) << 1)) ) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFRECURSINGFOLDER_STRING)); - fmt.SetParam(_t("%path"), fi.GetFullFilePath()); - pTask->m_log.logi(fmt); - - // no movefile possibility - use CustomCopyFile - pTask->GetClipboardData(i)->SetMove(false); - - pTask->FilesAddDir(fi.GetFullFilePath(), pFilters, i, true, !bIgnoreDirs || bForceDirectories); - } - - // check for kill need - if (pTask->GetKillFlag()) - { - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFADDINGKILLREQEST_STRING)); - throw new CProcessingException(E_KILL_REQUEST, pTask); - } - } - else - { - if (bMove && pTask->GetCopies() == 1 && iDestDrvNumber != -1 && iDestDrvNumber == fi.GetDriveNumber() && - !CFileInfo::Exist(fi.GetDestinationPath(pTask->GetDestPath().GetPath(), 0, ((int)bForceDirectories) << 1)) ) - { - // if moving within one partition boundary set the file size to 0 so the overall size will - // be ok - fi.SetLength64(0); - } - else - pTask->GetClipboardData(i)->SetMove(false); // no MoveFile - - pTask->FilesAdd(fi); // file - add - - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFADDEDFILE_STRING)); - fmt.SetParam(_t("%path"), fi.GetFullFilePath()); - pTask->m_log.logi(fmt); - } - } - - // calc size of all files - pTask->CalcAllSize(); - - // update *m_pnTasksAll; - pTask->IncreaseAllTasksSize(pTask->GetAllSize()); - - // change state to ST_COPYING - finished searching for files - pTask->SetStatus(ST_COPYING, ST_STEP_MASK); - - // save task status - pTask->Store(true); - pTask->Store(false); - - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFSEARCHINGFINISHED_STRING)); -} - -// delete files - after copying -void DeleteFiles(CTask* pTask) -{ - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFDELETINGFILES_STRING)); - - // current processed path - BOOL bSuccess; - CFileInfo fi; - ictranslate::CFormat fmt; - - // index points to 0 or next item to process - for (int i=pTask->GetCurrentIndex();iFilesGetSize();i++) - { - // set index in pTask to currently deleted element - pTask->SetCurrentIndex(i); - - // check for kill flag - if (pTask->GetKillFlag()) - { - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFDELETINGKILLREQUEST_STRING)); - throw new CProcessingException(E_KILL_REQUEST, pTask); - } - - // current processed element - fi=pTask->FilesGetAt(pTask->FilesGetSize()-i-1); - if(!(fi.GetFlags() & FIF_PROCESSED)) - continue; - - // delete data - if (fi.IsDirectory()) - { - if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) - SetFileAttributes(fi.GetFullFilePath(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); - bSuccess=RemoveDirectory(fi.GetFullFilePath()); - } - else - { - // set files attributes to normal - it'd slow processing a bit, but it's better. - if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) - SetFileAttributes(fi.GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); - bSuccess=DeleteFile(fi.GetFullFilePath()); - } - - // operation failed - DWORD dwLastError=GetLastError(); - if (!bSuccess && dwLastError != ERROR_PATH_NOT_FOUND && dwLastError != ERROR_FILE_NOT_FOUND) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFDELETINGERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), fi.GetFullFilePath()); - pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pTask, dwLastError, fmt); - } - }//for - - // change status to finished - pTask->SetStatus(ST_FINISHED, ST_STEP_MASK); - - // add 1 to current index - looks better - pTask->IncreaseCurrentIndex(); - - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFDELETINGFINISHED_STRING)); -} - -void CustomCopyFile(PCUSTOM_COPY_PARAMS pData) -{ - HANDLE hSrc=INVALID_HANDLE_VALUE, hDst=INVALID_HANDLE_VALUE; - ictranslate::CFormat fmt; - try - { - // do we copy rest or recopy ? - bool bCopyRest=GetConfig()->get_bool(PP_CMUSEAUTOCOMPLETEFILES); -// UINT uiNotificationType=(UINT)GetConfig()->get_signed_num(PP_CMSHOWVISUALFEEDBACK); - - // Data regarding dest file - CFileInfo fiDest; - bool bExist=fiDest.Create(pData->strDstFile, -1); - - chcore::IFeedbackHandler* piFeedbackHandler = pData->pTask->GetFeedbackHandler(); - BOOST_ASSERT(piFeedbackHandler); - -// int iDlgCode=-1; -// int *piLastDlgDesc=NULL; // ptr to int describing last used dialog - - // don't ask for copy rest -// bool bDontAsk=(pData->pTask->GetCurrentIndex() == pData->pTask->GetLastProcessedIndex()); - pData->pTask->SetLastProcessedIndex(-1); - - // if dest file size >0 - we can do somethng more than usual - if(bExist) - { - // src and dst files are the same - FEEDBACK_ALREADYEXISTS feedStruct = { pData->pfiSrcFile, &fiDest }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileAlreadyExists, &feedStruct); - // check for dialog result - switch(frResult) - { - case CFeedbackHandler::eResult_Overwrite: - { - bCopyRest=false; - break; - } - case CFeedbackHandler::eResult_CopyRest: - { - bCopyRest=true; - break; - } - case CFeedbackHandler::eResult_Skip: - { - pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); - pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); - pData->bProcessed = false; - return; - } - case CFeedbackHandler::eResult_Cancel: - { - // log - if (GetConfig()->get_bool(PP_CMCREATELOG)) - { - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFPRECHECKCANCELREQUEST_STRING)); - fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); - pData->pTask->m_log.logi(fmt); - } - throw new CProcessingException(E_CANCEL, pData->pTask); - break; - } - case CFeedbackHandler::eResult_Pause: - { - throw new CProcessingException(E_PAUSE, pData->pTask); - break; - } - default: - { - BOOST_ASSERT(FALSE); // unknown result - throw new CProcessingException(E_ERROR, pData->pTask, 0, _t("Unknown feedback result type")); - break; - } - } - }// bExist - - // change attributes of a dest file - if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) - SetFileAttributes(pData->strDstFile, FILE_ATTRIBUTE_NORMAL); - - // first or second pass ? only for FFNB - bool bFirstPass=true; - - // check size of src file to know whether use flag FILE_FLAG_NOBUFFERING -l_start: - bool bNoBuffer=(bFirstPass && GetConfig()->get_bool(PP_BFUSENOBUFFERING) && pData->pfiSrcFile->GetLength64() >= (unsigned long long)GetConfig()->get_signed_num(PP_BFBOUNDARYLIMIT)); - - // refresh data about file - if (!bFirstPass) - bExist=fiDest.Create(pData->strDstFile, -1); - - // open src -l_openingsrc: - hSrc=CreateFile(pData->pfiSrcFile->GetFullFilePath(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffer ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); - if (hSrc == INVALID_HANDLE_VALUE) - { - DWORD dwLastError=GetLastError(); - CString strFile = pData->pfiSrcFile->GetFullFilePath(); - FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strFile, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); - - switch (frResult) - { - case CFeedbackHandler::eResult_Skip: - pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); - pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); - pData->bProcessed = false; - return; - break; - case CFeedbackHandler::eResult_Cancel: - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFOPENINGCANCELREQUEST_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); - pData->pTask->m_log.loge(fmt); - throw new CProcessingException(E_CANCEL, pData->pTask); - break; - case CFeedbackHandler::eResult_Pause: - throw new CProcessingException(E_PAUSE, pData->pTask); - break; - case CFeedbackHandler::eResult_Retry: - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFOPENINGRETRY_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); - pData->pTask->m_log.loge(fmt); - goto l_openingsrc; - break; - default: - { - BOOST_ASSERT(FALSE); // unknown result - throw new CProcessingException(E_ERROR, pData->pTask, 0, _t("Unknown feedback result type")); - break; - } - } - } - - // open dest -l_openingdst: - hDst=CreateFile(pData->strDstFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffer ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); - if (hDst == INVALID_HANDLE_VALUE) - { - DWORD dwLastError=GetLastError(); - CString strFile = pData->strDstFile; - - FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strFile, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); - switch (frResult) - { - case CFeedbackHandler::eResult_Retry: - // change attributes - if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) - SetFileAttributes(pData->strDstFile, FILE_ATTRIBUTE_NORMAL); - - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFDESTOPENINGRETRY_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pData->strDstFile); - pData->pTask->m_log.loge(fmt); - goto l_openingdst; - break; - case CFeedbackHandler::eResult_Cancel: - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFDESTOPENINGCANCELREQUEST_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pData->strDstFile); - pData->pTask->m_log.loge(fmt); - throw new CProcessingException(E_CANCEL, pData->pTask); - break; - case CFeedbackHandler::eResult_Skip: - pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); - pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); - pData->bProcessed = false; - return; - break; - case CFeedbackHandler::eResult_Pause: - throw new CProcessingException(E_PAUSE, pData->pTask); - break; - default: - { - BOOST_ASSERT(FALSE); // unknown result - throw new CProcessingException(E_ERROR, pData->pTask, 0, _t("Unknown feedback result type")); - break; - } - } - } - - // seeking - DWORD dwLastError=0; - if (!pData->bOnlyCreate) - { - if ( bCopyRest ) // if copy rest - { - if (!bFirstPass || (bExist && fiDest.GetLength64() > 0)) - { - // try to move file pointers to the end - ULONGLONG ullMove=(bNoBuffer ? ROUNDDOWN(fiDest.GetLength64(), MAXSECTORSIZE) : fiDest.GetLength64()); - if (SetFilePointer64(hSrc, ullMove, FILE_BEGIN) == -1 || SetFilePointer64(hDst, ullMove, FILE_BEGIN) == -1) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFMOVINGPOINTERSERROR_STRING)); - fmt.SetParam(_t("%errno"), GetLastError()); - fmt.SetParam(_t("%srcpath"), pData->pfiSrcFile->GetFullFilePath()); - fmt.SetParam(_t("%dstpath"), pData->strDstFile); - fmt.SetParam(_t("%pos"), ullMove); - pData->pTask->m_log.loge(fmt); - - // seek failed - seek to begin - if (SetFilePointer64(hSrc, 0, FILE_BEGIN) == -1 || SetFilePointer64(hDst, 0, FILE_BEGIN) == -1) - { - // log - dwLastError=GetLastError(); - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFRESTORINGPOINTERSERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%srcpath"), pData->pfiSrcFile->GetFullFilePath()); - fmt.SetParam(_t("%dstpath"), pData->strDstFile); - pData->pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); - } - else - { - // file pointers restored - if second pass subtract what's needed - if (!bFirstPass) - { - pData->pTask->IncreaseProcessedSize(-static_cast<__int64>(ullMove)); - pData->pTask->IncreaseProcessedTasksSize(-static_cast<__int64>(ullMove)); - } - } - } - else - { - // file pointers moved - so we have skipped some work - update positions - if (bFirstPass) // przy drugim obiegu jest ju� uwzgl�dnione - { - pData->pTask->IncreaseProcessedSize(ullMove); - pData->pTask->IncreaseProcessedTasksSize(ullMove); - } - } - } - } - else - if (!SetEndOfFile(hDst)) // if recopying - reset the dest file - { - // log - dwLastError=GetLastError(); - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFSETTINGZEROSIZEERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pData->strDstFile); - pData->pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); - } - - // copying - unsigned long tord, rd, wr; - int iBufferIndex; - do - { - // kill flag checks - if (pData->pTask->GetKillFlag()) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCOPYINGKILLREQUEST_STRING)); - fmt.SetParam(_t("%srcpath"), pData->pfiSrcFile->GetFullFilePath()); - fmt.SetParam(_t("%dstpath"), pData->strDstFile); - pData->pTask->m_log.logi(fmt); - throw new CProcessingException(E_KILL_REQUEST, pData->pTask); - } - - // recreate buffer if needed - if (!(*pData->dbBuffer.GetSizes() == *pData->pTask->GetBufferSizes())) - { - // log - const BUFFERSIZES *pbs1=pData->dbBuffer.GetSizes(), *pbs2=pData->pTask->GetBufferSizes(); - - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCHANGINGBUFFERSIZE_STRING)); - - fmt.SetParam(_t("%defsize"), pbs1->m_uiDefaultSize); - fmt.SetParam(_t("%onesize"), pbs1->m_uiOneDiskSize); - fmt.SetParam(_t("%twosize"), pbs1->m_uiTwoDisksSize); - fmt.SetParam(_t("%cdsize"), pbs1->m_uiCDSize); - fmt.SetParam(_t("%lansize"), pbs1->m_uiLANSize); - fmt.SetParam(_t("%defsize2"), pbs2->m_uiDefaultSize); - fmt.SetParam(_t("%onesize2"), pbs2->m_uiOneDiskSize); - fmt.SetParam(_t("%twosize2"), pbs2->m_uiTwoDisksSize); - fmt.SetParam(_t("%cdsize2"), pbs2->m_uiCDSize); - fmt.SetParam(_t("%lansize2"), pbs2->m_uiLANSize); - fmt.SetParam(_t("%srcfile"), pData->pfiSrcFile->GetFullFilePath()); - fmt.SetParam(_t("%dstfile"), pData->strDstFile); - - pData->pTask->m_log.logi(fmt); - pData->pTask->SetBufferSizes(pData->dbBuffer.Create(pData->pTask->GetBufferSizes())); - } - - // establish count of data to read - iBufferIndex=pData->pTask->GetBufferSizes()->m_bOnlyDefault ? 0 : pData->pfiSrcFile->GetBufferIndex(); - tord=bNoBuffer ? ROUNDUP(pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex], MAXSECTORSIZE) : pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex]; - - // read - if (!ReadFile(hSrc, pData->dbBuffer, tord, &rd, NULL)) - { - // log - dwLastError=GetLastError(); - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFREADINGERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%count"), tord); - fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); - pData->pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); - } - - // change count of stored data - if (bNoBuffer && (ROUNDUP(rd, MAXSECTORSIZE)) != rd) - { - // we need to copy rest so do the second pass - // close files - CloseHandle(hSrc); - CloseHandle(hDst); - - // second pass - bFirstPass=false; - bCopyRest=true; // nedd to copy rest - - goto l_start; - } - - // zapisz - if (!WriteFile(hDst, pData->dbBuffer, rd, &wr, NULL) || wr != rd) - { - // log - dwLastError=GetLastError(); - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFWRITINGERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%count"), rd); - fmt.SetParam(_t("%path"), pData->strDstFile); - pData->pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); - } - - // increase count of processed data - pData->pTask->IncreaseProcessedSize(rd); - pData->pTask->IncreaseProcessedTasksSize(rd); -// TRACE("Read: %d, Written: %d\n", rd, wr); - } - while ( rd != 0 ); - } - else - { - // we don't copy contents, but need to increase processed size - pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); - pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); - } - - // close files - CloseHandle(hSrc); - CloseHandle(hDst); - - pData->bProcessed = true; - } - catch(...) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCAUGHTEXCEPTIONCCF_STRING)); - fmt.SetParam(_t("%errno"), GetLastError()); - fmt.SetParam(_t("%timestamp"), GetTickCount()); - pData->pTask->m_log.loge(fmt); - - // close handles - if (hSrc != INVALID_HANDLE_VALUE) - CloseHandle(hSrc); - if (hDst != INVALID_HANDLE_VALUE) - CloseHandle(hDst); - - throw; - } -} - -// function processes files/folders -void ProcessFiles(CTask* pTask) -{ - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFPROCESSINGFILES_STRING)); - - // count how much has been done (updates also a member in CTaskArray) - pTask->CalcProcessedSize(); - - // create a buffer of size pTask->m_nBufferSize - CUSTOM_COPY_PARAMS ccp; - ccp.bProcessed = false; - ccp.pTask=pTask; - ccp.bOnlyCreate=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_CONTENT) != 0; - ccp.dbBuffer.Create(pTask->GetBufferSizes()); - - // helpers - //CFileInfo fi; // for currently processed element - DWORD dwLastError; - - // begin at index which wasn't processed previously - int nSize=pTask->FilesGetSize(); // wielko�� tablicy - int iCopiesCount=pTask->GetCopies(); // ilo�� kopii - bool bIgnoreFolders=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_DIRS) != 0; - bool bForceDirectories=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_FORCE_DIRS) != 0; - const CDestPath& dpDestPath=pTask->GetDestPath(); - - // log - const BUFFERSIZES* pbs=ccp.dbBuffer.GetSizes(); - - ictranslate::CFormat fmt; - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFPROCESSINGFILESDATA_STRING)); - fmt.SetParam(_t("%create"), ccp.bOnlyCreate); - fmt.SetParam(_t("%defsize"), pbs->m_uiDefaultSize); - fmt.SetParam(_t("%onesize"), pbs->m_uiOneDiskSize); - fmt.SetParam(_t("%twosize"), pbs->m_uiTwoDisksSize); - fmt.SetParam(_t("%cdsize"), pbs->m_uiCDSize); - fmt.SetParam(_t("%lansize"), pbs->m_uiLANSize); - fmt.SetParam(_t("%filecount"), nSize); - fmt.SetParam(_t("%copycount"), iCopiesCount); - fmt.SetParam(_t("%ignorefolders"), bIgnoreFolders); - fmt.SetParam(_t("%dstpath"), dpDestPath.GetPath()); - fmt.SetParam(_t("%currpass"), pTask->GetCurrentCopy()); - fmt.SetParam(_t("%currindex"), pTask->GetCurrentIndex()); - - pTask->m_log.logi(fmt); - - for (unsigned char j=pTask->GetCurrentCopy();jSetCurrentCopy(j); - for (int i=pTask->GetCurrentIndex();iSetCurrentIndex(i); - CFileInfo& fi=pTask->FilesGetAtCurrentIndex(); - - // should we kill ? - if (pTask->GetKillFlag()) - { - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFPROCESSINGKILLREQUEST_STRING)); - throw new CProcessingException(E_KILL_REQUEST, pTask); - } - - // set dest path with filename - ccp.strDstFile=fi.GetDestinationPath(dpDestPath.GetPath(), j, ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); - - // are the files/folders lie on the same partition ? - bool bMove=pTask->GetStatus(ST_OPERATION_MASK) == ST_MOVE; - if (bMove && dpDestPath.GetDriveNumber() != -1 && dpDestPath.GetDriveNumber() == fi.GetDriveNumber() && iCopiesCount == 1 && fi.GetMove()) - { - if (!MoveFile(fi.GetFullFilePath(), ccp.strDstFile)) - { - dwLastError=GetLastError(); - //log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFMOVEFILEERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%srcpath"), fi.GetFullFilePath()); - fmt.SetParam(_t("%dstpath"), ccp.strDstFile); - pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pTask, dwLastError, fmt); - } - else - fi.SetFlags(FIF_PROCESSED, FIF_PROCESSED); - } - else - { - // if folder - create it - if ( fi.IsDirectory() ) - { - if (!CreateDirectory(ccp.strDstFile, NULL) && (dwLastError=GetLastError()) != ERROR_ALREADY_EXISTS ) - { - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCREATEDIRECTORYERROR_STRING)); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), ccp.strDstFile); - pTask->m_log.loge(fmt); - throw new CProcessingException(E_ERROR, pTask, dwLastError, fmt); - } - - pTask->IncreaseProcessedSize(fi.GetLength64()); - pTask->IncreaseProcessedTasksSize(fi.GetLength64()); - fi.SetFlags(FIF_PROCESSED, FIF_PROCESSED); - } - else - { - // start copying/moving file - ccp.pfiSrcFile=&fi; - ccp.bProcessed = false; - - // kopiuj dane - CustomCopyFile(&ccp); - fi.SetFlags(ccp.bProcessed ? FIF_PROCESSED : 0, FIF_PROCESSED); - - // if moving - delete file (only if config flag is set) - if (bMove && fi.GetFlags() & FIF_PROCESSED && !GetConfig()->get_bool(PP_CMDELETEAFTERFINISHED) && j == iCopiesCount-1) - { - if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) - SetFileAttributes(fi.GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); - DeleteFile(fi.GetFullFilePath()); // there will be another try later, so I don't check - // if succeeded - } - } - - // set a time - if (GetConfig()->get_bool(PP_CMSETDESTDATE)) - SetFileDirectoryTime(ccp.strDstFile, &fi); // no error check - ma�o istotne - - // attributes - if (GetConfig()->get_bool(PP_CMSETDESTATTRIBUTES)) - SetFileAttributes(ccp.strDstFile, fi.GetAttributes()); // j.w. - } - } - - // current copy finished - change what's needed - pTask->SetCurrentIndex(0); - } - - // delete buffer - it's not needed - ccp.dbBuffer.Delete(); - - // change status - if (pTask->GetStatus(ST_OPERATION_MASK) == ST_MOVE) - { - pTask->SetStatus(ST_DELETING, ST_STEP_MASK); - // set the index to 0 before deleting - pTask->SetCurrentIndex(0); - } - else - { - pTask->SetStatus(ST_FINISHED, ST_STEP_MASK); - - // to look better - increase current index by 1 - pTask->SetCurrentIndex(nSize); - } - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFPROCESSINGFINISHED_STRING)); -} - -void CheckForWaitState(CTask* pTask) -{ - // limiting operation count - pTask->SetStatus(ST_WAITING, ST_WAITING_MASK); - bool bContinue=false; - while (!bContinue) - { - if (pTask->CanBegin()) - { - TRACE("CAN BEGIN ALLOWED TO CONTINUE...\n"); - pTask->SetStatus(0, ST_WAITING); - bContinue=true; - - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFWAITINGFINISHED_STRING)); - -// return; // skips sleep and kill flag checking - } - - Sleep(50); // not to make it too hard for processor - - if (pTask->GetKillFlag()) - { - // log - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFWAITINGKILLREQUEST_STRING)); - throw new CProcessingException(E_KILL_REQUEST, pTask); - } - } -} - -UINT ThrdProc(LPVOID pParam) -{ - TRACE("\n\nENTERING ThrdProc (new task started)...\n"); - CTask* pTask=static_cast(pParam); - - TCHAR szPath[_MAX_PATH]; - - tstring_t strPath = pTask->GetTaskPath(); - strPath += pTask->GetUniqueName()+_T(".log"); - - pTask->m_log.init(strPath.c_str(), 262144, icpf::log_file::level_debug, false, false); - - // set thread boost - HANDLE hThread=GetCurrentThread(); - ::SetThreadPriorityBoost(hThread, GetConfig()->get_bool(PP_CMDISABLEPRIORITYBOOST)); - - CTime tm=CTime::GetCurrentTime(); - - ictranslate::CFormat fmt; - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFTHREADSTART_STRING)); - fmt.SetParam(_t("%year"), tm.GetYear()); - fmt.SetParam(_t("%month"), tm.GetMonth()); - fmt.SetParam(_t("%day"), tm.GetDay()); - fmt.SetParam(_t("%hour"), tm.GetHour()); - fmt.SetParam(_t("%minute"), tm.GetMinute()); - fmt.SetParam(_t("%second"), tm.GetSecond()); - pTask->m_log.logi(fmt); - - try - { - // to make the value stable - bool bReadTasksSize=GetConfig()->get_bool(PP_CMREADSIZEBEFOREBLOCKING); - - if (!bReadTasksSize) - CheckForWaitState(pTask); // operation limiting - - // set what's needed - pTask->m_lLastTime=(long)time(NULL); // last time (start counting) - - // search for files if needed - if ((pTask->GetStatus(ST_STEP_MASK) == ST_NULL_STATUS - || pTask->GetStatus(ST_STEP_MASK) == ST_SEARCHING)) - { - // get rid of info about processed sizes - pTask->DecreaseProcessedTasksSize(pTask->GetProcessedSize()); - pTask->SetProcessedSize(0); - pTask->DecreaseAllTasksSize(pTask->GetAllSize()); - pTask->SetAllSize(0); - - // start searching - RecurseDirectories(pTask); - } - - // check for free space - ull_t ullNeededSize = 0, ullAvailableSize = 0; -l_showfeedback: - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFCHECKINGSPACE_STRING)); - - if (!pTask->GetRequiredFreeSpace(&ullNeededSize, &ullAvailableSize)) - { - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFNOTENOUGHFREESPACE_STRING)); - fmt.SetParam(_t("%needsize"), ullNeededSize); - fmt.SetParam(_t("%availablesize"), ullAvailableSize); - pTask->m_log.logw(fmt); - - chcore::IFeedbackHandler* piFeedbackHandler = pTask->GetFeedbackHandler(); - BOOST_ASSERT(piFeedbackHandler); - - if(pTask->GetClipboardDataSize() > 0) - { - CString strSrcPath = pTask->GetClipboardData(0)->GetPath(); - CString strDstPath = pTask->GetDestPath().GetPath(); - FEEDBACK_NOTENOUGHSPACE feedStruct = { ullNeededSize, (PCTSTR)strSrcPath, (PCTSTR)strDstPath }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_NotEnoughSpace, &feedStruct); - - // default - switch (frResult) - { - case CFeedbackHandler::eResult_Cancel: - { - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFFREESPACECANCELREQUEST_STRING)); - throw new CProcessingException(E_CANCEL, pTask); - break; - } - case CFeedbackHandler::eResult_Retry: - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFFREESPACERETRYING_STRING)); - goto l_showfeedback; - break; - case CFeedbackHandler::eResult_Skip: - pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFFREESPACEIGNORE_STRING)); - break; - default: - BOOST_ASSERT(FALSE); // unknown result - throw new CProcessingException(E_ERROR, pTask, 0, _t("Unknown feedback result type")); - break; - } - } - } - - if (bReadTasksSize) - { - pTask->UpdateTime(); - pTask->m_lLastTime=-1; - - CheckForWaitState(pTask); - - pTask->m_lLastTime=(long)time(NULL); - } - - // Phase II - copying/moving - if (pTask->GetStatus(ST_STEP_MASK) == ST_COPYING) - { - // decrease processed in ctaskarray - the rest will be done in ProcessFiles - pTask->DecreaseProcessedTasksSize(pTask->GetProcessedSize()); - ProcessFiles(pTask); - } - - // deleting data - III phase - if (pTask->GetStatus(ST_STEP_MASK) == ST_DELETING) - DeleteFiles(pTask); - - // refresh time - pTask->UpdateTime(); - - // save progress before killed - pTask->Store(false); - - // we are ending - pTask->DecreaseOperationsPending(); - - // play sound - if (GetConfig()->get_bool(PP_SNDPLAYSOUNDS)) - { - GetConfig()->get_string(PP_SNDFINISHEDSOUNDPATH, szPath, _MAX_PATH); - GetApp()->ExpandPath(szPath); - PlaySound(szPath, NULL, SND_FILENAME | SND_ASYNC); - } - - tm=CTime::GetCurrentTime(); - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFTHREADFINISHED_STRING)); - fmt.SetParam(_t("%year"), tm.GetYear()); - fmt.SetParam(_t("%month"), tm.GetMonth()); - fmt.SetParam(_t("%day"), tm.GetDay()); - fmt.SetParam(_t("%hour"), tm.GetHour()); - fmt.SetParam(_t("%minute"), tm.GetMinute()); - fmt.SetParam(_t("%second"), tm.GetSecond()); - pTask->m_log.logi(fmt); - - // we have been killed - the last operation - InterlockedIncrement(pTask->m_plFinished); - pTask->CleanupAfterKill(); - pTask->SetKilledFlag(); - } - catch(CProcessingException* e) - { - // increment count of beginnings - InterlockedIncrement(pTask->m_plFinished); - - // refresh time - pTask->UpdateTime(); - - // log - fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCAUGHTEXCEPTIONMAIN_STRING)); - fmt.SetParam(_t("%errno"), e->m_dwError); - fmt.SetParam(_t("%type"), e->m_iType); - pTask->m_log.loge(fmt); - - if (e->m_iType == E_ERROR && GetConfig()->get_bool(PP_SNDPLAYSOUNDS)) - { - GetConfig()->get_string(PP_SNDERRORSOUNDPATH, szPath, _MAX_PATH); - GetApp()->ExpandPath(szPath); - PlaySound(szPath, NULL, SND_FILENAME | SND_ASYNC); - } - - // pause task if requested - if(e->m_iType == E_PAUSE) - pTask->SetStatus(ST_PAUSED, ST_PAUSED); - - // cleanup changes flags and calls cleanup for a task - e->Cleanup(); - delete e; - - if (pTask->GetStatus(ST_WAITING_MASK) & ST_WAITING) - pTask->SetStatus(0, ST_WAITING); - - pTask->DecreaseOperationsPending(); - pTask->SetContinueFlag(false); - pTask->SetForceFlag(false); - - return 0xffffffff; // almost like -1 - } - - TRACE("TASK FINISHED - exiting ThrdProc.\n"); - return 0; -} - -UINT ClipboardMonitorProc(LPVOID pParam) -{ - volatile CLIPBOARDMONITORDATA* pData=static_cast(pParam); - ASSERT(pData->m_hwnd); - - // bufor - TCHAR path[_MAX_PATH]; -// UINT i; // counter - CTask *pTask; // ptr to a task - CClipboardEntry* pEntry=NULL; - - // register clipboard format - UINT nFormat=RegisterClipboardFormat(_T("Preferred DropEffect")); - UINT uiCounter=0, uiShutCounter=0;; - LONG lFinished=0; - bool bEnd=false; - - icpf::config* pConfig = GetConfig(); - BOOST_ASSERT(pConfig); - if(!pConfig) - return 1; - while (!pData->bKill) - { - if (uiCounter == 0 && pConfig->get_bool(PP_PCLIPBOARDMONITORING) && IsClipboardFormatAvailable(CF_HDROP)) - { - // get data from clipboard - OpenClipboard(pData->m_hwnd); - HANDLE handle=GetClipboardData(CF_HDROP); - - UINT nCount=DragQueryFile(static_cast(handle), 0xffffffff, NULL, 0); - - pTask = pData->m_pTasks->CreateTask(); - - for (UINT i=0;i(handle), i, path, _MAX_PATH); - pEntry=new CClipboardEntry; - pEntry->SetPath(path); - pTask->AddClipboardData(pEntry); - } - - if (IsClipboardFormatAvailable(nFormat)) - { - handle=GetClipboardData(nFormat); - LPVOID addr=GlobalLock(handle); - - DWORD dwData=((DWORD*)addr)[0]; - if (dwData & DROPEFFECT_COPY) - pTask->SetStatus(ST_COPY, ST_OPERATION_MASK); // copy - else if (dwData & DROPEFFECT_MOVE) - pTask->SetStatus(ST_MOVE, ST_OPERATION_MASK); // move - - GlobalUnlock(handle); - } - else - pTask->SetStatus(ST_COPY, ST_OPERATION_MASK); // default - copy - - EmptyClipboard(); - CloseClipboard(); - - BUFFERSIZES bs; - bs.m_bOnlyDefault=pConfig->get_bool(PP_BFUSEONLYDEFAULT); - bs.m_uiDefaultSize=(UINT)pConfig->get_signed_num(PP_BFDEFAULT); - bs.m_uiOneDiskSize=(UINT)pConfig->get_signed_num(PP_BFONEDISK); - bs.m_uiTwoDisksSize=(UINT)pConfig->get_signed_num(PP_BFTWODISKS); - bs.m_uiCDSize=(UINT)pConfig->get_signed_num(PP_BFCD); - bs.m_uiLANSize=(UINT)pConfig->get_signed_num(PP_BFLAN); - - pTask->SetBufferSizes(&bs); - pTask->SetPriority((int)pConfig->get_signed_num(PP_CMDEFAULTPRIORITY)); - - // get dest folder - CFolderDialog dlg; - - const tchar_t* pszPath = NULL; - dlg.m_bdData.cvShortcuts.clear(true); - size_t stCount = pConfig->get_value_count(PP_SHORTCUTS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - pszPath = pConfig->get_string(PP_SHORTCUTS, stIndex); - dlg.m_bdData.cvShortcuts.push_back(pszPath); - } - - dlg.m_bdData.cvRecent.clear(true); - stCount = pConfig->get_value_count(PP_RECENTPATHS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); - dlg.m_bdData.cvRecent.push_back(pszPath); - } - - dlg.m_bdData.bExtended=pConfig->get_bool(PP_FDEXTENDEDVIEW); - dlg.m_bdData.cx=(int)pConfig->get_signed_num(PP_FDWIDTH); - dlg.m_bdData.cy=(int)pConfig->get_signed_num(PP_FDHEIGHT); - dlg.m_bdData.iView=(int)pConfig->get_signed_num(PP_FDSHORTCUTLISTSTYLE); - dlg.m_bdData.bIgnoreDialogs=pConfig->get_bool(PP_FDIGNORESHELLDIALOGS); - - dlg.m_bdData.strInitialDir=(dlg.m_bdData.cvRecent.size() > 0) ? dlg.m_bdData.cvRecent.at(0) : _T(""); - - int iStatus=pTask->GetStatus(ST_OPERATION_MASK); - if (iStatus == ST_COPY) - dlg.m_bdData.strCaption=GetResManager()->LoadString(IDS_TITLECOPY_STRING); - else if (iStatus == ST_MOVE) - dlg.m_bdData.strCaption=GetResManager()->LoadString(IDS_TITLEMOVE_STRING); - else - dlg.m_bdData.strCaption=GetResManager()->LoadString(IDS_TITLEUNKNOWNOPERATION_STRING); - dlg.m_bdData.strText=GetResManager()->LoadString(IDS_MAINBROWSETEXT_STRING); - - // set count of data to display - int iClipboardSize=pTask->GetClipboardDataSize(); - int iEntries=(iClipboardSize > 3) ? 2 : iClipboardSize; - for (int i=0;iGetClipboardData(i)->GetPath()+_T("\n"); - - // add ... - if (iEntries < iClipboardSize) - dlg.m_bdData.strText+=_T("..."); - - // show window - int iResult=dlg.DoModal(); - - // set data to config - pConfig->clear_array_values(PP_SHORTCUTS); - for(char_vector::iterator it = dlg.m_bdData.cvShortcuts.begin(); it != dlg.m_bdData.cvShortcuts.end(); it++) - { - pConfig->set_string(PP_SHORTCUTS, (*it), icpf::property::action_add); - } - - pConfig->clear_array_values(PP_RECENTPATHS); - for(char_vector::iterator it = dlg.m_bdData.cvRecent.begin(); it != dlg.m_bdData.cvRecent.end(); it++) - { - pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); - } - - pConfig->set_bool(PP_FDEXTENDEDVIEW, dlg.m_bdData.bExtended); - pConfig->set_signed_num(PP_FDWIDTH, dlg.m_bdData.cx); - pConfig->set_signed_num(PP_FDHEIGHT, dlg.m_bdData.cy); - pConfig->set_signed_num(PP_FDSHORTCUTLISTSTYLE, dlg.m_bdData.iView); - pConfig->set_bool(PP_FDIGNORESHELLDIALOGS, dlg.m_bdData.bIgnoreDialogs); - pConfig->write(NULL); - - if ( iResult != IDOK ) - delete pTask; - else - { - // get dest path - CString strData; - dlg.GetPath(strData); - pTask->SetDestPath(strData); - - // get the relationship between src and dst paths - for (int i=0;iGetClipboard()->GetSize();i++) - pTask->GetClipboard()->GetAt(i)->CalcBufferIndex(pTask->GetDestPath()); - - // add task to a list of tasks and start - pData->m_pTasks->Add(pTask); - - // write pTask to a file - pTask->Store(true); - pTask->Store(false); - - // start processing - pTask->BeginProcessing(); - } - } - - // do we need to check for turning computer off - if (GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED)) - { - if (uiShutCounter == 0) - { - if (lFinished != pData->m_pTasks->m_lFinished) - { - bEnd=true; - lFinished=pData->m_pTasks->m_lFinished; - } - - if (bEnd && pData->m_pTasks->IsFinished()) - { - TRACE("Shut down windows\n"); - bool bShutdown=true; - if (GetConfig()->get_signed_num(PP_PTIMEBEFORESHUTDOWN) != 0) - { - CShutdownDlg dlg; - dlg.m_iOverallTime=(int)GetConfig()->get_signed_num(PP_PTIMEBEFORESHUTDOWN); - if (dlg.m_iOverallTime < 0) - dlg.m_iOverallTime=-dlg.m_iOverallTime; - bShutdown=(dlg.DoModal() != IDCANCEL); - } - - GetConfig()->set_bool(PP_PSHUTDOWNAFTREFINISHED, false); - GetConfig()->write(NULL); - if (bShutdown) - { - // we're killed - pData->bKilled=true; - - // adjust token privileges for NT - HANDLE hToken=NULL; - TOKEN_PRIVILEGES tp; - if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) - && LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid)) - { - tp.PrivilegeCount=1; - tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; - - AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, NULL, NULL); - } - - BOOL bExit=ExitWindowsEx(EWX_POWEROFF | EWX_SHUTDOWN | (GetConfig()->get_bool(PP_PFORCESHUTDOWN) ? EWX_FORCE : 0), 0); - if (bExit) - return 1; - else - { - pData->bKilled=false; - - // some kind of error - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_SHUTDOWNERROR_STRING)); - fmt.SetParam(_t("%errno"), GetLastError()); - AfxMessageBox(fmt, MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); - } - } - } - } - } - else - { - bEnd=false; - lFinished=pData->m_pTasks->m_lFinished; - } - - // sleep for some time - const int iSleepCount=200; - Sleep(iSleepCount); - uiCounter+=iSleepCount; - uiShutCounter+=iSleepCount; - if (uiCounter >= (UINT)GetConfig()->get_signed_num(PP_PMONITORSCANINTERVAL)) - uiCounter=0; - if (uiShutCounter >= 800) - uiShutCounter=0; - } - - pData->bKilled=true; - TRACE("Monitoring clipboard proc aborted...\n"); - - return 0; -} - -///////////////////////////////////////////////////////////////////////////// -// CMainWnd message handlers - -int CMainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) -{ - lpCreateStruct->dwExStyle |= WS_EX_TOPMOST; - if (CWnd::OnCreate(lpCreateStruct) == -1) - return -1; - - // get msg id of taskbar created message - m_uiTaskbarRestart=RegisterWindowMessage(_T("TaskbarCreated")); - - // Create the tray icon - ShowTrayIcon(); - - // initialize CTaskArray - m_tasks.Create(m_pFeedbackFactory, &ThrdProc); - - // load last state - CString strPath; - GetApp()->GetProgramDataPath(strPath); - strPath += _T("\\tasks"); - m_tasks.SetTasksDir(strPath); - m_tasks.LoadDataProgress(); - m_tasks.TasksRetryProcessing(); - - // start clipboard monitoring - cmd.bKill=false; - cmd.bKilled=false; - cmd.m_hwnd=this->m_hWnd; - cmd.m_pTasks=&m_tasks; - - AfxBeginThread(&ClipboardMonitorProc, static_cast(&cmd), THREAD_PRIORITY_IDLE); - - // start saving timer - SetTimer(1023, (UINT)GetConfig()->get_signed_num(PP_PAUTOSAVEINTERVAL), NULL); - - SetTimer(7834, TM_AUTORESUME/*GetConfig()->GetAutoRetryInterval()*/, NULL); - SetTimer(3245, TM_AUTOREMOVE, NULL); - SetTimer(8743, TM_ACCEPTING, NULL); // ends wait state in tasks - - if (GetConfig()->get_bool(PP_MVAUTOSHOWWHENRUN)) - PostMessage(WM_SHOWMINIVIEW); - - return 0; -} - -LRESULT CMainWnd::OnTrayNotification(WPARAM wParam, LPARAM lParam) -{ - if (wParam != m_ctlTray.m_tnd.uID) - return (LRESULT)FALSE; - - TCHAR text[_MAX_PATH]; - switch(LOWORD(lParam)) - { - case WM_LBUTTONDOWN: - { - ::SetForegroundWindow(this->m_hWnd); - break; - } - case WM_LBUTTONDBLCLK: - { - CMenu mMenu, *pSubMenu; - HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_POPUP_MENU)); - if (!mMenu.Attach(hMenu)) - return (LRESULT)FALSE; - - if ((pSubMenu = mMenu.GetSubMenu(0)) == NULL) - return (LRESULT)FALSE; - - // double click received, the default action is to execute first menu item - ::SetForegroundWindow(this->m_hWnd); - ::SendMessage(this->m_hWnd, WM_COMMAND, pSubMenu->GetMenuItemID(0), 0); - - pSubMenu->DestroyMenu(); - mMenu.DestroyMenu(); - break; - } - case WM_RBUTTONUP: - { - // load main menu - HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_POPUP_MENU)); - CMenu mMenu, *pSubMenu; - if (!mMenu.Attach(hMenu)) - return (LRESULT)FALSE; - - if ((pSubMenu = mMenu.GetSubMenu(0)) == NULL) - return (LRESULT)FALSE; - - // set menu default item - pSubMenu->SetDefaultItem(0, TRUE); - - // make window foreground - SetForegroundWindow(); - - // get current cursor pos - POINT pt; - GetCursorPos(&pt); - - pSubMenu->CheckMenuItem(ID_POPUP_MONITORING, MF_BYCOMMAND | (GetConfig()->get_bool(PP_PCLIPBOARDMONITORING) ? MF_CHECKED : MF_UNCHECKED)); - pSubMenu->CheckMenuItem(ID_POPUP_SHUTAFTERFINISHED, MF_BYCOMMAND | (GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED) ? MF_CHECKED : MF_UNCHECKED)); - - // track the menu - pSubMenu->TrackPopupMenu(TPM_LEFTBUTTON, pt.x, pt.y, this); - - // destroy - pSubMenu->DestroyMenu(); - mMenu.DestroyMenu(); - - break; - } - case WM_MOUSEMOVE: - { - if (m_tasks.GetSize() != 0) - { - _sntprintf(text, _MAX_PATH, _T("%s - %d %%"), GetApp()->GetAppName(), m_tasks.GetPercent()); - m_ctlTray.SetTooltipText(text); - } - else - m_ctlTray.SetTooltipText(GetApp()->GetAppNameVer()); - break; - } - } - - return (LRESULT)TRUE; -} - -///////////////////////////////////////////////////////////////////////////// -// CMainWnd/CTrayIcon menu message handlers - -void CMainWnd::ShowStatusWindow(const CTask *pSelect) -{ - m_pdlgStatus=new CStatusDlg(&m_tasks, this); // self deleting - m_pdlgStatus->m_pInitialSelection=pSelect; - m_pdlgStatus->m_bLockInstance=true; - m_pdlgStatus->m_bAutoDelete=true; - m_pdlgStatus->Create(); - - // hide miniview if showing status - if (m_pdlgMiniView != NULL && m_pdlgMiniView->m_bLock) - { - if (::IsWindow(m_pdlgMiniView->m_hWnd)) - m_pdlgMiniView->HideWindow(); - } -} - -void CMainWnd::OnPopupShowStatus() -{ - ShowStatusWindow(); -} - -void CMainWnd::OnClose() -{ - PrepareToExit(); - CWnd::OnClose(); -} - -void CMainWnd::OnTimer(UINT_PTR nIDEvent) -{ - switch (nIDEvent) - { - case 1023: - // autosave timer - KillTimer(1023); - m_tasks.SaveProgress(); - SetTimer(1023, (UINT)GetConfig()->get_signed_num(PP_PAUTOSAVEINTERVAL), NULL); - break; - case 7834: - { - // auto-resume timer - KillTimer(7834); - DWORD dwTime=GetTickCount(); - DWORD dwInterval=(m_dwLastTime == 0) ? TM_AUTORESUME : dwTime-m_dwLastTime; - m_dwLastTime=dwTime; - - if (GetConfig()->get_bool(PP_CMAUTORETRYONERROR)) - { - if (m_tasks.TasksRetryProcessing(true, dwInterval) && m_pdlgStatus && m_pdlgStatus->m_bLock && IsWindow(m_pdlgStatus->m_hWnd)) - m_pdlgStatus->SendMessage(WM_UPDATESTATUS); - } - SetTimer(7834, TM_AUTORESUME/*GetConfig()->GetAutoRetryInterval()*/, NULL); - } - break; - case 3245: - // auto-delete finished tasks timer - KillTimer(3245); - if (GetConfig()->get_bool(PP_STATUSAUTOREMOVEFINISHED)) - { - int iSize=m_tasks.GetSize(); - m_tasks.RemoveAllFinished(); - if (m_tasks.GetSize() != iSize && m_pdlgStatus && m_pdlgStatus->m_bLock && IsWindow(m_pdlgStatus->m_hWnd)) - m_pdlgStatus->SendMessage(WM_UPDATESTATUS); - } - - SetTimer(3245, TM_AUTOREMOVE, NULL); - break; - case 8743: - { - // wait state handling section - CTask* pTask; - if (GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS) == 0 || m_tasks.GetOperationsPending() < (UINT)GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS)) - { - for (int i=0;iGetStatus(ST_WAITING_MASK) & ST_WAITING && (GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS) == 0 || m_tasks.GetOperationsPending() < (UINT)GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS))) - { - TRACE("Enabling task %ld\n", i); - pTask->SetContinueFlag(true); - pTask->IncreaseOperationsPending(); - pTask->SetStatus(0, ST_WAITING); // turn off wait state - } - } - } - break; - } - } - - CWnd::OnTimer(nIDEvent); -} - -void CMainWnd::OnPopupShowOptions() -{ - COptionsDlg *pDlg=new COptionsDlg(this); - pDlg->m_bAutoDelete=true; - pDlg->m_bLockInstance=true; - pDlg->Create(); -} - -BOOL CMainWnd::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) -{ - if(!GetApp()->IsShellExtEnabled()) - return FALSE; - - // copying or moving ? - bool bMove=false; - switch(pCopyDataStruct->dwData & OPERATION_MASK) - { - case DD_MOVE_FLAG: - case EC_MOVETO_FLAG: - bMove=true; - break; - case EC_PASTE_FLAG: - case EC_PASTESPECIAL_FLAG: - bMove=(pCopyDataStruct->dwData & ~OPERATION_MASK) != 0; - break; - } - - // buffer with: dst path and src paths separated by single '\0' - TCHAR *pBuffer=static_cast(pCopyDataStruct->lpData); - unsigned long ulLen=pCopyDataStruct->cbData / sizeof(TCHAR); - - CString str, strDstPath; - CStringArray astrFiles; - UINT iOffset=0; - - do - { - str=pBuffer+iOffset; - if (iOffset == 0) - strDstPath=str; - else - astrFiles.Add(str); - - iOffset+=str.GetLength()+1; - } - while (iOffset < ulLen); - - icpf::config* pConfig = GetConfig(); - assert(pConfig); - - // special operation - modify stuff - CFiltersArray ffFilters; - int iPriority=(int)GetConfig()->get_signed_num(PP_CMDEFAULTPRIORITY); - BUFFERSIZES bsSizes; - bsSizes.m_bOnlyDefault=GetConfig()->get_bool(PP_BFUSEONLYDEFAULT); - bsSizes.m_uiDefaultSize=(UINT)GetConfig()->get_signed_num(PP_BFDEFAULT); - bsSizes.m_uiOneDiskSize=(UINT)GetConfig()->get_signed_num(PP_BFONEDISK); - bsSizes.m_uiTwoDisksSize=(UINT)GetConfig()->get_signed_num(PP_BFTWODISKS); - bsSizes.m_uiCDSize=(UINT)GetConfig()->get_signed_num(PP_BFCD); - bsSizes.m_uiLANSize=(UINT)GetConfig()->get_signed_num(PP_BFLAN); - - BOOL bOnlyCreate=FALSE; - BOOL bIgnoreDirs=FALSE; - BOOL bForceDirectories=FALSE; - unsigned char ucCopies=1; - switch(pCopyDataStruct->dwData & OPERATION_MASK) - { - case DD_COPYMOVESPECIAL_FLAG: - case EC_PASTESPECIAL_FLAG: - case EC_COPYMOVETOSPECIAL_FLAG: - CCustomCopyDlg dlg; - dlg.m_ccData.m_astrPaths.Copy(astrFiles); - dlg.m_ccData.m_iOperation=bMove ? 1 : 0; - dlg.m_ccData.m_iPriority=iPriority; - dlg.m_ccData.m_strDestPath=strDstPath; - dlg.m_ccData.m_bsSizes=bsSizes; - dlg.m_ccData.m_bIgnoreFolders=(bIgnoreDirs != 0); - dlg.m_ccData.m_bForceDirectories=(bForceDirectories != 0); - dlg.m_ccData.m_bCreateStructure=(bOnlyCreate != 0); - dlg.m_ccData.m_ucCount=ucCopies; - - dlg.m_ccData.m_vRecent.clear(true); - const tchar_t* pszPath = NULL; - size_t stCount = pConfig->get_value_count(PP_RECENTPATHS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); - if(pszPath) - dlg.m_ccData.m_vRecent.push_back(pszPath); - } - - int iModalResult; - if ( (iModalResult=dlg.DoModal()) == IDCANCEL) - return CWnd::OnCopyData(pWnd, pCopyDataStruct); - else if (iModalResult == -1) // windows has been closed by a parent - return TRUE; - - astrFiles.Copy(dlg.m_ccData.m_astrPaths); - bMove=(dlg.m_ccData.m_iOperation != 0); - iPriority=dlg.m_ccData.m_iPriority; - strDstPath=dlg.m_ccData.m_strDestPath; - bsSizes=dlg.m_ccData.m_bsSizes; - ffFilters = dlg.m_ccData.m_afFilters; - bIgnoreDirs=dlg.m_ccData.m_bIgnoreFolders; - bForceDirectories=dlg.m_ccData.m_bForceDirectories; - bOnlyCreate=dlg.m_ccData.m_bCreateStructure; - ucCopies=dlg.m_ccData.m_ucCount; - dlg.m_ccData.m_vRecent.insert(dlg.m_ccData.m_vRecent.begin(), (const PTSTR)(LPCTSTR)strDstPath, true); - - pConfig->clear_array_values(PP_RECENTPATHS); - for(char_vector::iterator it = dlg.m_ccData.m_vRecent.begin(); it != dlg.m_ccData.m_vRecent.end(); it++) - { - pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); - } - } - - // create new task - CTask *pTask = m_tasks.CreateTask(); - pTask->SetDestPath(strDstPath); - CClipboardEntry* pEntry; - - // files - for (int i=0;iSetPath(astrFiles.GetAt(i)); - pEntry->CalcBufferIndex(pTask->GetDestPath()); - pTask->AddClipboardData(pEntry); - } - - pTask->SetStatus(bMove ? ST_MOVE : ST_COPY, ST_OPERATION_MASK); - - // special status - pTask->SetStatus((bOnlyCreate ? ST_IGNORE_CONTENT : 0) | (bIgnoreDirs ? ST_IGNORE_DIRS : 0) | (bForceDirectories ? ST_FORCE_DIRS : 0), ST_SPECIAL_MASK); - - // set some stuff related with task - pTask->SetBufferSizes(&bsSizes); - pTask->SetPriority(iPriority); - pTask->SetFilters(&ffFilters); - pTask->SetCopies(ucCopies); - - m_tasks.Add(pTask); - - // save state of a task - pTask->Store(true); - pTask->Store(false); - - // add to task list and start processing - pTask->BeginProcessing(); - - return CWnd::OnCopyData(pWnd, pCopyDataStruct); -} - -void CMainWnd::OnShowMiniView() -{ - m_pdlgMiniView=new CMiniViewDlg(&m_tasks, &CStatusDlg::m_bLock, this); // self-deleting - m_pdlgMiniView->m_bAutoDelete=true; - m_pdlgMiniView->m_bLockInstance=true; - m_pdlgMiniView->Create(); -} - -void CMainWnd::OnPopupCustomCopy() -{ - icpf::config* pConfig = GetConfig(); - assert(pConfig); - if(!pConfig) - return; - - CCustomCopyDlg dlg; - dlg.m_ccData.m_iOperation=0; - dlg.m_ccData.m_iPriority=(int)pConfig->get_signed_num(PP_CMDEFAULTPRIORITY); - dlg.m_ccData.m_bsSizes.m_bOnlyDefault=pConfig->get_bool(PP_BFUSEONLYDEFAULT); - dlg.m_ccData.m_bsSizes.m_uiDefaultSize=(UINT)pConfig->get_signed_num(PP_BFDEFAULT); - dlg.m_ccData.m_bsSizes.m_uiOneDiskSize=(UINT)pConfig->get_signed_num(PP_BFONEDISK); - dlg.m_ccData.m_bsSizes.m_uiTwoDisksSize=(UINT)pConfig->get_signed_num(PP_BFTWODISKS); - dlg.m_ccData.m_bsSizes.m_uiCDSize=(UINT)pConfig->get_signed_num(PP_BFCD); - dlg.m_ccData.m_bsSizes.m_uiLANSize=(UINT)pConfig->get_signed_num(PP_BFLAN); - - dlg.m_ccData.m_bCreateStructure=false; - dlg.m_ccData.m_bForceDirectories=false; - dlg.m_ccData.m_bIgnoreFolders=false; - dlg.m_ccData.m_ucCount=1; - - dlg.m_ccData.m_vRecent.clear(true); - const tchar_t* pszPath = NULL; - size_t stCount = pConfig->get_value_count(PP_RECENTPATHS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); - if(pszPath) - dlg.m_ccData.m_vRecent.push_back(pszPath); - } - - if (dlg.DoModal() == IDOK) - { - // save recent paths - dlg.m_ccData.m_vRecent.push_back((PCTSTR)dlg.m_ccData.m_strDestPath); - - pConfig->clear_array_values(PP_RECENTPATHS); - for(char_vector::iterator it = dlg.m_ccData.m_vRecent.begin(); it != dlg.m_ccData.m_vRecent.end(); it++) - { - pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); - } - - // new task - CTask *pTask = m_tasks.CreateTask(); - pTask->SetDestPath(dlg.m_ccData.m_strDestPath); - CClipboardEntry *pEntry; - for (int i=0;iSetPath(dlg.m_ccData.m_astrPaths.GetAt(i)); - pEntry->CalcBufferIndex(pTask->GetDestPath()); - pTask->AddClipboardData(pEntry); - } - - pTask->SetStatus((dlg.m_ccData.m_iOperation == 1) ? ST_MOVE : ST_COPY, ST_OPERATION_MASK); - - // special status - pTask->SetStatus((dlg.m_ccData.m_bCreateStructure ? ST_IGNORE_CONTENT : 0) | (dlg.m_ccData.m_bIgnoreFolders ? ST_IGNORE_DIRS : 0) - | (dlg.m_ccData.m_bForceDirectories ? ST_FORCE_DIRS : 0), ST_SPECIAL_MASK); - - pTask->SetBufferSizes(&dlg.m_ccData.m_bsSizes); - pTask->SetPriority(dlg.m_ccData.m_iPriority); - pTask->SetFilters(&dlg.m_ccData.m_afFilters); - - m_tasks.Add(pTask); - - // save - pTask->Store(true); - pTask->Store(false); - - // store and start - pTask->BeginProcessing(); - } -} - -LRESULT CMainWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) - { - case WM_MINIVIEWDBLCLK: - { - ShowStatusWindow((CTask*)lParam); - break; - } - case WM_SHOWMINIVIEW: - { - OnShowMiniView(); - return static_cast(0); - break; - } - - case WM_CONFIGNOTIFY: - { - GetApp()->SetAutorun(GetConfig()->get_bool(PP_PRELOADAFTERRESTART)); - - // set this process class - HANDLE hProcess=GetCurrentProcess(); - ::SetPriorityClass(hProcess, (DWORD)GetConfig()->get_signed_num(PP_PPROCESSPRIORITYCLASS)); - - break; - } - - case WM_GETCONFIG: - { - icpf::config* pConfig = GetConfig(); - assert(pConfig); - - // std config values - g_pscsShared->bShowFreeSpace=pConfig->get_bool(PP_SHSHOWFREESPACE); - - // experimental - doesn't work on all systems - g_pscsShared->bShowShortcutIcons=pConfig->get_bool(PP_SHSHOWSHELLICONS); - g_pscsShared->bOverrideDefault=pConfig->get_bool(PP_SHUSEDRAGDROP); // only for d&d - g_pscsShared->uiDefaultAction=(UINT)pConfig->get_signed_num(PP_SHDEFAULTACTION); - - // sizes - for (int i=0;i<6;i++) - _tcscpy(g_pscsShared->szSizes[i], GetResManager()->LoadString(IDS_BYTE_STRING+i)); - - // convert to list of _COMMAND's - _COMMAND *pCommand = g_pscsShared->GetCommandsPtr(); - - // what kind of menu ? - switch (wParam) - { - case GC_DRAGDROP: - { - g_pscsShared->iCommandCount=3; - g_pscsShared->iShortcutsCount=0; - g_pscsShared->uiFlags=(pConfig->get_bool(PP_SHSHOWCOPY) ? DD_COPY_FLAG : 0) - | (pConfig->get_bool(PP_SHSHOWMOVE) ? DD_MOVE_FLAG : 0) - | (pConfig->get_bool(PP_SHSHOWCOPYMOVE) ? DD_COPYMOVESPECIAL_FLAG : 0); - - pCommand[0].uiCommandID=DD_COPY_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUCOPY_STRING, pCommand[0].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPCOPY_STRING, pCommand[0].szDesc, 128); - - pCommand[1].uiCommandID=DD_MOVE_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUMOVE_STRING, pCommand[1].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPMOVE_STRING, pCommand[1].szDesc, 128); - - pCommand[2].uiCommandID=DD_COPYMOVESPECIAL_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUCOPYMOVESPECIAL_STRING, pCommand[2].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPCOPYMOVESPECIAL_STRING, pCommand[2].szDesc, 128); - } - break; - case GC_EXPLORER: - { - g_pscsShared->iCommandCount=5; - g_pscsShared->uiFlags=(pConfig->get_bool(PP_SHSHOWPASTE) ? EC_PASTE_FLAG : 0) - | (pConfig->get_bool(PP_SHSHOWPASTESPECIAL) ? EC_PASTESPECIAL_FLAG : 0) - | (pConfig->get_bool(PP_SHSHOWCOPYTO) ? EC_COPYTO_FLAG : 0) - | (pConfig->get_bool(PP_SHSHOWMOVETO) ? EC_MOVETO_FLAG : 0) - | (pConfig->get_bool(PP_SHSHOWCOPYMOVETO) ? EC_COPYMOVETOSPECIAL_FLAG : 0); - - pCommand[0].uiCommandID=EC_PASTE_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUPASTE_STRING, pCommand[0].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPPASTE_STRING, pCommand[0].szDesc, 128); - pCommand[1].uiCommandID=EC_PASTESPECIAL_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUPASTESPECIAL_STRING, pCommand[1].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPPASTESPECIAL_STRING, pCommand[1].szDesc, 128); - pCommand[2].uiCommandID=EC_COPYTO_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUCOPYTO_STRING, pCommand[2].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPCOPYTO_STRING, pCommand[2].szDesc, 128); - pCommand[3].uiCommandID=EC_MOVETO_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUMOVETO_STRING, pCommand[3].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPMOVETO_STRING, pCommand[3].szDesc, 128); - pCommand[4].uiCommandID=EC_COPYMOVETOSPECIAL_FLAG; - GetResManager()->LoadStringCopy(IDS_MENUCOPYMOVETOSPECIAL_STRING, pCommand[4].szCommand, 128); - GetResManager()->LoadStringCopy(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING, pCommand[4].szDesc, 128); - - // prepare shortcuts - char_vector cvShortcuts; - const tchar_t* pszPath = NULL; - size_t stCount = pConfig->get_value_count(PP_SHORTCUTS); - for(size_t stIndex = 0; stIndex < stCount; stIndex++) - { - pszPath = pConfig->get_string(PP_SHORTCUTS, stIndex); - if(pszPath) - cvShortcuts.push_back(pszPath); - } - - // count of shortcuts to store - g_pscsShared->iShortcutsCount=__min(cvShortcuts.size(), (SHARED_BUFFERSIZE - 5 * sizeof(_COMMAND)) / sizeof(_SHORTCUT)); - _SHORTCUT* pShortcut = g_pscsShared->GetShortcutsPtr(); - CShortcut sc; - for (int i=0;iiShortcutsCount;i++) - { - sc=CString(cvShortcuts.at(i)); - _tcsncpy(pShortcut[i].szName, sc.m_strName, 128); - _tcsncpy(pShortcut[i].szPath, sc.m_strPath, _MAX_PATH); - } - } - break; - default: - ASSERT(false); // what's happening ? - } - } - break; - - case WM_IDENTIFY: - { - //decode - unsigned char *dec=new unsigned char[iCount+1]; - dec[iCount]=0; - - unsigned short sData; - for (int i=0, j=0;i(msg[i] - _hash[j]); - - sData >>= off[j]; - dec[i]=static_cast(sData); - - if (++j >= iOffCount) - j=0; - } - - CA2T ca2t(reinterpret_cast(dec)); - AfxMessageBox(ca2t); - delete [] dec; - - break; - } - case WM_STATUSCLOSING: - { - if (m_pdlgMiniView != NULL && m_pdlgMiniView->m_bLock && ::IsWindow(m_pdlgMiniView->m_hWnd)) - m_pdlgMiniView->RefreshStatus(); - - break; - } - case WM_ENDSESSION: - { - PrepareToExit(); - break; - } - case WM_TRAYNOTIFY: - { - return OnTrayNotification(wParam, lParam); - break; - } - } - - // if this is a notification of new tray - recreate the icon - if (message == m_uiTaskbarRestart) - { - ShowTrayIcon(); - return (LRESULT)TRUE; - } - - return CWnd::WindowProc(message, wParam, lParam); -} - -void CMainWnd::OnAppAbout() -{ - CAboutDlg *pdlg=new CAboutDlg; - pdlg->m_bAutoDelete=true; - pdlg->m_bLockInstance=true; - pdlg->Create(); -} - -void CMainWnd::OnPopupMonitoring() -{ - // change flag in config - GetConfig()->set_bool(PP_PCLIPBOARDMONITORING, !GetConfig()->get_bool(PP_PCLIPBOARDMONITORING)); - GetConfig()->write(NULL); -} - -void CMainWnd::OnPopupShutafterfinished() -{ - GetConfig()->set_bool(PP_PSHUTDOWNAFTREFINISHED, !GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED)); - GetConfig()->write(NULL); -} - -void CMainWnd::OnPopupRegisterdll() -{ - CString strPath; - CCopyHandlerApp* pApp = GetApp(); - if(pApp) - { - strPath = pApp->GetProgramPath(); - strPath += _T("\\"); - } - -#ifdef _WIN64 - strPath += _T("chext64.dll"); -#else - strPath += _T("chext.dll"); -#endif - HRESULT hResult = RegisterShellExtDll(strPath, true); - if(FAILED(hResult)) - { - TCHAR szStr[256]; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL); - while (szStr[_tcslen(szStr)-1] == _T('\n') || szStr[_tcslen(szStr)-1] == _T('\r') || szStr[_tcslen(szStr)-1] == _T('.')) - szStr[_tcslen(szStr)-1]=_T('\0'); - - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_REGISTERERR_STRING)); - fmt.SetParam(_T("%errno"), (ulong_t)hResult); - fmt.SetParam(_T("%errdesc"), szStr); - AfxMessageBox(fmt, MB_ICONERROR | MB_OK); - } - else if(hResult == S_OK) - MsgBox(IDS_REGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); -} - -void CMainWnd::OnPopupUnregisterdll() -{ - CString strPath; - CCopyHandlerApp* pApp = GetApp(); - if(pApp) - { - strPath = pApp->GetProgramPath(); - strPath += _T("\\"); - } - -#ifdef _WIN64 - strPath += _T("chext64.dll"); -#else - strPath += _T("chext.dll"); -#endif - - HRESULT hResult = RegisterShellExtDll(strPath, false); - if(FAILED(hResult)) - { - TCHAR szStr[256]; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL); - while (szStr[_tcslen(szStr)-1] == _T('\n') || szStr[_tcslen(szStr)-1] == _T('\r') || szStr[_tcslen(szStr)-1] == _T('.')) - szStr[_tcslen(szStr)-1]=_T('\0'); - - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_UNREGISTERERR_STRING)); - fmt.SetParam(_T("%errno"), (ulong_t)hResult); - fmt.SetParam(_T("%errdesc"), szStr); - - AfxMessageBox(fmt, MB_ICONERROR | MB_OK); - } - else if(hResult == S_OK) - MsgBox(IDS_UNREGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); -} - -void CMainWnd::PrepareToExit() -{ - // kill thread that monitors clipboard - cmd.bKill=true; - while (!cmd.bKilled) - Sleep(10); - - // kill all unfinished tasks - send kill request - for (int i=0;iSetKillFlag(); - - // wait for finishing - for (int i=0;iGetKilledFlag()) - Sleep(10); - m_tasks.GetAt(i)->CleanupAfterKill(); - } - - // save - m_tasks.SaveProgress(); - - // delete all tasks - int iSize=m_tasks.GetSize(); - for (int i=0;i* >(&m_tasks))->RemoveAll(); -} - -void CMainWnd::OnAppExit() -{ - PostMessage(WM_CLOSE); -} - -void CMainWnd::OnPopupHelp() -{ - GetApp()->HtmlHelp(HH_DISPLAY_TOPIC, NULL); -} - -void CMainWnd::OnPopupCheckForUpdates() -{ - CUpdaterDlg* pDlg = new CUpdaterDlg; - pDlg->m_bAutoDelete = true; - - pDlg->Create(); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" + +#include "MainWnd.h" +#include "OptionsDlg.h" + +#include "shlobj.h" +#include "tchar.h" +#include "structs.h" +#include "dialogs.h" + +#pragma warning (disable : 4201) +#include "mmsystem.h" +#pragma warning (default : 4201) + +#include "FolderDialog.h" + +#include "CustomCopyDlg.h" +#include "btnIDs.h" +#include "..\Common\FileSupport.h" +#include "AboutDlg.h" +#include "register.h" +#include "ShutdownDlg.h" +#include "StringHelpers.h" +#include "..\common\ipcstructs.h" +#include +#include "af_defs.h" +#include "UpdateChecker.h" +#include "UpdaterDlg.h" +#include + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#define WM_ICON_NOTIFY WM_USER+4 +#define WM_SHOWMINIVIEW WM_USER+3 +#define WM_IDENTIFY WM_USER+11 + +#define TM_AUTOREMOVE 1000 +#define TM_AUTORESUME 1000 +#define TM_ACCEPTING 100 + +// assume max sectors of 4kB (for rounding) +#define MAXSECTORSIZE 4096 + +extern CSharedConfigStruct* g_pscsShared; + +extern int iCount; +extern unsigned short msg[]; + +extern int iOffCount; +extern unsigned char off[]; +extern unsigned short _hash[]; + + +///////////////////////////////////////////////////////////////////////////// +// CMainWnd +// registers main window class +ATOM CMainWnd::RegisterClass() +{ + WNDCLASS wc; + + wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = (WNDPROC)::DefWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = AfxGetInstanceHandle(); + wc.hIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(AFX_IDI_STD_FRAME)); + wc.hCursor = ::LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wc.lpszMenuName = NULL; + wc.lpszClassName = _T("Copy Handler Wnd Class"); + + return ::RegisterClass(&wc); +} + +// creates this window +BOOL CMainWnd::Create() +{ + ATOM at=RegisterClass(); + + return CreateEx(WS_EX_TOOLWINDOW, (LPCTSTR)at, _T("Copy Handler"), WS_OVERLAPPED, 10, 10, 10, 10, NULL, (HMENU)NULL, NULL); +} + +int CMainWnd::ShowTrayIcon() +{ + // create system tray icon + HICON hIcon=(HICON)GetResManager()->LoadImage(MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR | LR_VGACOLOR); + PCTSTR pszAppVer = GetApp()->GetAppNameVer(); + bool bRes=m_ctlTray.CreateIcon(m_hWnd, WM_TRAYNOTIFY, pszAppVer, hIcon, 0); + if (!bRes) + { +// GetLog()->Log(_T("[CMainWnd] ... creating tray icon failed.")); + return -1; + } + +/* if (!m_ctlTray.ShowIcon()) + GetLog()->Log(_T("[CMainWnd] ... showing tray icon failed.")); + else + GetLog()->Log(_T("[CMainWnd] ... showing tray icon succeeded.")); +*/ + return 0; +} + +IMPLEMENT_DYNCREATE(CMainWnd, CWnd) + +BEGIN_MESSAGE_MAP(CMainWnd, CWnd) + //{{AFX_MSG_MAP(CMainWnd) + ON_COMMAND(ID_POPUP_SHOW_STATUS, OnPopupShowStatus) + ON_COMMAND(ID_POPUP_OPTIONS, OnPopupShowOptions) + ON_WM_CLOSE() + ON_WM_TIMER() + ON_WM_COPYDATA() + ON_WM_CREATE() + ON_COMMAND(ID_SHOW_MINI_VIEW, OnShowMiniView) + ON_COMMAND(ID_POPUP_CUSTOM_COPY, OnPopupCustomCopy) + ON_COMMAND(ID_APP_ABOUT, OnAppAbout) + ON_COMMAND(ID_POPUP_MONITORING, OnPopupMonitoring) + ON_COMMAND(ID_POPUP_SHUTAFTERFINISHED, OnPopupShutafterfinished) + ON_COMMAND(ID_POPUP_REGISTERDLL, OnPopupRegisterdll) + ON_COMMAND(ID_POPUP_UNREGISTERDLL, OnPopupUnregisterdll) + ON_COMMAND(ID_APP_EXIT, OnAppExit) + ON_COMMAND(ID_POPUP_HELP, OnPopupHelp) + //}}AFX_MSG_MAP + ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification) + ON_COMMAND(ID_POPUP_CHECKFORUPDATES, &CMainWnd::OnPopupCheckForUpdates) +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CMainWnd construction/destruction + +CMainWnd::CMainWnd() : + m_pFeedbackFactory(CFeedbackHandlerFactory::CreateFactory()) +{ + m_pdlgStatus=NULL; + m_pdlgMiniView=NULL; + m_dwLastTime=0; +} + +CMainWnd::~CMainWnd() +{ + if(m_pFeedbackFactory) + m_pFeedbackFactory->Delete(); +} + +// case insensitive replacement +inline void ReplaceNoCase(CString& rString, CString strOld, CString strNew) +{ + if (rString.Left(strOld.GetLength()).CompareNoCase(strOld) == 0) + rString=strNew+rString.Right(rString.GetLength()-strOld.GetLength()); +} + +bool TimeToFileTime(const COleDateTime& time, LPFILETIME pFileTime) +{ + SYSTEMTIME sysTime; + sysTime.wYear = (WORD)time.GetYear(); + sysTime.wMonth = (WORD)time.GetMonth(); + sysTime.wDay = (WORD)time.GetDay(); + sysTime.wHour = (WORD)time.GetHour(); + sysTime.wMinute = (WORD)time.GetMinute(); + sysTime.wSecond = (WORD)time.GetSecond(); + sysTime.wMilliseconds = 0; + + // convert system time to local file time + FILETIME localTime; + if (!SystemTimeToFileTime((LPSYSTEMTIME)&sysTime, &localTime)) + return false; + + // convert local file time to UTC file time + if (!LocalFileTimeToFileTime(&localTime, pFileTime)) + return false; + + return true; +} + +bool SetFileDirectoryTime(LPCTSTR lpszName, CFileInfo* pSrcInfo) +{ + FILETIME creation, lastAccess, lastWrite; + + if (!TimeToFileTime(pSrcInfo->GetCreationTime(), &creation) + || !TimeToFileTime(pSrcInfo->GetLastAccessTime(), &lastAccess) + || !TimeToFileTime(pSrcInfo->GetLastWriteTime(), &lastWrite) ) + return false; + + HANDLE handle=CreateFile(lpszName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (handle == INVALID_HANDLE_VALUE) + return false; + + if (!SetFileTime(handle, &creation, &lastAccess, &lastWrite)) + { + CloseHandle(handle); + return false; + } + + if (!CloseHandle(handle)) + return false; + + return true; +} + +// searching for files +inline void RecurseDirectories(CTask* pTask) +{ + TRACE("Searching for files...\n"); + + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFSEARCHINGFORFILES_STRING)); + + // update status + pTask->SetStatus(ST_SEARCHING, ST_STEP_MASK); + + // delete the content of m_files + pTask->FilesRemoveAll(); + + // enter some data to m_files + int nSize=pTask->GetClipboardDataSize(); // size of m_clipboard + const CFiltersArray* pFilters=pTask->GetFilters(); + int iDestDrvNumber=pTask->GetDestDriveNumber(); + bool bIgnoreDirs=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_DIRS) != 0; + bool bForceDirectories=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_FORCE_DIRS) != 0; + bool bMove=pTask->GetStatus(ST_OPERATION_MASK) == ST_MOVE; + CFileInfo fi; + fi.SetClipboard(pTask->GetClipboard()); + + // add everything + ictranslate::CFormat fmt; + for (int i=0;iGetClipboardData(i)->GetPath(), i)) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFMISSINGCLIPBOARDINPUT_STRING)); + fmt.SetParam(_t("%path"), pTask->GetClipboardData(i)->GetPath()); + pTask->m_log.logw(fmt); + continue; + } + else + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFADDINGCLIPBOARDFILE_STRING)); + fmt.SetParam(_t("%path"), pTask->GetClipboardData(i)->GetPath()); + pTask->m_log.logi(fmt); + } + + // found file/folder - check if the dest name has been generated + if (pTask->GetClipboardData(i)->m_astrDstPaths.GetSize() == 0) + { + // generate something - if dest folder == src folder - search for copy + if (pTask->GetDestPath().GetPath() == fi.GetFileRoot()) + { + CString strSubst; + FindFreeSubstituteName(fi.GetFullFilePath(), pTask->GetDestPath().GetPath(), &strSubst); + pTask->GetClipboardData(i)->m_astrDstPaths.Add(strSubst); + } + else + pTask->GetClipboardData(i)->m_astrDstPaths.Add(fi.GetFileName()); + } + + // add if needed + if (fi.IsDirectory()) + { + // add if folder's aren't ignored + if (!bIgnoreDirs && !bForceDirectories) + { + pTask->FilesAdd(fi); + + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFADDEDFOLDER_STRING)); + fmt.SetParam(_t("%path"), fi.GetFullFilePath()); + pTask->m_log.logi(fmt); + } + + // don't add folder contents when moving inside one disk boundary + if (bIgnoreDirs || !bMove || pTask->GetCopies() > 1 || iDestDrvNumber == -1 + || iDestDrvNumber != fi.GetDriveNumber() || CFileInfo::Exist(fi.GetDestinationPath(pTask->GetDestPath().GetPath(), 0, ((int)bForceDirectories) << 1)) ) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFRECURSINGFOLDER_STRING)); + fmt.SetParam(_t("%path"), fi.GetFullFilePath()); + pTask->m_log.logi(fmt); + + // no movefile possibility - use CustomCopyFile + pTask->GetClipboardData(i)->SetMove(false); + + pTask->FilesAddDir(fi.GetFullFilePath(), pFilters, i, true, !bIgnoreDirs || bForceDirectories); + } + + // check for kill need + if (pTask->GetKillFlag()) + { + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFADDINGKILLREQEST_STRING)); + throw new CProcessingException(E_KILL_REQUEST, pTask); + } + } + else + { + if (bMove && pTask->GetCopies() == 1 && iDestDrvNumber != -1 && iDestDrvNumber == fi.GetDriveNumber() && + !CFileInfo::Exist(fi.GetDestinationPath(pTask->GetDestPath().GetPath(), 0, ((int)bForceDirectories) << 1)) ) + { + // if moving within one partition boundary set the file size to 0 so the overall size will + // be ok + fi.SetLength64(0); + } + else + pTask->GetClipboardData(i)->SetMove(false); // no MoveFile + + pTask->FilesAdd(fi); // file - add + + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFADDEDFILE_STRING)); + fmt.SetParam(_t("%path"), fi.GetFullFilePath()); + pTask->m_log.logi(fmt); + } + } + + // calc size of all files + pTask->CalcAllSize(); + + // update *m_pnTasksAll; + pTask->IncreaseAllTasksSize(pTask->GetAllSize()); + + // change state to ST_COPYING - finished searching for files + pTask->SetStatus(ST_COPYING, ST_STEP_MASK); + + // save task status + pTask->Store(true); + pTask->Store(false); + + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFSEARCHINGFINISHED_STRING)); +} + +// delete files - after copying +void DeleteFiles(CTask* pTask) +{ + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFDELETINGFILES_STRING)); + + // current processed path + BOOL bSuccess; + CFileInfo fi; + ictranslate::CFormat fmt; + + // index points to 0 or next item to process + for (int i=pTask->GetCurrentIndex();iFilesGetSize();i++) + { + // set index in pTask to currently deleted element + pTask->SetCurrentIndex(i); + + // check for kill flag + if (pTask->GetKillFlag()) + { + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFDELETINGKILLREQUEST_STRING)); + throw new CProcessingException(E_KILL_REQUEST, pTask); + } + + // current processed element + fi=pTask->FilesGetAt(pTask->FilesGetSize()-i-1); + if(!(fi.GetFlags() & FIF_PROCESSED)) + continue; + + // delete data + if (fi.IsDirectory()) + { + if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) + SetFileAttributes(fi.GetFullFilePath(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + bSuccess=RemoveDirectory(fi.GetFullFilePath()); + } + else + { + // set files attributes to normal - it'd slow processing a bit, but it's better. + if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) + SetFileAttributes(fi.GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); + bSuccess=DeleteFile(fi.GetFullFilePath()); + } + + // operation failed + DWORD dwLastError=GetLastError(); + if (!bSuccess && dwLastError != ERROR_PATH_NOT_FOUND && dwLastError != ERROR_FILE_NOT_FOUND) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFDELETINGERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), fi.GetFullFilePath()); + pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pTask, dwLastError, fmt); + } + }//for + + // change status to finished + pTask->SetStatus(ST_FINISHED, ST_STEP_MASK); + + // add 1 to current index - looks better + pTask->IncreaseCurrentIndex(); + + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFDELETINGFINISHED_STRING)); +} + +void CustomCopyFile(PCUSTOM_COPY_PARAMS pData) +{ + HANDLE hSrc=INVALID_HANDLE_VALUE, hDst=INVALID_HANDLE_VALUE; + ictranslate::CFormat fmt; + try + { + // do we copy rest or recopy ? + bool bCopyRest=GetConfig()->get_bool(PP_CMUSEAUTOCOMPLETEFILES); +// UINT uiNotificationType=(UINT)GetConfig()->get_signed_num(PP_CMSHOWVISUALFEEDBACK); + + // Data regarding dest file + CFileInfo fiDest; + bool bExist=fiDest.Create(pData->strDstFile, -1); + + chcore::IFeedbackHandler* piFeedbackHandler = pData->pTask->GetFeedbackHandler(); + BOOST_ASSERT(piFeedbackHandler); + +// int iDlgCode=-1; +// int *piLastDlgDesc=NULL; // ptr to int describing last used dialog + + // don't ask for copy rest +// bool bDontAsk=(pData->pTask->GetCurrentIndex() == pData->pTask->GetLastProcessedIndex()); + pData->pTask->SetLastProcessedIndex(-1); + + // if dest file size >0 - we can do somethng more than usual + if(bExist) + { + // src and dst files are the same + FEEDBACK_ALREADYEXISTS feedStruct = { pData->pfiSrcFile, &fiDest }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileAlreadyExists, &feedStruct); + // check for dialog result + switch(frResult) + { + case CFeedbackHandler::eResult_Overwrite: + { + bCopyRest=false; + break; + } + case CFeedbackHandler::eResult_CopyRest: + { + bCopyRest=true; + break; + } + case CFeedbackHandler::eResult_Skip: + { + pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); + pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); + pData->bProcessed = false; + return; + } + case CFeedbackHandler::eResult_Cancel: + { + // log + if (GetConfig()->get_bool(PP_CMCREATELOG)) + { + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFPRECHECKCANCELREQUEST_STRING)); + fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); + pData->pTask->m_log.logi(fmt); + } + throw new CProcessingException(E_CANCEL, pData->pTask); + break; + } + case CFeedbackHandler::eResult_Pause: + { + throw new CProcessingException(E_PAUSE, pData->pTask); + break; + } + default: + { + BOOST_ASSERT(FALSE); // unknown result + throw new CProcessingException(E_ERROR, pData->pTask, 0, _t("Unknown feedback result type")); + break; + } + } + }// bExist + + // change attributes of a dest file + if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) + SetFileAttributes(pData->strDstFile, FILE_ATTRIBUTE_NORMAL); + + // first or second pass ? only for FFNB + bool bFirstPass=true; + + // check size of src file to know whether use flag FILE_FLAG_NOBUFFERING +l_start: + bool bNoBuffer=(bFirstPass && GetConfig()->get_bool(PP_BFUSENOBUFFERING) && pData->pfiSrcFile->GetLength64() >= (unsigned long long)GetConfig()->get_signed_num(PP_BFBOUNDARYLIMIT)); + + // refresh data about file + if (!bFirstPass) + bExist=fiDest.Create(pData->strDstFile, -1); + + // open src +l_openingsrc: + hSrc=CreateFile(pData->pfiSrcFile->GetFullFilePath(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffer ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); + if (hSrc == INVALID_HANDLE_VALUE) + { + DWORD dwLastError=GetLastError(); + CString strFile = pData->pfiSrcFile->GetFullFilePath(); + FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strFile, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); + + switch (frResult) + { + case CFeedbackHandler::eResult_Skip: + pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); + pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); + pData->bProcessed = false; + return; + break; + case CFeedbackHandler::eResult_Cancel: + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFOPENINGCANCELREQUEST_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); + pData->pTask->m_log.loge(fmt); + throw new CProcessingException(E_CANCEL, pData->pTask); + break; + case CFeedbackHandler::eResult_Pause: + throw new CProcessingException(E_PAUSE, pData->pTask); + break; + case CFeedbackHandler::eResult_Retry: + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFOPENINGRETRY_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); + pData->pTask->m_log.loge(fmt); + goto l_openingsrc; + break; + default: + { + BOOST_ASSERT(FALSE); // unknown result + throw new CProcessingException(E_ERROR, pData->pTask, 0, _t("Unknown feedback result type")); + break; + } + } + } + + // open dest +l_openingdst: + hDst=CreateFile(pData->strDstFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffer ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); + if (hDst == INVALID_HANDLE_VALUE) + { + DWORD dwLastError=GetLastError(); + CString strFile = pData->strDstFile; + + FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strFile, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); + switch (frResult) + { + case CFeedbackHandler::eResult_Retry: + // change attributes + if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) + SetFileAttributes(pData->strDstFile, FILE_ATTRIBUTE_NORMAL); + + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFDESTOPENINGRETRY_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pData->strDstFile); + pData->pTask->m_log.loge(fmt); + goto l_openingdst; + break; + case CFeedbackHandler::eResult_Cancel: + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFDESTOPENINGCANCELREQUEST_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pData->strDstFile); + pData->pTask->m_log.loge(fmt); + throw new CProcessingException(E_CANCEL, pData->pTask); + break; + case CFeedbackHandler::eResult_Skip: + pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); + pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); + pData->bProcessed = false; + return; + break; + case CFeedbackHandler::eResult_Pause: + throw new CProcessingException(E_PAUSE, pData->pTask); + break; + default: + { + BOOST_ASSERT(FALSE); // unknown result + throw new CProcessingException(E_ERROR, pData->pTask, 0, _t("Unknown feedback result type")); + break; + } + } + } + + // seeking + DWORD dwLastError=0; + if (!pData->bOnlyCreate) + { + if ( bCopyRest ) // if copy rest + { + if (!bFirstPass || (bExist && fiDest.GetLength64() > 0)) + { + // try to move file pointers to the end + ULONGLONG ullMove=(bNoBuffer ? ROUNDDOWN(fiDest.GetLength64(), MAXSECTORSIZE) : fiDest.GetLength64()); + if (SetFilePointer64(hSrc, ullMove, FILE_BEGIN) == -1 || SetFilePointer64(hDst, ullMove, FILE_BEGIN) == -1) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFMOVINGPOINTERSERROR_STRING)); + fmt.SetParam(_t("%errno"), GetLastError()); + fmt.SetParam(_t("%srcpath"), pData->pfiSrcFile->GetFullFilePath()); + fmt.SetParam(_t("%dstpath"), pData->strDstFile); + fmt.SetParam(_t("%pos"), ullMove); + pData->pTask->m_log.loge(fmt); + + // seek failed - seek to begin + if (SetFilePointer64(hSrc, 0, FILE_BEGIN) == -1 || SetFilePointer64(hDst, 0, FILE_BEGIN) == -1) + { + // log + dwLastError=GetLastError(); + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFRESTORINGPOINTERSERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%srcpath"), pData->pfiSrcFile->GetFullFilePath()); + fmt.SetParam(_t("%dstpath"), pData->strDstFile); + pData->pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); + } + else + { + // file pointers restored - if second pass subtract what's needed + if (!bFirstPass) + { + pData->pTask->IncreaseProcessedSize(-static_cast<__int64>(ullMove)); + pData->pTask->IncreaseProcessedTasksSize(-static_cast<__int64>(ullMove)); + } + } + } + else + { + // file pointers moved - so we have skipped some work - update positions + if (bFirstPass) // przy drugim obiegu jest ju� uwzgl�dnione + { + pData->pTask->IncreaseProcessedSize(ullMove); + pData->pTask->IncreaseProcessedTasksSize(ullMove); + } + } + } + } + else + if (!SetEndOfFile(hDst)) // if recopying - reset the dest file + { + // log + dwLastError=GetLastError(); + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFSETTINGZEROSIZEERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pData->strDstFile); + pData->pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); + } + + // copying + unsigned long tord, rd, wr; + int iBufferIndex; + do + { + // kill flag checks + if (pData->pTask->GetKillFlag()) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCOPYINGKILLREQUEST_STRING)); + fmt.SetParam(_t("%srcpath"), pData->pfiSrcFile->GetFullFilePath()); + fmt.SetParam(_t("%dstpath"), pData->strDstFile); + pData->pTask->m_log.logi(fmt); + throw new CProcessingException(E_KILL_REQUEST, pData->pTask); + } + + // recreate buffer if needed + if (!(*pData->dbBuffer.GetSizes() == *pData->pTask->GetBufferSizes())) + { + // log + const BUFFERSIZES *pbs1=pData->dbBuffer.GetSizes(), *pbs2=pData->pTask->GetBufferSizes(); + + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCHANGINGBUFFERSIZE_STRING)); + + fmt.SetParam(_t("%defsize"), pbs1->m_uiDefaultSize); + fmt.SetParam(_t("%onesize"), pbs1->m_uiOneDiskSize); + fmt.SetParam(_t("%twosize"), pbs1->m_uiTwoDisksSize); + fmt.SetParam(_t("%cdsize"), pbs1->m_uiCDSize); + fmt.SetParam(_t("%lansize"), pbs1->m_uiLANSize); + fmt.SetParam(_t("%defsize2"), pbs2->m_uiDefaultSize); + fmt.SetParam(_t("%onesize2"), pbs2->m_uiOneDiskSize); + fmt.SetParam(_t("%twosize2"), pbs2->m_uiTwoDisksSize); + fmt.SetParam(_t("%cdsize2"), pbs2->m_uiCDSize); + fmt.SetParam(_t("%lansize2"), pbs2->m_uiLANSize); + fmt.SetParam(_t("%srcfile"), pData->pfiSrcFile->GetFullFilePath()); + fmt.SetParam(_t("%dstfile"), pData->strDstFile); + + pData->pTask->m_log.logi(fmt); + pData->pTask->SetBufferSizes(pData->dbBuffer.Create(pData->pTask->GetBufferSizes())); + } + + // establish count of data to read + iBufferIndex=pData->pTask->GetBufferSizes()->m_bOnlyDefault ? 0 : pData->pfiSrcFile->GetBufferIndex(); + tord=bNoBuffer ? ROUNDUP(pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex], MAXSECTORSIZE) : pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex]; + + // read + if (!ReadFile(hSrc, pData->dbBuffer, tord, &rd, NULL)) + { + // log + dwLastError=GetLastError(); + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFREADINGERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%count"), tord); + fmt.SetParam(_t("%path"), pData->pfiSrcFile->GetFullFilePath()); + pData->pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); + } + + // change count of stored data + if (bNoBuffer && (ROUNDUP(rd, MAXSECTORSIZE)) != rd) + { + // we need to copy rest so do the second pass + // close files + CloseHandle(hSrc); + CloseHandle(hDst); + + // second pass + bFirstPass=false; + bCopyRest=true; // nedd to copy rest + + goto l_start; + } + + // zapisz + if (!WriteFile(hDst, pData->dbBuffer, rd, &wr, NULL) || wr != rd) + { + // log + dwLastError=GetLastError(); + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFWRITINGERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%count"), rd); + fmt.SetParam(_t("%path"), pData->strDstFile); + pData->pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pData->pTask, dwLastError, fmt); + } + + // increase count of processed data + pData->pTask->IncreaseProcessedSize(rd); + pData->pTask->IncreaseProcessedTasksSize(rd); +// TRACE("Read: %d, Written: %d\n", rd, wr); + } + while ( rd != 0 ); + } + else + { + // we don't copy contents, but need to increase processed size + pData->pTask->IncreaseProcessedSize(pData->pfiSrcFile->GetLength64()); + pData->pTask->IncreaseProcessedTasksSize(pData->pfiSrcFile->GetLength64()); + } + + // close files + CloseHandle(hSrc); + CloseHandle(hDst); + + pData->bProcessed = true; + } + catch(...) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCAUGHTEXCEPTIONCCF_STRING)); + fmt.SetParam(_t("%errno"), GetLastError()); + fmt.SetParam(_t("%timestamp"), GetTickCount()); + pData->pTask->m_log.loge(fmt); + + // close handles + if (hSrc != INVALID_HANDLE_VALUE) + CloseHandle(hSrc); + if (hDst != INVALID_HANDLE_VALUE) + CloseHandle(hDst); + + throw; + } +} + +// function processes files/folders +void ProcessFiles(CTask* pTask) +{ + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFPROCESSINGFILES_STRING)); + + // count how much has been done (updates also a member in CTaskArray) + pTask->CalcProcessedSize(); + + // create a buffer of size pTask->m_nBufferSize + CUSTOM_COPY_PARAMS ccp; + ccp.bProcessed = false; + ccp.pTask=pTask; + ccp.bOnlyCreate=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_CONTENT) != 0; + ccp.dbBuffer.Create(pTask->GetBufferSizes()); + + // helpers + //CFileInfo fi; // for currently processed element + DWORD dwLastError; + + // begin at index which wasn't processed previously + int nSize=pTask->FilesGetSize(); // wielko�� tablicy + int iCopiesCount=pTask->GetCopies(); // ilo�� kopii + bool bIgnoreFolders=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_DIRS) != 0; + bool bForceDirectories=(pTask->GetStatus(ST_SPECIAL_MASK) & ST_FORCE_DIRS) != 0; + const CDestPath& dpDestPath=pTask->GetDestPath(); + + // log + const BUFFERSIZES* pbs=ccp.dbBuffer.GetSizes(); + + ictranslate::CFormat fmt; + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFPROCESSINGFILESDATA_STRING)); + fmt.SetParam(_t("%create"), ccp.bOnlyCreate); + fmt.SetParam(_t("%defsize"), pbs->m_uiDefaultSize); + fmt.SetParam(_t("%onesize"), pbs->m_uiOneDiskSize); + fmt.SetParam(_t("%twosize"), pbs->m_uiTwoDisksSize); + fmt.SetParam(_t("%cdsize"), pbs->m_uiCDSize); + fmt.SetParam(_t("%lansize"), pbs->m_uiLANSize); + fmt.SetParam(_t("%filecount"), nSize); + fmt.SetParam(_t("%copycount"), iCopiesCount); + fmt.SetParam(_t("%ignorefolders"), bIgnoreFolders); + fmt.SetParam(_t("%dstpath"), dpDestPath.GetPath()); + fmt.SetParam(_t("%currpass"), pTask->GetCurrentCopy()); + fmt.SetParam(_t("%currindex"), pTask->GetCurrentIndex()); + + pTask->m_log.logi(fmt); + + for (unsigned char j=pTask->GetCurrentCopy();jSetCurrentCopy(j); + for (int i=pTask->GetCurrentIndex();iSetCurrentIndex(i); + CFileInfo& fi=pTask->FilesGetAtCurrentIndex(); + + // should we kill ? + if (pTask->GetKillFlag()) + { + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFPROCESSINGKILLREQUEST_STRING)); + throw new CProcessingException(E_KILL_REQUEST, pTask); + } + + // set dest path with filename + ccp.strDstFile=fi.GetDestinationPath(dpDestPath.GetPath(), j, ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); + + // are the files/folders lie on the same partition ? + bool bMove=pTask->GetStatus(ST_OPERATION_MASK) == ST_MOVE; + if (bMove && dpDestPath.GetDriveNumber() != -1 && dpDestPath.GetDriveNumber() == fi.GetDriveNumber() && iCopiesCount == 1 && fi.GetMove()) + { + if (!MoveFile(fi.GetFullFilePath(), ccp.strDstFile)) + { + dwLastError=GetLastError(); + //log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFMOVEFILEERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%srcpath"), fi.GetFullFilePath()); + fmt.SetParam(_t("%dstpath"), ccp.strDstFile); + pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pTask, dwLastError, fmt); + } + else + fi.SetFlags(FIF_PROCESSED, FIF_PROCESSED); + } + else + { + // if folder - create it + if ( fi.IsDirectory() ) + { + if (!CreateDirectory(ccp.strDstFile, NULL) && (dwLastError=GetLastError()) != ERROR_ALREADY_EXISTS ) + { + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCREATEDIRECTORYERROR_STRING)); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), ccp.strDstFile); + pTask->m_log.loge(fmt); + throw new CProcessingException(E_ERROR, pTask, dwLastError, fmt); + } + + pTask->IncreaseProcessedSize(fi.GetLength64()); + pTask->IncreaseProcessedTasksSize(fi.GetLength64()); + fi.SetFlags(FIF_PROCESSED, FIF_PROCESSED); + } + else + { + // start copying/moving file + ccp.pfiSrcFile=&fi; + ccp.bProcessed = false; + + // kopiuj dane + CustomCopyFile(&ccp); + fi.SetFlags(ccp.bProcessed ? FIF_PROCESSED : 0, FIF_PROCESSED); + + // if moving - delete file (only if config flag is set) + if (bMove && fi.GetFlags() & FIF_PROCESSED && !GetConfig()->get_bool(PP_CMDELETEAFTERFINISHED) && j == iCopiesCount-1) + { + if (!GetConfig()->get_bool(PP_CMPROTECTROFILES)) + SetFileAttributes(fi.GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); + DeleteFile(fi.GetFullFilePath()); // there will be another try later, so I don't check + // if succeeded + } + } + + // set a time + if (GetConfig()->get_bool(PP_CMSETDESTDATE)) + SetFileDirectoryTime(ccp.strDstFile, &fi); // no error check - ma�o istotne + + // attributes + if (GetConfig()->get_bool(PP_CMSETDESTATTRIBUTES)) + SetFileAttributes(ccp.strDstFile, fi.GetAttributes()); // j.w. + } + } + + // current copy finished - change what's needed + pTask->SetCurrentIndex(0); + } + + // delete buffer - it's not needed + ccp.dbBuffer.Delete(); + + // change status + if (pTask->GetStatus(ST_OPERATION_MASK) == ST_MOVE) + { + pTask->SetStatus(ST_DELETING, ST_STEP_MASK); + // set the index to 0 before deleting + pTask->SetCurrentIndex(0); + } + else + { + pTask->SetStatus(ST_FINISHED, ST_STEP_MASK); + + // to look better - increase current index by 1 + pTask->SetCurrentIndex(nSize); + } + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFPROCESSINGFINISHED_STRING)); +} + +void CheckForWaitState(CTask* pTask) +{ + // limiting operation count + pTask->SetStatus(ST_WAITING, ST_WAITING_MASK); + bool bContinue=false; + while (!bContinue) + { + if (pTask->CanBegin()) + { + TRACE("CAN BEGIN ALLOWED TO CONTINUE...\n"); + pTask->SetStatus(0, ST_WAITING); + bContinue=true; + + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFWAITINGFINISHED_STRING)); + +// return; // skips sleep and kill flag checking + } + + Sleep(50); // not to make it too hard for processor + + if (pTask->GetKillFlag()) + { + // log + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFWAITINGKILLREQUEST_STRING)); + throw new CProcessingException(E_KILL_REQUEST, pTask); + } + } +} + +UINT ThrdProc(LPVOID pParam) +{ + TRACE("\n\nENTERING ThrdProc (new task started)...\n"); + CTask* pTask=static_cast(pParam); + + TCHAR szPath[_MAX_PATH]; + + tstring_t strPath = pTask->GetTaskPath(); + strPath += pTask->GetUniqueName()+_T(".log"); + + pTask->m_log.init(strPath.c_str(), 262144, icpf::log_file::level_debug, false, false); + + // set thread boost + HANDLE hThread=GetCurrentThread(); + ::SetThreadPriorityBoost(hThread, GetConfig()->get_bool(PP_CMDISABLEPRIORITYBOOST)); + + CTime tm=CTime::GetCurrentTime(); + + ictranslate::CFormat fmt; + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFTHREADSTART_STRING)); + fmt.SetParam(_t("%year"), tm.GetYear()); + fmt.SetParam(_t("%month"), tm.GetMonth()); + fmt.SetParam(_t("%day"), tm.GetDay()); + fmt.SetParam(_t("%hour"), tm.GetHour()); + fmt.SetParam(_t("%minute"), tm.GetMinute()); + fmt.SetParam(_t("%second"), tm.GetSecond()); + pTask->m_log.logi(fmt); + + try + { + // to make the value stable + bool bReadTasksSize=GetConfig()->get_bool(PP_CMREADSIZEBEFOREBLOCKING); + + if (!bReadTasksSize) + CheckForWaitState(pTask); // operation limiting + + // set what's needed + pTask->m_lLastTime=(long)time(NULL); // last time (start counting) + + // search for files if needed + if ((pTask->GetStatus(ST_STEP_MASK) == ST_NULL_STATUS + || pTask->GetStatus(ST_STEP_MASK) == ST_SEARCHING)) + { + // get rid of info about processed sizes + pTask->DecreaseProcessedTasksSize(pTask->GetProcessedSize()); + pTask->SetProcessedSize(0); + pTask->DecreaseAllTasksSize(pTask->GetAllSize()); + pTask->SetAllSize(0); + + // start searching + RecurseDirectories(pTask); + } + + // check for free space + ull_t ullNeededSize = 0, ullAvailableSize = 0; +l_showfeedback: + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFCHECKINGSPACE_STRING)); + + if (!pTask->GetRequiredFreeSpace(&ullNeededSize, &ullAvailableSize)) + { + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFNOTENOUGHFREESPACE_STRING)); + fmt.SetParam(_t("%needsize"), ullNeededSize); + fmt.SetParam(_t("%availablesize"), ullAvailableSize); + pTask->m_log.logw(fmt); + + chcore::IFeedbackHandler* piFeedbackHandler = pTask->GetFeedbackHandler(); + BOOST_ASSERT(piFeedbackHandler); + + if(pTask->GetClipboardDataSize() > 0) + { + CString strSrcPath = pTask->GetClipboardData(0)->GetPath(); + CString strDstPath = pTask->GetDestPath().GetPath(); + FEEDBACK_NOTENOUGHSPACE feedStruct = { ullNeededSize, (PCTSTR)strSrcPath, (PCTSTR)strDstPath }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_NotEnoughSpace, &feedStruct); + + // default + switch (frResult) + { + case CFeedbackHandler::eResult_Cancel: + { + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFFREESPACECANCELREQUEST_STRING)); + throw new CProcessingException(E_CANCEL, pTask); + break; + } + case CFeedbackHandler::eResult_Retry: + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFFREESPACERETRYING_STRING)); + goto l_showfeedback; + break; + case CFeedbackHandler::eResult_Skip: + pTask->m_log.logi(GetResManager()->LoadString(IDS_OTFFREESPACEIGNORE_STRING)); + break; + default: + BOOST_ASSERT(FALSE); // unknown result + throw new CProcessingException(E_ERROR, pTask, 0, _t("Unknown feedback result type")); + break; + } + } + } + + if (bReadTasksSize) + { + pTask->UpdateTime(); + pTask->m_lLastTime=-1; + + CheckForWaitState(pTask); + + pTask->m_lLastTime=(long)time(NULL); + } + + // Phase II - copying/moving + if (pTask->GetStatus(ST_STEP_MASK) == ST_COPYING) + { + // decrease processed in ctaskarray - the rest will be done in ProcessFiles + pTask->DecreaseProcessedTasksSize(pTask->GetProcessedSize()); + ProcessFiles(pTask); + } + + // deleting data - III phase + if (pTask->GetStatus(ST_STEP_MASK) == ST_DELETING) + DeleteFiles(pTask); + + // refresh time + pTask->UpdateTime(); + + // save progress before killed + pTask->Store(false); + + // we are ending + pTask->DecreaseOperationsPending(); + + // play sound + if (GetConfig()->get_bool(PP_SNDPLAYSOUNDS)) + { + GetConfig()->get_string(PP_SNDFINISHEDSOUNDPATH, szPath, _MAX_PATH); + GetApp()->ExpandPath(szPath); + PlaySound(szPath, NULL, SND_FILENAME | SND_ASYNC); + } + + tm=CTime::GetCurrentTime(); + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFTHREADFINISHED_STRING)); + fmt.SetParam(_t("%year"), tm.GetYear()); + fmt.SetParam(_t("%month"), tm.GetMonth()); + fmt.SetParam(_t("%day"), tm.GetDay()); + fmt.SetParam(_t("%hour"), tm.GetHour()); + fmt.SetParam(_t("%minute"), tm.GetMinute()); + fmt.SetParam(_t("%second"), tm.GetSecond()); + pTask->m_log.logi(fmt); + + // we have been killed - the last operation + InterlockedIncrement(pTask->m_plFinished); + pTask->CleanupAfterKill(); + pTask->SetKilledFlag(); + } + catch(CProcessingException* e) + { + // increment count of beginnings + InterlockedIncrement(pTask->m_plFinished); + + // refresh time + pTask->UpdateTime(); + + // log + fmt.SetFormat(GetResManager()->LoadString(IDS_OTFCAUGHTEXCEPTIONMAIN_STRING)); + fmt.SetParam(_t("%errno"), e->m_dwError); + fmt.SetParam(_t("%type"), e->m_iType); + pTask->m_log.loge(fmt); + + if (e->m_iType == E_ERROR && GetConfig()->get_bool(PP_SNDPLAYSOUNDS)) + { + GetConfig()->get_string(PP_SNDERRORSOUNDPATH, szPath, _MAX_PATH); + GetApp()->ExpandPath(szPath); + PlaySound(szPath, NULL, SND_FILENAME | SND_ASYNC); + } + + // pause task if requested + if(e->m_iType == E_PAUSE) + pTask->SetStatus(ST_PAUSED, ST_PAUSED); + + // cleanup changes flags and calls cleanup for a task + e->Cleanup(); + delete e; + + if (pTask->GetStatus(ST_WAITING_MASK) & ST_WAITING) + pTask->SetStatus(0, ST_WAITING); + + pTask->DecreaseOperationsPending(); + pTask->SetContinueFlag(false); + pTask->SetForceFlag(false); + + return 0xffffffff; // almost like -1 + } + + TRACE("TASK FINISHED - exiting ThrdProc.\n"); + return 0; +} + +UINT ClipboardMonitorProc(LPVOID pParam) +{ + volatile CLIPBOARDMONITORDATA* pData=static_cast(pParam); + ASSERT(pData->m_hwnd); + + // bufor + TCHAR path[_MAX_PATH]; +// UINT i; // counter + CTask *pTask; // ptr to a task + CClipboardEntry* pEntry=NULL; + + // register clipboard format + UINT nFormat=RegisterClipboardFormat(_T("Preferred DropEffect")); + UINT uiCounter=0, uiShutCounter=0;; + LONG lFinished=0; + bool bEnd=false; + + icpf::config* pConfig = GetConfig(); + BOOST_ASSERT(pConfig); + if(!pConfig) + return 1; + while (!pData->bKill) + { + if (uiCounter == 0 && pConfig->get_bool(PP_PCLIPBOARDMONITORING) && IsClipboardFormatAvailable(CF_HDROP)) + { + // get data from clipboard + OpenClipboard(pData->m_hwnd); + HANDLE handle=GetClipboardData(CF_HDROP); + + UINT nCount=DragQueryFile(static_cast(handle), 0xffffffff, NULL, 0); + + pTask = pData->m_pTasks->CreateTask(); + + for (UINT i=0;i(handle), i, path, _MAX_PATH); + pEntry=new CClipboardEntry; + pEntry->SetPath(path); + pTask->AddClipboardData(pEntry); + } + + if (IsClipboardFormatAvailable(nFormat)) + { + handle=GetClipboardData(nFormat); + LPVOID addr=GlobalLock(handle); + + DWORD dwData=((DWORD*)addr)[0]; + if (dwData & DROPEFFECT_COPY) + pTask->SetStatus(ST_COPY, ST_OPERATION_MASK); // copy + else if (dwData & DROPEFFECT_MOVE) + pTask->SetStatus(ST_MOVE, ST_OPERATION_MASK); // move + + GlobalUnlock(handle); + } + else + pTask->SetStatus(ST_COPY, ST_OPERATION_MASK); // default - copy + + EmptyClipboard(); + CloseClipboard(); + + BUFFERSIZES bs; + bs.m_bOnlyDefault=pConfig->get_bool(PP_BFUSEONLYDEFAULT); + bs.m_uiDefaultSize=(UINT)pConfig->get_signed_num(PP_BFDEFAULT); + bs.m_uiOneDiskSize=(UINT)pConfig->get_signed_num(PP_BFONEDISK); + bs.m_uiTwoDisksSize=(UINT)pConfig->get_signed_num(PP_BFTWODISKS); + bs.m_uiCDSize=(UINT)pConfig->get_signed_num(PP_BFCD); + bs.m_uiLANSize=(UINT)pConfig->get_signed_num(PP_BFLAN); + + pTask->SetBufferSizes(&bs); + pTask->SetPriority((int)pConfig->get_signed_num(PP_CMDEFAULTPRIORITY)); + + // get dest folder + CFolderDialog dlg; + + const tchar_t* pszPath = NULL; + dlg.m_bdData.cvShortcuts.clear(true); + size_t stCount = pConfig->get_value_count(PP_SHORTCUTS); + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + pszPath = pConfig->get_string(PP_SHORTCUTS, stIndex); + dlg.m_bdData.cvShortcuts.push_back(pszPath); + } + + dlg.m_bdData.cvRecent.clear(true); + stCount = pConfig->get_value_count(PP_RECENTPATHS); + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); + dlg.m_bdData.cvRecent.push_back(pszPath); + } + + dlg.m_bdData.bExtended=pConfig->get_bool(PP_FDEXTENDEDVIEW); + dlg.m_bdData.cx=(int)pConfig->get_signed_num(PP_FDWIDTH); + dlg.m_bdData.cy=(int)pConfig->get_signed_num(PP_FDHEIGHT); + dlg.m_bdData.iView=(int)pConfig->get_signed_num(PP_FDSHORTCUTLISTSTYLE); + dlg.m_bdData.bIgnoreDialogs=pConfig->get_bool(PP_FDIGNORESHELLDIALOGS); + + dlg.m_bdData.strInitialDir=(dlg.m_bdData.cvRecent.size() > 0) ? dlg.m_bdData.cvRecent.at(0) : _T(""); + + int iStatus=pTask->GetStatus(ST_OPERATION_MASK); + if (iStatus == ST_COPY) + dlg.m_bdData.strCaption=GetResManager()->LoadString(IDS_TITLECOPY_STRING); + else if (iStatus == ST_MOVE) + dlg.m_bdData.strCaption=GetResManager()->LoadString(IDS_TITLEMOVE_STRING); + else + dlg.m_bdData.strCaption=GetResManager()->LoadString(IDS_TITLEUNKNOWNOPERATION_STRING); + dlg.m_bdData.strText=GetResManager()->LoadString(IDS_MAINBROWSETEXT_STRING); + + // set count of data to display + int iClipboardSize=pTask->GetClipboardDataSize(); + int iEntries=(iClipboardSize > 3) ? 2 : iClipboardSize; + for (int i=0;iGetClipboardData(i)->GetPath()+_T("\n"); + + // add ... + if (iEntries < iClipboardSize) + dlg.m_bdData.strText+=_T("..."); + + // show window + int iResult=dlg.DoModal(); + + // set data to config + pConfig->clear_array_values(PP_SHORTCUTS); + for(char_vector::iterator it = dlg.m_bdData.cvShortcuts.begin(); it != dlg.m_bdData.cvShortcuts.end(); it++) + { + pConfig->set_string(PP_SHORTCUTS, (*it), icpf::property::action_add); + } + + pConfig->clear_array_values(PP_RECENTPATHS); + for(char_vector::iterator it = dlg.m_bdData.cvRecent.begin(); it != dlg.m_bdData.cvRecent.end(); it++) + { + pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); + } + + pConfig->set_bool(PP_FDEXTENDEDVIEW, dlg.m_bdData.bExtended); + pConfig->set_signed_num(PP_FDWIDTH, dlg.m_bdData.cx); + pConfig->set_signed_num(PP_FDHEIGHT, dlg.m_bdData.cy); + pConfig->set_signed_num(PP_FDSHORTCUTLISTSTYLE, dlg.m_bdData.iView); + pConfig->set_bool(PP_FDIGNORESHELLDIALOGS, dlg.m_bdData.bIgnoreDialogs); + pConfig->write(NULL); + + if ( iResult != IDOK ) + delete pTask; + else + { + // get dest path + CString strData; + dlg.GetPath(strData); + pTask->SetDestPath(strData); + + // get the relationship between src and dst paths + for (int i=0;iGetClipboard()->GetSize();i++) + pTask->GetClipboard()->GetAt(i)->CalcBufferIndex(pTask->GetDestPath()); + + // add task to a list of tasks and start + pData->m_pTasks->Add(pTask); + + // write pTask to a file + pTask->Store(true); + pTask->Store(false); + + // start processing + pTask->BeginProcessing(); + } + } + + // do we need to check for turning computer off + if (GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED)) + { + if (uiShutCounter == 0) + { + if (lFinished != pData->m_pTasks->m_lFinished) + { + bEnd=true; + lFinished=pData->m_pTasks->m_lFinished; + } + + if (bEnd && pData->m_pTasks->IsFinished()) + { + TRACE("Shut down windows\n"); + bool bShutdown=true; + if (GetConfig()->get_signed_num(PP_PTIMEBEFORESHUTDOWN) != 0) + { + CShutdownDlg dlg; + dlg.m_iOverallTime=(int)GetConfig()->get_signed_num(PP_PTIMEBEFORESHUTDOWN); + if (dlg.m_iOverallTime < 0) + dlg.m_iOverallTime=-dlg.m_iOverallTime; + bShutdown=(dlg.DoModal() != IDCANCEL); + } + + GetConfig()->set_bool(PP_PSHUTDOWNAFTREFINISHED, false); + GetConfig()->write(NULL); + if (bShutdown) + { + // we're killed + pData->bKilled=true; + + // adjust token privileges for NT + HANDLE hToken=NULL; + TOKEN_PRIVILEGES tp; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) + && LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tp.Privileges[0].Luid)) + { + tp.PrivilegeCount=1; + tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; + + AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, NULL, NULL); + } + + BOOL bExit=ExitWindowsEx(EWX_POWEROFF | EWX_SHUTDOWN | (GetConfig()->get_bool(PP_PFORCESHUTDOWN) ? EWX_FORCE : 0), 0); + if (bExit) + return 1; + else + { + pData->bKilled=false; + + // some kind of error + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_SHUTDOWNERROR_STRING)); + fmt.SetParam(_t("%errno"), GetLastError()); + AfxMessageBox(fmt, MB_ICONERROR | MB_OK | MB_SYSTEMMODAL); + } + } + } + } + } + else + { + bEnd=false; + lFinished=pData->m_pTasks->m_lFinished; + } + + // sleep for some time + const int iSleepCount=200; + Sleep(iSleepCount); + uiCounter+=iSleepCount; + uiShutCounter+=iSleepCount; + if (uiCounter >= (UINT)GetConfig()->get_signed_num(PP_PMONITORSCANINTERVAL)) + uiCounter=0; + if (uiShutCounter >= 800) + uiShutCounter=0; + } + + pData->bKilled=true; + TRACE("Monitoring clipboard proc aborted...\n"); + + return 0; +} + +///////////////////////////////////////////////////////////////////////////// +// CMainWnd message handlers + +int CMainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) +{ + lpCreateStruct->dwExStyle |= WS_EX_TOPMOST; + if (CWnd::OnCreate(lpCreateStruct) == -1) + return -1; + + // get msg id of taskbar created message + m_uiTaskbarRestart=RegisterWindowMessage(_T("TaskbarCreated")); + + // Create the tray icon + ShowTrayIcon(); + + // initialize CTaskArray + m_tasks.Create(m_pFeedbackFactory, &ThrdProc); + + // load last state + CString strPath; + GetApp()->GetProgramDataPath(strPath); + strPath += _T("\\tasks"); + m_tasks.SetTasksDir(strPath); + m_tasks.LoadDataProgress(); + m_tasks.TasksRetryProcessing(); + + // start clipboard monitoring + cmd.bKill=false; + cmd.bKilled=false; + cmd.m_hwnd=this->m_hWnd; + cmd.m_pTasks=&m_tasks; + + AfxBeginThread(&ClipboardMonitorProc, static_cast(&cmd), THREAD_PRIORITY_IDLE); + + // start saving timer + SetTimer(1023, (UINT)GetConfig()->get_signed_num(PP_PAUTOSAVEINTERVAL), NULL); + + SetTimer(7834, TM_AUTORESUME/*GetConfig()->GetAutoRetryInterval()*/, NULL); + SetTimer(3245, TM_AUTOREMOVE, NULL); + SetTimer(8743, TM_ACCEPTING, NULL); // ends wait state in tasks + + if (GetConfig()->get_bool(PP_MVAUTOSHOWWHENRUN)) + PostMessage(WM_SHOWMINIVIEW); + + return 0; +} + +LRESULT CMainWnd::OnTrayNotification(WPARAM wParam, LPARAM lParam) +{ + if (wParam != m_ctlTray.m_tnd.uID) + return (LRESULT)FALSE; + + TCHAR text[_MAX_PATH]; + switch(LOWORD(lParam)) + { + case WM_LBUTTONDOWN: + { + ::SetForegroundWindow(this->m_hWnd); + break; + } + case WM_LBUTTONDBLCLK: + { + CMenu mMenu, *pSubMenu; + HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_POPUP_MENU)); + if (!mMenu.Attach(hMenu)) + return (LRESULT)FALSE; + + if ((pSubMenu = mMenu.GetSubMenu(0)) == NULL) + return (LRESULT)FALSE; + + // double click received, the default action is to execute first menu item + ::SetForegroundWindow(this->m_hWnd); + ::SendMessage(this->m_hWnd, WM_COMMAND, pSubMenu->GetMenuItemID(0), 0); + + pSubMenu->DestroyMenu(); + mMenu.DestroyMenu(); + break; + } + case WM_RBUTTONUP: + { + // load main menu + HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_POPUP_MENU)); + CMenu mMenu, *pSubMenu; + if (!mMenu.Attach(hMenu)) + return (LRESULT)FALSE; + + if ((pSubMenu = mMenu.GetSubMenu(0)) == NULL) + return (LRESULT)FALSE; + + // set menu default item + pSubMenu->SetDefaultItem(0, TRUE); + + // make window foreground + SetForegroundWindow(); + + // get current cursor pos + POINT pt; + GetCursorPos(&pt); + + pSubMenu->CheckMenuItem(ID_POPUP_MONITORING, MF_BYCOMMAND | (GetConfig()->get_bool(PP_PCLIPBOARDMONITORING) ? MF_CHECKED : MF_UNCHECKED)); + pSubMenu->CheckMenuItem(ID_POPUP_SHUTAFTERFINISHED, MF_BYCOMMAND | (GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED) ? MF_CHECKED : MF_UNCHECKED)); + + // track the menu + pSubMenu->TrackPopupMenu(TPM_LEFTBUTTON, pt.x, pt.y, this); + + // destroy + pSubMenu->DestroyMenu(); + mMenu.DestroyMenu(); + + break; + } + case WM_MOUSEMOVE: + { + if (m_tasks.GetSize() != 0) + { + _sntprintf(text, _MAX_PATH, _T("%s - %d %%"), GetApp()->GetAppName(), m_tasks.GetPercent()); + m_ctlTray.SetTooltipText(text); + } + else + m_ctlTray.SetTooltipText(GetApp()->GetAppNameVer()); + break; + } + } + + return (LRESULT)TRUE; +} + +///////////////////////////////////////////////////////////////////////////// +// CMainWnd/CTrayIcon menu message handlers + +void CMainWnd::ShowStatusWindow(const CTask *pSelect) +{ + m_pdlgStatus=new CStatusDlg(&m_tasks, this); // self deleting + m_pdlgStatus->m_pInitialSelection=pSelect; + m_pdlgStatus->m_bLockInstance=true; + m_pdlgStatus->m_bAutoDelete=true; + m_pdlgStatus->Create(); + + // hide miniview if showing status + if (m_pdlgMiniView != NULL && m_pdlgMiniView->m_bLock) + { + if (::IsWindow(m_pdlgMiniView->m_hWnd)) + m_pdlgMiniView->HideWindow(); + } +} + +void CMainWnd::OnPopupShowStatus() +{ + ShowStatusWindow(); +} + +void CMainWnd::OnClose() +{ + PrepareToExit(); + CWnd::OnClose(); +} + +void CMainWnd::OnTimer(UINT_PTR nIDEvent) +{ + switch (nIDEvent) + { + case 1023: + // autosave timer + KillTimer(1023); + m_tasks.SaveProgress(); + SetTimer(1023, (UINT)GetConfig()->get_signed_num(PP_PAUTOSAVEINTERVAL), NULL); + break; + case 7834: + { + // auto-resume timer + KillTimer(7834); + DWORD dwTime=GetTickCount(); + DWORD dwInterval=(m_dwLastTime == 0) ? TM_AUTORESUME : dwTime-m_dwLastTime; + m_dwLastTime=dwTime; + + if (GetConfig()->get_bool(PP_CMAUTORETRYONERROR)) + { + if (m_tasks.TasksRetryProcessing(true, dwInterval) && m_pdlgStatus && m_pdlgStatus->m_bLock && IsWindow(m_pdlgStatus->m_hWnd)) + m_pdlgStatus->SendMessage(WM_UPDATESTATUS); + } + SetTimer(7834, TM_AUTORESUME/*GetConfig()->GetAutoRetryInterval()*/, NULL); + } + break; + case 3245: + // auto-delete finished tasks timer + KillTimer(3245); + if (GetConfig()->get_bool(PP_STATUSAUTOREMOVEFINISHED)) + { + int iSize=m_tasks.GetSize(); + m_tasks.RemoveAllFinished(); + if (m_tasks.GetSize() != iSize && m_pdlgStatus && m_pdlgStatus->m_bLock && IsWindow(m_pdlgStatus->m_hWnd)) + m_pdlgStatus->SendMessage(WM_UPDATESTATUS); + } + + SetTimer(3245, TM_AUTOREMOVE, NULL); + break; + case 8743: + { + // wait state handling section + CTask* pTask; + if (GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS) == 0 || m_tasks.GetOperationsPending() < (UINT)GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS)) + { + for (int i=0;iGetStatus(ST_WAITING_MASK) & ST_WAITING && (GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS) == 0 || m_tasks.GetOperationsPending() < (UINT)GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS))) + { + TRACE("Enabling task %ld\n", i); + pTask->SetContinueFlag(true); + pTask->IncreaseOperationsPending(); + pTask->SetStatus(0, ST_WAITING); // turn off wait state + } + } + } + break; + } + } + + CWnd::OnTimer(nIDEvent); +} + +void CMainWnd::OnPopupShowOptions() +{ + COptionsDlg *pDlg=new COptionsDlg(this); + pDlg->m_bAutoDelete=true; + pDlg->m_bLockInstance=true; + pDlg->Create(); +} + +BOOL CMainWnd::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) +{ + if(!GetApp()->IsShellExtEnabled()) + return FALSE; + + // copying or moving ? + bool bMove=false; + switch(pCopyDataStruct->dwData & OPERATION_MASK) + { + case DD_MOVE_FLAG: + case EC_MOVETO_FLAG: + bMove=true; + break; + case EC_PASTE_FLAG: + case EC_PASTESPECIAL_FLAG: + bMove=(pCopyDataStruct->dwData & ~OPERATION_MASK) != 0; + break; + } + + // buffer with: dst path and src paths separated by single '\0' + TCHAR *pBuffer=static_cast(pCopyDataStruct->lpData); + unsigned long ulLen=pCopyDataStruct->cbData / sizeof(TCHAR); + + CString str, strDstPath; + CStringArray astrFiles; + UINT iOffset=0; + + do + { + str=pBuffer+iOffset; + if (iOffset == 0) + strDstPath=str; + else + astrFiles.Add(str); + + iOffset+=str.GetLength()+1; + } + while (iOffset < ulLen); + + icpf::config* pConfig = GetConfig(); + assert(pConfig); + + // special operation - modify stuff + CFiltersArray ffFilters; + int iPriority=(int)GetConfig()->get_signed_num(PP_CMDEFAULTPRIORITY); + BUFFERSIZES bsSizes; + bsSizes.m_bOnlyDefault=GetConfig()->get_bool(PP_BFUSEONLYDEFAULT); + bsSizes.m_uiDefaultSize=(UINT)GetConfig()->get_signed_num(PP_BFDEFAULT); + bsSizes.m_uiOneDiskSize=(UINT)GetConfig()->get_signed_num(PP_BFONEDISK); + bsSizes.m_uiTwoDisksSize=(UINT)GetConfig()->get_signed_num(PP_BFTWODISKS); + bsSizes.m_uiCDSize=(UINT)GetConfig()->get_signed_num(PP_BFCD); + bsSizes.m_uiLANSize=(UINT)GetConfig()->get_signed_num(PP_BFLAN); + + BOOL bOnlyCreate=FALSE; + BOOL bIgnoreDirs=FALSE; + BOOL bForceDirectories=FALSE; + unsigned char ucCopies=1; + switch(pCopyDataStruct->dwData & OPERATION_MASK) + { + case DD_COPYMOVESPECIAL_FLAG: + case EC_PASTESPECIAL_FLAG: + case EC_COPYMOVETOSPECIAL_FLAG: + CCustomCopyDlg dlg; + dlg.m_ccData.m_astrPaths.Copy(astrFiles); + dlg.m_ccData.m_iOperation=bMove ? 1 : 0; + dlg.m_ccData.m_iPriority=iPriority; + dlg.m_ccData.m_strDestPath=strDstPath; + dlg.m_ccData.m_bsSizes=bsSizes; + dlg.m_ccData.m_bIgnoreFolders=(bIgnoreDirs != 0); + dlg.m_ccData.m_bForceDirectories=(bForceDirectories != 0); + dlg.m_ccData.m_bCreateStructure=(bOnlyCreate != 0); + dlg.m_ccData.m_ucCount=ucCopies; + + dlg.m_ccData.m_vRecent.clear(true); + const tchar_t* pszPath = NULL; + size_t stCount = pConfig->get_value_count(PP_RECENTPATHS); + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); + if(pszPath) + dlg.m_ccData.m_vRecent.push_back(pszPath); + } + + int iModalResult; + if ( (iModalResult=dlg.DoModal()) == IDCANCEL) + return CWnd::OnCopyData(pWnd, pCopyDataStruct); + else if (iModalResult == -1) // windows has been closed by a parent + return TRUE; + + astrFiles.Copy(dlg.m_ccData.m_astrPaths); + bMove=(dlg.m_ccData.m_iOperation != 0); + iPriority=dlg.m_ccData.m_iPriority; + strDstPath=dlg.m_ccData.m_strDestPath; + bsSizes=dlg.m_ccData.m_bsSizes; + ffFilters = dlg.m_ccData.m_afFilters; + bIgnoreDirs=dlg.m_ccData.m_bIgnoreFolders; + bForceDirectories=dlg.m_ccData.m_bForceDirectories; + bOnlyCreate=dlg.m_ccData.m_bCreateStructure; + ucCopies=dlg.m_ccData.m_ucCount; + dlg.m_ccData.m_vRecent.insert(dlg.m_ccData.m_vRecent.begin(), (const PTSTR)(LPCTSTR)strDstPath, true); + + pConfig->clear_array_values(PP_RECENTPATHS); + for(char_vector::iterator it = dlg.m_ccData.m_vRecent.begin(); it != dlg.m_ccData.m_vRecent.end(); it++) + { + pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); + } + } + + // create new task + CTask *pTask = m_tasks.CreateTask(); + pTask->SetDestPath(strDstPath); + CClipboardEntry* pEntry; + + // files + for (int i=0;iSetPath(astrFiles.GetAt(i)); + pEntry->CalcBufferIndex(pTask->GetDestPath()); + pTask->AddClipboardData(pEntry); + } + + pTask->SetStatus(bMove ? ST_MOVE : ST_COPY, ST_OPERATION_MASK); + + // special status + pTask->SetStatus((bOnlyCreate ? ST_IGNORE_CONTENT : 0) | (bIgnoreDirs ? ST_IGNORE_DIRS : 0) | (bForceDirectories ? ST_FORCE_DIRS : 0), ST_SPECIAL_MASK); + + // set some stuff related with task + pTask->SetBufferSizes(&bsSizes); + pTask->SetPriority(iPriority); + pTask->SetFilters(&ffFilters); + pTask->SetCopies(ucCopies); + + m_tasks.Add(pTask); + + // save state of a task + pTask->Store(true); + pTask->Store(false); + + // add to task list and start processing + pTask->BeginProcessing(); + + return CWnd::OnCopyData(pWnd, pCopyDataStruct); +} + +void CMainWnd::OnShowMiniView() +{ + m_pdlgMiniView=new CMiniViewDlg(&m_tasks, &CStatusDlg::m_bLock, this); // self-deleting + m_pdlgMiniView->m_bAutoDelete=true; + m_pdlgMiniView->m_bLockInstance=true; + m_pdlgMiniView->Create(); +} + +void CMainWnd::OnPopupCustomCopy() +{ + icpf::config* pConfig = GetConfig(); + assert(pConfig); + if(!pConfig) + return; + + CCustomCopyDlg dlg; + dlg.m_ccData.m_iOperation=0; + dlg.m_ccData.m_iPriority=(int)pConfig->get_signed_num(PP_CMDEFAULTPRIORITY); + dlg.m_ccData.m_bsSizes.m_bOnlyDefault=pConfig->get_bool(PP_BFUSEONLYDEFAULT); + dlg.m_ccData.m_bsSizes.m_uiDefaultSize=(UINT)pConfig->get_signed_num(PP_BFDEFAULT); + dlg.m_ccData.m_bsSizes.m_uiOneDiskSize=(UINT)pConfig->get_signed_num(PP_BFONEDISK); + dlg.m_ccData.m_bsSizes.m_uiTwoDisksSize=(UINT)pConfig->get_signed_num(PP_BFTWODISKS); + dlg.m_ccData.m_bsSizes.m_uiCDSize=(UINT)pConfig->get_signed_num(PP_BFCD); + dlg.m_ccData.m_bsSizes.m_uiLANSize=(UINT)pConfig->get_signed_num(PP_BFLAN); + + dlg.m_ccData.m_bCreateStructure=false; + dlg.m_ccData.m_bForceDirectories=false; + dlg.m_ccData.m_bIgnoreFolders=false; + dlg.m_ccData.m_ucCount=1; + + dlg.m_ccData.m_vRecent.clear(true); + const tchar_t* pszPath = NULL; + size_t stCount = pConfig->get_value_count(PP_RECENTPATHS); + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); + if(pszPath) + dlg.m_ccData.m_vRecent.push_back(pszPath); + } + + if (dlg.DoModal() == IDOK) + { + // save recent paths + dlg.m_ccData.m_vRecent.push_back((PCTSTR)dlg.m_ccData.m_strDestPath); + + pConfig->clear_array_values(PP_RECENTPATHS); + for(char_vector::iterator it = dlg.m_ccData.m_vRecent.begin(); it != dlg.m_ccData.m_vRecent.end(); it++) + { + pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); + } + + // new task + CTask *pTask = m_tasks.CreateTask(); + pTask->SetDestPath(dlg.m_ccData.m_strDestPath); + CClipboardEntry *pEntry; + for (int i=0;iSetPath(dlg.m_ccData.m_astrPaths.GetAt(i)); + pEntry->CalcBufferIndex(pTask->GetDestPath()); + pTask->AddClipboardData(pEntry); + } + + pTask->SetStatus((dlg.m_ccData.m_iOperation == 1) ? ST_MOVE : ST_COPY, ST_OPERATION_MASK); + + // special status + pTask->SetStatus((dlg.m_ccData.m_bCreateStructure ? ST_IGNORE_CONTENT : 0) | (dlg.m_ccData.m_bIgnoreFolders ? ST_IGNORE_DIRS : 0) + | (dlg.m_ccData.m_bForceDirectories ? ST_FORCE_DIRS : 0), ST_SPECIAL_MASK); + + pTask->SetBufferSizes(&dlg.m_ccData.m_bsSizes); + pTask->SetPriority(dlg.m_ccData.m_iPriority); + pTask->SetFilters(&dlg.m_ccData.m_afFilters); + + m_tasks.Add(pTask); + + // save + pTask->Store(true); + pTask->Store(false); + + // store and start + pTask->BeginProcessing(); + } +} + +LRESULT CMainWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_MINIVIEWDBLCLK: + { + ShowStatusWindow((CTask*)lParam); + break; + } + case WM_SHOWMINIVIEW: + { + OnShowMiniView(); + return static_cast(0); + break; + } + + case WM_CONFIGNOTIFY: + { + GetApp()->SetAutorun(GetConfig()->get_bool(PP_PRELOADAFTERRESTART)); + + // set this process class + HANDLE hProcess=GetCurrentProcess(); + ::SetPriorityClass(hProcess, (DWORD)GetConfig()->get_signed_num(PP_PPROCESSPRIORITYCLASS)); + + break; + } + + case WM_GETCONFIG: + { + icpf::config* pConfig = GetConfig(); + assert(pConfig); + + // std config values + g_pscsShared->bShowFreeSpace=pConfig->get_bool(PP_SHSHOWFREESPACE); + + // experimental - doesn't work on all systems + g_pscsShared->bShowShortcutIcons=pConfig->get_bool(PP_SHSHOWSHELLICONS); + g_pscsShared->bOverrideDefault=pConfig->get_bool(PP_SHUSEDRAGDROP); // only for d&d + g_pscsShared->uiDefaultAction=(UINT)pConfig->get_signed_num(PP_SHDEFAULTACTION); + + // sizes + for (int i=0;i<6;i++) + _tcscpy(g_pscsShared->szSizes[i], GetResManager()->LoadString(IDS_BYTE_STRING+i)); + + // convert to list of _COMMAND's + _COMMAND *pCommand = g_pscsShared->GetCommandsPtr(); + + // what kind of menu ? + switch (wParam) + { + case GC_DRAGDROP: + { + g_pscsShared->iCommandCount=3; + g_pscsShared->iShortcutsCount=0; + g_pscsShared->uiFlags=(pConfig->get_bool(PP_SHSHOWCOPY) ? DD_COPY_FLAG : 0) + | (pConfig->get_bool(PP_SHSHOWMOVE) ? DD_MOVE_FLAG : 0) + | (pConfig->get_bool(PP_SHSHOWCOPYMOVE) ? DD_COPYMOVESPECIAL_FLAG : 0); + + pCommand[0].uiCommandID=DD_COPY_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUCOPY_STRING, pCommand[0].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPCOPY_STRING, pCommand[0].szDesc, 128); + + pCommand[1].uiCommandID=DD_MOVE_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUMOVE_STRING, pCommand[1].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPMOVE_STRING, pCommand[1].szDesc, 128); + + pCommand[2].uiCommandID=DD_COPYMOVESPECIAL_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUCOPYMOVESPECIAL_STRING, pCommand[2].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPCOPYMOVESPECIAL_STRING, pCommand[2].szDesc, 128); + } + break; + case GC_EXPLORER: + { + g_pscsShared->iCommandCount=5; + g_pscsShared->uiFlags=(pConfig->get_bool(PP_SHSHOWPASTE) ? EC_PASTE_FLAG : 0) + | (pConfig->get_bool(PP_SHSHOWPASTESPECIAL) ? EC_PASTESPECIAL_FLAG : 0) + | (pConfig->get_bool(PP_SHSHOWCOPYTO) ? EC_COPYTO_FLAG : 0) + | (pConfig->get_bool(PP_SHSHOWMOVETO) ? EC_MOVETO_FLAG : 0) + | (pConfig->get_bool(PP_SHSHOWCOPYMOVETO) ? EC_COPYMOVETOSPECIAL_FLAG : 0); + + pCommand[0].uiCommandID=EC_PASTE_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUPASTE_STRING, pCommand[0].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPPASTE_STRING, pCommand[0].szDesc, 128); + pCommand[1].uiCommandID=EC_PASTESPECIAL_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUPASTESPECIAL_STRING, pCommand[1].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPPASTESPECIAL_STRING, pCommand[1].szDesc, 128); + pCommand[2].uiCommandID=EC_COPYTO_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUCOPYTO_STRING, pCommand[2].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPCOPYTO_STRING, pCommand[2].szDesc, 128); + pCommand[3].uiCommandID=EC_MOVETO_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUMOVETO_STRING, pCommand[3].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPMOVETO_STRING, pCommand[3].szDesc, 128); + pCommand[4].uiCommandID=EC_COPYMOVETOSPECIAL_FLAG; + GetResManager()->LoadStringCopy(IDS_MENUCOPYMOVETOSPECIAL_STRING, pCommand[4].szCommand, 128); + GetResManager()->LoadStringCopy(IDS_MENUTIPCOPYMOVETOSPECIAL_STRING, pCommand[4].szDesc, 128); + + // prepare shortcuts + char_vector cvShortcuts; + const tchar_t* pszPath = NULL; + size_t stCount = pConfig->get_value_count(PP_SHORTCUTS); + for(size_t stIndex = 0; stIndex < stCount; stIndex++) + { + pszPath = pConfig->get_string(PP_SHORTCUTS, stIndex); + if(pszPath) + cvShortcuts.push_back(pszPath); + } + + // count of shortcuts to store + g_pscsShared->iShortcutsCount=__min(cvShortcuts.size(), (SHARED_BUFFERSIZE - 5 * sizeof(_COMMAND)) / sizeof(_SHORTCUT)); + _SHORTCUT* pShortcut = g_pscsShared->GetShortcutsPtr(); + CShortcut sc; + for (int i=0;iiShortcutsCount;i++) + { + sc=CString(cvShortcuts.at(i)); + _tcsncpy(pShortcut[i].szName, sc.m_strName, 128); + _tcsncpy(pShortcut[i].szPath, sc.m_strPath, _MAX_PATH); + } + } + break; + default: + ASSERT(false); // what's happening ? + } + } + break; + + case WM_IDENTIFY: + { + //decode + unsigned char *dec=new unsigned char[iCount+1]; + dec[iCount]=0; + + unsigned short sData; + for (int i=0, j=0;i(msg[i] - _hash[j]); + + sData >>= off[j]; + dec[i]=static_cast(sData); + + if (++j >= iOffCount) + j=0; + } + + CA2T ca2t(reinterpret_cast(dec)); + AfxMessageBox(ca2t); + delete [] dec; + + break; + } + case WM_STATUSCLOSING: + { + if (m_pdlgMiniView != NULL && m_pdlgMiniView->m_bLock && ::IsWindow(m_pdlgMiniView->m_hWnd)) + m_pdlgMiniView->RefreshStatus(); + + break; + } + case WM_ENDSESSION: + { + PrepareToExit(); + break; + } + case WM_TRAYNOTIFY: + { + return OnTrayNotification(wParam, lParam); + break; + } + } + + // if this is a notification of new tray - recreate the icon + if (message == m_uiTaskbarRestart) + { + ShowTrayIcon(); + return (LRESULT)TRUE; + } + + return CWnd::WindowProc(message, wParam, lParam); +} + +void CMainWnd::OnAppAbout() +{ + CAboutDlg *pdlg=new CAboutDlg; + pdlg->m_bAutoDelete=true; + pdlg->m_bLockInstance=true; + pdlg->Create(); +} + +void CMainWnd::OnPopupMonitoring() +{ + // change flag in config + GetConfig()->set_bool(PP_PCLIPBOARDMONITORING, !GetConfig()->get_bool(PP_PCLIPBOARDMONITORING)); + GetConfig()->write(NULL); +} + +void CMainWnd::OnPopupShutafterfinished() +{ + GetConfig()->set_bool(PP_PSHUTDOWNAFTREFINISHED, !GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED)); + GetConfig()->write(NULL); +} + +void CMainWnd::OnPopupRegisterdll() +{ + CString strPath; + CCopyHandlerApp* pApp = GetApp(); + if(pApp) + { + strPath = pApp->GetProgramPath(); + strPath += _T("\\"); + } + +#ifdef _WIN64 + strPath += _T("chext64.dll"); +#else + strPath += _T("chext.dll"); +#endif + HRESULT hResult = RegisterShellExtDll(strPath, true); + if(FAILED(hResult)) + { + TCHAR szStr[256]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL); + while (szStr[_tcslen(szStr)-1] == _T('\n') || szStr[_tcslen(szStr)-1] == _T('\r') || szStr[_tcslen(szStr)-1] == _T('.')) + szStr[_tcslen(szStr)-1]=_T('\0'); + + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_REGISTERERR_STRING)); + fmt.SetParam(_T("%errno"), (ulong_t)hResult); + fmt.SetParam(_T("%errdesc"), szStr); + AfxMessageBox(fmt, MB_ICONERROR | MB_OK); + } + else if(hResult == S_OK) + MsgBox(IDS_REGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); +} + +void CMainWnd::OnPopupUnregisterdll() +{ + CString strPath; + CCopyHandlerApp* pApp = GetApp(); + if(pApp) + { + strPath = pApp->GetProgramPath(); + strPath += _T("\\"); + } + +#ifdef _WIN64 + strPath += _T("chext64.dll"); +#else + strPath += _T("chext.dll"); +#endif + + HRESULT hResult = RegisterShellExtDll(strPath, false); + if(FAILED(hResult)) + { + TCHAR szStr[256]; + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hResult, 0, szStr, 256, NULL); + while (szStr[_tcslen(szStr)-1] == _T('\n') || szStr[_tcslen(szStr)-1] == _T('\r') || szStr[_tcslen(szStr)-1] == _T('.')) + szStr[_tcslen(szStr)-1]=_T('\0'); + + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_UNREGISTERERR_STRING)); + fmt.SetParam(_T("%errno"), (ulong_t)hResult); + fmt.SetParam(_T("%errdesc"), szStr); + + AfxMessageBox(fmt, MB_ICONERROR | MB_OK); + } + else if(hResult == S_OK) + MsgBox(IDS_UNREGISTEROK_STRING, MB_ICONINFORMATION | MB_OK); +} + +void CMainWnd::PrepareToExit() +{ + // kill thread that monitors clipboard + cmd.bKill=true; + while (!cmd.bKilled) + Sleep(10); + + // kill all unfinished tasks - send kill request + for (int i=0;iSetKillFlag(); + + // wait for finishing + for (int i=0;iGetKilledFlag()) + Sleep(10); + m_tasks.GetAt(i)->CleanupAfterKill(); + } + + // save + m_tasks.SaveProgress(); + + // delete all tasks + int iSize=m_tasks.GetSize(); + for (int i=0;i* >(&m_tasks))->RemoveAll(); +} + +void CMainWnd::OnAppExit() +{ + PostMessage(WM_CLOSE); +} + +void CMainWnd::OnPopupHelp() +{ + GetApp()->HtmlHelp(HH_DISPLAY_TOPIC, NULL); +} + +void CMainWnd::OnPopupCheckForUpdates() +{ + CUpdaterDlg* pDlg = new CUpdaterDlg; + pDlg->m_bAutoDelete = true; + + pDlg->Create(); +} Index: src/ch/MainWnd.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/MainWnd.h (.../MainWnd.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/MainWnd.h (.../MainWnd.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,112 +1,112 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ - -#ifndef __MAINFRM_H__ -#define __MAINFRM_H__ - -#include "TrayIcon.h" -#include "structs.h" -#include "MiniviewDlg.h" -#include "DataBuffer.h" -#include "StatusDlg.h" -#include "FeedbackHandler.h" - -typedef struct _CUSTOM_COPY_PARAMS -{ - CTask* pTask; // ptr to CTask object on which we do the operation - - CFileInfo* pfiSrcFile; // CFileInfo - src file - CString strDstFile; // dest path with filename - - CDataBuffer dbBuffer; // buffer handling - bool bOnlyCreate; // flag from configuration - skips real copying - only create - bool bProcessed; // has the element been processed ? (false if skipped) -} CUSTOM_COPY_PARAMS, *PCUSTOM_COPY_PARAMS; - -class CMainWnd : public CWnd -{ -public: - CMainWnd(); - DECLARE_DYNCREATE(CMainWnd) - - BOOL Create(); - -// Attributes -public: - CTrayIcon m_ctlTray; - CLIPBOARDMONITORDATA cmd; - - CTaskArray m_tasks; - chcore::IFeedbackHandlerFactory* m_pFeedbackFactory; - - CMiniViewDlg* m_pdlgMiniView; - CStatusDlg* m_pdlgStatus; - - DWORD m_dwLastTime; - UINT m_uiTaskbarRestart; - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CMainFrame) - protected: - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CMainWnd(); - -// Generated message map functions -protected: - ATOM RegisterClass(); - int ShowTrayIcon(); - void ShowStatusWindow(const CTask* pSelect=NULL); - void PrepareToExit(); - //{{AFX_MSG(CMainWnd) - afx_msg void OnPopupShowStatus(); - afx_msg void OnPopupShowOptions(); - afx_msg void OnClose(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct); - afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - afx_msg void OnShowMiniView(); - afx_msg void OnPopupCustomCopy(); - afx_msg void OnAppAbout(); - afx_msg void OnPopupMonitoring(); - afx_msg void OnPopupShutafterfinished(); - afx_msg void OnPopupRegisterdll(); - afx_msg void OnPopupUnregisterdll(); - afx_msg void OnAppExit(); - afx_msg void OnPopupHelp(); - //}}AFX_MSG - afx_msg LRESULT OnTrayNotification(WPARAM wParam, LPARAM lParam); - DECLARE_MESSAGE_MAP() -public: - afx_msg void OnPopupCheckForUpdates(); -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ + +#ifndef __MAINFRM_H__ +#define __MAINFRM_H__ + +#include "TrayIcon.h" +#include "structs.h" +#include "MiniviewDlg.h" +#include "DataBuffer.h" +#include "StatusDlg.h" +#include "FeedbackHandler.h" + +typedef struct _CUSTOM_COPY_PARAMS +{ + CTask* pTask; // ptr to CTask object on which we do the operation + + CFileInfo* pfiSrcFile; // CFileInfo - src file + CString strDstFile; // dest path with filename + + CDataBuffer dbBuffer; // buffer handling + bool bOnlyCreate; // flag from configuration - skips real copying - only create + bool bProcessed; // has the element been processed ? (false if skipped) +} CUSTOM_COPY_PARAMS, *PCUSTOM_COPY_PARAMS; + +class CMainWnd : public CWnd +{ +public: + CMainWnd(); + DECLARE_DYNCREATE(CMainWnd) + + BOOL Create(); + +// Attributes +public: + CTrayIcon m_ctlTray; + CLIPBOARDMONITORDATA cmd; + + CTaskArray m_tasks; + chcore::IFeedbackHandlerFactory* m_pFeedbackFactory; + + CMiniViewDlg* m_pdlgMiniView; + CStatusDlg* m_pdlgStatus; + + DWORD m_dwLastTime; + UINT m_uiTaskbarRestart; + +// Operations +public: + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CMainFrame) + protected: + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + //}}AFX_VIRTUAL + +// Implementation +public: + virtual ~CMainWnd(); + +// Generated message map functions +protected: + ATOM RegisterClass(); + int ShowTrayIcon(); + void ShowStatusWindow(const CTask* pSelect=NULL); + void PrepareToExit(); + //{{AFX_MSG(CMainWnd) + afx_msg void OnPopupShowStatus(); + afx_msg void OnPopupShowOptions(); + afx_msg void OnClose(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct); + afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + afx_msg void OnShowMiniView(); + afx_msg void OnPopupCustomCopy(); + afx_msg void OnAppAbout(); + afx_msg void OnPopupMonitoring(); + afx_msg void OnPopupShutafterfinished(); + afx_msg void OnPopupRegisterdll(); + afx_msg void OnPopupUnregisterdll(); + afx_msg void OnAppExit(); + afx_msg void OnPopupHelp(); + //}}AFX_MSG + afx_msg LRESULT OnTrayNotification(WPARAM wParam, LPARAM lParam); + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnPopupCheckForUpdates(); +}; + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Developer Studio will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/MemDC.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/MemDC.h (.../MemDC.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/MemDC.h (.../MemDC.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,106 +1,106 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/////////////////////////////////////////////////////////////// -// CMemDC - memory DC -// -// Author: Keith Rule -// Email: keithr@europa.com -// Copyright 1996-1997, Keith Rule -// -// You may freely use or modify this code provided this -// Copyright is included in all derived versions. -// -/////////////////////////////////////////////////////////////// -#ifndef _MEMDC_H_ -#define _MEMDC_H_ - -/////////////////////////////////////////////////////////////// -// BCMenuMemDC - memory DC -// -// Author: Keith Rule -// Email: keithr@europa.com -// Copyright 1996-1997, Keith Rule -// -// You may freely use or modify this code provided this -// Copyright is included in all derived versions. -// -// History - 10/3/97 Fixed scrolling bug. -// Added print support. -// 25 feb 98 - fixed minor assertion bug -// -// This class implements a memory Device Context -/////////////////////////////////////////////////////////////// -class CMemDC : public CDC -{ -public: - - // constructor sets up the memory DC - CMemDC(CDC* pDC, LPCRECT lpSrcRect) : CDC() - { - ASSERT(pDC != NULL); - if(!pDC) - return; - m_rect.CopyRect(lpSrcRect); - m_pDC = pDC; - m_pOldBitmap = NULL; - m_bMemDC = !pDC->IsPrinting(); - - if (m_bMemDC) // Create a Memory DC - { - CreateCompatibleDC(pDC); - m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); - m_pOldBitmap = SelectObject(&m_bitmap); - SetWindowOrg(m_rect.left, m_rect.top); - } - else // Make a copy of the relevent parts of the current DC for printing - { - m_bPrinting = pDC->m_bPrinting; - m_hDC = pDC->m_hDC; - m_hAttribDC = pDC->m_hAttribDC; - } - } - - // Destructor copies the contents of the mem DC to the original DC - ~CMemDC() - { - if (m_bMemDC) - { - // Copy the offscreen bitmap onto the screen. - m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), - this, m_rect.left, m_rect.top, SRCCOPY); - - //Swap back the original bitmap. - SelectObject(m_pOldBitmap); - } else { - // All we need to do is replace the DC with an illegal value, - // this keeps us from accidently deleting the handles associated with - // the CDC that was passed to the constructor. - m_hDC = m_hAttribDC = NULL; - } - } - -private: - CBitmap m_bitmap; // Offscreen bitmap - CBitmap* m_pOldBitmap; // bitmap originally found in BCMenuMemDC - CDC* m_pDC; // Saves CDC passed in constructor - CRect m_rect; // Rectangle of drawing area. - BOOL m_bMemDC; // TRUE if CDC really is a Memory DC. -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +/////////////////////////////////////////////////////////////// +// CMemDC - memory DC +// +// Author: Keith Rule +// Email: keithr@europa.com +// Copyright 1996-1997, Keith Rule +// +// You may freely use or modify this code provided this +// Copyright is included in all derived versions. +// +/////////////////////////////////////////////////////////////// +#ifndef _MEMDC_H_ +#define _MEMDC_H_ + +/////////////////////////////////////////////////////////////// +// BCMenuMemDC - memory DC +// +// Author: Keith Rule +// Email: keithr@europa.com +// Copyright 1996-1997, Keith Rule +// +// You may freely use or modify this code provided this +// Copyright is included in all derived versions. +// +// History - 10/3/97 Fixed scrolling bug. +// Added print support. +// 25 feb 98 - fixed minor assertion bug +// +// This class implements a memory Device Context +/////////////////////////////////////////////////////////////// +class CMemDC : public CDC +{ +public: + + // constructor sets up the memory DC + CMemDC(CDC* pDC, LPCRECT lpSrcRect) : CDC() + { + ASSERT(pDC != NULL); + if(!pDC) + return; + m_rect.CopyRect(lpSrcRect); + m_pDC = pDC; + m_pOldBitmap = NULL; + m_bMemDC = !pDC->IsPrinting(); + + if (m_bMemDC) // Create a Memory DC + { + CreateCompatibleDC(pDC); + m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); + m_pOldBitmap = SelectObject(&m_bitmap); + SetWindowOrg(m_rect.left, m_rect.top); + } + else // Make a copy of the relevent parts of the current DC for printing + { + m_bPrinting = pDC->m_bPrinting; + m_hDC = pDC->m_hDC; + m_hAttribDC = pDC->m_hAttribDC; + } + } + + // Destructor copies the contents of the mem DC to the original DC + ~CMemDC() + { + if (m_bMemDC) + { + // Copy the offscreen bitmap onto the screen. + m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), + this, m_rect.left, m_rect.top, SRCCOPY); + + //Swap back the original bitmap. + SelectObject(m_pOldBitmap); + } else { + // All we need to do is replace the DC with an illegal value, + // this keeps us from accidently deleting the handles associated with + // the CDC that was passed to the constructor. + m_hDC = m_hAttribDC = NULL; + } + } + +private: + CBitmap m_bitmap; // Offscreen bitmap + CBitmap* m_pOldBitmap; // bitmap originally found in BCMenuMemDC + CDC* m_pDC; // Saves CDC passed in constructor + CRect m_rect; // Rectangle of drawing area. + BOOL m_bMemDC; // TRUE if CDC really is a Memory DC. +}; + #endif \ No newline at end of file Index: src/ch/MiniViewDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/MiniViewDlg.cpp (.../MiniViewDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/MiniViewDlg.cpp (.../MiniViewDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,809 +1,809 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "MiniViewDlg.h" -#include "ch.h" -#include - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -#define WM_INITDATA WM_USER+5 - -static const int sg_iMargin=7; - -#define ROUND(val) ( ( (val)-static_cast(val) > 0.5 ) ? static_cast(val)+1 : static_cast(val) ) -#undef ROUNDUP // from other module -#define ROUNDUP(val, to) ( (static_cast((val)/(to))+1 )*(to) ) - -bool CMiniViewDlg::m_bLock=false; - -///////////////////////////////////////////////////////////////////////////// -// CMiniViewDlg dialog - -CMiniViewDlg::CMiniViewDlg(CTaskArray* pArray, bool *pbHide, CWnd* pParent /*=NULL*/) - :ictranslate::CLanguageDialog(CMiniViewDlg::IDD, pParent, &m_bLock) -{ - //{{AFX_DATA_INIT(CMiniViewDlg) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT - - m_brBackground.CreateSolidBrush(GetSysColor(COLOR_3DFACE)); - m_iLastHeight=0; - m_bShown=false; - m_pTasks=pArray; - m_bActive=false; - m_iIndex=-1; - m_pbHide=pbHide; -} - - -void CMiniViewDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CMiniViewDlg) - DDX_Control(pDX, IDC_PROGRESS_LIST, m_ctlStatus); - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(CMiniViewDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CMiniViewDlg) - ON_WM_CTLCOLOR() - ON_WM_TIMER() - ON_LBN_SELCHANGE(IDC_PROGRESS_LIST, OnSelchangeProgressList) - ON_WM_NCLBUTTONDOWN() - ON_WM_LBUTTONUP() - ON_WM_NCPAINT() - ON_WM_NCACTIVATE() - ON_LBN_SETFOCUS(IDC_PROGRESS_LIST, OnSetfocusProgressList) - ON_LBN_SELCANCEL(IDC_PROGRESS_LIST, OnSelcancelProgressList) - ON_WM_MOUSEMOVE() - ON_WM_SETTINGCHANGE() - ON_LBN_DBLCLK(IDC_PROGRESS_LIST, OnDblclkProgressList) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CMiniViewDlg message handlers - -HBRUSH CMiniViewDlg::OnCtlColor(CDC*, CWnd*, UINT) -{ - return m_brBackground; -} - -BOOL CMiniViewDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // fill the buttons' structure - m_bdButtons[0].pfnCallbackFunc=&OnPause; - m_bdButtons[0].iPosition=4; - m_bdButtons[0].bPressed=false; - m_bdButtons[0].bEnabled=false; - m_bdButtons[1].pfnCallbackFunc=&OnResume; - m_bdButtons[1].iPosition=3; - m_bdButtons[1].bPressed=false; - m_bdButtons[1].bEnabled=false; - m_bdButtons[2].pfnCallbackFunc=&OnCancelBtn; - m_bdButtons[2].iPosition=2; - m_bdButtons[2].bPressed=false; - m_bdButtons[2].bEnabled=false; - m_bdButtons[3].pfnCallbackFunc=&OnRestartBtn; - m_bdButtons[3].iPosition=1; - m_bdButtons[3].bPressed=false; - m_bdButtons[3].bEnabled=false; - m_bdButtons[4].pfnCallbackFunc=&OnCloseBtn; - m_bdButtons[4].iPosition=0; - m_bdButtons[4].bPressed=false; - m_bdButtons[4].bEnabled=true; - - ResizeDialog(); - PostMessage(WM_INITDATA); - - return TRUE; -} - -void CMiniViewDlg::OnTimer(UINT_PTR nIDEvent) -{ - if (nIDEvent == 9843) - { - KillTimer(9843); - - RefreshStatus(); - - SetTimer(9843, GetConfig()->get_signed_num(PP_MVREFRESHINTERVAL), NULL); - } - - CLanguageDialog::OnTimer(nIDEvent); -} - -void CMiniViewDlg::RecalcSize(int nHeight, bool bInitial) -{ - // set listbox size - CRect rcList; - m_ctlStatus.GetClientRect(&rcList); - - if (nHeight == 0) - nHeight=rcList.Height(); - - // don't do anything if height doesn't changed - if (nHeight == m_iLastHeight && !bInitial) - return; - - // remember height - m_iLastHeight = nHeight; - - // size of a dialog and screen - CRect rCLanguageDialog, rcScreen; - GetWindowRect(&rCLanguageDialog); - SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0); - - // place listbox in the best place - m_ctlStatus.SetWindowPos(NULL, sg_iMargin, 0/*sg_iMargin*/, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - - int iWidth=rcList.Width()+2*sg_iMargin+2*GetSystemMetrics(SM_CXDLGFRAME); - int iHeight=rcList.Height()+1*sg_iMargin+2*GetSystemMetrics(SM_CYDLGFRAME)+GetSystemMetrics(SM_CYSMCAPTION); - - if (bInitial || (rCLanguageDialog.left == rcScreen.right-rCLanguageDialog.Width() - && rCLanguageDialog.top == rcScreen.bottom-rCLanguageDialog.Height()) ) - { - SetWindowPos(&wndTopMost, rcScreen.right-iWidth, rcScreen.bottom-iHeight, iWidth, iHeight, - 0); - } - else - SetWindowPos(&wndTopMost, 0, 0, iWidth, iHeight, SWP_NOMOVE); -} - -void CMiniViewDlg::RefreshStatus() -{ - int index=0; - _PROGRESSITEM_* pItem=NULL; - - if (GetConfig()->get_bool(PP_MVSHOWSINGLETASKS)) - { - for (int i=0;iGetSize();i++) - { - CTask* pTask=m_pTasks->GetAt(i); - pTask->GetMiniSnapshot(&dd); - - if ((dd.m_uiStatus & ST_STEP_MASK) != ST_FINISHED && (dd.m_uiStatus & ST_STEP_MASK) != ST_CANCELLED) - { - pItem=m_ctlStatus.GetItemAddress(index++); - - // load - if ((dd.m_uiStatus & ST_WORKING_MASK) == ST_ERROR) - pItem->m_crColor=RGB(255, 0, 0); - else if ((dd.m_uiStatus & ST_WORKING_MASK) == ST_PAUSED) - pItem->m_crColor=RGB(255, 255, 0); - else if ((dd.m_uiStatus & ST_WAITING_MASK) == ST_WAITING) - pItem->m_crColor=RGB(50, 50, 50); - else - pItem->m_crColor=RGB(0, 255, 0); - - pItem->m_strText=dd.m_fi.GetFileName(); - pItem->m_uiPos=dd.m_nPercent; - pItem->m_pTask=pTask; - } - } - } - - // should we show ? - bool bInitial=false; - if (index == 0) - { - if (m_bShown) - { - if (GetConfig()->get_bool(PP_MVAUTOHIDEWHENEMPTY) || *m_pbHide) - HideWindow(); - } - else if (!GetConfig()->get_bool(PP_MVAUTOHIDEWHENEMPTY) && !(*m_pbHide)) - { - // need to be visible - ShowWindow(); - bInitial=true; - } - } - else - { - if (!m_bShown) - { - if (!(*m_pbHide)) - { - ShowWindow(); - bInitial=true; - } - } - else - { - if (*m_pbHide) - HideWindow(); - } - } - - // add all state - pItem=m_ctlStatus.GetItemAddress(index++); - pItem->m_crColor=GetSysColor(COLOR_HIGHLIGHT); - pItem->m_strText=GetResManager()->LoadString(IDS_MINIVIEWALL_STRING); - pItem->m_uiPos=m_pTasks->GetPercent(); - pItem->m_pTask=NULL; - - // get rid of the rest - m_ctlStatus.SetSmoothProgress(GetConfig()->get_bool(PP_MVUSESMOOTHPROGRESS)); - m_ctlStatus.UpdateItems(index, true); - - m_ctlStatus.SetShowCaptions(GetConfig()->get_bool(PP_MVSHOWFILENAMES)); - - // calc size - RecalcSize(0, bInitial); -} - -LRESULT CMiniViewDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - if (message == WM_INITDATA) - { - // listbox with progress pseudocontrols - m_ctlStatus.Init(); - - // refresh - RefreshStatus(); - - // set refresh timer - SetTimer(9843, GetConfig()->get_signed_num(PP_MVREFRESHINTERVAL), NULL); - - return static_cast(0); - } - - return ictranslate::CLanguageDialog::WindowProc(message, wParam, lParam); -} - -void CMiniViewDlg::OnNcPaint() -{ - int iCXBorder=GetSystemMetrics(SM_CXBORDER); - int iCYBorder=GetSystemMetrics(SM_CYBORDER); - int iWidth=GetSystemMetrics(SM_CXSMSIZE); - int iHeight=GetSystemMetrics(SM_CYSMSIZE); - int iFrameHeight=GetSystemMetrics(SM_CYDLGFRAME); - int iFrameWidth=GetSystemMetrics(SM_CXDLGFRAME); - bool bEnabled=(m_ctlStatus.GetCurSel() != LB_ERR); - - // NC coordinates - CRect rcWindow; - GetWindowRect(&rcWindow); - rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top); - - // device context - CWindowDC ncdc(this); - - // frame - ncdc.DrawEdge(&rcWindow, EDGE_RAISED, BF_RECT); - rcWindow.DeflateRect(iFrameWidth-iCXBorder, iFrameHeight-iCYBorder, iFrameWidth-iCXBorder, iFrameHeight-iCYBorder); - - CPen pen, pen2; - pen.CreatePen(PS_SOLID, iCXBorder, GetSysColor(COLOR_3DFACE)); - pen2.CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE)); - - ncdc.SelectObject(&pen); - ncdc.SelectStockObject(NULL_BRUSH); - - ncdc.Rectangle(&rcWindow); - - // caption bar - rcWindow.DeflateRect(iCXBorder, iCXBorder, iCXBorder, 0); - rcWindow.bottom=rcWindow.top+iHeight; // caption pos - - // additional horz bar - ncdc.SelectObject(&pen2); - ncdc.MoveTo(rcWindow.left, rcWindow.bottom); - ncdc.LineTo(rcWindow.right, rcWindow.bottom); - - // memdc - CMemDC dc(&ncdc, &rcWindow); - - COLORREF crLeft=GetSysColor(m_bActive ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION); - dc.FillSolidRect(&rcWindow, crLeft); - - // caption text - CString strWindow; - GetWindowText(strWindow); -// TRACE("DRAWING TEXT: "+strWindow+"\n"); - - rcWindow.DeflateRect(5, 0, BTN_COUNT*iWidth+iFrameWidth+5, 0); - - // caption font - NONCLIENTMETRICS ncm; - memset(&ncm, 0, sizeof(NONCLIENTMETRICS)); - ncm.cbSize=sizeof(NONCLIENTMETRICS); - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0); - - CFont font; - font.CreateFontIndirect(&ncm.lfSmCaptionFont); - dc.SelectObject(&font); - - dc.SetTextColor(GetSysColor(COLOR_CAPTIONTEXT)); - dc.SetBkMode(TRANSPARENT); - dc.DrawText(strWindow, &rcWindow, DT_END_ELLIPSIS | DT_VCENTER | DT_LEFT | DT_NOCLIP | DT_SINGLELINE); - // button drawing - GetClientRect(&rcWindow); - - for (int i=0;ircButton; - rcCopy.DeflateRect(2,2,2,2); - - // frame drawing - if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); - else - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); - - // fill the background - rcCopy.DeflateRect(1, 1, 1, 1); - pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); - - // pause - CPen pen; - int iPenWidth=rcCopy.Width()/10+1; - pen.CreatePen(PS_SOLID, iPenWidth, pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); - CPen* pOld=pDC->SelectObject(&pen); - - int iOffset=rcCopy.Width()/3; - pDC->MoveTo(rcCopy.left+iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.top+1*iPenWidth+pData->bPressed); - pDC->LineTo(rcCopy.left+iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.bottom-ROUND(1.5*iPenWidth)+pData->bPressed); - pDC->MoveTo(rcCopy.right-iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.top+1*iPenWidth+pData->bPressed); - pDC->LineTo(rcCopy.right-iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.bottom-ROUND(1.5*iPenWidth)+pData->bPressed); - - pDC->SelectObject(pOld); - break; - } - case MSG_ONCLICK: - int iSel=pDlg->m_ctlStatus.GetCurSel(); - if (iSel == LB_ERR) - return; - CTask* pTask; - if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) - pTask->PauseProcessing(); - else - pDlg->m_pTasks->TasksPauseProcessing(); - - break; - } -} - -void OnCloseBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) -{ - switch (uiMsg) - { - case MSG_DRAWBUTTON: - { - CRect rcCopy=pData->rcButton; - rcCopy.DeflateRect(2,2,2,2); - - // frame - if (!pData->bPressed) - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); - else - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); - - // background - rcCopy.DeflateRect(1, 1, 1, 1); - pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); - - // close - CPen pen; - int iPenSize=rcCopy.Width()/10+1; - pen.CreatePen(PS_SOLID | PS_INSIDEFRAME, iPenSize, GetSysColor(COLOR_BTNTEXT)); - CPen* pOld=pDC->SelectObject(&pen); - - switch (iPenSize) - { - case 1: - pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.top+pData->bPressed+ROUND(1.4*iPenSize)); - pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(1.4*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(1.6*iPenSize)); - pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(2.6*iPenSize)); - pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(1.4*iPenSize), rcCopy.top+pData->bPressed+ROUND(0.4*iPenSize)); - break; - default: - pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.top+pData->bPressed+ROUND(1.4*iPenSize)); - pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(2.0*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(2.0*iPenSize)); - pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(2.0*iPenSize)); - pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(2.0*iPenSize), rcCopy.top+pData->bPressed+ROUND(1.4*iPenSize)); - break; - } - - pDC->SelectObject(pOld); - break; - } - case MSG_ONCLICK: - pDlg->SendMessage(WM_CLOSE, 0, 0); - break; - } -} - -void OnResume(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) -{ - switch (uiMsg) - { - case MSG_DRAWBUTTON: - { - CRect rcCopy=pData->rcButton; - rcCopy.DeflateRect(2,2,2,2); - - // frame - if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); - else - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); - - // bkgnd - rcCopy.DeflateRect(1, 1, 1, 1); - pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); - - // triangle - int iOffset=rcCopy.Width()/4; - int iHeight=rcCopy.Width()/10+1; - POINT pt[3]={ {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed}, {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.bottom-ROUND(1.625*iHeight)+pData->bPressed}, - {rcCopy.right-iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed+(rcCopy.Height()-3*iHeight+1)/2} }; - - CBrush brs; - brs.CreateSolidBrush(pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); - CBrush* pOld=pDC->SelectObject(&brs); - - CPen pen; - pen.CreatePen(PS_SOLID, 1, pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); - CPen *pOldPen=pDC->SelectObject(&pen); - pDC->SetPolyFillMode(WINDING); - - pDC->Polygon(pt, 3); - - pDC->SelectObject(pOld); - pDC->SelectObject(pOldPen); - - break; - } - case MSG_ONCLICK: - int iSel=pDlg->m_ctlStatus.GetCurSel(); - if (iSel == LB_ERR) - return; - CTask* pTask; - if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) - { - if (pTask->GetStatus(ST_WAITING_MASK) & ST_WAITING) - pTask->SetForceFlag(true); - else - pTask->ResumeProcessing(); - } - else - pDlg->m_pTasks->TasksResumeProcessing(); - break; - } -} - -void OnCancelBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) -{ - switch (uiMsg) - { - case MSG_DRAWBUTTON: - { - CRect rcCopy=pData->rcButton; - rcCopy.DeflateRect(2,2,2,2); - - // frame - if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); - else - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); - - // bkgnd - rcCopy.DeflateRect(1, 1, 1, 1); - pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); - - // square - int iWidth=rcCopy.Width()/10+1; - rcCopy.DeflateRect(1*iWidth+pData->bPressed, 1*iWidth+pData->bPressed, ROUND(1.6*iWidth)-pData->bPressed, 1*iWidth-pData->bPressed); - pDC->FillSolidRect(&rcCopy, pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); - break; - } - case MSG_ONCLICK: - int iSel=pDlg->m_ctlStatus.GetCurSel(); - if (iSel == LB_ERR) - return; - CTask* pTask; - if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) - pTask->CancelProcessing(); - else - pDlg->m_pTasks->TasksCancelProcessing(); - break; - } -} - -void OnRestartBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) -{ - switch (uiMsg) - { - case MSG_DRAWBUTTON: - { - CRect rcCopy=pData->rcButton; - rcCopy.DeflateRect(2,2,2,2); - - // frame - if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); - else - pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); - - // bkgnd - rcCopy.DeflateRect(1, 1, 1, 1); - pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); - - // triangle in a square - int iOffset=rcCopy.Width()/4; - int iHeight=rcCopy.Width()/10+1; - POINT pt[3]={ {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed}, {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.bottom-ROUND(1.625*iHeight)+pData->bPressed}, - {rcCopy.right-iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed+(rcCopy.Height()-3*iHeight+1)/2} }; - - CBrush brs; - brs.CreateSolidBrush(pData->bEnabled ? RGB(255, 0, 0) : GetSysColor(COLOR_BTNSHADOW)); - CBrush* pOld=pDC->SelectObject(&brs); - - CPen pen; - pen.CreatePen(PS_SOLID, 1, pData->bEnabled ? RGB(255, 0, 0) : GetSysColor(COLOR_BTNSHADOW)); - CPen *pOldPen=pDC->SelectObject(&pen); - - pDC->SetPolyFillMode(WINDING); - pDC->Polygon(pt, 3); - pDC->SelectObject(pOld); - pDC->SelectObject(pOldPen); - - break; - } - case MSG_ONCLICK: - int iSel=pDlg->m_ctlStatus.GetCurSel(); - if (iSel == LB_ERR) - return; - CTask* pTask; - if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) - pTask->RestartProcessing(); - else - pDlg->m_pTasks->TasksRestartProcessing(); - break; - } -} - -void CMiniViewDlg::OnSelchangeProgressList() -{ - RefreshStatus(); - RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME); -// PostMessage(WM_NCPAINT); -} - -void CMiniViewDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) -{ - bool bEnabled=false; - CRect rcBtn; - int iNCHeight=GetSystemMetrics(SM_CYSMCAPTION)+GetSystemMetrics(SM_CYDLGFRAME); - - // has been button pressed ? - for (int i=0;i(static_cast(((9+2)-2*iEdgeWidth))*(2.0/3.0))+1; - int iWidth=BTN_COUNT*(GetSystemMetrics(SM_CYSMCAPTION))+sSize.cx+2*GetSystemMetrics(SM_CXDLGFRAME)+18; - - // change pos of listbox - m_ctlStatus.SetWindowPos(NULL, 0, 0, ROUNDUP(iWidth-2*sg_iMargin, iBoxWidth)+2*iEdgeWidth, rcList.Height(), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE); - - RecalcSize(0, true); -} - -void CMiniViewDlg::HideWindow() -{ - static_cast(this)->ShowWindow(SW_HIDE); - m_bShown=false; -} - -void CMiniViewDlg::ShowWindow() -{ - static_cast(this)->ShowWindow(SW_SHOW); - m_bShown=true; -} - -void CMiniViewDlg::OnDblclkProgressList() -{ - int iSel=m_ctlStatus.GetCurSel(); - if (iSel == LB_ERR) - return; - CTask* pTask; - pTask=m_ctlStatus.m_items.GetAt(iSel)->m_pTask; - - GetParent()->PostMessage(WM_MINIVIEWDBLCLK, 0, (LPARAM)pTask); -} - -void CMiniViewDlg::OnLanguageChanged() -{ - ResizeDialog(); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "MiniViewDlg.h" +#include "ch.h" +#include + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +#define WM_INITDATA WM_USER+5 + +static const int sg_iMargin=7; + +#define ROUND(val) ( ( (val)-static_cast(val) > 0.5 ) ? static_cast(val)+1 : static_cast(val) ) +#undef ROUNDUP // from other module +#define ROUNDUP(val, to) ( (static_cast((val)/(to))+1 )*(to) ) + +bool CMiniViewDlg::m_bLock=false; + +///////////////////////////////////////////////////////////////////////////// +// CMiniViewDlg dialog + +CMiniViewDlg::CMiniViewDlg(CTaskArray* pArray, bool *pbHide, CWnd* pParent /*=NULL*/) + :ictranslate::CLanguageDialog(CMiniViewDlg::IDD, pParent, &m_bLock) +{ + //{{AFX_DATA_INIT(CMiniViewDlg) + // NOTE: the ClassWizard will add member initialization here + //}}AFX_DATA_INIT + + m_brBackground.CreateSolidBrush(GetSysColor(COLOR_3DFACE)); + m_iLastHeight=0; + m_bShown=false; + m_pTasks=pArray; + m_bActive=false; + m_iIndex=-1; + m_pbHide=pbHide; +} + + +void CMiniViewDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CMiniViewDlg) + DDX_Control(pDX, IDC_PROGRESS_LIST, m_ctlStatus); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CMiniViewDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CMiniViewDlg) + ON_WM_CTLCOLOR() + ON_WM_TIMER() + ON_LBN_SELCHANGE(IDC_PROGRESS_LIST, OnSelchangeProgressList) + ON_WM_NCLBUTTONDOWN() + ON_WM_LBUTTONUP() + ON_WM_NCPAINT() + ON_WM_NCACTIVATE() + ON_LBN_SETFOCUS(IDC_PROGRESS_LIST, OnSetfocusProgressList) + ON_LBN_SELCANCEL(IDC_PROGRESS_LIST, OnSelcancelProgressList) + ON_WM_MOUSEMOVE() + ON_WM_SETTINGCHANGE() + ON_LBN_DBLCLK(IDC_PROGRESS_LIST, OnDblclkProgressList) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CMiniViewDlg message handlers + +HBRUSH CMiniViewDlg::OnCtlColor(CDC*, CWnd*, UINT) +{ + return m_brBackground; +} + +BOOL CMiniViewDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // fill the buttons' structure + m_bdButtons[0].pfnCallbackFunc=&OnPause; + m_bdButtons[0].iPosition=4; + m_bdButtons[0].bPressed=false; + m_bdButtons[0].bEnabled=false; + m_bdButtons[1].pfnCallbackFunc=&OnResume; + m_bdButtons[1].iPosition=3; + m_bdButtons[1].bPressed=false; + m_bdButtons[1].bEnabled=false; + m_bdButtons[2].pfnCallbackFunc=&OnCancelBtn; + m_bdButtons[2].iPosition=2; + m_bdButtons[2].bPressed=false; + m_bdButtons[2].bEnabled=false; + m_bdButtons[3].pfnCallbackFunc=&OnRestartBtn; + m_bdButtons[3].iPosition=1; + m_bdButtons[3].bPressed=false; + m_bdButtons[3].bEnabled=false; + m_bdButtons[4].pfnCallbackFunc=&OnCloseBtn; + m_bdButtons[4].iPosition=0; + m_bdButtons[4].bPressed=false; + m_bdButtons[4].bEnabled=true; + + ResizeDialog(); + PostMessage(WM_INITDATA); + + return TRUE; +} + +void CMiniViewDlg::OnTimer(UINT_PTR nIDEvent) +{ + if (nIDEvent == 9843) + { + KillTimer(9843); + + RefreshStatus(); + + SetTimer(9843, GetConfig()->get_signed_num(PP_MVREFRESHINTERVAL), NULL); + } + + CLanguageDialog::OnTimer(nIDEvent); +} + +void CMiniViewDlg::RecalcSize(int nHeight, bool bInitial) +{ + // set listbox size + CRect rcList; + m_ctlStatus.GetClientRect(&rcList); + + if (nHeight == 0) + nHeight=rcList.Height(); + + // don't do anything if height doesn't changed + if (nHeight == m_iLastHeight && !bInitial) + return; + + // remember height + m_iLastHeight = nHeight; + + // size of a dialog and screen + CRect rCLanguageDialog, rcScreen; + GetWindowRect(&rCLanguageDialog); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0); + + // place listbox in the best place + m_ctlStatus.SetWindowPos(NULL, sg_iMargin, 0/*sg_iMargin*/, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + + int iWidth=rcList.Width()+2*sg_iMargin+2*GetSystemMetrics(SM_CXDLGFRAME); + int iHeight=rcList.Height()+1*sg_iMargin+2*GetSystemMetrics(SM_CYDLGFRAME)+GetSystemMetrics(SM_CYSMCAPTION); + + if (bInitial || (rCLanguageDialog.left == rcScreen.right-rCLanguageDialog.Width() + && rCLanguageDialog.top == rcScreen.bottom-rCLanguageDialog.Height()) ) + { + SetWindowPos(&wndTopMost, rcScreen.right-iWidth, rcScreen.bottom-iHeight, iWidth, iHeight, + 0); + } + else + SetWindowPos(&wndTopMost, 0, 0, iWidth, iHeight, SWP_NOMOVE); +} + +void CMiniViewDlg::RefreshStatus() +{ + int index=0; + _PROGRESSITEM_* pItem=NULL; + + if (GetConfig()->get_bool(PP_MVSHOWSINGLETASKS)) + { + for (int i=0;iGetSize();i++) + { + CTask* pTask=m_pTasks->GetAt(i); + pTask->GetMiniSnapshot(&dd); + + if ((dd.m_uiStatus & ST_STEP_MASK) != ST_FINISHED && (dd.m_uiStatus & ST_STEP_MASK) != ST_CANCELLED) + { + pItem=m_ctlStatus.GetItemAddress(index++); + + // load + if ((dd.m_uiStatus & ST_WORKING_MASK) == ST_ERROR) + pItem->m_crColor=RGB(255, 0, 0); + else if ((dd.m_uiStatus & ST_WORKING_MASK) == ST_PAUSED) + pItem->m_crColor=RGB(255, 255, 0); + else if ((dd.m_uiStatus & ST_WAITING_MASK) == ST_WAITING) + pItem->m_crColor=RGB(50, 50, 50); + else + pItem->m_crColor=RGB(0, 255, 0); + + pItem->m_strText=dd.m_fi.GetFileName(); + pItem->m_uiPos=dd.m_nPercent; + pItem->m_pTask=pTask; + } + } + } + + // should we show ? + bool bInitial=false; + if (index == 0) + { + if (m_bShown) + { + if (GetConfig()->get_bool(PP_MVAUTOHIDEWHENEMPTY) || *m_pbHide) + HideWindow(); + } + else if (!GetConfig()->get_bool(PP_MVAUTOHIDEWHENEMPTY) && !(*m_pbHide)) + { + // need to be visible + ShowWindow(); + bInitial=true; + } + } + else + { + if (!m_bShown) + { + if (!(*m_pbHide)) + { + ShowWindow(); + bInitial=true; + } + } + else + { + if (*m_pbHide) + HideWindow(); + } + } + + // add all state + pItem=m_ctlStatus.GetItemAddress(index++); + pItem->m_crColor=GetSysColor(COLOR_HIGHLIGHT); + pItem->m_strText=GetResManager()->LoadString(IDS_MINIVIEWALL_STRING); + pItem->m_uiPos=m_pTasks->GetPercent(); + pItem->m_pTask=NULL; + + // get rid of the rest + m_ctlStatus.SetSmoothProgress(GetConfig()->get_bool(PP_MVUSESMOOTHPROGRESS)); + m_ctlStatus.UpdateItems(index, true); + + m_ctlStatus.SetShowCaptions(GetConfig()->get_bool(PP_MVSHOWFILENAMES)); + + // calc size + RecalcSize(0, bInitial); +} + +LRESULT CMiniViewDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + if (message == WM_INITDATA) + { + // listbox with progress pseudocontrols + m_ctlStatus.Init(); + + // refresh + RefreshStatus(); + + // set refresh timer + SetTimer(9843, GetConfig()->get_signed_num(PP_MVREFRESHINTERVAL), NULL); + + return static_cast(0); + } + + return ictranslate::CLanguageDialog::WindowProc(message, wParam, lParam); +} + +void CMiniViewDlg::OnNcPaint() +{ + int iCXBorder=GetSystemMetrics(SM_CXBORDER); + int iCYBorder=GetSystemMetrics(SM_CYBORDER); + int iWidth=GetSystemMetrics(SM_CXSMSIZE); + int iHeight=GetSystemMetrics(SM_CYSMSIZE); + int iFrameHeight=GetSystemMetrics(SM_CYDLGFRAME); + int iFrameWidth=GetSystemMetrics(SM_CXDLGFRAME); + bool bEnabled=(m_ctlStatus.GetCurSel() != LB_ERR); + + // NC coordinates + CRect rcWindow; + GetWindowRect(&rcWindow); + rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top); + + // device context + CWindowDC ncdc(this); + + // frame + ncdc.DrawEdge(&rcWindow, EDGE_RAISED, BF_RECT); + rcWindow.DeflateRect(iFrameWidth-iCXBorder, iFrameHeight-iCYBorder, iFrameWidth-iCXBorder, iFrameHeight-iCYBorder); + + CPen pen, pen2; + pen.CreatePen(PS_SOLID, iCXBorder, GetSysColor(COLOR_3DFACE)); + pen2.CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE)); + + ncdc.SelectObject(&pen); + ncdc.SelectStockObject(NULL_BRUSH); + + ncdc.Rectangle(&rcWindow); + + // caption bar + rcWindow.DeflateRect(iCXBorder, iCXBorder, iCXBorder, 0); + rcWindow.bottom=rcWindow.top+iHeight; // caption pos + + // additional horz bar + ncdc.SelectObject(&pen2); + ncdc.MoveTo(rcWindow.left, rcWindow.bottom); + ncdc.LineTo(rcWindow.right, rcWindow.bottom); + + // memdc + CMemDC dc(&ncdc, &rcWindow); + + COLORREF crLeft=GetSysColor(m_bActive ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION); + dc.FillSolidRect(&rcWindow, crLeft); + + // caption text + CString strWindow; + GetWindowText(strWindow); +// TRACE("DRAWING TEXT: "+strWindow+"\n"); + + rcWindow.DeflateRect(5, 0, BTN_COUNT*iWidth+iFrameWidth+5, 0); + + // caption font + NONCLIENTMETRICS ncm; + memset(&ncm, 0, sizeof(NONCLIENTMETRICS)); + ncm.cbSize=sizeof(NONCLIENTMETRICS); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0); + + CFont font; + font.CreateFontIndirect(&ncm.lfSmCaptionFont); + dc.SelectObject(&font); + + dc.SetTextColor(GetSysColor(COLOR_CAPTIONTEXT)); + dc.SetBkMode(TRANSPARENT); + dc.DrawText(strWindow, &rcWindow, DT_END_ELLIPSIS | DT_VCENTER | DT_LEFT | DT_NOCLIP | DT_SINGLELINE); + // button drawing + GetClientRect(&rcWindow); + + for (int i=0;ircButton; + rcCopy.DeflateRect(2,2,2,2); + + // frame drawing + if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); + else + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); + + // fill the background + rcCopy.DeflateRect(1, 1, 1, 1); + pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); + + // pause + CPen pen; + int iPenWidth=rcCopy.Width()/10+1; + pen.CreatePen(PS_SOLID, iPenWidth, pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); + CPen* pOld=pDC->SelectObject(&pen); + + int iOffset=rcCopy.Width()/3; + pDC->MoveTo(rcCopy.left+iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.top+1*iPenWidth+pData->bPressed); + pDC->LineTo(rcCopy.left+iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.bottom-ROUND(1.5*iPenWidth)+pData->bPressed); + pDC->MoveTo(rcCopy.right-iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.top+1*iPenWidth+pData->bPressed); + pDC->LineTo(rcCopy.right-iOffset-ROUND(0.66*iPenWidth)+pData->bPressed, rcCopy.bottom-ROUND(1.5*iPenWidth)+pData->bPressed); + + pDC->SelectObject(pOld); + break; + } + case MSG_ONCLICK: + int iSel=pDlg->m_ctlStatus.GetCurSel(); + if (iSel == LB_ERR) + return; + CTask* pTask; + if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) + pTask->PauseProcessing(); + else + pDlg->m_pTasks->TasksPauseProcessing(); + + break; + } +} + +void OnCloseBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) +{ + switch (uiMsg) + { + case MSG_DRAWBUTTON: + { + CRect rcCopy=pData->rcButton; + rcCopy.DeflateRect(2,2,2,2); + + // frame + if (!pData->bPressed) + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); + else + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); + + // background + rcCopy.DeflateRect(1, 1, 1, 1); + pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); + + // close + CPen pen; + int iPenSize=rcCopy.Width()/10+1; + pen.CreatePen(PS_SOLID | PS_INSIDEFRAME, iPenSize, GetSysColor(COLOR_BTNTEXT)); + CPen* pOld=pDC->SelectObject(&pen); + + switch (iPenSize) + { + case 1: + pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.top+pData->bPressed+ROUND(1.4*iPenSize)); + pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(1.4*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(1.6*iPenSize)); + pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(2.6*iPenSize)); + pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(1.4*iPenSize), rcCopy.top+pData->bPressed+ROUND(0.4*iPenSize)); + break; + default: + pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.top+pData->bPressed+ROUND(1.4*iPenSize)); + pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(2.0*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(2.0*iPenSize)); + pDC->MoveTo(rcCopy.left+pData->bPressed+ROUND(1.4*iPenSize), rcCopy.bottom+pData->bPressed-ROUND(2.0*iPenSize)); + pDC->LineTo(rcCopy.right+pData->bPressed-ROUND(2.0*iPenSize), rcCopy.top+pData->bPressed+ROUND(1.4*iPenSize)); + break; + } + + pDC->SelectObject(pOld); + break; + } + case MSG_ONCLICK: + pDlg->SendMessage(WM_CLOSE, 0, 0); + break; + } +} + +void OnResume(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) +{ + switch (uiMsg) + { + case MSG_DRAWBUTTON: + { + CRect rcCopy=pData->rcButton; + rcCopy.DeflateRect(2,2,2,2); + + // frame + if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); + else + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); + + // bkgnd + rcCopy.DeflateRect(1, 1, 1, 1); + pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); + + // triangle + int iOffset=rcCopy.Width()/4; + int iHeight=rcCopy.Width()/10+1; + POINT pt[3]={ {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed}, {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.bottom-ROUND(1.625*iHeight)+pData->bPressed}, + {rcCopy.right-iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed+(rcCopy.Height()-3*iHeight+1)/2} }; + + CBrush brs; + brs.CreateSolidBrush(pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); + CBrush* pOld=pDC->SelectObject(&brs); + + CPen pen; + pen.CreatePen(PS_SOLID, 1, pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); + CPen *pOldPen=pDC->SelectObject(&pen); + pDC->SetPolyFillMode(WINDING); + + pDC->Polygon(pt, 3); + + pDC->SelectObject(pOld); + pDC->SelectObject(pOldPen); + + break; + } + case MSG_ONCLICK: + int iSel=pDlg->m_ctlStatus.GetCurSel(); + if (iSel == LB_ERR) + return; + CTask* pTask; + if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) + { + if (pTask->GetStatus(ST_WAITING_MASK) & ST_WAITING) + pTask->SetForceFlag(true); + else + pTask->ResumeProcessing(); + } + else + pDlg->m_pTasks->TasksResumeProcessing(); + break; + } +} + +void OnCancelBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) +{ + switch (uiMsg) + { + case MSG_DRAWBUTTON: + { + CRect rcCopy=pData->rcButton; + rcCopy.DeflateRect(2,2,2,2); + + // frame + if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); + else + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); + + // bkgnd + rcCopy.DeflateRect(1, 1, 1, 1); + pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); + + // square + int iWidth=rcCopy.Width()/10+1; + rcCopy.DeflateRect(1*iWidth+pData->bPressed, 1*iWidth+pData->bPressed, ROUND(1.6*iWidth)-pData->bPressed, 1*iWidth-pData->bPressed); + pDC->FillSolidRect(&rcCopy, pData->bEnabled ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_BTNSHADOW)); + break; + } + case MSG_ONCLICK: + int iSel=pDlg->m_ctlStatus.GetCurSel(); + if (iSel == LB_ERR) + return; + CTask* pTask; + if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) + pTask->CancelProcessing(); + else + pDlg->m_pTasks->TasksCancelProcessing(); + break; + } +} + +void OnRestartBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC) +{ + switch (uiMsg) + { + case MSG_DRAWBUTTON: + { + CRect rcCopy=pData->rcButton; + rcCopy.DeflateRect(2,2,2,2); + + // frame + if (!pData->bPressed || pDlg->m_ctlStatus.GetCurSel() == LB_ERR) + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNHIGHLIGHT), GetSysColor(COLOR_BTNSHADOW)); + else + pDC->Draw3dRect(&rcCopy, GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHIGHLIGHT)); + + // bkgnd + rcCopy.DeflateRect(1, 1, 1, 1); + pDC->FillSolidRect(&rcCopy, GetSysColor(COLOR_3DFACE)); + + // triangle in a square + int iOffset=rcCopy.Width()/4; + int iHeight=rcCopy.Width()/10+1; + POINT pt[3]={ {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed}, {rcCopy.left+iOffset-1+pData->bPressed, rcCopy.bottom-ROUND(1.625*iHeight)+pData->bPressed}, + {rcCopy.right-iOffset-1+pData->bPressed, rcCopy.top+1*iHeight+pData->bPressed+(rcCopy.Height()-3*iHeight+1)/2} }; + + CBrush brs; + brs.CreateSolidBrush(pData->bEnabled ? RGB(255, 0, 0) : GetSysColor(COLOR_BTNSHADOW)); + CBrush* pOld=pDC->SelectObject(&brs); + + CPen pen; + pen.CreatePen(PS_SOLID, 1, pData->bEnabled ? RGB(255, 0, 0) : GetSysColor(COLOR_BTNSHADOW)); + CPen *pOldPen=pDC->SelectObject(&pen); + + pDC->SetPolyFillMode(WINDING); + pDC->Polygon(pt, 3); + pDC->SelectObject(pOld); + pDC->SelectObject(pOldPen); + + break; + } + case MSG_ONCLICK: + int iSel=pDlg->m_ctlStatus.GetCurSel(); + if (iSel == LB_ERR) + return; + CTask* pTask; + if ( (pTask=pDlg->m_ctlStatus.m_items.GetAt(iSel)->m_pTask) != NULL) + pTask->RestartProcessing(); + else + pDlg->m_pTasks->TasksRestartProcessing(); + break; + } +} + +void CMiniViewDlg::OnSelchangeProgressList() +{ + RefreshStatus(); + RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME); +// PostMessage(WM_NCPAINT); +} + +void CMiniViewDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) +{ + bool bEnabled=false; + CRect rcBtn; + int iNCHeight=GetSystemMetrics(SM_CYSMCAPTION)+GetSystemMetrics(SM_CYDLGFRAME); + + // has been button pressed ? + for (int i=0;i(static_cast(((9+2)-2*iEdgeWidth))*(2.0/3.0))+1; + int iWidth=BTN_COUNT*(GetSystemMetrics(SM_CYSMCAPTION))+sSize.cx+2*GetSystemMetrics(SM_CXDLGFRAME)+18; + + // change pos of listbox + m_ctlStatus.SetWindowPos(NULL, 0, 0, ROUNDUP(iWidth-2*sg_iMargin, iBoxWidth)+2*iEdgeWidth, rcList.Height(), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE); + + RecalcSize(0, true); +} + +void CMiniViewDlg::HideWindow() +{ + static_cast(this)->ShowWindow(SW_HIDE); + m_bShown=false; +} + +void CMiniViewDlg::ShowWindow() +{ + static_cast(this)->ShowWindow(SW_SHOW); + m_bShown=true; +} + +void CMiniViewDlg::OnDblclkProgressList() +{ + int iSel=m_ctlStatus.GetCurSel(); + if (iSel == LB_ERR) + return; + CTask* pTask; + pTask=m_ctlStatus.m_items.GetAt(iSel)->m_pTask; + + GetParent()->PostMessage(WM_MINIVIEWDBLCLK, 0, (LPARAM)pTask); +} + +void CMiniViewDlg::OnLanguageChanged() +{ + ResizeDialog(); +} Index: src/ch/MiniViewDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/MiniViewDlg.h (.../MiniViewDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/MiniViewDlg.h (.../MiniViewDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,127 +1,127 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __MINIVIEWDLG_H__ -#define __MINIVIEWDLG_H__ - -///////////////////////////////////////////////////////////////////////////// -// CMiniViewDlg dialog -#include "structs.h" -#include "ProgressListBox.h" -#include "resource.h" - -#define BTN_COUNT 5 - -#define MSG_DRAWBUTTON 1 -#define MSG_ONCLICK 2 - -#define WM_MINIVIEWDBLCLK WM_USER+14 - -class CMiniViewDlg : public ictranslate::CLanguageDialog -{ -// internal struct -public: - struct _BTNDATA_ - { - void (*pfnCallbackFunc)(CMiniViewDlg*, UINT, _BTNDATA_*, CDC*); // callback - click - int iPosition; // button pos counting from right - bool bPressed; // is it pressed ? - bool bEnabled; // is it enabled ? - - CRect rcButton; // filled in OnNCPaint - } m_bdButtons[BTN_COUNT]; - -// Construction -public: - CMiniViewDlg(CTaskArray* pArray, bool* pbHide, CWnd* pParent = NULL); // standard constructor - - void ShowWindow(); - void HideWindow(); - void ResizeDialog(); - friend void OnRestartBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); - friend void OnCancelBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); - friend void OnResume(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); - friend void OnPause(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); - friend void OnCloseBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC); - - void RefreshStatus(); - void RecalcSize(int nHeight, bool bInitial); - - virtual UINT GetLanguageUpdateOptions() { return LDF_NODIALOGSIZE; }; - virtual void OnLanguageChanged(); - - // from CMainWnd - CTaskArray *m_pTasks; - - CBrush m_brBackground; - int m_iLastHeight; - bool m_bShown; - _PROGRESSITEM_ item; - - // cache - TASK_MINI_DISPLAY_DATA dd; - bool m_bActive; - - // lock - static bool m_bLock; - bool *m_pbHide; // does the big status dialog visible ? - - // in onmousemove points to last pressed button - int m_iIndex; - -// Dialog Data - //{{AFX_DATA(CMiniViewDlg) - enum { IDD = IDD_MINIVIEW_DIALOG }; - CProgressListBox m_ctlStatus; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CMiniViewDlg) - public: - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - //}}AFX_VIRTUAL - -// Implementation -protected: - // Generated message map functions - //{{AFX_MSG(CMiniViewDlg) - afx_msg HBRUSH OnCtlColor(CDC*, CWnd*, UINT); - virtual BOOL OnInitDialog(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - afx_msg void OnSelchangeProgressList(); - afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point); - afx_msg void OnLButtonUp(UINT nFlags, CPoint point); - afx_msg void OnNcPaint(); - afx_msg BOOL OnNcActivate(BOOL bActive); - afx_msg void OnSetfocusProgressList(); - afx_msg void OnSelcancelProgressList(); - afx_msg void OnMouseMove(UINT nFlags, CPoint point); - afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection); - afx_msg void OnDblclkProgressList(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __MINIVIEWDLG_H__ +#define __MINIVIEWDLG_H__ + +///////////////////////////////////////////////////////////////////////////// +// CMiniViewDlg dialog +#include "structs.h" +#include "ProgressListBox.h" +#include "resource.h" + +#define BTN_COUNT 5 + +#define MSG_DRAWBUTTON 1 +#define MSG_ONCLICK 2 + +#define WM_MINIVIEWDBLCLK WM_USER+14 + +class CMiniViewDlg : public ictranslate::CLanguageDialog +{ +// internal struct +public: + struct _BTNDATA_ + { + void (*pfnCallbackFunc)(CMiniViewDlg*, UINT, _BTNDATA_*, CDC*); // callback - click + int iPosition; // button pos counting from right + bool bPressed; // is it pressed ? + bool bEnabled; // is it enabled ? + + CRect rcButton; // filled in OnNCPaint + } m_bdButtons[BTN_COUNT]; + +// Construction +public: + CMiniViewDlg(CTaskArray* pArray, bool* pbHide, CWnd* pParent = NULL); // standard constructor + + void ShowWindow(); + void HideWindow(); + void ResizeDialog(); + friend void OnRestartBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); + friend void OnCancelBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); + friend void OnResume(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); + friend void OnPause(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC=NULL); + friend void OnCloseBtn(CMiniViewDlg* pDlg, UINT uiMsg, CMiniViewDlg::_BTNDATA_* pData, CDC* pDC); + + void RefreshStatus(); + void RecalcSize(int nHeight, bool bInitial); + + virtual UINT GetLanguageUpdateOptions() { return LDF_NODIALOGSIZE; }; + virtual void OnLanguageChanged(); + + // from CMainWnd + CTaskArray *m_pTasks; + + CBrush m_brBackground; + int m_iLastHeight; + bool m_bShown; + _PROGRESSITEM_ item; + + // cache + TASK_MINI_DISPLAY_DATA dd; + bool m_bActive; + + // lock + static bool m_bLock; + bool *m_pbHide; // does the big status dialog visible ? + + // in onmousemove points to last pressed button + int m_iIndex; + +// Dialog Data + //{{AFX_DATA(CMiniViewDlg) + enum { IDD = IDD_MINIVIEW_DIALOG }; + CProgressListBox m_ctlStatus; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CMiniViewDlg) + public: + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + //}}AFX_VIRTUAL + +// Implementation +protected: + // Generated message map functions + //{{AFX_MSG(CMiniViewDlg) + afx_msg HBRUSH OnCtlColor(CDC*, CWnd*, UINT); + virtual BOOL OnInitDialog(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + afx_msg void OnSelchangeProgressList(); + afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point); + afx_msg void OnLButtonUp(UINT nFlags, CPoint point); + afx_msg void OnNcPaint(); + afx_msg BOOL OnNcActivate(BOOL bActive); + afx_msg void OnSetfocusProgressList(); + afx_msg void OnSelcancelProgressList(); + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg void OnSettingChange(UINT uFlags, LPCTSTR lpszSection); + afx_msg void OnDblclkProgressList(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/OptionsDlg.cpp =================================================================== diff -u -rf6c4389122d92e5f84a509e9be0facebac429151 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/OptionsDlg.cpp (.../OptionsDlg.cpp) (revision f6c4389122d92e5f84a509e9be0facebac429151) +++ src/ch/OptionsDlg.cpp (.../OptionsDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,539 +1,539 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "resource.h" -#include "OptionsDlg.h" -#include "BufferSizeDlg.h" -#include "ShortcutsDlg.h" -#include "RecentDlg.h" -#include - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -bool COptionsDlg::m_bLock=false; - -///////////////////////////////////////////////////////////////////////////// -// COptionsDlg dialog - -COptionsDlg::COptionsDlg(CWnd* pParent /*=NULL*/) - :ictranslate::CLanguageDialog(COptionsDlg::IDD, pParent, &m_bLock) -{ - //{{AFX_DATA_INIT(COptionsDlg) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT -} - -void COptionsDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(COptionsDlg) - DDX_Control(pDX, IDC_PROPERTIES_LIST, m_ctlProperties); - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(COptionsDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(COptionsDlg) - ON_BN_CLICKED(IDC_APPLY_BUTTON, OnApplyButton) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// COptionsDlg message handlers - -// properties handling macros -#define PROP_SEPARATOR(text)\ - m_ctlProperties.AddString(text); - -#define PROP_BOOL(text, value)\ - m_ctlProperties.AddString(text, ID_PROPERTY_COMBO_LIST, IDS_BOOLTEXT_STRING, (value)); - -#define PROP_UINT(text, value)\ - m_ctlProperties.AddString(text, ID_PROPERTY_TEXT, _itot((int)(value), m_szBuffer, 10), 0); - -#define PROP_COMBO(text, prop_text, value)\ - m_ctlProperties.AddString(text, ID_PROPERTY_COMBO_LIST, prop_text, (int)((value))); - -#define PROP_DIR(text, prop_text, value)\ - m_ctlProperties.AddString(text, ID_PROPERTY_DIR, (value)+CString(GetResManager()->LoadString(prop_text)), 0); - -#define PROP_PATH(text, prop_text, value)\ - m_ctlProperties.AddString(text, ID_PROPERTY_PATH, (value)+CString(GetResManager()->LoadString(prop_text)), 0); - -#define PROP_CUSTOM_UINT(text, value, callback, param)\ - m_ctlProperties.AddString(text, ID_PROPERTY_CUSTOM, CString(_itot((int)(value), m_szBuffer, 10)), callback, this, param, 0); - -#define SKIP_SEPARATOR(pos)\ - pos++; - -BOOL COptionsDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - m_ctlProperties.Init(); - - // copy shortcut and recent paths - icpf::config* pConfig = GetConfig(); - assert(pConfig); - if(!pConfig) - return FALSE; - - m_cvRecent.clear(true); - size_t stSize = pConfig->get_value_count(PP_RECENTPATHS); - const tchar_t* pszPath = NULL; - for(size_t stIndex = 0; stIndex < stSize; stIndex++) - { - pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); - if(pszPath) - m_cvRecent.push_back(pszPath); - } - - m_cvShortcuts.clear(true); - stSize = pConfig->get_value_count(PP_SHORTCUTS); - for(size_t stIndex = 0; stIndex < stSize; stIndex++) - { - pszPath = pConfig->get_string(PP_SHORTCUTS, stIndex); - if(pszPath) - m_cvShortcuts.push_back(pszPath); - } - - _tcscpy(m_szLangPath, _T("\\Langs\\")); - GetApp()->ExpandPath(m_szLangPath); - - GetResManager()->Scan(m_szLangPath, &m_vld); - - // some attributes - m_ctlProperties.SetBkColor(RGB(255, 255, 255)); - m_ctlProperties.SetTextColor(RGB(80, 80, 80)); - m_ctlProperties.SetTextHighlightColor(RGB(80,80,80)); - m_ctlProperties.SetHighlightColor(RGB(200, 200, 200)); - m_ctlProperties.SetPropertyBkColor(RGB(255,255,255)); - m_ctlProperties.SetPropertyTextColor(RGB(0,0,0)); - m_ctlProperties.SetLineStyle(RGB(74,109,132), PS_SOLID); - - FillPropertyList(); - - return TRUE; -} - -void CustomPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex) -{ - COptionsDlg* pDlg=static_cast(lpParam); - CBufferSizeDlg dlg; - - dlg.m_bsSizes.m_bOnlyDefault=pDlg->GetBoolProp(iIndex-iParam-1); - dlg.m_bsSizes.m_uiDefaultSize=pDlg->GetUintProp(iIndex-iParam); - dlg.m_bsSizes.m_uiOneDiskSize=pDlg->GetUintProp(iIndex-iParam+1); - dlg.m_bsSizes.m_uiTwoDisksSize=pDlg->GetUintProp(iIndex-iParam+2); - dlg.m_bsSizes.m_uiCDSize=pDlg->GetUintProp(iIndex-iParam+3); - dlg.m_bsSizes.m_uiLANSize=pDlg->GetUintProp(iIndex-iParam+4); - dlg.m_iActiveIndex=iParam; // selected buffer for editing - - if (dlg.DoModal() == IDOK) - { - PROPERTYITEM* pItem; - TCHAR xx[32]; - - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam-1)); - pItem->nPropertySelected=(dlg.m_bsSizes.m_bOnlyDefault ? 1 : 0); - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam)); - pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiDefaultSize, xx, 10)); - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+1)); - pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiOneDiskSize, xx, 10)); - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+2)); - pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiTwoDisksSize, xx, 10)); - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+3)); - pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiCDSize, xx, 10)); - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+4)); - pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiLANSize, xx, 10)); - } -} - -void ShortcutsPropertyCallbackProc(LPVOID lpParam, int /*iParam*/, CPtrList* pList, int iIndex) -{ - COptionsDlg* pDlg=static_cast(lpParam); - - CShortcutsDlg dlg; - dlg.m_cvShortcuts.assign(pDlg->m_cvShortcuts.begin(), pDlg->m_cvShortcuts.end(), true, true); - dlg.m_pcvRecent=&pDlg->m_cvRecent; - if (dlg.DoModal() == IDOK) - { - // restore shortcuts to pDlg->cvShortcuts - pDlg->m_cvShortcuts.assign(dlg.m_cvShortcuts.begin(), dlg.m_cvShortcuts.end(), true, false); - dlg.m_cvShortcuts.erase(dlg.m_cvShortcuts.begin(), dlg.m_cvShortcuts.end(), false); - - // property list - TCHAR szBuf[32]; - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex)); - pItem->csProperties.SetAt(0, _itot(pDlg->m_cvShortcuts.size(), szBuf, 10)); - } -} - -void RecentPropertyCallbackProc(LPVOID lpParam, int /*iParam*/, CPtrList* pList, int iIndex) -{ - COptionsDlg* pDlg=static_cast(lpParam); - - CRecentDlg dlg; - dlg.m_cvRecent.assign(pDlg->m_cvRecent.begin(), pDlg->m_cvRecent.end(), true, true); - if (dlg.DoModal() == IDOK) - { - // restore - pDlg->m_cvRecent.assign(dlg.m_cvRecent.begin(), dlg.m_cvRecent.end(), true, false); - dlg.m_cvRecent.erase(dlg.m_cvRecent.begin(), dlg.m_cvRecent.end(), false); - - // property list - TCHAR szBuf[32]; - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex)); - pItem->csProperties.SetAt(0, _itot(pDlg->m_cvRecent.size(), szBuf, 10)); - } -} - -void COptionsDlg::OnOK() -{ - // kill focuses - m_ctlProperties.HideControls(); - - ApplyProperties(); - - SendClosingNotify(); - CLanguageDialog::OnOK(); -} - -void COptionsDlg::FillPropertyList() -{ - CString strPath; - - // load settings - PROP_SEPARATOR(IDS_PROGRAM_STRING) - PROP_BOOL(IDS_CLIPBOARDMONITORING_STRING, GetConfig()->get_bool(PP_PCLIPBOARDMONITORING)) - PROP_UINT(IDS_CLIPBOARDINTERVAL_STRING, GetConfig()->get_signed_num(PP_PMONITORSCANINTERVAL)) - PROP_BOOL(IDS_AUTORUNPROGRAM_STRING, GetConfig()->get_bool(PP_PRELOADAFTERRESTART)) - PROP_BOOL(IDS_AUTOSHUTDOWN_STRING, GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED)) - PROP_UINT(IDS_SHUTDOWNTIME_STRING, GetConfig()->get_signed_num(PP_PTIMEBEFORESHUTDOWN)) - PROP_COMBO(IDS_FORCESHUTDOWN_STRING, IDS_FORCESHUTDOWNVALUES_STRING, GetConfig()->get_bool(PP_PFORCESHUTDOWN)) - PROP_UINT(IDS_AUTOSAVEINTERVAL_STRING, GetConfig()->get_signed_num(PP_PAUTOSAVEINTERVAL)) - PROP_COMBO(IDS_CFGPRIORITYCLASS_STRING, IDS_CFGPRIORITYCLASSITEMS_STRING, PriorityClassToIndex(GetConfig()->get_signed_num(PP_PPROCESSPRIORITYCLASS))) - PROP_DIR(IDS_TEMPFOLDER_STRING, IDS_TEMPFOLDERCHOOSE_STRING, strPath) - - // lang - CString strLangs; - UINT uiIndex=0; - for (vector::iterator it=m_vld.begin();it != m_vld.end();it++) - { - strLangs+=(*it).GetLangName(); - strLangs+=_T("!"); - if (_tcsicmp((*it).GetFilename(true), GetResManager()->m_ld.GetFilename(true)) == 0) - uiIndex=it-m_vld.begin(); - } - strLangs.TrimRight(_T('!')); - - PROP_COMBO(IDS_LANGUAGE_STRING, strLangs, uiIndex) - - ///////////////// - PROP_SEPARATOR(IDS_STATUSWINDOW_STRING); - PROP_UINT(IDS_REFRESHSTATUSINTERVAL_STRING, GetConfig()->get_signed_num(PP_STATUSREFRESHINTERVAL)) - PROP_BOOL(IDS_STATUSSHOWDETAILS_STRING, GetConfig()->get_bool(PP_STATUSSHOWDETAILS)) - PROP_BOOL(IDS_STATUSAUTOREMOVE_STRING, GetConfig()->get_bool(PP_STATUSAUTOREMOVEFINISHED)) - - PROP_SEPARATOR(IDS_MINIVIEW_STRING) - PROP_BOOL(IDS_SHOWFILENAMES_STRING, GetConfig()->get_bool(PP_MVSHOWFILENAMES)) - PROP_BOOL(IDS_SHOWSINGLETASKS_STRING, GetConfig()->get_bool(PP_MVSHOWSINGLETASKS)) - PROP_UINT(IDS_MINIVIEWREFRESHINTERVAL_STRING, GetConfig()->get_signed_num(PP_MVREFRESHINTERVAL)) - PROP_BOOL(IDS_MINIVIEWSHOWAFTERSTART_STRING, GetConfig()->get_bool(PP_MVAUTOSHOWWHENRUN)) - PROP_BOOL(IDS_MINIVIEWAUTOHIDE_STRING, GetConfig()->get_bool(PP_MVAUTOHIDEWHENEMPTY)) - PROP_BOOL(IDS_MINIVIEWSMOOTHPROGRESS_STRING, GetConfig()->get_bool(PP_MVUSESMOOTHPROGRESS)) - - PROP_SEPARATOR(IDS_CFGFOLDERDIALOG_STRING) - PROP_BOOL(IDS_CFGFDEXTVIEW_STRING, GetConfig()->get_bool(PP_FDEXTENDEDVIEW)) - PROP_UINT(IDS_CFGFDWIDTH_STRING, GetConfig()->get_signed_num(PP_FDWIDTH)) - PROP_UINT(IDS_CFGFDHEIGHT_STRING, GetConfig()->get_signed_num(PP_FDHEIGHT)) - PROP_COMBO(IDS_CFGFDSHORTCUTS_STRING, IDS_CFGFDSHORTCUTSSTYLES_STRING, GetConfig()->get_signed_num(PP_FDSHORTCUTLISTSTYLE)) - PROP_BOOL(IDS_CFGFDIGNOREDIALOGS_STRING, GetConfig()->get_bool(PP_FDIGNORESHELLDIALOGS)) - - PROP_SEPARATOR(IDS_CFGSHELL_STRING) - PROP_BOOL(IDS_CFGSHCOPY_STRING, GetConfig()->get_bool(PP_SHSHOWCOPY)) - PROP_BOOL(IDS_CFGSHMOVE_STRING, GetConfig()->get_bool(PP_SHSHOWMOVE)) - PROP_BOOL(IDS_CFGSHCMSPECIAL_STRING, GetConfig()->get_bool(PP_SHSHOWCOPYMOVE)) - PROP_BOOL(IDS_CFGSHPASTE_STRING, GetConfig()->get_bool(PP_SHSHOWPASTE)) - PROP_BOOL(IDS_CFGSHPASTESPECIAL_STRING, GetConfig()->get_bool(PP_SHSHOWPASTESPECIAL)) - PROP_BOOL(IDS_CFGSHCOPYTO_STRING, GetConfig()->get_bool(PP_SHSHOWCOPYTO)) - PROP_BOOL(IDS_CFGSHMOVETO_STRING, GetConfig()->get_bool(PP_SHSHOWMOVETO)) - PROP_BOOL(IDS_CFGSHCMTOSPECIAL_STRING, GetConfig()->get_bool(PP_SHSHOWCOPYMOVETO)) - PROP_BOOL(IDS_CFGSHSHOWFREESPACE_STRING, GetConfig()->get_bool(PP_SHSHOWFREESPACE)) - PROP_BOOL(IDS_CFGSHSHOWICONS_STRING, GetConfig()->get_bool(PP_SHSHOWSHELLICONS)) - PROP_BOOL(IDS_CFGSHOVERRIDEDRAG_STRING, GetConfig()->get_bool(PP_SHUSEDRAGDROP)) - PROP_COMBO(IDS_CFGOVERRIDEDEFACTION_STRING, IDS_CFGACTIONS_STRING, GetConfig()->get_signed_num(PP_SHDEFAULTACTION)); - - PROP_SEPARATOR(IDS_PROCESSINGTHREAD_STRING) - PROP_BOOL(IDS_AUTOCOPYREST_STRING, GetConfig()->get_bool(PP_CMUSEAUTOCOMPLETEFILES)) - PROP_BOOL(IDS_SETDESTATTRIB_STRING, GetConfig()->get_bool(PP_CMSETDESTATTRIBUTES)) - PROP_BOOL(IDS_SETDESTTIME_STRING, GetConfig()->get_bool(PP_CMSETDESTDATE)) - PROP_BOOL(IDS_PROTECTROFILES_STRING, GetConfig()->get_bool(PP_CMPROTECTROFILES)) - PROP_UINT(IDS_LIMITOPERATIONS_STRING, GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS)) - PROP_BOOL(IDS_READSIZEBEFOREBLOCK_STRING, GetConfig()->get_bool(PP_CMREADSIZEBEFOREBLOCKING)) - PROP_COMBO(IDS_SHOWVISUALFEEDBACK_STRING, IDS_FEEDBACKTYPE_STRING, GetConfig()->get_signed_num(PP_CMSHOWVISUALFEEDBACK)) - PROP_BOOL(IDS_USETIMEDDIALOGS_STRING, GetConfig()->get_bool(PP_CMUSETIMEDFEEDBACK)) - PROP_UINT(IDS_TIMEDDIALOGINTERVAL_STRING, GetConfig()->get_signed_num(PP_CMFEEDBACKTIME)) - PROP_BOOL(IDS_AUTORETRYONERROR_STRING, GetConfig()->get_bool(PP_CMAUTORETRYONERROR)) - PROP_UINT(IDS_AUTORETRYINTERVAL_STRING, GetConfig()->get_signed_num(PP_CMAUTORETRYINTERVAL)) - PROP_COMBO(IDS_DEFAULTPRIORITY_STRING, MakeCompoundString(IDS_PRIORITY0_STRING, 7, _T("!")), PriorityToIndex(GetConfig()->get_signed_num(PP_CMDEFAULTPRIORITY))) - PROP_BOOL(IDS_CFGDISABLEPRIORITYBOOST_STRING, GetConfig()->get_bool(PP_CMDISABLEPRIORITYBOOST)) - PROP_BOOL(IDS_DELETEAFTERFINISHED_STRING, GetConfig()->get_bool(PP_CMDELETEAFTERFINISHED)) - PROP_BOOL(IDS_CREATELOGFILES_STRING, GetConfig()->get_bool(PP_CMCREATELOG)) - - // Buffer - PROP_SEPARATOR(IDS_OPTIONSBUFFER_STRING) - PROP_BOOL(IDS_AUTODETECTBUFFERSIZE_STRING, GetConfig()->get_bool(PP_BFUSEONLYDEFAULT)) - PROP_CUSTOM_UINT(IDS_DEFAULTBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFDEFAULT), &CustomPropertyCallbackProc, 0) - PROP_CUSTOM_UINT(IDS_ONEDISKBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFONEDISK), &CustomPropertyCallbackProc, 1) - PROP_CUSTOM_UINT(IDS_TWODISKSBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFTWODISKS), &CustomPropertyCallbackProc, 2) - PROP_CUSTOM_UINT(IDS_CDBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFCD), &CustomPropertyCallbackProc, 3) - PROP_CUSTOM_UINT(IDS_LANBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFLAN), &CustomPropertyCallbackProc, 4) - PROP_BOOL(IDS_USENOBUFFERING_STRING, GetConfig()->get_bool(PP_BFUSENOBUFFERING)) - PROP_UINT(IDS_LARGEFILESMINSIZE_STRING, GetConfig()->get_signed_num(PP_BFBOUNDARYLIMIT)) - - - // Sounds - PROP_SEPARATOR(IDS_SOUNDS_STRING) - PROP_BOOL(IDS_PLAYSOUNDS_STRING, GetConfig()->get_bool(PP_SNDPLAYSOUNDS)) - GetConfig()->get_string(PP_SNDERRORSOUNDPATH, strPath.GetBuffer(_MAX_PATH), _MAX_PATH); - strPath.ReleaseBuffer(); - PROP_PATH(IDS_SOUNDONERROR_STRING, IDS_SOUNDSWAVFILTER_STRING, strPath) - GetConfig()->get_string(PP_SNDFINISHEDSOUNDPATH, strPath.GetBuffer(_MAX_PATH), _MAX_PATH); - strPath.ReleaseBuffer(); - PROP_PATH(IDS_SOUNDONFINISH_STRING, IDS_SOUNDSWAVFILTER_STRING, strPath) - - PROP_SEPARATOR(IDS_CFGSHORTCUTS_STRING) - PROP_CUSTOM_UINT(IDS_CFGSCCOUNT_STRING, m_cvShortcuts.size(), &ShortcutsPropertyCallbackProc, 0) - - PROP_SEPARATOR(IDS_CFGRECENT_STRING) - PROP_CUSTOM_UINT(IDS_CFGRPCOUNT_STRING, m_cvRecent.size(), &RecentPropertyCallbackProc, 0) - - /* PROP_SEPARATOR(IDS_CFGLOGFILE_STRING) - PROP_BOOL(IDS_CFGENABLELOGGING_STRING, GetConfig()->get_bool(PP_LOGENABLELOGGING)) - PROP_BOOL(IDS_CFGLIMITATION_STRING, GetConfig()->get_bool(PP_LOGLIMITATION)) - PROP_UINT(IDS_CFGMAXLIMIT_STRING, GetConfig()->get_signed_num(PP_LOGMAXLIMIT)) - PROP_BOOL(IDS_CFGLOGPRECISELIMITING_STRING, GetConfig()->get_bool(PP_LOGPRECISELIMITING)) - PROP_UINT(IDS_CFGTRUNCBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_LOGTRUNCBUFFERSIZE))*/ -} - -void COptionsDlg::ApplyProperties() -{ - // counter - int iPosition=0; - - icpf::config* pConfig = GetConfig(); - assert(pConfig); - if(!pConfig) - return; - - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_PCLIPBOARDMONITORING, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_PMONITORSCANINTERVAL, GetUintProp(iPosition++)); - pConfig->set_bool(PP_PRELOADAFTERRESTART, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_PSHUTDOWNAFTREFINISHED, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_PTIMEBEFORESHUTDOWN, GetUintProp(iPosition++)); - pConfig->set_bool(PP_PFORCESHUTDOWN, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_PAUTOSAVEINTERVAL, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_PPROCESSPRIORITYCLASS, IndexToPriorityClass(GetIndexProp(iPosition++))); - // language - PCTSTR pszSrc=m_vld.at(GetIndexProp(iPosition++)).GetFilename(true); - if (_tcsnicmp(pszSrc, GetApp()->GetProgramPath(), _tcslen(GetApp()->GetProgramPath())) == 0) - { - // replace the first part of path with - TCHAR szData[_MAX_PATH]; - _sntprintf(szData, _MAX_PATH, _T("%s"), pszSrc+_tcslen(GetApp()->GetProgramPath())); - pConfig->set_string(PP_PLANGUAGE, szData); - } - else - pConfig->set_string(PP_PLANGUAGE, pszSrc); - - SKIP_SEPARATOR(iPosition) - pConfig->set_signed_num(PP_STATUSREFRESHINTERVAL, GetUintProp(iPosition++)); - pConfig->set_bool(PP_STATUSSHOWDETAILS, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_STATUSAUTOREMOVEFINISHED, GetBoolProp(iPosition++)); - - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_MVSHOWFILENAMES, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_MVSHOWSINGLETASKS, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_MVREFRESHINTERVAL, GetUintProp(iPosition++)); - pConfig->set_bool(PP_MVAUTOSHOWWHENRUN, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_MVAUTOHIDEWHENEMPTY, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_MVUSESMOOTHPROGRESS, GetBoolProp(iPosition++)); - - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_FDEXTENDEDVIEW, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_FDWIDTH, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_FDHEIGHT, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_FDSHORTCUTLISTSTYLE, GetIndexProp(iPosition++)); - pConfig->set_bool(PP_FDIGNORESHELLDIALOGS, GetBoolProp(iPosition++)); - - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_SHSHOWCOPY, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWMOVE, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWCOPYMOVE, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWPASTE, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWPASTESPECIAL, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWCOPYTO, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWMOVETO, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWCOPYMOVETO, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWFREESPACE, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHSHOWSHELLICONS, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_SHUSEDRAGDROP, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_SHDEFAULTACTION, GetIndexProp(iPosition++)); - - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_CMUSEAUTOCOMPLETEFILES, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_CMSETDESTATTRIBUTES, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_CMSETDESTDATE, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_CMPROTECTROFILES, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_CMLIMITMAXOPERATIONS, GetUintProp(iPosition++)); - pConfig->set_bool(PP_CMREADSIZEBEFOREBLOCKING, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_CMSHOWVISUALFEEDBACK, GetIndexProp(iPosition++)); - pConfig->set_bool(PP_CMUSETIMEDFEEDBACK, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_CMFEEDBACKTIME, GetUintProp(iPosition++)); - pConfig->set_bool(PP_CMAUTORETRYONERROR, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_CMAUTORETRYINTERVAL, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_CMDEFAULTPRIORITY, IndexToPriority(GetIndexProp(iPosition++))); - pConfig->set_bool(PP_CMDISABLEPRIORITYBOOST, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_CMDELETEAFTERFINISHED, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_CMCREATELOG, GetBoolProp(iPosition++)); - - // Buffer - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_BFUSEONLYDEFAULT, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_BFDEFAULT, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_BFONEDISK, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_BFTWODISKS, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_BFCD, GetUintProp(iPosition++)); - pConfig->set_signed_num(PP_BFLAN, GetUintProp(iPosition++)); - pConfig->set_bool(PP_BFUSENOBUFFERING, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_BFBOUNDARYLIMIT, GetUintProp(iPosition++)); - - // log file -/* SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_LOGENABLELOGGING, GetBoolProp(iPosition++)); - pConfig->set_bool(PP_LOGLIMITATION, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_LOGMAXLIMIT, GetUintProp(iPosition++)); - pConfig->set_bool(PP_LOGPRECISELIMITING, GetBoolProp(iPosition++)); - pConfig->set_signed_num(PP_LOGTRUNCBUFFERSIZE, GetUintProp(iPosition++));*/ - - // Sounds - SKIP_SEPARATOR(iPosition) - pConfig->set_bool(PP_SNDPLAYSOUNDS, GetBoolProp(iPosition++)); - pConfig->set_string(PP_SNDERRORSOUNDPATH, GetStringProp(iPosition++)); - pConfig->set_string(PP_SNDFINISHEDSOUNDPATH, GetStringProp(iPosition++)); - - // shortcuts & recent paths - SKIP_SEPARATOR(iPosition) - pConfig->clear_array_values(PP_SHORTCUTS); - for(char_vector::iterator it = m_cvShortcuts.begin(); it != m_cvShortcuts.end(); it++) - { - pConfig->set_string(PP_SHORTCUTS, (*it), icpf::property::action_add); - } - - SKIP_SEPARATOR(iPosition) - pConfig->clear_array_values(PP_RECENTPATHS); - for(char_vector::iterator it = m_cvRecent.begin(); it != m_cvRecent.end(); it++) - { - pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); - } - - pConfig->write(NULL); -} - -void COptionsDlg::OnCancel() -{ - SendClosingNotify(); - CLanguageDialog::OnCancel(); -} - -void COptionsDlg::SendClosingNotify() -{ - GetParent()->PostMessage(WM_CONFIGNOTIFY); -} - -CString COptionsDlg::MakeCompoundString(UINT uiBase, int iCount, LPCTSTR lpszSeparator) -{ - assert(lpszSeparator); - if(!lpszSeparator) - return _T(""); - _tcscpy(m_szBuffer, GetResManager()->LoadString(uiBase+0)); - for (int i=1;iLoadString(uiBase+i)); - } - - return CString((PCTSTR)m_szBuffer); -} - -bool COptionsDlg::GetBoolProp(int iPosition) -{ - m_ctlProperties.GetProperty(iPosition, &m_iSel); - return m_iSel != 0; -} - -UINT COptionsDlg::GetUintProp(int iPosition) -{ - m_ctlProperties.GetProperty(iPosition, &m_strTemp); - return _ttoi(m_strTemp); -} - -CString COptionsDlg::GetStringProp(int iPosition) -{ - m_ctlProperties.GetProperty(iPosition, &m_strTemp); - return m_strTemp; -} - -int COptionsDlg::GetIndexProp(int iPosition) -{ - m_ctlProperties.GetProperty(iPosition, &m_iSel); - return m_iSel; -} - -void COptionsDlg::OnApplyButton() -{ - // kill focuses - m_ctlProperties.HideControls(); - - ApplyProperties(); -} - -void COptionsDlg::OnLanguageChanged() -{ - m_ctlProperties.Reinit(); - - // set attributes - m_ctlProperties.SetBkColor(RGB(255, 255, 255)); - m_ctlProperties.SetTextColor(RGB(80, 80, 80)); - m_ctlProperties.SetTextHighlightColor(RGB(80,80,80)); - m_ctlProperties.SetHighlightColor(RGB(200, 200, 200)); - m_ctlProperties.SetPropertyBkColor(RGB(255,255,255)); - m_ctlProperties.SetPropertyTextColor(RGB(0,0,0)); - m_ctlProperties.SetLineStyle(RGB(74,109,132), PS_SOLID); - - FillPropertyList(); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "resource.h" +#include "OptionsDlg.h" +#include "BufferSizeDlg.h" +#include "ShortcutsDlg.h" +#include "RecentDlg.h" +#include + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +bool COptionsDlg::m_bLock=false; + +///////////////////////////////////////////////////////////////////////////// +// COptionsDlg dialog + +COptionsDlg::COptionsDlg(CWnd* pParent /*=NULL*/) + :ictranslate::CLanguageDialog(COptionsDlg::IDD, pParent, &m_bLock) +{ + //{{AFX_DATA_INIT(COptionsDlg) + // NOTE: the ClassWizard will add member initialization here + //}}AFX_DATA_INIT +} + +void COptionsDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(COptionsDlg) + DDX_Control(pDX, IDC_PROPERTIES_LIST, m_ctlProperties); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(COptionsDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(COptionsDlg) + ON_BN_CLICKED(IDC_APPLY_BUTTON, OnApplyButton) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// COptionsDlg message handlers + +// properties handling macros +#define PROP_SEPARATOR(text)\ + m_ctlProperties.AddString(text); + +#define PROP_BOOL(text, value)\ + m_ctlProperties.AddString(text, ID_PROPERTY_COMBO_LIST, IDS_BOOLTEXT_STRING, (value)); + +#define PROP_UINT(text, value)\ + m_ctlProperties.AddString(text, ID_PROPERTY_TEXT, _itot((int)(value), m_szBuffer, 10), 0); + +#define PROP_COMBO(text, prop_text, value)\ + m_ctlProperties.AddString(text, ID_PROPERTY_COMBO_LIST, prop_text, (int)((value))); + +#define PROP_DIR(text, prop_text, value)\ + m_ctlProperties.AddString(text, ID_PROPERTY_DIR, (value)+CString(GetResManager()->LoadString(prop_text)), 0); + +#define PROP_PATH(text, prop_text, value)\ + m_ctlProperties.AddString(text, ID_PROPERTY_PATH, (value)+CString(GetResManager()->LoadString(prop_text)), 0); + +#define PROP_CUSTOM_UINT(text, value, callback, param)\ + m_ctlProperties.AddString(text, ID_PROPERTY_CUSTOM, CString(_itot((int)(value), m_szBuffer, 10)), callback, this, param, 0); + +#define SKIP_SEPARATOR(pos)\ + pos++; + +BOOL COptionsDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + m_ctlProperties.Init(); + + // copy shortcut and recent paths + icpf::config* pConfig = GetConfig(); + assert(pConfig); + if(!pConfig) + return FALSE; + + m_cvRecent.clear(true); + size_t stSize = pConfig->get_value_count(PP_RECENTPATHS); + const tchar_t* pszPath = NULL; + for(size_t stIndex = 0; stIndex < stSize; stIndex++) + { + pszPath = pConfig->get_string(PP_RECENTPATHS, stIndex); + if(pszPath) + m_cvRecent.push_back(pszPath); + } + + m_cvShortcuts.clear(true); + stSize = pConfig->get_value_count(PP_SHORTCUTS); + for(size_t stIndex = 0; stIndex < stSize; stIndex++) + { + pszPath = pConfig->get_string(PP_SHORTCUTS, stIndex); + if(pszPath) + m_cvShortcuts.push_back(pszPath); + } + + _tcscpy(m_szLangPath, _T("\\Langs\\")); + GetApp()->ExpandPath(m_szLangPath); + + GetResManager()->Scan(m_szLangPath, &m_vld); + + // some attributes + m_ctlProperties.SetBkColor(RGB(255, 255, 255)); + m_ctlProperties.SetTextColor(RGB(80, 80, 80)); + m_ctlProperties.SetTextHighlightColor(RGB(80,80,80)); + m_ctlProperties.SetHighlightColor(RGB(200, 200, 200)); + m_ctlProperties.SetPropertyBkColor(RGB(255,255,255)); + m_ctlProperties.SetPropertyTextColor(RGB(0,0,0)); + m_ctlProperties.SetLineStyle(RGB(74,109,132), PS_SOLID); + + FillPropertyList(); + + return TRUE; +} + +void CustomPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex) +{ + COptionsDlg* pDlg=static_cast(lpParam); + CBufferSizeDlg dlg; + + dlg.m_bsSizes.m_bOnlyDefault=pDlg->GetBoolProp(iIndex-iParam-1); + dlg.m_bsSizes.m_uiDefaultSize=pDlg->GetUintProp(iIndex-iParam); + dlg.m_bsSizes.m_uiOneDiskSize=pDlg->GetUintProp(iIndex-iParam+1); + dlg.m_bsSizes.m_uiTwoDisksSize=pDlg->GetUintProp(iIndex-iParam+2); + dlg.m_bsSizes.m_uiCDSize=pDlg->GetUintProp(iIndex-iParam+3); + dlg.m_bsSizes.m_uiLANSize=pDlg->GetUintProp(iIndex-iParam+4); + dlg.m_iActiveIndex=iParam; // selected buffer for editing + + if (dlg.DoModal() == IDOK) + { + PROPERTYITEM* pItem; + TCHAR xx[32]; + + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam-1)); + pItem->nPropertySelected=(dlg.m_bsSizes.m_bOnlyDefault ? 1 : 0); + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam)); + pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiDefaultSize, xx, 10)); + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+1)); + pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiOneDiskSize, xx, 10)); + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+2)); + pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiTwoDisksSize, xx, 10)); + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+3)); + pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiCDSize, xx, 10)); + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex-iParam+4)); + pItem->csProperties.SetAt(0, _itot(dlg.m_bsSizes.m_uiLANSize, xx, 10)); + } +} + +void ShortcutsPropertyCallbackProc(LPVOID lpParam, int /*iParam*/, CPtrList* pList, int iIndex) +{ + COptionsDlg* pDlg=static_cast(lpParam); + + CShortcutsDlg dlg; + dlg.m_cvShortcuts.assign(pDlg->m_cvShortcuts.begin(), pDlg->m_cvShortcuts.end(), true, true); + dlg.m_pcvRecent=&pDlg->m_cvRecent; + if (dlg.DoModal() == IDOK) + { + // restore shortcuts to pDlg->cvShortcuts + pDlg->m_cvShortcuts.assign(dlg.m_cvShortcuts.begin(), dlg.m_cvShortcuts.end(), true, false); + dlg.m_cvShortcuts.erase(dlg.m_cvShortcuts.begin(), dlg.m_cvShortcuts.end(), false); + + // property list + TCHAR szBuf[32]; + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex)); + pItem->csProperties.SetAt(0, _itot(pDlg->m_cvShortcuts.size(), szBuf, 10)); + } +} + +void RecentPropertyCallbackProc(LPVOID lpParam, int /*iParam*/, CPtrList* pList, int iIndex) +{ + COptionsDlg* pDlg=static_cast(lpParam); + + CRecentDlg dlg; + dlg.m_cvRecent.assign(pDlg->m_cvRecent.begin(), pDlg->m_cvRecent.end(), true, true); + if (dlg.DoModal() == IDOK) + { + // restore + pDlg->m_cvRecent.assign(dlg.m_cvRecent.begin(), dlg.m_cvRecent.end(), true, false); + dlg.m_cvRecent.erase(dlg.m_cvRecent.begin(), dlg.m_cvRecent.end(), false); + + // property list + TCHAR szBuf[32]; + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)pList->GetAt(pList->FindIndex(iIndex)); + pItem->csProperties.SetAt(0, _itot(pDlg->m_cvRecent.size(), szBuf, 10)); + } +} + +void COptionsDlg::OnOK() +{ + // kill focuses + m_ctlProperties.HideControls(); + + ApplyProperties(); + + SendClosingNotify(); + CLanguageDialog::OnOK(); +} + +void COptionsDlg::FillPropertyList() +{ + CString strPath; + + // load settings + PROP_SEPARATOR(IDS_PROGRAM_STRING) + PROP_BOOL(IDS_CLIPBOARDMONITORING_STRING, GetConfig()->get_bool(PP_PCLIPBOARDMONITORING)) + PROP_UINT(IDS_CLIPBOARDINTERVAL_STRING, GetConfig()->get_signed_num(PP_PMONITORSCANINTERVAL)) + PROP_BOOL(IDS_AUTORUNPROGRAM_STRING, GetConfig()->get_bool(PP_PRELOADAFTERRESTART)) + PROP_BOOL(IDS_AUTOSHUTDOWN_STRING, GetConfig()->get_bool(PP_PSHUTDOWNAFTREFINISHED)) + PROP_UINT(IDS_SHUTDOWNTIME_STRING, GetConfig()->get_signed_num(PP_PTIMEBEFORESHUTDOWN)) + PROP_COMBO(IDS_FORCESHUTDOWN_STRING, IDS_FORCESHUTDOWNVALUES_STRING, GetConfig()->get_bool(PP_PFORCESHUTDOWN)) + PROP_UINT(IDS_AUTOSAVEINTERVAL_STRING, GetConfig()->get_signed_num(PP_PAUTOSAVEINTERVAL)) + PROP_COMBO(IDS_CFGPRIORITYCLASS_STRING, IDS_CFGPRIORITYCLASSITEMS_STRING, PriorityClassToIndex(GetConfig()->get_signed_num(PP_PPROCESSPRIORITYCLASS))) + PROP_DIR(IDS_TEMPFOLDER_STRING, IDS_TEMPFOLDERCHOOSE_STRING, strPath) + + // lang + CString strLangs; + UINT uiIndex=0; + for (vector::iterator it=m_vld.begin();it != m_vld.end();it++) + { + strLangs+=(*it).GetLangName(); + strLangs+=_T("!"); + if (_tcsicmp((*it).GetFilename(true), GetResManager()->m_ld.GetFilename(true)) == 0) + uiIndex=it-m_vld.begin(); + } + strLangs.TrimRight(_T('!')); + + PROP_COMBO(IDS_LANGUAGE_STRING, strLangs, uiIndex) + + ///////////////// + PROP_SEPARATOR(IDS_STATUSWINDOW_STRING); + PROP_UINT(IDS_REFRESHSTATUSINTERVAL_STRING, GetConfig()->get_signed_num(PP_STATUSREFRESHINTERVAL)) + PROP_BOOL(IDS_STATUSSHOWDETAILS_STRING, GetConfig()->get_bool(PP_STATUSSHOWDETAILS)) + PROP_BOOL(IDS_STATUSAUTOREMOVE_STRING, GetConfig()->get_bool(PP_STATUSAUTOREMOVEFINISHED)) + + PROP_SEPARATOR(IDS_MINIVIEW_STRING) + PROP_BOOL(IDS_SHOWFILENAMES_STRING, GetConfig()->get_bool(PP_MVSHOWFILENAMES)) + PROP_BOOL(IDS_SHOWSINGLETASKS_STRING, GetConfig()->get_bool(PP_MVSHOWSINGLETASKS)) + PROP_UINT(IDS_MINIVIEWREFRESHINTERVAL_STRING, GetConfig()->get_signed_num(PP_MVREFRESHINTERVAL)) + PROP_BOOL(IDS_MINIVIEWSHOWAFTERSTART_STRING, GetConfig()->get_bool(PP_MVAUTOSHOWWHENRUN)) + PROP_BOOL(IDS_MINIVIEWAUTOHIDE_STRING, GetConfig()->get_bool(PP_MVAUTOHIDEWHENEMPTY)) + PROP_BOOL(IDS_MINIVIEWSMOOTHPROGRESS_STRING, GetConfig()->get_bool(PP_MVUSESMOOTHPROGRESS)) + + PROP_SEPARATOR(IDS_CFGFOLDERDIALOG_STRING) + PROP_BOOL(IDS_CFGFDEXTVIEW_STRING, GetConfig()->get_bool(PP_FDEXTENDEDVIEW)) + PROP_UINT(IDS_CFGFDWIDTH_STRING, GetConfig()->get_signed_num(PP_FDWIDTH)) + PROP_UINT(IDS_CFGFDHEIGHT_STRING, GetConfig()->get_signed_num(PP_FDHEIGHT)) + PROP_COMBO(IDS_CFGFDSHORTCUTS_STRING, IDS_CFGFDSHORTCUTSSTYLES_STRING, GetConfig()->get_signed_num(PP_FDSHORTCUTLISTSTYLE)) + PROP_BOOL(IDS_CFGFDIGNOREDIALOGS_STRING, GetConfig()->get_bool(PP_FDIGNORESHELLDIALOGS)) + + PROP_SEPARATOR(IDS_CFGSHELL_STRING) + PROP_BOOL(IDS_CFGSHCOPY_STRING, GetConfig()->get_bool(PP_SHSHOWCOPY)) + PROP_BOOL(IDS_CFGSHMOVE_STRING, GetConfig()->get_bool(PP_SHSHOWMOVE)) + PROP_BOOL(IDS_CFGSHCMSPECIAL_STRING, GetConfig()->get_bool(PP_SHSHOWCOPYMOVE)) + PROP_BOOL(IDS_CFGSHPASTE_STRING, GetConfig()->get_bool(PP_SHSHOWPASTE)) + PROP_BOOL(IDS_CFGSHPASTESPECIAL_STRING, GetConfig()->get_bool(PP_SHSHOWPASTESPECIAL)) + PROP_BOOL(IDS_CFGSHCOPYTO_STRING, GetConfig()->get_bool(PP_SHSHOWCOPYTO)) + PROP_BOOL(IDS_CFGSHMOVETO_STRING, GetConfig()->get_bool(PP_SHSHOWMOVETO)) + PROP_BOOL(IDS_CFGSHCMTOSPECIAL_STRING, GetConfig()->get_bool(PP_SHSHOWCOPYMOVETO)) + PROP_BOOL(IDS_CFGSHSHOWFREESPACE_STRING, GetConfig()->get_bool(PP_SHSHOWFREESPACE)) + PROP_BOOL(IDS_CFGSHSHOWICONS_STRING, GetConfig()->get_bool(PP_SHSHOWSHELLICONS)) + PROP_BOOL(IDS_CFGSHOVERRIDEDRAG_STRING, GetConfig()->get_bool(PP_SHUSEDRAGDROP)) + PROP_COMBO(IDS_CFGOVERRIDEDEFACTION_STRING, IDS_CFGACTIONS_STRING, GetConfig()->get_signed_num(PP_SHDEFAULTACTION)); + + PROP_SEPARATOR(IDS_PROCESSINGTHREAD_STRING) + PROP_BOOL(IDS_AUTOCOPYREST_STRING, GetConfig()->get_bool(PP_CMUSEAUTOCOMPLETEFILES)) + PROP_BOOL(IDS_SETDESTATTRIB_STRING, GetConfig()->get_bool(PP_CMSETDESTATTRIBUTES)) + PROP_BOOL(IDS_SETDESTTIME_STRING, GetConfig()->get_bool(PP_CMSETDESTDATE)) + PROP_BOOL(IDS_PROTECTROFILES_STRING, GetConfig()->get_bool(PP_CMPROTECTROFILES)) + PROP_UINT(IDS_LIMITOPERATIONS_STRING, GetConfig()->get_signed_num(PP_CMLIMITMAXOPERATIONS)) + PROP_BOOL(IDS_READSIZEBEFOREBLOCK_STRING, GetConfig()->get_bool(PP_CMREADSIZEBEFOREBLOCKING)) + PROP_COMBO(IDS_SHOWVISUALFEEDBACK_STRING, IDS_FEEDBACKTYPE_STRING, GetConfig()->get_signed_num(PP_CMSHOWVISUALFEEDBACK)) + PROP_BOOL(IDS_USETIMEDDIALOGS_STRING, GetConfig()->get_bool(PP_CMUSETIMEDFEEDBACK)) + PROP_UINT(IDS_TIMEDDIALOGINTERVAL_STRING, GetConfig()->get_signed_num(PP_CMFEEDBACKTIME)) + PROP_BOOL(IDS_AUTORETRYONERROR_STRING, GetConfig()->get_bool(PP_CMAUTORETRYONERROR)) + PROP_UINT(IDS_AUTORETRYINTERVAL_STRING, GetConfig()->get_signed_num(PP_CMAUTORETRYINTERVAL)) + PROP_COMBO(IDS_DEFAULTPRIORITY_STRING, MakeCompoundString(IDS_PRIORITY0_STRING, 7, _T("!")), PriorityToIndex(GetConfig()->get_signed_num(PP_CMDEFAULTPRIORITY))) + PROP_BOOL(IDS_CFGDISABLEPRIORITYBOOST_STRING, GetConfig()->get_bool(PP_CMDISABLEPRIORITYBOOST)) + PROP_BOOL(IDS_DELETEAFTERFINISHED_STRING, GetConfig()->get_bool(PP_CMDELETEAFTERFINISHED)) + PROP_BOOL(IDS_CREATELOGFILES_STRING, GetConfig()->get_bool(PP_CMCREATELOG)) + + // Buffer + PROP_SEPARATOR(IDS_OPTIONSBUFFER_STRING) + PROP_BOOL(IDS_AUTODETECTBUFFERSIZE_STRING, GetConfig()->get_bool(PP_BFUSEONLYDEFAULT)) + PROP_CUSTOM_UINT(IDS_DEFAULTBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFDEFAULT), &CustomPropertyCallbackProc, 0) + PROP_CUSTOM_UINT(IDS_ONEDISKBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFONEDISK), &CustomPropertyCallbackProc, 1) + PROP_CUSTOM_UINT(IDS_TWODISKSBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFTWODISKS), &CustomPropertyCallbackProc, 2) + PROP_CUSTOM_UINT(IDS_CDBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFCD), &CustomPropertyCallbackProc, 3) + PROP_CUSTOM_UINT(IDS_LANBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_BFLAN), &CustomPropertyCallbackProc, 4) + PROP_BOOL(IDS_USENOBUFFERING_STRING, GetConfig()->get_bool(PP_BFUSENOBUFFERING)) + PROP_UINT(IDS_LARGEFILESMINSIZE_STRING, GetConfig()->get_signed_num(PP_BFBOUNDARYLIMIT)) + + + // Sounds + PROP_SEPARATOR(IDS_SOUNDS_STRING) + PROP_BOOL(IDS_PLAYSOUNDS_STRING, GetConfig()->get_bool(PP_SNDPLAYSOUNDS)) + GetConfig()->get_string(PP_SNDERRORSOUNDPATH, strPath.GetBuffer(_MAX_PATH), _MAX_PATH); + strPath.ReleaseBuffer(); + PROP_PATH(IDS_SOUNDONERROR_STRING, IDS_SOUNDSWAVFILTER_STRING, strPath) + GetConfig()->get_string(PP_SNDFINISHEDSOUNDPATH, strPath.GetBuffer(_MAX_PATH), _MAX_PATH); + strPath.ReleaseBuffer(); + PROP_PATH(IDS_SOUNDONFINISH_STRING, IDS_SOUNDSWAVFILTER_STRING, strPath) + + PROP_SEPARATOR(IDS_CFGSHORTCUTS_STRING) + PROP_CUSTOM_UINT(IDS_CFGSCCOUNT_STRING, m_cvShortcuts.size(), &ShortcutsPropertyCallbackProc, 0) + + PROP_SEPARATOR(IDS_CFGRECENT_STRING) + PROP_CUSTOM_UINT(IDS_CFGRPCOUNT_STRING, m_cvRecent.size(), &RecentPropertyCallbackProc, 0) + + /* PROP_SEPARATOR(IDS_CFGLOGFILE_STRING) + PROP_BOOL(IDS_CFGENABLELOGGING_STRING, GetConfig()->get_bool(PP_LOGENABLELOGGING)) + PROP_BOOL(IDS_CFGLIMITATION_STRING, GetConfig()->get_bool(PP_LOGLIMITATION)) + PROP_UINT(IDS_CFGMAXLIMIT_STRING, GetConfig()->get_signed_num(PP_LOGMAXLIMIT)) + PROP_BOOL(IDS_CFGLOGPRECISELIMITING_STRING, GetConfig()->get_bool(PP_LOGPRECISELIMITING)) + PROP_UINT(IDS_CFGTRUNCBUFFERSIZE_STRING, GetConfig()->get_signed_num(PP_LOGTRUNCBUFFERSIZE))*/ +} + +void COptionsDlg::ApplyProperties() +{ + // counter + int iPosition=0; + + icpf::config* pConfig = GetConfig(); + assert(pConfig); + if(!pConfig) + return; + + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_PCLIPBOARDMONITORING, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_PMONITORSCANINTERVAL, GetUintProp(iPosition++)); + pConfig->set_bool(PP_PRELOADAFTERRESTART, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_PSHUTDOWNAFTREFINISHED, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_PTIMEBEFORESHUTDOWN, GetUintProp(iPosition++)); + pConfig->set_bool(PP_PFORCESHUTDOWN, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_PAUTOSAVEINTERVAL, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_PPROCESSPRIORITYCLASS, IndexToPriorityClass(GetIndexProp(iPosition++))); + // language + PCTSTR pszSrc=m_vld.at(GetIndexProp(iPosition++)).GetFilename(true); + if (_tcsnicmp(pszSrc, GetApp()->GetProgramPath(), _tcslen(GetApp()->GetProgramPath())) == 0) + { + // replace the first part of path with + TCHAR szData[_MAX_PATH]; + _sntprintf(szData, _MAX_PATH, _T("%s"), pszSrc+_tcslen(GetApp()->GetProgramPath())); + pConfig->set_string(PP_PLANGUAGE, szData); + } + else + pConfig->set_string(PP_PLANGUAGE, pszSrc); + + SKIP_SEPARATOR(iPosition) + pConfig->set_signed_num(PP_STATUSREFRESHINTERVAL, GetUintProp(iPosition++)); + pConfig->set_bool(PP_STATUSSHOWDETAILS, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_STATUSAUTOREMOVEFINISHED, GetBoolProp(iPosition++)); + + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_MVSHOWFILENAMES, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_MVSHOWSINGLETASKS, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_MVREFRESHINTERVAL, GetUintProp(iPosition++)); + pConfig->set_bool(PP_MVAUTOSHOWWHENRUN, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_MVAUTOHIDEWHENEMPTY, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_MVUSESMOOTHPROGRESS, GetBoolProp(iPosition++)); + + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_FDEXTENDEDVIEW, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_FDWIDTH, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_FDHEIGHT, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_FDSHORTCUTLISTSTYLE, GetIndexProp(iPosition++)); + pConfig->set_bool(PP_FDIGNORESHELLDIALOGS, GetBoolProp(iPosition++)); + + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_SHSHOWCOPY, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWMOVE, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWCOPYMOVE, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWPASTE, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWPASTESPECIAL, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWCOPYTO, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWMOVETO, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWCOPYMOVETO, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWFREESPACE, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHSHOWSHELLICONS, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_SHUSEDRAGDROP, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_SHDEFAULTACTION, GetIndexProp(iPosition++)); + + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_CMUSEAUTOCOMPLETEFILES, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_CMSETDESTATTRIBUTES, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_CMSETDESTDATE, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_CMPROTECTROFILES, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_CMLIMITMAXOPERATIONS, GetUintProp(iPosition++)); + pConfig->set_bool(PP_CMREADSIZEBEFOREBLOCKING, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_CMSHOWVISUALFEEDBACK, GetIndexProp(iPosition++)); + pConfig->set_bool(PP_CMUSETIMEDFEEDBACK, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_CMFEEDBACKTIME, GetUintProp(iPosition++)); + pConfig->set_bool(PP_CMAUTORETRYONERROR, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_CMAUTORETRYINTERVAL, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_CMDEFAULTPRIORITY, IndexToPriority(GetIndexProp(iPosition++))); + pConfig->set_bool(PP_CMDISABLEPRIORITYBOOST, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_CMDELETEAFTERFINISHED, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_CMCREATELOG, GetBoolProp(iPosition++)); + + // Buffer + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_BFUSEONLYDEFAULT, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_BFDEFAULT, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_BFONEDISK, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_BFTWODISKS, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_BFCD, GetUintProp(iPosition++)); + pConfig->set_signed_num(PP_BFLAN, GetUintProp(iPosition++)); + pConfig->set_bool(PP_BFUSENOBUFFERING, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_BFBOUNDARYLIMIT, GetUintProp(iPosition++)); + + // log file +/* SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_LOGENABLELOGGING, GetBoolProp(iPosition++)); + pConfig->set_bool(PP_LOGLIMITATION, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_LOGMAXLIMIT, GetUintProp(iPosition++)); + pConfig->set_bool(PP_LOGPRECISELIMITING, GetBoolProp(iPosition++)); + pConfig->set_signed_num(PP_LOGTRUNCBUFFERSIZE, GetUintProp(iPosition++));*/ + + // Sounds + SKIP_SEPARATOR(iPosition) + pConfig->set_bool(PP_SNDPLAYSOUNDS, GetBoolProp(iPosition++)); + pConfig->set_string(PP_SNDERRORSOUNDPATH, GetStringProp(iPosition++)); + pConfig->set_string(PP_SNDFINISHEDSOUNDPATH, GetStringProp(iPosition++)); + + // shortcuts & recent paths + SKIP_SEPARATOR(iPosition) + pConfig->clear_array_values(PP_SHORTCUTS); + for(char_vector::iterator it = m_cvShortcuts.begin(); it != m_cvShortcuts.end(); it++) + { + pConfig->set_string(PP_SHORTCUTS, (*it), icpf::property::action_add); + } + + SKIP_SEPARATOR(iPosition) + pConfig->clear_array_values(PP_RECENTPATHS); + for(char_vector::iterator it = m_cvRecent.begin(); it != m_cvRecent.end(); it++) + { + pConfig->set_string(PP_RECENTPATHS, (*it), icpf::property::action_add); + } + + pConfig->write(NULL); +} + +void COptionsDlg::OnCancel() +{ + SendClosingNotify(); + CLanguageDialog::OnCancel(); +} + +void COptionsDlg::SendClosingNotify() +{ + GetParent()->PostMessage(WM_CONFIGNOTIFY); +} + +CString COptionsDlg::MakeCompoundString(UINT uiBase, int iCount, LPCTSTR lpszSeparator) +{ + assert(lpszSeparator); + if(!lpszSeparator) + return _T(""); + _tcscpy(m_szBuffer, GetResManager()->LoadString(uiBase+0)); + for (int i=1;iLoadString(uiBase+i)); + } + + return CString((PCTSTR)m_szBuffer); +} + +bool COptionsDlg::GetBoolProp(int iPosition) +{ + m_ctlProperties.GetProperty(iPosition, &m_iSel); + return m_iSel != 0; +} + +UINT COptionsDlg::GetUintProp(int iPosition) +{ + m_ctlProperties.GetProperty(iPosition, &m_strTemp); + return _ttoi(m_strTemp); +} + +CString COptionsDlg::GetStringProp(int iPosition) +{ + m_ctlProperties.GetProperty(iPosition, &m_strTemp); + return m_strTemp; +} + +int COptionsDlg::GetIndexProp(int iPosition) +{ + m_ctlProperties.GetProperty(iPosition, &m_iSel); + return m_iSel; +} + +void COptionsDlg::OnApplyButton() +{ + // kill focuses + m_ctlProperties.HideControls(); + + ApplyProperties(); +} + +void COptionsDlg::OnLanguageChanged() +{ + m_ctlProperties.Reinit(); + + // set attributes + m_ctlProperties.SetBkColor(RGB(255, 255, 255)); + m_ctlProperties.SetTextColor(RGB(80, 80, 80)); + m_ctlProperties.SetTextHighlightColor(RGB(80,80,80)); + m_ctlProperties.SetHighlightColor(RGB(200, 200, 200)); + m_ctlProperties.SetPropertyBkColor(RGB(255,255,255)); + m_ctlProperties.SetPropertyTextColor(RGB(0,0,0)); + m_ctlProperties.SetLineStyle(RGB(74,109,132), PS_SOLID); + + FillPropertyList(); +} Index: src/ch/OptionsDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/OptionsDlg.h (.../OptionsDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/OptionsDlg.h (.../OptionsDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,97 +1,97 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __OPTIONSDLG_H__ -#define __OPTIONSDLG_H__ - -#include "PropertyListCtrl.h" -#include "structs.h" -#include "shortcuts.h" -#include "charvect.h" - -#define WM_CONFIGNOTIFY WM_USER+13 - -///////////////////////////////////////////////////////////////////////////// -// COptionsDlg dialog - -class COptionsDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - void SendClosingNotify(); - COptionsDlg(CWnd* pParent = NULL); // standard constructor - - virtual void OnLanguageChanged(); - - static bool m_bLock; // locker - - char_vector m_cvRecent; - char_vector m_cvShortcuts; - - // for languages - vector m_vld; - TCHAR m_szLangPath[_MAX_PATH]; // the full path to a folder with langs (@read) - - friend void CustomPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex); - friend void ShortcutsPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex); - friend void RecentPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex); - -// Dialog Data - //{{AFX_DATA(COptionsDlg) - enum { IDD = IDD_OPTIONS_DIALOG }; - CPropertyListCtrl m_ctlProperties; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(COptionsDlg) - public: - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - void FillPropertyList(); - void ApplyProperties(); - - int GetIndexProp(int iPosition); - CString GetStringProp(int iPosition); - UINT GetUintProp(int iPosition); - bool GetBoolProp(int iPosition); - CString MakeCompoundString(UINT uiBase, int iCount, LPCTSTR lpszSeparator); - - TCHAR m_szBuffer[_MAX_PATH]; // for macro use - CString m_strTemp; - int m_iSel; - - // Generated message map functions - //{{AFX_MSG(COptionsDlg) - virtual BOOL OnInitDialog(); - virtual void OnOK(); - virtual void OnCancel(); - afx_msg void OnApplyButton(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __OPTIONSDLG_H__ +#define __OPTIONSDLG_H__ + +#include "PropertyListCtrl.h" +#include "structs.h" +#include "shortcuts.h" +#include "charvect.h" + +#define WM_CONFIGNOTIFY WM_USER+13 + +///////////////////////////////////////////////////////////////////////////// +// COptionsDlg dialog + +class COptionsDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + void SendClosingNotify(); + COptionsDlg(CWnd* pParent = NULL); // standard constructor + + virtual void OnLanguageChanged(); + + static bool m_bLock; // locker + + char_vector m_cvRecent; + char_vector m_cvShortcuts; + + // for languages + vector m_vld; + TCHAR m_szLangPath[_MAX_PATH]; // the full path to a folder with langs (@read) + + friend void CustomPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex); + friend void ShortcutsPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex); + friend void RecentPropertyCallbackProc(LPVOID lpParam, int iParam, CPtrList* pList, int iIndex); + +// Dialog Data + //{{AFX_DATA(COptionsDlg) + enum { IDD = IDD_OPTIONS_DIALOG }; + CPropertyListCtrl m_ctlProperties; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(COptionsDlg) + public: + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + void FillPropertyList(); + void ApplyProperties(); + + int GetIndexProp(int iPosition); + CString GetStringProp(int iPosition); + UINT GetUintProp(int iPosition); + bool GetBoolProp(int iPosition); + CString MakeCompoundString(UINT uiBase, int iCount, LPCTSTR lpszSeparator); + + TCHAR m_szBuffer[_MAX_PATH]; // for macro use + CString m_strTemp; + int m_iSel; + + // Generated message map functions + //{{AFX_MSG(COptionsDlg) + virtual BOOL OnInitDialog(); + virtual void OnOK(); + virtual void OnCancel(); + afx_msg void OnApplyButton(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/ProgressListBox.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ProgressListBox.cpp (.../ProgressListBox.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ProgressListBox.cpp (.../ProgressListBox.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,244 +1,244 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ProgressListBox.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -//#define USE_SMOOTH_PROGRESS - -///////////////////////////////////////////////////////////////////////////// -// CProgressListBox - -CProgressListBox::CProgressListBox() -{ - m_bShowCaptions=true; - m_bSmoothProgress=false; -} - -CProgressListBox::~CProgressListBox() -{ - for (int i=0;iitemID == -1) - return; - _PROGRESSITEM_* pItem=m_items.GetAt(lpDrawItemStruct->itemID); - - // device context - CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); - pDC->SetBkMode(TRANSPARENT); - - if (lpDrawItemStruct->itemState & ODS_SELECTED) - { - // fill with color, because in other way the trash appears - pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_3DFACE)); - CPoint apt[3]={ CPoint(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top+(lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top)/4), - CPoint(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top+3*((lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top)/4)), - CPoint(lpDrawItemStruct->rcItem.left+7, lpDrawItemStruct->rcItem.top+(lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top)/2) }; - pDC->Polygon(apt, 3); - lpDrawItemStruct->rcItem.left+=10; - } - - // draw text - if (m_bShowCaptions) - { - CRect rcText(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top+2, - lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom-(9+2)); - pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); - pDC->DrawText(pItem->m_strText, &rcText, - DT_PATH_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); - } - - // frame sizes - int iEdgeWidth=1/*GetSystemMetrics(SM_CXEDGE)*/; - int iEdgeHeight=1/*GetSystemMetrics(SM_CYEDGE)*/; - - // progress like drawing - int iBoxWidth=static_cast(static_cast(((9+2)-2*iEdgeWidth))*(2.0/3.0))+1; - CRect rcProgress(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom-(9+2), - lpDrawItemStruct->rcItem.left+2*iEdgeWidth+((lpDrawItemStruct->rcItem.right-lpDrawItemStruct->rcItem.left-2*iEdgeWidth)/iBoxWidth)*iBoxWidth, - lpDrawItemStruct->rcItem.bottom); - - // edge - pDC->Draw3dRect(&rcProgress, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHIGHLIGHT)); - - if (!m_bSmoothProgress) - { - // boxes within edge - double dCount=static_cast(static_cast(((rcProgress.Width()-2*iEdgeHeight)/iBoxWidth)) - *(static_cast(pItem->m_uiPos)/static_cast(pItem->m_uiRange))); - int iBoxCount=((dCount-static_cast(dCount)) > 0.2) ? static_cast(dCount)+1 : static_cast(dCount); - - for (int i=0;iFillSolidRect(lpDrawItemStruct->rcItem.left+i*iBoxWidth+iEdgeWidth+1, - lpDrawItemStruct->rcItem.bottom-(9+2)+iEdgeHeight+1, - iBoxWidth-2, rcProgress.Height()-2*iEdgeHeight-2, pItem->m_crColor); - } - else - { - pDC->FillSolidRect(lpDrawItemStruct->rcItem.left+iEdgeWidth+1, lpDrawItemStruct->rcItem.bottom-(9+2)+iEdgeHeight+1, - static_cast((rcProgress.Width()-2*iEdgeHeight-3)*(static_cast(pItem->m_uiPos)/static_cast(pItem->m_uiRange))), - rcProgress.Height()-2*iEdgeHeight-2, pItem->m_crColor); - } -} - -bool CProgressListBox::GetShowCaptions() -{ - return m_bShowCaptions; -} - -void CProgressListBox::SetShowCaptions(bool bShow) -{ - if (bShow != m_bShowCaptions) - { - m_bShowCaptions=bShow; - if (bShow) - { - CClientDC dc(this); - dc.SelectObject(GetFont()); - TEXTMETRIC tm; - dc.GetTextMetrics(&tm); - int iHeight=MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY); - - SetItemHeight(0, 9+2+2+iHeight); - } - else - SetItemHeight(0, 9+2+2); - - RecalcHeight(); - } -} - -void CProgressListBox::RecalcHeight() -{ - // new height - int iCtlHeight=m_items.GetSize()*GetItemHeight(0); - - // change control size - CRect rcCtl; - GetClientRect(&rcCtl); - this->SetWindowPos(NULL, 0, 0, rcCtl.Width(), iCtlHeight, SWP_NOZORDER | SWP_NOMOVE); -} - -void CProgressListBox::Init() -{ - // set new height of an item - CClientDC dc(this); - TEXTMETRIC tm; - dc.GetTextMetrics(&tm); - int iHeight=MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY); - SetItemHeight(0, m_bShowCaptions ? iHeight+2+9+2 : 2+9+2); -} - -_PROGRESSITEM_* CProgressListBox::GetItemAddress(int iIndex) -{ - if (m_items.GetSize() > iIndex) - return m_items.GetAt(iIndex); - else - { - _PROGRESSITEM_* pItem=new _PROGRESSITEM_; - pItem->m_uiRange=100; - m_items.Add(pItem); - return pItem; - } -} - -void CProgressListBox::UpdateItems(int nLimit, bool bUpdateSize) -{ - // delete items from array - while (m_items.GetSize() > nLimit) - { - delete m_items.GetAt(nLimit); - m_items.RemoveAt(nLimit); - } - - // change count of elements in a listbox - if (GetCount() != m_items.GetSize()) - { - while (GetCount() < m_items.GetSize()) - AddString(_T("")); - - while (GetCount() > m_items.GetSize()) - DeleteString(m_items.GetSize()); - } - - if (bUpdateSize) - { - Invalidate(); - RecalcHeight(); - } -} - -void CProgressListBox::OnPaint() -{ - CPaintDC dc(this); // device context for painting - CRect rcClip; - dc.GetClipBox(&rcClip); - - CMemDC memDC(&dc, &rcClip); - memDC.FillSolidRect(&rcClip, GetSysColor(COLOR_3DFACE)); - - DefWindowProc(WM_PAINT, reinterpret_cast(memDC.m_hDC), 0); -} - -BOOL CProgressListBox::OnEraseBkgnd(CDC*) -{ - return FALSE/*CListBox::OnEraseBkgnd(pDC)*/; -} - -int CProgressListBox::SetCurSel(int nSelect) -{ - int nResult=static_cast(this)->SetCurSel(nSelect); - if (nSelect == -1) - GetParent()->SendMessage(WM_COMMAND, (LBN_SELCANCEL << 16) | GetDlgCtrlID(), reinterpret_cast(this->m_hWnd)); - - return nResult; -} - -void CProgressListBox::OnKillfocus() -{ - SetCurSel(-1); -} - -void CProgressListBox::SetSmoothProgress(bool bSmoothProgress) -{ - m_bSmoothProgress=bSmoothProgress; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ProgressListBox.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +//#define USE_SMOOTH_PROGRESS + +///////////////////////////////////////////////////////////////////////////// +// CProgressListBox + +CProgressListBox::CProgressListBox() +{ + m_bShowCaptions=true; + m_bSmoothProgress=false; +} + +CProgressListBox::~CProgressListBox() +{ + for (int i=0;iitemID == -1) + return; + _PROGRESSITEM_* pItem=m_items.GetAt(lpDrawItemStruct->itemID); + + // device context + CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); + pDC->SetBkMode(TRANSPARENT); + + if (lpDrawItemStruct->itemState & ODS_SELECTED) + { + // fill with color, because in other way the trash appears + pDC->FillSolidRect(&lpDrawItemStruct->rcItem, GetSysColor(COLOR_3DFACE)); + CPoint apt[3]={ CPoint(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top+(lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top)/4), + CPoint(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top+3*((lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top)/4)), + CPoint(lpDrawItemStruct->rcItem.left+7, lpDrawItemStruct->rcItem.top+(lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top)/2) }; + pDC->Polygon(apt, 3); + lpDrawItemStruct->rcItem.left+=10; + } + + // draw text + if (m_bShowCaptions) + { + CRect rcText(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top+2, + lpDrawItemStruct->rcItem.right, lpDrawItemStruct->rcItem.bottom-(9+2)); + pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); + pDC->DrawText(pItem->m_strText, &rcText, + DT_PATH_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); + } + + // frame sizes + int iEdgeWidth=1/*GetSystemMetrics(SM_CXEDGE)*/; + int iEdgeHeight=1/*GetSystemMetrics(SM_CYEDGE)*/; + + // progress like drawing + int iBoxWidth=static_cast(static_cast(((9+2)-2*iEdgeWidth))*(2.0/3.0))+1; + CRect rcProgress(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.bottom-(9+2), + lpDrawItemStruct->rcItem.left+2*iEdgeWidth+((lpDrawItemStruct->rcItem.right-lpDrawItemStruct->rcItem.left-2*iEdgeWidth)/iBoxWidth)*iBoxWidth, + lpDrawItemStruct->rcItem.bottom); + + // edge + pDC->Draw3dRect(&rcProgress, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHIGHLIGHT)); + + if (!m_bSmoothProgress) + { + // boxes within edge + double dCount=static_cast(static_cast(((rcProgress.Width()-2*iEdgeHeight)/iBoxWidth)) + *(static_cast(pItem->m_uiPos)/static_cast(pItem->m_uiRange))); + int iBoxCount=((dCount-static_cast(dCount)) > 0.2) ? static_cast(dCount)+1 : static_cast(dCount); + + for (int i=0;iFillSolidRect(lpDrawItemStruct->rcItem.left+i*iBoxWidth+iEdgeWidth+1, + lpDrawItemStruct->rcItem.bottom-(9+2)+iEdgeHeight+1, + iBoxWidth-2, rcProgress.Height()-2*iEdgeHeight-2, pItem->m_crColor); + } + else + { + pDC->FillSolidRect(lpDrawItemStruct->rcItem.left+iEdgeWidth+1, lpDrawItemStruct->rcItem.bottom-(9+2)+iEdgeHeight+1, + static_cast((rcProgress.Width()-2*iEdgeHeight-3)*(static_cast(pItem->m_uiPos)/static_cast(pItem->m_uiRange))), + rcProgress.Height()-2*iEdgeHeight-2, pItem->m_crColor); + } +} + +bool CProgressListBox::GetShowCaptions() +{ + return m_bShowCaptions; +} + +void CProgressListBox::SetShowCaptions(bool bShow) +{ + if (bShow != m_bShowCaptions) + { + m_bShowCaptions=bShow; + if (bShow) + { + CClientDC dc(this); + dc.SelectObject(GetFont()); + TEXTMETRIC tm; + dc.GetTextMetrics(&tm); + int iHeight=MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY); + + SetItemHeight(0, 9+2+2+iHeight); + } + else + SetItemHeight(0, 9+2+2); + + RecalcHeight(); + } +} + +void CProgressListBox::RecalcHeight() +{ + // new height + int iCtlHeight=m_items.GetSize()*GetItemHeight(0); + + // change control size + CRect rcCtl; + GetClientRect(&rcCtl); + this->SetWindowPos(NULL, 0, 0, rcCtl.Width(), iCtlHeight, SWP_NOZORDER | SWP_NOMOVE); +} + +void CProgressListBox::Init() +{ + // set new height of an item + CClientDC dc(this); + TEXTMETRIC tm; + dc.GetTextMetrics(&tm); + int iHeight=MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY); + SetItemHeight(0, m_bShowCaptions ? iHeight+2+9+2 : 2+9+2); +} + +_PROGRESSITEM_* CProgressListBox::GetItemAddress(int iIndex) +{ + if (m_items.GetSize() > iIndex) + return m_items.GetAt(iIndex); + else + { + _PROGRESSITEM_* pItem=new _PROGRESSITEM_; + pItem->m_uiRange=100; + m_items.Add(pItem); + return pItem; + } +} + +void CProgressListBox::UpdateItems(int nLimit, bool bUpdateSize) +{ + // delete items from array + while (m_items.GetSize() > nLimit) + { + delete m_items.GetAt(nLimit); + m_items.RemoveAt(nLimit); + } + + // change count of elements in a listbox + if (GetCount() != m_items.GetSize()) + { + while (GetCount() < m_items.GetSize()) + AddString(_T("")); + + while (GetCount() > m_items.GetSize()) + DeleteString(m_items.GetSize()); + } + + if (bUpdateSize) + { + Invalidate(); + RecalcHeight(); + } +} + +void CProgressListBox::OnPaint() +{ + CPaintDC dc(this); // device context for painting + CRect rcClip; + dc.GetClipBox(&rcClip); + + CMemDC memDC(&dc, &rcClip); + memDC.FillSolidRect(&rcClip, GetSysColor(COLOR_3DFACE)); + + DefWindowProc(WM_PAINT, reinterpret_cast(memDC.m_hDC), 0); +} + +BOOL CProgressListBox::OnEraseBkgnd(CDC*) +{ + return FALSE/*CListBox::OnEraseBkgnd(pDC)*/; +} + +int CProgressListBox::SetCurSel(int nSelect) +{ + int nResult=static_cast(this)->SetCurSel(nSelect); + if (nSelect == -1) + GetParent()->SendMessage(WM_COMMAND, (LBN_SELCANCEL << 16) | GetDlgCtrlID(), reinterpret_cast(this->m_hWnd)); + + return nResult; +} + +void CProgressListBox::OnKillfocus() +{ + SetCurSel(-1); +} + +void CProgressListBox::SetSmoothProgress(bool bSmoothProgress) +{ + m_bSmoothProgress=bSmoothProgress; +} Index: src/ch/ProgressListBox.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ProgressListBox.h (.../ProgressListBox.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ProgressListBox.h (.../ProgressListBox.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,96 +1,96 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __PROGRESSLISTBOX_H__ -#define __PROGRESSLISTBOX_H__ - -#include "memdc.h" -#include "afxtempl.h" -#include "structs.h" - -///////////////////////////////////////////////////////////////////////////// -// CProgressListBox window -struct _PROGRESSITEM_ -{ - CString m_strText; - - UINT m_uiPos; - UINT m_uiRange; - - COLORREF m_crColor; - - CTask* m_pTask; -}; - -class CProgressListBox : public CListBox -{ -// Construction -public: - CProgressListBox(); - -// Attributes -public: - -// Operations -public: - CArray<_PROGRESSITEM_*, _PROGRESSITEM_*> m_items; - -protected: - bool m_bShowCaptions; - bool m_bSmoothProgress; - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CProgressListBox) - public: - virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); - //}}AFX_VIRTUAL - -// Implementation -public: - void SetSmoothProgress(bool bSmoothProgress); - int SetCurSel( int nSelect ); - void Init(); - - void UpdateItems(int nLimit, bool bUpdateSize); // updates items in listbox - void RecalcHeight(); // sets size of a listbox by counting szie of the items - - _PROGRESSITEM_* GetItemAddress(int iIndex); - - void SetShowCaptions(bool bShow=true); - bool GetShowCaptions(); - - virtual ~CProgressListBox(); - - // Generated message map functions -protected: - //{{AFX_MSG(CProgressListBox) - afx_msg void OnPaint(); - afx_msg BOOL OnEraseBkgnd(CDC*); - afx_msg void OnKillfocus(); - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __PROGRESSLISTBOX_H__ +#define __PROGRESSLISTBOX_H__ + +#include "memdc.h" +#include "afxtempl.h" +#include "structs.h" + +///////////////////////////////////////////////////////////////////////////// +// CProgressListBox window +struct _PROGRESSITEM_ +{ + CString m_strText; + + UINT m_uiPos; + UINT m_uiRange; + + COLORREF m_crColor; + + CTask* m_pTask; +}; + +class CProgressListBox : public CListBox +{ +// Construction +public: + CProgressListBox(); + +// Attributes +public: + +// Operations +public: + CArray<_PROGRESSITEM_*, _PROGRESSITEM_*> m_items; + +protected: + bool m_bShowCaptions; + bool m_bSmoothProgress; + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CProgressListBox) + public: + virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); + //}}AFX_VIRTUAL + +// Implementation +public: + void SetSmoothProgress(bool bSmoothProgress); + int SetCurSel( int nSelect ); + void Init(); + + void UpdateItems(int nLimit, bool bUpdateSize); // updates items in listbox + void RecalcHeight(); // sets size of a listbox by counting szie of the items + + _PROGRESSITEM_* GetItemAddress(int iIndex); + + void SetShowCaptions(bool bShow=true); + bool GetShowCaptions(); + + virtual ~CProgressListBox(); + + // Generated message map functions +protected: + //{{AFX_MSG(CProgressListBox) + afx_msg void OnPaint(); + afx_msg BOOL OnEraseBkgnd(CDC*); + afx_msg void OnKillfocus(); + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() +}; + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/PropertyListCtrl.cpp =================================================================== diff -u -rb6b8ac5b0a1ab85b4ac788e5429be860d2f20bd5 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/PropertyListCtrl.cpp (.../PropertyListCtrl.cpp) (revision b6b8ac5b0a1ab85b4ac788e5429be860d2f20bd5) +++ src/ch/PropertyListCtrl.cpp (.../PropertyListCtrl.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,1275 +1,1275 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "PropertyListCtrl.h" -#include "dialogs.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CComboButton -CComboButton::CComboButton() -{ -} - -CComboButton::~CComboButton() -{ - // Delete the objects created - delete m_pBkBrush; - delete m_pBlackBrush; -// delete m_pGrayPen; - delete m_pBkPen; -} - -BEGIN_MESSAGE_MAP(CComboButton, CButton) - //{{AFX_MSG_MAP(CComboButton) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CComboButton message handlers -BOOL CComboButton::Create( CRect Rect, CWnd* pParent, UINT uID) -{ - // Create the Brushes and Pens - m_pBkBrush = new CBrush( GetSysColor(COLOR_BTNFACE)); - m_pBkPen = new CPen( PS_SOLID, 1, GetSysColor(COLOR_BTNFACE)); -// m_pGrayPen = new CPen( PS_SOLID, 1, RGB(128,128,128)); - m_pBlackBrush = new CBrush(GetSysColor(COLOR_BTNTEXT)); - - // Create the CButton - if( !CButton::Create(_T(""), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, Rect, pParent, uID )) - return FALSE; - - return 0; -} - -///////////////////////////////////////////////////////////////////////////// -// Draw the Button -void CComboButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct ) -{ - CDC* prDC = CDC::FromHandle(lpDrawItemStruct->hDC); - CRect ButtonRect = lpDrawItemStruct->rcItem; - CMemDC dc(prDC, ButtonRect); - CMemDC *pDC=&dc; - - // Fill the Background - CBrush* pOldBrush = (CBrush*)pDC->SelectObject( m_pBkBrush ); - CPen* pOldPen = (CPen*)pDC->SelectObject(m_pBkPen); - pDC->Rectangle(ButtonRect); - - // Draw the Correct Border - if(lpDrawItemStruct->itemState & ODS_SELECTED) - { - pDC->DrawEdge(ButtonRect, EDGE_SUNKEN, BF_RECT); - ButtonRect.left++; - ButtonRect.right++; - ButtonRect.bottom++; - ButtonRect.top++; - } - else - pDC->DrawEdge(ButtonRect, EDGE_RAISED, BF_RECT); - - // Draw the Triangle - ButtonRect.left += 3; - ButtonRect.right -= 4; - ButtonRect.top += 5; - ButtonRect.bottom -= 5; - DrawTriangle(pDC, ButtonRect); - - // Return what was used - pDC->SelectObject( pOldPen ); - pDC->SelectObject( pOldBrush ); -} - -void CComboButton::DrawTriangle(CDC* pDC, CRect Rect) -{ - POINT ptArray[3]; - - // Figure out the Top left - ptArray[0].x = Rect.left; - ptArray[0].y = Rect.top; - ptArray[1].x = Rect.right; - ptArray[1].y = Rect.top; - ptArray[2].x = Rect.right - (Rect.Width() / 2); - ptArray[2].y = Rect.bottom; - - // Select the Brush and Draw the triangle - /*CBrush* pOldBrush = (CBrush*)*/pDC->SelectObject(m_pBlackBrush); - pDC->Polygon(ptArray, 3 ); -} -void CComboButton::MeasureItem(LPMEASUREITEMSTRUCT/* lpMeasureItemStruct*/) -{ -} - -///////////////////////////////////////////////////////////////////////////// -// CPropertyListCtrl -CPropertyListCtrl::CPropertyListCtrl() -{ - m_nWidestItem = 0; - m_bDeleteFont = TRUE; - m_bBoldSelection = TRUE; - - m_pBkBrush = NULL; - m_pBkPropertyBrush = NULL; - m_pEditWnd = NULL; - m_pFontButton = NULL; - m_pPathButton = NULL; - m_pDirButton=NULL; - m_pCustomButton=NULL; - m_pComboButton = NULL; - m_pListBox = NULL; - m_pBkHighlightBrush = NULL; - m_pSelectedFont = NULL; - m_pBorderPen = NULL; - m_pCurItem = NULL; - m_pCurFont = NULL; - m_pCurDrawItem = NULL; - m_pTextFont = NULL; - m_pSelectedFont = NULL; - m_pBorderPen = NULL; - - m_crBorderColor = RGB(192,192,192); - m_crBkColor = GetSysColor(COLOR_WINDOW); - m_crPropertyBkColor = m_crBkColor; - m_crTextColor = GetSysColor(COLOR_WINDOWTEXT); - m_crPropertyTextColor = m_crTextColor; - m_crHighlightColor = GetSysColor(COLOR_HIGHLIGHT); - m_crTextHighlightColor = GetSysColor(COLOR_HIGHLIGHTTEXT); -} - -CPropertyListCtrl::~CPropertyListCtrl() -{ - if(m_bDeleteFont) delete m_pTextFont; - - if(m_pEditWnd) delete m_pEditWnd; - if(m_pFontButton) delete m_pFontButton; - if(m_pPathButton) delete m_pPathButton; - if (m_pDirButton) delete m_pDirButton; - if (m_pCustomButton) - delete m_pCustomButton; - if(m_pListBox) delete m_pListBox; - if(m_pComboButton) delete m_pComboButton; - - if(m_pBkBrush) delete m_pBkBrush; - if(m_pBkPropertyBrush) delete m_pBkPropertyBrush; - if(m_pBkHighlightBrush) delete m_pBkHighlightBrush; - if(m_pSelectedFont) delete m_pSelectedFont; - if(m_pBorderPen) delete m_pBorderPen; - - // Clear items - Reset(); -} - -void CPropertyListCtrl::Reinit() -{ - ResetContent(); - - // Clean up - if(m_bDeleteFont) delete m_pTextFont; - - if(m_pEditWnd) delete m_pEditWnd; - if(m_pFontButton) delete m_pFontButton; - if(m_pPathButton) delete m_pPathButton; - if (m_pDirButton) delete m_pDirButton; - if (m_pCustomButton) - delete m_pCustomButton; - if(m_pListBox) delete m_pListBox; - if(m_pComboButton) delete m_pComboButton; - - if(m_pBkBrush) delete m_pBkBrush; - if(m_pBkPropertyBrush) delete m_pBkPropertyBrush; - if(m_pBkHighlightBrush) delete m_pBkHighlightBrush; - if(m_pSelectedFont) delete m_pSelectedFont; - if(m_pBorderPen) delete m_pBorderPen; - - // Clear items - Reset(); - - m_nWidestItem = 0; - m_bDeleteFont = TRUE; - m_bBoldSelection = TRUE; - - m_pBkBrush = NULL; - m_pBkPropertyBrush = NULL; - m_pEditWnd = NULL; - m_pFontButton = NULL; - m_pPathButton = NULL; - m_pDirButton=NULL; - m_pCustomButton=NULL; - m_pComboButton = NULL; - m_pListBox = NULL; - m_pBkHighlightBrush = NULL; - m_pSelectedFont = NULL; - m_pBorderPen = NULL; - m_pCurItem = NULL; - m_pCurFont = NULL; - m_pCurDrawItem = NULL; - m_pTextFont = NULL; - m_pSelectedFont = NULL; - m_pBorderPen = NULL; - - m_crBorderColor = RGB(192,192,192); - m_crBkColor = GetSysColor(COLOR_WINDOW); - m_crPropertyBkColor = m_crBkColor; - m_crTextColor = GetSysColor(COLOR_WINDOWTEXT); - m_crPropertyTextColor = m_crTextColor; - m_crHighlightColor = GetSysColor(COLOR_HIGHLIGHT); - m_crTextHighlightColor = GetSysColor(COLOR_HIGHLIGHTTEXT); - - Init(); -} - -void CPropertyListCtrl::Reset() -{ - // Clear the List - POSITION Pos = m_Items.GetHeadPosition(); - while(Pos) - { - m_pCurItem = (PROPERTYITEM*)m_Items.GetNext(Pos); - if(m_pCurItem->pBrush) - delete m_pCurItem->pBrush; - delete m_pCurItem; - } - m_Items.RemoveAll(); -} - -BEGIN_MESSAGE_MAP(CPropertyListCtrl, CListBox) - //{{AFX_MSG_MAP(CPropertyListCtrl) - ON_WM_CREATE() - ON_WM_CTLCOLOR_REFLECT() - ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange) - ON_WM_CTLCOLOR() - ON_CONTROL_REFLECT(LBN_DBLCLK, OnDblclk) - ON_EN_KILLFOCUS( ID_PROPERTY_TEXT, OnEditLostFocus ) - ON_EN_CHANGE( ID_PROPERTY_TEXT, OnEditChange ) - ON_BN_CLICKED( ID_PROPERTY_FONT, OnFontPropertyClick ) - ON_BN_CLICKED( ID_PROPERTY_PATH, OnPathPropertyClick ) - ON_BN_CLICKED( ID_PROPERTY_DIR, OnDirPropertyClick ) - ON_BN_CLICKED( ID_PROPERTY_CUSTOM, OnCustomPropertyClick ) - ON_BN_CLICKED( ID_PROPERTY_COMBO_BTN, OnComboBoxClick ) - ON_LBN_SELCHANGE(ID_PROPERTY_COMBO_LIST, OnSelChange) - ON_LBN_KILLFOCUS(ID_PROPERTY_COMBO_LIST, OnListboxLostFocus) - ON_WM_LBUTTONDOWN() - ON_WM_VSCROLL() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CPropertyListCtrl message handlers - -HBRUSH CPropertyListCtrl::CtlColor(CDC* /*pDC*/, UINT/* nCtlColor*/) -{ - return (HBRUSH)m_pBkBrush->GetSafeHandle(); -} - -HBRUSH CPropertyListCtrl::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) -{ - HBRUSH hbr = CListBox::OnCtlColor(pDC, pWnd, nCtlColor); - -/* if( nCtlColor == CTLCOLOR_EDIT) - { - pDC->SetBkColor(m_crPropertyBkColor); - pDC->SetTextColor(m_crPropertyTextColor); - }*/ - pDC->SetBkColor(m_crPropertyBkColor); - pDC->SetTextColor(m_crPropertyTextColor); - - if(m_pBkPropertyBrush) - return (HBRUSH)(m_pBkPropertyBrush->GetSafeHandle() ); - else - return hbr; -} -void CPropertyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) -{ - // Make sure its a valid item - if( lpDrawItemStruct->itemID == LB_ERR ) - return; - - // Obtain the text for this item - m_csText.Empty(); - GetText(lpDrawItemStruct->itemID, m_csText); - - // Get the drawing DC - CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); - - // Set the Current member we are drawing - m_pCurDrawItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(lpDrawItemStruct->itemID)); - - // Obtain the Item Rect - CRect ItemRect(lpDrawItemStruct->rcItem); - - // Draw This item - DrawItem( pDC, ItemRect, lpDrawItemStruct->itemState & ODS_SELECTED); -} -void CPropertyListCtrl::MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/) -{ -} -void CPropertyListCtrl::OnDblclk() -{ - // Get the Course Position - POINT pPoint; - GetCursorPos(&pPoint); - - // Convert this rect to coordinates of the desktop - CRect TempRect = m_CurRect; - MapWindowPoints(GetDesktopWindow(), TempRect); - - // Display the Correct Control - switch(m_pCurItem->nType) - { - case ID_PROPERTY_BOOL: - // Is the Mouse in this area - if(TempRect.PtInRect(pPoint)) - { - // Reverse the Selection - m_pCurItem->nPropertySelected = !m_pCurItem->nPropertySelected; - - // Redraw this item - RedrawWindow(); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); - } - break; - - case ID_PROPERTY_FONT: - m_pFontButton->SetFocus(); - OnFontPropertyClick(); - break; - - case ID_PROPERTY_PATH: - m_pPathButton->SetFocus(); - OnPathPropertyClick(); - break; - - case ID_PROPERTY_DIR: - m_pDirButton->SetFocus(); - OnDirPropertyClick(); - break; - - case ID_PROPERTY_CUSTOM: - m_pCustomButton->SetFocus(); - OnCustomPropertyClick(); - break; - - case ID_PROPERTY_COLOR: - LOGBRUSH lb; - m_pCurItem->pBrush->GetLogBrush(&lb); - CColorDialog ColorDialog(lb.lbColor, 0, GetParent()); - if(ColorDialog.DoModal() != IDOK) - return; - - // Destroy the Brush and create a new one - if(m_pCurItem->pBrush) delete m_pCurItem->pBrush; - m_pCurItem->pBrush = new CBrush(ColorDialog.GetColor()); - - // Redraw the Widow (Theres probably a better way) - RedrawWindow(); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); - break; - } - -} -void CPropertyListCtrl::OnSelchange() -{ - HideControls(); - - // Display the Correct Control - CRect TempRect = m_CurRect; - TempRect.InflateRect(-1,-1); - switch(m_pCurItem->nType) - { - case ID_PROPERTY_TEXT: - TempRect.left += 1; - m_pEditWnd->SetWindowText(m_pCurItem->csProperties.GetAt(0)); - m_pEditWnd->MoveWindow(TempRect); - m_pEditWnd->ShowWindow(SW_SHOWNORMAL); -// m_pEditWnd->SetFocus(); -// m_pEditWnd->SetSel(0,-1); - break; - - case ID_PROPERTY_FONT: - TempRect.left = TempRect.right - 17; - m_pFontButton->MoveWindow(TempRect); - m_pFontButton->ShowWindow(SW_SHOWNORMAL); - break; - - case ID_PROPERTY_PATH: - TempRect.left = TempRect.right - 17; - m_pPathButton->MoveWindow(TempRect); - m_pPathButton->ShowWindow(SW_SHOWNORMAL); - break; - - case ID_PROPERTY_DIR: - TempRect.left = TempRect.right - 17; - m_pDirButton->MoveWindow(TempRect); - m_pDirButton->ShowWindow(SW_SHOWNORMAL); - break; - - case ID_PROPERTY_CUSTOM: - TempRect.left = TempRect.right - 17; - m_pCustomButton->MoveWindow(TempRect); - m_pCustomButton->ShowWindow(SW_SHOWNORMAL); - break; - - case ID_PROPERTY_COMBO_LIST: - TempRect.left = TempRect.right - 17; - m_pComboButton->MoveWindow(TempRect); - m_pComboButton->ShowWindow(SW_SHOWNORMAL); - - TempRect.left = m_CurRect.left + 2; - TempRect.right -= 17; - if(m_pCurItem->bComboEditable) - { - m_pEditWnd->SetWindowText(m_pCurItem->csProperties.GetAt(m_pCurItem->nPropertySelected)); -// m_pEditWnd->SetFocus(); -// m_pEditWnd->SetSel(0,-1); - m_pEditWnd->MoveWindow(TempRect); - m_pEditWnd->ShowWindow(SW_SHOWNORMAL); - } - - // Move the Lsit box -// TempRect.left--; - TempRect.right += 18; - TempRect.top = TempRect.bottom; - - // Set the Bottom Height - if(m_pCurItem->csProperties.GetSize() > 5) - TempRect.bottom += GetItemHeight(0) * 5; - else - TempRect.bottom += GetItemHeight(0) * m_pCurItem->csProperties.GetSize(); - - // pobierz wsp�rz�dne tej kontrolki w stosunku do okna parenta -// CRect rcThisParent; -// GetWindowRect(&rcThisParent); -// GetParent()->ScreenToClient(&rcThisParent); - -// TempRect.OffsetRect(rcThisParent.left+2, rcThisParent.top+2); - m_pListBox->MoveWindow(TempRect); - - // Force the Expansion - OnComboBoxClick(); - break; - - } -} -void CPropertyListCtrl::OnEditLostFocus() -{ - // Get the text - CString csText; - m_pEditWnd->GetWindowText(csText); - - // Is the current item a text item - if(m_pCurItem->nType == ID_PROPERTY_TEXT) - { - // Did the text change - if(!m_bChanged) - return; - - m_pCurItem->csProperties.SetAt(0, csText); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); - } - else - { - // Get the window that has the focus now - if(GetFocus() == m_pComboButton || !m_pListBox->GetCount()) - return; - - // Did the text change - if(!m_bChanged) - return; - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); - - // Look for this text - m_bChanged = FALSE; - if( m_pListBox->FindStringExact(-1,csText) != LB_ERR) - return; - - // Add it and select it - m_pCurItem->nPropertySelected = m_pCurItem->csProperties.Add(csText); - } -} -void CPropertyListCtrl::OnEditChange() -{ - m_bChanged = TRUE; -} -void CPropertyListCtrl::OnFontPropertyClick() -{ - // Show the Dialog - CFontDialog FontDialog(&m_pCurItem->LogFont); - if(FontDialog.DoModal() != IDOK) - return; - - // Set the Font data - FontDialog.GetCurrentFont(&m_pCurItem->LogFont); - - // Redraw - RedrawWindow(); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); -} -void CPropertyListCtrl::OnPathPropertyClick() -{ - // Look for a ending tag - CString csExt = "*"; - CString csPath = m_pCurItem->csProperties.GetAt(0); - int nPos = csPath.ReverseFind('.'); - if(nPos) - csExt = csPath.Right(csPath.GetLength() - nPos - 1); - - // Show the Dialog - CFileDialog QuizFileDlg(TRUE, _T("*"), _T("*.") + csExt, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, m_pCurItem->csProperties.GetAt(1) ); - QuizFileDlg.m_ofn.lpstrInitialDir = csPath; - if(QuizFileDlg.DoModal() != IDOK) - return; - - // Obtain the Path they selected - m_pCurItem->csProperties.SetAt(0, QuizFileDlg.GetPathName()); - - // Redraw - RedrawWindow(); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); -} - -void CPropertyListCtrl::OnDirPropertyClick() -{ - CString strPath; - if (BrowseForFolder(m_pCurItem->csProperties.GetAt(1), &strPath)) - { - m_pCurItem->csProperties.SetAt(0, strPath); - RedrawWindow(); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); - } -} - -void CPropertyListCtrl::OnCustomPropertyClick() -{ - m_pCurItem->pfnCallback(m_pCurItem->lpParam, m_pCurItem->iParam, &m_Items, GetCurSel()); - RedrawWindow(); -} - -void CPropertyListCtrl::OnComboBoxClick() -{ - // Add the items - m_pListBox->ResetContent(); - - // Loop for all items - for( int nItem = 0; nItem < m_pCurItem->csProperties.GetSize(); nItem++) - m_pListBox->AddString(m_pCurItem->csProperties.GetAt(nItem)); - - // Select the correct item - m_pListBox->SetCurSel(m_pCurItem->nPropertySelected); - m_pListBox->SetTopIndex(m_pCurItem->nPropertySelected); - - // Show the List box - m_pListBox->ShowWindow(SW_NORMAL); -} -void CPropertyListCtrl::OnSelChange() -{ - // Set the new current item - m_pCurItem->nPropertySelected = m_pListBox->GetCurSel(); - - // Hide the Windows - m_pListBox->ShowWindow(SW_HIDE); - - if(m_pCurItem->bComboEditable) - m_pEditWnd->SetWindowText(m_pCurItem->csProperties.GetAt(m_pCurItem->nPropertySelected)); - else - RedrawWindow(); - - // Send the message that a property has changed - GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); - m_pComboButton->SetFocus(); -} -void CPropertyListCtrl::OnListboxLostFocus() -{ - m_pListBox->ShowWindow(SW_HIDE); -} -void CPropertyListCtrl::OnLButtonDown(UINT nFlags, CPoint point) -{ - // is there an item at this point - BOOL bOutside; - /*UINT uItem =*/ ItemFromPoint(point, bOutside); - - // Is this outside the client - if(bOutside) - HideControls(); - - CListBox::OnLButtonDown(nFlags, point); -} -void CPropertyListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) -{ - // Hide the Controls - HideControls(); - - CListBox::OnVScroll(nSBCode, nPos, pScrollBar); -} - -///////////////////////////////////////////////////////////////////////////// -// GUI User Functions -///////////////////////////////////////////////////////////////////////////// - -void CPropertyListCtrl::Init() -{ - // utw�rz czcionk� bazowan� na czcionce okna - LOGFONT lf; - GetFont()->GetLogFont(&lf); - - if(m_pTextFont) delete m_pTextFont; - if(m_pSelectedFont) delete m_pSelectedFont; - - m_pTextFont=new CFont(); - m_pTextFont->CreateFontIndirect(&lf); - - lf.lfWeight=FW_BOLD; - m_pSelectedFont=new CFont(); - m_pSelectedFont->CreateFontIndirect(&lf); - - m_bDeleteFont=TRUE; - - // Create the Border Pen - m_pBorderPen = new CPen(PS_SOLID, 1, m_crBorderColor); - - // Create the Selected Background brush - m_pBkHighlightBrush = new CBrush(m_crHighlightColor); - m_pBkBrush = new CBrush(m_crBkColor); - - // Set the row height - read text height - CClientDC dc(this); - dc.SelectObject(&m_pSelectedFont); - TEXTMETRIC tm; - dc.GetTextMetrics(&tm); - - SetItemHeight(-1, MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY) ); -} - -void CPropertyListCtrl::SetFont(CFont* pFont) -{ - // Delete our font and set our font to theirs - if(m_pTextFont) delete m_pTextFont; - if(m_pSelectedFont) delete m_pSelectedFont; - m_pTextFont = pFont; - m_bDeleteFont = FALSE; - - // Figure out the text size - LOGFONT lpLogFont; - m_pTextFont->GetLogFont(&lpLogFont); - - // Set the font and redraw - CWnd::SetFont(m_pTextFont, FALSE); - - // Create the heading font with the bold attribute - lpLogFont.lfWeight = FW_BOLD; - m_pSelectedFont = new CFont(); - m_pSelectedFont->CreateFontIndirect(&lpLogFont); - - // Set the Row height - CClientDC dc(this); - dc.SelectObject(&m_pSelectedFont); - TEXTMETRIC tm; - dc.GetTextMetrics(&tm); - - SetItemHeight(-1, MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY) ); - - // ** IMPLEMENT LATER ?? ** - // Recalculate the Width Position -} - -void CPropertyListCtrl::SetLineStyle(COLORREF crColor, int nStyle) -{ - // Delete the old Pen - if(m_pBorderPen) delete m_pBorderPen; - - // Create the brush - m_pBorderPen = new CPen(nStyle, 1, crColor); - m_crBorderColor = crColor; -} -void CPropertyListCtrl::SetBkColor(COLORREF crColor) -{ - // Delete the old brush - if(m_pBkBrush) delete m_pBkBrush; - - // Create the brush - m_pBkBrush = new CBrush(crColor); - m_crBkColor = crColor; -} -void CPropertyListCtrl::SetPropertyBkColor(COLORREF crColor) -{ - // Delete the old brush - if(m_pBkPropertyBrush) delete m_pBkPropertyBrush; - - // Create the brush - m_pBkPropertyBrush = new CBrush(crColor); - m_crPropertyBkColor = crColor; -} - -void CPropertyListCtrl::SetHighlightColor(COLORREF crColor) -{ - // Delete the old brush - if(m_pBkHighlightBrush) delete m_pBkHighlightBrush; - - // Create the brush - m_pBkHighlightBrush = new CBrush(crColor); - m_crHighlightColor = crColor; -} - -///////////////////////////////////////////////////////////////////////////// -// Add Properties Functions -///////////////////////////////////////////////////////////////////////////// -BOOL CPropertyListCtrl::AddString(CString csText) -{ - // Call our function (assume its a text Item) - return AddString(csText, ID_PROPERTY_STATIC, _T("")); -} - -BOOL CPropertyListCtrl::AddString(UINT nIDString) -{ - return AddString(GetResManager()->LoadString(nIDString)); -} - -BOOL CPropertyListCtrl::AddString(UINT nIDString, int nType, CString csData, void (*pfnCallback)(LPVOID, int, CPtrList*, int), LPVOID lpParam, int iParam, int nPropertySelected, int nAlignment, BOOL bComboEditable) -{ - // Is this a valid Control type - if(nType > ID_PROPERTY_COMBO_LIST) - return FALSE; - - // load string - const TCHAR *pszText=GetResManager()->LoadString(nIDString); - - // Create a new Structure to hold it - PROPERTYITEM* pNewItem = new PROPERTYITEM; - pNewItem->nType = nType; - pNewItem->nAlignment = nAlignment; - pNewItem->pBrush = NULL; - pNewItem->bComboEditable = bComboEditable; - pNewItem->pfnCallback=pfnCallback; - pNewItem->iParam=iParam; - pNewItem->lpParam=lpParam; - - // Calculate the Width of the string based on the font set - CDC* pDC = GetDC(); - pDC->SelectObject(m_pSelectedFont); - CSize Size = pDC->GetTextExtent(pszText); - if(Size.cx + 10 > m_nWidestItem) - m_nWidestItem = Size.cx + 10; - ReleaseDC(pDC); - pNewItem->nWidth = Size.cx; - pNewItem->nPropertySelected = nPropertySelected; - - // Set Property - if(!SetProperty(pNewItem, nType, csData)) - { - delete pNewItem; - return FALSE; - } - - // Is the item set bigger than the number of properties - if(pNewItem->nPropertySelected > pNewItem->csProperties.GetSize()) - { - delete pNewItem; - return FALSE; - } - - // Add to the list - m_Items.AddTail(pNewItem); - - // Add the string to the list box - /*int nPos =*/ CListBox::AddString(pszText); - - // Create the Control if Needed - CreateControl(nType); - return TRUE; -} - -BOOL CPropertyListCtrl::AddString(CString csText, int nType, CString csData, int nPropertySelected, int nAlignment, BOOL bComboEditable) -{ - // Is this a valid Control type - if(nType > ID_PROPERTY_COMBO_LIST) - return FALSE; - - // Create a new Structure to hold it - PROPERTYITEM* pNewItem = new PROPERTYITEM; - pNewItem->nType = nType; - pNewItem->nAlignment = nAlignment; - pNewItem->pBrush = NULL; - pNewItem->bComboEditable = bComboEditable; - - // Calculate the Width of the string based on the font set - CDC* pDC = GetDC(); - pDC->SelectObject(m_pSelectedFont); - CSize Size = pDC->GetTextExtent(csText); - if(Size.cx + 10 > m_nWidestItem) - m_nWidestItem = Size.cx + 10; - ReleaseDC(pDC); - pNewItem->nWidth = Size.cx; - pNewItem->nPropertySelected = nPropertySelected; - - // Set Property - if(!SetProperty(pNewItem, nType, csData)) - { - delete pNewItem; - return FALSE; - } - - // Is the item set bigger than the number of properties - if(pNewItem->nPropertySelected > pNewItem->csProperties.GetSize()) - { - delete pNewItem; - return FALSE; - } - - // Add to the list - m_Items.AddTail(pNewItem); - - // Add the string to the list box - /*int nPos =*/ CListBox::AddString(csText); - - // Create the Control if Needed - CreateControl(nType); - return TRUE; -} - -BOOL CPropertyListCtrl::AddString(UINT nIDString, int nType, UINT nIDData, int nPropertySelected, int nAlignment, BOOL bComboEditable) -{ - return AddString(GetResManager()->LoadString(nIDString), nType, GetResManager()->LoadString(nIDData), nPropertySelected, nAlignment, bComboEditable); -} - -BOOL CPropertyListCtrl::AddString(UINT nIDString, int nType, CString csData, int nPropertySelected, int nAlignment, BOOL bComboEditable) -{ - return AddString(GetResManager()->LoadString(nIDString), nType, csData, nPropertySelected, nAlignment, bComboEditable); -} - -BOOL CPropertyListCtrl::AddString(CString csText, COLORREF crColor, int nAlignment) -{ - // Create a new brush based on this color - m_pCurBrush = new CBrush(crColor); - - // Call the other functions - return AddString(csText, ID_PROPERTY_COLOR, _T(""), 0, nAlignment); -} - -BOOL CPropertyListCtrl::AddString(UINT nIDString, COLORREF crColor, int nAlignment) -{ - return AddString(GetResManager()->LoadString(nIDString), crColor, nAlignment); -} - -BOOL CPropertyListCtrl::AddString(CString csText, CFont* pFont, int nAlignment) -{ - // Safe the Font - m_pCurFont = pFont; - - // Call the other functions - return AddString(csText, ID_PROPERTY_FONT, _T(""), 0, nAlignment); -} - -BOOL CPropertyListCtrl::AddString(UINT nIDString, CFont* pFont, int nAlignment) -{ - return AddString(GetResManager()->LoadString(nIDString), pFont, nAlignment); -} - -///////////////////////////////////////////////////////////////////////////// -// Helper Functions -///////////////////////////////////////////////////////////////////////////// -void CPropertyListCtrl::DrawItem(CDC* pDC, CRect ItemRect, BOOL bSelected) -{ - if (m_pCurDrawItem->nType != ID_PROPERTY_STATIC) - { - ///////////////////////////////////////// - // Paint the Background rectangle (Property Value) - if(m_pCurDrawItem->nType == ID_PROPERTY_COLOR) - pDC->SelectObject(m_pCurDrawItem->pBrush); - else - pDC->SelectObject(m_pBkBrush); - pDC->SelectObject(m_pBorderPen); - - // Draw the Rectangle - ItemRect.left = m_nWidestItem - 1; - ItemRect.top--; - ItemRect.right++; - pDC->Rectangle(ItemRect); - CRect OrginalRect = ItemRect; - - ///////////////////////////////////////// - // Draw the Property Text - pDC->SetBkMode(TRANSPARENT); - pDC->SelectObject(m_pBkBrush); - pDC->SelectObject(m_pTextFont); - pDC->SetTextColor(m_crTextColor); - DrawPropertyText(pDC, ItemRect); - - ///////////////////////////////////////// - // Paint the Background rectangle (Property Name) - if( bSelected ) - pDC->SelectObject(m_pBkHighlightBrush); - - // Draw the Rectangle - ItemRect.right = m_nWidestItem; - ItemRect.left = -1; - pDC->Rectangle(ItemRect); - - ///////////////////////////////////////// - // Paint the Property name Text - // Is this item selected? - if( bSelected ) - { - if(m_bBoldSelection) pDC->SelectObject(m_pSelectedFont); - pDC->SetTextColor(m_crTextHighlightColor); - m_pCurItem = m_pCurDrawItem; - m_CurRect = OrginalRect; - } - - // Draw the Text - ItemRect.left += 6; - ItemRect.right -= 5; - pDC->DrawText( m_csText, m_csText.GetLength(), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|m_pCurDrawItem->nAlignment); - } - else - { - ///////////////////////////////////////// - // Paint the Background rectangle (Property Value) - pDC->SelectObject(m_pBkHighlightBrush); - pDC->SelectObject(m_pBorderPen); - pDC->SelectObject(m_pSelectedFont); - - // Draw the Rectangle - pDC->Rectangle(ItemRect); - CRect OrginalRect = ItemRect; - - ///////////////////////////////////////// - // Draw - pDC->SetBkMode(TRANSPARENT); - pDC->SetTextColor(m_crTextHighlightColor); - if (bSelected) - { - m_pCurItem = m_pCurDrawItem; - m_CurRect = OrginalRect; - } - - // Draw the Text - pDC->DrawText( m_csText, m_csText.GetLength(), ItemRect, DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER|DT_CENTER); - } -} - -void CPropertyListCtrl::DrawPropertyText(CDC* pDC, CRect ItemRect) -{ - ItemRect.left += 5; - switch(m_pCurDrawItem->nType) - { - case ID_PROPERTY_BOOL: - case ID_PROPERTY_COMBO_LIST: - { - CString strText; - INT_PTR iCount = m_pCurDrawItem->csProperties.GetCount(); - if(m_pCurDrawItem->nPropertySelected >= 0 && m_pCurDrawItem->nPropertySelected < iCount) - strText = m_pCurDrawItem->csProperties.GetAt(m_pCurDrawItem->nPropertySelected); - - pDC->DrawText( strText, strText.GetLength(), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX); - break; - } - - case ID_PROPERTY_TEXT: - case ID_PROPERTY_PATH: - case ID_PROPERTY_DIR: - case ID_PROPERTY_CUSTOM: - case ID_PROPERTY_STATIC: - { - CString strText; - INT_PTR iCount = m_pCurDrawItem->csProperties.GetCount(); - if(iCount > 0) - strText = m_pCurDrawItem->csProperties.GetAt(0); - - pDC->DrawText( strText, strText.GetLength(), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX); - break; - } - - case ID_PROPERTY_FONT: - if(m_pCurDrawItem->LogFont.lfHeight) - pDC->DrawText( m_pCurDrawItem->LogFont.lfFaceName, _tcslen(m_pCurDrawItem->LogFont.lfFaceName), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX); - break; - } -} - -void CPropertyListCtrl::CreateControl(int nType) -{ - switch(nType) - { - // Edit Window - case ID_PROPERTY_TEXT: - if(!m_pEditWnd) - { - m_pEditWnd = new CEdit(); - m_pEditWnd->Create(WS_CHILD|ES_AUTOHSCROLL|ES_LEFT, CRect(0,0,100,100), this, ID_PROPERTY_TEXT); - m_pEditWnd->SetFont(m_pTextFont); - } - break; - - // Font Button - case ID_PROPERTY_FONT: - if(!m_pFontButton) - { - m_pFontButton = new CButton(); - m_pFontButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_FONT); - m_pFontButton->SetFont(m_pTextFont); - } - break; - - case ID_PROPERTY_PATH: - if(!m_pPathButton) - { - m_pPathButton = new CButton(); - m_pPathButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_PATH); - m_pPathButton->SetFont(m_pTextFont); - } - break; - - case ID_PROPERTY_DIR: - if(!m_pDirButton) - { - m_pDirButton = new CButton(); - m_pDirButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_DIR); - m_pDirButton->SetFont(m_pTextFont); - } - break; - - case ID_PROPERTY_CUSTOM: - if(!m_pCustomButton) - { - m_pCustomButton = new CButton(); - m_pCustomButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_CUSTOM); - m_pCustomButton->SetFont(m_pTextFont); - } - break; - - case ID_PROPERTY_COMBO_LIST: - if(!m_pEditWnd) - { - m_pEditWnd = new CEdit(); - m_pEditWnd->Create(WS_CHILD|ES_AUTOHSCROLL|ES_LEFT, CRect(0,0,100,100), this, ID_PROPERTY_TEXT); - m_pEditWnd->SetFont(m_pTextFont); - } - if(!m_pListBox) - { - m_pListBox = new CListBox(); - m_pListBox->Create(WS_CHILD|WS_BORDER|LBS_NOTIFY|WS_VSCROLL|LBS_HASSTRINGS, CRect(0,0,100,100), this, ID_PROPERTY_COMBO_LIST); - m_pListBox->SetFont(m_pTextFont); - - m_pComboButton = new CComboButton(); - m_pComboButton->Create(CRect(0,0,0,0), this, ID_PROPERTY_COMBO_BTN ); - } - break; - } -} - -BOOL CPropertyListCtrl::SetProperty(PROPERTYITEM* pPropertyItem, int nType, CString csData) -{ - switch(nType) - { - case ID_PROPERTY_BOOL: - case ID_PROPERTY_PATH: - case ID_PROPERTY_DIR: - ParseProperties(pPropertyItem, csData); - - // Is the item selected more than items in the array? - if(pPropertyItem->csProperties.GetSize() != 2 ) - return FALSE; - break; - - case ID_PROPERTY_TEXT: - case ID_PROPERTY_STATIC: - case ID_PROPERTY_CUSTOM: - pPropertyItem->csProperties.Add(csData); - break; - - case ID_PROPERTY_FONT: - memset(&pPropertyItem->LogFont, 0, sizeof(pPropertyItem->LogFont)); - if(m_pCurFont) - { - m_pCurFont->GetLogFont(&pPropertyItem->LogFont); - m_pCurFont = NULL; - } - break; - - case ID_PROPERTY_COLOR: - pPropertyItem->pBrush = m_pCurBrush; - break; - - case ID_PROPERTY_COMBO_LIST: - ParseProperties(pPropertyItem, csData); - break; - - } - - return TRUE; -} - -void CPropertyListCtrl::ParseProperties(PROPERTYITEM* pPropertyItem, CString csData) -{ - // Parse the Items - TCHAR* pText = csData.GetBuffer( csData.GetLength() ); - TCHAR* pWord; - TCHAR Separations[] = _T("!"); - - // Establish string and get the first token: - pWord = _tcstok( pText, Separations); - while( pWord != NULL ) - { - // Add this to the Array - pPropertyItem->csProperties.Add(pWord); - - // Get next token - pWord = _tcstok( NULL, Separations ); - } - - // Release the buffer - csData.ReleaseBuffer(); -} - -void CPropertyListCtrl::HideControls() -{ - // Hide the controls - if(m_pEditWnd) m_pEditWnd->ShowWindow(SW_HIDE); - if(m_pFontButton) m_pFontButton->ShowWindow(SW_HIDE); - if(m_pPathButton) m_pPathButton->ShowWindow(SW_HIDE); - if (m_pDirButton) m_pDirButton->ShowWindow(SW_HIDE); - if (m_pCustomButton) - m_pCustomButton->ShowWindow(SW_HIDE); - if(m_pListBox) m_pListBox->ShowWindow(SW_HIDE); - if(m_pComboButton) m_pComboButton->ShowWindow(SW_HIDE); -} - -///////////////////////////////////////////////////////////////////////////// -// Get Properties Functions -///////////////////////////////////////////////////////////////////////////// -bool CPropertyListCtrl::GetProperty(int nItem, CString* pText) -{ - // is the item to high - if(nItem + 1 > GetCount()) - return false; - - // Make sure this item is the correct type - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); - if(pItem->nType != ID_PROPERTY_TEXT && pItem->nType != ID_PROPERTY_PATH && pItem->nType != ID_PROPERTY_DIR && pItem->nType != ID_PROPERTY_STATIC && pItem->nType != ID_PROPERTY_CUSTOM) - return false; - - // Copy the item - *pText = pItem->csProperties.GetAt(0); - return true; -} -bool CPropertyListCtrl::GetProperty(int nItem, bool* bValue) -{ - // is the item to high - if(nItem + 1 > GetCount()) - return false; - - // Make sure this item is the correct type - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); - if(pItem->nType != ID_PROPERTY_BOOL) - return false; - - // Copy the item - *bValue = pItem->nPropertySelected != 0; - return true; -} -bool CPropertyListCtrl::GetProperty(int nItem, COLORREF* crColor) -{ - // is the item to high - if(nItem + 1 > GetCount()) - return false; - - // Make sure this item is the correct type - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); - if(pItem->nType != ID_PROPERTY_COLOR) - return false; - - // Copy the item - LOGBRUSH LogBrush; - pItem->pBrush->GetLogBrush(&LogBrush); - *crColor = LogBrush.lbColor; - return true; -} -bool CPropertyListCtrl::GetProperty(int nItem, LOGFONT* LogFont) -{ - // is the item to high - if(nItem + 1 > GetCount()) - return false; - - // Make sure this item is the correct type - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); - if(pItem->nType != ID_PROPERTY_FONT) - return false; - - // Copy the item - *LogFont = pItem->LogFont; - return true; -} -bool CPropertyListCtrl::GetProperty(int nItem, CStringArray* pArray, int* /*SelectedItem*/) -{ - // is the item to high - if(nItem + 1 > GetCount()) - return false; - - // Make sure this item is the correct type - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); - if(pItem->nType != ID_PROPERTY_COMBO_LIST) - return false; - - // I do NOT want to send them a pointer to my array so I loop through and copy the item to thiers - for( int nString = 0; nString < pItem->csProperties.GetSize(); nString++) - pArray->Add(pItem->csProperties.GetAt(nString)); - return true; -} -bool CPropertyListCtrl::GetProperty(int nItem, int* SelectedItem, CString* pText) -{ - // is the item to high - if(nItem + 1 > GetCount()) - return false; - - // Make sure this item is the correct type - PROPERTYITEM* pItem; - pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); - - // Copy the item - *SelectedItem = pItem->nPropertySelected; - - // Do they want the text - if(pText != NULL && pItem->nType == ID_PROPERTY_COMBO_LIST) - *pText = pItem->csProperties.GetAt(pItem->nPropertySelected); - return true; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "PropertyListCtrl.h" +#include "dialogs.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CComboButton +CComboButton::CComboButton() +{ +} + +CComboButton::~CComboButton() +{ + // Delete the objects created + delete m_pBkBrush; + delete m_pBlackBrush; +// delete m_pGrayPen; + delete m_pBkPen; +} + +BEGIN_MESSAGE_MAP(CComboButton, CButton) + //{{AFX_MSG_MAP(CComboButton) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CComboButton message handlers +BOOL CComboButton::Create( CRect Rect, CWnd* pParent, UINT uID) +{ + // Create the Brushes and Pens + m_pBkBrush = new CBrush( GetSysColor(COLOR_BTNFACE)); + m_pBkPen = new CPen( PS_SOLID, 1, GetSysColor(COLOR_BTNFACE)); +// m_pGrayPen = new CPen( PS_SOLID, 1, RGB(128,128,128)); + m_pBlackBrush = new CBrush(GetSysColor(COLOR_BTNTEXT)); + + // Create the CButton + if( !CButton::Create(_T(""), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, Rect, pParent, uID )) + return FALSE; + + return 0; +} + +///////////////////////////////////////////////////////////////////////////// +// Draw the Button +void CComboButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct ) +{ + CDC* prDC = CDC::FromHandle(lpDrawItemStruct->hDC); + CRect ButtonRect = lpDrawItemStruct->rcItem; + CMemDC dc(prDC, ButtonRect); + CMemDC *pDC=&dc; + + // Fill the Background + CBrush* pOldBrush = (CBrush*)pDC->SelectObject( m_pBkBrush ); + CPen* pOldPen = (CPen*)pDC->SelectObject(m_pBkPen); + pDC->Rectangle(ButtonRect); + + // Draw the Correct Border + if(lpDrawItemStruct->itemState & ODS_SELECTED) + { + pDC->DrawEdge(ButtonRect, EDGE_SUNKEN, BF_RECT); + ButtonRect.left++; + ButtonRect.right++; + ButtonRect.bottom++; + ButtonRect.top++; + } + else + pDC->DrawEdge(ButtonRect, EDGE_RAISED, BF_RECT); + + // Draw the Triangle + ButtonRect.left += 3; + ButtonRect.right -= 4; + ButtonRect.top += 5; + ButtonRect.bottom -= 5; + DrawTriangle(pDC, ButtonRect); + + // Return what was used + pDC->SelectObject( pOldPen ); + pDC->SelectObject( pOldBrush ); +} + +void CComboButton::DrawTriangle(CDC* pDC, CRect Rect) +{ + POINT ptArray[3]; + + // Figure out the Top left + ptArray[0].x = Rect.left; + ptArray[0].y = Rect.top; + ptArray[1].x = Rect.right; + ptArray[1].y = Rect.top; + ptArray[2].x = Rect.right - (Rect.Width() / 2); + ptArray[2].y = Rect.bottom; + + // Select the Brush and Draw the triangle + /*CBrush* pOldBrush = (CBrush*)*/pDC->SelectObject(m_pBlackBrush); + pDC->Polygon(ptArray, 3 ); +} +void CComboButton::MeasureItem(LPMEASUREITEMSTRUCT/* lpMeasureItemStruct*/) +{ +} + +///////////////////////////////////////////////////////////////////////////// +// CPropertyListCtrl +CPropertyListCtrl::CPropertyListCtrl() +{ + m_nWidestItem = 0; + m_bDeleteFont = TRUE; + m_bBoldSelection = TRUE; + + m_pBkBrush = NULL; + m_pBkPropertyBrush = NULL; + m_pEditWnd = NULL; + m_pFontButton = NULL; + m_pPathButton = NULL; + m_pDirButton=NULL; + m_pCustomButton=NULL; + m_pComboButton = NULL; + m_pListBox = NULL; + m_pBkHighlightBrush = NULL; + m_pSelectedFont = NULL; + m_pBorderPen = NULL; + m_pCurItem = NULL; + m_pCurFont = NULL; + m_pCurDrawItem = NULL; + m_pTextFont = NULL; + m_pSelectedFont = NULL; + m_pBorderPen = NULL; + + m_crBorderColor = RGB(192,192,192); + m_crBkColor = GetSysColor(COLOR_WINDOW); + m_crPropertyBkColor = m_crBkColor; + m_crTextColor = GetSysColor(COLOR_WINDOWTEXT); + m_crPropertyTextColor = m_crTextColor; + m_crHighlightColor = GetSysColor(COLOR_HIGHLIGHT); + m_crTextHighlightColor = GetSysColor(COLOR_HIGHLIGHTTEXT); +} + +CPropertyListCtrl::~CPropertyListCtrl() +{ + if(m_bDeleteFont) delete m_pTextFont; + + if(m_pEditWnd) delete m_pEditWnd; + if(m_pFontButton) delete m_pFontButton; + if(m_pPathButton) delete m_pPathButton; + if (m_pDirButton) delete m_pDirButton; + if (m_pCustomButton) + delete m_pCustomButton; + if(m_pListBox) delete m_pListBox; + if(m_pComboButton) delete m_pComboButton; + + if(m_pBkBrush) delete m_pBkBrush; + if(m_pBkPropertyBrush) delete m_pBkPropertyBrush; + if(m_pBkHighlightBrush) delete m_pBkHighlightBrush; + if(m_pSelectedFont) delete m_pSelectedFont; + if(m_pBorderPen) delete m_pBorderPen; + + // Clear items + Reset(); +} + +void CPropertyListCtrl::Reinit() +{ + ResetContent(); + + // Clean up + if(m_bDeleteFont) delete m_pTextFont; + + if(m_pEditWnd) delete m_pEditWnd; + if(m_pFontButton) delete m_pFontButton; + if(m_pPathButton) delete m_pPathButton; + if (m_pDirButton) delete m_pDirButton; + if (m_pCustomButton) + delete m_pCustomButton; + if(m_pListBox) delete m_pListBox; + if(m_pComboButton) delete m_pComboButton; + + if(m_pBkBrush) delete m_pBkBrush; + if(m_pBkPropertyBrush) delete m_pBkPropertyBrush; + if(m_pBkHighlightBrush) delete m_pBkHighlightBrush; + if(m_pSelectedFont) delete m_pSelectedFont; + if(m_pBorderPen) delete m_pBorderPen; + + // Clear items + Reset(); + + m_nWidestItem = 0; + m_bDeleteFont = TRUE; + m_bBoldSelection = TRUE; + + m_pBkBrush = NULL; + m_pBkPropertyBrush = NULL; + m_pEditWnd = NULL; + m_pFontButton = NULL; + m_pPathButton = NULL; + m_pDirButton=NULL; + m_pCustomButton=NULL; + m_pComboButton = NULL; + m_pListBox = NULL; + m_pBkHighlightBrush = NULL; + m_pSelectedFont = NULL; + m_pBorderPen = NULL; + m_pCurItem = NULL; + m_pCurFont = NULL; + m_pCurDrawItem = NULL; + m_pTextFont = NULL; + m_pSelectedFont = NULL; + m_pBorderPen = NULL; + + m_crBorderColor = RGB(192,192,192); + m_crBkColor = GetSysColor(COLOR_WINDOW); + m_crPropertyBkColor = m_crBkColor; + m_crTextColor = GetSysColor(COLOR_WINDOWTEXT); + m_crPropertyTextColor = m_crTextColor; + m_crHighlightColor = GetSysColor(COLOR_HIGHLIGHT); + m_crTextHighlightColor = GetSysColor(COLOR_HIGHLIGHTTEXT); + + Init(); +} + +void CPropertyListCtrl::Reset() +{ + // Clear the List + POSITION Pos = m_Items.GetHeadPosition(); + while(Pos) + { + m_pCurItem = (PROPERTYITEM*)m_Items.GetNext(Pos); + if(m_pCurItem->pBrush) + delete m_pCurItem->pBrush; + delete m_pCurItem; + } + m_Items.RemoveAll(); +} + +BEGIN_MESSAGE_MAP(CPropertyListCtrl, CListBox) + //{{AFX_MSG_MAP(CPropertyListCtrl) + ON_WM_CREATE() + ON_WM_CTLCOLOR_REFLECT() + ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange) + ON_WM_CTLCOLOR() + ON_CONTROL_REFLECT(LBN_DBLCLK, OnDblclk) + ON_EN_KILLFOCUS( ID_PROPERTY_TEXT, OnEditLostFocus ) + ON_EN_CHANGE( ID_PROPERTY_TEXT, OnEditChange ) + ON_BN_CLICKED( ID_PROPERTY_FONT, OnFontPropertyClick ) + ON_BN_CLICKED( ID_PROPERTY_PATH, OnPathPropertyClick ) + ON_BN_CLICKED( ID_PROPERTY_DIR, OnDirPropertyClick ) + ON_BN_CLICKED( ID_PROPERTY_CUSTOM, OnCustomPropertyClick ) + ON_BN_CLICKED( ID_PROPERTY_COMBO_BTN, OnComboBoxClick ) + ON_LBN_SELCHANGE(ID_PROPERTY_COMBO_LIST, OnSelChange) + ON_LBN_KILLFOCUS(ID_PROPERTY_COMBO_LIST, OnListboxLostFocus) + ON_WM_LBUTTONDOWN() + ON_WM_VSCROLL() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CPropertyListCtrl message handlers + +HBRUSH CPropertyListCtrl::CtlColor(CDC* /*pDC*/, UINT/* nCtlColor*/) +{ + return (HBRUSH)m_pBkBrush->GetSafeHandle(); +} + +HBRUSH CPropertyListCtrl::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) +{ + HBRUSH hbr = CListBox::OnCtlColor(pDC, pWnd, nCtlColor); + +/* if( nCtlColor == CTLCOLOR_EDIT) + { + pDC->SetBkColor(m_crPropertyBkColor); + pDC->SetTextColor(m_crPropertyTextColor); + }*/ + pDC->SetBkColor(m_crPropertyBkColor); + pDC->SetTextColor(m_crPropertyTextColor); + + if(m_pBkPropertyBrush) + return (HBRUSH)(m_pBkPropertyBrush->GetSafeHandle() ); + else + return hbr; +} +void CPropertyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) +{ + // Make sure its a valid item + if( lpDrawItemStruct->itemID == LB_ERR ) + return; + + // Obtain the text for this item + m_csText.Empty(); + GetText(lpDrawItemStruct->itemID, m_csText); + + // Get the drawing DC + CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); + + // Set the Current member we are drawing + m_pCurDrawItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(lpDrawItemStruct->itemID)); + + // Obtain the Item Rect + CRect ItemRect(lpDrawItemStruct->rcItem); + + // Draw This item + DrawItem( pDC, ItemRect, lpDrawItemStruct->itemState & ODS_SELECTED); +} +void CPropertyListCtrl::MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/) +{ +} +void CPropertyListCtrl::OnDblclk() +{ + // Get the Course Position + POINT pPoint; + GetCursorPos(&pPoint); + + // Convert this rect to coordinates of the desktop + CRect TempRect = m_CurRect; + MapWindowPoints(GetDesktopWindow(), TempRect); + + // Display the Correct Control + switch(m_pCurItem->nType) + { + case ID_PROPERTY_BOOL: + // Is the Mouse in this area + if(TempRect.PtInRect(pPoint)) + { + // Reverse the Selection + m_pCurItem->nPropertySelected = !m_pCurItem->nPropertySelected; + + // Redraw this item + RedrawWindow(); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); + } + break; + + case ID_PROPERTY_FONT: + m_pFontButton->SetFocus(); + OnFontPropertyClick(); + break; + + case ID_PROPERTY_PATH: + m_pPathButton->SetFocus(); + OnPathPropertyClick(); + break; + + case ID_PROPERTY_DIR: + m_pDirButton->SetFocus(); + OnDirPropertyClick(); + break; + + case ID_PROPERTY_CUSTOM: + m_pCustomButton->SetFocus(); + OnCustomPropertyClick(); + break; + + case ID_PROPERTY_COLOR: + LOGBRUSH lb; + m_pCurItem->pBrush->GetLogBrush(&lb); + CColorDialog ColorDialog(lb.lbColor, 0, GetParent()); + if(ColorDialog.DoModal() != IDOK) + return; + + // Destroy the Brush and create a new one + if(m_pCurItem->pBrush) delete m_pCurItem->pBrush; + m_pCurItem->pBrush = new CBrush(ColorDialog.GetColor()); + + // Redraw the Widow (Theres probably a better way) + RedrawWindow(); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); + break; + } + +} +void CPropertyListCtrl::OnSelchange() +{ + HideControls(); + + // Display the Correct Control + CRect TempRect = m_CurRect; + TempRect.InflateRect(-1,-1); + switch(m_pCurItem->nType) + { + case ID_PROPERTY_TEXT: + TempRect.left += 1; + m_pEditWnd->SetWindowText(m_pCurItem->csProperties.GetAt(0)); + m_pEditWnd->MoveWindow(TempRect); + m_pEditWnd->ShowWindow(SW_SHOWNORMAL); +// m_pEditWnd->SetFocus(); +// m_pEditWnd->SetSel(0,-1); + break; + + case ID_PROPERTY_FONT: + TempRect.left = TempRect.right - 17; + m_pFontButton->MoveWindow(TempRect); + m_pFontButton->ShowWindow(SW_SHOWNORMAL); + break; + + case ID_PROPERTY_PATH: + TempRect.left = TempRect.right - 17; + m_pPathButton->MoveWindow(TempRect); + m_pPathButton->ShowWindow(SW_SHOWNORMAL); + break; + + case ID_PROPERTY_DIR: + TempRect.left = TempRect.right - 17; + m_pDirButton->MoveWindow(TempRect); + m_pDirButton->ShowWindow(SW_SHOWNORMAL); + break; + + case ID_PROPERTY_CUSTOM: + TempRect.left = TempRect.right - 17; + m_pCustomButton->MoveWindow(TempRect); + m_pCustomButton->ShowWindow(SW_SHOWNORMAL); + break; + + case ID_PROPERTY_COMBO_LIST: + TempRect.left = TempRect.right - 17; + m_pComboButton->MoveWindow(TempRect); + m_pComboButton->ShowWindow(SW_SHOWNORMAL); + + TempRect.left = m_CurRect.left + 2; + TempRect.right -= 17; + if(m_pCurItem->bComboEditable) + { + m_pEditWnd->SetWindowText(m_pCurItem->csProperties.GetAt(m_pCurItem->nPropertySelected)); +// m_pEditWnd->SetFocus(); +// m_pEditWnd->SetSel(0,-1); + m_pEditWnd->MoveWindow(TempRect); + m_pEditWnd->ShowWindow(SW_SHOWNORMAL); + } + + // Move the Lsit box +// TempRect.left--; + TempRect.right += 18; + TempRect.top = TempRect.bottom; + + // Set the Bottom Height + if(m_pCurItem->csProperties.GetSize() > 5) + TempRect.bottom += GetItemHeight(0) * 5; + else + TempRect.bottom += GetItemHeight(0) * m_pCurItem->csProperties.GetSize(); + + // pobierz wsp�rz�dne tej kontrolki w stosunku do okna parenta +// CRect rcThisParent; +// GetWindowRect(&rcThisParent); +// GetParent()->ScreenToClient(&rcThisParent); + +// TempRect.OffsetRect(rcThisParent.left+2, rcThisParent.top+2); + m_pListBox->MoveWindow(TempRect); + + // Force the Expansion + OnComboBoxClick(); + break; + + } +} +void CPropertyListCtrl::OnEditLostFocus() +{ + // Get the text + CString csText; + m_pEditWnd->GetWindowText(csText); + + // Is the current item a text item + if(m_pCurItem->nType == ID_PROPERTY_TEXT) + { + // Did the text change + if(!m_bChanged) + return; + + m_pCurItem->csProperties.SetAt(0, csText); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); + } + else + { + // Get the window that has the focus now + if(GetFocus() == m_pComboButton || !m_pListBox->GetCount()) + return; + + // Did the text change + if(!m_bChanged) + return; + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); + + // Look for this text + m_bChanged = FALSE; + if( m_pListBox->FindStringExact(-1,csText) != LB_ERR) + return; + + // Add it and select it + m_pCurItem->nPropertySelected = m_pCurItem->csProperties.Add(csText); + } +} +void CPropertyListCtrl::OnEditChange() +{ + m_bChanged = TRUE; +} +void CPropertyListCtrl::OnFontPropertyClick() +{ + // Show the Dialog + CFontDialog FontDialog(&m_pCurItem->LogFont); + if(FontDialog.DoModal() != IDOK) + return; + + // Set the Font data + FontDialog.GetCurrentFont(&m_pCurItem->LogFont); + + // Redraw + RedrawWindow(); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); +} +void CPropertyListCtrl::OnPathPropertyClick() +{ + // Look for a ending tag + CString csExt = "*"; + CString csPath = m_pCurItem->csProperties.GetAt(0); + int nPos = csPath.ReverseFind('.'); + if(nPos) + csExt = csPath.Right(csPath.GetLength() - nPos - 1); + + // Show the Dialog + CFileDialog QuizFileDlg(TRUE, _T("*"), _T("*.") + csExt, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, m_pCurItem->csProperties.GetAt(1) ); + QuizFileDlg.m_ofn.lpstrInitialDir = csPath; + if(QuizFileDlg.DoModal() != IDOK) + return; + + // Obtain the Path they selected + m_pCurItem->csProperties.SetAt(0, QuizFileDlg.GetPathName()); + + // Redraw + RedrawWindow(); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); +} + +void CPropertyListCtrl::OnDirPropertyClick() +{ + CString strPath; + if (BrowseForFolder(m_pCurItem->csProperties.GetAt(1), &strPath)) + { + m_pCurItem->csProperties.SetAt(0, strPath); + RedrawWindow(); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); + } +} + +void CPropertyListCtrl::OnCustomPropertyClick() +{ + m_pCurItem->pfnCallback(m_pCurItem->lpParam, m_pCurItem->iParam, &m_Items, GetCurSel()); + RedrawWindow(); +} + +void CPropertyListCtrl::OnComboBoxClick() +{ + // Add the items + m_pListBox->ResetContent(); + + // Loop for all items + for( int nItem = 0; nItem < m_pCurItem->csProperties.GetSize(); nItem++) + m_pListBox->AddString(m_pCurItem->csProperties.GetAt(nItem)); + + // Select the correct item + m_pListBox->SetCurSel(m_pCurItem->nPropertySelected); + m_pListBox->SetTopIndex(m_pCurItem->nPropertySelected); + + // Show the List box + m_pListBox->ShowWindow(SW_NORMAL); +} +void CPropertyListCtrl::OnSelChange() +{ + // Set the new current item + m_pCurItem->nPropertySelected = m_pListBox->GetCurSel(); + + // Hide the Windows + m_pListBox->ShowWindow(SW_HIDE); + + if(m_pCurItem->bComboEditable) + m_pEditWnd->SetWindowText(m_pCurItem->csProperties.GetAt(m_pCurItem->nPropertySelected)); + else + RedrawWindow(); + + // Send the message that a property has changed + GetParent()->PostMessage(ID_PROPERTY_CHANGED, GetCurSel(), m_pCurItem->nType); + m_pComboButton->SetFocus(); +} +void CPropertyListCtrl::OnListboxLostFocus() +{ + m_pListBox->ShowWindow(SW_HIDE); +} +void CPropertyListCtrl::OnLButtonDown(UINT nFlags, CPoint point) +{ + // is there an item at this point + BOOL bOutside; + /*UINT uItem =*/ ItemFromPoint(point, bOutside); + + // Is this outside the client + if(bOutside) + HideControls(); + + CListBox::OnLButtonDown(nFlags, point); +} +void CPropertyListCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) +{ + // Hide the Controls + HideControls(); + + CListBox::OnVScroll(nSBCode, nPos, pScrollBar); +} + +///////////////////////////////////////////////////////////////////////////// +// GUI User Functions +///////////////////////////////////////////////////////////////////////////// + +void CPropertyListCtrl::Init() +{ + // utw�rz czcionk� bazowan� na czcionce okna + LOGFONT lf; + GetFont()->GetLogFont(&lf); + + if(m_pTextFont) delete m_pTextFont; + if(m_pSelectedFont) delete m_pSelectedFont; + + m_pTextFont=new CFont(); + m_pTextFont->CreateFontIndirect(&lf); + + lf.lfWeight=FW_BOLD; + m_pSelectedFont=new CFont(); + m_pSelectedFont->CreateFontIndirect(&lf); + + m_bDeleteFont=TRUE; + + // Create the Border Pen + m_pBorderPen = new CPen(PS_SOLID, 1, m_crBorderColor); + + // Create the Selected Background brush + m_pBkHighlightBrush = new CBrush(m_crHighlightColor); + m_pBkBrush = new CBrush(m_crBkColor); + + // Set the row height - read text height + CClientDC dc(this); + dc.SelectObject(&m_pSelectedFont); + TEXTMETRIC tm; + dc.GetTextMetrics(&tm); + + SetItemHeight(-1, MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY) ); +} + +void CPropertyListCtrl::SetFont(CFont* pFont) +{ + // Delete our font and set our font to theirs + if(m_pTextFont) delete m_pTextFont; + if(m_pSelectedFont) delete m_pSelectedFont; + m_pTextFont = pFont; + m_bDeleteFont = FALSE; + + // Figure out the text size + LOGFONT lpLogFont; + m_pTextFont->GetLogFont(&lpLogFont); + + // Set the font and redraw + CWnd::SetFont(m_pTextFont, FALSE); + + // Create the heading font with the bold attribute + lpLogFont.lfWeight = FW_BOLD; + m_pSelectedFont = new CFont(); + m_pSelectedFont->CreateFontIndirect(&lpLogFont); + + // Set the Row height + CClientDC dc(this); + dc.SelectObject(&m_pSelectedFont); + TEXTMETRIC tm; + dc.GetTextMetrics(&tm); + + SetItemHeight(-1, MulDiv(tm.tmHeight+tm.tmExternalLeading, dc.GetDeviceCaps(LOGPIXELSY), tm.tmDigitizedAspectY) ); + + // ** IMPLEMENT LATER ?? ** + // Recalculate the Width Position +} + +void CPropertyListCtrl::SetLineStyle(COLORREF crColor, int nStyle) +{ + // Delete the old Pen + if(m_pBorderPen) delete m_pBorderPen; + + // Create the brush + m_pBorderPen = new CPen(nStyle, 1, crColor); + m_crBorderColor = crColor; +} +void CPropertyListCtrl::SetBkColor(COLORREF crColor) +{ + // Delete the old brush + if(m_pBkBrush) delete m_pBkBrush; + + // Create the brush + m_pBkBrush = new CBrush(crColor); + m_crBkColor = crColor; +} +void CPropertyListCtrl::SetPropertyBkColor(COLORREF crColor) +{ + // Delete the old brush + if(m_pBkPropertyBrush) delete m_pBkPropertyBrush; + + // Create the brush + m_pBkPropertyBrush = new CBrush(crColor); + m_crPropertyBkColor = crColor; +} + +void CPropertyListCtrl::SetHighlightColor(COLORREF crColor) +{ + // Delete the old brush + if(m_pBkHighlightBrush) delete m_pBkHighlightBrush; + + // Create the brush + m_pBkHighlightBrush = new CBrush(crColor); + m_crHighlightColor = crColor; +} + +///////////////////////////////////////////////////////////////////////////// +// Add Properties Functions +///////////////////////////////////////////////////////////////////////////// +BOOL CPropertyListCtrl::AddString(CString csText) +{ + // Call our function (assume its a text Item) + return AddString(csText, ID_PROPERTY_STATIC, _T("")); +} + +BOOL CPropertyListCtrl::AddString(UINT nIDString) +{ + return AddString(GetResManager()->LoadString(nIDString)); +} + +BOOL CPropertyListCtrl::AddString(UINT nIDString, int nType, CString csData, void (*pfnCallback)(LPVOID, int, CPtrList*, int), LPVOID lpParam, int iParam, int nPropertySelected, int nAlignment, BOOL bComboEditable) +{ + // Is this a valid Control type + if(nType > ID_PROPERTY_COMBO_LIST) + return FALSE; + + // load string + const TCHAR *pszText=GetResManager()->LoadString(nIDString); + + // Create a new Structure to hold it + PROPERTYITEM* pNewItem = new PROPERTYITEM; + pNewItem->nType = nType; + pNewItem->nAlignment = nAlignment; + pNewItem->pBrush = NULL; + pNewItem->bComboEditable = bComboEditable; + pNewItem->pfnCallback=pfnCallback; + pNewItem->iParam=iParam; + pNewItem->lpParam=lpParam; + + // Calculate the Width of the string based on the font set + CDC* pDC = GetDC(); + pDC->SelectObject(m_pSelectedFont); + CSize Size = pDC->GetTextExtent(pszText); + if(Size.cx + 10 > m_nWidestItem) + m_nWidestItem = Size.cx + 10; + ReleaseDC(pDC); + pNewItem->nWidth = Size.cx; + pNewItem->nPropertySelected = nPropertySelected; + + // Set Property + if(!SetProperty(pNewItem, nType, csData)) + { + delete pNewItem; + return FALSE; + } + + // Is the item set bigger than the number of properties + if(pNewItem->nPropertySelected > pNewItem->csProperties.GetSize()) + { + delete pNewItem; + return FALSE; + } + + // Add to the list + m_Items.AddTail(pNewItem); + + // Add the string to the list box + /*int nPos =*/ CListBox::AddString(pszText); + + // Create the Control if Needed + CreateControl(nType); + return TRUE; +} + +BOOL CPropertyListCtrl::AddString(CString csText, int nType, CString csData, int nPropertySelected, int nAlignment, BOOL bComboEditable) +{ + // Is this a valid Control type + if(nType > ID_PROPERTY_COMBO_LIST) + return FALSE; + + // Create a new Structure to hold it + PROPERTYITEM* pNewItem = new PROPERTYITEM; + pNewItem->nType = nType; + pNewItem->nAlignment = nAlignment; + pNewItem->pBrush = NULL; + pNewItem->bComboEditable = bComboEditable; + + // Calculate the Width of the string based on the font set + CDC* pDC = GetDC(); + pDC->SelectObject(m_pSelectedFont); + CSize Size = pDC->GetTextExtent(csText); + if(Size.cx + 10 > m_nWidestItem) + m_nWidestItem = Size.cx + 10; + ReleaseDC(pDC); + pNewItem->nWidth = Size.cx; + pNewItem->nPropertySelected = nPropertySelected; + + // Set Property + if(!SetProperty(pNewItem, nType, csData)) + { + delete pNewItem; + return FALSE; + } + + // Is the item set bigger than the number of properties + if(pNewItem->nPropertySelected > pNewItem->csProperties.GetSize()) + { + delete pNewItem; + return FALSE; + } + + // Add to the list + m_Items.AddTail(pNewItem); + + // Add the string to the list box + /*int nPos =*/ CListBox::AddString(csText); + + // Create the Control if Needed + CreateControl(nType); + return TRUE; +} + +BOOL CPropertyListCtrl::AddString(UINT nIDString, int nType, UINT nIDData, int nPropertySelected, int nAlignment, BOOL bComboEditable) +{ + return AddString(GetResManager()->LoadString(nIDString), nType, GetResManager()->LoadString(nIDData), nPropertySelected, nAlignment, bComboEditable); +} + +BOOL CPropertyListCtrl::AddString(UINT nIDString, int nType, CString csData, int nPropertySelected, int nAlignment, BOOL bComboEditable) +{ + return AddString(GetResManager()->LoadString(nIDString), nType, csData, nPropertySelected, nAlignment, bComboEditable); +} + +BOOL CPropertyListCtrl::AddString(CString csText, COLORREF crColor, int nAlignment) +{ + // Create a new brush based on this color + m_pCurBrush = new CBrush(crColor); + + // Call the other functions + return AddString(csText, ID_PROPERTY_COLOR, _T(""), 0, nAlignment); +} + +BOOL CPropertyListCtrl::AddString(UINT nIDString, COLORREF crColor, int nAlignment) +{ + return AddString(GetResManager()->LoadString(nIDString), crColor, nAlignment); +} + +BOOL CPropertyListCtrl::AddString(CString csText, CFont* pFont, int nAlignment) +{ + // Safe the Font + m_pCurFont = pFont; + + // Call the other functions + return AddString(csText, ID_PROPERTY_FONT, _T(""), 0, nAlignment); +} + +BOOL CPropertyListCtrl::AddString(UINT nIDString, CFont* pFont, int nAlignment) +{ + return AddString(GetResManager()->LoadString(nIDString), pFont, nAlignment); +} + +///////////////////////////////////////////////////////////////////////////// +// Helper Functions +///////////////////////////////////////////////////////////////////////////// +void CPropertyListCtrl::DrawItem(CDC* pDC, CRect ItemRect, BOOL bSelected) +{ + if (m_pCurDrawItem->nType != ID_PROPERTY_STATIC) + { + ///////////////////////////////////////// + // Paint the Background rectangle (Property Value) + if(m_pCurDrawItem->nType == ID_PROPERTY_COLOR) + pDC->SelectObject(m_pCurDrawItem->pBrush); + else + pDC->SelectObject(m_pBkBrush); + pDC->SelectObject(m_pBorderPen); + + // Draw the Rectangle + ItemRect.left = m_nWidestItem - 1; + ItemRect.top--; + ItemRect.right++; + pDC->Rectangle(ItemRect); + CRect OrginalRect = ItemRect; + + ///////////////////////////////////////// + // Draw the Property Text + pDC->SetBkMode(TRANSPARENT); + pDC->SelectObject(m_pBkBrush); + pDC->SelectObject(m_pTextFont); + pDC->SetTextColor(m_crTextColor); + DrawPropertyText(pDC, ItemRect); + + ///////////////////////////////////////// + // Paint the Background rectangle (Property Name) + if( bSelected ) + pDC->SelectObject(m_pBkHighlightBrush); + + // Draw the Rectangle + ItemRect.right = m_nWidestItem; + ItemRect.left = -1; + pDC->Rectangle(ItemRect); + + ///////////////////////////////////////// + // Paint the Property name Text + // Is this item selected? + if( bSelected ) + { + if(m_bBoldSelection) pDC->SelectObject(m_pSelectedFont); + pDC->SetTextColor(m_crTextHighlightColor); + m_pCurItem = m_pCurDrawItem; + m_CurRect = OrginalRect; + } + + // Draw the Text + ItemRect.left += 6; + ItemRect.right -= 5; + pDC->DrawText( m_csText, m_csText.GetLength(), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_NOPREFIX|m_pCurDrawItem->nAlignment); + } + else + { + ///////////////////////////////////////// + // Paint the Background rectangle (Property Value) + pDC->SelectObject(m_pBkHighlightBrush); + pDC->SelectObject(m_pBorderPen); + pDC->SelectObject(m_pSelectedFont); + + // Draw the Rectangle + pDC->Rectangle(ItemRect); + CRect OrginalRect = ItemRect; + + ///////////////////////////////////////// + // Draw + pDC->SetBkMode(TRANSPARENT); + pDC->SetTextColor(m_crTextHighlightColor); + if (bSelected) + { + m_pCurItem = m_pCurDrawItem; + m_CurRect = OrginalRect; + } + + // Draw the Text + pDC->DrawText( m_csText, m_csText.GetLength(), ItemRect, DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER|DT_CENTER); + } +} + +void CPropertyListCtrl::DrawPropertyText(CDC* pDC, CRect ItemRect) +{ + ItemRect.left += 5; + switch(m_pCurDrawItem->nType) + { + case ID_PROPERTY_BOOL: + case ID_PROPERTY_COMBO_LIST: + { + CString strText; + INT_PTR iCount = m_pCurDrawItem->csProperties.GetCount(); + if(m_pCurDrawItem->nPropertySelected >= 0 && m_pCurDrawItem->nPropertySelected < iCount) + strText = m_pCurDrawItem->csProperties.GetAt(m_pCurDrawItem->nPropertySelected); + + pDC->DrawText( strText, strText.GetLength(), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX); + break; + } + + case ID_PROPERTY_TEXT: + case ID_PROPERTY_PATH: + case ID_PROPERTY_DIR: + case ID_PROPERTY_CUSTOM: + case ID_PROPERTY_STATIC: + { + CString strText; + INT_PTR iCount = m_pCurDrawItem->csProperties.GetCount(); + if(iCount > 0) + strText = m_pCurDrawItem->csProperties.GetAt(0); + + pDC->DrawText( strText, strText.GetLength(), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX); + break; + } + + case ID_PROPERTY_FONT: + if(m_pCurDrawItem->LogFont.lfHeight) + pDC->DrawText( m_pCurDrawItem->LogFont.lfFaceName, _tcslen(m_pCurDrawItem->LogFont.lfFaceName), ItemRect, DT_SINGLELINE|DT_VCENTER|DT_LEFT|DT_NOPREFIX); + break; + } +} + +void CPropertyListCtrl::CreateControl(int nType) +{ + switch(nType) + { + // Edit Window + case ID_PROPERTY_TEXT: + if(!m_pEditWnd) + { + m_pEditWnd = new CEdit(); + m_pEditWnd->Create(WS_CHILD|ES_AUTOHSCROLL|ES_LEFT, CRect(0,0,100,100), this, ID_PROPERTY_TEXT); + m_pEditWnd->SetFont(m_pTextFont); + } + break; + + // Font Button + case ID_PROPERTY_FONT: + if(!m_pFontButton) + { + m_pFontButton = new CButton(); + m_pFontButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_FONT); + m_pFontButton->SetFont(m_pTextFont); + } + break; + + case ID_PROPERTY_PATH: + if(!m_pPathButton) + { + m_pPathButton = new CButton(); + m_pPathButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_PATH); + m_pPathButton->SetFont(m_pTextFont); + } + break; + + case ID_PROPERTY_DIR: + if(!m_pDirButton) + { + m_pDirButton = new CButton(); + m_pDirButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_DIR); + m_pDirButton->SetFont(m_pTextFont); + } + break; + + case ID_PROPERTY_CUSTOM: + if(!m_pCustomButton) + { + m_pCustomButton = new CButton(); + m_pCustomButton->Create(_T("..."), WS_CHILD|BS_PUSHBUTTON, CRect(0,0,100,100), this, ID_PROPERTY_CUSTOM); + m_pCustomButton->SetFont(m_pTextFont); + } + break; + + case ID_PROPERTY_COMBO_LIST: + if(!m_pEditWnd) + { + m_pEditWnd = new CEdit(); + m_pEditWnd->Create(WS_CHILD|ES_AUTOHSCROLL|ES_LEFT, CRect(0,0,100,100), this, ID_PROPERTY_TEXT); + m_pEditWnd->SetFont(m_pTextFont); + } + if(!m_pListBox) + { + m_pListBox = new CListBox(); + m_pListBox->Create(WS_CHILD|WS_BORDER|LBS_NOTIFY|WS_VSCROLL|LBS_HASSTRINGS, CRect(0,0,100,100), this, ID_PROPERTY_COMBO_LIST); + m_pListBox->SetFont(m_pTextFont); + + m_pComboButton = new CComboButton(); + m_pComboButton->Create(CRect(0,0,0,0), this, ID_PROPERTY_COMBO_BTN ); + } + break; + } +} + +BOOL CPropertyListCtrl::SetProperty(PROPERTYITEM* pPropertyItem, int nType, CString csData) +{ + switch(nType) + { + case ID_PROPERTY_BOOL: + case ID_PROPERTY_PATH: + case ID_PROPERTY_DIR: + ParseProperties(pPropertyItem, csData); + + // Is the item selected more than items in the array? + if(pPropertyItem->csProperties.GetSize() != 2 ) + return FALSE; + break; + + case ID_PROPERTY_TEXT: + case ID_PROPERTY_STATIC: + case ID_PROPERTY_CUSTOM: + pPropertyItem->csProperties.Add(csData); + break; + + case ID_PROPERTY_FONT: + memset(&pPropertyItem->LogFont, 0, sizeof(pPropertyItem->LogFont)); + if(m_pCurFont) + { + m_pCurFont->GetLogFont(&pPropertyItem->LogFont); + m_pCurFont = NULL; + } + break; + + case ID_PROPERTY_COLOR: + pPropertyItem->pBrush = m_pCurBrush; + break; + + case ID_PROPERTY_COMBO_LIST: + ParseProperties(pPropertyItem, csData); + break; + + } + + return TRUE; +} + +void CPropertyListCtrl::ParseProperties(PROPERTYITEM* pPropertyItem, CString csData) +{ + // Parse the Items + TCHAR* pText = csData.GetBuffer( csData.GetLength() ); + TCHAR* pWord; + TCHAR Separations[] = _T("!"); + + // Establish string and get the first token: + pWord = _tcstok( pText, Separations); + while( pWord != NULL ) + { + // Add this to the Array + pPropertyItem->csProperties.Add(pWord); + + // Get next token + pWord = _tcstok( NULL, Separations ); + } + + // Release the buffer + csData.ReleaseBuffer(); +} + +void CPropertyListCtrl::HideControls() +{ + // Hide the controls + if(m_pEditWnd) m_pEditWnd->ShowWindow(SW_HIDE); + if(m_pFontButton) m_pFontButton->ShowWindow(SW_HIDE); + if(m_pPathButton) m_pPathButton->ShowWindow(SW_HIDE); + if (m_pDirButton) m_pDirButton->ShowWindow(SW_HIDE); + if (m_pCustomButton) + m_pCustomButton->ShowWindow(SW_HIDE); + if(m_pListBox) m_pListBox->ShowWindow(SW_HIDE); + if(m_pComboButton) m_pComboButton->ShowWindow(SW_HIDE); +} + +///////////////////////////////////////////////////////////////////////////// +// Get Properties Functions +///////////////////////////////////////////////////////////////////////////// +bool CPropertyListCtrl::GetProperty(int nItem, CString* pText) +{ + // is the item to high + if(nItem + 1 > GetCount()) + return false; + + // Make sure this item is the correct type + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); + if(pItem->nType != ID_PROPERTY_TEXT && pItem->nType != ID_PROPERTY_PATH && pItem->nType != ID_PROPERTY_DIR && pItem->nType != ID_PROPERTY_STATIC && pItem->nType != ID_PROPERTY_CUSTOM) + return false; + + // Copy the item + *pText = pItem->csProperties.GetAt(0); + return true; +} +bool CPropertyListCtrl::GetProperty(int nItem, bool* bValue) +{ + // is the item to high + if(nItem + 1 > GetCount()) + return false; + + // Make sure this item is the correct type + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); + if(pItem->nType != ID_PROPERTY_BOOL) + return false; + + // Copy the item + *bValue = pItem->nPropertySelected != 0; + return true; +} +bool CPropertyListCtrl::GetProperty(int nItem, COLORREF* crColor) +{ + // is the item to high + if(nItem + 1 > GetCount()) + return false; + + // Make sure this item is the correct type + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); + if(pItem->nType != ID_PROPERTY_COLOR) + return false; + + // Copy the item + LOGBRUSH LogBrush; + pItem->pBrush->GetLogBrush(&LogBrush); + *crColor = LogBrush.lbColor; + return true; +} +bool CPropertyListCtrl::GetProperty(int nItem, LOGFONT* LogFont) +{ + // is the item to high + if(nItem + 1 > GetCount()) + return false; + + // Make sure this item is the correct type + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); + if(pItem->nType != ID_PROPERTY_FONT) + return false; + + // Copy the item + *LogFont = pItem->LogFont; + return true; +} +bool CPropertyListCtrl::GetProperty(int nItem, CStringArray* pArray, int* /*SelectedItem*/) +{ + // is the item to high + if(nItem + 1 > GetCount()) + return false; + + // Make sure this item is the correct type + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); + if(pItem->nType != ID_PROPERTY_COMBO_LIST) + return false; + + // I do NOT want to send them a pointer to my array so I loop through and copy the item to thiers + for( int nString = 0; nString < pItem->csProperties.GetSize(); nString++) + pArray->Add(pItem->csProperties.GetAt(nString)); + return true; +} +bool CPropertyListCtrl::GetProperty(int nItem, int* SelectedItem, CString* pText) +{ + // is the item to high + if(nItem + 1 > GetCount()) + return false; + + // Make sure this item is the correct type + PROPERTYITEM* pItem; + pItem = (PROPERTYITEM*)m_Items.GetAt(m_Items.FindIndex(nItem)); + + // Copy the item + *SelectedItem = pItem->nPropertySelected; + + // Do they want the text + if(pText != NULL && pItem->nType == ID_PROPERTY_COMBO_LIST) + *pText = pItem->csProperties.GetAt(pItem->nPropertySelected); + return true; +} Index: src/ch/PropertyListCtrl.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/PropertyListCtrl.h (.../PropertyListCtrl.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/PropertyListCtrl.h (.../PropertyListCtrl.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,230 +1,230 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __PROPERTYLIST_H__ -#define __PROPERTYLIST_H__ - -#include "memdc.h" - -// Property Type -#define ID_PROPERTY_TEXT 1 -#define ID_PROPERTY_BOOL 2 -#define ID_PROPERTY_COLOR 3 -#define ID_PROPERTY_FONT 4 -#define ID_PROPERTY_PATH 5 -#define ID_PROPERTY_DIR 6 -#define ID_PROPERTY_CUSTOM 7 -#define ID_PROPERTY_STATIC 8 -#define ID_PROPERTY_COMBO_BTN 9 -#define ID_PROPERTY_COMBO_LIST 10 - -// Message ID to parent -#define ID_PROPERTY_CHANGED WM_USER+15 - -// Holds an item -typedef struct PropertyItem_t -{ - int nType; - int nWidth; - int nAlignment; - int nPropertySelected; - BOOL bComboEditable; - LOGFONT LogFont; - CBrush* pBrush; - CStringArray csProperties; - - // custom - void (*pfnCallback)(LPVOID, int, CPtrList*, int); - LPVOID lpParam; // ptr to the dialog - int iParam; // other data - -} PROPERTYITEM; - -///////////////////////////////////////////////////////////////////////////// -// CComboButton window -class CComboButton : public CButton -{ - void DrawTriangle(CDC* pDC, CRect Rect); - -// Construction -public: - BOOL Create( CRect Rect, CWnd* pParent, UINT uID); - CComboButton(); - -// Attributes -public: - CPen* m_pBkPen; -// CPen* m_pGrayPen; - CBrush* m_pBkBrush; - CBrush* m_pBlackBrush; - -// Operations -public: - - virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct ); - virtual void MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/); - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CComboButton) - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~CComboButton(); - - // Generated message map functions -protected: - //{{AFX_MSG(CComboButton) - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() -}; - - -///////////////////////////////////////////////////////////////////////////// -// CPropertyListCtrl window -class CPropertyListCtrl : public CListBox -{ - int m_nWidestItem; - BOOL m_bDeleteFont; - BOOL m_bBoldSelection; - BOOL m_bChanged; - CPen* m_pBorderPen; - CRect m_CurRect; - CFont* m_pTextFont; - CFont* m_pSelectedFont; - CFont* m_pCurFont; - CString m_csText; - CBrush* m_pCurBrush; - CBrush* m_pBkBrush; - CBrush* m_pBkHighlightBrush; - CBrush* m_pBkPropertyBrush; - CButton* m_pFontButton; - CButton* m_pPathButton; - CButton* m_pDirButton; - CButton* m_pCustomButton; - CComboButton* m_pComboButton; - CListBox* m_pListBox; - - COLORREF m_crBorderColor; - COLORREF m_crBkColor; - COLORREF m_crTextColor; - COLORREF m_crTextHighlightColor; - COLORREF m_crHighlightColor; - COLORREF m_crPropertyBkColor; - COLORREF m_crPropertyTextColor; - - // Controls - CEdit* m_pEditWnd; - - // The item list - CPtrList m_Items; - PROPERTYITEM* m_pCurItem; - PROPERTYITEM* m_pCurDrawItem; - -// Construction -public: - CPropertyListCtrl(); - -// Attributes -private: - // Helper Functions - void DrawItem(CDC* pDC, CRect ItemRect, BOOL bSelected); - void DrawPropertyText(CDC* pDC, CRect ItemRect); - void CreateControl(int nType); - BOOL SetProperty(PROPERTYITEM* pPropertyItem, int nType, CString csData); - void ParseProperties(PROPERTYITEM* pPropertyItem, CString csData); -public: - void HideControls(); - -// Operations -public: - // GUI Functions - void SetFont(CFont* pFont); - void SetBkColor(COLORREF crColor); - void SetPropertyBkColor(COLORREF crColor); - void SetHighlightColor(COLORREF crColor); - void SetLineStyle(COLORREF crColor, int nStyle = PS_SOLID); - inline void SetBoldSelection(BOOL bBoldSelection) { m_bBoldSelection = bBoldSelection; }; - inline void SetTextColor(COLORREF crColor) { m_crTextColor = crColor; }; - inline void SetTextHighlightColor(COLORREF crColor) { m_crTextHighlightColor = crColor; }; - inline void SetPropertyTextColor(COLORREF crColor) { m_crPropertyTextColor = crColor; }; - - // Add the data - BOOL AddString(CString csText); - BOOL AddString(UINT nIDString); - - BOOL AddString(CString csText, int nType, CString csData, int nPropertySelected = 0, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); - BOOL AddString(UINT nIDString, int nType, UINT nIDData, int nPropertySelected = 0, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); - BOOL AddString(UINT nIDString, int nType, CString csData, int nPropertySelected = 0, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); - BOOL AddString(UINT nIDString, int nType, CString csData, void (*pfnCallback)(LPVOID, int, CPtrList*, int), LPVOID lpParam, int iParam, int nPropertySelected, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); - - BOOL AddString(CString csText, COLORREF crColor, int nAlignment = DT_LEFT); - BOOL AddString(UINT nIDString, COLORREF crColor, int nAlignment = DT_LEFT); - - BOOL AddString(CString csText, CFont* pFont, int nAlignment = DT_LEFT); - BOOL AddString(UINT nIDString, CFont* pFont, int nAlignment = DT_LEFT); - - // Get the Data - bool GetProperty(int nItem, CString* pText); - bool GetProperty(int nItem, bool* bValue); - bool GetProperty(int nItem, COLORREF* crColor); - bool GetProperty(int nItem, LOGFONT* LogFont); - bool GetProperty(int nItem, CStringArray* pArray, int* /*SelectedItem = NULL*/); - bool GetProperty(int nItem, int* SelectedItem, CString* csText = NULL); - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CPropertyListCtrl) - public: - virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); - virtual void MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/); - //}}AFX_VIRTUAL - -// Implementation -public: - void Init(); - virtual ~CPropertyListCtrl(); - void Reset(); - void Reinit(); - - // Generated message map functions -protected: - //{{AFX_MSG(CPropertyListCtrl) - afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/); - afx_msg void OnSelchange(); - afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); - afx_msg void OnDblclk(); - afx_msg void OnEditLostFocus(); - afx_msg void OnEditChange(); - afx_msg void OnFontPropertyClick(); - afx_msg void OnPathPropertyClick(); - afx_msg void OnDirPropertyClick(); - afx_msg void OnCustomPropertyClick(); - afx_msg void OnComboBoxClick(); - afx_msg void OnSelChange(); - afx_msg void OnListboxLostFocus(); - afx_msg void OnLButtonDown(UINT nFlags, CPoint point); - afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() -}; - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __PROPERTYLIST_H__ +#define __PROPERTYLIST_H__ + +#include "memdc.h" + +// Property Type +#define ID_PROPERTY_TEXT 1 +#define ID_PROPERTY_BOOL 2 +#define ID_PROPERTY_COLOR 3 +#define ID_PROPERTY_FONT 4 +#define ID_PROPERTY_PATH 5 +#define ID_PROPERTY_DIR 6 +#define ID_PROPERTY_CUSTOM 7 +#define ID_PROPERTY_STATIC 8 +#define ID_PROPERTY_COMBO_BTN 9 +#define ID_PROPERTY_COMBO_LIST 10 + +// Message ID to parent +#define ID_PROPERTY_CHANGED WM_USER+15 + +// Holds an item +typedef struct PropertyItem_t +{ + int nType; + int nWidth; + int nAlignment; + int nPropertySelected; + BOOL bComboEditable; + LOGFONT LogFont; + CBrush* pBrush; + CStringArray csProperties; + + // custom + void (*pfnCallback)(LPVOID, int, CPtrList*, int); + LPVOID lpParam; // ptr to the dialog + int iParam; // other data + +} PROPERTYITEM; + +///////////////////////////////////////////////////////////////////////////// +// CComboButton window +class CComboButton : public CButton +{ + void DrawTriangle(CDC* pDC, CRect Rect); + +// Construction +public: + BOOL Create( CRect Rect, CWnd* pParent, UINT uID); + CComboButton(); + +// Attributes +public: + CPen* m_pBkPen; +// CPen* m_pGrayPen; + CBrush* m_pBkBrush; + CBrush* m_pBlackBrush; + +// Operations +public: + + virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct ); + virtual void MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/); + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CComboButton) + //}}AFX_VIRTUAL + +// Implementation +public: + virtual ~CComboButton(); + + // Generated message map functions +protected: + //{{AFX_MSG(CComboButton) + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() +}; + + +///////////////////////////////////////////////////////////////////////////// +// CPropertyListCtrl window +class CPropertyListCtrl : public CListBox +{ + int m_nWidestItem; + BOOL m_bDeleteFont; + BOOL m_bBoldSelection; + BOOL m_bChanged; + CPen* m_pBorderPen; + CRect m_CurRect; + CFont* m_pTextFont; + CFont* m_pSelectedFont; + CFont* m_pCurFont; + CString m_csText; + CBrush* m_pCurBrush; + CBrush* m_pBkBrush; + CBrush* m_pBkHighlightBrush; + CBrush* m_pBkPropertyBrush; + CButton* m_pFontButton; + CButton* m_pPathButton; + CButton* m_pDirButton; + CButton* m_pCustomButton; + CComboButton* m_pComboButton; + CListBox* m_pListBox; + + COLORREF m_crBorderColor; + COLORREF m_crBkColor; + COLORREF m_crTextColor; + COLORREF m_crTextHighlightColor; + COLORREF m_crHighlightColor; + COLORREF m_crPropertyBkColor; + COLORREF m_crPropertyTextColor; + + // Controls + CEdit* m_pEditWnd; + + // The item list + CPtrList m_Items; + PROPERTYITEM* m_pCurItem; + PROPERTYITEM* m_pCurDrawItem; + +// Construction +public: + CPropertyListCtrl(); + +// Attributes +private: + // Helper Functions + void DrawItem(CDC* pDC, CRect ItemRect, BOOL bSelected); + void DrawPropertyText(CDC* pDC, CRect ItemRect); + void CreateControl(int nType); + BOOL SetProperty(PROPERTYITEM* pPropertyItem, int nType, CString csData); + void ParseProperties(PROPERTYITEM* pPropertyItem, CString csData); +public: + void HideControls(); + +// Operations +public: + // GUI Functions + void SetFont(CFont* pFont); + void SetBkColor(COLORREF crColor); + void SetPropertyBkColor(COLORREF crColor); + void SetHighlightColor(COLORREF crColor); + void SetLineStyle(COLORREF crColor, int nStyle = PS_SOLID); + inline void SetBoldSelection(BOOL bBoldSelection) { m_bBoldSelection = bBoldSelection; }; + inline void SetTextColor(COLORREF crColor) { m_crTextColor = crColor; }; + inline void SetTextHighlightColor(COLORREF crColor) { m_crTextHighlightColor = crColor; }; + inline void SetPropertyTextColor(COLORREF crColor) { m_crPropertyTextColor = crColor; }; + + // Add the data + BOOL AddString(CString csText); + BOOL AddString(UINT nIDString); + + BOOL AddString(CString csText, int nType, CString csData, int nPropertySelected = 0, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); + BOOL AddString(UINT nIDString, int nType, UINT nIDData, int nPropertySelected = 0, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); + BOOL AddString(UINT nIDString, int nType, CString csData, int nPropertySelected = 0, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); + BOOL AddString(UINT nIDString, int nType, CString csData, void (*pfnCallback)(LPVOID, int, CPtrList*, int), LPVOID lpParam, int iParam, int nPropertySelected, int nAlignment = DT_LEFT, BOOL bComboEditable = FALSE); + + BOOL AddString(CString csText, COLORREF crColor, int nAlignment = DT_LEFT); + BOOL AddString(UINT nIDString, COLORREF crColor, int nAlignment = DT_LEFT); + + BOOL AddString(CString csText, CFont* pFont, int nAlignment = DT_LEFT); + BOOL AddString(UINT nIDString, CFont* pFont, int nAlignment = DT_LEFT); + + // Get the Data + bool GetProperty(int nItem, CString* pText); + bool GetProperty(int nItem, bool* bValue); + bool GetProperty(int nItem, COLORREF* crColor); + bool GetProperty(int nItem, LOGFONT* LogFont); + bool GetProperty(int nItem, CStringArray* pArray, int* /*SelectedItem = NULL*/); + bool GetProperty(int nItem, int* SelectedItem, CString* csText = NULL); + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CPropertyListCtrl) + public: + virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); + virtual void MeasureItem(LPMEASUREITEMSTRUCT /*lpMeasureItemStruct*/); + //}}AFX_VIRTUAL + +// Implementation +public: + void Init(); + virtual ~CPropertyListCtrl(); + void Reset(); + void Reinit(); + + // Generated message map functions +protected: + //{{AFX_MSG(CPropertyListCtrl) + afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/); + afx_msg void OnSelchange(); + afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); + afx_msg void OnDblclk(); + afx_msg void OnEditLostFocus(); + afx_msg void OnEditChange(); + afx_msg void OnFontPropertyClick(); + afx_msg void OnPathPropertyClick(); + afx_msg void OnDirPropertyClick(); + afx_msg void OnCustomPropertyClick(); + afx_msg void OnComboBoxClick(); + afx_msg void OnSelChange(); + afx_msg void OnListboxLostFocus(); + afx_msg void OnLButtonDown(UINT nFlags, CPoint point); + afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() +}; + +#endif Index: src/ch/RecentDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/RecentDlg.cpp (.../RecentDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/RecentDlg.cpp (.../RecentDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,173 +1,173 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "RecentDlg.h" -#include "dialogs.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CRecentDlg dialog - - -CRecentDlg::CRecentDlg(CWnd* pParent /*=NULL*/) - :ictranslate::CLanguageDialog(CRecentDlg::IDD, pParent) -{ - //{{AFX_DATA_INIT(CRecentDlg) - m_strPath = _T(""); - //}}AFX_DATA_INIT -} - - -void CRecentDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CRecentDlg) - DDX_Control(pDX, IDC_RECENT_LIST, m_ctlRecent); - DDX_Text(pDX, IDC_PATH_EDIT, m_strPath); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CRecentDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CRecentDlg) - ON_NOTIFY(LVN_ITEMCHANGED, IDC_RECENT_LIST, OnItemchangedRecentList) - ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton) - ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton) - ON_BN_CLICKED(IDC_CHANGE_BUTTON, OnChangeButton) - ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CRecentDlg message handlers - -BOOL CRecentDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // system image list - SHFILEINFO sfi; - m_himl = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - m_hliml=(HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX); - m_ctlRecent.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)m_himl); - m_ctlRecent.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)m_hliml); - - // modify list style - m_ctlRecent.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_INFOTIP | LVS_EX_UNDERLINEHOT); - - // update recent paths - for (int i=0;i<(int)m_cvRecent.size();i++) - { - sfi.iIcon=-1; - SHGetFileInfo(m_cvRecent.at(i), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlRecent.InsertItem(i, m_cvRecent.at(i), sfi.iIcon); - } - - return TRUE; -} - -void CRecentDlg::OnItemchangedRecentList(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_LISTVIEW* plv = (NM_LISTVIEW*)pNMHDR; - - // current selection - if (plv->iItem >= 0 && plv->iItem < (int)m_cvRecent.size()) - { - m_strPath=m_cvRecent.at(plv->iItem); - UpdateData(FALSE); - } - - *pResult = 0; -} - -void CRecentDlg::OnBrowseButton() -{ - CString strPath; - if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) - { - m_strPath=strPath; - UpdateData(FALSE); - } -} - -void CRecentDlg::OnAddButton() -{ - UpdateData(TRUE); - if (m_strPath.IsEmpty()) - return; - - // add to a table - m_cvRecent.push_back((const PTSTR)(LPCTSTR)m_strPath, true); - - // add to list with an icon - SHFILEINFO sfi; - sfi.iIcon=-1; - SHGetFileInfo(m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlRecent.InsertItem(m_cvRecent.size()-1, m_strPath, sfi.iIcon); -} - -void CRecentDlg::OnChangeButton() -{ - // read selection index - POSITION pos=m_ctlRecent.GetFirstSelectedItemPosition(); - if (pos) - { - // index - int iPos=m_ctlRecent.GetNextSelectedItem(pos); - - UpdateData(TRUE); - - if (m_strPath.IsEmpty()) - return; - - // array update - m_cvRecent.replace(m_cvRecent.begin()+iPos, (const PTSTR)(LPCTSTR)m_strPath, true, true); - - // list - SHFILEINFO sfi; - sfi.iIcon=-1; - SHGetFileInfo(m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - - m_ctlRecent.DeleteItem(iPos); - m_ctlRecent.InsertItem(iPos, m_strPath, sfi.iIcon); - } -} - -void CRecentDlg::OnDeleteButton() -{ - POSITION pos=m_ctlRecent.GetFirstSelectedItemPosition(); - int iPos=-1; - while (pos) - { - iPos=m_ctlRecent.GetNextSelectedItem(pos); - m_cvRecent.erase(m_cvRecent.begin()+iPos, true); - m_ctlRecent.DeleteItem(iPos); - } - - if (iPos != -1) - m_ctlRecent.SetItemState(iPos, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "RecentDlg.h" +#include "dialogs.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CRecentDlg dialog + + +CRecentDlg::CRecentDlg(CWnd* pParent /*=NULL*/) + :ictranslate::CLanguageDialog(CRecentDlg::IDD, pParent) +{ + //{{AFX_DATA_INIT(CRecentDlg) + m_strPath = _T(""); + //}}AFX_DATA_INIT +} + + +void CRecentDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CRecentDlg) + DDX_Control(pDX, IDC_RECENT_LIST, m_ctlRecent); + DDX_Text(pDX, IDC_PATH_EDIT, m_strPath); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CRecentDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CRecentDlg) + ON_NOTIFY(LVN_ITEMCHANGED, IDC_RECENT_LIST, OnItemchangedRecentList) + ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton) + ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton) + ON_BN_CLICKED(IDC_CHANGE_BUTTON, OnChangeButton) + ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CRecentDlg message handlers + +BOOL CRecentDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // system image list + SHFILEINFO sfi; + m_himl = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + m_hliml=(HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX); + m_ctlRecent.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)m_himl); + m_ctlRecent.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)m_hliml); + + // modify list style + m_ctlRecent.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_INFOTIP | LVS_EX_UNDERLINEHOT); + + // update recent paths + for (int i=0;i<(int)m_cvRecent.size();i++) + { + sfi.iIcon=-1; + SHGetFileInfo(m_cvRecent.at(i), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlRecent.InsertItem(i, m_cvRecent.at(i), sfi.iIcon); + } + + return TRUE; +} + +void CRecentDlg::OnItemchangedRecentList(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_LISTVIEW* plv = (NM_LISTVIEW*)pNMHDR; + + // current selection + if (plv->iItem >= 0 && plv->iItem < (int)m_cvRecent.size()) + { + m_strPath=m_cvRecent.at(plv->iItem); + UpdateData(FALSE); + } + + *pResult = 0; +} + +void CRecentDlg::OnBrowseButton() +{ + CString strPath; + if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) + { + m_strPath=strPath; + UpdateData(FALSE); + } +} + +void CRecentDlg::OnAddButton() +{ + UpdateData(TRUE); + if (m_strPath.IsEmpty()) + return; + + // add to a table + m_cvRecent.push_back((const PTSTR)(LPCTSTR)m_strPath, true); + + // add to list with an icon + SHFILEINFO sfi; + sfi.iIcon=-1; + SHGetFileInfo(m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlRecent.InsertItem(m_cvRecent.size()-1, m_strPath, sfi.iIcon); +} + +void CRecentDlg::OnChangeButton() +{ + // read selection index + POSITION pos=m_ctlRecent.GetFirstSelectedItemPosition(); + if (pos) + { + // index + int iPos=m_ctlRecent.GetNextSelectedItem(pos); + + UpdateData(TRUE); + + if (m_strPath.IsEmpty()) + return; + + // array update + m_cvRecent.replace(m_cvRecent.begin()+iPos, (const PTSTR)(LPCTSTR)m_strPath, true, true); + + // list + SHFILEINFO sfi; + sfi.iIcon=-1; + SHGetFileInfo(m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + + m_ctlRecent.DeleteItem(iPos); + m_ctlRecent.InsertItem(iPos, m_strPath, sfi.iIcon); + } +} + +void CRecentDlg::OnDeleteButton() +{ + POSITION pos=m_ctlRecent.GetFirstSelectedItemPosition(); + int iPos=-1; + while (pos) + { + iPos=m_ctlRecent.GetNextSelectedItem(pos); + m_cvRecent.erase(m_cvRecent.begin()+iPos, true); + m_ctlRecent.DeleteItem(iPos); + } + + if (iPos != -1) + m_ctlRecent.SetItemState(iPos, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); +} Index: src/ch/RecentDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/RecentDlg.h (.../RecentDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/RecentDlg.h (.../RecentDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,71 +1,71 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __RECENTDLG_H__ -#define __RECENTDLG_H__ - -#include "afxtempl.h" -#include "charvect.h" - -///////////////////////////////////////////////////////////////////////////// -// CRecentDlg dialog - -class CRecentDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CRecentDlg(CWnd* pParent = NULL); // standard constructor - -// Dialog Data - //{{AFX_DATA(CRecentDlg) - enum { IDD = IDD_RECENTEDIT_DIALOG }; - CListCtrl m_ctlRecent; - CString m_strPath; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CRecentDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -public: - char_vector m_cvRecent; - HIMAGELIST m_himl, m_hliml; - -protected: - - // Generated message map functions - //{{AFX_MSG(CRecentDlg) - virtual BOOL OnInitDialog(); - afx_msg void OnItemchangedRecentList(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnBrowseButton(); - afx_msg void OnAddButton(); - afx_msg void OnChangeButton(); - afx_msg void OnDeleteButton(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __RECENTDLG_H__ +#define __RECENTDLG_H__ + +#include "afxtempl.h" +#include "charvect.h" + +///////////////////////////////////////////////////////////////////////////// +// CRecentDlg dialog + +class CRecentDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CRecentDlg(CWnd* pParent = NULL); // standard constructor + +// Dialog Data + //{{AFX_DATA(CRecentDlg) + enum { IDD = IDD_RECENTEDIT_DIALOG }; + CListCtrl m_ctlRecent; + CString m_strPath; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CRecentDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +public: + char_vector m_cvRecent; + HIMAGELIST m_himl, m_hliml; + +protected: + + // Generated message map functions + //{{AFX_MSG(CRecentDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnItemchangedRecentList(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnBrowseButton(); + afx_msg void OnAddButton(); + afx_msg void OnChangeButton(); + afx_msg void OnDeleteButton(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/ReplacePathsDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ReplacePathsDlg.cpp (.../ReplacePathsDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ReplacePathsDlg.cpp (.../ReplacePathsDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,104 +1,104 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "resource.h" -#include "ReplacePathsDlg.h" -#include "dialogs.h" -#include "ch.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CReplacePathsDlg dialog - - -CReplacePathsDlg::CReplacePathsDlg() - : ictranslate::CLanguageDialog(CReplacePathsDlg::IDD) -{ - //{{AFX_DATA_INIT(CReplacePathsDlg) - m_strDest = _T(""); - m_strSource = _T(""); - //}}AFX_DATA_INIT -} - - -void CReplacePathsDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CReplacePathsDlg) - DDX_Control(pDX, IDC_PATHS_LIST, m_ctlPathsList); - DDX_Text(pDX, IDC_DESTINATION_EDIT, m_strDest); - DDX_Text(pDX, IDC_SOURCE_EDIT, m_strSource); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CReplacePathsDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CReplacePathsDlg) - ON_LBN_SELCHANGE(IDC_PATHS_LIST, OnSelchangePathsList) - ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CReplacePathsDlg message handlers - -BOOL CReplacePathsDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - for (int i=0;iGetClipboardDataSize();i++) - m_ctlPathsList.AddString(m_pTask->GetClipboardData(i)->GetPath()); - - return TRUE; -} - -void CReplacePathsDlg::OnSelchangePathsList() -{ - int iSel=m_ctlPathsList.GetCurSel(); - if (iSel == LB_ERR) - return; - - m_ctlPathsList.GetText(iSel, m_strSource); - UpdateData(FALSE); -} - -void CReplacePathsDlg::OnOK() -{ - UpdateData(TRUE); - if (m_strSource.IsEmpty()) - MsgBox(IDS_SOURCESTRINGMISSING_STRING); - else - CLanguageDialog::OnOK(); -} - -void CReplacePathsDlg::OnBrowseButton() -{ - CString strPath; - if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) - { - UpdateData(TRUE); - m_strDest=strPath; - UpdateData(FALSE); - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "resource.h" +#include "ReplacePathsDlg.h" +#include "dialogs.h" +#include "ch.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CReplacePathsDlg dialog + + +CReplacePathsDlg::CReplacePathsDlg() + : ictranslate::CLanguageDialog(CReplacePathsDlg::IDD) +{ + //{{AFX_DATA_INIT(CReplacePathsDlg) + m_strDest = _T(""); + m_strSource = _T(""); + //}}AFX_DATA_INIT +} + + +void CReplacePathsDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CReplacePathsDlg) + DDX_Control(pDX, IDC_PATHS_LIST, m_ctlPathsList); + DDX_Text(pDX, IDC_DESTINATION_EDIT, m_strDest); + DDX_Text(pDX, IDC_SOURCE_EDIT, m_strSource); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CReplacePathsDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CReplacePathsDlg) + ON_LBN_SELCHANGE(IDC_PATHS_LIST, OnSelchangePathsList) + ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CReplacePathsDlg message handlers + +BOOL CReplacePathsDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + for (int i=0;iGetClipboardDataSize();i++) + m_ctlPathsList.AddString(m_pTask->GetClipboardData(i)->GetPath()); + + return TRUE; +} + +void CReplacePathsDlg::OnSelchangePathsList() +{ + int iSel=m_ctlPathsList.GetCurSel(); + if (iSel == LB_ERR) + return; + + m_ctlPathsList.GetText(iSel, m_strSource); + UpdateData(FALSE); +} + +void CReplacePathsDlg::OnOK() +{ + UpdateData(TRUE); + if (m_strSource.IsEmpty()) + MsgBox(IDS_SOURCESTRINGMISSING_STRING); + else + CLanguageDialog::OnOK(); +} + +void CReplacePathsDlg::OnBrowseButton() +{ + CString strPath; + if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) + { + UpdateData(TRUE); + m_strDest=strPath; + UpdateData(FALSE); + } +} Index: src/ch/ReplacePathsDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ReplacePathsDlg.h (.../ReplacePathsDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ReplacePathsDlg.h (.../ReplacePathsDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,66 +1,66 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __REPLACEPATHSDLG_H__ -#define __REPLACEPATHSDLG_H__ - -#include "structs.h" - -///////////////////////////////////////////////////////////////////////////// -// CReplacePathsDlg dialog - -class CReplacePathsDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CReplacePathsDlg(); // standard constructor - - CTask* m_pTask; -// Dialog Data - //{{AFX_DATA(CReplacePathsDlg) - enum { IDD = IDD_REPLACE_PATHS_DIALOG }; - CListBox m_ctlPathsList; - CString m_strDest; - CString m_strSource; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CReplacePathsDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(CReplacePathsDlg) - virtual BOOL OnInitDialog(); - afx_msg void OnSelchangePathsList(); - virtual void OnOK(); - afx_msg void OnBrowseButton(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __REPLACEPATHSDLG_H__ +#define __REPLACEPATHSDLG_H__ + +#include "structs.h" + +///////////////////////////////////////////////////////////////////////////// +// CReplacePathsDlg dialog + +class CReplacePathsDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CReplacePathsDlg(); // standard constructor + + CTask* m_pTask; +// Dialog Data + //{{AFX_DATA(CReplacePathsDlg) + enum { IDD = IDD_REPLACE_PATHS_DIALOG }; + CListBox m_ctlPathsList; + CString m_strDest; + CString m_strSource; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CReplacePathsDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + + // Generated message map functions + //{{AFX_MSG(CReplacePathsDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnSelchangePathsList(); + virtual void OnOK(); + afx_msg void OnBrowseButton(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/ShortcutsDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ShortcutsDlg.cpp (.../ShortcutsDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ShortcutsDlg.cpp (.../ShortcutsDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,356 +1,356 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "ShortcutsDlg.h" -#include "dialogs.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CShortcutsDlg dialog - - -CShortcutsDlg::CShortcutsDlg(CWnd* pParent /*=NULL*/) - :ictranslate::CLanguageDialog(CShortcutsDlg::IDD, pParent) -{ - //{{AFX_DATA_INIT(CShortcutsDlg) - m_strName = _T(""); - //}}AFX_DATA_INIT - m_bActualisation=false; -} - - -void CShortcutsDlg::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CShortcutsDlg) - DDX_Control(pDX, IDC_PATH_COMBOBOXEX, m_ctlPath); - DDX_Control(pDX, IDC_SHORTCUT_LIST, m_ctlShortcuts); - DDX_Text(pDX, IDC_NAME_EDIT, m_strName); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CShortcutsDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CShortcutsDlg) - ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHORTCUT_LIST, OnItemchangedShortcutList) - ON_CBN_EDITCHANGE(IDC_PATH_COMBOBOXEX, OnEditchangePathComboboxex) - ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton) - ON_BN_CLICKED(IDC_CHANGE_BUTTON, OnChangeButton) - ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) - ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton) - ON_BN_CLICKED(IDC_UP_BUTTON, OnUpButton) - ON_BN_CLICKED(IDC_DOWN_BUTTON, OnDownButton) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CShortcutsDlg message handlers - -BOOL CShortcutsDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // system image list - SHFILEINFO sfi; - m_himl = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - m_hliml=(HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), - SHGFI_SYSICONINDEX); - m_ctlPath.SendMessage(CBEM_SETIMAGELIST, 0, (LPARAM)m_himl); - m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)m_himl); - m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)m_hliml); - - // copy all of the recent paths to combo - COMBOBOXEXITEM cbi; - cbi.mask=CBEIF_IMAGE | CBEIF_TEXT; - - for (int i=0;i<(int)m_pcvRecent->size();i++) - { - cbi.iItem=i; - cbi.pszText=m_pcvRecent->at(i); - sfi.iIcon=-1; - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - cbi.iImage=sfi.iIcon; - - m_ctlPath.InsertItem(&cbi); - } - - // create columns in shortcuts list - LVCOLUMN lvc; - lvc.mask=LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT; - lvc.iSubItem=-1; - lvc.cx=100; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_SHORTCUTNAME_STRING); - m_ctlShortcuts.InsertColumn(0, &lvc); - lvc.iSubItem=0; - lvc.cx=200; - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_SHORTCUTPATH_STRING); - m_ctlShortcuts.InsertColumn(1, &lvc); - - // modify list style - m_ctlShortcuts.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_INFOTIP | LVS_EX_UNDERLINEHOT); - - // update shortcut list - CShortcut sc; - for (int i=0;i<(int)m_cvShortcuts.size();i++) - { - sc=CString(m_cvShortcuts.at(i)); - sfi.iIcon=-1; - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.InsertItem(i, sc.m_strName, sfi.iIcon); - m_ctlShortcuts.SetItem(i, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - } - - return TRUE; -} - -void CShortcutsDlg::OnItemchangedShortcutList(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_LISTVIEW* plv = (NM_LISTVIEW*)pNMHDR; - - // current selection - if (plv->iItem >= 0 && plv->iItem < (int)m_cvShortcuts.size()) - { - CShortcut sc(CString(m_cvShortcuts.at(plv->iItem))); - m_strName=sc.m_strName; - UpdateData(FALSE); - SetComboPath(sc.m_strPath); - } - - *pResult = 0; -} - -void CShortcutsDlg::SetComboPath(LPCTSTR lpszPath) -{ - // unselect - m_ctlPath.SetCurSel(-1); - - SHFILEINFO sfi; - sfi.iIcon=-1; - - COMBOBOXEXITEM cbi; - - cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; - cbi.iItem=-1; - cbi.pszText=(LPTSTR)lpszPath; - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - cbi.iImage=sfi.iIcon; - - m_ctlPath.SetItem(&cbi); -} - -void CShortcutsDlg::UpdateComboIcon() -{ - // get combo text - COMBOBOXEXITEM cbi; - TCHAR szPath[_MAX_PATH]; - memset(szPath, 0, _MAX_PATH); - cbi.mask=CBEIF_TEXT; - cbi.iItem=m_ctlPath.GetCurSel()/*-1*/; - cbi.pszText=szPath; - cbi.cchTextMax=_MAX_PATH; - - if (!m_ctlPath.GetItem(&cbi)) - return; - - // unselect - m_ctlPath.SetCurSel(-1); - - // icon update - SHFILEINFO sfi; - sfi.iIcon=-1; - - cbi.mask |= CBEIF_IMAGE; - cbi.iItem=-1; - - CString str=(LPCTSTR)szPath; - if (str.Left(2) != _T("\\\\") || str.Find(_T('\\'), 2) != -1) - SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); - - cbi.iImage=sfi.iIcon; - - m_ctlPath.SetItem(&cbi); - - // unselect text - CEdit* pEdit=m_ctlPath.GetEditCtrl(); - if (!pEdit) - return; - - pEdit->SetSel(-1, -1); -} - -void CShortcutsDlg::OnEditchangePathComboboxex() -{ - if (m_bActualisation) - return; - m_bActualisation=true; - UpdateComboIcon(); - m_bActualisation=false; -} - -void CShortcutsDlg::OnAddButton() -{ - // create new shortcut - UpdateData(TRUE); - CShortcut sc; - sc.m_strName=m_strName; - m_ctlPath.GetWindowText(sc.m_strPath); - - // add to an array - m_cvShortcuts.push_back((const PTSTR)(LPCTSTR)(CString)sc, true); - - // add with an icon - SHFILEINFO sfi; - sfi.iIcon=-1; - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.InsertItem(m_cvShortcuts.size()-1, sc.m_strName, sfi.iIcon); - m_ctlShortcuts.SetItem(m_cvShortcuts.size()-1, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); -} - -void CShortcutsDlg::OnChangeButton() -{ - // get selection index - POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); - if (pos) - { - // index - int iPos=m_ctlShortcuts.GetNextSelectedItem(pos); - - // get new shortcut - UpdateData(TRUE); - CShortcut sc; - sc.m_strName=m_strName; - m_ctlPath.GetWindowText(sc.m_strPath); - - // array update - m_cvShortcuts.replace(m_cvShortcuts.begin()+iPos, (const PTSTR)(LPCTSTR)(CString)sc, true, true); - - // list - SHFILEINFO sfi; - sfi.iIcon=-1; - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - - m_ctlShortcuts.DeleteItem(iPos); - - m_ctlShortcuts.InsertItem(iPos, sc.m_strName, sfi.iIcon); - m_ctlShortcuts.SetItem(iPos, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - } -} - -void CShortcutsDlg::OnDeleteButton() -{ - POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); - int iPos=-1; - while (pos) - { - iPos=m_ctlShortcuts.GetNextSelectedItem(pos); - m_cvShortcuts.erase(m_cvShortcuts.begin()+iPos, true); - m_ctlShortcuts.DeleteItem(iPos); - } - - if (iPos != -1) - m_ctlShortcuts.SetItemState(iPos, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); -} - -void CShortcutsDlg::OnBrowseButton() -{ - CString strPath; - if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) - SetComboPath(strPath); -} - -void CShortcutsDlg::OnUpButton() -{ - POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); - int iPos=-1; - CShortcut sc; - while (pos) - { - // get current selected item - iPos=m_ctlShortcuts.GetNextSelectedItem(pos); - - // if the first element is trying to go up to nowhere - if (iPos == 0) - break; - - // swap data in m_ascShortcuts - m_cvShortcuts.swap_items(m_cvShortcuts.begin()+iPos-1, m_cvShortcuts.begin()+iPos); - - // do the same with list - SHFILEINFO sfi; - sfi.iIcon=-1; - - sc=CString(m_cvShortcuts.at(iPos-1)); - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.SetItem(iPos-1, -1, LVIF_TEXT | LVIF_IMAGE , sc.m_strName, sfi.iIcon, 0, 0, 0); - m_ctlShortcuts.SetItem(iPos-1, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - - sfi.iIcon=-1; - sc=CString(m_cvShortcuts.at(iPos)); - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.SetItem(iPos, -1, LVIF_TEXT | LVIF_IMAGE, sc.m_strName, sfi.iIcon, 0, 0, 0); - m_ctlShortcuts.SetItem(iPos, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - - m_ctlShortcuts.SetItemState(iPos, 0, LVIS_SELECTED | LVIS_FOCUSED); - m_ctlShortcuts.SetItemState(iPos-1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - } -} - -void CShortcutsDlg::OnDownButton() -{ - POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); - int iPos=-1; - CShortcut sc; - while (pos) - { - // get current selected item - iPos=m_ctlShortcuts.GetNextSelectedItem(pos); - - // if the last element is trying to go down to nowhere - if (iPos == m_ctlShortcuts.GetItemCount()-1) - break; - - // swap data in m_ascShortcuts - m_cvShortcuts.swap_items(m_cvShortcuts.begin()+iPos, m_cvShortcuts.begin()+iPos+1); - - // do the same with list - SHFILEINFO sfi; - sfi.iIcon=-1; - - sc=CString(m_cvShortcuts.at(iPos)); - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.SetItem(iPos, -1, LVIF_TEXT | LVIF_IMAGE , sc.m_strName, sfi.iIcon, 0, 0, 0); - m_ctlShortcuts.SetItem(iPos, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - - sfi.iIcon=-1; - sc=CString(m_cvShortcuts.at(iPos+1)); - SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); - m_ctlShortcuts.SetItem(iPos+1, -1, LVIF_TEXT | LVIF_IMAGE, sc.m_strName, sfi.iIcon, 0, 0, 0); - m_ctlShortcuts.SetItem(iPos+1, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); - - m_ctlShortcuts.SetItemState(iPos, 0, LVIS_SELECTED | LVIS_FOCUSED); - m_ctlShortcuts.SetItemState(iPos+1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "ShortcutsDlg.h" +#include "dialogs.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CShortcutsDlg dialog + + +CShortcutsDlg::CShortcutsDlg(CWnd* pParent /*=NULL*/) + :ictranslate::CLanguageDialog(CShortcutsDlg::IDD, pParent) +{ + //{{AFX_DATA_INIT(CShortcutsDlg) + m_strName = _T(""); + //}}AFX_DATA_INIT + m_bActualisation=false; +} + + +void CShortcutsDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CShortcutsDlg) + DDX_Control(pDX, IDC_PATH_COMBOBOXEX, m_ctlPath); + DDX_Control(pDX, IDC_SHORTCUT_LIST, m_ctlShortcuts); + DDX_Text(pDX, IDC_NAME_EDIT, m_strName); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CShortcutsDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CShortcutsDlg) + ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHORTCUT_LIST, OnItemchangedShortcutList) + ON_CBN_EDITCHANGE(IDC_PATH_COMBOBOXEX, OnEditchangePathComboboxex) + ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton) + ON_BN_CLICKED(IDC_CHANGE_BUTTON, OnChangeButton) + ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) + ON_BN_CLICKED(IDC_BROWSE_BUTTON, OnBrowseButton) + ON_BN_CLICKED(IDC_UP_BUTTON, OnUpButton) + ON_BN_CLICKED(IDC_DOWN_BUTTON, OnDownButton) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CShortcutsDlg message handlers + +BOOL CShortcutsDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // system image list + SHFILEINFO sfi; + m_himl = (HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + m_hliml=(HIMAGELIST)SHGetFileInfo(_T("C:\\"), FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), + SHGFI_SYSICONINDEX); + m_ctlPath.SendMessage(CBEM_SETIMAGELIST, 0, (LPARAM)m_himl); + m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_SMALL, (LPARAM)m_himl); + m_ctlShortcuts.SendMessage(LVM_SETIMAGELIST, (WPARAM)LVSIL_NORMAL, (LPARAM)m_hliml); + + // copy all of the recent paths to combo + COMBOBOXEXITEM cbi; + cbi.mask=CBEIF_IMAGE | CBEIF_TEXT; + + for (int i=0;i<(int)m_pcvRecent->size();i++) + { + cbi.iItem=i; + cbi.pszText=m_pcvRecent->at(i); + sfi.iIcon=-1; + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); + cbi.iImage=sfi.iIcon; + + m_ctlPath.InsertItem(&cbi); + } + + // create columns in shortcuts list + LVCOLUMN lvc; + lvc.mask=LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT; + lvc.iSubItem=-1; + lvc.cx=100; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_SHORTCUTNAME_STRING); + m_ctlShortcuts.InsertColumn(0, &lvc); + lvc.iSubItem=0; + lvc.cx=200; + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_SHORTCUTPATH_STRING); + m_ctlShortcuts.InsertColumn(1, &lvc); + + // modify list style + m_ctlShortcuts.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_INFOTIP | LVS_EX_UNDERLINEHOT); + + // update shortcut list + CShortcut sc; + for (int i=0;i<(int)m_cvShortcuts.size();i++) + { + sc=CString(m_cvShortcuts.at(i)); + sfi.iIcon=-1; + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.InsertItem(i, sc.m_strName, sfi.iIcon); + m_ctlShortcuts.SetItem(i, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + } + + return TRUE; +} + +void CShortcutsDlg::OnItemchangedShortcutList(NMHDR* pNMHDR, LRESULT* pResult) +{ + NM_LISTVIEW* plv = (NM_LISTVIEW*)pNMHDR; + + // current selection + if (plv->iItem >= 0 && plv->iItem < (int)m_cvShortcuts.size()) + { + CShortcut sc(CString(m_cvShortcuts.at(plv->iItem))); + m_strName=sc.m_strName; + UpdateData(FALSE); + SetComboPath(sc.m_strPath); + } + + *pResult = 0; +} + +void CShortcutsDlg::SetComboPath(LPCTSTR lpszPath) +{ + // unselect + m_ctlPath.SetCurSel(-1); + + SHFILEINFO sfi; + sfi.iIcon=-1; + + COMBOBOXEXITEM cbi; + + cbi.mask=CBEIF_TEXT | CBEIF_IMAGE; + cbi.iItem=-1; + cbi.pszText=(LPTSTR)lpszPath; + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + cbi.iImage=sfi.iIcon; + + m_ctlPath.SetItem(&cbi); +} + +void CShortcutsDlg::UpdateComboIcon() +{ + // get combo text + COMBOBOXEXITEM cbi; + TCHAR szPath[_MAX_PATH]; + memset(szPath, 0, _MAX_PATH); + cbi.mask=CBEIF_TEXT; + cbi.iItem=m_ctlPath.GetCurSel()/*-1*/; + cbi.pszText=szPath; + cbi.cchTextMax=_MAX_PATH; + + if (!m_ctlPath.GetItem(&cbi)) + return; + + // unselect + m_ctlPath.SetCurSel(-1); + + // icon update + SHFILEINFO sfi; + sfi.iIcon=-1; + + cbi.mask |= CBEIF_IMAGE; + cbi.iItem=-1; + + CString str=(LPCTSTR)szPath; + if (str.Left(2) != _T("\\\\") || str.Find(_T('\\'), 2) != -1) + SHGetFileInfo(cbi.pszText, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SMALLICON | SHGFI_SYSICONINDEX); + + cbi.iImage=sfi.iIcon; + + m_ctlPath.SetItem(&cbi); + + // unselect text + CEdit* pEdit=m_ctlPath.GetEditCtrl(); + if (!pEdit) + return; + + pEdit->SetSel(-1, -1); +} + +void CShortcutsDlg::OnEditchangePathComboboxex() +{ + if (m_bActualisation) + return; + m_bActualisation=true; + UpdateComboIcon(); + m_bActualisation=false; +} + +void CShortcutsDlg::OnAddButton() +{ + // create new shortcut + UpdateData(TRUE); + CShortcut sc; + sc.m_strName=m_strName; + m_ctlPath.GetWindowText(sc.m_strPath); + + // add to an array + m_cvShortcuts.push_back((const PTSTR)(LPCTSTR)(CString)sc, true); + + // add with an icon + SHFILEINFO sfi; + sfi.iIcon=-1; + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.InsertItem(m_cvShortcuts.size()-1, sc.m_strName, sfi.iIcon); + m_ctlShortcuts.SetItem(m_cvShortcuts.size()-1, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); +} + +void CShortcutsDlg::OnChangeButton() +{ + // get selection index + POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); + if (pos) + { + // index + int iPos=m_ctlShortcuts.GetNextSelectedItem(pos); + + // get new shortcut + UpdateData(TRUE); + CShortcut sc; + sc.m_strName=m_strName; + m_ctlPath.GetWindowText(sc.m_strPath); + + // array update + m_cvShortcuts.replace(m_cvShortcuts.begin()+iPos, (const PTSTR)(LPCTSTR)(CString)sc, true, true); + + // list + SHFILEINFO sfi; + sfi.iIcon=-1; + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + + m_ctlShortcuts.DeleteItem(iPos); + + m_ctlShortcuts.InsertItem(iPos, sc.m_strName, sfi.iIcon); + m_ctlShortcuts.SetItem(iPos, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + } +} + +void CShortcutsDlg::OnDeleteButton() +{ + POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); + int iPos=-1; + while (pos) + { + iPos=m_ctlShortcuts.GetNextSelectedItem(pos); + m_cvShortcuts.erase(m_cvShortcuts.begin()+iPos, true); + m_ctlShortcuts.DeleteItem(iPos); + } + + if (iPos != -1) + m_ctlShortcuts.SetItemState(iPos, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); +} + +void CShortcutsDlg::OnBrowseButton() +{ + CString strPath; + if (BrowseForFolder(GetResManager()->LoadString(IDS_BROWSE_STRING), &strPath)) + SetComboPath(strPath); +} + +void CShortcutsDlg::OnUpButton() +{ + POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); + int iPos=-1; + CShortcut sc; + while (pos) + { + // get current selected item + iPos=m_ctlShortcuts.GetNextSelectedItem(pos); + + // if the first element is trying to go up to nowhere + if (iPos == 0) + break; + + // swap data in m_ascShortcuts + m_cvShortcuts.swap_items(m_cvShortcuts.begin()+iPos-1, m_cvShortcuts.begin()+iPos); + + // do the same with list + SHFILEINFO sfi; + sfi.iIcon=-1; + + sc=CString(m_cvShortcuts.at(iPos-1)); + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.SetItem(iPos-1, -1, LVIF_TEXT | LVIF_IMAGE , sc.m_strName, sfi.iIcon, 0, 0, 0); + m_ctlShortcuts.SetItem(iPos-1, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + + sfi.iIcon=-1; + sc=CString(m_cvShortcuts.at(iPos)); + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.SetItem(iPos, -1, LVIF_TEXT | LVIF_IMAGE, sc.m_strName, sfi.iIcon, 0, 0, 0); + m_ctlShortcuts.SetItem(iPos, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + + m_ctlShortcuts.SetItemState(iPos, 0, LVIS_SELECTED | LVIS_FOCUSED); + m_ctlShortcuts.SetItemState(iPos-1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + } +} + +void CShortcutsDlg::OnDownButton() +{ + POSITION pos=m_ctlShortcuts.GetFirstSelectedItemPosition(); + int iPos=-1; + CShortcut sc; + while (pos) + { + // get current selected item + iPos=m_ctlShortcuts.GetNextSelectedItem(pos); + + // if the last element is trying to go down to nowhere + if (iPos == m_ctlShortcuts.GetItemCount()-1) + break; + + // swap data in m_ascShortcuts + m_cvShortcuts.swap_items(m_cvShortcuts.begin()+iPos, m_cvShortcuts.begin()+iPos+1); + + // do the same with list + SHFILEINFO sfi; + sfi.iIcon=-1; + + sc=CString(m_cvShortcuts.at(iPos)); + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.SetItem(iPos, -1, LVIF_TEXT | LVIF_IMAGE , sc.m_strName, sfi.iIcon, 0, 0, 0); + m_ctlShortcuts.SetItem(iPos, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + + sfi.iIcon=-1; + sc=CString(m_cvShortcuts.at(iPos+1)); + SHGetFileInfo(sc.m_strPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON); + m_ctlShortcuts.SetItem(iPos+1, -1, LVIF_TEXT | LVIF_IMAGE, sc.m_strName, sfi.iIcon, 0, 0, 0); + m_ctlShortcuts.SetItem(iPos+1, 1, LVIF_TEXT, sc.m_strPath, 0, 0, 0, 0); + + m_ctlShortcuts.SetItemState(iPos, 0, LVIS_SELECTED | LVIS_FOCUSED); + m_ctlShortcuts.SetItemState(iPos+1, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + } +} Index: src/ch/ShutdownDlg.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ShutdownDlg.cpp (.../ShutdownDlg.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ShutdownDlg.cpp (.../ShutdownDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,100 +1,100 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "ShutdownDlg.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CShutdownDlg dialog - - -CShutdownDlg::CShutdownDlg() - :ictranslate::CLanguageDialog(CShutdownDlg::IDD) -{ - //{{AFX_DATA_INIT(CShutdownDlg) - m_strTime = _T(""); - //}}AFX_DATA_INIT -} - - -void CShutdownDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CShutdownDlg) - DDX_Control(pDX, IDC_TIME_PROGRESS, m_ctlProgress); - DDX_Text(pDX, IDC_TIME_STATIC, m_strTime); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CShutdownDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CShutdownDlg) - ON_WM_TIMER() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CShutdownDlg message handlers - -BOOL CShutdownDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // make on top - SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); - - // init progress - m_iTime=m_iOverallTime; - m_ctlProgress.SetRange32(0, m_iOverallTime); - - // init timer - SetTimer(6678, 200, NULL); - - return TRUE; -} - -void CShutdownDlg::OnTimer(UINT_PTR nIDEvent) -{ - if (nIDEvent == 6678) - { - m_iTime-=200; - if (m_iTime < 0) - m_iTime=0; - - m_ctlProgress.SetPos(m_iOverallTime-m_iTime); - FormatTimeString(m_iTime, &m_strTime); - UpdateData(FALSE); - - if (m_iTime == 0) - EndDialog(IDOK); - } - - CLanguageDialog::OnTimer(nIDEvent); -} - -void CShutdownDlg::FormatTimeString(int iTime, CString *pstrData) -{ - pstrData->Format(_T("%lu s."), iTime/1000); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "ShutdownDlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CShutdownDlg dialog + + +CShutdownDlg::CShutdownDlg() + :ictranslate::CLanguageDialog(CShutdownDlg::IDD) +{ + //{{AFX_DATA_INIT(CShutdownDlg) + m_strTime = _T(""); + //}}AFX_DATA_INIT +} + + +void CShutdownDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CShutdownDlg) + DDX_Control(pDX, IDC_TIME_PROGRESS, m_ctlProgress); + DDX_Text(pDX, IDC_TIME_STATIC, m_strTime); + //}}AFX_DATA_MAP +} + + +BEGIN_MESSAGE_MAP(CShutdownDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CShutdownDlg) + ON_WM_TIMER() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CShutdownDlg message handlers + +BOOL CShutdownDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // make on top + SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE /*| SWP_SHOWWINDOW*/); + + // init progress + m_iTime=m_iOverallTime; + m_ctlProgress.SetRange32(0, m_iOverallTime); + + // init timer + SetTimer(6678, 200, NULL); + + return TRUE; +} + +void CShutdownDlg::OnTimer(UINT_PTR nIDEvent) +{ + if (nIDEvent == 6678) + { + m_iTime-=200; + if (m_iTime < 0) + m_iTime=0; + + m_ctlProgress.SetPos(m_iOverallTime-m_iTime); + FormatTimeString(m_iTime, &m_strTime); + UpdateData(FALSE); + + if (m_iTime == 0) + EndDialog(IDOK); + } + + CLanguageDialog::OnTimer(nIDEvent); +} + +void CShutdownDlg::FormatTimeString(int iTime, CString *pstrData) +{ + pstrData->Format(_T("%lu s."), iTime/1000); +} Index: src/ch/ShutdownDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ShutdownDlg.h (.../ShutdownDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ShutdownDlg.h (.../ShutdownDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,64 +1,64 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __SHUTDOWNDLG_H__ -#define __SHUTDOWNDLG_H__ - -///////////////////////////////////////////////////////////////////////////// -// CShutdownDlg dialog - -class CShutdownDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CShutdownDlg(); // standard constructor - - int m_iOverallTime; - -// Dialog Data - //{{AFX_DATA(CShutdownDlg) - enum { IDD = IDD_SHUTDOWN_DIALOG }; - CProgressCtrl m_ctlProgress; - CString m_strTime; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CShutdownDlg) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - void FormatTimeString(int iTime, CString* pstrData); - int m_iTime; // czas w sekundach - - // Generated message map functions - //{{AFX_MSG(CShutdownDlg) - virtual BOOL OnInitDialog(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __SHUTDOWNDLG_H__ +#define __SHUTDOWNDLG_H__ + +///////////////////////////////////////////////////////////////////////////// +// CShutdownDlg dialog + +class CShutdownDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CShutdownDlg(); // standard constructor + + int m_iOverallTime; + +// Dialog Data + //{{AFX_DATA(CShutdownDlg) + enum { IDD = IDD_SHUTDOWN_DIALOG }; + CProgressCtrl m_ctlProgress; + CString m_strTime; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CShutdownDlg) + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + //}}AFX_VIRTUAL + +// Implementation +protected: + void FormatTimeString(int iTime, CString* pstrData); + int m_iTime; // czas w sekundach + + // Generated message map functions + //{{AFX_MSG(CShutdownDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/StaticEx.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/StaticEx.cpp (.../StaticEx.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/StaticEx.cpp (.../StaticEx.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,352 +1,352 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "StaticEx.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#define STATICEX_CLASS _T("STATICEX") - -LRESULT CALLBACK StaticExWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - STATICEXSETTINGS* pSettings=(STATICEXSETTINGS*)GetWindowLongPtr(hwnd, 0); - switch (uMsg) - { - case WM_NCCREATE: - { - STATICEXSETTINGS* pSett=new STATICEXSETTINGS; - pSett->hFontNormal=NULL; - pSett->hFontUnderline=NULL; - pSett->pszLink=NULL; - pSett->pszText=NULL; - pSett->bActive=false; - pSett->bDown=false; - pSett->hLink=NULL; - pSett->hNormal=NULL; - pSett->rcText.left=0; - pSett->rcText.right=0; - pSett->rcText.top=0; - pSett->rcText.bottom=0; - ::SetWindowLongPtr(hwnd, 0, (LONG_PTR)pSett); - - // create cursors - pSett->hNormal=::LoadCursor(NULL, IDC_ARROW); - pSett->hLink=::LoadCursor(NULL, IDC_HAND); - - break; - } - case WM_CREATE: - { - CREATESTRUCT* pcs=(CREATESTRUCT*)lParam; - - const TCHAR* pSep=_tcsrchr(pcs->lpszName, _T('|')); - - if (!(pcs->style & SES_LINK) || pSep == NULL || pSep-pcs->lpszName < 0) - { - pSettings->pszText=new TCHAR[_tcslen(pcs->lpszName)+1]; - _tcscpy(pSettings->pszText, pcs->lpszName); - pSettings->pszLink=NULL; - } - else - { - pSettings->pszText=new TCHAR[pSep-pcs->lpszName+1]; - _tcsncpy(pSettings->pszText, pcs->lpszName, pSep-pcs->lpszName); - pSettings->pszText[pSep-pcs->lpszName]=_T('\0'); - pSep++; - pSettings->pszLink=new TCHAR[_tcslen(pSep)+1]; - _tcscpy(pSettings->pszLink, pSep); - } - - break; - } - case WM_NCDESTROY: - { - if (pSettings->hFontNormal) - DeleteObject(pSettings->hFontNormal); - if (pSettings->hFontUnderline) - DeleteObject(pSettings->hFontUnderline); - if (pSettings->hLink) - DeleteObject(pSettings->hLink); - if (pSettings->hNormal) - DeleteObject(pSettings->hNormal); - delete [] pSettings->pszLink; - delete [] pSettings->pszText; - - delete pSettings; - break; - } - case WM_SETFONT: - { - // delete old fonts - if (pSettings->hFontNormal) - DeleteObject(pSettings->hFontNormal); - if (pSettings->hFontUnderline) - DeleteObject(pSettings->hFontUnderline); - - // new font - create a font based on it (the normal and the underlined one) - HFONT hfont=(HFONT)wParam; - LOGFONT lf; - if (GetObject(hfont, sizeof(LOGFONT), &lf) != 0) - { - // size - if (::GetWindowLong(hwnd, GWL_STYLE) & SES_LARGE) - lf.lfHeight=(long)(lf.lfHeight*1.25); - - // create a font - if (::GetWindowLong(hwnd, GWL_STYLE) & SES_BOLD) - lf.lfWeight=FW_BOLD; - pSettings->hFontNormal=CreateFontIndirect(&lf); - lf.lfUnderline=TRUE; - pSettings->hFontUnderline=CreateFontIndirect(&lf); - } - else - { - pSettings->hFontNormal=NULL; - pSettings->hFontUnderline=NULL; - } - - break; - } - case WM_SETTEXT: - { - // delete the old font - delete [] pSettings->pszText; - delete [] pSettings->pszLink; - - // style - LONG lStyle=::GetWindowLong(hwnd, GWL_STYLE); - - LPCTSTR psz=(LPCTSTR)lParam; - const TCHAR* pSep=_tcsrchr(psz, _T('|')); - - if (!(lStyle & SES_LINK) || pSep == NULL || pSep-psz < 0) - { - pSettings->pszText=new TCHAR[_tcslen(psz)+1]; - _tcscpy(pSettings->pszText, psz); - pSettings->pszLink=NULL; - } - else - { - pSettings->pszText=new TCHAR[pSep-psz+1]; - _tcsncpy(pSettings->pszText, psz, pSep-psz); - pSettings->pszText[pSep-psz]=_T('\0'); - pSep++; - pSettings->pszLink=new TCHAR[_tcslen(pSep)+1]; - _tcscpy(pSettings->pszLink, pSep); - } - - ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); - break; - } - case WM_ERASEBKGND: - { - return (LRESULT)FALSE; - break; - } - case WM_PAINT: - { - // draw anything - PAINTSTRUCT ps; - HDC hDC=BeginPaint(hwnd, &ps); - - // flicker-free drawing - HDC hdc=::CreateCompatibleDC(hDC); - HBITMAP hBmp=::CreateCompatibleBitmap(hDC, ps.rcPaint.right-ps.rcPaint.left+1, ps.rcPaint.bottom-ps.rcPaint.top+1); - HBITMAP hOldBitmap=(HBITMAP)::SelectObject(hdc, hBmp); - ::SetWindowOrgEx(hdc, ps.rcPaint.left, ps.rcPaint.top, NULL); - - // paint the background - ::FillRect(hdc, &ps.rcPaint, (HBRUSH)::SendMessage((HWND)::GetWindowLong(hwnd, GWLP_HWNDPARENT), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd)); - - // size of the all control - RECT rcCtl; - ::GetClientRect(hwnd, &rcCtl); - - // draw text - DWORD dwFlags=DT_LEFT | DT_VCENTER | (::GetWindowLong(hwnd, GWL_STYLE) & SES_PATHELLIPSIS ? DT_PATH_ELLIPSIS : 0) - | (::GetWindowLong(hwnd, GWL_STYLE) & SES_ELLIPSIS ? DT_END_ELLIPSIS : 0) - | (::GetWindowLong(hwnd, GWL_STYLE) & SES_WORDBREAK ? DT_WORDBREAK : 0); - - pSettings->rcText=rcCtl; - if (::GetWindowLong(hwnd, GWL_STYLE) & SES_LINK) - { - HFONT hOld=(HFONT)::SelectObject(hdc, pSettings->hFontUnderline); - ::SetBkMode(hdc, TRANSPARENT); - - COLORREF crColor=(pSettings->bActive ? (RGB(255, 0, 0)) : (RGB(0, 0, 255))); - ::SetTextColor(hdc, crColor); - - if (pSettings->pszText) - { - DrawText(hdc, pSettings->pszText, -1, &pSettings->rcText, dwFlags | DT_CALCRECT); - DrawText(hdc, pSettings->pszText, -1, &rcCtl, dwFlags); - } - else - { - pSettings->rcText.left=0; - pSettings->rcText.right=0; - pSettings->rcText.top=0; - pSettings->rcText.bottom=0; - } - - ::SelectObject(hdc, hOld); - } - else - { - // aesthetics - rcCtl.left+=3; - rcCtl.right-=3; - - // draw - HFONT hOld=(HFONT)::SelectObject(hdc, pSettings->hFontNormal); - ::SetBkMode(hdc, TRANSPARENT); - ::SetTextColor(hdc, ::GetSysColor(COLOR_BTNTEXT)); - - if (pSettings->pszText) - { - DWORD dwMod=(::GetWindowLong(hwnd, GWL_STYLE) & SES_RALIGN) ? DT_RIGHT : 0; - DrawText(hdc, pSettings->pszText, -1, &pSettings->rcText, dwFlags | DT_CALCRECT | dwMod); - DrawText(hdc, pSettings->pszText, -1, &rcCtl, dwFlags | dwMod); - } - else - { - pSettings->rcText.left=0; - pSettings->rcText.right=0; - pSettings->rcText.top=0; - pSettings->rcText.bottom=0; - } - - ::SelectObject(hdc, hOld); - } - - // free the compatible dc - ::BitBlt(ps.hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left+1, ps.rcPaint.bottom-ps.rcPaint.top+1, - hdc, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); - ::SelectObject(hdc, hOldBitmap); - ::DeleteObject(hBmp); - ::DeleteDC(hdc); - - EndPaint(hwnd, &ps); - - break; - } - case WM_MOUSEMOVE: - { - if (::GetWindowLong(hwnd, GWL_STYLE) & SES_LINK) - { - POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - - if (pSettings->bActive) - { - if (!::PtInRect(&pSettings->rcText, pt)) - { - pSettings->bActive=false; - ::ReleaseCapture(); - ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); - - ::SetCursor(pSettings->hNormal); - } - } - else - { - if (::PtInRect(&pSettings->rcText, pt)) - { - pSettings->bActive=true; - ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); - ::SetCapture(hwnd); - ::SetCursor(pSettings->hLink); - } - } - } - break; - } - case WM_LBUTTONDOWN: - { - pSettings->bDown=true; - break; - } - case WM_LBUTTONUP: - { - POINT pt={ LOWORD(lParam), HIWORD(lParam) }; - if (pSettings->bDown && ::GetWindowLong(hwnd, GWL_STYLE) & SES_LINK && ::PtInRect(&pSettings->rcText, pt)) - { - if (::GetWindowLong(hwnd, GWL_STYLE) & SES_NOTIFY) - { - ::SendMessage((HWND)::GetWindowLong(hwnd, GWLP_HWNDPARENT), WM_COMMAND, (WPARAM)(SEN_CLICKED << 16 | ::GetWindowLong(hwnd, GWL_ID)), (LPARAM)hwnd); - } - else - { - - TRACE("Executing %s...\n", pSettings->pszLink); - ShellExecute(NULL, _T("open"), pSettings->pszLink, NULL, NULL, SW_SHOWNORMAL); - } - } - pSettings->bDown=false; - - break; - } - case WM_CANCELMODE: - { - pSettings->bActive=false; - pSettings->bDown=false; - break; - } - case SEM_GETLINK: - { - // wParam - count - // lParam - addr of a buffer - if (pSettings->pszLink) - _tcsncpy((PTSTR)lParam, pSettings->pszLink, (int)wParam); - else - _tcscpy((PTSTR)lParam, _T("")); - - return (LRESULT)TRUE; - break; - } - } - - return ::DefWindowProc(hwnd, uMsg, wParam, lParam); -} - -bool RegisterStaticExControl(HINSTANCE hInstance) -{ - WNDCLASS wndcls; - - if (!(::GetClassInfo(hInstance, STATICEX_CLASS, &wndcls))) - { - // need to register a new class - wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; - wndcls.lpfnWndProc = ::StaticExWndProc; - wndcls.cbClsExtra = 0; - wndcls.cbWndExtra = sizeof(STATICEXSETTINGS*); - wndcls.hInstance = hInstance; - wndcls.hIcon = NULL; - wndcls.hCursor = NULL; // will load each time needed - wndcls.hbrBackground = NULL; - wndcls.lpszMenuName = NULL; - wndcls.lpszClassName = STATICEX_CLASS; - - if (!RegisterClass(&wndcls)) - return false; - } - - return true; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "StaticEx.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#define STATICEX_CLASS _T("STATICEX") + +LRESULT CALLBACK StaticExWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + STATICEXSETTINGS* pSettings=(STATICEXSETTINGS*)GetWindowLongPtr(hwnd, 0); + switch (uMsg) + { + case WM_NCCREATE: + { + STATICEXSETTINGS* pSett=new STATICEXSETTINGS; + pSett->hFontNormal=NULL; + pSett->hFontUnderline=NULL; + pSett->pszLink=NULL; + pSett->pszText=NULL; + pSett->bActive=false; + pSett->bDown=false; + pSett->hLink=NULL; + pSett->hNormal=NULL; + pSett->rcText.left=0; + pSett->rcText.right=0; + pSett->rcText.top=0; + pSett->rcText.bottom=0; + ::SetWindowLongPtr(hwnd, 0, (LONG_PTR)pSett); + + // create cursors + pSett->hNormal=::LoadCursor(NULL, IDC_ARROW); + pSett->hLink=::LoadCursor(NULL, IDC_HAND); + + break; + } + case WM_CREATE: + { + CREATESTRUCT* pcs=(CREATESTRUCT*)lParam; + + const TCHAR* pSep=_tcsrchr(pcs->lpszName, _T('|')); + + if (!(pcs->style & SES_LINK) || pSep == NULL || pSep-pcs->lpszName < 0) + { + pSettings->pszText=new TCHAR[_tcslen(pcs->lpszName)+1]; + _tcscpy(pSettings->pszText, pcs->lpszName); + pSettings->pszLink=NULL; + } + else + { + pSettings->pszText=new TCHAR[pSep-pcs->lpszName+1]; + _tcsncpy(pSettings->pszText, pcs->lpszName, pSep-pcs->lpszName); + pSettings->pszText[pSep-pcs->lpszName]=_T('\0'); + pSep++; + pSettings->pszLink=new TCHAR[_tcslen(pSep)+1]; + _tcscpy(pSettings->pszLink, pSep); + } + + break; + } + case WM_NCDESTROY: + { + if (pSettings->hFontNormal) + DeleteObject(pSettings->hFontNormal); + if (pSettings->hFontUnderline) + DeleteObject(pSettings->hFontUnderline); + if (pSettings->hLink) + DeleteObject(pSettings->hLink); + if (pSettings->hNormal) + DeleteObject(pSettings->hNormal); + delete [] pSettings->pszLink; + delete [] pSettings->pszText; + + delete pSettings; + break; + } + case WM_SETFONT: + { + // delete old fonts + if (pSettings->hFontNormal) + DeleteObject(pSettings->hFontNormal); + if (pSettings->hFontUnderline) + DeleteObject(pSettings->hFontUnderline); + + // new font - create a font based on it (the normal and the underlined one) + HFONT hfont=(HFONT)wParam; + LOGFONT lf; + if (GetObject(hfont, sizeof(LOGFONT), &lf) != 0) + { + // size + if (::GetWindowLong(hwnd, GWL_STYLE) & SES_LARGE) + lf.lfHeight=(long)(lf.lfHeight*1.25); + + // create a font + if (::GetWindowLong(hwnd, GWL_STYLE) & SES_BOLD) + lf.lfWeight=FW_BOLD; + pSettings->hFontNormal=CreateFontIndirect(&lf); + lf.lfUnderline=TRUE; + pSettings->hFontUnderline=CreateFontIndirect(&lf); + } + else + { + pSettings->hFontNormal=NULL; + pSettings->hFontUnderline=NULL; + } + + break; + } + case WM_SETTEXT: + { + // delete the old font + delete [] pSettings->pszText; + delete [] pSettings->pszLink; + + // style + LONG lStyle=::GetWindowLong(hwnd, GWL_STYLE); + + LPCTSTR psz=(LPCTSTR)lParam; + const TCHAR* pSep=_tcsrchr(psz, _T('|')); + + if (!(lStyle & SES_LINK) || pSep == NULL || pSep-psz < 0) + { + pSettings->pszText=new TCHAR[_tcslen(psz)+1]; + _tcscpy(pSettings->pszText, psz); + pSettings->pszLink=NULL; + } + else + { + pSettings->pszText=new TCHAR[pSep-psz+1]; + _tcsncpy(pSettings->pszText, psz, pSep-psz); + pSettings->pszText[pSep-psz]=_T('\0'); + pSep++; + pSettings->pszLink=new TCHAR[_tcslen(pSep)+1]; + _tcscpy(pSettings->pszLink, pSep); + } + + ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); + break; + } + case WM_ERASEBKGND: + { + return (LRESULT)FALSE; + break; + } + case WM_PAINT: + { + // draw anything + PAINTSTRUCT ps; + HDC hDC=BeginPaint(hwnd, &ps); + + // flicker-free drawing + HDC hdc=::CreateCompatibleDC(hDC); + HBITMAP hBmp=::CreateCompatibleBitmap(hDC, ps.rcPaint.right-ps.rcPaint.left+1, ps.rcPaint.bottom-ps.rcPaint.top+1); + HBITMAP hOldBitmap=(HBITMAP)::SelectObject(hdc, hBmp); + ::SetWindowOrgEx(hdc, ps.rcPaint.left, ps.rcPaint.top, NULL); + + // paint the background + ::FillRect(hdc, &ps.rcPaint, (HBRUSH)::SendMessage((HWND)::GetWindowLong(hwnd, GWLP_HWNDPARENT), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd)); + + // size of the all control + RECT rcCtl; + ::GetClientRect(hwnd, &rcCtl); + + // draw text + DWORD dwFlags=DT_LEFT | DT_VCENTER | (::GetWindowLong(hwnd, GWL_STYLE) & SES_PATHELLIPSIS ? DT_PATH_ELLIPSIS : 0) + | (::GetWindowLong(hwnd, GWL_STYLE) & SES_ELLIPSIS ? DT_END_ELLIPSIS : 0) + | (::GetWindowLong(hwnd, GWL_STYLE) & SES_WORDBREAK ? DT_WORDBREAK : 0); + + pSettings->rcText=rcCtl; + if (::GetWindowLong(hwnd, GWL_STYLE) & SES_LINK) + { + HFONT hOld=(HFONT)::SelectObject(hdc, pSettings->hFontUnderline); + ::SetBkMode(hdc, TRANSPARENT); + + COLORREF crColor=(pSettings->bActive ? (RGB(255, 0, 0)) : (RGB(0, 0, 255))); + ::SetTextColor(hdc, crColor); + + if (pSettings->pszText) + { + DrawText(hdc, pSettings->pszText, -1, &pSettings->rcText, dwFlags | DT_CALCRECT); + DrawText(hdc, pSettings->pszText, -1, &rcCtl, dwFlags); + } + else + { + pSettings->rcText.left=0; + pSettings->rcText.right=0; + pSettings->rcText.top=0; + pSettings->rcText.bottom=0; + } + + ::SelectObject(hdc, hOld); + } + else + { + // aesthetics + rcCtl.left+=3; + rcCtl.right-=3; + + // draw + HFONT hOld=(HFONT)::SelectObject(hdc, pSettings->hFontNormal); + ::SetBkMode(hdc, TRANSPARENT); + ::SetTextColor(hdc, ::GetSysColor(COLOR_BTNTEXT)); + + if (pSettings->pszText) + { + DWORD dwMod=(::GetWindowLong(hwnd, GWL_STYLE) & SES_RALIGN) ? DT_RIGHT : 0; + DrawText(hdc, pSettings->pszText, -1, &pSettings->rcText, dwFlags | DT_CALCRECT | dwMod); + DrawText(hdc, pSettings->pszText, -1, &rcCtl, dwFlags | dwMod); + } + else + { + pSettings->rcText.left=0; + pSettings->rcText.right=0; + pSettings->rcText.top=0; + pSettings->rcText.bottom=0; + } + + ::SelectObject(hdc, hOld); + } + + // free the compatible dc + ::BitBlt(ps.hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left+1, ps.rcPaint.bottom-ps.rcPaint.top+1, + hdc, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); + ::SelectObject(hdc, hOldBitmap); + ::DeleteObject(hBmp); + ::DeleteDC(hdc); + + EndPaint(hwnd, &ps); + + break; + } + case WM_MOUSEMOVE: + { + if (::GetWindowLong(hwnd, GWL_STYLE) & SES_LINK) + { + POINT pt = { LOWORD(lParam), HIWORD(lParam) }; + + if (pSettings->bActive) + { + if (!::PtInRect(&pSettings->rcText, pt)) + { + pSettings->bActive=false; + ::ReleaseCapture(); + ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); + + ::SetCursor(pSettings->hNormal); + } + } + else + { + if (::PtInRect(&pSettings->rcText, pt)) + { + pSettings->bActive=true; + ::RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE); + ::SetCapture(hwnd); + ::SetCursor(pSettings->hLink); + } + } + } + break; + } + case WM_LBUTTONDOWN: + { + pSettings->bDown=true; + break; + } + case WM_LBUTTONUP: + { + POINT pt={ LOWORD(lParam), HIWORD(lParam) }; + if (pSettings->bDown && ::GetWindowLong(hwnd, GWL_STYLE) & SES_LINK && ::PtInRect(&pSettings->rcText, pt)) + { + if (::GetWindowLong(hwnd, GWL_STYLE) & SES_NOTIFY) + { + ::SendMessage((HWND)::GetWindowLong(hwnd, GWLP_HWNDPARENT), WM_COMMAND, (WPARAM)(SEN_CLICKED << 16 | ::GetWindowLong(hwnd, GWL_ID)), (LPARAM)hwnd); + } + else + { + + TRACE("Executing %s...\n", pSettings->pszLink); + ShellExecute(NULL, _T("open"), pSettings->pszLink, NULL, NULL, SW_SHOWNORMAL); + } + } + pSettings->bDown=false; + + break; + } + case WM_CANCELMODE: + { + pSettings->bActive=false; + pSettings->bDown=false; + break; + } + case SEM_GETLINK: + { + // wParam - count + // lParam - addr of a buffer + if (pSettings->pszLink) + _tcsncpy((PTSTR)lParam, pSettings->pszLink, (int)wParam); + else + _tcscpy((PTSTR)lParam, _T("")); + + return (LRESULT)TRUE; + break; + } + } + + return ::DefWindowProc(hwnd, uMsg, wParam, lParam); +} + +bool RegisterStaticExControl(HINSTANCE hInstance) +{ + WNDCLASS wndcls; + + if (!(::GetClassInfo(hInstance, STATICEX_CLASS, &wndcls))) + { + // need to register a new class + wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; + wndcls.lpfnWndProc = ::StaticExWndProc; + wndcls.cbClsExtra = 0; + wndcls.cbWndExtra = sizeof(STATICEXSETTINGS*); + wndcls.hInstance = hInstance; + wndcls.hIcon = NULL; + wndcls.hCursor = NULL; // will load each time needed + wndcls.hbrBackground = NULL; + wndcls.lpszMenuName = NULL; + wndcls.lpszClassName = STATICEX_CLASS; + + if (!RegisterClass(&wndcls)) + return false; + } + + return true; +} Index: src/ch/StaticEx.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/StaticEx.h (.../StaticEx.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/StaticEx.h (.../StaticEx.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,55 +1,55 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STATICEX_H__ -#define __STATICEX_H__ - -// styles -#define SES_LINK 0x0001 /* link instead of common static */ -#define SES_NOTIFY 0x0002 /* notifies parent about mouse messages */ -#define SES_PATHELLIPSIS 0x0004 -#define SES_ELLIPSIS 0x0008 -#define SES_BOLD 0x0010 -#define SES_LARGE 0x0020 -#define SES_RALIGN 0x0040 /* incompatible with SES_LINK */ -#define SES_WORDBREAK 0x0080 - -// messages -#define SEM_GETLINK (WM_USER+16) /* wParam - cnt of chars to copy, lParam - addr of text */ - -#define SEN_CLICKED 0x0001 - -bool RegisterStaticExControl(HINSTANCE hInstance); - -struct STATICEXSETTINGS -{ - HFONT hFontNormal; - HFONT hFontUnderline; - - HCURSOR hNormal; - HCURSOR hLink; - - bool bDown; // specifies if the mouse button has been pressed - bool bActive; // is the link hovered ? - RECT rcText; // current text position and size - - TCHAR *pszText; - TCHAR *pszLink; -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STATICEX_H__ +#define __STATICEX_H__ + +// styles +#define SES_LINK 0x0001 /* link instead of common static */ +#define SES_NOTIFY 0x0002 /* notifies parent about mouse messages */ +#define SES_PATHELLIPSIS 0x0004 +#define SES_ELLIPSIS 0x0008 +#define SES_BOLD 0x0010 +#define SES_LARGE 0x0020 +#define SES_RALIGN 0x0040 /* incompatible with SES_LINK */ +#define SES_WORDBREAK 0x0080 + +// messages +#define SEM_GETLINK (WM_USER+16) /* wParam - cnt of chars to copy, lParam - addr of text */ + +#define SEN_CLICKED 0x0001 + +bool RegisterStaticExControl(HINSTANCE hInstance); + +struct STATICEXSETTINGS +{ + HFONT hFontNormal; + HFONT hFontUnderline; + + HCURSOR hNormal; + HCURSOR hLink; + + bool bDown; // specifies if the mouse button has been pressed + bool bActive; // is the link hovered ? + RECT rcText; // current text position and size + + TCHAR *pszText; + TCHAR *pszLink; +}; + #endif \ No newline at end of file Index: src/ch/StatusDlg.cpp =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/StatusDlg.cpp (.../StatusDlg.cpp) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/ch/StatusDlg.cpp (.../StatusDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,979 +1,979 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "resource.h" -#include "StatusDlg.h" -#include "BufferSizeDlg.h" -#include "ReplacePathsDlg.h" -#include "StringHelpers.h" -#include "StaticEx.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -bool CStatusDlg::m_bLock=false; - -///////////////////////////////////////////////////////////////////////////// -// CStatusDlg dialog - -CStatusDlg::CStatusDlg(CTaskArray* pTasks, CWnd* pParent /*=NULL*/) - : ictranslate::CLanguageDialog(CStatusDlg::IDD, pParent, &m_bLock) -{ - //{{AFX_DATA_INIT(CStatusDlg) - //}}AFX_DATA_INIT - m_i64LastProcessed=0; - m_i64LastAllTasksProcessed=0; - m_pTasks=pTasks; - m_dwLastUpdate=0; - - RegisterStaticExControl(AfxGetInstanceHandle()); -} - -CStatusDlg::~CStatusDlg() -{ - -} - -void CStatusDlg::DoDataExchange(CDataExchange* pDX) -{ - CLanguageDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CStatusDlg) - DDX_Control(pDX, IDC_ERRORS_EDIT, m_ctlErrors); - DDX_Control(pDX, IDC_TASK_PROGRESS, m_ctlCurrentProgress); - DDX_Control(pDX, IDC_STATUS_LIST, m_ctlStatusList); - DDX_Control(pDX, IDC_ALL_PROGRESS, m_ctlProgressAll); - //}}AFX_DATA_MAP -} - -BEGIN_MESSAGE_MAP(CStatusDlg,ictranslate::CLanguageDialog) - //{{AFX_MSG_MAP(CStatusDlg) - ON_WM_TIMER() - ON_BN_CLICKED(IDC_PAUSE_BUTTON, OnPauseButton) - ON_BN_CLICKED(IDC_CANCEL_BUTTON, OnCancelButton) - ON_BN_CLICKED(IDC_ROLL_UNROLL_BUTTON, OnRollUnrollButton) - ON_BN_CLICKED(IDC_SET_PRIORITY_BUTTON, OnSetPriorityButton) - ON_BN_CLICKED(IDC_SET_BUFFERSIZE_BUTTON, OnSetBuffersizeButton) - ON_BN_CLICKED(IDC_START_ALL_BUTTON, OnStartAllButton) - ON_BN_CLICKED(IDC_RESTART_BUTTON, OnRestartButton) - ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) - ON_BN_CLICKED(IDC_PAUSE_ALL_BUTTON, OnPauseAllButton) - ON_BN_CLICKED(IDC_RESTART_ALL_BUTTON, OnRestartAllButton) - ON_BN_CLICKED(IDC_CANCEL_ALL_BUTTON, OnCancelAllButton) - ON_BN_CLICKED(IDC_REMOVE_FINISHED_BUTTON, OnRemoveFinishedButton) - ON_NOTIFY(LVN_KEYDOWN, IDC_STATUS_LIST, OnKeydownStatusList) - ON_NOTIFY(LVN_CHANGEDSELECTION, IDC_STATUS_LIST, OnSelectionChanged) - ON_BN_CLICKED(IDC_ADVANCED_BUTTON, OnAdvancedButton) - ON_COMMAND(ID_POPUP_REPLACE_PATHS, OnPopupReplacePaths) - ON_BN_CLICKED(IDC_SHOW_LOG_BUTTON, OnShowLogButton) - ON_BN_CLICKED(IDC_STICK_BUTTON, OnStickButton) - ON_BN_CLICKED(IDC_RESUME_BUTTON, OnResumeButton) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CStatusDlg message handlers - -BOOL CStatusDlg::OnInitDialog() -{ - CLanguageDialog::OnInitDialog(); - - // get size of list ctrl - CRect rcList; - m_ctlStatusList.GetWindowRect(&rcList); - int iWidth=rcList.Width(); - - // set additional styles - m_ctlStatusList.SetExtendedStyle(m_ctlStatusList.GetExtendedStyle() | LVS_EX_FULLROWSELECT); - - // add columns - LVCOLUMN lvc; - lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; - lvc.fmt=LVCFMT_LEFT; - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNSTATUS_STRING); /*_T("Status")*/; - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.27*iWidth); - lvc.iSubItem=-1; - m_ctlStatusList.InsertColumn(1, &lvc); - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNSOURCE_STRING);/*_T("File");*/ - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.3*iWidth); - lvc.iSubItem=0; - m_ctlStatusList.InsertColumn(2, &lvc); - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNDESTINATION_STRING);/*_T("To:");*/ - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.27*iWidth); - lvc.iSubItem=1; - m_ctlStatusList.InsertColumn(3, &lvc); - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNPROGRESS_STRING);/*_T("Progress");*/ - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.15*iWidth); - lvc.iSubItem=2; - m_ctlStatusList.InsertColumn(4, &lvc); - - // images - m_images.Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 3); - m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_WORKING_ICON))); - m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_ERROR_ICON))); - m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_PAUSED_ICON))); - m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_FINISHED_ICON))); - m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_CANCELLED_ICON))); - m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_WAITING_ICON))); - - m_ctlStatusList.SetImageList(&m_images, LVSIL_SMALL); - - // set fixed progresses ranges - m_ctlCurrentProgress.SetRange32(0, 100); - m_ctlProgressAll.SetRange32(0, 100); - - // change the size of a dialog - ApplyDisplayDetails(true); -// ApplyButtonsState(); -// EnableControls(false); - - // refresh data - RefreshStatus(); - - // select needed element - int i=0; - while (i < m_pTasks->GetSize()) - { - if (m_pTasks->GetAt(i) == m_pInitialSelection) - { - m_ctlStatusList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); - break; - } - - i++; - }; - - // refresh data timer - SetTimer(777, (UINT)GetConfig()->get_signed_num(PP_STATUSREFRESHINTERVAL), NULL); - - return TRUE; -} - -void CStatusDlg::EnableControls(bool bEnable) -{ - // enable/disable controls - GetDlgItem(IDC_SET_BUFFERSIZE_BUTTON)->EnableWindow(bEnable); - GetDlgItem(IDC_SET_PRIORITY_BUTTON)->EnableWindow(bEnable); - - if (!bEnable) - { - // get rid of text id disabling - GetDlgItem(IDC_OPERATION_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYOPERATIONTEXT_STRING)); - GetDlgItem(IDC_SOURCE_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYSOURCETEXT_STRING)); - GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYDESTINATIONTEXT_STRING)); - GetDlgItem(IDC_BUFFERSIZE_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYBUFFERSIZETEXT_STRING)); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYPRIORITYTEXT_STRING)); - - const TCHAR *pszText=GetResManager()->LoadString(IDS_EMPTYERRORTEXT_STRING); - m_ctlErrors.GetWindowText(m_strTemp); - if (m_strTemp != pszText) - m_ctlErrors.SetWindowText(pszText); - - GetDlgItem(IDC_PROGRESS_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYPROCESSEDTEXT_STRING)); - GetDlgItem(IDC_TRANSFER_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYTRANSFERTEXT_STRING)); - GetDlgItem(IDC_TIME_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYTIMETEXT_STRING)); - GetDlgItem(IDC_ASSOCIATEDFILES__STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYASSOCFILE_STRING)); - - m_ctlCurrentProgress.SetPos(0); - } -} - -void CStatusDlg::OnTimer(UINT_PTR nIDEvent) -{ - if (nIDEvent == 777) // refreshing data - { - // turn off timer for some time - KillTimer(777); - - RefreshStatus(); - - // reenable - SetTimer(777, (UINT)GetConfig()->get_signed_num(PP_STATUSREFRESHINTERVAL), NULL); - } - - CLanguageDialog::OnTimer(nIDEvent); -} - -void CStatusDlg::AddTaskInfo(int nPos, CTask *pTask, DWORD dwCurrentTime) -{ - // index to string - _itot(nPos, m_szData, 10); - - // get data snapshot from task - pTask->GetSnapshot(&td); - - // index subitem - lvi.mask=LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; - lvi.iItem=nPos; - lvi.iSubItem=0; - lvi.pszText=td.m_szStatusText; - lvi.cchTextMax=lstrlen(lvi.pszText); - lvi.lParam=reinterpret_cast(pTask); - lvi.iImage=GetImageFromStatus(td.m_uiStatus); - if (nPos < m_ctlStatusList.GetItemCount()) - m_ctlStatusList.SetItem(&lvi); - else - m_ctlStatusList.InsertItem(&lvi); - - // status subitem - lvi.mask=LVIF_TEXT; // zmie� mask� - lvi.iSubItem=1; - m_strTemp=td.m_fi.GetFileName(); - lvi.pszText=m_strTemp.GetBuffer(0); - m_strTemp.ReleaseBuffer(); - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlStatusList.SetItem(&lvi); - - // insert 'file' subitem - lvi.iSubItem=2; - m_strTemp=td.m_pdpDestPath->GetPath(); - lvi.pszText=m_strTemp.GetBuffer(0); - m_strTemp.ReleaseBuffer(); - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlStatusList.SetItem(&lvi); - - // insert dest subitem - lvi.iSubItem=3; - _itot( td.m_nPercent, m_szData, 10 ); - _tcscat(m_szData, _T(" %")); - lvi.pszText=m_szData; - lvi.cchTextMax=lstrlen(lvi.pszText); - m_ctlStatusList.SetItem(&lvi); - - // right side update - if (pTask == pSelectedItem && GetConfig()->get_bool(PP_STATUSSHOWDETAILS)) - { - // data that can be changed by a thread - GetDlgItem(IDC_OPERATION_STATIC)->SetWindowText(td.m_szStatusText); // operation - GetDlgItem(IDC_SOURCE_STATIC)->SetWindowText(td.m_fi.GetFullFilePath()); // src object - - // error message - if ( (td.m_uiStatus & ST_WORKING_MASK) == ST_ERROR ) - { - m_ctlErrors.GetWindowText(m_strTemp); - if (m_strTemp != td.m_strErrorDesc) - m_ctlErrors.SetWindowText(td.m_strErrorDesc); - } - else - { - const TCHAR *pszText=GetResManager()->LoadString(IDS_EMPTYERRORTEXT_STRING); - - m_ctlErrors.GetWindowText(m_strTemp2); - if (m_strTemp2 != pszText) - m_ctlErrors.SetWindowText(pszText); - } - - // count of processed data/overall count of data - _sntprintf(m_szData, _MAX_PATH, _T("%d/%d ("), td.m_iIndex, td.m_iSize); - m_strTemp=CString(m_szData); - m_strTemp+=GetSizeString(td.m_ullProcessedSize, m_szData, _MAX_PATH)+CString(_T("/")); - m_strTemp+=GetSizeString(td.m_ullSizeAll, m_szData, _MAX_PATH)+CString(_T(")")); - _sntprintf(m_szData, _MAX_PATH, _T(" (%s%d/%d)"), GetResManager()->LoadString(IDS_CURRENTPASS_STRING), td.m_ucCurrentCopy, td.m_ucCopies); - m_strTemp+=m_szData; - GetDlgItem(IDC_PROGRESS_STATIC)->SetWindowText(m_strTemp); - - // transfer - if (m_i64LastProcessed == 0) // if first time - show average - m_strTemp=GetSizeString( td.m_lTimeElapsed ? td.m_ullProcessedSize/td.m_lTimeElapsed : 0, m_szData, _MAX_PATH); // last avg - else - if ( (dwCurrentTime-m_dwLastUpdate) != 0) - m_strTemp=GetSizeString( (static_cast(td.m_ullProcessedSize) - static_cast(m_i64LastProcessed))/(static_cast(dwCurrentTime-m_dwLastUpdate)/1000.0), m_szData, _MAX_PATH); - else - m_strTemp=GetSizeString( 0ULL, m_szData, _MAX_PATH); - - // avg transfer - GetDlgItem(IDC_TRANSFER_STATIC)->SetWindowText(m_strTemp+_T("/s (")+CString(GetResManager()->LoadString(IDS_AVERAGEWORD_STRING)) - +CString(GetSizeString(td.m_lTimeElapsed ? td.m_ullProcessedSize/td.m_lTimeElapsed : 0, m_szData, _MAX_PATH))+_T("/s )") - ); - - // elapsed time/estimated time - FormatTime(td.m_lTimeElapsed, m_szTimeBuffer1, 40); - FormatTime( (td.m_ullProcessedSize == 0) ? 0 : static_cast((static_cast<__int64>(td.m_ullSizeAll)*static_cast<__int64>(td.m_lTimeElapsed))/td.m_ullProcessedSize), m_szTimeBuffer2, 40); - - _sntprintf(m_szData, _MAX_PATH, _T("%s / %s"), m_szTimeBuffer1, m_szTimeBuffer2); - GetDlgItem(IDC_TIME_STATIC)->SetWindowText(m_szData); - - // remember current processed data (used for calculating transfer) - m_i64LastProcessed=td.m_ullProcessedSize; - - // set progress - m_ctlCurrentProgress.SetPos(td.m_nPercent); - - SetBufferSizesString(td.m_pbsSizes->m_auiSizes[td.m_iCurrentBufferIndex], td.m_iCurrentBufferIndex); - - // data that can be changed only by user from outside the thread - // refresh only when there are new selected item -// if (pTask != m_pLastSelected) - { - GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(td.m_pdpDestPath->GetPath()); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(td.m_nPriority))); - GetDlgItem(IDC_ASSOCIATEDFILES__STATIC)->SetWindowText(*td.m_pstrUniqueName+_T(".atd (.atp, .log)")); - } - - // refresh m_pLastSelected - m_pLastSelected=pTask; - } -} - -void CStatusDlg::OnSetBuffersizeButton() -{ - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - CBufferSizeDlg dlg; - dlg.m_bsSizes=*pTask->GetBufferSizes(); - dlg.m_iActiveIndex=pTask->GetCurrentBufferIndex(); - if (dlg.DoModal() == IDOK) - { - // if the task has been deleted - skip - if ( pTask != GetSelectedItemPointer() ) - { - TRACE("Task were finished and deleted when trying to change buffer sizes"); - return; - } - - TRACE("bOnlyDefault=%d\n", dlg.m_bsSizes.m_bOnlyDefault); - pTask->SetBufferSizes(&dlg.m_bsSizes); - } -} - -CTask* CStatusDlg::GetSelectedItemPointer() -{ -// TRACE("inside GetSelectedItemPointer()\n"); - // returns ptr to a CTask for a given element in listview - if (m_ctlStatusList.GetSelectedCount() == 1) - { - POSITION pos=m_ctlStatusList.GetFirstSelectedItemPosition(); - int nPos=m_ctlStatusList.GetNextSelectedItem(pos); - CTask* pSelectedItem=reinterpret_cast(m_ctlStatusList.GetItemData(nPos)); -// if (AfxIsValidAddress(pSelectedItem, sizeof(CTask))) - return pSelectedItem; - } -// TRACE("exiting GetSelectedItemPointer()\n"); - - return NULL; -} - -void CStatusDlg::OnRollUnrollButton() -{ - // change settings in config dialog - GetConfig()->set_bool(PP_STATUSSHOWDETAILS, !GetConfig()->get_bool(PP_STATUSSHOWDETAILS)); - - ApplyDisplayDetails(); -} - -void CStatusDlg::ApplyDisplayDetails(bool bInitial) -{ - // get coord of screen and window - CRect rcScreen, rect; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0); - GetWindowRect(&rect); - - bool bDetails=GetConfig()->get_bool(PP_STATUSSHOWDETAILS); - - // stick cause - if (rect.right == rcScreen.right && rect.bottom == rcScreen.bottom) - bInitial=true; - - GetDlgItem(IDC_ROLL_UNROLL_BUTTON)->SetWindowText(bDetails ? _T("<<") : _T(">>")); - - CRect list, progress; - m_ctlProgressAll.GetWindowRect(&progress); - ScreenToClient(&progress); - m_ctlStatusList.GetWindowRect(&list); - ScreenToClient(&list); - - // set dialog size - CRect destRect; - if (!bInitial) - { - destRect.left=0; - destRect.top=0; - destRect.right=bDetails ? progress.right+list.left+3*GetSystemMetrics(SM_CXBORDER) : list.right+list.left+3*GetSystemMetrics(SM_CXBORDER); - destRect.bottom=rect.Height(); - SetWindowPos(NULL, destRect.left, destRect.top, destRect.right, destRect.bottom, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); - } - else - { - SetWindowPos(NULL, rcScreen.right-(bDetails ? progress.right+list.left+3*GetSystemMetrics(SM_CXBORDER) : list.right+list.left+3*GetSystemMetrics(SM_CXBORDER)), - rcScreen.bottom-rect.Height(), (bDetails ? progress.right+list.left+3*GetSystemMetrics(SM_CXBORDER) : list.right+list.left+3*GetSystemMetrics(SM_CXBORDER)), - rect.Height(), SWP_NOOWNERZORDER | SWP_NOZORDER); - } -} - -void CStatusDlg::ApplyButtonsState() -{ - // remember ptr to CTask - pSelectedItem=GetSelectedItemPointer(); - bool bShowLog=GetConfig()->get_bool(PP_CMCREATELOG); - - // set status of buttons pause/resume/cancel - if (pSelectedItem != NULL) - { - GetDlgItem(IDC_RESTART_BUTTON)->EnableWindow(true); - GetDlgItem(IDC_SHOW_LOG_BUTTON)->EnableWindow(bShowLog); - GetDlgItem(IDC_DELETE_BUTTON)->EnableWindow(true); - - if (pSelectedItem->GetStatus(ST_STEP_MASK) == ST_FINISHED - || pSelectedItem->GetStatus(ST_STEP_MASK) == ST_CANCELLED) - { - GetDlgItem(IDC_CANCEL_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(false); - } - else - { - // pause/resume - if (pSelectedItem->GetStatus(ST_WORKING_MASK) & ST_PAUSED) - { - GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(true); - } - else - { - GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(true); - if (pSelectedItem->GetStatus(ST_WAITING_MASK) & ST_WAITING) - GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(true); - else - GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(false); - } - - GetDlgItem(IDC_CANCEL_BUTTON)->EnableWindow(true); - } - } - else - { - GetDlgItem(IDC_SHOW_LOG_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_RESTART_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_CANCEL_BUTTON)->EnableWindow(false); - GetDlgItem(IDC_DELETE_BUTTON)->EnableWindow(false); - } -} - -void CStatusDlg::OnSetPriorityButton() -{ - CMenu menu; - HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_PRIORITY_MENU)); - if (!menu.Attach(hMenu)) - { - DestroyMenu(hMenu); - return; - } - - CMenu* pPopup = menu.GetSubMenu(0); - ASSERT(pPopup != NULL); - if(pPopup) - { - // set point in which to set menu - CRect rect; - GetDlgItem(IDC_SET_PRIORITY_BUTTON)->GetWindowRect(&rect); - - pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right+1, rect.top, this); - } -} - -BOOL CStatusDlg::OnCommand(WPARAM wParam, LPARAM lParam) -{ - if (HIWORD(wParam) == 0) - { - if (LOWORD(wParam) >= ID_POPUP_TIME_CRITICAL && LOWORD(wParam) <= ID_POPUP_IDLE) - { - // processing priority - if ( (pSelectedItem=GetSelectedItemPointer()) == NULL ) - return ictranslate::CLanguageDialog::OnCommand(wParam, lParam); - - switch (LOWORD(wParam)) - { - case ID_POPUP_TIME_CRITICAL: - pSelectedItem->SetPriority(THREAD_PRIORITY_TIME_CRITICAL); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_TIME_CRITICAL))); - break; - case ID_POPUP_HIGHEST: - pSelectedItem->SetPriority(THREAD_PRIORITY_HIGHEST); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_HIGHEST))); - break; - case ID_POPUP_ABOVE_NORMAL: - pSelectedItem->SetPriority(THREAD_PRIORITY_ABOVE_NORMAL); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_ABOVE_NORMAL))); - break; - case ID_POPUP_NORMAL: - pSelectedItem->SetPriority(THREAD_PRIORITY_NORMAL); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_NORMAL))); - break; - case ID_POPUP_BELOW_NORMAL: - pSelectedItem->SetPriority(THREAD_PRIORITY_BELOW_NORMAL); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_BELOW_NORMAL))); - break; - case ID_POPUP_LOWEST: - pSelectedItem->SetPriority(THREAD_PRIORITY_LOWEST); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_LOWEST))); - break; - case ID_POPUP_IDLE: - pSelectedItem->SetPriority(THREAD_PRIORITY_IDLE); - GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_IDLE))); - break; - } - } - } - return ictranslate::CLanguageDialog::OnCommand(wParam, lParam); -} - -void CStatusDlg::OnPauseButton() -{ - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - TRACE("PauseProcessing call...\n"); - pTask->PauseProcessing(); - - RefreshStatus(); -} - -void CStatusDlg::OnResumeButton() -{ - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - TRACE("ResumeProcessing call "); - if (pTask->GetStatus(ST_WAITING_MASK) & ST_WAITING) - { - TRACE("by setting force flag\n"); - pTask->SetForceFlag(); - } - else - { - TRACE("by function ResumeProcessing\n"); - pTask->ResumeProcessing(); - } - - RefreshStatus(); -} - -void CStatusDlg::OnCancelButton() -{ - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) != NULL ) - { - TRACE("CancelProcessing call...\n"); - pTask->CancelProcessing(); - } - RefreshStatus(); -} - -void CStatusDlg::OnRestartButton() -{ - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - TRACE("RestartProcessing call...\n"); - pTask->RestartProcessing(); - RefreshStatus(); -} - -void CStatusDlg::OnDeleteButton() -{ - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - UINT uiStatus=pTask->GetStatus(ST_STEP_MASK); - if ( (uiStatus & ST_STEP_MASK) != ST_FINISHED && (uiStatus & ST_STEP_MASK) != ST_CANCELLED ) - { - // ask if cancel - if (MsgBox(IDS_CONFIRMCANCEL_STRING, MB_OKCANCEL | MB_ICONQUESTION) == IDOK) - { - // cancel - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - pTask->CancelProcessing(); - } - else - return; - } - - m_pTasks->RemoveFinished(&pTask); - RefreshStatus(); -} - -void CStatusDlg::OnPauseAllButton() -{ - TRACE("Pause All...\n"); - m_pTasks->TasksPauseProcessing(); - RefreshStatus(); -} - -void CStatusDlg::OnStartAllButton() -{ - TRACE("Resume Processing...\n"); - m_pTasks->TasksResumeProcessing(); - RefreshStatus(); -} - -void CStatusDlg::OnRestartAllButton() -{ - TRACE("Restart Processing...\n"); - m_pTasks->TasksRestartProcessing(); - RefreshStatus(); -} - -void CStatusDlg::OnCancelAllButton() -{ - TRACE("Cancel Processing...\n"); - m_pTasks->TasksCancelProcessing(); - RefreshStatus(); -} - -void CStatusDlg::OnRemoveFinishedButton() -{ - m_pTasks->RemoveAllFinished(); - RefreshStatus(); -} - -void CStatusDlg::OnKeydownStatusList(NMHDR* pNMHDR, LRESULT* pResult) -{ - LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; - switch (pLVKeyDow->wVKey) - { - case VK_DELETE: - OnDeleteButton(); - break; - case VK_SPACE: - { - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL ) - return; - - if (pTask->GetStatus(ST_WORKING_MASK) & ST_PAUSED) - OnResumeButton(); - else - OnPauseButton(); - break; - } - } - - *pResult = 0; -} - -int CStatusDlg::GetImageFromStatus(UINT nStatus) -{ - if ( (nStatus & ST_STEP_MASK) == ST_CANCELLED ) - return 4; - if ( (nStatus & ST_STEP_MASK) == ST_FINISHED ) - return 3; - if ( (nStatus & ST_WAITING_MASK) == ST_WAITING ) - return 5; - if ( (nStatus & ST_WORKING_MASK) == ST_PAUSED ) - return 2; - if ( (nStatus & ST_WORKING_MASK) == ST_ERROR ) - return 1; - return 0; -} - -LPTSTR CStatusDlg::FormatTime(long lSeconds, LPTSTR lpszBuffer, size_t stMaxBufferSize) -{ - long lDays=lSeconds/86400; - lSeconds%=86400; - long lHours=lSeconds/3600; - lSeconds%=3600; - long lMinutes=lSeconds/60; - lSeconds%=60; - - if (lDays != 0) - _sntprintf(lpszBuffer, stMaxBufferSize, _T("%02d:%02d:%02d:%02d"), lDays, lHours, lMinutes, lSeconds); - else - if (lHours != 0) - _sntprintf(lpszBuffer, stMaxBufferSize, _T("%02d:%02d:%02d"), lHours, lMinutes, lSeconds); - else - _sntprintf(lpszBuffer, stMaxBufferSize, _T("%02d:%02d"), lMinutes, lSeconds); - - return lpszBuffer; -} - -void CStatusDlg::RefreshStatus() -{ - // remember address of a current selection - pSelectedItem=GetSelectedItemPointer(); - - // current time - DWORD dwCurrentTime=GetTickCount(); - - // get rid of item after the current part - m_ctlStatusList.LimitItems(m_pTasks->GetSize()); - - // add task info - for (int i=0;iGetSize();i++) - AddTaskInfo(i, m_pTasks->GetAt(i), dwCurrentTime); - - // percent - int nPercent=m_pTasks->GetPercent(); - - // set title - if (m_pTasks->GetSize() != 0) - _sntprintf(m_szData, _MAX_PATH, _T("%s [%d %%]"), GetResManager()->LoadString(IDS_STATUSTITLE_STRING), m_pTasks->GetPercent()); - else - _sntprintf(m_szData, _MAX_PATH, _T("%s"), GetResManager()->LoadString(IDS_STATUSTITLE_STRING)); - - // if changed - GetWindowText(m_strTemp); - if (m_strTemp != CString(m_szData)) - SetWindowText(m_szData); - - // refresh overall progress - if (GetConfig()->get_bool(PP_STATUSSHOWDETAILS)) - { - m_ctlProgressAll.SetPos(nPercent); - - // progress - count of processed data/count of data - m_strTemp=GetSizeString(m_pTasks->GetPosition(), m_szData, _MAX_PATH)+CString(_T("/")); - m_strTemp+=GetSizeString(m_pTasks->GetRange(), m_szData, _MAX_PATH); - GetDlgItem(IDC_OVERALL_PROGRESS_STATIC)->SetWindowText(m_strTemp); - - // transfer - if (m_i64LastAllTasksProcessed == 0) - m_i64LastAllTasksProcessed=m_pTasks->GetPosition(); - - if (dwCurrentTime-m_dwLastUpdate != 0) - m_strTemp=GetSizeString( (static_cast(m_pTasks->GetPosition()) - static_cast(m_i64LastAllTasksProcessed))/static_cast(static_cast(dwCurrentTime-m_dwLastUpdate)/1000.0), m_szData, _MAX_PATH); - else - m_strTemp=GetSizeString( 0ULL, m_szData, _MAX_PATH); - - GetDlgItem(IDC_OVERALL_TRANSFER_STATIC)->SetWindowText(m_strTemp+_T("/s")); - m_i64LastAllTasksProcessed=m_pTasks->GetPosition(); - m_dwLastUpdate=dwCurrentTime; - } - - // if selection's missing - hide controls - if (m_ctlStatusList.GetSelectedCount() == 0) - { - EnableControls(false); - m_pLastSelected=NULL; - m_i64LastProcessed=0; - } - else - EnableControls(); // enable controls - - // apply state of the resume, cancel, ... buttons - ApplyButtonsState(); -} - -void CStatusDlg::OnSelectionChanged(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/) -{ - TRACE("Received LVN_CHANGEDSELECTION\n"); - RefreshStatus(); -} - -void CStatusDlg::OnCancel() -{ - PostCloseMessage(); - CLanguageDialog::OnCancel(); -} - -void CStatusDlg::OnAdvancedButton() -{ - CMenu menu; - HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_ADVANCED_MENU)); - if (!menu.Attach(hMenu)) - { - DestroyMenu(hMenu); - return; - } - - CMenu* pPopup = menu.GetSubMenu(0); - ASSERT(pPopup != NULL); - if(pPopup) - { - // get the point to show menu at - CRect rect; - GetDlgItem(IDC_ADVANCED_BUTTON)->GetWindowRect(&rect); - - pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right+1, rect.top, this); - } -} - -void CStatusDlg::OnPopupReplacePaths() -{ - // check if there's a selection currently - if ( (pSelectedItem=GetSelectedItemPointer()) != NULL ) - { - if (pSelectedItem->GetStatus(ST_WORKING_MASK) & ST_PAUSED) - { - bool bContinue=false; - if (pSelectedItem->GetStatus(ST_WORKING_MASK) == ST_ERROR) - { - pSelectedItem->PauseProcessing(); - bContinue=true; - } - - // assuming here that there's selection and task is paused - CReplacePathsDlg dlg; - dlg.m_pTask=pSelectedItem; - if (dlg.DoModal() == IDOK) - { - // change 'no case' - int iClipboard=pSelectedItem->ReplaceClipboardStrings(dlg.m_strSource, dlg.m_strDest); - - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_REPLACEPATHSTEXT_STRING)); - fmt.SetParam(_t("%count"), iClipboard); - AfxMessageBox(fmt); - } - - // resume if earlier was an error - if (bContinue) - pSelectedItem->ResumeProcessing(); - } - else - MsgBox(IDS_TASKNOTPAUSED_STRING); - } - else - MsgBox(IDS_TASKNOTSELECTED_STRING); -} - -void CStatusDlg::OnShowLogButton() -{ - // show log - CTask* pTask; - if ( (pTask=GetSelectedItemPointer()) == NULL || !GetConfig()->get_bool(PP_CMCREATELOG)) - return; - - // call what's needed - unsigned long lResult=(unsigned long)(ShellExecute(this->m_hWnd, _T("open"), _T("notepad.exe"), - CString(pTask->GetTaskPath())+pTask->GetUniqueName()+_T(".log"), NULL, SW_SHOWNORMAL)); - if (lResult < 32) - { - CString str=CString(pTask->GetTaskPath())+pTask->GetUniqueName()+_T(".log"); - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_SHELLEXECUTEERROR_STRING)); - fmt.SetParam(_t("%errno"), lResult); - fmt.SetParam(_t("%path"), str); - AfxMessageBox(fmt); - } -} - -LRESULT CStatusDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - if (message == WM_UPDATESTATUS) - { - TRACE("Received WM_UPDATESTATUS\n"); - RefreshStatus(); - } - return ictranslate::CLanguageDialog::WindowProc(message, wParam, lParam); -} - -void CStatusDlg::OnStickButton() -{ - ApplyDisplayDetails(true); -} - -void CStatusDlg::SetBufferSizesString(UINT uiValue, int iIndex) -{ - TCHAR szData[1024]; - switch(iIndex) - { - case BI_DEFAULT: - GetResManager()->LoadStringCopy(IDS_BSDEFAULT_STRING, szData, 256); - break; - case BI_ONEDISK: - GetResManager()->LoadStringCopy(IDS_BSONEDISK_STRING, szData, 256); - break; - case BI_TWODISKS: - GetResManager()->LoadStringCopy(IDS_BSTWODISKS_STRING, szData, 256); - break; - case BI_CD: - GetResManager()->LoadStringCopy(IDS_BSCD_STRING, szData, 256); - break; - case BI_LAN: - GetResManager()->LoadStringCopy(IDS_BSLAN_STRING, szData, 256); - break; - default: - _ASSERTE(false); - szData[0] = _T('\0'); - } - - _tcscat(szData, GetSizeString((ull_t)uiValue, m_szData, _MAX_PATH)); - - GetDlgItem(IDC_BUFFERSIZE_STATIC)->SetWindowText(szData); -} - -void CStatusDlg::PostCloseMessage() -{ - GetParent()->PostMessage(WM_STATUSCLOSING); -} - -void CStatusDlg::OnLanguageChanged() -{ - // remove all columns - int iCnt=m_ctlStatusList.GetHeaderCtrl()->GetItemCount(); - - // Delete all of the columns. - for (int i=0;iLoadString(IDS_COLUMNSTATUS_STRING); /*_T("Status")*/; - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.27*iWidth); - lvc.iSubItem=-1; - m_ctlStatusList.InsertColumn(1, &lvc); - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNSOURCE_STRING);/*_T("File");*/ - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.3*iWidth); - lvc.iSubItem=0; - m_ctlStatusList.InsertColumn(2, &lvc); - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNDESTINATION_STRING);/*_T("To:");*/ - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.27*iWidth); - lvc.iSubItem=1; - m_ctlStatusList.InsertColumn(3, &lvc); - - lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNPROGRESS_STRING);/*_T("Progress");*/ - lvc.cchTextMax = lstrlen(lvc.pszText); - lvc.cx = static_cast(0.15*iWidth); - lvc.iSubItem=2; - m_ctlStatusList.InsertColumn(4, &lvc); - - RefreshStatus(); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "resource.h" +#include "StatusDlg.h" +#include "BufferSizeDlg.h" +#include "ReplacePathsDlg.h" +#include "StringHelpers.h" +#include "StaticEx.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +bool CStatusDlg::m_bLock=false; + +///////////////////////////////////////////////////////////////////////////// +// CStatusDlg dialog + +CStatusDlg::CStatusDlg(CTaskArray* pTasks, CWnd* pParent /*=NULL*/) + : ictranslate::CLanguageDialog(CStatusDlg::IDD, pParent, &m_bLock) +{ + //{{AFX_DATA_INIT(CStatusDlg) + //}}AFX_DATA_INIT + m_i64LastProcessed=0; + m_i64LastAllTasksProcessed=0; + m_pTasks=pTasks; + m_dwLastUpdate=0; + + RegisterStaticExControl(AfxGetInstanceHandle()); +} + +CStatusDlg::~CStatusDlg() +{ + +} + +void CStatusDlg::DoDataExchange(CDataExchange* pDX) +{ + CLanguageDialog::DoDataExchange(pDX); + //{{AFX_DATA_MAP(CStatusDlg) + DDX_Control(pDX, IDC_ERRORS_EDIT, m_ctlErrors); + DDX_Control(pDX, IDC_TASK_PROGRESS, m_ctlCurrentProgress); + DDX_Control(pDX, IDC_STATUS_LIST, m_ctlStatusList); + DDX_Control(pDX, IDC_ALL_PROGRESS, m_ctlProgressAll); + //}}AFX_DATA_MAP +} + +BEGIN_MESSAGE_MAP(CStatusDlg,ictranslate::CLanguageDialog) + //{{AFX_MSG_MAP(CStatusDlg) + ON_WM_TIMER() + ON_BN_CLICKED(IDC_PAUSE_BUTTON, OnPauseButton) + ON_BN_CLICKED(IDC_CANCEL_BUTTON, OnCancelButton) + ON_BN_CLICKED(IDC_ROLL_UNROLL_BUTTON, OnRollUnrollButton) + ON_BN_CLICKED(IDC_SET_PRIORITY_BUTTON, OnSetPriorityButton) + ON_BN_CLICKED(IDC_SET_BUFFERSIZE_BUTTON, OnSetBuffersizeButton) + ON_BN_CLICKED(IDC_START_ALL_BUTTON, OnStartAllButton) + ON_BN_CLICKED(IDC_RESTART_BUTTON, OnRestartButton) + ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton) + ON_BN_CLICKED(IDC_PAUSE_ALL_BUTTON, OnPauseAllButton) + ON_BN_CLICKED(IDC_RESTART_ALL_BUTTON, OnRestartAllButton) + ON_BN_CLICKED(IDC_CANCEL_ALL_BUTTON, OnCancelAllButton) + ON_BN_CLICKED(IDC_REMOVE_FINISHED_BUTTON, OnRemoveFinishedButton) + ON_NOTIFY(LVN_KEYDOWN, IDC_STATUS_LIST, OnKeydownStatusList) + ON_NOTIFY(LVN_CHANGEDSELECTION, IDC_STATUS_LIST, OnSelectionChanged) + ON_BN_CLICKED(IDC_ADVANCED_BUTTON, OnAdvancedButton) + ON_COMMAND(ID_POPUP_REPLACE_PATHS, OnPopupReplacePaths) + ON_BN_CLICKED(IDC_SHOW_LOG_BUTTON, OnShowLogButton) + ON_BN_CLICKED(IDC_STICK_BUTTON, OnStickButton) + ON_BN_CLICKED(IDC_RESUME_BUTTON, OnResumeButton) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CStatusDlg message handlers + +BOOL CStatusDlg::OnInitDialog() +{ + CLanguageDialog::OnInitDialog(); + + // get size of list ctrl + CRect rcList; + m_ctlStatusList.GetWindowRect(&rcList); + int iWidth=rcList.Width(); + + // set additional styles + m_ctlStatusList.SetExtendedStyle(m_ctlStatusList.GetExtendedStyle() | LVS_EX_FULLROWSELECT); + + // add columns + LVCOLUMN lvc; + lvc.mask=LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt=LVCFMT_LEFT; + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNSTATUS_STRING); /*_T("Status")*/; + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.27*iWidth); + lvc.iSubItem=-1; + m_ctlStatusList.InsertColumn(1, &lvc); + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNSOURCE_STRING);/*_T("File");*/ + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.3*iWidth); + lvc.iSubItem=0; + m_ctlStatusList.InsertColumn(2, &lvc); + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNDESTINATION_STRING);/*_T("To:");*/ + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.27*iWidth); + lvc.iSubItem=1; + m_ctlStatusList.InsertColumn(3, &lvc); + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNPROGRESS_STRING);/*_T("Progress");*/ + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.15*iWidth); + lvc.iSubItem=2; + m_ctlStatusList.InsertColumn(4, &lvc); + + // images + m_images.Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 3); + m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_WORKING_ICON))); + m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_ERROR_ICON))); + m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_PAUSED_ICON))); + m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_FINISHED_ICON))); + m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_CANCELLED_ICON))); + m_images.Add(AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_WAITING_ICON))); + + m_ctlStatusList.SetImageList(&m_images, LVSIL_SMALL); + + // set fixed progresses ranges + m_ctlCurrentProgress.SetRange32(0, 100); + m_ctlProgressAll.SetRange32(0, 100); + + // change the size of a dialog + ApplyDisplayDetails(true); +// ApplyButtonsState(); +// EnableControls(false); + + // refresh data + RefreshStatus(); + + // select needed element + int i=0; + while (i < m_pTasks->GetSize()) + { + if (m_pTasks->GetAt(i) == m_pInitialSelection) + { + m_ctlStatusList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); + break; + } + + i++; + }; + + // refresh data timer + SetTimer(777, (UINT)GetConfig()->get_signed_num(PP_STATUSREFRESHINTERVAL), NULL); + + return TRUE; +} + +void CStatusDlg::EnableControls(bool bEnable) +{ + // enable/disable controls + GetDlgItem(IDC_SET_BUFFERSIZE_BUTTON)->EnableWindow(bEnable); + GetDlgItem(IDC_SET_PRIORITY_BUTTON)->EnableWindow(bEnable); + + if (!bEnable) + { + // get rid of text id disabling + GetDlgItem(IDC_OPERATION_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYOPERATIONTEXT_STRING)); + GetDlgItem(IDC_SOURCE_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYSOURCETEXT_STRING)); + GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYDESTINATIONTEXT_STRING)); + GetDlgItem(IDC_BUFFERSIZE_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYBUFFERSIZETEXT_STRING)); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYPRIORITYTEXT_STRING)); + + const TCHAR *pszText=GetResManager()->LoadString(IDS_EMPTYERRORTEXT_STRING); + m_ctlErrors.GetWindowText(m_strTemp); + if (m_strTemp != pszText) + m_ctlErrors.SetWindowText(pszText); + + GetDlgItem(IDC_PROGRESS_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYPROCESSEDTEXT_STRING)); + GetDlgItem(IDC_TRANSFER_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYTRANSFERTEXT_STRING)); + GetDlgItem(IDC_TIME_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYTIMETEXT_STRING)); + GetDlgItem(IDC_ASSOCIATEDFILES__STATIC)->SetWindowText(GetResManager()->LoadString(IDS_EMPTYASSOCFILE_STRING)); + + m_ctlCurrentProgress.SetPos(0); + } +} + +void CStatusDlg::OnTimer(UINT_PTR nIDEvent) +{ + if (nIDEvent == 777) // refreshing data + { + // turn off timer for some time + KillTimer(777); + + RefreshStatus(); + + // reenable + SetTimer(777, (UINT)GetConfig()->get_signed_num(PP_STATUSREFRESHINTERVAL), NULL); + } + + CLanguageDialog::OnTimer(nIDEvent); +} + +void CStatusDlg::AddTaskInfo(int nPos, CTask *pTask, DWORD dwCurrentTime) +{ + // index to string + _itot(nPos, m_szData, 10); + + // get data snapshot from task + pTask->GetSnapshot(&td); + + // index subitem + lvi.mask=LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; + lvi.iItem=nPos; + lvi.iSubItem=0; + lvi.pszText=td.m_szStatusText; + lvi.cchTextMax=lstrlen(lvi.pszText); + lvi.lParam=reinterpret_cast(pTask); + lvi.iImage=GetImageFromStatus(td.m_uiStatus); + if (nPos < m_ctlStatusList.GetItemCount()) + m_ctlStatusList.SetItem(&lvi); + else + m_ctlStatusList.InsertItem(&lvi); + + // status subitem + lvi.mask=LVIF_TEXT; // zmie� mask� + lvi.iSubItem=1; + m_strTemp=td.m_fi.GetFileName(); + lvi.pszText=m_strTemp.GetBuffer(0); + m_strTemp.ReleaseBuffer(); + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlStatusList.SetItem(&lvi); + + // insert 'file' subitem + lvi.iSubItem=2; + m_strTemp=td.m_pdpDestPath->GetPath(); + lvi.pszText=m_strTemp.GetBuffer(0); + m_strTemp.ReleaseBuffer(); + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlStatusList.SetItem(&lvi); + + // insert dest subitem + lvi.iSubItem=3; + _itot( td.m_nPercent, m_szData, 10 ); + _tcscat(m_szData, _T(" %")); + lvi.pszText=m_szData; + lvi.cchTextMax=lstrlen(lvi.pszText); + m_ctlStatusList.SetItem(&lvi); + + // right side update + if (pTask == pSelectedItem && GetConfig()->get_bool(PP_STATUSSHOWDETAILS)) + { + // data that can be changed by a thread + GetDlgItem(IDC_OPERATION_STATIC)->SetWindowText(td.m_szStatusText); // operation + GetDlgItem(IDC_SOURCE_STATIC)->SetWindowText(td.m_fi.GetFullFilePath()); // src object + + // error message + if ( (td.m_uiStatus & ST_WORKING_MASK) == ST_ERROR ) + { + m_ctlErrors.GetWindowText(m_strTemp); + if (m_strTemp != td.m_strErrorDesc) + m_ctlErrors.SetWindowText(td.m_strErrorDesc); + } + else + { + const TCHAR *pszText=GetResManager()->LoadString(IDS_EMPTYERRORTEXT_STRING); + + m_ctlErrors.GetWindowText(m_strTemp2); + if (m_strTemp2 != pszText) + m_ctlErrors.SetWindowText(pszText); + } + + // count of processed data/overall count of data + _sntprintf(m_szData, _MAX_PATH, _T("%d/%d ("), td.m_iIndex, td.m_iSize); + m_strTemp=CString(m_szData); + m_strTemp+=GetSizeString(td.m_ullProcessedSize, m_szData, _MAX_PATH)+CString(_T("/")); + m_strTemp+=GetSizeString(td.m_ullSizeAll, m_szData, _MAX_PATH)+CString(_T(")")); + _sntprintf(m_szData, _MAX_PATH, _T(" (%s%d/%d)"), GetResManager()->LoadString(IDS_CURRENTPASS_STRING), td.m_ucCurrentCopy, td.m_ucCopies); + m_strTemp+=m_szData; + GetDlgItem(IDC_PROGRESS_STATIC)->SetWindowText(m_strTemp); + + // transfer + if (m_i64LastProcessed == 0) // if first time - show average + m_strTemp=GetSizeString( td.m_lTimeElapsed ? td.m_ullProcessedSize/td.m_lTimeElapsed : 0, m_szData, _MAX_PATH); // last avg + else + if ( (dwCurrentTime-m_dwLastUpdate) != 0) + m_strTemp=GetSizeString( (static_cast(td.m_ullProcessedSize) - static_cast(m_i64LastProcessed))/(static_cast(dwCurrentTime-m_dwLastUpdate)/1000.0), m_szData, _MAX_PATH); + else + m_strTemp=GetSizeString( 0ULL, m_szData, _MAX_PATH); + + // avg transfer + GetDlgItem(IDC_TRANSFER_STATIC)->SetWindowText(m_strTemp+_T("/s (")+CString(GetResManager()->LoadString(IDS_AVERAGEWORD_STRING)) + +CString(GetSizeString(td.m_lTimeElapsed ? td.m_ullProcessedSize/td.m_lTimeElapsed : 0, m_szData, _MAX_PATH))+_T("/s )") + ); + + // elapsed time/estimated time + FormatTime(td.m_lTimeElapsed, m_szTimeBuffer1, 40); + FormatTime( (td.m_ullProcessedSize == 0) ? 0 : static_cast((static_cast<__int64>(td.m_ullSizeAll)*static_cast<__int64>(td.m_lTimeElapsed))/td.m_ullProcessedSize), m_szTimeBuffer2, 40); + + _sntprintf(m_szData, _MAX_PATH, _T("%s / %s"), m_szTimeBuffer1, m_szTimeBuffer2); + GetDlgItem(IDC_TIME_STATIC)->SetWindowText(m_szData); + + // remember current processed data (used for calculating transfer) + m_i64LastProcessed=td.m_ullProcessedSize; + + // set progress + m_ctlCurrentProgress.SetPos(td.m_nPercent); + + SetBufferSizesString(td.m_pbsSizes->m_auiSizes[td.m_iCurrentBufferIndex], td.m_iCurrentBufferIndex); + + // data that can be changed only by user from outside the thread + // refresh only when there are new selected item +// if (pTask != m_pLastSelected) + { + GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(td.m_pdpDestPath->GetPath()); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(td.m_nPriority))); + GetDlgItem(IDC_ASSOCIATEDFILES__STATIC)->SetWindowText(*td.m_pstrUniqueName+_T(".atd (.atp, .log)")); + } + + // refresh m_pLastSelected + m_pLastSelected=pTask; + } +} + +void CStatusDlg::OnSetBuffersizeButton() +{ + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + CBufferSizeDlg dlg; + dlg.m_bsSizes=*pTask->GetBufferSizes(); + dlg.m_iActiveIndex=pTask->GetCurrentBufferIndex(); + if (dlg.DoModal() == IDOK) + { + // if the task has been deleted - skip + if ( pTask != GetSelectedItemPointer() ) + { + TRACE("Task were finished and deleted when trying to change buffer sizes"); + return; + } + + TRACE("bOnlyDefault=%d\n", dlg.m_bsSizes.m_bOnlyDefault); + pTask->SetBufferSizes(&dlg.m_bsSizes); + } +} + +CTask* CStatusDlg::GetSelectedItemPointer() +{ +// TRACE("inside GetSelectedItemPointer()\n"); + // returns ptr to a CTask for a given element in listview + if (m_ctlStatusList.GetSelectedCount() == 1) + { + POSITION pos=m_ctlStatusList.GetFirstSelectedItemPosition(); + int nPos=m_ctlStatusList.GetNextSelectedItem(pos); + CTask* pSelectedItem=reinterpret_cast(m_ctlStatusList.GetItemData(nPos)); +// if (AfxIsValidAddress(pSelectedItem, sizeof(CTask))) + return pSelectedItem; + } +// TRACE("exiting GetSelectedItemPointer()\n"); + + return NULL; +} + +void CStatusDlg::OnRollUnrollButton() +{ + // change settings in config dialog + GetConfig()->set_bool(PP_STATUSSHOWDETAILS, !GetConfig()->get_bool(PP_STATUSSHOWDETAILS)); + + ApplyDisplayDetails(); +} + +void CStatusDlg::ApplyDisplayDetails(bool bInitial) +{ + // get coord of screen and window + CRect rcScreen, rect; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0); + GetWindowRect(&rect); + + bool bDetails=GetConfig()->get_bool(PP_STATUSSHOWDETAILS); + + // stick cause + if (rect.right == rcScreen.right && rect.bottom == rcScreen.bottom) + bInitial=true; + + GetDlgItem(IDC_ROLL_UNROLL_BUTTON)->SetWindowText(bDetails ? _T("<<") : _T(">>")); + + CRect list, progress; + m_ctlProgressAll.GetWindowRect(&progress); + ScreenToClient(&progress); + m_ctlStatusList.GetWindowRect(&list); + ScreenToClient(&list); + + // set dialog size + CRect destRect; + if (!bInitial) + { + destRect.left=0; + destRect.top=0; + destRect.right=bDetails ? progress.right+list.left+3*GetSystemMetrics(SM_CXBORDER) : list.right+list.left+3*GetSystemMetrics(SM_CXBORDER); + destRect.bottom=rect.Height(); + SetWindowPos(NULL, destRect.left, destRect.top, destRect.right, destRect.bottom, SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER); + } + else + { + SetWindowPos(NULL, rcScreen.right-(bDetails ? progress.right+list.left+3*GetSystemMetrics(SM_CXBORDER) : list.right+list.left+3*GetSystemMetrics(SM_CXBORDER)), + rcScreen.bottom-rect.Height(), (bDetails ? progress.right+list.left+3*GetSystemMetrics(SM_CXBORDER) : list.right+list.left+3*GetSystemMetrics(SM_CXBORDER)), + rect.Height(), SWP_NOOWNERZORDER | SWP_NOZORDER); + } +} + +void CStatusDlg::ApplyButtonsState() +{ + // remember ptr to CTask + pSelectedItem=GetSelectedItemPointer(); + bool bShowLog=GetConfig()->get_bool(PP_CMCREATELOG); + + // set status of buttons pause/resume/cancel + if (pSelectedItem != NULL) + { + GetDlgItem(IDC_RESTART_BUTTON)->EnableWindow(true); + GetDlgItem(IDC_SHOW_LOG_BUTTON)->EnableWindow(bShowLog); + GetDlgItem(IDC_DELETE_BUTTON)->EnableWindow(true); + + if (pSelectedItem->GetStatus(ST_STEP_MASK) == ST_FINISHED + || pSelectedItem->GetStatus(ST_STEP_MASK) == ST_CANCELLED) + { + GetDlgItem(IDC_CANCEL_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(false); + } + else + { + // pause/resume + if (pSelectedItem->GetStatus(ST_WORKING_MASK) & ST_PAUSED) + { + GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(true); + } + else + { + GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(true); + if (pSelectedItem->GetStatus(ST_WAITING_MASK) & ST_WAITING) + GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(true); + else + GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(false); + } + + GetDlgItem(IDC_CANCEL_BUTTON)->EnableWindow(true); + } + } + else + { + GetDlgItem(IDC_SHOW_LOG_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_PAUSE_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_RESUME_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_RESTART_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_CANCEL_BUTTON)->EnableWindow(false); + GetDlgItem(IDC_DELETE_BUTTON)->EnableWindow(false); + } +} + +void CStatusDlg::OnSetPriorityButton() +{ + CMenu menu; + HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_PRIORITY_MENU)); + if (!menu.Attach(hMenu)) + { + DestroyMenu(hMenu); + return; + } + + CMenu* pPopup = menu.GetSubMenu(0); + ASSERT(pPopup != NULL); + if(pPopup) + { + // set point in which to set menu + CRect rect; + GetDlgItem(IDC_SET_PRIORITY_BUTTON)->GetWindowRect(&rect); + + pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right+1, rect.top, this); + } +} + +BOOL CStatusDlg::OnCommand(WPARAM wParam, LPARAM lParam) +{ + if (HIWORD(wParam) == 0) + { + if (LOWORD(wParam) >= ID_POPUP_TIME_CRITICAL && LOWORD(wParam) <= ID_POPUP_IDLE) + { + // processing priority + if ( (pSelectedItem=GetSelectedItemPointer()) == NULL ) + return ictranslate::CLanguageDialog::OnCommand(wParam, lParam); + + switch (LOWORD(wParam)) + { + case ID_POPUP_TIME_CRITICAL: + pSelectedItem->SetPriority(THREAD_PRIORITY_TIME_CRITICAL); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_TIME_CRITICAL))); + break; + case ID_POPUP_HIGHEST: + pSelectedItem->SetPriority(THREAD_PRIORITY_HIGHEST); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_HIGHEST))); + break; + case ID_POPUP_ABOVE_NORMAL: + pSelectedItem->SetPriority(THREAD_PRIORITY_ABOVE_NORMAL); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_ABOVE_NORMAL))); + break; + case ID_POPUP_NORMAL: + pSelectedItem->SetPriority(THREAD_PRIORITY_NORMAL); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_NORMAL))); + break; + case ID_POPUP_BELOW_NORMAL: + pSelectedItem->SetPriority(THREAD_PRIORITY_BELOW_NORMAL); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_BELOW_NORMAL))); + break; + case ID_POPUP_LOWEST: + pSelectedItem->SetPriority(THREAD_PRIORITY_LOWEST); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_LOWEST))); + break; + case ID_POPUP_IDLE: + pSelectedItem->SetPriority(THREAD_PRIORITY_IDLE); + GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager()->LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(THREAD_PRIORITY_IDLE))); + break; + } + } + } + return ictranslate::CLanguageDialog::OnCommand(wParam, lParam); +} + +void CStatusDlg::OnPauseButton() +{ + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + TRACE("PauseProcessing call...\n"); + pTask->PauseProcessing(); + + RefreshStatus(); +} + +void CStatusDlg::OnResumeButton() +{ + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + TRACE("ResumeProcessing call "); + if (pTask->GetStatus(ST_WAITING_MASK) & ST_WAITING) + { + TRACE("by setting force flag\n"); + pTask->SetForceFlag(); + } + else + { + TRACE("by function ResumeProcessing\n"); + pTask->ResumeProcessing(); + } + + RefreshStatus(); +} + +void CStatusDlg::OnCancelButton() +{ + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) != NULL ) + { + TRACE("CancelProcessing call...\n"); + pTask->CancelProcessing(); + } + RefreshStatus(); +} + +void CStatusDlg::OnRestartButton() +{ + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + TRACE("RestartProcessing call...\n"); + pTask->RestartProcessing(); + RefreshStatus(); +} + +void CStatusDlg::OnDeleteButton() +{ + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + UINT uiStatus=pTask->GetStatus(ST_STEP_MASK); + if ( (uiStatus & ST_STEP_MASK) != ST_FINISHED && (uiStatus & ST_STEP_MASK) != ST_CANCELLED ) + { + // ask if cancel + if (MsgBox(IDS_CONFIRMCANCEL_STRING, MB_OKCANCEL | MB_ICONQUESTION) == IDOK) + { + // cancel + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + pTask->CancelProcessing(); + } + else + return; + } + + m_pTasks->RemoveFinished(&pTask); + RefreshStatus(); +} + +void CStatusDlg::OnPauseAllButton() +{ + TRACE("Pause All...\n"); + m_pTasks->TasksPauseProcessing(); + RefreshStatus(); +} + +void CStatusDlg::OnStartAllButton() +{ + TRACE("Resume Processing...\n"); + m_pTasks->TasksResumeProcessing(); + RefreshStatus(); +} + +void CStatusDlg::OnRestartAllButton() +{ + TRACE("Restart Processing...\n"); + m_pTasks->TasksRestartProcessing(); + RefreshStatus(); +} + +void CStatusDlg::OnCancelAllButton() +{ + TRACE("Cancel Processing...\n"); + m_pTasks->TasksCancelProcessing(); + RefreshStatus(); +} + +void CStatusDlg::OnRemoveFinishedButton() +{ + m_pTasks->RemoveAllFinished(); + RefreshStatus(); +} + +void CStatusDlg::OnKeydownStatusList(NMHDR* pNMHDR, LRESULT* pResult) +{ + LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; + switch (pLVKeyDow->wVKey) + { + case VK_DELETE: + OnDeleteButton(); + break; + case VK_SPACE: + { + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL ) + return; + + if (pTask->GetStatus(ST_WORKING_MASK) & ST_PAUSED) + OnResumeButton(); + else + OnPauseButton(); + break; + } + } + + *pResult = 0; +} + +int CStatusDlg::GetImageFromStatus(UINT nStatus) +{ + if ( (nStatus & ST_STEP_MASK) == ST_CANCELLED ) + return 4; + if ( (nStatus & ST_STEP_MASK) == ST_FINISHED ) + return 3; + if ( (nStatus & ST_WAITING_MASK) == ST_WAITING ) + return 5; + if ( (nStatus & ST_WORKING_MASK) == ST_PAUSED ) + return 2; + if ( (nStatus & ST_WORKING_MASK) == ST_ERROR ) + return 1; + return 0; +} + +LPTSTR CStatusDlg::FormatTime(long lSeconds, LPTSTR lpszBuffer, size_t stMaxBufferSize) +{ + long lDays=lSeconds/86400; + lSeconds%=86400; + long lHours=lSeconds/3600; + lSeconds%=3600; + long lMinutes=lSeconds/60; + lSeconds%=60; + + if (lDays != 0) + _sntprintf(lpszBuffer, stMaxBufferSize, _T("%02d:%02d:%02d:%02d"), lDays, lHours, lMinutes, lSeconds); + else + if (lHours != 0) + _sntprintf(lpszBuffer, stMaxBufferSize, _T("%02d:%02d:%02d"), lHours, lMinutes, lSeconds); + else + _sntprintf(lpszBuffer, stMaxBufferSize, _T("%02d:%02d"), lMinutes, lSeconds); + + return lpszBuffer; +} + +void CStatusDlg::RefreshStatus() +{ + // remember address of a current selection + pSelectedItem=GetSelectedItemPointer(); + + // current time + DWORD dwCurrentTime=GetTickCount(); + + // get rid of item after the current part + m_ctlStatusList.LimitItems(m_pTasks->GetSize()); + + // add task info + for (int i=0;iGetSize();i++) + AddTaskInfo(i, m_pTasks->GetAt(i), dwCurrentTime); + + // percent + int nPercent=m_pTasks->GetPercent(); + + // set title + if (m_pTasks->GetSize() != 0) + _sntprintf(m_szData, _MAX_PATH, _T("%s [%d %%]"), GetResManager()->LoadString(IDS_STATUSTITLE_STRING), m_pTasks->GetPercent()); + else + _sntprintf(m_szData, _MAX_PATH, _T("%s"), GetResManager()->LoadString(IDS_STATUSTITLE_STRING)); + + // if changed + GetWindowText(m_strTemp); + if (m_strTemp != CString(m_szData)) + SetWindowText(m_szData); + + // refresh overall progress + if (GetConfig()->get_bool(PP_STATUSSHOWDETAILS)) + { + m_ctlProgressAll.SetPos(nPercent); + + // progress - count of processed data/count of data + m_strTemp=GetSizeString(m_pTasks->GetPosition(), m_szData, _MAX_PATH)+CString(_T("/")); + m_strTemp+=GetSizeString(m_pTasks->GetRange(), m_szData, _MAX_PATH); + GetDlgItem(IDC_OVERALL_PROGRESS_STATIC)->SetWindowText(m_strTemp); + + // transfer + if (m_i64LastAllTasksProcessed == 0) + m_i64LastAllTasksProcessed=m_pTasks->GetPosition(); + + if (dwCurrentTime-m_dwLastUpdate != 0) + m_strTemp=GetSizeString( (static_cast(m_pTasks->GetPosition()) - static_cast(m_i64LastAllTasksProcessed))/static_cast(static_cast(dwCurrentTime-m_dwLastUpdate)/1000.0), m_szData, _MAX_PATH); + else + m_strTemp=GetSizeString( 0ULL, m_szData, _MAX_PATH); + + GetDlgItem(IDC_OVERALL_TRANSFER_STATIC)->SetWindowText(m_strTemp+_T("/s")); + m_i64LastAllTasksProcessed=m_pTasks->GetPosition(); + m_dwLastUpdate=dwCurrentTime; + } + + // if selection's missing - hide controls + if (m_ctlStatusList.GetSelectedCount() == 0) + { + EnableControls(false); + m_pLastSelected=NULL; + m_i64LastProcessed=0; + } + else + EnableControls(); // enable controls + + // apply state of the resume, cancel, ... buttons + ApplyButtonsState(); +} + +void CStatusDlg::OnSelectionChanged(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/) +{ + TRACE("Received LVN_CHANGEDSELECTION\n"); + RefreshStatus(); +} + +void CStatusDlg::OnCancel() +{ + PostCloseMessage(); + CLanguageDialog::OnCancel(); +} + +void CStatusDlg::OnAdvancedButton() +{ + CMenu menu; + HMENU hMenu=GetResManager()->LoadMenu(MAKEINTRESOURCE(IDR_ADVANCED_MENU)); + if (!menu.Attach(hMenu)) + { + DestroyMenu(hMenu); + return; + } + + CMenu* pPopup = menu.GetSubMenu(0); + ASSERT(pPopup != NULL); + if(pPopup) + { + // get the point to show menu at + CRect rect; + GetDlgItem(IDC_ADVANCED_BUTTON)->GetWindowRect(&rect); + + pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right+1, rect.top, this); + } +} + +void CStatusDlg::OnPopupReplacePaths() +{ + // check if there's a selection currently + if ( (pSelectedItem=GetSelectedItemPointer()) != NULL ) + { + if (pSelectedItem->GetStatus(ST_WORKING_MASK) & ST_PAUSED) + { + bool bContinue=false; + if (pSelectedItem->GetStatus(ST_WORKING_MASK) == ST_ERROR) + { + pSelectedItem->PauseProcessing(); + bContinue=true; + } + + // assuming here that there's selection and task is paused + CReplacePathsDlg dlg; + dlg.m_pTask=pSelectedItem; + if (dlg.DoModal() == IDOK) + { + // change 'no case' + int iClipboard=pSelectedItem->ReplaceClipboardStrings(dlg.m_strSource, dlg.m_strDest); + + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_REPLACEPATHSTEXT_STRING)); + fmt.SetParam(_t("%count"), iClipboard); + AfxMessageBox(fmt); + } + + // resume if earlier was an error + if (bContinue) + pSelectedItem->ResumeProcessing(); + } + else + MsgBox(IDS_TASKNOTPAUSED_STRING); + } + else + MsgBox(IDS_TASKNOTSELECTED_STRING); +} + +void CStatusDlg::OnShowLogButton() +{ + // show log + CTask* pTask; + if ( (pTask=GetSelectedItemPointer()) == NULL || !GetConfig()->get_bool(PP_CMCREATELOG)) + return; + + // call what's needed + unsigned long lResult=(unsigned long)(ShellExecute(this->m_hWnd, _T("open"), _T("notepad.exe"), + CString(pTask->GetTaskPath())+pTask->GetUniqueName()+_T(".log"), NULL, SW_SHOWNORMAL)); + if (lResult < 32) + { + CString str=CString(pTask->GetTaskPath())+pTask->GetUniqueName()+_T(".log"); + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_SHELLEXECUTEERROR_STRING)); + fmt.SetParam(_t("%errno"), lResult); + fmt.SetParam(_t("%path"), str); + AfxMessageBox(fmt); + } +} + +LRESULT CStatusDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + if (message == WM_UPDATESTATUS) + { + TRACE("Received WM_UPDATESTATUS\n"); + RefreshStatus(); + } + return ictranslate::CLanguageDialog::WindowProc(message, wParam, lParam); +} + +void CStatusDlg::OnStickButton() +{ + ApplyDisplayDetails(true); +} + +void CStatusDlg::SetBufferSizesString(UINT uiValue, int iIndex) +{ + TCHAR szData[1024]; + switch(iIndex) + { + case BI_DEFAULT: + GetResManager()->LoadStringCopy(IDS_BSDEFAULT_STRING, szData, 256); + break; + case BI_ONEDISK: + GetResManager()->LoadStringCopy(IDS_BSONEDISK_STRING, szData, 256); + break; + case BI_TWODISKS: + GetResManager()->LoadStringCopy(IDS_BSTWODISKS_STRING, szData, 256); + break; + case BI_CD: + GetResManager()->LoadStringCopy(IDS_BSCD_STRING, szData, 256); + break; + case BI_LAN: + GetResManager()->LoadStringCopy(IDS_BSLAN_STRING, szData, 256); + break; + default: + _ASSERTE(false); + szData[0] = _T('\0'); + } + + _tcscat(szData, GetSizeString((ull_t)uiValue, m_szData, _MAX_PATH)); + + GetDlgItem(IDC_BUFFERSIZE_STATIC)->SetWindowText(szData); +} + +void CStatusDlg::PostCloseMessage() +{ + GetParent()->PostMessage(WM_STATUSCLOSING); +} + +void CStatusDlg::OnLanguageChanged() +{ + // remove all columns + int iCnt=m_ctlStatusList.GetHeaderCtrl()->GetItemCount(); + + // Delete all of the columns. + for (int i=0;iLoadString(IDS_COLUMNSTATUS_STRING); /*_T("Status")*/; + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.27*iWidth); + lvc.iSubItem=-1; + m_ctlStatusList.InsertColumn(1, &lvc); + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNSOURCE_STRING);/*_T("File");*/ + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.3*iWidth); + lvc.iSubItem=0; + m_ctlStatusList.InsertColumn(2, &lvc); + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNDESTINATION_STRING);/*_T("To:");*/ + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.27*iWidth); + lvc.iSubItem=1; + m_ctlStatusList.InsertColumn(3, &lvc); + + lvc.pszText=(PTSTR)GetResManager()->LoadString(IDS_COLUMNPROGRESS_STRING);/*_T("Progress");*/ + lvc.cchTextMax = lstrlen(lvc.pszText); + lvc.cx = static_cast(0.15*iWidth); + lvc.iSubItem=2; + m_ctlStatusList.InsertColumn(4, &lvc); + + RefreshStatus(); +} Index: src/ch/StatusDlg.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/StatusDlg.h (.../StatusDlg.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/StatusDlg.h (.../StatusDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,125 +1,125 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STATUSDLG_H__ -#define __STATUSDLG_H__ - -#include "structs.h" -#include "FFListCtrl.h" - -#define WM_UPDATESTATUS WM_USER+6 -#define WM_STATUSCLOSING WM_USER+12 - -///////////////////////////////////////////////////////////////////////////// -// CStatusDlg dialog -class CStatusDlg : public ictranslate::CLanguageDialog -{ -// Construction -public: - CStatusDlg(CTaskArray* pTasks, CWnd* pParent = NULL); // standard constructor - ~CStatusDlg(); - void PostCloseMessage(); - void SetBufferSizesString(UINT uiValue, int iIndex); - void RefreshStatus(); - LPTSTR FormatTime(long lSeconds, LPTSTR lpszBuffer, size_t stMaxBufferSize); - int GetImageFromStatus(UINT nStatus); - - void ApplyButtonsState(); - void ApplyDisplayDetails(bool bInitial=false); - CTask* GetSelectedItemPointer(); - - void AddTaskInfo(int nPos, CTask *pTask, DWORD dwCurrentTime); - void EnableControls(bool bEnable=true); - - CTaskArray* m_pTasks; - CTask* pSelectedItem; - const CTask *m_pLastSelected; - const CTask* m_pInitialSelection; - - TCHAR m_szData[_MAX_PATH]; - TCHAR m_szTimeBuffer1[40]; - TCHAR m_szTimeBuffer2[40]; - - __int64 m_i64LastProcessed; - __int64 m_i64LastAllTasksProcessed; - DWORD m_dwLastUpdate; - - LVITEM lvi; - TASK_DISPLAY_DATA td; - CString m_strTemp, m_strTemp2; - - CImageList m_images; - - static bool m_bLock; // locker - -// Dialog Data - //{{AFX_DATA(CStatusDlg) - enum { IDD = IDD_STATUS_DIALOG }; - CEdit m_ctlErrors; - CProgressCtrl m_ctlCurrentProgress; - CFFListCtrl m_ctlStatusList; - CProgressCtrl m_ctlProgressAll; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CStatusDlg) - public: - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - //}}AFX_VIRTUAL - -// Implementation -protected: - virtual void OnLanguageChanged(); - - // Generated message map functions - //{{AFX_MSG(CStatusDlg) - virtual BOOL OnInitDialog(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - afx_msg void OnPauseButton(); - afx_msg void OnCancelButton(); - afx_msg void OnRollUnrollButton(); - afx_msg void OnSetPriorityButton(); - afx_msg void OnSetBuffersizeButton(); - afx_msg void OnStartAllButton(); - afx_msg void OnRestartButton(); - afx_msg void OnDeleteButton(); - afx_msg void OnPauseAllButton(); - afx_msg void OnRestartAllButton(); - afx_msg void OnCancelAllButton(); - afx_msg void OnRemoveFinishedButton(); - afx_msg void OnKeydownStatusList(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnSelectionChanged(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/); - virtual void OnCancel(); - afx_msg void OnAdvancedButton(); - afx_msg void OnPopupReplacePaths(); - afx_msg void OnShowLogButton(); - afx_msg void OnStickButton(); - afx_msg void OnResumeButton(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STATUSDLG_H__ +#define __STATUSDLG_H__ + +#include "structs.h" +#include "FFListCtrl.h" + +#define WM_UPDATESTATUS WM_USER+6 +#define WM_STATUSCLOSING WM_USER+12 + +///////////////////////////////////////////////////////////////////////////// +// CStatusDlg dialog +class CStatusDlg : public ictranslate::CLanguageDialog +{ +// Construction +public: + CStatusDlg(CTaskArray* pTasks, CWnd* pParent = NULL); // standard constructor + ~CStatusDlg(); + void PostCloseMessage(); + void SetBufferSizesString(UINT uiValue, int iIndex); + void RefreshStatus(); + LPTSTR FormatTime(long lSeconds, LPTSTR lpszBuffer, size_t stMaxBufferSize); + int GetImageFromStatus(UINT nStatus); + + void ApplyButtonsState(); + void ApplyDisplayDetails(bool bInitial=false); + CTask* GetSelectedItemPointer(); + + void AddTaskInfo(int nPos, CTask *pTask, DWORD dwCurrentTime); + void EnableControls(bool bEnable=true); + + CTaskArray* m_pTasks; + CTask* pSelectedItem; + const CTask *m_pLastSelected; + const CTask* m_pInitialSelection; + + TCHAR m_szData[_MAX_PATH]; + TCHAR m_szTimeBuffer1[40]; + TCHAR m_szTimeBuffer2[40]; + + __int64 m_i64LastProcessed; + __int64 m_i64LastAllTasksProcessed; + DWORD m_dwLastUpdate; + + LVITEM lvi; + TASK_DISPLAY_DATA td; + CString m_strTemp, m_strTemp2; + + CImageList m_images; + + static bool m_bLock; // locker + +// Dialog Data + //{{AFX_DATA(CStatusDlg) + enum { IDD = IDD_STATUS_DIALOG }; + CEdit m_ctlErrors; + CProgressCtrl m_ctlCurrentProgress; + CFFListCtrl m_ctlStatusList; + CProgressCtrl m_ctlProgressAll; + //}}AFX_DATA + + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CStatusDlg) + public: + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + //}}AFX_VIRTUAL + +// Implementation +protected: + virtual void OnLanguageChanged(); + + // Generated message map functions + //{{AFX_MSG(CStatusDlg) + virtual BOOL OnInitDialog(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + afx_msg void OnPauseButton(); + afx_msg void OnCancelButton(); + afx_msg void OnRollUnrollButton(); + afx_msg void OnSetPriorityButton(); + afx_msg void OnSetBuffersizeButton(); + afx_msg void OnStartAllButton(); + afx_msg void OnRestartButton(); + afx_msg void OnDeleteButton(); + afx_msg void OnPauseAllButton(); + afx_msg void OnRestartAllButton(); + afx_msg void OnCancelAllButton(); + afx_msg void OnRemoveFinishedButton(); + afx_msg void OnKeydownStatusList(NMHDR* pNMHDR, LRESULT* pResult); + afx_msg void OnSelectionChanged(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/); + virtual void OnCancel(); + afx_msg void OnAdvancedButton(); + afx_msg void OnPopupReplacePaths(); + afx_msg void OnShowLogButton(); + afx_msg void OnStickButton(); + afx_msg void OnResumeButton(); + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +}; + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/Stdafx.h =================================================================== diff -u -rac7af753315c3538300a7c7966bbf0abb7b4f3c4 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Stdafx.h (.../Stdafx.h) (revision ac7af753315c3538300a7c7966bbf0abb7b4f3c4) +++ src/ch/Stdafx.h (.../Stdafx.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,49 +1,49 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STDAFX_H__ -#define __STDAFX_H__ - -#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers - -#include // MFC core and standard components -#include // MFC extensions -#ifndef _AFX_NO_AFXCMN_SUPPORT -#include // MFC support for Windows Common Controls -#endif // _AFX_NO_AFXCMN_SUPPORT -#include "afxmt.h" - -#pragma warning (disable: 4711) -#include "debug.h" -#include "../libicpf/file.h" -#include "../libictranslate/LanguageDialog.h" -#include - -#ifdef _UNICODE -#if defined _M_IX86 -#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") -#elif defined _M_IA64 -#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") -#elif defined _M_X64 -#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") -#else -#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") -#endif -#endif - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STDAFX_H__ +#define __STDAFX_H__ + +#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers + +#include // MFC core and standard components +#include // MFC extensions +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC support for Windows Common Controls +#endif // _AFX_NO_AFXCMN_SUPPORT +#include "afxmt.h" + +#pragma warning (disable: 4711) +#include "debug.h" +#include "../libicpf/file.h" +#include "../libictranslate/LanguageDialog.h" +#include + +#ifdef _UNICODE +#if defined _M_IX86 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_IA64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + +#endif Index: src/ch/StringHelpers.cpp =================================================================== diff -u -rd6da900f71c2fb7f65e7443baf279c7f626d057d -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/StringHelpers.cpp (.../StringHelpers.cpp) (revision d6da900f71c2fb7f65e7443baf279c7f626d057d) +++ src/ch/StringHelpers.cpp (.../StringHelpers.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,76 +1,76 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" -#include "StringHelpers.h" -#include "stdio.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#ifdef _MFC_VER -void ExpandFormatString(CString* pstrFmt, DWORD dwError) -{ - // replace strings %errnum & %errdesc to something else - TCHAR xx[_MAX_PATH]; - pstrFmt->Replace(_T("%errnum"), _itot(dwError, xx, 10)); - - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, xx, _MAX_PATH, NULL); - - while (xx[_tcslen(xx)-1] == _T('\n') || xx[_tcslen(xx)-1] == _T('\r')) - xx[_tcslen(xx)-1] = _T('\0'); - - pstrFmt->Replace(_T("%errdesc"), xx); -} -#endif - -LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize) -{ - if (dData < 0.0) - dData=0.0; - - if (dData < 1200.0) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), dData, GetResManager()->LoadString(IDS_BYTE_STRING)); - else if (dData < 1228800.0) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1024.0, GetResManager()->LoadString(IDS_KBYTE_STRING)); - else if (dData < 1258291200.0) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1048576.0, GetResManager()->LoadString(IDS_MBYTE_STRING)); - else - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1073741824.0, GetResManager()->LoadString(IDS_GBYTE_STRING)); - - return pszBuffer; -} - -LPTSTR GetSizeString(ull_t ullData, LPTSTR pszBuffer, size_t stMaxBufferSize, bool bStrict) -{ - if (ullData < 0) - ullData=0; - - if (ullData >= 1258291200 && (!bStrict || (ullData % 1073741824) == 0)) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), (double)(ullData/1073741824.0), GetResManager()->LoadString(IDS_GBYTE_STRING)); - else if (ullData >= 1228800 && (!bStrict || (ullData % 1048576) == 0)) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), (double)(ullData/1048576.0), GetResManager()->LoadString(IDS_MBYTE_STRING)); - else if (ullData >= 1200 && (!bStrict || (ullData % 1024) == 0)) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), (double)(ullData/1024.0), GetResManager()->LoadString(IDS_KBYTE_STRING)); - else - _sntprintf(pszBuffer, stMaxBufferSize, _T("%I64u %s"), ullData, GetResManager()->LoadString(IDS_BYTE_STRING)); - - return pszBuffer; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" +#include "StringHelpers.h" +#include "stdio.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#ifdef _MFC_VER +void ExpandFormatString(CString* pstrFmt, DWORD dwError) +{ + // replace strings %errnum & %errdesc to something else + TCHAR xx[_MAX_PATH]; + pstrFmt->Replace(_T("%errnum"), _itot(dwError, xx, 10)); + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, xx, _MAX_PATH, NULL); + + while (xx[_tcslen(xx)-1] == _T('\n') || xx[_tcslen(xx)-1] == _T('\r')) + xx[_tcslen(xx)-1] = _T('\0'); + + pstrFmt->Replace(_T("%errdesc"), xx); +} +#endif + +LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize) +{ + if (dData < 0.0) + dData=0.0; + + if (dData < 1200.0) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), dData, GetResManager()->LoadString(IDS_BYTE_STRING)); + else if (dData < 1228800.0) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1024.0, GetResManager()->LoadString(IDS_KBYTE_STRING)); + else if (dData < 1258291200.0) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1048576.0, GetResManager()->LoadString(IDS_MBYTE_STRING)); + else + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1073741824.0, GetResManager()->LoadString(IDS_GBYTE_STRING)); + + return pszBuffer; +} + +LPTSTR GetSizeString(ull_t ullData, LPTSTR pszBuffer, size_t stMaxBufferSize, bool bStrict) +{ + if (ullData < 0) + ullData=0; + + if (ullData >= 1258291200 && (!bStrict || (ullData % 1073741824) == 0)) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), (double)(ullData/1073741824.0), GetResManager()->LoadString(IDS_GBYTE_STRING)); + else if (ullData >= 1228800 && (!bStrict || (ullData % 1048576) == 0)) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), (double)(ullData/1048576.0), GetResManager()->LoadString(IDS_MBYTE_STRING)); + else if (ullData >= 1200 && (!bStrict || (ullData % 1024) == 0)) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), (double)(ullData/1024.0), GetResManager()->LoadString(IDS_KBYTE_STRING)); + else + _sntprintf(pszBuffer, stMaxBufferSize, _T("%I64u %s"), ullData, GetResManager()->LoadString(IDS_BYTE_STRING)); + + return pszBuffer; +} Index: src/ch/StringHelpers.h =================================================================== diff -u -rd6da900f71c2fb7f65e7443baf279c7f626d057d -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/StringHelpers.h (.../StringHelpers.h) (revision d6da900f71c2fb7f65e7443baf279c7f626d057d) +++ src/ch/StringHelpers.h (.../StringHelpers.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,30 +1,30 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STRINGHELPERS_H__ -#define __STRINGHELPERS_H__ - -// formatting routines -#ifdef _MFC_VER -void ExpandFormatString(CString* pstrFmt, DWORD dwError); -#endif - -LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize); -LPTSTR GetSizeString(ull_t ullData, LPTSTR pszBuffer, size_t stMaxBufferSize, bool bStrict = false); - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STRINGHELPERS_H__ +#define __STRINGHELPERS_H__ + +// formatting routines +#ifdef _MFC_VER +void ExpandFormatString(CString* pstrFmt, DWORD dwError); +#endif + +LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize); +LPTSTR GetSizeString(ull_t ullData, LPTSTR pszBuffer, size_t stMaxBufferSize, bool bStrict = false); + +#endif Index: src/ch/Structs.cpp =================================================================== diff -u -r09d557ffefb1dd57e7606695e16c3151e42285f2 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Structs.cpp (.../Structs.cpp) (revision 09d557ffefb1dd57e7606695e16c3151e42285f2) +++ src/ch/Structs.cpp (.../Structs.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,1663 +1,1663 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "structs.h" -#include "resource.h" -#include "StringHelpers.h" -#include "..\common\FileSupport.h" -#include "ch.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -// global -int PriorityToIndex(int nPriority) -{ - switch(nPriority) - { - case THREAD_PRIORITY_TIME_CRITICAL: - return 0; - case THREAD_PRIORITY_HIGHEST: - return 1; - case THREAD_PRIORITY_ABOVE_NORMAL: - return 2; - case THREAD_PRIORITY_NORMAL: - return 3; - case THREAD_PRIORITY_BELOW_NORMAL: - return 4; - case THREAD_PRIORITY_LOWEST: - return 5; - case THREAD_PRIORITY_IDLE: - return 6; - default: - return 3; - } -} - -int IndexToPriority(int nIndex) -{ - switch(nIndex) - { - case 0: - return THREAD_PRIORITY_TIME_CRITICAL; - case 1: - return THREAD_PRIORITY_HIGHEST; - case 2: - return THREAD_PRIORITY_ABOVE_NORMAL; - case 3: - return THREAD_PRIORITY_NORMAL; - case 4: - return THREAD_PRIORITY_BELOW_NORMAL; - case 5: - return THREAD_PRIORITY_LOWEST; - case 6: - return THREAD_PRIORITY_IDLE; - default: - return THREAD_PRIORITY_NORMAL; - } -} - -int IndexToPriorityClass(int iIndex) -{ - switch(iIndex) - { - case 0: - return IDLE_PRIORITY_CLASS; - case 1: - return NORMAL_PRIORITY_CLASS; - case 2: - return HIGH_PRIORITY_CLASS; - case 3: - return REALTIME_PRIORITY_CLASS; - default: - return NORMAL_PRIORITY_CLASS; - } -} - -int PriorityClassToIndex(int iPriority) -{ - switch(iPriority) - { - case IDLE_PRIORITY_CLASS: - return 0; - case NORMAL_PRIORITY_CLASS: - return 1; - case HIGH_PRIORITY_CLASS: - return 2; - case REALTIME_PRIORITY_CLASS: - return 3; - default: - return 1; - } -} - -//////////////////////////////////////////////////////////////////////////// -// CTask members - -CTask::CTask(chcore::IFeedbackHandler* piFeedbackHandler, const TASK_CREATE_DATA *pCreateData) : - m_log(), - m_piFeedbackHandler(piFeedbackHandler) -{ - BOOST_ASSERT(piFeedbackHandler); - - m_nCurrentIndex=0; - m_iLastProcessedIndex=-1; - m_nStatus=ST_NULL_STATUS; - m_bsSizes.m_uiDefaultSize=65536; - m_bsSizes.m_uiOneDiskSize=4194304; - m_bsSizes.m_uiTwoDisksSize=262144; - m_bsSizes.m_uiCDSize=262144; - m_bsSizes.m_uiLANSize=65536; - m_pThread=NULL; - m_nPriority=THREAD_PRIORITY_NORMAL; - m_nProcessed=0; - m_nAll=0; - m_pnTasksProcessed=pCreateData->pTasksProcessed; - m_pnTasksAll=pCreateData->pTasksAll; - m_bKill=false; - m_bKilled=true; - m_pcs=pCreateData->pcs; - m_pfnTaskProc=pCreateData->pfnTaskProc; - m_lTimeElapsed=0; - m_lLastTime=-1; - m_puiOperationsPending=pCreateData->puiOperationsPending; - m_bQueued=false; - m_ucCopies=1; - m_ucCurrentCopy=0; - m_files.Init(&m_clipboard); - m_uiResumeInterval=0; - m_plFinished=pCreateData->plFinished; - m_bForce=false; - m_bContinue=false; - m_bSaved=false; - - m_iIdentical=-1; - m_iDestinationLess=-1; - m_iDestinationGreater=-1; - m_iMissingInput=-1; - m_iOutputError=-1; - m_iMoveFile=-1; - - TCHAR xx[16]; - _itot((int)time(NULL), xx, 10); - m_strUniqueName=xx; -} - -CTask::~CTask() -{ - KillThread(); - if(m_piFeedbackHandler) - m_piFeedbackHandler->Delete(); -} - -// m_clipboard -int CTask::AddClipboardData(CClipboardEntry* pEntry) -{ - m_cs.Lock(); - int retval=m_clipboard.Add(pEntry); - m_cs.Unlock(); - - return retval; -} - -CClipboardEntry* CTask::GetClipboardData(int nIndex) -{ - m_cs.Lock(); - CClipboardEntry* pEntry=m_clipboard.GetAt(nIndex); - m_cs.Unlock(); - - return pEntry; -} - -int CTask::GetClipboardDataSize() -{ - m_cs.Lock(); - int rv=m_clipboard.GetSize(); - m_cs.Unlock(); - - return rv; -} - -int CTask::ReplaceClipboardStrings(CString strOld, CString strNew) -{ - // small chars to make comparing case insensitive - strOld.MakeLower(); - - CString strText; - int iOffset; - int iCount=0; - m_cs.Lock(); - for (int i=0;iGetPath(); - strText.MakeLower(); - iOffset=strText.Find(strOld, 0); - if (iOffset != -1) - { - // found - strText=pEntry->GetPath(); - strText=strText.Left(iOffset)+strNew+strText.Mid(iOffset+strOld.GetLength()); - pEntry->SetPath(strText); - iCount++; - } - } - m_cs.Unlock(); - - return iCount; -} - -// m_files -int CTask::FilesAddDir(const CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, - const bool bRecurse, const bool bIncludeDirs) -{ - // this uses much of memory, but resolves problem critical section hungs and m_bKill - CFileInfoArray fa; - fa.Init(&m_clipboard); - - fa.AddDir(strDirName, pFilters, iSrcIndex, bRecurse, bIncludeDirs, &m_bKill); - - m_cs.Lock(); - - m_files.Append(fa); - - m_cs.Unlock(); - - return 0; -} - -int CTask::FilesAdd(CFileInfo fi) -{ - int rv=-1; - m_cs.Lock(); - if (fi.IsDirectory() || m_afFilters.Match(fi)) - rv=m_files.Add(fi); - m_cs.Unlock(); - - return rv; -} - -CFileInfo CTask::FilesGetAt(int nIndex) -{ - m_cs.Lock(); - CFileInfo info=m_files.GetAt(nIndex); - m_cs.Unlock(); - - return info; -} - -CFileInfo& CTask::FilesGetAtCurrentIndex() -{ - m_cs.Lock(); - CFileInfo& info=m_files.GetAt(m_nCurrentIndex); - m_cs.Unlock(); - return info; -} - -void CTask::FilesRemoveAll() -{ - m_cs.Lock(); - m_files.RemoveAll(); - m_cs.Unlock(); -} - -int CTask::FilesGetSize() -{ - m_cs.Lock(); - int nSize=m_files.GetSize(); - m_cs.Unlock(); - - return nSize; -} - -// m_nCurrentIndex -void CTask::IncreaseCurrentIndex() -{ - m_cs.Lock(); - ++m_nCurrentIndex; - m_cs.Unlock(); -} - -int CTask::GetCurrentIndex() -{ - m_cs.Lock(); - int nIndex=m_nCurrentIndex; - m_cs.Unlock(); - - return nIndex; -} - -void CTask::SetCurrentIndex(int nIndex) -{ - m_cs.Lock(); - m_nCurrentIndex=nIndex; - m_cs.Unlock(); -} - -// m_strDestPath - adds '\\' -void CTask::SetDestPath(LPCTSTR lpszPath) -{ - m_dpDestPath.SetPath(lpszPath); -} - -// guaranteed '\\' -const CDestPath& CTask::GetDestPath() -{ - return m_dpDestPath; -} - -int CTask::GetDestDriveNumber() -{ - return m_dpDestPath.GetDriveNumber(); -} - -// m_nStatus -void CTask::SetStatus(UINT nStatus, UINT nMask) -{ - m_cs.Lock(); - m_nStatus &= ~nMask; - m_nStatus |= nStatus; - m_cs.Unlock(); -} - -UINT CTask::GetStatus(UINT nMask) -{ - m_cs.Lock(); - UINT nStatus=m_nStatus; - m_cs.Unlock(); - - return (nStatus & nMask); -} - -// m_nBufferSize -void CTask::SetBufferSizes(const BUFFERSIZES* bsSizes) -{ - m_cs.Lock(); - m_bsSizes=*bsSizes; - m_bSaved=false; - m_cs.Unlock(); -} - -const BUFFERSIZES* CTask::GetBufferSizes() -{ - m_cs.Lock(); - const BUFFERSIZES* pbsSizes=&m_bsSizes; - m_cs.Unlock(); - - return pbsSizes; -} - -int CTask::GetCurrentBufferIndex() -{ - int rv=0; - m_cs.Lock(); - int iSize=m_files.GetSize(); - if (iSize > 0 && m_nCurrentIndex != -1) - rv=m_bsSizes.m_bOnlyDefault ? 0 : m_files.GetAt((m_nCurrentIndex < iSize) ? m_nCurrentIndex : 0).GetBufferIndex(); - m_cs.Unlock(); - - return rv; -} - -// m_pThread -// m_nPriority -int CTask::GetPriority() -{ - m_cs.Lock(); - int nPriority=m_nPriority; - m_cs.Unlock(); - return nPriority; -} - -void CTask::SetPriority(int nPriority) -{ - m_cs.Lock(); - m_nPriority=nPriority; - m_bSaved=false; - if (m_pThread != NULL) - { - TRACE("Changing thread priority"); - m_pThread->SuspendThread(); - m_pThread->SetThreadPriority(nPriority); - m_pThread->ResumeThread(); - } - m_cs.Unlock(); -} - -// m_nProcessed -void CTask::IncreaseProcessedSize(__int64 nSize) -{ - m_cs.Lock(); - m_nProcessed+=nSize; - m_cs.Unlock(); -} - -void CTask::SetProcessedSize(__int64 nSize) -{ - m_cs.Lock(); - m_nProcessed=nSize; - m_cs.Unlock(); -} - -__int64 CTask::GetProcessedSize() -{ - m_cs.Lock(); - __int64 nSize=m_nProcessed; - m_cs.Unlock(); - - return nSize; -} - -// m_nAll -void CTask::SetAllSize(__int64 nSize) -{ - m_cs.Lock(); - m_nAll=nSize; - m_cs.Unlock(); -} - -__int64 CTask::GetAllSize() -{ - m_cs.Lock(); - __int64 nAll=m_nAll; - m_cs.Unlock(); - - return nAll; -} - -void CTask::CalcAllSize() -{ - m_cs.Lock(); - m_nAll=0; - - int nSize=m_files.GetSize(); - CFileInfo* pFiles=m_files.GetData(); - - for (int i=0;iLock(); - (*m_pnTasksProcessed)+=nSize; - m_pcs->Unlock(); -// m_cs.Unlock(); -} - -void CTask::DecreaseProcessedTasksSize(__int64 nSize) -{ -// m_cs.Lock(); - m_pcs->Lock(); - (*m_pnTasksProcessed)-=nSize; - m_pcs->Unlock(); -// m_cs.Unlock(); -} - -// m_pnTasksAll -void CTask::IncreaseAllTasksSize(__int64 nSize) -{ -// m_cs.Lock(); - m_pcs->Lock(); - (*m_pnTasksAll)+=nSize; - m_pcs->Unlock(); -// m_cs.Unlock(); -} - -void CTask::DecreaseAllTasksSize(__int64 nSize) -{ -// m_cs.Lock(); - m_pcs->Lock(); - (*m_pnTasksAll)-=nSize; - m_pcs->Unlock(); -// m_cs.Unlock(); -} - -// m_bKill -/*inline*/ void CTask::SetKillFlag(bool bKill) -{ - m_cs.Lock(); - m_bKill=bKill; - m_cs.Unlock(); -} - -bool CTask::GetKillFlag() -{ - m_cs.Lock(); - bool bKill=m_bKill; - m_cs.Unlock(); - - return bKill; -} - -// m_bKilled -/*inline*/ void CTask::SetKilledFlag(bool bKilled) -{ - m_cs.Lock(); - m_bKilled=bKilled; - m_cs.Unlock(); -} - -/*inline*/ bool CTask::GetKilledFlag() -{ - m_cs.Lock(); - bool bKilled=m_bKilled; - m_cs.Unlock(); - - return bKilled; -} - -// m_strUniqueName - -CString CTask::GetUniqueName() -{ - m_cs.Lock(); - CString name=m_strUniqueName; - m_cs.Unlock(); - - return name; -} - -void CTask::Load(icpf::archive& ar, bool bData) -{ - m_cs.Lock(); - try - { - if (bData) - { - m_clipboard.Serialize(ar, bData); - - m_files.Load(ar, false); - m_dpDestPath.Serialize(ar); - ar>>m_strUniqueName; - m_afFilters.Serialize(ar); - ar>>m_ucCopies; - } - else - { - int data; - unsigned long part; - - ar>>data; - m_nCurrentIndex=data; - ar>>data; - m_nStatus=data; - ar>>m_lOsError; - ar>>m_strErrorDesc; - m_bsSizes.Serialize(ar); - ar>>m_nPriority; - - ar>>part; - m_nAll=(static_cast(part) << 32); - ar>>part; - m_nAll|=part; - // czas - ar>>m_lTimeElapsed; - - ar>>part; - m_nProcessed=(static_cast(part) << 32); - ar>>part; - m_nProcessed|=part; - - ar>>m_ucCurrentCopy; - - m_clipboard.Serialize(ar, bData); - m_files.Load(ar, true); - - unsigned char ucTmp; - ar>>ucTmp; - m_bSaved=ucTmp != 0; - } - } - catch(icpf::exception&) - { - m_cs.Unlock(); - throw; - } - m_cs.Unlock(); -} - -void CTask::Store(bool bData) -{ - m_cs.Lock(); - BOOST_ASSERT(!m_strTaskBasePath.empty()); - if(m_strTaskBasePath.empty()) - { - m_cs.Unlock(); - THROW(_t("Missing task path."), 0, 0, 0); - } - if (!bData && m_bSaved) - { - m_cs.Unlock(); - TRACE("Saving locked - file not saved\n"); - return; - } - - if (!bData && !m_bSaved && ( (m_nStatus & ST_STEP_MASK) == ST_FINISHED || (m_nStatus & ST_STEP_MASK) == ST_CANCELLED - || (m_nStatus & ST_WORKING_MASK) == ST_PAUSED )) - { - TRACE("Last save - saving blocked\n"); - m_bSaved=true; - } - - try - { - CString strPath = m_strTaskBasePath.c_str() + GetUniqueName()+( (bData) ? _T(".atd") : _T(".atp") ); - icpf::archive ar; - ar.open(strPath, FA_WRITE | FA_CREATE | FA_TRUNCATE); - ar.datablock_begin(); - - if (bData) - { - m_clipboard.Serialize(ar, bData); - - if (GetStatus(ST_STEP_MASK) > ST_SEARCHING) - m_files.Store(ar, false); - else - ar<(0); - - m_dpDestPath.Serialize(ar); - ar<((m_nAll & 0xffffffff00000000) >> 32); - ar<(m_nAll & 0x00000000ffffffff); - ar<((m_nProcessed & 0xffffffff00000000) >> 32); - ar<(m_nProcessed & 0x00000000ffffffff); - ar< ST_SEARCHING) - m_files.Store(ar, true); - else - ar<(0); - ar<<(unsigned char)m_bSaved; - } - ar.datablock_end(); - ar.close(); - } - catch(icpf::exception& /*e*/) - { - m_cs.Unlock(); - return; - } - m_cs.Unlock(); -} - -/*inline*/ void CTask::KillThread() -{ - if (!GetKilledFlag()) // protection from recalling Cleanup - { - SetKillFlag(); - while (!GetKilledFlag()) - Sleep(10); - - // cleanup - CleanupAfterKill(); - } -} - -void CTask::BeginProcessing() -{ - m_cs.Lock(); - if (m_pThread != NULL) - { - m_cs.Unlock(); - return; - } - m_cs.Unlock(); - - // create new thread - m_uiResumeInterval=0; // just in case - m_bSaved=false; // save - SetKillFlag(false); - SetKilledFlag(false); - CWinThread* pThread=AfxBeginThread(m_pfnTaskProc, this, GetPriority()); - - m_cs.Lock(); - m_pThread=pThread; - m_cs.Unlock(); -} - -void CTask::ResumeProcessing() -{ - // the same as retry but less demanding - if ( (GetStatus(ST_WORKING_MASK) & ST_PAUSED) && GetStatus(ST_STEP_MASK) != ST_FINISHED - && GetStatus(ST_STEP_MASK) != ST_CANCELLED) - { - SetStatus(0, ST_ERROR); - BeginProcessing(); - } -} - -bool CTask::RetryProcessing(bool bOnlyErrors/*=false*/, UINT uiInterval) -{ - // retry used to auto-resume, after loading - if ( (GetStatus(ST_WORKING_MASK) == ST_ERROR || (!bOnlyErrors && GetStatus(ST_WORKING_MASK) != ST_PAUSED)) - && GetStatus(ST_STEP_MASK) != ST_FINISHED && GetStatus(ST_STEP_MASK) != ST_CANCELLED) - { - if (uiInterval != 0) - { - m_uiResumeInterval+=uiInterval; - if (m_uiResumeInterval < (UINT)GetConfig()->get_signed_num(PP_CMAUTORETRYINTERVAL)) - return false; - else - m_uiResumeInterval=0; - } - - SetStatus(0, ST_ERROR); - BeginProcessing(); - return true; - } - return false; -} - -void CTask::RestartProcessing() -{ - KillThread(); - SetStatus(0, ST_ERROR); - SetStatus(ST_NULL_STATUS, ST_STEP_MASK); - m_lTimeElapsed=0; - SetCurrentIndex(0); - SetCurrentCopy(0); - BeginProcessing(); -} - -void CTask::PauseProcessing() -{ - if (GetStatus(ST_STEP_MASK) != ST_FINISHED && GetStatus(ST_STEP_MASK) != ST_CANCELLED) - { - KillThread(); - SetStatus(ST_PAUSED, ST_WORKING_MASK); - SetLastProcessedIndex(GetCurrentIndex()); - m_bSaved=false; - } -} - -void CTask::CancelProcessing() -{ - // change to ST_CANCELLED - if (GetStatus(ST_STEP_MASK) != ST_FINISHED) - { - KillThread(); - SetStatus(ST_CANCELLED, ST_STEP_MASK); - SetStatus(0, ST_ERROR); - m_bSaved=false; - } -} - -void CTask::GetMiniSnapshot(TASK_MINI_DISPLAY_DATA *pData) -{ - m_cs.Lock(); - if (m_nCurrentIndex >= 0 && m_nCurrentIndex < m_files.GetSize()) - pData->m_fi=m_files.GetAt(m_nCurrentIndex); - else - { - if (m_files.GetSize() > 0) - { - pData->m_fi=m_files.GetAt(0); - pData->m_fi.SetFilePath(pData->m_fi.GetFullFilePath()); - pData->m_fi.SetSrcIndex(-1); - } - else - { - if (m_clipboard.GetSize() > 0) - { - pData->m_fi.SetFilePath(m_clipboard.GetAt(0)->GetPath()); - pData->m_fi.SetSrcIndex(-1); - } - else - { - pData->m_fi.SetFilePath(GetResManager()->LoadString(IDS_NONEINPUTFILE_STRING)); - pData->m_fi.SetSrcIndex(-1); - } - } - } - - pData->m_uiStatus=m_nStatus; - - // percents - int iSize=m_files.GetSize()*m_ucCopies; - int iIndex=m_nCurrentIndex+m_ucCurrentCopy*m_files.GetSize(); - if (m_nAll != 0 && !((m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_CONTENT)) - pData->m_nPercent=static_cast( (static_cast(m_nProcessed)*100.0)/static_cast(m_nAll) ); - else - if (iSize != 0) - pData->m_nPercent=static_cast( static_cast(iIndex)*100.0/static_cast(iSize) ); - else - pData->m_nPercent=0; - - m_cs.Unlock(); -} - -void CTask::GetSnapshot(TASK_DISPLAY_DATA *pData) -{ - m_cs.Lock(); - if (m_nCurrentIndex >= 0 && m_nCurrentIndex < m_files.GetSize()) - pData->m_fi=m_files.GetAt(m_nCurrentIndex); - else - { - if (m_files.GetSize() > 0) - { - pData->m_fi=m_files.GetAt(0); - pData->m_fi.SetFilePath(pData->m_fi.GetFullFilePath()); - pData->m_fi.SetSrcIndex(-1); - } - else - { - if (m_clipboard.GetSize() > 0) - { - pData->m_fi.SetFilePath(m_clipboard.GetAt(0)->GetPath()); - pData->m_fi.SetSrcIndex(-1); - } - else - { - pData->m_fi.SetFilePath(GetResManager()->LoadString(IDS_NONEINPUTFILE_STRING)); - pData->m_fi.SetSrcIndex(-1); - } - } - } - - pData->m_pbsSizes=&m_bsSizes; - pData->m_nPriority=m_nPriority; - pData->m_pdpDestPath=&m_dpDestPath; - pData->m_pafFilters=&m_afFilters; - pData->m_dwOsErrorCode=m_lOsError; - pData->m_strErrorDesc=m_strErrorDesc; - pData->m_uiStatus=m_nStatus; - pData->m_iIndex=m_nCurrentIndex+m_ucCurrentCopy*m_files.GetSize(); - pData->m_ullProcessedSize=m_nProcessed; - pData->m_iSize=m_files.GetSize()*m_ucCopies; - pData->m_ullSizeAll=m_nAll; - pData->m_ucCurrentCopy=static_cast(m_ucCurrentCopy+1); // visual aspect - pData->m_ucCopies=m_ucCopies; - pData->m_pstrUniqueName=&m_strUniqueName; - - if (m_files.GetSize() > 0 && m_nCurrentIndex != -1) - pData->m_iCurrentBufferIndex=m_bsSizes.m_bOnlyDefault ? 0 : m_files.GetAt((m_nCurrentIndex < m_files.GetSize()) ? m_nCurrentIndex : 0).GetBufferIndex(); - else - pData->m_iCurrentBufferIndex=0; - - // percents - if (m_nAll != 0 && !((m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_CONTENT)) - pData->m_nPercent=static_cast( (static_cast(m_nProcessed)*100.0)/static_cast(m_nAll) ); - else - if (pData->m_iSize != 0) - pData->m_nPercent=static_cast( static_cast(pData->m_iIndex)*100.0/static_cast(pData->m_iSize) ); - else - pData->m_nPercent=0; - - // status string - // first - if ( (m_nStatus & ST_WORKING_MASK) == ST_ERROR ) - { - GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+4, pData->m_szStatusText, _MAX_PATH); - _tcscat(pData->m_szStatusText, _T("/")); - } - else if ( (m_nStatus & ST_WORKING_MASK) == ST_PAUSED ) - { - GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+5, pData->m_szStatusText, _MAX_PATH); - _tcscat(pData->m_szStatusText, _T("/")); - } - else if ( (m_nStatus & ST_STEP_MASK) == ST_FINISHED ) - { - GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+3, pData->m_szStatusText, _MAX_PATH); - _tcscat(pData->m_szStatusText, _T("/")); - } - else if ( (m_nStatus & ST_WAITING_MASK) == ST_WAITING ) - { - GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+9, pData->m_szStatusText, _MAX_PATH); - _tcscat(pData->m_szStatusText, _T("/")); - } - else if ( (m_nStatus & ST_STEP_MASK) == ST_CANCELLED ) - { - GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+8, pData->m_szStatusText, _MAX_PATH); - _tcscat(pData->m_szStatusText, _T("/")); - } - else - _tcscpy(pData->m_szStatusText, _T("")); - - // second part - if ( (m_nStatus & ST_STEP_MASK) == ST_DELETING ) - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+6)); - else if ( (m_nStatus & ST_STEP_MASK) == ST_SEARCHING ) - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+0)); - else if ((m_nStatus & ST_OPERATION_MASK) == ST_COPY ) - { - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+1)); - if(!m_afFilters.IsEmpty()) - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_FILTERING_STRING)); - } - else if ( (m_nStatus & ST_OPERATION_MASK) == ST_MOVE ) - { - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+2)); - if(!m_afFilters.IsEmpty()) - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_FILTERING_STRING)); - } - else - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+7)); - - // third part - if ( (m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_DIRS ) - { - _tcscat(pData->m_szStatusText, _T("/")); - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+10)); - } - if ( (m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_CONTENT ) - { - _tcscat(pData->m_szStatusText, _T("/")); - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+11)); - } - - // count of copies - if (m_ucCopies > 1) - { - _tcscat(pData->m_szStatusText, _T("/")); - TCHAR xx[4]; - _tcscat(pData->m_szStatusText, _itot(m_ucCopies, xx, 10)); - if (m_ucCopies < 5) - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_COPYWORDLESSFIVE_STRING)); - else - _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_COPYWORDMOREFOUR_STRING)); - } - - // time - UpdateTime(); - pData->m_lTimeElapsed=m_lTimeElapsed; - - m_cs.Unlock(); -} - -/*inline*/ void CTask::CleanupAfterKill() -{ - m_cs.Lock(); - m_pThread=NULL; - UpdateTime(); - m_lLastTime=-1; - m_cs.Unlock(); -} - -void CTask::DeleteProgress(LPCTSTR lpszDirectory) -{ - m_cs.Lock(); - DeleteFile(lpszDirectory+m_strUniqueName+_T(".atd")); - DeleteFile(lpszDirectory+m_strUniqueName+_T(".atp")); - DeleteFile(lpszDirectory+m_strUniqueName+_T(".log")); - m_cs.Unlock(); -} - -void CTask::SetOsErrorCode(DWORD dwError, LPCTSTR lpszErrDesc) -{ - m_cs.Lock(); - m_lOsError=dwError; - m_strErrorDesc=lpszErrDesc; - m_cs.Unlock(); -} - -void CTask::UpdateTime() -{ - m_cs.Lock(); - if (m_lLastTime != -1) - { - long lVal=(long)time(NULL); - m_lTimeElapsed+=lVal-m_lLastTime; - m_lLastTime=lVal; - } - m_cs.Unlock(); -} - -void CTask::DecreaseOperationsPending(UINT uiBy) -{ - m_pcs->Lock(); - if (m_bQueued) - { - TRACE("Decreasing operations pending by %lu\n", uiBy); - (*m_puiOperationsPending)-=uiBy; - m_bQueued=false; - } - m_pcs->Unlock(); -} - -void CTask::IncreaseOperationsPending(UINT uiBy) -{ - TRACE("Trying to increase operations pending...\n"); - if (!m_bQueued) - { - TRACE("Increasing operations pending by %lu\n", uiBy); - m_pcs->Lock(); - (*m_puiOperationsPending)+=uiBy; - m_pcs->Unlock(); - m_bQueued=true; - } -} - -const CFiltersArray* CTask::GetFilters() -{ - return &m_afFilters; -} - -void CTask::SetFilters(const CFiltersArray* pFilters) -{ - BOOST_ASSERT(pFilters); - if(!pFilters) - return; - - m_cs.Lock(); - m_afFilters = *pFilters; - m_cs.Unlock(); -} - -bool CTask::CanBegin() -{ - bool bRet=true; - m_cs.Lock(); - if (GetContinueFlag() || GetForceFlag()) - { - TRACE("New operation Begins... continue: %d, force: %d\n", GetContinueFlag(), GetForceFlag()); - IncreaseOperationsPending(); - SetForceFlag(false); - SetContinueFlag(false); - } - else - bRet=false; - m_cs.Unlock(); - - return bRet; -} - -void CTask::SetCopies(unsigned char ucCopies) -{ - m_cs.Lock(); - m_ucCopies=ucCopies; - m_cs.Unlock(); -} - -unsigned char CTask::GetCopies() -{ - unsigned char ucCopies; - m_cs.Lock(); - ucCopies=m_ucCopies; - m_cs.Unlock(); - - return ucCopies; -} - -void CTask::SetCurrentCopy(unsigned char ucCopy) -{ - m_cs.Lock(); - m_ucCurrentCopy=ucCopy; - m_cs.Unlock(); -} - -unsigned char CTask::GetCurrentCopy() -{ - m_cs.Lock(); - unsigned char ucCopy=m_ucCurrentCopy; - m_cs.Unlock(); - - return ucCopy; -} - -void CTask::SetLastProcessedIndex(int iIndex) -{ - m_cs.Lock(); - m_iLastProcessedIndex=iIndex; - m_cs.Unlock(); -} - -int CTask::GetLastProcessedIndex() -{ - int iIndex; - m_cs.Lock(); - iIndex=m_iLastProcessedIndex; - m_cs.Unlock(); - - return iIndex; -} - -bool CTask::GetRequiredFreeSpace(ull_t *pullNeeded, ull_t *pullAvailable) -{ - *pullNeeded=GetAllSize()-GetProcessedSize(); // it'd be nice to round up to take cluster size into consideration, - // but GetDiskFreeSpace returns flase values - - // get free space - if (!GetDynamicFreeSpace(GetDestPath().GetPath(), pullAvailable, NULL)) - return true; - - return (*pullNeeded <= *pullAvailable); -} - -void CTask::SetTaskPath(const tchar_t* pszDir) -{ - m_cs.Lock(); - m_strTaskBasePath = pszDir; - m_cs.Unlock(); -} - -const tchar_t* CTask::GetTaskPath() const -{ - const tchar_t* pszText = NULL; - m_cs.Lock(); - pszText = m_strTaskBasePath.c_str(); - m_cs.Unlock(); - - return pszText; -} - -void CTask::SetForceFlag(bool bFlag) -{ - m_cs.Lock(); - m_bForce=bFlag; - m_cs.Unlock(); -} - -bool CTask::GetForceFlag() -{ - return m_bForce; -} - -void CTask::SetContinueFlag(bool bFlag) -{ - m_cs.Lock(); - m_bContinue=bFlag; - m_cs.Unlock(); -} - -bool CTask::GetContinueFlag() -{ - return m_bContinue; -} - -/* -CString CTask::GetLogName() -{ - TCHAR szPath[_MAX_PATH]; - GetConfig()->get_string(PP_PAUTOSAVEDIRECTORY, szPath, _MAX_PATH); - return GetApp()->ExpandPath(szPath)+GetUniqueName()+_T(".log"); -} -*/ - -//////////////////////////////////////////////////////////////////////////////// -// CTaskArray members -CTaskArray::CTaskArray() : - CArray(), - m_uhRange(0), - m_uhPosition(0), - m_uiOperationsPending(0), - m_lFinished(0), - m_piFeedbackFactory(NULL) -{ -} - -CTaskArray::~CTaskArray() -{ - // NOTE: do not delete the feedback factory, since we are not responsible for releasing it -} - -void CTaskArray::Create(chcore::IFeedbackHandlerFactory* piFeedbackHandlerFactory, UINT (*pfnTaskProc)(LPVOID pParam)) -{ - BOOST_ASSERT(piFeedbackHandlerFactory && pfnTaskProc); - - m_tcd.pcs=&m_cs; - m_tcd.pfnTaskProc=pfnTaskProc; - m_tcd.pTasksAll=&m_uhRange; - m_tcd.pTasksProcessed=&m_uhPosition; - m_tcd.puiOperationsPending=&m_uiOperationsPending; - m_tcd.plFinished=&m_lFinished; - m_piFeedbackFactory = piFeedbackHandlerFactory; -} - -CTask* CTaskArray::CreateTask() -{ - BOOST_ASSERT(m_piFeedbackFactory); - if(!m_piFeedbackFactory) - return NULL; - - chcore::IFeedbackHandler* piHandler = m_piFeedbackFactory->Create(); - if(!piHandler) - return NULL; - - CTask* pTask = NULL; - try - { - pTask = new CTask(piHandler, &m_tcd); - } - catch(...) - { -// piHandler->Delete(); - throw; - } - - return pTask; -} - -int CTaskArray::GetSize( ) -{ - m_cs.Lock(); - int nSize=m_nSize; - m_cs.Unlock(); - - return nSize; -} - -int CTaskArray::GetUpperBound( ) -{ - m_cs.Lock(); - int upper=m_nSize; - m_cs.Unlock(); - - return upper-1; -} - -void CTaskArray::SetSize( int nNewSize, int nGrowBy ) -{ - m_cs.Lock(); - (static_cast*>(this))->SetSize(nNewSize, nGrowBy); - m_cs.Unlock(); -} - -CTask* CTaskArray::GetAt( int nIndex ) -{ - ASSERT(nIndex >= 0 && nIndex < m_nSize); - m_cs.Lock(); - CTask* pTask=m_pData[nIndex]; - m_cs.Unlock(); - - return pTask; -} - -/* -void CTaskArray::SetAt( int nIndex, CTask* newElement ) -{ - m_cs.Lock(); - ASSERT(nIndex >= 0 && nIndex < m_nSize); - m_uhRange-=m_pData[nIndex]->GetAllSize(); // subtract old element - m_pData[nIndex]=newElement; - m_uhRange+=m_pData[nIndex]->GetAllSize(); // add new - m_cs.Unlock(); -} -*/ - -int CTaskArray::Add( CTask* newElement ) -{ - if(!newElement) - THROW(_t("Invalid argument"), 0, 0, 0); - m_cs.Lock(); - // here we know load succeeded - newElement->SetTaskPath(m_strTasksDir.c_str()); - - m_uhRange+=newElement->GetAllSize(); - m_uhPosition+=newElement->GetProcessedSize(); - int pos=(static_cast*>(this))->Add(newElement); - m_cs.Unlock(); - - return pos; -} - -void CTaskArray::RemoveAt(int nIndex, int nCount) -{ - m_cs.Lock(); - for (int i=nIndex;iKillThread(); - - m_uhRange-=pTask->GetAllSize(); - m_uhPosition-=pTask->GetProcessedSize(); - - delete pTask; - } - - // remove elements from array - (static_cast*>(this))->RemoveAt(nIndex, nCount); - m_cs.Unlock(); -} - -void CTaskArray::RemoveAll() -{ - m_cs.Lock(); - CTask* pTask; - - for (int i=0;iSetKillFlag(); // send an info about finishing - - // wait for finishing and get rid of it - for (int i=0;iGetKilledFlag()) - Sleep(10); - - pTask->CleanupAfterKill(); - - m_uhRange-=pTask->GetAllSize(); - m_uhPosition-=pTask->GetProcessedSize(); - - // delete data - delete pTask; - } - - (static_cast*>(this))->RemoveAll(); - m_cs.Unlock(); -} - -void CTaskArray::RemoveAllFinished() -{ - m_cs.Lock(); - int i=GetSize(); - - while (i) - { - CTask* pTask=GetAt(i-1); - - // delete only when the thread is finished - if ( (pTask->GetStatus(ST_STEP_MASK) == ST_FINISHED || pTask->GetStatus(ST_STEP_MASK) == ST_CANCELLED) - && pTask->GetKilledFlag()) - { - m_uhRange-=pTask->GetAllSize(); - m_uhPosition-=pTask->GetProcessedSize(); - - // delete associated files - pTask->DeleteProgress(m_strTasksDir.c_str()); - - delete pTask; - - static_cast*>(this)->RemoveAt(i-1); - } - - --i; - } - - m_cs.Unlock(); -} - -void CTaskArray::RemoveFinished(CTask** pSelTask) -{ - m_cs.Lock(); - for (int i=0;iGetStatus(ST_STEP_MASK) == ST_FINISHED || pTask->GetStatus(ST_STEP_MASK) == ST_CANCELLED)) - { - // kill task if needed - pTask->KillThread(); - - m_uhRange-=pTask->GetAllSize(); - m_uhPosition-=pTask->GetProcessedSize(); - - // delete associated files - pTask->DeleteProgress(m_strTasksDir.c_str()); - - // delete data - delete pTask; - - static_cast*>(this)->RemoveAt(i); - - m_cs.Unlock(); - return; - } - } - m_cs.Unlock(); -} - -void CTaskArray::SaveData() -{ - m_cs.Lock(); - for (int i=0;iStore(true); - m_cs.Unlock(); -} - -void CTaskArray::SaveProgress() -{ - m_cs.Lock(); - for (int i=0;iStore(false); - m_cs.Unlock(); -} - -void CTaskArray::LoadDataProgress() -{ - m_cs.Lock(); - CFileFind finder; - CTask* pTask; - - BOOL bWorking=finder.FindFile(CString(m_strTasksDir.c_str())+_T("*.atd")); - while ( bWorking ) - { - bWorking=finder.FindNextFile(); - - // load data - pTask = CreateTask(); - - try - { - CString strPath=finder.GetFilePath(); - - // load data file - icpf::archive ar; - ar.open(strPath, FA_READ); - ar.datablock_begin(); - pTask->Load(ar, true); - ar.datablock_end(); - ar.close(); - - // load progress file - strPath=strPath.Left(strPath.GetLength()-4); - strPath+=_T(".atp"); - icpf::archive ar2; - ar2.open(strPath, FA_READ); - ar2.datablock_begin(); - pTask->Load(ar2, false); - ar2.datablock_end(); - ar2.close(); - - // add read task to array - Add(pTask); - } - catch(icpf::exception&) - { - delete pTask; - } - } - finder.Close(); - - m_cs.Unlock(); -} - -void CTaskArray::TasksBeginProcessing() -{ - for (int i=0;iBeginProcessing(); -} - -void CTaskArray::TasksPauseProcessing() -{ - for (int i=0;iPauseProcessing(); -} - -void CTaskArray::TasksResumeProcessing() -{ - for (int i=0;iResumeProcessing(); -} - -void CTaskArray::TasksRestartProcessing() -{ - for (int i=0;iRestartProcessing(); -} - -bool CTaskArray::TasksRetryProcessing(bool bOnlyErrors/*=false*/, UINT uiInterval) -{ - bool bChanged=false; - for (int i=0;iRetryProcessing(bOnlyErrors, uiInterval)) - bChanged=true; - } - - return bChanged; -} - -void CTaskArray::TasksCancelProcessing() -{ - for (int i=0;iCancelProcessing(); -} - -ull_t CTaskArray::GetPosition() -{ - m_cs.Lock(); - ull_t rv=m_uhPosition; - m_cs.Unlock(); - - return rv; -} - -ull_t CTaskArray::GetRange() -{ - m_cs.Lock(); - ull_t rv=m_uhRange; - m_cs.Unlock(); - - return rv; -} - -int CTaskArray::GetPercent() -{ - int pos; - m_cs.Lock(); - if (m_uhRange != 0) - pos=static_cast((static_cast(m_uhPosition)*100.0)/static_cast(m_uhRange)); - else - if (GetSize() != 0) // if anything is in an array, but size of it is 0 - pos=100; - else - pos=0; - m_cs.Unlock(); - - return pos; -} - -UINT CTaskArray::GetOperationsPending() -{ - m_cs.Lock(); - UINT uiOP=m_uiOperationsPending; - m_cs.Unlock(); - return uiOP; -} - -bool CTaskArray::IsFinished() -{ - bool bFlag=true; - UINT uiStatus; - - m_cs.Lock(); - if (m_uiOperationsPending != 0) - bFlag=false; - else - { - for (int i=0;iGetStatus(); - bFlag=((uiStatus & ST_STEP_MASK) == ST_FINISHED || (uiStatus & ST_STEP_MASK) == ST_CANCELLED - || (uiStatus & ST_WORKING_MASK) == ST_PAUSED - || ((uiStatus & ST_WORKING_MASK) == ST_ERROR && !GetConfig()->get_bool(PP_CMAUTORETRYONERROR))); - } - } - - m_cs.Unlock(); - return bFlag; -} - -/////////////////////////////////////////////////////////////////////// -// CProcessingException - -CProcessingException::CProcessingException(int iType, CTask* pTask, UINT uiFmtID, DWORD dwError, ...) -{ - // std values - m_iType=iType; - m_pTask=pTask; - m_dwError=dwError; - - // format some text - CString strFormat=GetResManager()->LoadString(uiFmtID); - ExpandFormatString(&strFormat, dwError); - - // get param list - va_list marker; - va_start(marker, dwError); - m_strErrorDesc.FormatV(strFormat, marker); - va_end(marker); -} - -CProcessingException::CProcessingException(int iType, CTask* pTask, DWORD dwError, const tchar_t* pszDesc) -{ - // std values - m_iType=iType; - m_pTask=pTask; - m_dwError=dwError; - - // format some text - m_strErrorDesc = pszDesc; -} - -void CProcessingException::Cleanup() -{ - switch (m_pTask->GetStatus(ST_STEP_MASK)) - { - case ST_NULL_STATUS: - case ST_SEARCHING: - // get rif of m_files contents - m_pTask->FilesRemoveAll(); - - // save state of a task - m_pTask->Store(true); - m_pTask->Store(false); - - m_pTask->SetKilledFlag(); - m_pTask->CleanupAfterKill(); - - break; - case ST_COPYING: - case ST_DELETING: - switch (m_iType) - { - case E_ERROR: - m_pTask->SetStatus(ST_ERROR, ST_WORKING_MASK); - m_pTask->SetOsErrorCode(m_dwError, this->m_strErrorDesc); - break; - case E_CANCEL: - m_pTask->SetStatus(ST_CANCELLED, ST_STEP_MASK); - break; - } - - m_pTask->Store(false); - - m_pTask->SetKilledFlag(); - m_pTask->CleanupAfterKill(); - - break; - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "structs.h" +#include "resource.h" +#include "StringHelpers.h" +#include "..\common\FileSupport.h" +#include "ch.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +// global +int PriorityToIndex(int nPriority) +{ + switch(nPriority) + { + case THREAD_PRIORITY_TIME_CRITICAL: + return 0; + case THREAD_PRIORITY_HIGHEST: + return 1; + case THREAD_PRIORITY_ABOVE_NORMAL: + return 2; + case THREAD_PRIORITY_NORMAL: + return 3; + case THREAD_PRIORITY_BELOW_NORMAL: + return 4; + case THREAD_PRIORITY_LOWEST: + return 5; + case THREAD_PRIORITY_IDLE: + return 6; + default: + return 3; + } +} + +int IndexToPriority(int nIndex) +{ + switch(nIndex) + { + case 0: + return THREAD_PRIORITY_TIME_CRITICAL; + case 1: + return THREAD_PRIORITY_HIGHEST; + case 2: + return THREAD_PRIORITY_ABOVE_NORMAL; + case 3: + return THREAD_PRIORITY_NORMAL; + case 4: + return THREAD_PRIORITY_BELOW_NORMAL; + case 5: + return THREAD_PRIORITY_LOWEST; + case 6: + return THREAD_PRIORITY_IDLE; + default: + return THREAD_PRIORITY_NORMAL; + } +} + +int IndexToPriorityClass(int iIndex) +{ + switch(iIndex) + { + case 0: + return IDLE_PRIORITY_CLASS; + case 1: + return NORMAL_PRIORITY_CLASS; + case 2: + return HIGH_PRIORITY_CLASS; + case 3: + return REALTIME_PRIORITY_CLASS; + default: + return NORMAL_PRIORITY_CLASS; + } +} + +int PriorityClassToIndex(int iPriority) +{ + switch(iPriority) + { + case IDLE_PRIORITY_CLASS: + return 0; + case NORMAL_PRIORITY_CLASS: + return 1; + case HIGH_PRIORITY_CLASS: + return 2; + case REALTIME_PRIORITY_CLASS: + return 3; + default: + return 1; + } +} + +//////////////////////////////////////////////////////////////////////////// +// CTask members + +CTask::CTask(chcore::IFeedbackHandler* piFeedbackHandler, const TASK_CREATE_DATA *pCreateData) : + m_log(), + m_piFeedbackHandler(piFeedbackHandler) +{ + BOOST_ASSERT(piFeedbackHandler); + + m_nCurrentIndex=0; + m_iLastProcessedIndex=-1; + m_nStatus=ST_NULL_STATUS; + m_bsSizes.m_uiDefaultSize=65536; + m_bsSizes.m_uiOneDiskSize=4194304; + m_bsSizes.m_uiTwoDisksSize=262144; + m_bsSizes.m_uiCDSize=262144; + m_bsSizes.m_uiLANSize=65536; + m_pThread=NULL; + m_nPriority=THREAD_PRIORITY_NORMAL; + m_nProcessed=0; + m_nAll=0; + m_pnTasksProcessed=pCreateData->pTasksProcessed; + m_pnTasksAll=pCreateData->pTasksAll; + m_bKill=false; + m_bKilled=true; + m_pcs=pCreateData->pcs; + m_pfnTaskProc=pCreateData->pfnTaskProc; + m_lTimeElapsed=0; + m_lLastTime=-1; + m_puiOperationsPending=pCreateData->puiOperationsPending; + m_bQueued=false; + m_ucCopies=1; + m_ucCurrentCopy=0; + m_files.Init(&m_clipboard); + m_uiResumeInterval=0; + m_plFinished=pCreateData->plFinished; + m_bForce=false; + m_bContinue=false; + m_bSaved=false; + + m_iIdentical=-1; + m_iDestinationLess=-1; + m_iDestinationGreater=-1; + m_iMissingInput=-1; + m_iOutputError=-1; + m_iMoveFile=-1; + + TCHAR xx[16]; + _itot((int)time(NULL), xx, 10); + m_strUniqueName=xx; +} + +CTask::~CTask() +{ + KillThread(); + if(m_piFeedbackHandler) + m_piFeedbackHandler->Delete(); +} + +// m_clipboard +int CTask::AddClipboardData(CClipboardEntry* pEntry) +{ + m_cs.Lock(); + int retval=m_clipboard.Add(pEntry); + m_cs.Unlock(); + + return retval; +} + +CClipboardEntry* CTask::GetClipboardData(int nIndex) +{ + m_cs.Lock(); + CClipboardEntry* pEntry=m_clipboard.GetAt(nIndex); + m_cs.Unlock(); + + return pEntry; +} + +int CTask::GetClipboardDataSize() +{ + m_cs.Lock(); + int rv=m_clipboard.GetSize(); + m_cs.Unlock(); + + return rv; +} + +int CTask::ReplaceClipboardStrings(CString strOld, CString strNew) +{ + // small chars to make comparing case insensitive + strOld.MakeLower(); + + CString strText; + int iOffset; + int iCount=0; + m_cs.Lock(); + for (int i=0;iGetPath(); + strText.MakeLower(); + iOffset=strText.Find(strOld, 0); + if (iOffset != -1) + { + // found + strText=pEntry->GetPath(); + strText=strText.Left(iOffset)+strNew+strText.Mid(iOffset+strOld.GetLength()); + pEntry->SetPath(strText); + iCount++; + } + } + m_cs.Unlock(); + + return iCount; +} + +// m_files +int CTask::FilesAddDir(const CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, + const bool bRecurse, const bool bIncludeDirs) +{ + // this uses much of memory, but resolves problem critical section hungs and m_bKill + CFileInfoArray fa; + fa.Init(&m_clipboard); + + fa.AddDir(strDirName, pFilters, iSrcIndex, bRecurse, bIncludeDirs, &m_bKill); + + m_cs.Lock(); + + m_files.Append(fa); + + m_cs.Unlock(); + + return 0; +} + +int CTask::FilesAdd(CFileInfo fi) +{ + int rv=-1; + m_cs.Lock(); + if (fi.IsDirectory() || m_afFilters.Match(fi)) + rv=m_files.Add(fi); + m_cs.Unlock(); + + return rv; +} + +CFileInfo CTask::FilesGetAt(int nIndex) +{ + m_cs.Lock(); + CFileInfo info=m_files.GetAt(nIndex); + m_cs.Unlock(); + + return info; +} + +CFileInfo& CTask::FilesGetAtCurrentIndex() +{ + m_cs.Lock(); + CFileInfo& info=m_files.GetAt(m_nCurrentIndex); + m_cs.Unlock(); + return info; +} + +void CTask::FilesRemoveAll() +{ + m_cs.Lock(); + m_files.RemoveAll(); + m_cs.Unlock(); +} + +int CTask::FilesGetSize() +{ + m_cs.Lock(); + int nSize=m_files.GetSize(); + m_cs.Unlock(); + + return nSize; +} + +// m_nCurrentIndex +void CTask::IncreaseCurrentIndex() +{ + m_cs.Lock(); + ++m_nCurrentIndex; + m_cs.Unlock(); +} + +int CTask::GetCurrentIndex() +{ + m_cs.Lock(); + int nIndex=m_nCurrentIndex; + m_cs.Unlock(); + + return nIndex; +} + +void CTask::SetCurrentIndex(int nIndex) +{ + m_cs.Lock(); + m_nCurrentIndex=nIndex; + m_cs.Unlock(); +} + +// m_strDestPath - adds '\\' +void CTask::SetDestPath(LPCTSTR lpszPath) +{ + m_dpDestPath.SetPath(lpszPath); +} + +// guaranteed '\\' +const CDestPath& CTask::GetDestPath() +{ + return m_dpDestPath; +} + +int CTask::GetDestDriveNumber() +{ + return m_dpDestPath.GetDriveNumber(); +} + +// m_nStatus +void CTask::SetStatus(UINT nStatus, UINT nMask) +{ + m_cs.Lock(); + m_nStatus &= ~nMask; + m_nStatus |= nStatus; + m_cs.Unlock(); +} + +UINT CTask::GetStatus(UINT nMask) +{ + m_cs.Lock(); + UINT nStatus=m_nStatus; + m_cs.Unlock(); + + return (nStatus & nMask); +} + +// m_nBufferSize +void CTask::SetBufferSizes(const BUFFERSIZES* bsSizes) +{ + m_cs.Lock(); + m_bsSizes=*bsSizes; + m_bSaved=false; + m_cs.Unlock(); +} + +const BUFFERSIZES* CTask::GetBufferSizes() +{ + m_cs.Lock(); + const BUFFERSIZES* pbsSizes=&m_bsSizes; + m_cs.Unlock(); + + return pbsSizes; +} + +int CTask::GetCurrentBufferIndex() +{ + int rv=0; + m_cs.Lock(); + int iSize=m_files.GetSize(); + if (iSize > 0 && m_nCurrentIndex != -1) + rv=m_bsSizes.m_bOnlyDefault ? 0 : m_files.GetAt((m_nCurrentIndex < iSize) ? m_nCurrentIndex : 0).GetBufferIndex(); + m_cs.Unlock(); + + return rv; +} + +// m_pThread +// m_nPriority +int CTask::GetPriority() +{ + m_cs.Lock(); + int nPriority=m_nPriority; + m_cs.Unlock(); + return nPriority; +} + +void CTask::SetPriority(int nPriority) +{ + m_cs.Lock(); + m_nPriority=nPriority; + m_bSaved=false; + if (m_pThread != NULL) + { + TRACE("Changing thread priority"); + m_pThread->SuspendThread(); + m_pThread->SetThreadPriority(nPriority); + m_pThread->ResumeThread(); + } + m_cs.Unlock(); +} + +// m_nProcessed +void CTask::IncreaseProcessedSize(__int64 nSize) +{ + m_cs.Lock(); + m_nProcessed+=nSize; + m_cs.Unlock(); +} + +void CTask::SetProcessedSize(__int64 nSize) +{ + m_cs.Lock(); + m_nProcessed=nSize; + m_cs.Unlock(); +} + +__int64 CTask::GetProcessedSize() +{ + m_cs.Lock(); + __int64 nSize=m_nProcessed; + m_cs.Unlock(); + + return nSize; +} + +// m_nAll +void CTask::SetAllSize(__int64 nSize) +{ + m_cs.Lock(); + m_nAll=nSize; + m_cs.Unlock(); +} + +__int64 CTask::GetAllSize() +{ + m_cs.Lock(); + __int64 nAll=m_nAll; + m_cs.Unlock(); + + return nAll; +} + +void CTask::CalcAllSize() +{ + m_cs.Lock(); + m_nAll=0; + + int nSize=m_files.GetSize(); + CFileInfo* pFiles=m_files.GetData(); + + for (int i=0;iLock(); + (*m_pnTasksProcessed)+=nSize; + m_pcs->Unlock(); +// m_cs.Unlock(); +} + +void CTask::DecreaseProcessedTasksSize(__int64 nSize) +{ +// m_cs.Lock(); + m_pcs->Lock(); + (*m_pnTasksProcessed)-=nSize; + m_pcs->Unlock(); +// m_cs.Unlock(); +} + +// m_pnTasksAll +void CTask::IncreaseAllTasksSize(__int64 nSize) +{ +// m_cs.Lock(); + m_pcs->Lock(); + (*m_pnTasksAll)+=nSize; + m_pcs->Unlock(); +// m_cs.Unlock(); +} + +void CTask::DecreaseAllTasksSize(__int64 nSize) +{ +// m_cs.Lock(); + m_pcs->Lock(); + (*m_pnTasksAll)-=nSize; + m_pcs->Unlock(); +// m_cs.Unlock(); +} + +// m_bKill +/*inline*/ void CTask::SetKillFlag(bool bKill) +{ + m_cs.Lock(); + m_bKill=bKill; + m_cs.Unlock(); +} + +bool CTask::GetKillFlag() +{ + m_cs.Lock(); + bool bKill=m_bKill; + m_cs.Unlock(); + + return bKill; +} + +// m_bKilled +/*inline*/ void CTask::SetKilledFlag(bool bKilled) +{ + m_cs.Lock(); + m_bKilled=bKilled; + m_cs.Unlock(); +} + +/*inline*/ bool CTask::GetKilledFlag() +{ + m_cs.Lock(); + bool bKilled=m_bKilled; + m_cs.Unlock(); + + return bKilled; +} + +// m_strUniqueName + +CString CTask::GetUniqueName() +{ + m_cs.Lock(); + CString name=m_strUniqueName; + m_cs.Unlock(); + + return name; +} + +void CTask::Load(icpf::archive& ar, bool bData) +{ + m_cs.Lock(); + try + { + if (bData) + { + m_clipboard.Serialize(ar, bData); + + m_files.Load(ar, false); + m_dpDestPath.Serialize(ar); + ar>>m_strUniqueName; + m_afFilters.Serialize(ar); + ar>>m_ucCopies; + } + else + { + int data; + unsigned long part; + + ar>>data; + m_nCurrentIndex=data; + ar>>data; + m_nStatus=data; + ar>>m_lOsError; + ar>>m_strErrorDesc; + m_bsSizes.Serialize(ar); + ar>>m_nPriority; + + ar>>part; + m_nAll=(static_cast(part) << 32); + ar>>part; + m_nAll|=part; + // czas + ar>>m_lTimeElapsed; + + ar>>part; + m_nProcessed=(static_cast(part) << 32); + ar>>part; + m_nProcessed|=part; + + ar>>m_ucCurrentCopy; + + m_clipboard.Serialize(ar, bData); + m_files.Load(ar, true); + + unsigned char ucTmp; + ar>>ucTmp; + m_bSaved=ucTmp != 0; + } + } + catch(icpf::exception&) + { + m_cs.Unlock(); + throw; + } + m_cs.Unlock(); +} + +void CTask::Store(bool bData) +{ + m_cs.Lock(); + BOOST_ASSERT(!m_strTaskBasePath.empty()); + if(m_strTaskBasePath.empty()) + { + m_cs.Unlock(); + THROW(_t("Missing task path."), 0, 0, 0); + } + if (!bData && m_bSaved) + { + m_cs.Unlock(); + TRACE("Saving locked - file not saved\n"); + return; + } + + if (!bData && !m_bSaved && ( (m_nStatus & ST_STEP_MASK) == ST_FINISHED || (m_nStatus & ST_STEP_MASK) == ST_CANCELLED + || (m_nStatus & ST_WORKING_MASK) == ST_PAUSED )) + { + TRACE("Last save - saving blocked\n"); + m_bSaved=true; + } + + try + { + CString strPath = m_strTaskBasePath.c_str() + GetUniqueName()+( (bData) ? _T(".atd") : _T(".atp") ); + icpf::archive ar; + ar.open(strPath, FA_WRITE | FA_CREATE | FA_TRUNCATE); + ar.datablock_begin(); + + if (bData) + { + m_clipboard.Serialize(ar, bData); + + if (GetStatus(ST_STEP_MASK) > ST_SEARCHING) + m_files.Store(ar, false); + else + ar<(0); + + m_dpDestPath.Serialize(ar); + ar<((m_nAll & 0xffffffff00000000) >> 32); + ar<(m_nAll & 0x00000000ffffffff); + ar<((m_nProcessed & 0xffffffff00000000) >> 32); + ar<(m_nProcessed & 0x00000000ffffffff); + ar< ST_SEARCHING) + m_files.Store(ar, true); + else + ar<(0); + ar<<(unsigned char)m_bSaved; + } + ar.datablock_end(); + ar.close(); + } + catch(icpf::exception& /*e*/) + { + m_cs.Unlock(); + return; + } + m_cs.Unlock(); +} + +/*inline*/ void CTask::KillThread() +{ + if (!GetKilledFlag()) // protection from recalling Cleanup + { + SetKillFlag(); + while (!GetKilledFlag()) + Sleep(10); + + // cleanup + CleanupAfterKill(); + } +} + +void CTask::BeginProcessing() +{ + m_cs.Lock(); + if (m_pThread != NULL) + { + m_cs.Unlock(); + return; + } + m_cs.Unlock(); + + // create new thread + m_uiResumeInterval=0; // just in case + m_bSaved=false; // save + SetKillFlag(false); + SetKilledFlag(false); + CWinThread* pThread=AfxBeginThread(m_pfnTaskProc, this, GetPriority()); + + m_cs.Lock(); + m_pThread=pThread; + m_cs.Unlock(); +} + +void CTask::ResumeProcessing() +{ + // the same as retry but less demanding + if ( (GetStatus(ST_WORKING_MASK) & ST_PAUSED) && GetStatus(ST_STEP_MASK) != ST_FINISHED + && GetStatus(ST_STEP_MASK) != ST_CANCELLED) + { + SetStatus(0, ST_ERROR); + BeginProcessing(); + } +} + +bool CTask::RetryProcessing(bool bOnlyErrors/*=false*/, UINT uiInterval) +{ + // retry used to auto-resume, after loading + if ( (GetStatus(ST_WORKING_MASK) == ST_ERROR || (!bOnlyErrors && GetStatus(ST_WORKING_MASK) != ST_PAUSED)) + && GetStatus(ST_STEP_MASK) != ST_FINISHED && GetStatus(ST_STEP_MASK) != ST_CANCELLED) + { + if (uiInterval != 0) + { + m_uiResumeInterval+=uiInterval; + if (m_uiResumeInterval < (UINT)GetConfig()->get_signed_num(PP_CMAUTORETRYINTERVAL)) + return false; + else + m_uiResumeInterval=0; + } + + SetStatus(0, ST_ERROR); + BeginProcessing(); + return true; + } + return false; +} + +void CTask::RestartProcessing() +{ + KillThread(); + SetStatus(0, ST_ERROR); + SetStatus(ST_NULL_STATUS, ST_STEP_MASK); + m_lTimeElapsed=0; + SetCurrentIndex(0); + SetCurrentCopy(0); + BeginProcessing(); +} + +void CTask::PauseProcessing() +{ + if (GetStatus(ST_STEP_MASK) != ST_FINISHED && GetStatus(ST_STEP_MASK) != ST_CANCELLED) + { + KillThread(); + SetStatus(ST_PAUSED, ST_WORKING_MASK); + SetLastProcessedIndex(GetCurrentIndex()); + m_bSaved=false; + } +} + +void CTask::CancelProcessing() +{ + // change to ST_CANCELLED + if (GetStatus(ST_STEP_MASK) != ST_FINISHED) + { + KillThread(); + SetStatus(ST_CANCELLED, ST_STEP_MASK); + SetStatus(0, ST_ERROR); + m_bSaved=false; + } +} + +void CTask::GetMiniSnapshot(TASK_MINI_DISPLAY_DATA *pData) +{ + m_cs.Lock(); + if (m_nCurrentIndex >= 0 && m_nCurrentIndex < m_files.GetSize()) + pData->m_fi=m_files.GetAt(m_nCurrentIndex); + else + { + if (m_files.GetSize() > 0) + { + pData->m_fi=m_files.GetAt(0); + pData->m_fi.SetFilePath(pData->m_fi.GetFullFilePath()); + pData->m_fi.SetSrcIndex(-1); + } + else + { + if (m_clipboard.GetSize() > 0) + { + pData->m_fi.SetFilePath(m_clipboard.GetAt(0)->GetPath()); + pData->m_fi.SetSrcIndex(-1); + } + else + { + pData->m_fi.SetFilePath(GetResManager()->LoadString(IDS_NONEINPUTFILE_STRING)); + pData->m_fi.SetSrcIndex(-1); + } + } + } + + pData->m_uiStatus=m_nStatus; + + // percents + int iSize=m_files.GetSize()*m_ucCopies; + int iIndex=m_nCurrentIndex+m_ucCurrentCopy*m_files.GetSize(); + if (m_nAll != 0 && !((m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_CONTENT)) + pData->m_nPercent=static_cast( (static_cast(m_nProcessed)*100.0)/static_cast(m_nAll) ); + else + if (iSize != 0) + pData->m_nPercent=static_cast( static_cast(iIndex)*100.0/static_cast(iSize) ); + else + pData->m_nPercent=0; + + m_cs.Unlock(); +} + +void CTask::GetSnapshot(TASK_DISPLAY_DATA *pData) +{ + m_cs.Lock(); + if (m_nCurrentIndex >= 0 && m_nCurrentIndex < m_files.GetSize()) + pData->m_fi=m_files.GetAt(m_nCurrentIndex); + else + { + if (m_files.GetSize() > 0) + { + pData->m_fi=m_files.GetAt(0); + pData->m_fi.SetFilePath(pData->m_fi.GetFullFilePath()); + pData->m_fi.SetSrcIndex(-1); + } + else + { + if (m_clipboard.GetSize() > 0) + { + pData->m_fi.SetFilePath(m_clipboard.GetAt(0)->GetPath()); + pData->m_fi.SetSrcIndex(-1); + } + else + { + pData->m_fi.SetFilePath(GetResManager()->LoadString(IDS_NONEINPUTFILE_STRING)); + pData->m_fi.SetSrcIndex(-1); + } + } + } + + pData->m_pbsSizes=&m_bsSizes; + pData->m_nPriority=m_nPriority; + pData->m_pdpDestPath=&m_dpDestPath; + pData->m_pafFilters=&m_afFilters; + pData->m_dwOsErrorCode=m_lOsError; + pData->m_strErrorDesc=m_strErrorDesc; + pData->m_uiStatus=m_nStatus; + pData->m_iIndex=m_nCurrentIndex+m_ucCurrentCopy*m_files.GetSize(); + pData->m_ullProcessedSize=m_nProcessed; + pData->m_iSize=m_files.GetSize()*m_ucCopies; + pData->m_ullSizeAll=m_nAll; + pData->m_ucCurrentCopy=static_cast(m_ucCurrentCopy+1); // visual aspect + pData->m_ucCopies=m_ucCopies; + pData->m_pstrUniqueName=&m_strUniqueName; + + if (m_files.GetSize() > 0 && m_nCurrentIndex != -1) + pData->m_iCurrentBufferIndex=m_bsSizes.m_bOnlyDefault ? 0 : m_files.GetAt((m_nCurrentIndex < m_files.GetSize()) ? m_nCurrentIndex : 0).GetBufferIndex(); + else + pData->m_iCurrentBufferIndex=0; + + // percents + if (m_nAll != 0 && !((m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_CONTENT)) + pData->m_nPercent=static_cast( (static_cast(m_nProcessed)*100.0)/static_cast(m_nAll) ); + else + if (pData->m_iSize != 0) + pData->m_nPercent=static_cast( static_cast(pData->m_iIndex)*100.0/static_cast(pData->m_iSize) ); + else + pData->m_nPercent=0; + + // status string + // first + if ( (m_nStatus & ST_WORKING_MASK) == ST_ERROR ) + { + GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+4, pData->m_szStatusText, _MAX_PATH); + _tcscat(pData->m_szStatusText, _T("/")); + } + else if ( (m_nStatus & ST_WORKING_MASK) == ST_PAUSED ) + { + GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+5, pData->m_szStatusText, _MAX_PATH); + _tcscat(pData->m_szStatusText, _T("/")); + } + else if ( (m_nStatus & ST_STEP_MASK) == ST_FINISHED ) + { + GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+3, pData->m_szStatusText, _MAX_PATH); + _tcscat(pData->m_szStatusText, _T("/")); + } + else if ( (m_nStatus & ST_WAITING_MASK) == ST_WAITING ) + { + GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+9, pData->m_szStatusText, _MAX_PATH); + _tcscat(pData->m_szStatusText, _T("/")); + } + else if ( (m_nStatus & ST_STEP_MASK) == ST_CANCELLED ) + { + GetResManager()->LoadStringCopy(IDS_STATUS0_STRING+8, pData->m_szStatusText, _MAX_PATH); + _tcscat(pData->m_szStatusText, _T("/")); + } + else + _tcscpy(pData->m_szStatusText, _T("")); + + // second part + if ( (m_nStatus & ST_STEP_MASK) == ST_DELETING ) + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+6)); + else if ( (m_nStatus & ST_STEP_MASK) == ST_SEARCHING ) + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+0)); + else if ((m_nStatus & ST_OPERATION_MASK) == ST_COPY ) + { + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+1)); + if(!m_afFilters.IsEmpty()) + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_FILTERING_STRING)); + } + else if ( (m_nStatus & ST_OPERATION_MASK) == ST_MOVE ) + { + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+2)); + if(!m_afFilters.IsEmpty()) + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_FILTERING_STRING)); + } + else + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+7)); + + // third part + if ( (m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_DIRS ) + { + _tcscat(pData->m_szStatusText, _T("/")); + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+10)); + } + if ( (m_nStatus & ST_SPECIAL_MASK) & ST_IGNORE_CONTENT ) + { + _tcscat(pData->m_szStatusText, _T("/")); + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_STATUS0_STRING+11)); + } + + // count of copies + if (m_ucCopies > 1) + { + _tcscat(pData->m_szStatusText, _T("/")); + TCHAR xx[4]; + _tcscat(pData->m_szStatusText, _itot(m_ucCopies, xx, 10)); + if (m_ucCopies < 5) + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_COPYWORDLESSFIVE_STRING)); + else + _tcscat(pData->m_szStatusText, GetResManager()->LoadString(IDS_COPYWORDMOREFOUR_STRING)); + } + + // time + UpdateTime(); + pData->m_lTimeElapsed=m_lTimeElapsed; + + m_cs.Unlock(); +} + +/*inline*/ void CTask::CleanupAfterKill() +{ + m_cs.Lock(); + m_pThread=NULL; + UpdateTime(); + m_lLastTime=-1; + m_cs.Unlock(); +} + +void CTask::DeleteProgress(LPCTSTR lpszDirectory) +{ + m_cs.Lock(); + DeleteFile(lpszDirectory+m_strUniqueName+_T(".atd")); + DeleteFile(lpszDirectory+m_strUniqueName+_T(".atp")); + DeleteFile(lpszDirectory+m_strUniqueName+_T(".log")); + m_cs.Unlock(); +} + +void CTask::SetOsErrorCode(DWORD dwError, LPCTSTR lpszErrDesc) +{ + m_cs.Lock(); + m_lOsError=dwError; + m_strErrorDesc=lpszErrDesc; + m_cs.Unlock(); +} + +void CTask::UpdateTime() +{ + m_cs.Lock(); + if (m_lLastTime != -1) + { + long lVal=(long)time(NULL); + m_lTimeElapsed+=lVal-m_lLastTime; + m_lLastTime=lVal; + } + m_cs.Unlock(); +} + +void CTask::DecreaseOperationsPending(UINT uiBy) +{ + m_pcs->Lock(); + if (m_bQueued) + { + TRACE("Decreasing operations pending by %lu\n", uiBy); + (*m_puiOperationsPending)-=uiBy; + m_bQueued=false; + } + m_pcs->Unlock(); +} + +void CTask::IncreaseOperationsPending(UINT uiBy) +{ + TRACE("Trying to increase operations pending...\n"); + if (!m_bQueued) + { + TRACE("Increasing operations pending by %lu\n", uiBy); + m_pcs->Lock(); + (*m_puiOperationsPending)+=uiBy; + m_pcs->Unlock(); + m_bQueued=true; + } +} + +const CFiltersArray* CTask::GetFilters() +{ + return &m_afFilters; +} + +void CTask::SetFilters(const CFiltersArray* pFilters) +{ + BOOST_ASSERT(pFilters); + if(!pFilters) + return; + + m_cs.Lock(); + m_afFilters = *pFilters; + m_cs.Unlock(); +} + +bool CTask::CanBegin() +{ + bool bRet=true; + m_cs.Lock(); + if (GetContinueFlag() || GetForceFlag()) + { + TRACE("New operation Begins... continue: %d, force: %d\n", GetContinueFlag(), GetForceFlag()); + IncreaseOperationsPending(); + SetForceFlag(false); + SetContinueFlag(false); + } + else + bRet=false; + m_cs.Unlock(); + + return bRet; +} + +void CTask::SetCopies(unsigned char ucCopies) +{ + m_cs.Lock(); + m_ucCopies=ucCopies; + m_cs.Unlock(); +} + +unsigned char CTask::GetCopies() +{ + unsigned char ucCopies; + m_cs.Lock(); + ucCopies=m_ucCopies; + m_cs.Unlock(); + + return ucCopies; +} + +void CTask::SetCurrentCopy(unsigned char ucCopy) +{ + m_cs.Lock(); + m_ucCurrentCopy=ucCopy; + m_cs.Unlock(); +} + +unsigned char CTask::GetCurrentCopy() +{ + m_cs.Lock(); + unsigned char ucCopy=m_ucCurrentCopy; + m_cs.Unlock(); + + return ucCopy; +} + +void CTask::SetLastProcessedIndex(int iIndex) +{ + m_cs.Lock(); + m_iLastProcessedIndex=iIndex; + m_cs.Unlock(); +} + +int CTask::GetLastProcessedIndex() +{ + int iIndex; + m_cs.Lock(); + iIndex=m_iLastProcessedIndex; + m_cs.Unlock(); + + return iIndex; +} + +bool CTask::GetRequiredFreeSpace(ull_t *pullNeeded, ull_t *pullAvailable) +{ + *pullNeeded=GetAllSize()-GetProcessedSize(); // it'd be nice to round up to take cluster size into consideration, + // but GetDiskFreeSpace returns flase values + + // get free space + if (!GetDynamicFreeSpace(GetDestPath().GetPath(), pullAvailable, NULL)) + return true; + + return (*pullNeeded <= *pullAvailable); +} + +void CTask::SetTaskPath(const tchar_t* pszDir) +{ + m_cs.Lock(); + m_strTaskBasePath = pszDir; + m_cs.Unlock(); +} + +const tchar_t* CTask::GetTaskPath() const +{ + const tchar_t* pszText = NULL; + m_cs.Lock(); + pszText = m_strTaskBasePath.c_str(); + m_cs.Unlock(); + + return pszText; +} + +void CTask::SetForceFlag(bool bFlag) +{ + m_cs.Lock(); + m_bForce=bFlag; + m_cs.Unlock(); +} + +bool CTask::GetForceFlag() +{ + return m_bForce; +} + +void CTask::SetContinueFlag(bool bFlag) +{ + m_cs.Lock(); + m_bContinue=bFlag; + m_cs.Unlock(); +} + +bool CTask::GetContinueFlag() +{ + return m_bContinue; +} + +/* +CString CTask::GetLogName() +{ + TCHAR szPath[_MAX_PATH]; + GetConfig()->get_string(PP_PAUTOSAVEDIRECTORY, szPath, _MAX_PATH); + return GetApp()->ExpandPath(szPath)+GetUniqueName()+_T(".log"); +} +*/ + +//////////////////////////////////////////////////////////////////////////////// +// CTaskArray members +CTaskArray::CTaskArray() : + CArray(), + m_uhRange(0), + m_uhPosition(0), + m_uiOperationsPending(0), + m_lFinished(0), + m_piFeedbackFactory(NULL) +{ +} + +CTaskArray::~CTaskArray() +{ + // NOTE: do not delete the feedback factory, since we are not responsible for releasing it +} + +void CTaskArray::Create(chcore::IFeedbackHandlerFactory* piFeedbackHandlerFactory, UINT (*pfnTaskProc)(LPVOID pParam)) +{ + BOOST_ASSERT(piFeedbackHandlerFactory && pfnTaskProc); + + m_tcd.pcs=&m_cs; + m_tcd.pfnTaskProc=pfnTaskProc; + m_tcd.pTasksAll=&m_uhRange; + m_tcd.pTasksProcessed=&m_uhPosition; + m_tcd.puiOperationsPending=&m_uiOperationsPending; + m_tcd.plFinished=&m_lFinished; + m_piFeedbackFactory = piFeedbackHandlerFactory; +} + +CTask* CTaskArray::CreateTask() +{ + BOOST_ASSERT(m_piFeedbackFactory); + if(!m_piFeedbackFactory) + return NULL; + + chcore::IFeedbackHandler* piHandler = m_piFeedbackFactory->Create(); + if(!piHandler) + return NULL; + + CTask* pTask = NULL; + try + { + pTask = new CTask(piHandler, &m_tcd); + } + catch(...) + { +// piHandler->Delete(); + throw; + } + + return pTask; +} + +int CTaskArray::GetSize( ) +{ + m_cs.Lock(); + int nSize=m_nSize; + m_cs.Unlock(); + + return nSize; +} + +int CTaskArray::GetUpperBound( ) +{ + m_cs.Lock(); + int upper=m_nSize; + m_cs.Unlock(); + + return upper-1; +} + +void CTaskArray::SetSize( int nNewSize, int nGrowBy ) +{ + m_cs.Lock(); + (static_cast*>(this))->SetSize(nNewSize, nGrowBy); + m_cs.Unlock(); +} + +CTask* CTaskArray::GetAt( int nIndex ) +{ + ASSERT(nIndex >= 0 && nIndex < m_nSize); + m_cs.Lock(); + CTask* pTask=m_pData[nIndex]; + m_cs.Unlock(); + + return pTask; +} + +/* +void CTaskArray::SetAt( int nIndex, CTask* newElement ) +{ + m_cs.Lock(); + ASSERT(nIndex >= 0 && nIndex < m_nSize); + m_uhRange-=m_pData[nIndex]->GetAllSize(); // subtract old element + m_pData[nIndex]=newElement; + m_uhRange+=m_pData[nIndex]->GetAllSize(); // add new + m_cs.Unlock(); +} +*/ + +int CTaskArray::Add( CTask* newElement ) +{ + if(!newElement) + THROW(_t("Invalid argument"), 0, 0, 0); + m_cs.Lock(); + // here we know load succeeded + newElement->SetTaskPath(m_strTasksDir.c_str()); + + m_uhRange+=newElement->GetAllSize(); + m_uhPosition+=newElement->GetProcessedSize(); + int pos=(static_cast*>(this))->Add(newElement); + m_cs.Unlock(); + + return pos; +} + +void CTaskArray::RemoveAt(int nIndex, int nCount) +{ + m_cs.Lock(); + for (int i=nIndex;iKillThread(); + + m_uhRange-=pTask->GetAllSize(); + m_uhPosition-=pTask->GetProcessedSize(); + + delete pTask; + } + + // remove elements from array + (static_cast*>(this))->RemoveAt(nIndex, nCount); + m_cs.Unlock(); +} + +void CTaskArray::RemoveAll() +{ + m_cs.Lock(); + CTask* pTask; + + for (int i=0;iSetKillFlag(); // send an info about finishing + + // wait for finishing and get rid of it + for (int i=0;iGetKilledFlag()) + Sleep(10); + + pTask->CleanupAfterKill(); + + m_uhRange-=pTask->GetAllSize(); + m_uhPosition-=pTask->GetProcessedSize(); + + // delete data + delete pTask; + } + + (static_cast*>(this))->RemoveAll(); + m_cs.Unlock(); +} + +void CTaskArray::RemoveAllFinished() +{ + m_cs.Lock(); + int i=GetSize(); + + while (i) + { + CTask* pTask=GetAt(i-1); + + // delete only when the thread is finished + if ( (pTask->GetStatus(ST_STEP_MASK) == ST_FINISHED || pTask->GetStatus(ST_STEP_MASK) == ST_CANCELLED) + && pTask->GetKilledFlag()) + { + m_uhRange-=pTask->GetAllSize(); + m_uhPosition-=pTask->GetProcessedSize(); + + // delete associated files + pTask->DeleteProgress(m_strTasksDir.c_str()); + + delete pTask; + + static_cast*>(this)->RemoveAt(i-1); + } + + --i; + } + + m_cs.Unlock(); +} + +void CTaskArray::RemoveFinished(CTask** pSelTask) +{ + m_cs.Lock(); + for (int i=0;iGetStatus(ST_STEP_MASK) == ST_FINISHED || pTask->GetStatus(ST_STEP_MASK) == ST_CANCELLED)) + { + // kill task if needed + pTask->KillThread(); + + m_uhRange-=pTask->GetAllSize(); + m_uhPosition-=pTask->GetProcessedSize(); + + // delete associated files + pTask->DeleteProgress(m_strTasksDir.c_str()); + + // delete data + delete pTask; + + static_cast*>(this)->RemoveAt(i); + + m_cs.Unlock(); + return; + } + } + m_cs.Unlock(); +} + +void CTaskArray::SaveData() +{ + m_cs.Lock(); + for (int i=0;iStore(true); + m_cs.Unlock(); +} + +void CTaskArray::SaveProgress() +{ + m_cs.Lock(); + for (int i=0;iStore(false); + m_cs.Unlock(); +} + +void CTaskArray::LoadDataProgress() +{ + m_cs.Lock(); + CFileFind finder; + CTask* pTask; + + BOOL bWorking=finder.FindFile(CString(m_strTasksDir.c_str())+_T("*.atd")); + while ( bWorking ) + { + bWorking=finder.FindNextFile(); + + // load data + pTask = CreateTask(); + + try + { + CString strPath=finder.GetFilePath(); + + // load data file + icpf::archive ar; + ar.open(strPath, FA_READ); + ar.datablock_begin(); + pTask->Load(ar, true); + ar.datablock_end(); + ar.close(); + + // load progress file + strPath=strPath.Left(strPath.GetLength()-4); + strPath+=_T(".atp"); + icpf::archive ar2; + ar2.open(strPath, FA_READ); + ar2.datablock_begin(); + pTask->Load(ar2, false); + ar2.datablock_end(); + ar2.close(); + + // add read task to array + Add(pTask); + } + catch(icpf::exception&) + { + delete pTask; + } + } + finder.Close(); + + m_cs.Unlock(); +} + +void CTaskArray::TasksBeginProcessing() +{ + for (int i=0;iBeginProcessing(); +} + +void CTaskArray::TasksPauseProcessing() +{ + for (int i=0;iPauseProcessing(); +} + +void CTaskArray::TasksResumeProcessing() +{ + for (int i=0;iResumeProcessing(); +} + +void CTaskArray::TasksRestartProcessing() +{ + for (int i=0;iRestartProcessing(); +} + +bool CTaskArray::TasksRetryProcessing(bool bOnlyErrors/*=false*/, UINT uiInterval) +{ + bool bChanged=false; + for (int i=0;iRetryProcessing(bOnlyErrors, uiInterval)) + bChanged=true; + } + + return bChanged; +} + +void CTaskArray::TasksCancelProcessing() +{ + for (int i=0;iCancelProcessing(); +} + +ull_t CTaskArray::GetPosition() +{ + m_cs.Lock(); + ull_t rv=m_uhPosition; + m_cs.Unlock(); + + return rv; +} + +ull_t CTaskArray::GetRange() +{ + m_cs.Lock(); + ull_t rv=m_uhRange; + m_cs.Unlock(); + + return rv; +} + +int CTaskArray::GetPercent() +{ + int pos; + m_cs.Lock(); + if (m_uhRange != 0) + pos=static_cast((static_cast(m_uhPosition)*100.0)/static_cast(m_uhRange)); + else + if (GetSize() != 0) // if anything is in an array, but size of it is 0 + pos=100; + else + pos=0; + m_cs.Unlock(); + + return pos; +} + +UINT CTaskArray::GetOperationsPending() +{ + m_cs.Lock(); + UINT uiOP=m_uiOperationsPending; + m_cs.Unlock(); + return uiOP; +} + +bool CTaskArray::IsFinished() +{ + bool bFlag=true; + UINT uiStatus; + + m_cs.Lock(); + if (m_uiOperationsPending != 0) + bFlag=false; + else + { + for (int i=0;iGetStatus(); + bFlag=((uiStatus & ST_STEP_MASK) == ST_FINISHED || (uiStatus & ST_STEP_MASK) == ST_CANCELLED + || (uiStatus & ST_WORKING_MASK) == ST_PAUSED + || ((uiStatus & ST_WORKING_MASK) == ST_ERROR && !GetConfig()->get_bool(PP_CMAUTORETRYONERROR))); + } + } + + m_cs.Unlock(); + return bFlag; +} + +/////////////////////////////////////////////////////////////////////// +// CProcessingException + +CProcessingException::CProcessingException(int iType, CTask* pTask, UINT uiFmtID, DWORD dwError, ...) +{ + // std values + m_iType=iType; + m_pTask=pTask; + m_dwError=dwError; + + // format some text + CString strFormat=GetResManager()->LoadString(uiFmtID); + ExpandFormatString(&strFormat, dwError); + + // get param list + va_list marker; + va_start(marker, dwError); + m_strErrorDesc.FormatV(strFormat, marker); + va_end(marker); +} + +CProcessingException::CProcessingException(int iType, CTask* pTask, DWORD dwError, const tchar_t* pszDesc) +{ + // std values + m_iType=iType; + m_pTask=pTask; + m_dwError=dwError; + + // format some text + m_strErrorDesc = pszDesc; +} + +void CProcessingException::Cleanup() +{ + switch (m_pTask->GetStatus(ST_STEP_MASK)) + { + case ST_NULL_STATUS: + case ST_SEARCHING: + // get rif of m_files contents + m_pTask->FilesRemoveAll(); + + // save state of a task + m_pTask->Store(true); + m_pTask->Store(false); + + m_pTask->SetKilledFlag(); + m_pTask->CleanupAfterKill(); + + break; + case ST_COPYING: + case ST_DELETING: + switch (m_iType) + { + case E_ERROR: + m_pTask->SetStatus(ST_ERROR, ST_WORKING_MASK); + m_pTask->SetOsErrorCode(m_dwError, this->m_strErrorDesc); + break; + case E_CANCEL: + m_pTask->SetStatus(ST_CANCELLED, ST_STEP_MASK); + break; + } + + m_pTask->Store(false); + + m_pTask->SetKilledFlag(); + m_pTask->CleanupAfterKill(); + + break; + } +} Index: src/ch/Structs.h =================================================================== diff -u -rac7af753315c3538300a7c7966bbf0abb7b4f3c4 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Structs.h (.../Structs.h) (revision ac7af753315c3538300a7c7966bbf0abb7b4f3c4) +++ src/ch/Structs.h (.../Structs.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,440 +1,440 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STRUCTS_H__ -#define __STRUCTS_H__ - -#include "FileInfo.h" -#include "FileFilter.h" -#include "DestPath.h" -#include "DataBuffer.h" -//#include "LogFile.h" -#include "../libicpf/log.h" -#include "../libchcore/FeedbackHandlerBase.h" - -#define ST_NULL_STATUS 0x00000000 - -#define ST_WRITE_MASK 0x000fffff - -//------------------------------------ -#define ST_STEP_MASK 0x000000ff -#define ST_SEARCHING 0x00000001 -#define ST_COPYING 0x00000002 -#define ST_DELETING 0x00000003 -#define ST_FINISHED 0x00000004 -#define ST_CANCELLED 0x00000005 - -//------------------------------------ -#define ST_OPERATION_MASK 0x00000f00 -#define ST_COPY 0x00000100 -// moving - delete after copying all files -#define ST_MOVE 0x00000200 - -//------------------------------------ -#define ST_SPECIAL_MASK 0x0000f000 -// simultaneous flags -#define ST_IGNORE_DIRS 0x00001000 -#define ST_IGNORE_CONTENT 0x00002000 -#define ST_FORCE_DIRS 0x00004000 - -//------------------------------------ -#define ST_WORKING_MASK 0x000f0000 -#define ST_ERROR 0x000C0000 -#define ST_PAUSED 0x00080000 - -//------------------------------------ -#define ST_WAITING_MASK 0x00f00000 -#define ST_WAITING 0x00100000 - - -///////////////////////////////////////////////////////////////////////////// -// priority - -int PriorityToIndex(int nPriority); -int IndexToPriority(int nIndex); -int IndexToPriorityClass(int iIndex); -int PriorityClassToIndex(int iPriority); - -/////////////////////////////////////////////////////////////////////////// -// Exceptions - -#define E_KILL_REQUEST 0x00 -#define E_ERROR 0x01 -#define E_CANCEL 0x02 -#define E_PAUSE 0x03 - -///////////////////////////////////////////////////////////////////// -// CTask - -struct TASK_CREATE_DATA -{ - __int64 *pTasksProcessed; - __int64 *pTasksAll; - - UINT *puiOperationsPending; - LONG *plFinished; - - CCriticalSection* pcs; - - UINT (*pfnTaskProc)(LPVOID pParam); -}; - -// structure for gettings status of a task -struct TASK_DISPLAY_DATA -{ - CFileInfo m_fi; // fi at CurrIndex - int m_iCurrentBufferIndex; - int m_iIndex; - int m_iSize; - - CDestPath* m_pdpDestPath; - CFiltersArray* m_pafFilters; - - UINT m_uiStatus; - DWORD m_dwOsErrorCode; - CString m_strErrorDesc; - - const BUFFERSIZES* m_pbsSizes; - int m_nPriority; - - ull_t m_ullProcessedSize; - ull_t m_ullSizeAll; - int m_nPercent; - - long m_lTimeElapsed; - - unsigned char m_ucCurrentCopy; - unsigned char m_ucCopies; - - const CString* m_pstrUniqueName; // doesn't change from first setting - - TCHAR m_szStatusText[_MAX_PATH]; -}; - -struct TASK_MINI_DISPLAY_DATA -{ - CFileInfo m_fi; // fi at CurrIndex - - UINT m_uiStatus; - int m_nPercent; -}; - -class CTask -{ -public: - CTask(chcore::IFeedbackHandler* piFeedbackHandler, const TASK_CREATE_DATA *pCreateData); - ~CTask(); -public: - -// Attributes -public: - // m_clipboard - int AddClipboardData(CClipboardEntry* pEntry); - CClipboardEntry* GetClipboardData(int nIndex); - int GetClipboardDataSize(); - int ReplaceClipboardStrings(CString strOld, CString strNew); - - // m_files - int FilesAddDir(const CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, - const bool bRecurse, const bool bIncludeDirs); - int FilesAdd(CFileInfo fi); - CFileInfo FilesGetAt(int nIndex); - CFileInfo& FilesGetAtCurrentIndex(); - void FilesRemoveAll(); - int FilesGetSize(); - - // m_nCurrentIndex - void IncreaseCurrentIndex(); - int GetCurrentIndex(); - void SetCurrentIndex(int nIndex); - - // m_strDestPath - void SetDestPath(LPCTSTR lpszPath); - const CDestPath& GetDestPath(); - int GetDestDriveNumber(); - - // m_nStatus - void SetStatus(UINT nStatus, UINT nMask); - UINT GetStatus(UINT nMask=0xffffffff); - - // m_nBufferSize - void SetBufferSizes(const BUFFERSIZES* bsSizes); - const BUFFERSIZES* GetBufferSizes(); - int GetCurrentBufferIndex(); - - // m_pThread - // m_nPriority - int GetPriority(); - void SetPriority(int nPriority); - - // m_nProcessed - void IncreaseProcessedSize(__int64 nSize); - void SetProcessedSize(__int64 nSize); - __int64 GetProcessedSize(); - - // m_nAll - void SetAllSize(__int64 nSize); - __int64 GetAllSize(); - void CalcAllSize(); - - // m_pnTasksProcessed - void IncreaseProcessedTasksSize(__int64 nSize); - void DecreaseProcessedTasksSize(__int64 nSize); - - // m_pnTasksAll - void IncreaseAllTasksSize(__int64 nSize); - void DecreaseAllTasksSize(__int64 nSize); - - // m_bKill - void SetKillFlag(bool bKill=true); - bool GetKillFlag(); - - // m_bKilled - void SetKilledFlag(bool bKilled=true); - bool GetKilledFlag(); - - void KillThread(); - void CleanupAfterKill(); - - // m_strUniqueName - CString GetUniqueName(); - - void Load(icpf::archive& ar, bool bData); - void Store(bool bData); - - void BeginProcessing(); - - void PauseProcessing(); // pause - void ResumeProcessing(); // resume - bool RetryProcessing(bool bOnlyErrors=false, UINT uiInterval=0); // retry - void RestartProcessing(); // from beginning - void CancelProcessing(); // cancel - - void GetSnapshot(TASK_DISPLAY_DATA *pData); - void GetMiniSnapshot(TASK_MINI_DISPLAY_DATA *pData); - - void DeleteProgress(LPCTSTR lpszDirectory); - - void SetOsErrorCode(DWORD dwError, LPCTSTR lpszErrDesc); - void CalcProcessedSize(); - - void DecreaseOperationsPending(UINT uiBy=1); - void IncreaseOperationsPending(UINT uiBy=1); - - bool CanBegin(); - - void UpdateTime(); - - void SetFilters(const CFiltersArray* pFilters); - const CFiltersArray* GetFilters(); - - void SetCopies(unsigned char ucCopies); - unsigned char GetCopies(); - void SetCurrentCopy(unsigned char ucCopy); - unsigned char GetCurrentCopy(); - - CClipboardArray* GetClipboard() { return &m_clipboard; }; - - void SetLastProcessedIndex(int iIndex); - int GetLastProcessedIndex(); - -// CString GetLogName(); - - bool GetRequiredFreeSpace(ull_t *pi64Needed, ull_t *pi64Available); - - void SetTaskPath(const tchar_t* pszDir); - const tchar_t* GetTaskPath() const; - - chcore::IFeedbackHandler* GetFeedbackHandler() const { return m_piFeedbackHandler; } - -// Implementation -protected: - CClipboardArray m_clipboard; - CFileInfoArray m_files; - volatile int m_nCurrentIndex; - int m_iLastProcessedIndex; - - CDestPath m_dpDestPath; - - volatile UINT m_nStatus; - - // info about last error - DWORD m_lOsError; - CString m_strErrorDesc; - - // buffers - BUFFERSIZES m_bsSizes; - - CWinThread *m_pThread; - int m_nPriority; - - __int64 m_nProcessed; - __int64 m_nAll; - - __int64 *m_pnTasksProcessed; - __int64 *m_pnTasksAll; - - bool m_bQueued; // has operations pending for this task been increased ? - UINT *m_puiOperationsPending; - - volatile bool m_bKill; - volatile bool m_bKilled; - - // other stuff - CString m_strUniqueName; - - // mask (filter) - CFiltersArray m_afFilters; - - // copies count - unsigned char m_ucCopies; - unsigned char m_ucCurrentCopy; - - tstring_t m_strTaskBasePath; // base path at which the files will be stored - bool m_bSaved; // has the state been saved ('til next modification) - -public: - UINT m_uiResumeInterval; // works only if the thread is off - // time - long m_lTimeElapsed; // store - long m_lLastTime; // not store - - // feedback - chcore::IFeedbackHandler* m_piFeedbackHandler; - int m_iIdentical; - int m_iDestinationLess; - int m_iDestinationGreater; - int m_iMissingInput; - int m_iOutputError; - int m_iMoveFile; - - // ptr to count of currently started tasks - LONG* m_plFinished; - bool m_bForce; // if the continuation of tasks should be independent of limitation - bool m_bContinue; // used by ClipboardMonitorProc - -protected: - CCriticalSection* m_pcs; // protects *m_pnTasksProcessed & *m_pnTasksAll from external array - - UINT (*m_pfnTaskProc)(LPVOID pParam); // external function that processes this task -public: - void SetForceFlag(bool bFlag=true); - bool GetForceFlag(); - void SetContinueFlag(bool bFlag=true); - bool GetContinueFlag(); - -// CLogFile m_log; - icpf::log_file m_log; - mutable CCriticalSection m_cs; // protection for this class -}; - -/////////////////////////////////////////////////////////////////////////// -// CTaskArray - -class CTaskArray : public CArray -{ -public: - CTaskArray(); - ~CTaskArray(); - - void Create(chcore::IFeedbackHandlerFactory* piFeedbackHandlerFactory, UINT (*pfnTaskProc)(LPVOID pParam)); - - CTask* CreateTask(); - - int GetSize( ); - int GetUpperBound( ); - void SetSize( int nNewSize, int nGrowBy = -1 ); - - CTask* GetAt( int nIndex ); -// void SetAt( int nIndex, CTask* newElement ); - int Add( CTask* newElement ); - - void RemoveAt( int nIndex, int nCount = 1 ); - void RemoveAll(); - void RemoveAllFinished(); - void RemoveFinished(CTask** pSelTask); - - void SaveData(); - void SaveProgress(); - void LoadDataProgress(); - - void TasksBeginProcessing(); - void TasksPauseProcessing(); - void TasksResumeProcessing(); - void TasksRestartProcessing(); - bool TasksRetryProcessing(bool bOnlyErrors=false, UINT uiInterval=0); - void TasksCancelProcessing(); - - ull_t GetPosition(); - ull_t GetRange(); - int GetPercent(); - - UINT GetOperationsPending(); - void SetLimitOperations(UINT uiLimit); - UINT GetLimitOperations(); - - bool IsFinished(); - - void SetTasksDir(const tchar_t* pszPath) { m_strTasksDir = pszPath; } - -public: - __int64 m_uhRange, m_uhPosition; - tstring_t m_strTasksDir; - - UINT m_uiOperationsPending; // count of current operations - LONG m_lFinished; // count of finished tasks - - CCriticalSection m_cs; - TASK_CREATE_DATA m_tcd; - -protected: - chcore::IFeedbackHandlerFactory* m_piFeedbackFactory; -}; - -/////////////////////////////////////////////////////////////////////////// -// CLIPBOARDMONITORDATA - -struct CLIPBOARDMONITORDATA -{ - HWND m_hwnd; // hwnd to window - CTaskArray *m_pTasks; - - volatile bool bKill, bKilled; -}; - -/////////////////////////////////////////////////////////////////////////// -// CProcessingException - -class CProcessingException -{ -public: - CProcessingException(int iType, CTask* pTask) { m_iType=iType; m_pTask=pTask; m_dwError=0; }; - CProcessingException(int iType, CTask* pTask, UINT uiFmtID, DWORD dwError, ...); - CProcessingException(int iType, CTask* pTask, DWORD dwError, const tchar_t* pszDesc); - void Cleanup(); - -// Implementation -public: - int m_iType; // kill request, error, ... - CTask* m_pTask; - - CString m_strErrorDesc; - DWORD m_dwError; -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STRUCTS_H__ +#define __STRUCTS_H__ + +#include "FileInfo.h" +#include "FileFilter.h" +#include "DestPath.h" +#include "DataBuffer.h" +//#include "LogFile.h" +#include "../libicpf/log.h" +#include "../libchcore/FeedbackHandlerBase.h" + +#define ST_NULL_STATUS 0x00000000 + +#define ST_WRITE_MASK 0x000fffff + +//------------------------------------ +#define ST_STEP_MASK 0x000000ff +#define ST_SEARCHING 0x00000001 +#define ST_COPYING 0x00000002 +#define ST_DELETING 0x00000003 +#define ST_FINISHED 0x00000004 +#define ST_CANCELLED 0x00000005 + +//------------------------------------ +#define ST_OPERATION_MASK 0x00000f00 +#define ST_COPY 0x00000100 +// moving - delete after copying all files +#define ST_MOVE 0x00000200 + +//------------------------------------ +#define ST_SPECIAL_MASK 0x0000f000 +// simultaneous flags +#define ST_IGNORE_DIRS 0x00001000 +#define ST_IGNORE_CONTENT 0x00002000 +#define ST_FORCE_DIRS 0x00004000 + +//------------------------------------ +#define ST_WORKING_MASK 0x000f0000 +#define ST_ERROR 0x000C0000 +#define ST_PAUSED 0x00080000 + +//------------------------------------ +#define ST_WAITING_MASK 0x00f00000 +#define ST_WAITING 0x00100000 + + +///////////////////////////////////////////////////////////////////////////// +// priority + +int PriorityToIndex(int nPriority); +int IndexToPriority(int nIndex); +int IndexToPriorityClass(int iIndex); +int PriorityClassToIndex(int iPriority); + +/////////////////////////////////////////////////////////////////////////// +// Exceptions + +#define E_KILL_REQUEST 0x00 +#define E_ERROR 0x01 +#define E_CANCEL 0x02 +#define E_PAUSE 0x03 + +///////////////////////////////////////////////////////////////////// +// CTask + +struct TASK_CREATE_DATA +{ + __int64 *pTasksProcessed; + __int64 *pTasksAll; + + UINT *puiOperationsPending; + LONG *plFinished; + + CCriticalSection* pcs; + + UINT (*pfnTaskProc)(LPVOID pParam); +}; + +// structure for gettings status of a task +struct TASK_DISPLAY_DATA +{ + CFileInfo m_fi; // fi at CurrIndex + int m_iCurrentBufferIndex; + int m_iIndex; + int m_iSize; + + CDestPath* m_pdpDestPath; + CFiltersArray* m_pafFilters; + + UINT m_uiStatus; + DWORD m_dwOsErrorCode; + CString m_strErrorDesc; + + const BUFFERSIZES* m_pbsSizes; + int m_nPriority; + + ull_t m_ullProcessedSize; + ull_t m_ullSizeAll; + int m_nPercent; + + long m_lTimeElapsed; + + unsigned char m_ucCurrentCopy; + unsigned char m_ucCopies; + + const CString* m_pstrUniqueName; // doesn't change from first setting + + TCHAR m_szStatusText[_MAX_PATH]; +}; + +struct TASK_MINI_DISPLAY_DATA +{ + CFileInfo m_fi; // fi at CurrIndex + + UINT m_uiStatus; + int m_nPercent; +}; + +class CTask +{ +public: + CTask(chcore::IFeedbackHandler* piFeedbackHandler, const TASK_CREATE_DATA *pCreateData); + ~CTask(); +public: + +// Attributes +public: + // m_clipboard + int AddClipboardData(CClipboardEntry* pEntry); + CClipboardEntry* GetClipboardData(int nIndex); + int GetClipboardDataSize(); + int ReplaceClipboardStrings(CString strOld, CString strNew); + + // m_files + int FilesAddDir(const CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, + const bool bRecurse, const bool bIncludeDirs); + int FilesAdd(CFileInfo fi); + CFileInfo FilesGetAt(int nIndex); + CFileInfo& FilesGetAtCurrentIndex(); + void FilesRemoveAll(); + int FilesGetSize(); + + // m_nCurrentIndex + void IncreaseCurrentIndex(); + int GetCurrentIndex(); + void SetCurrentIndex(int nIndex); + + // m_strDestPath + void SetDestPath(LPCTSTR lpszPath); + const CDestPath& GetDestPath(); + int GetDestDriveNumber(); + + // m_nStatus + void SetStatus(UINT nStatus, UINT nMask); + UINT GetStatus(UINT nMask=0xffffffff); + + // m_nBufferSize + void SetBufferSizes(const BUFFERSIZES* bsSizes); + const BUFFERSIZES* GetBufferSizes(); + int GetCurrentBufferIndex(); + + // m_pThread + // m_nPriority + int GetPriority(); + void SetPriority(int nPriority); + + // m_nProcessed + void IncreaseProcessedSize(__int64 nSize); + void SetProcessedSize(__int64 nSize); + __int64 GetProcessedSize(); + + // m_nAll + void SetAllSize(__int64 nSize); + __int64 GetAllSize(); + void CalcAllSize(); + + // m_pnTasksProcessed + void IncreaseProcessedTasksSize(__int64 nSize); + void DecreaseProcessedTasksSize(__int64 nSize); + + // m_pnTasksAll + void IncreaseAllTasksSize(__int64 nSize); + void DecreaseAllTasksSize(__int64 nSize); + + // m_bKill + void SetKillFlag(bool bKill=true); + bool GetKillFlag(); + + // m_bKilled + void SetKilledFlag(bool bKilled=true); + bool GetKilledFlag(); + + void KillThread(); + void CleanupAfterKill(); + + // m_strUniqueName + CString GetUniqueName(); + + void Load(icpf::archive& ar, bool bData); + void Store(bool bData); + + void BeginProcessing(); + + void PauseProcessing(); // pause + void ResumeProcessing(); // resume + bool RetryProcessing(bool bOnlyErrors=false, UINT uiInterval=0); // retry + void RestartProcessing(); // from beginning + void CancelProcessing(); // cancel + + void GetSnapshot(TASK_DISPLAY_DATA *pData); + void GetMiniSnapshot(TASK_MINI_DISPLAY_DATA *pData); + + void DeleteProgress(LPCTSTR lpszDirectory); + + void SetOsErrorCode(DWORD dwError, LPCTSTR lpszErrDesc); + void CalcProcessedSize(); + + void DecreaseOperationsPending(UINT uiBy=1); + void IncreaseOperationsPending(UINT uiBy=1); + + bool CanBegin(); + + void UpdateTime(); + + void SetFilters(const CFiltersArray* pFilters); + const CFiltersArray* GetFilters(); + + void SetCopies(unsigned char ucCopies); + unsigned char GetCopies(); + void SetCurrentCopy(unsigned char ucCopy); + unsigned char GetCurrentCopy(); + + CClipboardArray* GetClipboard() { return &m_clipboard; }; + + void SetLastProcessedIndex(int iIndex); + int GetLastProcessedIndex(); + +// CString GetLogName(); + + bool GetRequiredFreeSpace(ull_t *pi64Needed, ull_t *pi64Available); + + void SetTaskPath(const tchar_t* pszDir); + const tchar_t* GetTaskPath() const; + + chcore::IFeedbackHandler* GetFeedbackHandler() const { return m_piFeedbackHandler; } + +// Implementation +protected: + CClipboardArray m_clipboard; + CFileInfoArray m_files; + volatile int m_nCurrentIndex; + int m_iLastProcessedIndex; + + CDestPath m_dpDestPath; + + volatile UINT m_nStatus; + + // info about last error + DWORD m_lOsError; + CString m_strErrorDesc; + + // buffers + BUFFERSIZES m_bsSizes; + + CWinThread *m_pThread; + int m_nPriority; + + __int64 m_nProcessed; + __int64 m_nAll; + + __int64 *m_pnTasksProcessed; + __int64 *m_pnTasksAll; + + bool m_bQueued; // has operations pending for this task been increased ? + UINT *m_puiOperationsPending; + + volatile bool m_bKill; + volatile bool m_bKilled; + + // other stuff + CString m_strUniqueName; + + // mask (filter) + CFiltersArray m_afFilters; + + // copies count + unsigned char m_ucCopies; + unsigned char m_ucCurrentCopy; + + tstring_t m_strTaskBasePath; // base path at which the files will be stored + bool m_bSaved; // has the state been saved ('til next modification) + +public: + UINT m_uiResumeInterval; // works only if the thread is off + // time + long m_lTimeElapsed; // store + long m_lLastTime; // not store + + // feedback + chcore::IFeedbackHandler* m_piFeedbackHandler; + int m_iIdentical; + int m_iDestinationLess; + int m_iDestinationGreater; + int m_iMissingInput; + int m_iOutputError; + int m_iMoveFile; + + // ptr to count of currently started tasks + LONG* m_plFinished; + bool m_bForce; // if the continuation of tasks should be independent of limitation + bool m_bContinue; // used by ClipboardMonitorProc + +protected: + CCriticalSection* m_pcs; // protects *m_pnTasksProcessed & *m_pnTasksAll from external array + + UINT (*m_pfnTaskProc)(LPVOID pParam); // external function that processes this task +public: + void SetForceFlag(bool bFlag=true); + bool GetForceFlag(); + void SetContinueFlag(bool bFlag=true); + bool GetContinueFlag(); + +// CLogFile m_log; + icpf::log_file m_log; + mutable CCriticalSection m_cs; // protection for this class +}; + +/////////////////////////////////////////////////////////////////////////// +// CTaskArray + +class CTaskArray : public CArray +{ +public: + CTaskArray(); + ~CTaskArray(); + + void Create(chcore::IFeedbackHandlerFactory* piFeedbackHandlerFactory, UINT (*pfnTaskProc)(LPVOID pParam)); + + CTask* CreateTask(); + + int GetSize( ); + int GetUpperBound( ); + void SetSize( int nNewSize, int nGrowBy = -1 ); + + CTask* GetAt( int nIndex ); +// void SetAt( int nIndex, CTask* newElement ); + int Add( CTask* newElement ); + + void RemoveAt( int nIndex, int nCount = 1 ); + void RemoveAll(); + void RemoveAllFinished(); + void RemoveFinished(CTask** pSelTask); + + void SaveData(); + void SaveProgress(); + void LoadDataProgress(); + + void TasksBeginProcessing(); + void TasksPauseProcessing(); + void TasksResumeProcessing(); + void TasksRestartProcessing(); + bool TasksRetryProcessing(bool bOnlyErrors=false, UINT uiInterval=0); + void TasksCancelProcessing(); + + ull_t GetPosition(); + ull_t GetRange(); + int GetPercent(); + + UINT GetOperationsPending(); + void SetLimitOperations(UINT uiLimit); + UINT GetLimitOperations(); + + bool IsFinished(); + + void SetTasksDir(const tchar_t* pszPath) { m_strTasksDir = pszPath; } + +public: + __int64 m_uhRange, m_uhPosition; + tstring_t m_strTasksDir; + + UINT m_uiOperationsPending; // count of current operations + LONG m_lFinished; // count of finished tasks + + CCriticalSection m_cs; + TASK_CREATE_DATA m_tcd; + +protected: + chcore::IFeedbackHandlerFactory* m_piFeedbackFactory; +}; + +/////////////////////////////////////////////////////////////////////////// +// CLIPBOARDMONITORDATA + +struct CLIPBOARDMONITORDATA +{ + HWND m_hwnd; // hwnd to window + CTaskArray *m_pTasks; + + volatile bool bKill, bKilled; +}; + +/////////////////////////////////////////////////////////////////////////// +// CProcessingException + +class CProcessingException +{ +public: + CProcessingException(int iType, CTask* pTask) { m_iType=iType; m_pTask=pTask; m_dwError=0; }; + CProcessingException(int iType, CTask* pTask, UINT uiFmtID, DWORD dwError, ...); + CProcessingException(int iType, CTask* pTask, DWORD dwError, const tchar_t* pszDesc); + void Cleanup(); + +// Implementation +public: + int m_iType; // kill request, error, ... + CTask* m_pTask; + + CString m_strErrorDesc; + DWORD m_dwError; +}; + #endif \ No newline at end of file Index: src/ch/Theme Helpers.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Theme Helpers.cpp (.../Theme Helpers.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/Theme Helpers.cpp (.../Theme Helpers.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,119 +1,119 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "Theme Helpers.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -CUxThemeSupport::CUxThemeSupport() -{ - m_hThemesDll=LoadLibrary(_T("UxTheme.dll")); -} - -CUxThemeSupport::~CUxThemeSupport() -{ - if (m_hThemesDll) - FreeLibrary(m_hThemesDll); -} - -HTHEME CUxThemeSupport::OpenThemeData(HWND hwnd, LPCWSTR pszClassList) -{ - ASSERT(m_hThemesDll); - if(!m_hThemesDll) - return NULL; - - PFNOPENTHEMEDATA pfnProc=(PFNOPENTHEMEDATA)GetProcAddress(m_hThemesDll, "OpenThemeData"); - - if (pfnProc) - return (*pfnProc)(hwnd, pszClassList); - else - return NULL; -} - -HRESULT CUxThemeSupport::CloseThemeData(HTHEME hTheme) -{ - ASSERT(m_hThemesDll); - if(!m_hThemesDll) - return E_FAIL; - - PFNCLOSETHEMEDATA pfnProc=(PFNCLOSETHEMEDATA)GetProcAddress(m_hThemesDll, "CloseThemeData"); - - if (pfnProc) - return (*pfnProc)(hTheme); - else - return E_UNEXPECTED; -} - -HRESULT CUxThemeSupport::DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect) -{ - ASSERT(m_hThemesDll); - if(!m_hThemesDll) - return E_FAIL; - - PFNDRAWTHEMEEDGE pfnProc=(PFNDRAWTHEMEEDGE)GetProcAddress(m_hThemesDll, "DrawThemeEdge"); - - if (pfnProc) - return (*pfnProc)(hTheme, hdc, iPartId, iStateId, pDestRect, uEdge, uFlags, pContentRect); - else - return E_UNEXPECTED; -} - -HRESULT CUxThemeSupport::DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect) -{ - ASSERT(m_hThemesDll); - if(!m_hThemesDll) - return E_FAIL; - - PFNDRAWTHEMEBACKGROUND pfnProc=(PFNDRAWTHEMEBACKGROUND)GetProcAddress(m_hThemesDll, "DrawThemeBackground"); - - if (pfnProc) - return (*pfnProc)(hTheme, hdc, iPartId, iStateId, pRect, pClipRect); - else - return E_UNEXPECTED; -} - -HRESULT CUxThemeSupport::DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT* prc) -{ - ASSERT(m_hThemesDll); - if(!m_hThemesDll) - return E_FAIL; - - PFNDRAWTHEMEPARENTBACKGROUND pfnProc=(PFNDRAWTHEMEPARENTBACKGROUND)GetProcAddress(m_hThemesDll, "DrawThemeParentBackground"); - - if (pfnProc) - return (*pfnProc)(hwnd, hdc, prc); - else - return E_UNEXPECTED; -} - -BOOL CUxThemeSupport::IsAppThemed() -{ - ASSERT(m_hThemesDll); - if(!m_hThemesDll) - return FALSE; - - PFNISAPPTHEMED pfnProc=(PFNISAPPTHEMED)GetProcAddress(m_hThemesDll, "IsAppThemed"); - - if (pfnProc) - return (*pfnProc)(); - else - return FALSE; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "Theme Helpers.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +CUxThemeSupport::CUxThemeSupport() +{ + m_hThemesDll=LoadLibrary(_T("UxTheme.dll")); +} + +CUxThemeSupport::~CUxThemeSupport() +{ + if (m_hThemesDll) + FreeLibrary(m_hThemesDll); +} + +HTHEME CUxThemeSupport::OpenThemeData(HWND hwnd, LPCWSTR pszClassList) +{ + ASSERT(m_hThemesDll); + if(!m_hThemesDll) + return NULL; + + PFNOPENTHEMEDATA pfnProc=(PFNOPENTHEMEDATA)GetProcAddress(m_hThemesDll, "OpenThemeData"); + + if (pfnProc) + return (*pfnProc)(hwnd, pszClassList); + else + return NULL; +} + +HRESULT CUxThemeSupport::CloseThemeData(HTHEME hTheme) +{ + ASSERT(m_hThemesDll); + if(!m_hThemesDll) + return E_FAIL; + + PFNCLOSETHEMEDATA pfnProc=(PFNCLOSETHEMEDATA)GetProcAddress(m_hThemesDll, "CloseThemeData"); + + if (pfnProc) + return (*pfnProc)(hTheme); + else + return E_UNEXPECTED; +} + +HRESULT CUxThemeSupport::DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect) +{ + ASSERT(m_hThemesDll); + if(!m_hThemesDll) + return E_FAIL; + + PFNDRAWTHEMEEDGE pfnProc=(PFNDRAWTHEMEEDGE)GetProcAddress(m_hThemesDll, "DrawThemeEdge"); + + if (pfnProc) + return (*pfnProc)(hTheme, hdc, iPartId, iStateId, pDestRect, uEdge, uFlags, pContentRect); + else + return E_UNEXPECTED; +} + +HRESULT CUxThemeSupport::DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect) +{ + ASSERT(m_hThemesDll); + if(!m_hThemesDll) + return E_FAIL; + + PFNDRAWTHEMEBACKGROUND pfnProc=(PFNDRAWTHEMEBACKGROUND)GetProcAddress(m_hThemesDll, "DrawThemeBackground"); + + if (pfnProc) + return (*pfnProc)(hTheme, hdc, iPartId, iStateId, pRect, pClipRect); + else + return E_UNEXPECTED; +} + +HRESULT CUxThemeSupport::DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT* prc) +{ + ASSERT(m_hThemesDll); + if(!m_hThemesDll) + return E_FAIL; + + PFNDRAWTHEMEPARENTBACKGROUND pfnProc=(PFNDRAWTHEMEPARENTBACKGROUND)GetProcAddress(m_hThemesDll, "DrawThemeParentBackground"); + + if (pfnProc) + return (*pfnProc)(hwnd, hdc, prc); + else + return E_UNEXPECTED; +} + +BOOL CUxThemeSupport::IsAppThemed() +{ + ASSERT(m_hThemesDll); + if(!m_hThemesDll) + return FALSE; + + PFNISAPPTHEMED pfnProc=(PFNISAPPTHEMED)GetProcAddress(m_hThemesDll, "IsAppThemed"); + + if (pfnProc) + return (*pfnProc)(); + else + return FALSE; +} Index: src/ch/Theme Helpers.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/Theme Helpers.h (.../Theme Helpers.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/Theme Helpers.h (.../Theme Helpers.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,172 +1,172 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __THEME_SUPPORT__ -#define __THEME_SUPPORT__ - -// definicja HTHEME - podobna do tej z UxTheme...h -#ifndef HTHEME -#define HTHEME HANDLE -#endif - -typedef HTHEME(_stdcall *PFNOPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList); -typedef HRESULT(_stdcall *PFNCLOSETHEMEDATA)(HTHEME hTheme); -typedef HRESULT(_stdcall *PFNDRAWTHEMEEDGE)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect); -typedef HRESULT(_stdcall *PFNDRAWTHEMEBACKGROUND)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect); -typedef HRESULT(_stdcall *PFNDRAWTHEMEPARENTBACKGROUND)(HWND hwnd, HDC hdc, RECT* prc); -typedef BOOL(_stdcall *PFNISAPPTHEMED)(); - -class CUxThemeSupport -{ -public: - CUxThemeSupport(); - ~CUxThemeSupport(); - - HTHEME OpenThemeData(HWND hwnd, LPCWSTR pszClassList); - HRESULT CloseThemeData(HTHEME hTheme); - - bool IsThemeSupported() { return m_hThemesDll != NULL; }; - BOOL IsAppThemed(); - - HRESULT DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect); - - HRESULT DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect); - HRESULT DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT* prc); - -/* HRESULT DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect); - -THEMEAPI GetThemeBackgroundContentRect(HTHEME hTheme, OPTIONAL HDC hdc, - int iPartId, int iStateId, const RECT *pBoundingRect, - OUT RECT *pContentRect); - -THEMEAPI GetThemeBackgroundExtent(HTHEME hTheme, OPTIONAL HDC hdc, - int iPartId, int iStateId, const RECT *pContentRect, - OUT RECT *pExtentRect); - -THEMEAPI GetThemeTextMetrics(HTHEME hTheme, OPTIONAL HDC hdc, - int iPartId, int iStateId, OUT TEXTMETRIC* ptm); - -THEMEAPI GetThemeBackgroundRegion(HTHEME hTheme, OPTIONAL HDC hdc, - int iPartId, int iStateId, const RECT *pRect, OUT HRGN *pRegion); - -THEMEAPI HitTestThemeBackground(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, - int iStateId, DWORD dwOptions, const RECT *pRect, OPTIONAL HRGN hrgn, - POINT ptTest, OUT WORD *pwHitTestCode); - -THEMEAPI DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, - const RECT *pDestRect, UINT uEdge, UINT uFlags, OPTIONAL OUT RECT *pContentRect); - -THEMEAPI DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId, - int iStateId, const RECT *pRect, HIMAGELIST himl, int iImageIndex); - -THEMEAPI_(BOOL) IsThemePartDefined(HTHEME hTheme, int iPartId, - int iStateId); - -THEMEAPI_(BOOL) IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, - int iPartId, int iStateId); - -THEMEAPI GetThemeColor(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT COLORREF *pColor); - -THEMEAPI GetThemeMetric(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, - int iStateId, int iPropId, OUT int *piVal); - -THEMEAPI GetThemeString(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars); - -THEMEAPI GetThemeBool(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT BOOL *pfVal); - -THEMEAPI GetThemeInt(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT int *piVal); - -THEMEAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT int *piVal); - -THEMEAPI GetThemePosition(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT POINT *pPoint); - -THEMEAPI GetThemeFont(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, - int iStateId, int iPropId, OUT LOGFONT *pFont); - -THEMEAPI GetThemeRect(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT RECT *pRect); - -THEMEAPI GetThemeMargins(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, - int iStateId, int iPropId, OPTIONAL RECT *prc, OUT MARGINS *pMargins); - -THEMEAPI GetThemeIntList(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT INTLIST *pIntList); - -THEMEAPI GetThemePropertyOrigin(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT enum PROPERTYORIGIN *pOrigin); - -THEMEAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName, - LPCWSTR pszSubIdList); - -THEMEAPI GetThemeFilename(HTHEME hTheme, int iPartId, - int iStateId, int iPropId, OUT LPWSTR pszThemeFileName, int cchMaxBuffChars); - -THEMEAPI_(COLORREF) GetThemeSysColor(HTHEME hTheme, int iColorId); - -THEMEAPI_(HBRUSH) GetThemeSysColorBrush(HTHEME hTheme, int iColorId); - -THEMEAPI_(BOOL) GetThemeSysBool(HTHEME hTheme, int iBoolId); - -THEMEAPI_(int) GetThemeSysSize(HTHEME hTheme, int iSizeId); - -THEMEAPI GetThemeSysFont(HTHEME hTheme, int iFontId, OUT LOGFONT *plf); - -THEMEAPI GetThemeSysString(HTHEME hTheme, int iStringId, - OUT LPWSTR pszStringBuff, int cchMaxStringChars); - -THEMEAPI GetThemeSysInt(HTHEME hTheme, int iIntId, int *piValue); - -THEMEAPI_(BOOL) IsThemeActive(); - - -THEMEAPI_(HTHEME) GetWindowTheme(HWND hwnd); - - -THEMEAPI EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags); - - -THEMEAPI_(BOOL) IsThemeDialogTextureEnabled(HWND hwnd); - -THEMEAPI_(DWORD) GetThemeAppProperties(); - -THEMEAPI_(void) SetThemeAppProperties(DWORD dwFlags); - -THEMEAPI GetCurrentThemeName( - OUT LPWSTR pszThemeFileName, int cchMaxNameChars, - OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars, - OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars); - -THEMEAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName, - LPCWSTR pszPropertyName, OUT LPWSTR pszValueBuff, int cchMaxValChars); - -THEMEAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, OPTIONAL RECT* prc); - -THEMEAPI EnableTheming(BOOL fEnable); -*/ -protected: - - HMODULE m_hThemesDll; -}; - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __THEME_SUPPORT__ +#define __THEME_SUPPORT__ + +// definicja HTHEME - podobna do tej z UxTheme...h +#ifndef HTHEME +#define HTHEME HANDLE +#endif + +typedef HTHEME(_stdcall *PFNOPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList); +typedef HRESULT(_stdcall *PFNCLOSETHEMEDATA)(HTHEME hTheme); +typedef HRESULT(_stdcall *PFNDRAWTHEMEEDGE)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect); +typedef HRESULT(_stdcall *PFNDRAWTHEMEBACKGROUND)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect); +typedef HRESULT(_stdcall *PFNDRAWTHEMEPARENTBACKGROUND)(HWND hwnd, HDC hdc, RECT* prc); +typedef BOOL(_stdcall *PFNISAPPTHEMED)(); + +class CUxThemeSupport +{ +public: + CUxThemeSupport(); + ~CUxThemeSupport(); + + HTHEME OpenThemeData(HWND hwnd, LPCWSTR pszClassList); + HRESULT CloseThemeData(HTHEME hTheme); + + bool IsThemeSupported() { return m_hThemesDll != NULL; }; + BOOL IsAppThemed(); + + HRESULT DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect); + + HRESULT DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect); + HRESULT DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT* prc); + +/* HRESULT DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect); + +THEMEAPI GetThemeBackgroundContentRect(HTHEME hTheme, OPTIONAL HDC hdc, + int iPartId, int iStateId, const RECT *pBoundingRect, + OUT RECT *pContentRect); + +THEMEAPI GetThemeBackgroundExtent(HTHEME hTheme, OPTIONAL HDC hdc, + int iPartId, int iStateId, const RECT *pContentRect, + OUT RECT *pExtentRect); + +THEMEAPI GetThemeTextMetrics(HTHEME hTheme, OPTIONAL HDC hdc, + int iPartId, int iStateId, OUT TEXTMETRIC* ptm); + +THEMEAPI GetThemeBackgroundRegion(HTHEME hTheme, OPTIONAL HDC hdc, + int iPartId, int iStateId, const RECT *pRect, OUT HRGN *pRegion); + +THEMEAPI HitTestThemeBackground(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, + int iStateId, DWORD dwOptions, const RECT *pRect, OPTIONAL HRGN hrgn, + POINT ptTest, OUT WORD *pwHitTestCode); + +THEMEAPI DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, + const RECT *pDestRect, UINT uEdge, UINT uFlags, OPTIONAL OUT RECT *pContentRect); + +THEMEAPI DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId, + int iStateId, const RECT *pRect, HIMAGELIST himl, int iImageIndex); + +THEMEAPI_(BOOL) IsThemePartDefined(HTHEME hTheme, int iPartId, + int iStateId); + +THEMEAPI_(BOOL) IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, + int iPartId, int iStateId); + +THEMEAPI GetThemeColor(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT COLORREF *pColor); + +THEMEAPI GetThemeMetric(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, + int iStateId, int iPropId, OUT int *piVal); + +THEMEAPI GetThemeString(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars); + +THEMEAPI GetThemeBool(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT BOOL *pfVal); + +THEMEAPI GetThemeInt(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT int *piVal); + +THEMEAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT int *piVal); + +THEMEAPI GetThemePosition(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT POINT *pPoint); + +THEMEAPI GetThemeFont(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, + int iStateId, int iPropId, OUT LOGFONT *pFont); + +THEMEAPI GetThemeRect(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT RECT *pRect); + +THEMEAPI GetThemeMargins(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, + int iStateId, int iPropId, OPTIONAL RECT *prc, OUT MARGINS *pMargins); + +THEMEAPI GetThemeIntList(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT INTLIST *pIntList); + +THEMEAPI GetThemePropertyOrigin(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT enum PROPERTYORIGIN *pOrigin); + +THEMEAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName, + LPCWSTR pszSubIdList); + +THEMEAPI GetThemeFilename(HTHEME hTheme, int iPartId, + int iStateId, int iPropId, OUT LPWSTR pszThemeFileName, int cchMaxBuffChars); + +THEMEAPI_(COLORREF) GetThemeSysColor(HTHEME hTheme, int iColorId); + +THEMEAPI_(HBRUSH) GetThemeSysColorBrush(HTHEME hTheme, int iColorId); + +THEMEAPI_(BOOL) GetThemeSysBool(HTHEME hTheme, int iBoolId); + +THEMEAPI_(int) GetThemeSysSize(HTHEME hTheme, int iSizeId); + +THEMEAPI GetThemeSysFont(HTHEME hTheme, int iFontId, OUT LOGFONT *plf); + +THEMEAPI GetThemeSysString(HTHEME hTheme, int iStringId, + OUT LPWSTR pszStringBuff, int cchMaxStringChars); + +THEMEAPI GetThemeSysInt(HTHEME hTheme, int iIntId, int *piValue); + +THEMEAPI_(BOOL) IsThemeActive(); + + +THEMEAPI_(HTHEME) GetWindowTheme(HWND hwnd); + + +THEMEAPI EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags); + + +THEMEAPI_(BOOL) IsThemeDialogTextureEnabled(HWND hwnd); + +THEMEAPI_(DWORD) GetThemeAppProperties(); + +THEMEAPI_(void) SetThemeAppProperties(DWORD dwFlags); + +THEMEAPI GetCurrentThemeName( + OUT LPWSTR pszThemeFileName, int cchMaxNameChars, + OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars, + OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars); + +THEMEAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName, + LPCWSTR pszPropertyName, OUT LPWSTR pszValueBuff, int cchMaxValChars); + +THEMEAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, OPTIONAL RECT* prc); + +THEMEAPI EnableTheming(BOOL fEnable); +*/ +protected: + + HMODULE m_hThemesDll; +}; + +#endif Index: src/ch/ThemedButton.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ThemedButton.cpp (.../ThemedButton.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ThemedButton.cpp (.../ThemedButton.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,142 +1,142 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ThemedButton.h" -#include "MemDC.h" -#include "Theme helpers.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CThemedButton - -// undefine this if use some internal windows files -#define TP_BUTTON 1 -#define TS_NORMAL 1 -#define TS_HOT 2 -#define TS_PRESSED 3 -#define TS_DISABLED 4 -#define TS_CHECKED 5 -#define TS_HOTCHECKED 6 - -CThemedButton::CThemedButton() -{ - m_bHovering=false; - m_iIndex=-1; - m_pilList=NULL; -} - -CThemedButton::~CThemedButton() -{ -} - - -BEGIN_MESSAGE_MAP(CThemedButton, CButton) - //{{AFX_MSG_MAP(CThemedButton) - ON_WM_MOUSEMOVE() - ON_WM_ERASEBKGND() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CThemedButton message handlers - -void CThemedButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) -{ - CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); - CMemDC memdc(pDC, &lpDrawItemStruct->rcItem); - - bool bPushed=(lpDrawItemStruct->itemState & ODS_SELECTED); - CRect rcItem=lpDrawItemStruct->rcItem; - - // draw button's frame - CUxThemeSupport uxTheme; - if (uxTheme.IsThemeSupported() && uxTheme.IsAppThemed()) - { - HTHEME ht=uxTheme.OpenThemeData(lpDrawItemStruct->hwndItem, L"TOOLBAR"); - - uxTheme.DrawThemeParentBackground(lpDrawItemStruct->hwndItem, memdc.GetSafeHdc(), &rcItem); - uxTheme.DrawThemeBackground(ht, memdc.GetSafeHdc(), TP_BUTTON, bPushed ? TS_PRESSED : (m_bHovering ? TS_HOT : TS_NORMAL), &rcItem, NULL); - - uxTheme.CloseThemeData(ht); - } - else - DrawFrameControl(memdc.GetSafeHdc(), &rcItem, DFC_BUTTON, DFCS_ADJUSTRECT | DFCS_BUTTONPUSH | (bPushed ? DFCS_PUSHED : 0)); - - ASSERT(m_pilList); // make sure the image list exist - if(m_pilList) - { - int cx=16, cy=16; - ImageList_GetIconSize(m_pilList->m_hImageList, &cx, &cy); - - CRect rcBtn; - GetClientRect(&rcBtn); - m_pilList->Draw(&memdc, m_iIndex, CPoint( ((rcBtn.Width()-cx)/2)+(bPushed ? 1 : 0), (rcBtn.Height()-cy)/2+(bPushed ? 1 : 0)), ILD_TRANSPARENT); - } -} - -void CThemedButton::OnMouseMove(UINT nFlags, CPoint point) -{ - if (!m_bHovering) - { - TRACKMOUSEEVENT tme; - tme.cbSize=sizeof(TRACKMOUSEEVENT); - tme.dwFlags=TME_LEAVE; - tme.dwHoverTime=0; - tme.hwndTrack=this->GetSafeHwnd(); - - ::_TrackMouseEvent(&tme); - - m_bHovering=true; - Invalidate(); - } - - CButton::OnMouseMove(nFlags, point); -} - -LRESULT CThemedButton::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) -{ - switch(message) - { - case WM_LBUTTONDBLCLK: - message=WM_LBUTTONDOWN; - break; - case WM_MOUSELEAVE: - m_bHovering=false; - Invalidate(); - break; - } - - return CButton::WindowProc(message, wParam, lParam); -} - -BOOL CThemedButton::OnEraseBkgnd(CDC* /*pDC*/) -{ - return FALSE;/*CButton::OnEraseBkgnd(pDC);*/ -} - -void CThemedButton::SetImage(CImageList *pImgList, int iIndex) -{ - m_pilList=pImgList; - m_iIndex=iIndex; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ThemedButton.h" +#include "MemDC.h" +#include "Theme helpers.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CThemedButton + +// undefine this if use some internal windows files +#define TP_BUTTON 1 +#define TS_NORMAL 1 +#define TS_HOT 2 +#define TS_PRESSED 3 +#define TS_DISABLED 4 +#define TS_CHECKED 5 +#define TS_HOTCHECKED 6 + +CThemedButton::CThemedButton() +{ + m_bHovering=false; + m_iIndex=-1; + m_pilList=NULL; +} + +CThemedButton::~CThemedButton() +{ +} + + +BEGIN_MESSAGE_MAP(CThemedButton, CButton) + //{{AFX_MSG_MAP(CThemedButton) + ON_WM_MOUSEMOVE() + ON_WM_ERASEBKGND() + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +///////////////////////////////////////////////////////////////////////////// +// CThemedButton message handlers + +void CThemedButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) +{ + CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC); + CMemDC memdc(pDC, &lpDrawItemStruct->rcItem); + + bool bPushed=(lpDrawItemStruct->itemState & ODS_SELECTED); + CRect rcItem=lpDrawItemStruct->rcItem; + + // draw button's frame + CUxThemeSupport uxTheme; + if (uxTheme.IsThemeSupported() && uxTheme.IsAppThemed()) + { + HTHEME ht=uxTheme.OpenThemeData(lpDrawItemStruct->hwndItem, L"TOOLBAR"); + + uxTheme.DrawThemeParentBackground(lpDrawItemStruct->hwndItem, memdc.GetSafeHdc(), &rcItem); + uxTheme.DrawThemeBackground(ht, memdc.GetSafeHdc(), TP_BUTTON, bPushed ? TS_PRESSED : (m_bHovering ? TS_HOT : TS_NORMAL), &rcItem, NULL); + + uxTheme.CloseThemeData(ht); + } + else + DrawFrameControl(memdc.GetSafeHdc(), &rcItem, DFC_BUTTON, DFCS_ADJUSTRECT | DFCS_BUTTONPUSH | (bPushed ? DFCS_PUSHED : 0)); + + ASSERT(m_pilList); // make sure the image list exist + if(m_pilList) + { + int cx=16, cy=16; + ImageList_GetIconSize(m_pilList->m_hImageList, &cx, &cy); + + CRect rcBtn; + GetClientRect(&rcBtn); + m_pilList->Draw(&memdc, m_iIndex, CPoint( ((rcBtn.Width()-cx)/2)+(bPushed ? 1 : 0), (rcBtn.Height()-cy)/2+(bPushed ? 1 : 0)), ILD_TRANSPARENT); + } +} + +void CThemedButton::OnMouseMove(UINT nFlags, CPoint point) +{ + if (!m_bHovering) + { + TRACKMOUSEEVENT tme; + tme.cbSize=sizeof(TRACKMOUSEEVENT); + tme.dwFlags=TME_LEAVE; + tme.dwHoverTime=0; + tme.hwndTrack=this->GetSafeHwnd(); + + ::_TrackMouseEvent(&tme); + + m_bHovering=true; + Invalidate(); + } + + CButton::OnMouseMove(nFlags, point); +} + +LRESULT CThemedButton::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_LBUTTONDBLCLK: + message=WM_LBUTTONDOWN; + break; + case WM_MOUSELEAVE: + m_bHovering=false; + Invalidate(); + break; + } + + return CButton::WindowProc(message, wParam, lParam); +} + +BOOL CThemedButton::OnEraseBkgnd(CDC* /*pDC*/) +{ + return FALSE;/*CButton::OnEraseBkgnd(pDC);*/ +} + +void CThemedButton::SetImage(CImageList *pImgList, int iIndex) +{ + m_pilList=pImgList; + m_iIndex=iIndex; +} Index: src/ch/ThemedButton.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ThemedButton.h (.../ThemedButton.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/ThemedButton.h (.../ThemedButton.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,71 +1,71 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __THEMEDBUTTON_H__ -#define __THEMEDBUTTON_H__ - -///////////////////////////////////////////////////////////////////////////// -// CThemedButton window - -class CThemedButton : public CButton -{ -// Construction -public: - CThemedButton(); - -// Attributes -public: - -// Operations -public: - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CThemedButton) - public: - virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); - protected: - virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); - //}}AFX_VIRTUAL - -// Implementation -public: - void SetImage(CImageList *pImgList, int iIndex); - virtual ~CThemedButton(); - - // Generated message map functions -protected: - bool m_bHovering; - - CImageList* m_pilList; - int m_iIndex; - - //{{AFX_MSG(CThemedButton) - afx_msg void OnMouseMove(UINT nFlags, CPoint point); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - //}}AFX_MSG - - DECLARE_MESSAGE_MAP() -}; - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __THEMEDBUTTON_H__ +#define __THEMEDBUTTON_H__ + +///////////////////////////////////////////////////////////////////////////// +// CThemedButton window + +class CThemedButton : public CButton +{ +// Construction +public: + CThemedButton(); + +// Attributes +public: + +// Operations +public: + +// Overrides + // ClassWizard generated virtual function overrides + //{{AFX_VIRTUAL(CThemedButton) + public: + virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); + protected: + virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam); + //}}AFX_VIRTUAL + +// Implementation +public: + void SetImage(CImageList *pImgList, int iIndex); + virtual ~CThemedButton(); + + // Generated message map functions +protected: + bool m_bHovering; + + CImageList* m_pilList; + int m_iIndex; + + //{{AFX_MSG(CThemedButton) + afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg BOOL OnEraseBkgnd(CDC* pDC); + //}}AFX_MSG + + DECLARE_MESSAGE_MAP() +}; + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/TrayIcon.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/TrayIcon.cpp (.../TrayIcon.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/TrayIcon.cpp (.../TrayIcon.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,161 +1,161 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "TrayIcon.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon construction/creation/destruction - -CTrayIcon::CTrayIcon() -{ - memset(&m_tnd, 0, sizeof(m_tnd)); - m_bHidden=false; -} - -CTrayIcon::CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) -{ - CreateIcon(hWnd, uClbMsg, szText, hIcon, uiID); - m_bHidden=false; -} - -bool CTrayIcon::CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) -{ - _ASSERT(hWnd); - - // load up the NOTIFYICONDATA structure - m_tnd.cbSize=sizeof(NOTIFYICONDATA); - m_tnd.hWnd=hWnd; - m_tnd.uID=uiID; - m_tnd.hIcon=hIcon; - m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; - m_tnd.uCallbackMessage=uClbMsg; - _tcsncpy(m_tnd.szTip, szText, 64); - size_t tLen=_tcslen(szText); - if (tLen < 64) - m_tnd.szTip[tLen]=_T('\0'); - else - m_tnd.szTip[63]=_T('\0'); - - // Set the tray icon - return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; -} - -CTrayIcon::~CTrayIcon() -{ - RemoveIcon(); -} - - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon icon manipulation - -void CTrayIcon::MoveToRight() -{ - HideIcon(); - ShowIcon(); -} - -void CTrayIcon::RemoveIcon() -{ - m_tnd.uFlags=0; - Shell_NotifyIcon(NIM_DELETE, &m_tnd); -} - -void CTrayIcon::HideIcon() -{ - if (!m_bHidden) - { - m_tnd.uFlags=NIF_ICON; - Shell_NotifyIcon (NIM_DELETE, &m_tnd); - m_bHidden=true; - } -} - -bool CTrayIcon::ShowIcon() -{ - if (m_bHidden) - { - m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; - m_bHidden=false; - return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; - } - return true; -} - -bool CTrayIcon::SetIcon(HICON hIcon) -{ - m_tnd.uFlags=NIF_ICON; - m_tnd.hIcon=hIcon; - - return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != 0; -} - -bool CTrayIcon::SetStandardIcon(LPCTSTR lpIconName) -{ - HICON hIcon=::LoadIcon(NULL, lpIconName); - return SetIcon(hIcon); -} - -HICON CTrayIcon::GetIcon() const -{ - return m_tnd.hIcon; -} - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon tooltip text manipulation - -bool CTrayIcon::SetTooltipText(LPCTSTR pszTip) -{ - m_tnd.uFlags = NIF_TIP; - _tcsncpy(m_tnd.szTip, pszTip, 64); - size_t tLen=_tcslen(pszTip); - if (tLen < 64) - m_tnd.szTip[tLen]=_T('\0'); - else - m_tnd.szTip[63]=_T('\0'); - - return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; -} - -void CTrayIcon::GetTooltipText(LPTSTR pszText) const -{ - _tcscpy(pszText, m_tnd.szTip); -} - -///////////////////////////////////////////////////////////////////////////// -// CTrayIcon notification window stuff - -bool CTrayIcon::SetNotificationWnd(HWND hWnd) -{ - _ASSERT(hWnd); - - m_tnd.hWnd=hWnd; - m_tnd.uFlags=0; - - return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; -} - -HWND CTrayIcon::GetNotificationWnd() const -{ - return m_tnd.hWnd; +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "TrayIcon.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon construction/creation/destruction + +CTrayIcon::CTrayIcon() +{ + memset(&m_tnd, 0, sizeof(m_tnd)); + m_bHidden=false; +} + +CTrayIcon::CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) +{ + CreateIcon(hWnd, uClbMsg, szText, hIcon, uiID); + m_bHidden=false; +} + +bool CTrayIcon::CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID) +{ + _ASSERT(hWnd); + + // load up the NOTIFYICONDATA structure + m_tnd.cbSize=sizeof(NOTIFYICONDATA); + m_tnd.hWnd=hWnd; + m_tnd.uID=uiID; + m_tnd.hIcon=hIcon; + m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; + m_tnd.uCallbackMessage=uClbMsg; + _tcsncpy(m_tnd.szTip, szText, 64); + size_t tLen=_tcslen(szText); + if (tLen < 64) + m_tnd.szTip[tLen]=_T('\0'); + else + m_tnd.szTip[63]=_T('\0'); + + // Set the tray icon + return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; +} + +CTrayIcon::~CTrayIcon() +{ + RemoveIcon(); +} + + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon icon manipulation + +void CTrayIcon::MoveToRight() +{ + HideIcon(); + ShowIcon(); +} + +void CTrayIcon::RemoveIcon() +{ + m_tnd.uFlags=0; + Shell_NotifyIcon(NIM_DELETE, &m_tnd); +} + +void CTrayIcon::HideIcon() +{ + if (!m_bHidden) + { + m_tnd.uFlags=NIF_ICON; + Shell_NotifyIcon (NIM_DELETE, &m_tnd); + m_bHidden=true; + } +} + +bool CTrayIcon::ShowIcon() +{ + if (m_bHidden) + { + m_tnd.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP; + m_bHidden=false; + return Shell_NotifyIcon(NIM_ADD, &m_tnd) != FALSE; + } + return true; +} + +bool CTrayIcon::SetIcon(HICON hIcon) +{ + m_tnd.uFlags=NIF_ICON; + m_tnd.hIcon=hIcon; + + return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != 0; +} + +bool CTrayIcon::SetStandardIcon(LPCTSTR lpIconName) +{ + HICON hIcon=::LoadIcon(NULL, lpIconName); + return SetIcon(hIcon); +} + +HICON CTrayIcon::GetIcon() const +{ + return m_tnd.hIcon; +} + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon tooltip text manipulation + +bool CTrayIcon::SetTooltipText(LPCTSTR pszTip) +{ + m_tnd.uFlags = NIF_TIP; + _tcsncpy(m_tnd.szTip, pszTip, 64); + size_t tLen=_tcslen(pszTip); + if (tLen < 64) + m_tnd.szTip[tLen]=_T('\0'); + else + m_tnd.szTip[63]=_T('\0'); + + return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; +} + +void CTrayIcon::GetTooltipText(LPTSTR pszText) const +{ + _tcscpy(pszText, m_tnd.szTip); +} + +///////////////////////////////////////////////////////////////////////////// +// CTrayIcon notification window stuff + +bool CTrayIcon::SetNotificationWnd(HWND hWnd) +{ + _ASSERT(hWnd); + + m_tnd.hWnd=hWnd; + m_tnd.uFlags=0; + + return Shell_NotifyIcon(NIM_MODIFY, &m_tnd) != FALSE; +} + +HWND CTrayIcon::GetNotificationWnd() const +{ + return m_tnd.hWnd; } \ No newline at end of file Index: src/ch/TrayIcon.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/TrayIcon.h (.../TrayIcon.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/TrayIcon.h (.../TrayIcon.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,60 +1,60 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -/* Code based on code written by Chris Maunder (Chris.Maunder@cbr.clw.csiro.au) */ - -#ifndef __TRAYICON_H__ -#define __TRAYICON_H__ - -#include "shellapi.h" - -class CTrayIcon -{ -public: -// construction/destruction - CTrayIcon(); - CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); - ~CTrayIcon(); - -//creation - bool CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); - -// ToolTip text handleing - bool SetTooltipText(LPCTSTR pszTip); - void GetTooltipText(LPTSTR pszText) const; - -// Icon handling - bool SetIcon(HICON hIcon); - bool SetStandardIcon(LPCTSTR lpIconName); - HICON GetIcon() const; - void HideIcon(); - bool ShowIcon(); - void RemoveIcon(); - void MoveToRight(); - -// Notifications - bool SetNotificationWnd(HWND hWnd); - HWND GetNotificationWnd() const; - -// Attribs -public: - bool m_bHidden; // Has the icon been hidden? - NOTIFYICONDATA m_tnd; -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +/* Code based on code written by Chris Maunder (Chris.Maunder@cbr.clw.csiro.au) */ + +#ifndef __TRAYICON_H__ +#define __TRAYICON_H__ + +#include "shellapi.h" + +class CTrayIcon +{ +public: +// construction/destruction + CTrayIcon(); + CTrayIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); + ~CTrayIcon(); + +//creation + bool CreateIcon(HWND hWnd, UINT uClbMsg, LPCTSTR szText, HICON hIcon, UINT uiID); + +// ToolTip text handleing + bool SetTooltipText(LPCTSTR pszTip); + void GetTooltipText(LPTSTR pszText) const; + +// Icon handling + bool SetIcon(HICON hIcon); + bool SetStandardIcon(LPCTSTR lpIconName); + HICON GetIcon() const; + void HideIcon(); + bool ShowIcon(); + void RemoveIcon(); + void MoveToRight(); + +// Notifications + bool SetNotificationWnd(HWND hWnd); + HWND GetNotificationWnd() const; + +// Attribs +public: + bool m_bHidden; // Has the icon been hidden? + NOTIFYICONDATA m_tnd; +}; + #endif \ No newline at end of file Index: src/ch/UpdateChecker.cpp =================================================================== diff -u -rd9982d1ee462dceb76298ef4216f0b6122d004a6 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/UpdateChecker.cpp (.../UpdateChecker.cpp) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) +++ src/ch/UpdateChecker.cpp (.../UpdateChecker.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,112 +1,112 @@ -#include "stdafx.h" -#include "UpdateChecker.h" -#include -#include -#include "../common/version.h" -#include "../libicpf/cfg.h" -#include "../libicpf/exception.h" - -CUpdateChecker::ECheckResult CUpdateChecker::CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta) -{ - try - { - CString strSite(pszSite); - strSite.Replace(_T("http://"), _T("")); - - CInternetSession inetSession; - CHttpConnection* pHttpConnection = inetSession.GetHttpConnection(strSite, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, 80); - if(!pHttpConnection) - { - m_eResult = eResult_Error; - return m_eResult; - } - - CString strAddr = _T("chver.ini"); - CHttpFile* pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strAddr); - if(!pHttpFile) - { - m_eResult = eResult_Error; - return m_eResult; - } - - if(!pHttpFile->SendRequest()) - { - m_eResult = eResult_Error; - return m_eResult; - } - - const size_t stBufferSize(65536); - tchar_t* pszBuf = new tchar_t[stBufferSize]; - UINT uiRD = pHttpFile->Read(pszBuf, stBufferSize - 1); - if(uiRD > 0) - pszBuf[uiRD] = _T('\0'); - - // convert text to unicode - icpf::config cfg(icpf::config::eIni); - const uint_t uiVersionNumeric = cfg.register_string(_t("Version/Numeric"), _t("")); - const uint_t uiVersionReadable = cfg.register_string(_t("Version/Human Readable"), _t("")); - const uint_t uiDownloadAddress = cfg.register_string(_t("Version/Download Address"), pszSite); - const uint_t uiBetaVersionNumeric = cfg.register_string(_t("Version/Numeric Beta"), _t("")); - const uint_t uiBetaVersionReadable = cfg.register_string(_t("Version/Human Readable Beta"), _t("")); - const uint_t uiBetaDownloadAddress = cfg.register_string(_t("Version/Download Address Beta"), pszSite); - try - { - cfg.read_from_buffer(pszBuf, uiRD); - } - catch(icpf::exception& e) - { - m_strLastError = e.get_desc(); - - delete [] pszBuf; - m_eResult = eResult_Error; - return m_eResult; - } - delete [] pszBuf; - - if(bCheckBeta) - { - m_strReadableVersion = cfg.get_string(uiBetaVersionReadable); - m_strNumericVersion = cfg.get_string(uiBetaVersionNumeric); - m_strDownloadAddress = cfg.get_string(uiBetaDownloadAddress); - } - - if(!bCheckBeta || m_strNumericVersion.IsEmpty()) - { - m_strNumericVersion = cfg.get_string(uiVersionNumeric); - m_strReadableVersion = cfg.get_string(uiVersionReadable); - m_strDownloadAddress = cfg.get_string(uiDownloadAddress); - } - - // and compare to current version - ushort_t usVer[4]; - if(_stscanf(m_strNumericVersion, _t("%hu.%hu.%hu.%hu"), &usVer[0], &usVer[1], &usVer[2], &usVer[3]) != 4) - { - TRACE(_T("Error parsing retrieved version number.")); - m_eResult = eResult_Error; - return m_eResult; - } - - ull_t ullCurrentVersion = ((ull_t)PRODUCT_VERSION1) << 48 | ((ull_t)PRODUCT_VERSION2) << 32 | ((ull_t)PRODUCT_VERSION3) << 16 | ((ull_t)PRODUCT_VERSION4); - ull_t ullSiteVersion = ((ull_t)usVer[0]) << 48 | ((ull_t)usVer[1]) << 32 | ((ull_t)usVer[2]) << 16 | ((ull_t)usVer[3]); - - if(ullCurrentVersion < ullSiteVersion) - m_eResult = eResult_VersionNewer; - else if(ullCurrentVersion == ullSiteVersion) - m_eResult = eResult_VersionCurrent; - else - m_eResult = eResult_VersionOlder; - - return m_eResult; - } - catch(CInternetException* e) - { - TCHAR* pszBuffer = m_strLastError.GetBufferSetLength(1024); - e->GetErrorMessage(pszBuffer, 1023); - pszBuffer[1023] = _T('\0'); - m_strLastError.ReleaseBuffer(); - m_strLastError.TrimRight(); - - m_eResult = eResult_Error; - return m_eResult; - } -} +#include "stdafx.h" +#include "UpdateChecker.h" +#include +#include +#include "../common/version.h" +#include "../libicpf/cfg.h" +#include "../libicpf/exception.h" + +CUpdateChecker::ECheckResult CUpdateChecker::CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta) +{ + try + { + CString strSite(pszSite); + strSite.Replace(_T("http://"), _T("")); + + CInternetSession inetSession; + CHttpConnection* pHttpConnection = inetSession.GetHttpConnection(strSite, INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, 80); + if(!pHttpConnection) + { + m_eResult = eResult_Error; + return m_eResult; + } + + CString strAddr = _T("chver.ini"); + CHttpFile* pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET, strAddr); + if(!pHttpFile) + { + m_eResult = eResult_Error; + return m_eResult; + } + + if(!pHttpFile->SendRequest()) + { + m_eResult = eResult_Error; + return m_eResult; + } + + const size_t stBufferSize(65536); + tchar_t* pszBuf = new tchar_t[stBufferSize]; + UINT uiRD = pHttpFile->Read(pszBuf, stBufferSize - 1); + if(uiRD > 0) + pszBuf[uiRD] = _T('\0'); + + // convert text to unicode + icpf::config cfg(icpf::config::eIni); + const uint_t uiVersionNumeric = cfg.register_string(_t("Version/Numeric"), _t("")); + const uint_t uiVersionReadable = cfg.register_string(_t("Version/Human Readable"), _t("")); + const uint_t uiDownloadAddress = cfg.register_string(_t("Version/Download Address"), pszSite); + const uint_t uiBetaVersionNumeric = cfg.register_string(_t("Version/Numeric Beta"), _t("")); + const uint_t uiBetaVersionReadable = cfg.register_string(_t("Version/Human Readable Beta"), _t("")); + const uint_t uiBetaDownloadAddress = cfg.register_string(_t("Version/Download Address Beta"), pszSite); + try + { + cfg.read_from_buffer(pszBuf, uiRD); + } + catch(icpf::exception& e) + { + m_strLastError = e.get_desc(); + + delete [] pszBuf; + m_eResult = eResult_Error; + return m_eResult; + } + delete [] pszBuf; + + if(bCheckBeta) + { + m_strReadableVersion = cfg.get_string(uiBetaVersionReadable); + m_strNumericVersion = cfg.get_string(uiBetaVersionNumeric); + m_strDownloadAddress = cfg.get_string(uiBetaDownloadAddress); + } + + if(!bCheckBeta || m_strNumericVersion.IsEmpty()) + { + m_strNumericVersion = cfg.get_string(uiVersionNumeric); + m_strReadableVersion = cfg.get_string(uiVersionReadable); + m_strDownloadAddress = cfg.get_string(uiDownloadAddress); + } + + // and compare to current version + ushort_t usVer[4]; + if(_stscanf(m_strNumericVersion, _t("%hu.%hu.%hu.%hu"), &usVer[0], &usVer[1], &usVer[2], &usVer[3]) != 4) + { + TRACE(_T("Error parsing retrieved version number.")); + m_eResult = eResult_Error; + return m_eResult; + } + + ull_t ullCurrentVersion = ((ull_t)PRODUCT_VERSION1) << 48 | ((ull_t)PRODUCT_VERSION2) << 32 | ((ull_t)PRODUCT_VERSION3) << 16 | ((ull_t)PRODUCT_VERSION4); + ull_t ullSiteVersion = ((ull_t)usVer[0]) << 48 | ((ull_t)usVer[1]) << 32 | ((ull_t)usVer[2]) << 16 | ((ull_t)usVer[3]); + + if(ullCurrentVersion < ullSiteVersion) + m_eResult = eResult_VersionNewer; + else if(ullCurrentVersion == ullSiteVersion) + m_eResult = eResult_VersionCurrent; + else + m_eResult = eResult_VersionOlder; + + return m_eResult; + } + catch(CInternetException* e) + { + TCHAR* pszBuffer = m_strLastError.GetBufferSetLength(1024); + e->GetErrorMessage(pszBuffer, 1023); + pszBuffer[1023] = _T('\0'); + m_strLastError.ReleaseBuffer(); + m_strLastError.TrimRight(); + + m_eResult = eResult_Error; + return m_eResult; + } +} Index: src/ch/UpdateChecker.h =================================================================== diff -u -rd9982d1ee462dceb76298ef4216f0b6122d004a6 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) +++ src/ch/UpdateChecker.h (.../UpdateChecker.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,37 +1,37 @@ -#ifndef __UPDATECHECKER_H__ -#define __UPDATECHECKER_H__ - -class CUpdateChecker -{ -public: - enum ECheckResult - { - eResult_Undefined, - eResult_VersionOlder, - eResult_VersionCurrent, - eResult_VersionNewer, - eResult_Error - }; -public: - CUpdateChecker() : m_eResult(eResult_Undefined) { }; - ~CUpdateChecker() { }; - - ECheckResult CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta); - - const tchar_t* GetNumericVersion() const { return (const tchar_t*)m_strNumericVersion; } - const tchar_t* GetReadableVersion() const { return (const tchar_t*)m_strReadableVersion; } - const tchar_t* GetLastError() const { return (const tchar_t*)m_strLastError; } - const tchar_t* GetDownloadAddress() const { return m_strDownloadAddress; } - - ECheckResult GetResult() const { return m_eResult; } - -protected: - CString m_strSite; - CString m_strLastError; - CString m_strNumericVersion; - CString m_strReadableVersion; - CString m_strDownloadAddress; - ECheckResult m_eResult; -}; - -#endif +#ifndef __UPDATECHECKER_H__ +#define __UPDATECHECKER_H__ + +class CUpdateChecker +{ +public: + enum ECheckResult + { + eResult_Undefined, + eResult_VersionOlder, + eResult_VersionCurrent, + eResult_VersionNewer, + eResult_Error + }; +public: + CUpdateChecker() : m_eResult(eResult_Undefined) { }; + ~CUpdateChecker() { }; + + ECheckResult CheckForUpdates(const tchar_t* pszSite, bool bCheckBeta); + + const tchar_t* GetNumericVersion() const { return (const tchar_t*)m_strNumericVersion; } + const tchar_t* GetReadableVersion() const { return (const tchar_t*)m_strReadableVersion; } + const tchar_t* GetLastError() const { return (const tchar_t*)m_strLastError; } + const tchar_t* GetDownloadAddress() const { return m_strDownloadAddress; } + + ECheckResult GetResult() const { return m_eResult; } + +protected: + CString m_strSite; + CString m_strLastError; + CString m_strNumericVersion; + CString m_strReadableVersion; + CString m_strDownloadAddress; + ECheckResult m_eResult; +}; + +#endif Index: src/ch/UpdaterDlg.cpp =================================================================== diff -u -rd9982d1ee462dceb76298ef4216f0b6122d004a6 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) +++ src/ch/UpdaterDlg.cpp (.../UpdaterDlg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,102 +1,102 @@ -// UpdaterDlg.cpp : implementation file -// - -#include "stdafx.h" -#include "ch.h" -#include "UpdaterDlg.h" -#include "UpdateChecker.h" -#include "../common/version.h" -#include - -#define UPDATER_TIMER 639 - -BEGIN_MESSAGE_MAP(CUpdaterDlg, ictranslate::CLanguageDialog) - ON_BN_CLICKED(IDC_OPEN_WEBPAGE_BUTTON, &CUpdaterDlg::OnBnClickedOpenWebpageButton) - ON_WM_TIMER() -END_MESSAGE_MAP() - - -// CUpdaterDlg dialog - -IMPLEMENT_DYNAMIC(CUpdaterDlg, ictranslate::CLanguageDialog) - -CUpdaterDlg::CUpdaterDlg(CWnd* pParent /*=NULL*/) -: ictranslate::CLanguageDialog(CUpdaterDlg::IDD, pParent) -{ -} - -CUpdaterDlg::~CUpdaterDlg() -{ -} - -void CUpdaterDlg::DoDataExchange(CDataExchange* pDX) -{ - ictranslate::CLanguageDialog::DoDataExchange(pDX); - DDX_Control(pDX, IDC_INFO_STATIC, m_ctlText); -} - -BOOL CUpdaterDlg::OnInitDialog() -{ - ictranslate::CLanguageDialog::OnInitDialog(); - - ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_UPDATER_WAITING_STRING)); - fmt.SetParam(_t("%site"), _T(PRODUCT_SITE)); - m_ctlText.SetWindowText(fmt); - - SetTimer(UPDATER_TIMER, 10, NULL); - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void CUpdaterDlg::StartChecking() -{ - m_ucChecker.CheckForUpdates(_T(PRODUCT_SITE), false); - - ictranslate::CResourceManager* pResManager = GetResManager(); - BOOST_ASSERT(pResManager); - if(!pResManager) - return; - - ictranslate::CFormat fmt; - - CString strFmt; - switch(m_ucChecker.GetResult()) - { - case CUpdateChecker::eResult_Error: - strFmt = pResManager->LoadString(IDS_UPDATER_ERROR_STRING); - break; - case CUpdateChecker::eResult_VersionNewer: - strFmt = pResManager->LoadString(IDS_UPDATER_NEW_VERSION_STRING); - break; - case CUpdateChecker::eResult_VersionCurrent: - strFmt = pResManager->LoadString(IDS_UPDATER_EQUAL_VERSION_STRING); - break; - case CUpdateChecker::eResult_VersionOlder: - strFmt = pResManager->LoadString(IDS_UPDATER_OLD_VERSION_STRING); - break; - } - - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%errdesc"), m_ucChecker.GetLastError()); - fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); - fmt.SetParam(_t("%officialver"), m_ucChecker.GetReadableVersion()); - - m_ctlText.SetWindowText(fmt); -} - -void CUpdaterDlg::OnBnClickedOpenWebpageButton() -{ - ShellExecute(NULL, _T("open"), m_ucChecker.GetDownloadAddress(), NULL, NULL, SW_SHOW); -} - -void CUpdaterDlg::OnTimer(UINT_PTR nIDEvent) -{ - if(nIDEvent == UPDATER_TIMER) - { - KillTimer(UPDATER_TIMER); - StartChecking(); - } - - CLanguageDialog::OnTimer(nIDEvent); -} +// UpdaterDlg.cpp : implementation file +// + +#include "stdafx.h" +#include "ch.h" +#include "UpdaterDlg.h" +#include "UpdateChecker.h" +#include "../common/version.h" +#include + +#define UPDATER_TIMER 639 + +BEGIN_MESSAGE_MAP(CUpdaterDlg, ictranslate::CLanguageDialog) + ON_BN_CLICKED(IDC_OPEN_WEBPAGE_BUTTON, &CUpdaterDlg::OnBnClickedOpenWebpageButton) + ON_WM_TIMER() +END_MESSAGE_MAP() + + +// CUpdaterDlg dialog + +IMPLEMENT_DYNAMIC(CUpdaterDlg, ictranslate::CLanguageDialog) + +CUpdaterDlg::CUpdaterDlg(CWnd* pParent /*=NULL*/) +: ictranslate::CLanguageDialog(CUpdaterDlg::IDD, pParent) +{ +} + +CUpdaterDlg::~CUpdaterDlg() +{ +} + +void CUpdaterDlg::DoDataExchange(CDataExchange* pDX) +{ + ictranslate::CLanguageDialog::DoDataExchange(pDX); + DDX_Control(pDX, IDC_INFO_STATIC, m_ctlText); +} + +BOOL CUpdaterDlg::OnInitDialog() +{ + ictranslate::CLanguageDialog::OnInitDialog(); + + ictranslate::CFormat fmt(GetResManager()->LoadString(IDS_UPDATER_WAITING_STRING)); + fmt.SetParam(_t("%site"), _T(PRODUCT_SITE)); + m_ctlText.SetWindowText(fmt); + + SetTimer(UPDATER_TIMER, 10, NULL); + + return TRUE; // return TRUE unless you set the focus to a control + // EXCEPTION: OCX Property Pages should return FALSE +} + +void CUpdaterDlg::StartChecking() +{ + m_ucChecker.CheckForUpdates(_T(PRODUCT_SITE), false); + + ictranslate::CResourceManager* pResManager = GetResManager(); + BOOST_ASSERT(pResManager); + if(!pResManager) + return; + + ictranslate::CFormat fmt; + + CString strFmt; + switch(m_ucChecker.GetResult()) + { + case CUpdateChecker::eResult_Error: + strFmt = pResManager->LoadString(IDS_UPDATER_ERROR_STRING); + break; + case CUpdateChecker::eResult_VersionNewer: + strFmt = pResManager->LoadString(IDS_UPDATER_NEW_VERSION_STRING); + break; + case CUpdateChecker::eResult_VersionCurrent: + strFmt = pResManager->LoadString(IDS_UPDATER_EQUAL_VERSION_STRING); + break; + case CUpdateChecker::eResult_VersionOlder: + strFmt = pResManager->LoadString(IDS_UPDATER_OLD_VERSION_STRING); + break; + } + + fmt.SetFormat(strFmt); + fmt.SetParam(_t("%errdesc"), m_ucChecker.GetLastError()); + fmt.SetParam(_t("%thisver"), _T(PRODUCT_VERSION)); + fmt.SetParam(_t("%officialver"), m_ucChecker.GetReadableVersion()); + + m_ctlText.SetWindowText(fmt); +} + +void CUpdaterDlg::OnBnClickedOpenWebpageButton() +{ + ShellExecute(NULL, _T("open"), m_ucChecker.GetDownloadAddress(), NULL, NULL, SW_SHOW); +} + +void CUpdaterDlg::OnTimer(UINT_PTR nIDEvent) +{ + if(nIDEvent == UPDATER_TIMER) + { + KillTimer(UPDATER_TIMER); + StartChecking(); + } + + CLanguageDialog::OnTimer(nIDEvent); +} Index: src/ch/UpdaterDlg.h =================================================================== diff -u -rd9982d1ee462dceb76298ef4216f0b6122d004a6 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/UpdaterDlg.h (.../UpdaterDlg.h) (revision d9982d1ee462dceb76298ef4216f0b6122d004a6) +++ src/ch/UpdaterDlg.h (.../UpdaterDlg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,33 +1,33 @@ -#pragma once -#include "afxwin.h" -#include "UpdateChecker.h" - -// CUpdaterDlg dialog - -class CUpdaterDlg : public ictranslate::CLanguageDialog -{ - DECLARE_DYNAMIC(CUpdaterDlg) - -public: - CUpdaterDlg(CWnd* pParent = NULL); // standard constructor - virtual ~CUpdaterDlg(); - - // Dialog Data - enum { IDD = IDD_UPDATER_DIALOG }; - - virtual BOOL OnInitDialog(); - void StartChecking(); - - afx_msg void OnBnClickedOpenWebpageButton(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - -protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - - DECLARE_MESSAGE_MAP() - -protected: - CStatic m_ctlText; - CUpdateChecker m_ucChecker; - -}; +#pragma once +#include "afxwin.h" +#include "UpdateChecker.h" + +// CUpdaterDlg dialog + +class CUpdaterDlg : public ictranslate::CLanguageDialog +{ + DECLARE_DYNAMIC(CUpdaterDlg) + +public: + CUpdaterDlg(CWnd* pParent = NULL); // standard constructor + virtual ~CUpdaterDlg(); + + // Dialog Data + enum { IDD = IDD_UPDATER_DIALOG }; + + virtual BOOL OnInitDialog(); + void StartChecking(); + + afx_msg void OnBnClickedOpenWebpageButton(); + afx_msg void OnTimer(UINT_PTR nIDEvent); + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + + DECLARE_MESSAGE_MAP() + +protected: + CStatic m_ctlText; + CUpdateChecker m_ucChecker; + +}; Index: src/ch/af_defs.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/af_defs.h (.../af_defs.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/af_defs.h (.../af_defs.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -15,12 +15,12 @@ * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __AFMESSAGES_H__ -#define __AFMESSAGES_H__ - -// messages used by the app framework's modules -#define WM_TRAYNOTIFY (WM_USER+0) -#define WM_CFGNOTIFY (WM_USER+1) - +***************************************************************************/ +#ifndef __AFMESSAGES_H__ +#define __AFMESSAGES_H__ + +// messages used by the app framework's modules +#define WM_TRAYNOTIFY (WM_USER+0) +#define WM_CFGNOTIFY (WM_USER+1) + #endif \ No newline at end of file Index: src/ch/btnIDs.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/btnIDs.h (.../btnIDs.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/btnIDs.h (.../btnIDs.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -15,21 +15,21 @@ * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __BUTTON_IDENTIFIERS_H__ -#define __BUTTON_IDENTIFIERS_H__ - -#define ID_IGNORE 0x10 -#define ID_IGNOREALL 0x11 -#define ID_COPYREST 0x12 -#define ID_COPYRESTALL 0x13 -#define ID_RECOPY 0x14 -#define ID_RECOPYALL 0x15 -#define ID_REFRESHENTRY 0x16 -#define ID_REFRESHENTRYALL 0x17 -#define ID_WAIT 0x18 -#define ID_RETRY 0x19 -#define ID_YESALL 0x1a -#define ID_NOALL 0x1b - +***************************************************************************/ +#ifndef __BUTTON_IDENTIFIERS_H__ +#define __BUTTON_IDENTIFIERS_H__ + +#define ID_IGNORE 0x10 +#define ID_IGNOREALL 0x11 +#define ID_COPYREST 0x12 +#define ID_COPYRESTALL 0x13 +#define ID_RECOPY 0x14 +#define ID_RECOPYALL 0x15 +#define ID_REFRESHENTRY 0x16 +#define ID_REFRESHENTRYALL 0x17 +#define ID_WAIT 0x18 +#define ID_RETRY 0x19 +#define ID_YESALL 0x1a +#define ID_NOALL 0x1b + #endif \ No newline at end of file Index: src/ch/ch.cpp =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ch.cpp (.../ch.cpp) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/ch/ch.cpp (.../ch.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,460 +1,460 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "ch.h" - -#include "CfgProperties.h" -#include "MainWnd.h" -#include "../common/ipcstructs.h" -#include -#include "CrashDlg.h" -#include "../common/version.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CCopyHandlerApp - -BEGIN_MESSAGE_MAP(CCopyHandlerApp, CWinApp) - //{{AFX_MSG_MAP(CCopyHandlerApp) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -CSharedConfigStruct* g_pscsShared; - -int iCount=98; -unsigned short msg[]={ 0x40d1, 0x4dcd, 0x8327, 0x6cdf, 0xb912, 0x017b, 0xac78, 0x1e04, 0x5637, - 0x1822, 0x0a69, 0x1b40, 0x4169, 0x504d, 0x80ff, 0x6c2f, 0xa612, 0x017e, - 0xac84, 0x1c8c, 0x552b, 0x16e2, 0x0a4b, 0x1dc0, 0x4179, 0x4d0d, 0x8337, - 0x6c4f, 0x6512, 0x0169, 0xac46, 0x1db4, 0x55cf, 0x1652, 0x0a0b, 0x1480, - 0x40fd, 0x470d, 0x822f, 0x6b8f, 0x6512, 0x013a, 0xac5a, 0x1d24, 0x5627, - 0x1762, 0x0a27, 0x1240, 0x40f5, 0x3f8d, 0x8187, 0x690f, 0x6e12, 0x011c, - 0xabc0, 0x1cc4, 0x567f, 0x1952, 0x0a51, 0x1cc0, 0x4175, 0x3ccd, 0x8377, - 0x6c5f, 0x6512, 0x0186, 0xac7c, 0x1e04, 0x5677, 0x1412, 0x0a61, 0x1d80, - 0x4169, 0x4e8d, 0x838f, 0x6c0f, 0xb212, 0x0132, 0xac7e, 0x1e54, 0x5593, - 0x1412, 0x0a15, 0x3dc0, 0x4195, 0x4e0d, 0x832f, 0x67ff, 0x9812, 0x0186, - 0xac6e, 0x1e4c, 0x5667, 0x1942, 0x0a47, 0x1f80, 0x4191, 0x4f8d }; - -int iOffCount=12; -unsigned char off[]={ 2, 6, 3, 4, 8, 0, 1, 3, 2, 4, 1, 6 }; -unsigned short _hash[]={ 0x3fad, 0x34cd, 0x7fff, 0x65ff, 0x4512, 0x0112, 0xabac, 0x1abc, 0x54ab, 0x1212, 0x0981, 0x0100 }; - -///////////////////////////////////////////////////////////////////////////// -// The one and only CCopyHandlerApp object - -CCopyHandlerApp theApp; - -///////////////////////////////////////////////////////////////////////////// -// CCopyHandlerApp construction - -// main routing function - routes any message that comes from modules -void ResManCallback(uint_t uiMsg) -{ - theApp.OnResManNotify(uiMsg); -} - -void ConfigPropertyChangedCallback(uint_t uiPropID, ptr_t /*pParam*/) -{ - theApp.OnConfigNotify(uiPropID); -} - -CCopyHandlerApp::CCopyHandlerApp() : - m_lfLog(), - m_cfgSettings(icpf::config::eIni), - m_piShellExtControl(NULL) -{ - m_pMainWindow=NULL; - - // this is the one-instance application - InitProtection(); -} - -CCopyHandlerApp::~CCopyHandlerApp() -{ - // Unmap shared memory from the process's address space. - UnmapViewOfFile((LPVOID)g_pscsShared); - - // Close the process's handle to the file-mapping object. - CloseHandle(m_hMapObject); - - if (m_pMainWindow) - { - ((CMainWnd*)m_pMainWindow)->DestroyWindow(); - delete m_pMainWindow; - m_pMainWnd=NULL; - } - - if(m_piShellExtControl) - { - m_piShellExtControl->Release(); - m_piShellExtControl = NULL; - } -} - -CCopyHandlerApp* GetApp() -{ - return &theApp; -} - -ictranslate::CResourceManager* GetResManager() -{ - return &theApp.m_resManager; -} - -chcore::engine_config* GetConfig() -{ - return &theApp.m_cfgSettings; -} -/* -CLogFile* GetLog() -{ - return &theApp.m_lfLog; -}*/ - -int MsgBox(UINT uiID, UINT nType, UINT nIDHelp) -{ - return AfxMessageBox(GetResManager()->LoadString(uiID), nType, nIDHelp); -} - -bool CCopyHandlerApp::UpdateHelpPaths() -{ - bool bChanged=false; // flag that'll be returned - if the paths has changed - - // generate the current filename - uses language from config - TCHAR szBuffer[_MAX_PATH]; - _tcscpy(szBuffer, _T("\\Help\\")); - ExpandPath(szBuffer); - _tcscat(szBuffer, GetResManager()->m_ld.GetHelpName()); - if(_tcscmp(szBuffer, m_pszHelpFilePath) != 0) - { - free((void*)m_pszHelpFilePath); - m_pszHelpFilePath = _tcsdup(szBuffer); - bChanged=true; - } - - return bChanged; -} - -///////////////////////////////////////////////////////////////////////////// -// CCopyHandlerApp initialization -#include "charvect.h" - -LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) -{ - // Step1 - should not fail - prepare some more unique crash name, create under the path where ch data exists - TCHAR szPath[_MAX_PATH]; - HRESULT hResult = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, szPath); - if(FAILED(hResult)) - _tcscpy(szPath, _T("c:\\")); - - CString strPath(szPath); - // make sure to create the required directories if they does not exist - strPath += _T("\\Copy Handler"); - CreateDirectory(strPath, NULL); - strPath += _T("\\Dumps"); - CreateDirectory(strPath, NULL); - - // current date - SYSTEMTIME st; - GetLocalTime(&st); - - TCHAR szName[_MAX_PATH]; - _sntprintf(szName, _MAX_PATH, _T("%s\\ch_crashdump_%hu-%hu-%hu_%hu_%hu_%hu_%hu.dmp"), (PCTSTR)strPath, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); - szPath[_MAX_PATH - 1] = _T('\0'); - - // Step 2 - create the crash dump in case anything happens later - bool bResult = false; - HANDLE hFile = CreateFile(szName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if(hFile != INVALID_HANDLE_VALUE) - { - MINIDUMP_EXCEPTION_INFORMATION mei; - mei.ThreadId = GetCurrentThreadId(); - mei.ExceptionPointers = ExceptionInfo; - mei.ClientPointers = TRUE; - - if(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithProcessThreadData, &mei, NULL, NULL)) - bResult = true; - } - - CloseHandle(hFile); - - CCrashDlg dlgCrash(bResult, szName); - dlgCrash.DoModal(); - - return EXCEPTION_EXECUTE_HANDLER; -} - -BOOL CCopyHandlerApp::InitInstance() -{ - // set the exception handler to catch the crash dumps - SetUnhandledExceptionFilter(&MyUnhandledExceptionFilter); - - HRESULT hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED); - if(FAILED(hResult)) - AfxMessageBox(_T("Cannot initialize COM, the application will now exit."), MB_ICONERROR | MB_OK); - - // InitCommonControlsEx() is required on Windows XP if an application - // manifest specifies use of ComCtl32.dll version 6 or later to enable - // visual styles. Otherwise, any window creation will fail. - INITCOMMONCONTROLSEX InitCtrls; - InitCtrls.dwSize = sizeof(InitCtrls); - // Set this to include all the common control classes you want to use - // in your application. - InitCtrls.dwICC = ICC_WIN95_CLASSES; - InitCommonControlsEx(&InitCtrls); - - EnableHtmlHelp(); - //SetHelpMode(afxHTMLHelp); - - CWinApp::InitInstance(); - - m_hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CSharedConfigStruct), _T("CHLMFile")); - if (m_hMapObject == NULL) - return FALSE; - - // Get a pointer to the file-mapped shared memory. - g_pscsShared=(CSharedConfigStruct*)MapViewOfFile(m_hMapObject, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); - if (g_pscsShared == NULL) - return FALSE; - - // load configuration - m_cfgSettings.set_callback(ConfigPropertyChangedCallback, NULL); - CString strPath; - // note that the GetProgramDataPath() below should create a directory; ExpandPath() could - // depend on the directory to be created earlier - if(GetProgramDataPath(strPath)) - { - strPath += _T("\\ch.ini"); - try - { - m_cfgSettings.read(strPath); - } - catch(...) - { - } - } - - // set working dir for the engine - m_cfgSettings.set_base_path(strPath); - // register all properties - RegisterProperties(&m_cfgSettings); - - // set this process class - HANDLE hProcess=GetCurrentProcess(); - ::SetPriorityClass(hProcess, (DWORD)m_cfgSettings.get_signed_num(PP_PPROCESSPRIORITYCLASS)); - - // set current language - TCHAR szPath[_MAX_PATH]; - m_resManager.Init(AfxGetInstanceHandle()); - m_resManager.SetCallback(ResManCallback); - m_cfgSettings.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); - TRACE(_T("Help path=%s\n"), szPath); - if (!m_resManager.SetLanguage(ExpandPath(szPath))) - { - TCHAR szData[2048]; - _sntprintf(szData, 2048, _T("Couldn't find the language file specified in configuration file:\n%s\nPlease correct this path to point the language file to use.\nProgram will now exit."), szPath); - AfxMessageBox(szData, MB_ICONSTOP | MB_OK); - return FALSE; - } - - UpdateHelpPaths(); - - // for dialogs - ictranslate::CLanguageDialog::SetResManager(&m_resManager); - - // initialize log file - m_cfgSettings.get_string(PP_LOGPATH, szPath, _MAX_PATH); - m_lfLog.init(ExpandPath(szPath), (int_t)m_cfgSettings.get_signed_num(PP_LOGMAXLIMIT), icpf::log_file::level_debug, false, false); - - // TODO: remove unused properties from configuration -/* m_lfLog.EnableLogging(m_cfgManager.GetBoolValue(PP_LOGENABLELOGGING)); - m_lfLog.SetPreciseLimiting(m_cfgManager.GetBoolValue(PP_LOGPRECISELIMITING)); - m_lfLog.SetSizeLimit(m_cfgManager.GetBoolValue(PP_LOGLIMITATION), m_cfgManager.GetIntValue(PP_LOGMAXLIMIT)); - m_lfLog.SetTruncateBufferSize(m_cfgManager.GetIntValue(PP_LOGTRUNCBUFFERSIZE)); - m_lfLog.Init(ExpandPath(szPath), GetResManager());*/ - -#ifndef _DEBUG // for easier writing the program - doesn't collide with std CH - // set "run with system" registry settings - SetAutorun(m_cfgSettings.get_bool(PP_PRELOADAFTERRESTART)); -#endif - - // check instance - return false if it's the second one - if (!IsFirstInstance()) - { - MsgBox(IDS_ONECOPY_STRING); - return FALSE; - } - - // calculate ch version - LONG lCHVersion = PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4; - - // check the version of shell extension - LONG lVersion = 0; - BSTR bstrVersion = NULL; - - hResult = CoCreateInstance(CLSID_CShellExtControl, NULL, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl); - if(SUCCEEDED(hResult) && !m_piShellExtControl) - hResult = E_FAIL; - if(SUCCEEDED(hResult)) - hResult = m_piShellExtControl->GetVersion(&lVersion, &bstrVersion); - if(SUCCEEDED(hResult) && lVersion == lCHVersion) - hResult = m_piShellExtControl->SetFlags(eShellExt_Enabled, eShellExt_Enabled); - if(FAILED(hResult) || lCHVersion != lVersion) - { - MsgBox(IDS_SHELL_EXTENSION_MISMATCH_STRING); - - if(m_piShellExtControl) - m_piShellExtControl->SetFlags(0, eShellExt_Enabled); - } - - if(bstrVersion) - ::SysFreeString(bstrVersion); - - // create main window - m_pMainWindow=new CMainWnd; - if (!((CMainWnd*)m_pMainWindow)->Create()) - return FALSE; // will be deleted at destructor - - m_pMainWnd = m_pMainWindow; - - return TRUE; -} - -bool CCopyHandlerApp::IsShellExtEnabled() const -{ - if(m_piShellExtControl) - { - LONG lFlags = 0; - HRESULT hResult = m_piShellExtControl->GetFlags(&lFlags); - if(SUCCEEDED(hResult) && (lFlags & eShellExt_Enabled)) - return true; - } - return false; -} - -void CCopyHandlerApp::OnConfigNotify(uint_t uiPropID) -{ - // is this language - if(uiPropID == PP_PLANGUAGE) - { - // update language in resource manager - TCHAR szPath[_MAX_PATH]; - m_cfgSettings.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); - m_resManager.SetLanguage(ExpandPath(szPath)); - } -} - -void CCopyHandlerApp::OnResManNotify(UINT uiType) -{ - if (uiType == RMNT_LANGCHANGE) - { - // language has been changed - close the current help file - if (UpdateHelpPaths()) - HtmlHelp(NULL, HH_CLOSE_ALL); - } -} - -HWND CCopyHandlerApp::HHelp(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD dwData) -{ - PCTSTR pszPath=NULL; - WIN32_FIND_DATA wfd; - HANDLE handle=::FindFirstFile(m_pszHelpFilePath, &wfd); - if (handle != INVALID_HANDLE_VALUE) - { - pszPath=m_pszHelpFilePath; - ::FindClose(handle); - } - - if (pszPath == NULL) - return NULL; - - if (pszFile != NULL) - { - TCHAR szAdd[2*_MAX_PATH]; - _tcscpy(szAdd, pszPath); - _tcscat(szAdd, pszFile); - return ::HtmlHelp(hwndCaller, szAdd, uCommand, dwData); - } - else - return ::HtmlHelp(hwndCaller, pszPath, uCommand, dwData); -} - -void CCopyHandlerApp::HtmlHelp(DWORD_PTR dwData, UINT nCmd) -{ - switch (nCmd) - { - case HH_DISPLAY_TOPIC: - case HH_HELP_CONTEXT: - { - HHelp(GetDesktopWindow(), NULL, nCmd, dwData); - break; - } - case HH_CLOSE_ALL: - ::HtmlHelp(NULL, NULL, HH_CLOSE_ALL, NULL); - break; - case HH_DISPLAY_TEXT_POPUP: - { - HELPINFO* pHelp=(HELPINFO*)dwData; - if ( pHelp->dwContextId == 0 || pHelp->iCtrlId == 0 - || ::GetWindowContextHelpId((HWND)pHelp->hItemHandle) == 0) - return; - - HH_POPUP hhp; - hhp.cbStruct=sizeof(HH_POPUP); - hhp.hinst=NULL; - hhp.idString=(pHelp->dwContextId & 0xffff); - hhp.pszText=NULL; - hhp.pt=pHelp->MousePos; - hhp.pt.y+=::GetSystemMetrics(SM_CYCURSOR)/2; - hhp.clrForeground=(COLORREF)-1; - hhp.clrBackground=(COLORREF)-1; - hhp.rcMargins.left=-1; - hhp.rcMargins.right=-1; - hhp.rcMargins.top=-1; - hhp.rcMargins.bottom=-1; - hhp.pszFont=_T("Tahoma, 8, , "); - - TCHAR szPath[_MAX_PATH]; - _sntprintf(szPath, _MAX_PATH, _T("::/%lu.txt"), (pHelp->dwContextId >> 16) & 0x7fff); - HHelp(GetDesktopWindow(), szPath, HH_DISPLAY_TEXT_POPUP, (DWORD)&hhp); - - break; - } - } -} - -int CCopyHandlerApp::ExitInstance() -{ - if(m_piShellExtControl) - { - m_piShellExtControl->Release(); - m_piShellExtControl = NULL; - } - CoUninitialize(); - - return __super::ExitInstance(); -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "ch.h" + +#include "CfgProperties.h" +#include "MainWnd.h" +#include "../common/ipcstructs.h" +#include +#include "CrashDlg.h" +#include "../common/version.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#ifdef _DEBUG +#define new DEBUG_NEW +#undef THIS_FILE +static char THIS_FILE[] = __FILE__; +#endif + +///////////////////////////////////////////////////////////////////////////// +// CCopyHandlerApp + +BEGIN_MESSAGE_MAP(CCopyHandlerApp, CWinApp) + //{{AFX_MSG_MAP(CCopyHandlerApp) + //}}AFX_MSG_MAP +END_MESSAGE_MAP() + +CSharedConfigStruct* g_pscsShared; + +int iCount=98; +unsigned short msg[]={ 0x40d1, 0x4dcd, 0x8327, 0x6cdf, 0xb912, 0x017b, 0xac78, 0x1e04, 0x5637, + 0x1822, 0x0a69, 0x1b40, 0x4169, 0x504d, 0x80ff, 0x6c2f, 0xa612, 0x017e, + 0xac84, 0x1c8c, 0x552b, 0x16e2, 0x0a4b, 0x1dc0, 0x4179, 0x4d0d, 0x8337, + 0x6c4f, 0x6512, 0x0169, 0xac46, 0x1db4, 0x55cf, 0x1652, 0x0a0b, 0x1480, + 0x40fd, 0x470d, 0x822f, 0x6b8f, 0x6512, 0x013a, 0xac5a, 0x1d24, 0x5627, + 0x1762, 0x0a27, 0x1240, 0x40f5, 0x3f8d, 0x8187, 0x690f, 0x6e12, 0x011c, + 0xabc0, 0x1cc4, 0x567f, 0x1952, 0x0a51, 0x1cc0, 0x4175, 0x3ccd, 0x8377, + 0x6c5f, 0x6512, 0x0186, 0xac7c, 0x1e04, 0x5677, 0x1412, 0x0a61, 0x1d80, + 0x4169, 0x4e8d, 0x838f, 0x6c0f, 0xb212, 0x0132, 0xac7e, 0x1e54, 0x5593, + 0x1412, 0x0a15, 0x3dc0, 0x4195, 0x4e0d, 0x832f, 0x67ff, 0x9812, 0x0186, + 0xac6e, 0x1e4c, 0x5667, 0x1942, 0x0a47, 0x1f80, 0x4191, 0x4f8d }; + +int iOffCount=12; +unsigned char off[]={ 2, 6, 3, 4, 8, 0, 1, 3, 2, 4, 1, 6 }; +unsigned short _hash[]={ 0x3fad, 0x34cd, 0x7fff, 0x65ff, 0x4512, 0x0112, 0xabac, 0x1abc, 0x54ab, 0x1212, 0x0981, 0x0100 }; + +///////////////////////////////////////////////////////////////////////////// +// The one and only CCopyHandlerApp object + +CCopyHandlerApp theApp; + +///////////////////////////////////////////////////////////////////////////// +// CCopyHandlerApp construction + +// main routing function - routes any message that comes from modules +void ResManCallback(uint_t uiMsg) +{ + theApp.OnResManNotify(uiMsg); +} + +void ConfigPropertyChangedCallback(uint_t uiPropID, ptr_t /*pParam*/) +{ + theApp.OnConfigNotify(uiPropID); +} + +CCopyHandlerApp::CCopyHandlerApp() : + m_lfLog(), + m_cfgSettings(icpf::config::eIni), + m_piShellExtControl(NULL) +{ + m_pMainWindow=NULL; + + // this is the one-instance application + InitProtection(); +} + +CCopyHandlerApp::~CCopyHandlerApp() +{ + // Unmap shared memory from the process's address space. + UnmapViewOfFile((LPVOID)g_pscsShared); + + // Close the process's handle to the file-mapping object. + CloseHandle(m_hMapObject); + + if (m_pMainWindow) + { + ((CMainWnd*)m_pMainWindow)->DestroyWindow(); + delete m_pMainWindow; + m_pMainWnd=NULL; + } + + if(m_piShellExtControl) + { + m_piShellExtControl->Release(); + m_piShellExtControl = NULL; + } +} + +CCopyHandlerApp* GetApp() +{ + return &theApp; +} + +ictranslate::CResourceManager* GetResManager() +{ + return &theApp.m_resManager; +} + +chcore::engine_config* GetConfig() +{ + return &theApp.m_cfgSettings; +} +/* +CLogFile* GetLog() +{ + return &theApp.m_lfLog; +}*/ + +int MsgBox(UINT uiID, UINT nType, UINT nIDHelp) +{ + return AfxMessageBox(GetResManager()->LoadString(uiID), nType, nIDHelp); +} + +bool CCopyHandlerApp::UpdateHelpPaths() +{ + bool bChanged=false; // flag that'll be returned - if the paths has changed + + // generate the current filename - uses language from config + TCHAR szBuffer[_MAX_PATH]; + _tcscpy(szBuffer, _T("\\Help\\")); + ExpandPath(szBuffer); + _tcscat(szBuffer, GetResManager()->m_ld.GetHelpName()); + if(_tcscmp(szBuffer, m_pszHelpFilePath) != 0) + { + free((void*)m_pszHelpFilePath); + m_pszHelpFilePath = _tcsdup(szBuffer); + bChanged=true; + } + + return bChanged; +} + +///////////////////////////////////////////////////////////////////////////// +// CCopyHandlerApp initialization +#include "charvect.h" + +LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo) +{ + // Step1 - should not fail - prepare some more unique crash name, create under the path where ch data exists + TCHAR szPath[_MAX_PATH]; + HRESULT hResult = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, szPath); + if(FAILED(hResult)) + _tcscpy(szPath, _T("c:\\")); + + CString strPath(szPath); + // make sure to create the required directories if they does not exist + strPath += _T("\\Copy Handler"); + CreateDirectory(strPath, NULL); + strPath += _T("\\Dumps"); + CreateDirectory(strPath, NULL); + + // current date + SYSTEMTIME st; + GetLocalTime(&st); + + TCHAR szName[_MAX_PATH]; + _sntprintf(szName, _MAX_PATH, _T("%s\\ch_crashdump_%hu-%hu-%hu_%hu_%hu_%hu_%hu.dmp"), (PCTSTR)strPath, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); + szPath[_MAX_PATH - 1] = _T('\0'); + + // Step 2 - create the crash dump in case anything happens later + bool bResult = false; + HANDLE hFile = CreateFile(szName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if(hFile != INVALID_HANDLE_VALUE) + { + MINIDUMP_EXCEPTION_INFORMATION mei; + mei.ThreadId = GetCurrentThreadId(); + mei.ExceptionPointers = ExceptionInfo; + mei.ClientPointers = TRUE; + + if(MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithProcessThreadData, &mei, NULL, NULL)) + bResult = true; + } + + CloseHandle(hFile); + + CCrashDlg dlgCrash(bResult, szName); + dlgCrash.DoModal(); + + return EXCEPTION_EXECUTE_HANDLER; +} + +BOOL CCopyHandlerApp::InitInstance() +{ + // set the exception handler to catch the crash dumps + SetUnhandledExceptionFilter(&MyUnhandledExceptionFilter); + + HRESULT hResult = CoInitializeEx(NULL, COINIT_MULTITHREADED); + if(FAILED(hResult)) + AfxMessageBox(_T("Cannot initialize COM, the application will now exit."), MB_ICONERROR | MB_OK); + + // InitCommonControlsEx() is required on Windows XP if an application + // manifest specifies use of ComCtl32.dll version 6 or later to enable + // visual styles. Otherwise, any window creation will fail. + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // Set this to include all the common control classes you want to use + // in your application. + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + EnableHtmlHelp(); + //SetHelpMode(afxHTMLHelp); + + CWinApp::InitInstance(); + + m_hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(CSharedConfigStruct), _T("CHLMFile")); + if (m_hMapObject == NULL) + return FALSE; + + // Get a pointer to the file-mapped shared memory. + g_pscsShared=(CSharedConfigStruct*)MapViewOfFile(m_hMapObject, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); + if (g_pscsShared == NULL) + return FALSE; + + // load configuration + m_cfgSettings.set_callback(ConfigPropertyChangedCallback, NULL); + CString strPath; + // note that the GetProgramDataPath() below should create a directory; ExpandPath() could + // depend on the directory to be created earlier + if(GetProgramDataPath(strPath)) + { + strPath += _T("\\ch.ini"); + try + { + m_cfgSettings.read(strPath); + } + catch(...) + { + } + } + + // set working dir for the engine + m_cfgSettings.set_base_path(strPath); + // register all properties + RegisterProperties(&m_cfgSettings); + + // set this process class + HANDLE hProcess=GetCurrentProcess(); + ::SetPriorityClass(hProcess, (DWORD)m_cfgSettings.get_signed_num(PP_PPROCESSPRIORITYCLASS)); + + // set current language + TCHAR szPath[_MAX_PATH]; + m_resManager.Init(AfxGetInstanceHandle()); + m_resManager.SetCallback(ResManCallback); + m_cfgSettings.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); + TRACE(_T("Help path=%s\n"), szPath); + if (!m_resManager.SetLanguage(ExpandPath(szPath))) + { + TCHAR szData[2048]; + _sntprintf(szData, 2048, _T("Couldn't find the language file specified in configuration file:\n%s\nPlease correct this path to point the language file to use.\nProgram will now exit."), szPath); + AfxMessageBox(szData, MB_ICONSTOP | MB_OK); + return FALSE; + } + + UpdateHelpPaths(); + + // for dialogs + ictranslate::CLanguageDialog::SetResManager(&m_resManager); + + // initialize log file + m_cfgSettings.get_string(PP_LOGPATH, szPath, _MAX_PATH); + m_lfLog.init(ExpandPath(szPath), (int_t)m_cfgSettings.get_signed_num(PP_LOGMAXLIMIT), icpf::log_file::level_debug, false, false); + + // TODO: remove unused properties from configuration +/* m_lfLog.EnableLogging(m_cfgManager.GetBoolValue(PP_LOGENABLELOGGING)); + m_lfLog.SetPreciseLimiting(m_cfgManager.GetBoolValue(PP_LOGPRECISELIMITING)); + m_lfLog.SetSizeLimit(m_cfgManager.GetBoolValue(PP_LOGLIMITATION), m_cfgManager.GetIntValue(PP_LOGMAXLIMIT)); + m_lfLog.SetTruncateBufferSize(m_cfgManager.GetIntValue(PP_LOGTRUNCBUFFERSIZE)); + m_lfLog.Init(ExpandPath(szPath), GetResManager());*/ + +#ifndef _DEBUG // for easier writing the program - doesn't collide with std CH + // set "run with system" registry settings + SetAutorun(m_cfgSettings.get_bool(PP_PRELOADAFTERRESTART)); +#endif + + // check instance - return false if it's the second one + if (!IsFirstInstance()) + { + MsgBox(IDS_ONECOPY_STRING); + return FALSE; + } + + // calculate ch version + LONG lCHVersion = PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4; + + // check the version of shell extension + LONG lVersion = 0; + BSTR bstrVersion = NULL; + + hResult = CoCreateInstance(CLSID_CShellExtControl, NULL, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl); + if(SUCCEEDED(hResult) && !m_piShellExtControl) + hResult = E_FAIL; + if(SUCCEEDED(hResult)) + hResult = m_piShellExtControl->GetVersion(&lVersion, &bstrVersion); + if(SUCCEEDED(hResult) && lVersion == lCHVersion) + hResult = m_piShellExtControl->SetFlags(eShellExt_Enabled, eShellExt_Enabled); + if(FAILED(hResult) || lCHVersion != lVersion) + { + MsgBox(IDS_SHELL_EXTENSION_MISMATCH_STRING); + + if(m_piShellExtControl) + m_piShellExtControl->SetFlags(0, eShellExt_Enabled); + } + + if(bstrVersion) + ::SysFreeString(bstrVersion); + + // create main window + m_pMainWindow=new CMainWnd; + if (!((CMainWnd*)m_pMainWindow)->Create()) + return FALSE; // will be deleted at destructor + + m_pMainWnd = m_pMainWindow; + + return TRUE; +} + +bool CCopyHandlerApp::IsShellExtEnabled() const +{ + if(m_piShellExtControl) + { + LONG lFlags = 0; + HRESULT hResult = m_piShellExtControl->GetFlags(&lFlags); + if(SUCCEEDED(hResult) && (lFlags & eShellExt_Enabled)) + return true; + } + return false; +} + +void CCopyHandlerApp::OnConfigNotify(uint_t uiPropID) +{ + // is this language + if(uiPropID == PP_PLANGUAGE) + { + // update language in resource manager + TCHAR szPath[_MAX_PATH]; + m_cfgSettings.get_string(PP_PLANGUAGE, szPath, _MAX_PATH); + m_resManager.SetLanguage(ExpandPath(szPath)); + } +} + +void CCopyHandlerApp::OnResManNotify(UINT uiType) +{ + if (uiType == RMNT_LANGCHANGE) + { + // language has been changed - close the current help file + if (UpdateHelpPaths()) + HtmlHelp(NULL, HH_CLOSE_ALL); + } +} + +HWND CCopyHandlerApp::HHelp(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD dwData) +{ + PCTSTR pszPath=NULL; + WIN32_FIND_DATA wfd; + HANDLE handle=::FindFirstFile(m_pszHelpFilePath, &wfd); + if (handle != INVALID_HANDLE_VALUE) + { + pszPath=m_pszHelpFilePath; + ::FindClose(handle); + } + + if (pszPath == NULL) + return NULL; + + if (pszFile != NULL) + { + TCHAR szAdd[2*_MAX_PATH]; + _tcscpy(szAdd, pszPath); + _tcscat(szAdd, pszFile); + return ::HtmlHelp(hwndCaller, szAdd, uCommand, dwData); + } + else + return ::HtmlHelp(hwndCaller, pszPath, uCommand, dwData); +} + +void CCopyHandlerApp::HtmlHelp(DWORD_PTR dwData, UINT nCmd) +{ + switch (nCmd) + { + case HH_DISPLAY_TOPIC: + case HH_HELP_CONTEXT: + { + HHelp(GetDesktopWindow(), NULL, nCmd, dwData); + break; + } + case HH_CLOSE_ALL: + ::HtmlHelp(NULL, NULL, HH_CLOSE_ALL, NULL); + break; + case HH_DISPLAY_TEXT_POPUP: + { + HELPINFO* pHelp=(HELPINFO*)dwData; + if ( pHelp->dwContextId == 0 || pHelp->iCtrlId == 0 + || ::GetWindowContextHelpId((HWND)pHelp->hItemHandle) == 0) + return; + + HH_POPUP hhp; + hhp.cbStruct=sizeof(HH_POPUP); + hhp.hinst=NULL; + hhp.idString=(pHelp->dwContextId & 0xffff); + hhp.pszText=NULL; + hhp.pt=pHelp->MousePos; + hhp.pt.y+=::GetSystemMetrics(SM_CYCURSOR)/2; + hhp.clrForeground=(COLORREF)-1; + hhp.clrBackground=(COLORREF)-1; + hhp.rcMargins.left=-1; + hhp.rcMargins.right=-1; + hhp.rcMargins.top=-1; + hhp.rcMargins.bottom=-1; + hhp.pszFont=_T("Tahoma, 8, , "); + + TCHAR szPath[_MAX_PATH]; + _sntprintf(szPath, _MAX_PATH, _T("::/%lu.txt"), (pHelp->dwContextId >> 16) & 0x7fff); + HHelp(GetDesktopWindow(), szPath, HH_DISPLAY_TEXT_POPUP, (DWORD)&hhp); + + break; + } + } +} + +int CCopyHandlerApp::ExitInstance() +{ + if(m_piShellExtControl) + { + m_piShellExtControl->Release(); + m_piShellExtControl = NULL; + } + CoUninitialize(); + + return __super::ExitInstance(); +} Index: src/ch/ch.h =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/ch.h (.../ch.h) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/ch/ch.h (.../ch.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,103 +1,103 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __COPYHANDLER_H__ -#define __COPYHANDLER_H__ - -#ifndef __AFXWIN_H__ - #error include 'stdafx.h' before including this file for PCH -#endif - -#include "resource.h" // main symbols -#include "AppHelper.h" -#include "CfgProperties.h" -#include "../chext/chext.h" -//#include "LogFile.h" -#include "../libicpf/log.h" -#include "../libchcore/EngineCfg.h" -#include "../libictranslate/ResourceManager.h" - -using namespace std; - -///////////////////////////////////////////////////////////////////////////// -// CCopyHandlerApp: -// See CopyHandler.cpp for the implementation of this class -// - -class CCopyHandlerApp : public CWinApp, public CAppHelper -{ -public: - CCopyHandlerApp(); - ~CCopyHandlerApp(); - -// Overrides -public: - virtual BOOL InitInstance(); - - - virtual void HtmlHelp(DWORD_PTR dwData, UINT nCmd); - - PCTSTR GetHelpPath() const { return m_pszHelpFilePath; }; - - friend LRESULT MainRouter(ULONGLONG ullDst, UINT uiMsg, WPARAM wParam, LPARAM lParam); - friend int MsgBox(UINT uiID, UINT nType=MB_OK, UINT nIDHelp=0); - friend CCopyHandlerApp* GetApp(); - friend ictranslate::CResourceManager* GetResManager(); - friend chcore::engine_config* GetConfig(); -// friend CLogFile* GetLog(); - - bool IsShellExtEnabled() const; - - void OnConfigNotify(uint_t uiPropID); - void OnResManNotify(UINT uiType); -protected: - bool UpdateHelpPaths(); - HWND HHelp(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD dwData); - -public: - ictranslate::CResourceManager m_resManager; -// CConfigManager m_cfgManager; - chcore::engine_config m_cfgSettings; - icpf::log_file m_lfLog; - - IShellExtControl* m_piShellExtControl; - - CWnd *m_pMainWindow; - // currently opened dialogs -// list m_lhDialogs; - -protected: -// Implementation - HANDLE m_hMapObject; - //TCHAR m_szHelpPath[_MAX_PATH]; // full file path to the help file -// CString m_strCrashInfo; // crash info text - - //{{AFX_MSG(CCopyHandlerApp) - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -public: - virtual int ExitInstance(); -}; - - -///////////////////////////////////////////////////////////////////////////// - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __COPYHANDLER_H__ +#define __COPYHANDLER_H__ + +#ifndef __AFXWIN_H__ + #error include 'stdafx.h' before including this file for PCH +#endif + +#include "resource.h" // main symbols +#include "AppHelper.h" +#include "CfgProperties.h" +#include "../chext/chext.h" +//#include "LogFile.h" +#include "../libicpf/log.h" +#include "../libchcore/EngineCfg.h" +#include "../libictranslate/ResourceManager.h" + +using namespace std; + +///////////////////////////////////////////////////////////////////////////// +// CCopyHandlerApp: +// See CopyHandler.cpp for the implementation of this class +// + +class CCopyHandlerApp : public CWinApp, public CAppHelper +{ +public: + CCopyHandlerApp(); + ~CCopyHandlerApp(); + +// Overrides +public: + virtual BOOL InitInstance(); + + + virtual void HtmlHelp(DWORD_PTR dwData, UINT nCmd); + + PCTSTR GetHelpPath() const { return m_pszHelpFilePath; }; + + friend LRESULT MainRouter(ULONGLONG ullDst, UINT uiMsg, WPARAM wParam, LPARAM lParam); + friend int MsgBox(UINT uiID, UINT nType=MB_OK, UINT nIDHelp=0); + friend CCopyHandlerApp* GetApp(); + friend ictranslate::CResourceManager* GetResManager(); + friend chcore::engine_config* GetConfig(); +// friend CLogFile* GetLog(); + + bool IsShellExtEnabled() const; + + void OnConfigNotify(uint_t uiPropID); + void OnResManNotify(UINT uiType); +protected: + bool UpdateHelpPaths(); + HWND HHelp(HWND hwndCaller, LPCTSTR pszFile, UINT uCommand, DWORD dwData); + +public: + ictranslate::CResourceManager m_resManager; +// CConfigManager m_cfgManager; + chcore::engine_config m_cfgSettings; + icpf::log_file m_lfLog; + + IShellExtControl* m_piShellExtControl; + + CWnd *m_pMainWindow; + // currently opened dialogs +// list m_lhDialogs; + +protected: +// Implementation + HANDLE m_hMapObject; + //TCHAR m_szHelpPath[_MAX_PATH]; // full file path to the help file +// CString m_strCrashInfo; // crash info text + + //{{AFX_MSG(CCopyHandlerApp) + //}}AFX_MSG + DECLARE_MESSAGE_MAP() +public: + virtual int ExitInstance(); +}; + + +///////////////////////////////////////////////////////////////////////////// + +//{{AFX_INSERT_LOCATION}} +// Microsoft Developer Studio will insert additional declarations immediately before the previous line. + +#endif Index: src/ch/charvect.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/charvect.h (.../charvect.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/ch/charvect.h (.../charvect.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,140 +1,140 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __CHARVECT_H__ -#define __CHARVECT_H__ - -#include - -using namespace std; - -class char_vector : public vector -{ -public: - char_vector() : vector() { }; - char_vector(const char_vector& cv, bool bCopy) { insert(begin(), cv.begin(), cv.end(), bCopy); }; - ~char_vector() { erase(begin(), end(), true); }; - - void assign(size_type _Count, const PTSTR& _Type, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _Count, _Type, bCopy); }; - template void assign(_It _First, _It _Last, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _First, _Last, bCopy); }; - - void clear(bool bDelete) { erase(begin(), end(), bDelete); }; - - iterator erase(iterator _Where, bool bDelete) { if (bDelete) delete [] (*_Where); return ((vector*)this)->erase(_Where); }; - iterator erase(iterator _First, iterator _Last, bool bDelete) { if (bDelete) for (iterator _Run=_First;_Run != _Last;_Run++) delete [] (*_Run); return ((vector*)this)->erase(_First, _Last); }; - - void replace(iterator _Where, const PTSTR& _Val, bool bDelete, bool bCopy) - { - if (bDelete) - delete [] (*_Where); - if (bCopy) - { - (*_Where)=new TCHAR[_tcslen(_Val)+1]; - _tcscpy(*_Where, _Val); - } - else - (*_Where)=_Val; - }; - iterator insert(iterator _Where, const PTSTR& _Val, bool bCopy) - { - size_type _O = _Where - begin(); - insert(_Where, 1, _Val, bCopy); - return (begin() + _O); - }; - void insert(iterator _Where, size_type _Count, const PTSTR& _Val, bool bCopy) - { - if (bCopy) - { - size_type _Size=_tcslen(_Val)+1; - PTSTR *ppsz=new PTSTR[_Count]; - try - { - for (size_type i=0;i<_Count;i++) - { - ppsz[i]=new TCHAR[_Size]; - _tcscpy(ppsz[i], _Val); - } - - ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); - } - catch(...) - { - delete [] ppsz; - throw; - } - delete [] ppsz; - } - else - ((vector*)this)->insert(_Where, _Count, _Val); - }; - void insert(iterator _Where, size_type _Count, const PCTSTR& _Val) - { - size_type _Size=_tcslen(_Val)+1; - PTSTR *ppsz=new PTSTR[_Count]; - try - { - for(size_type i=0;i<_Count;i++) - { - ppsz[i]=new TCHAR[_Size]; - _tcscpy(ppsz[i], _Val); - } - - ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); - } - catch(...) - { - delete [] ppsz; - } - }; - template void insert(iterator _Where, _It _First, _It _Last, bool bCopy) - { - if (bCopy) - { - size_type _Cnt=_Last-_First; - PTSTR *ppsz=new PTSTR[_Cnt]; - try - { - for (size_type i=0;i<_Cnt;i++) - { - ppsz[i]=new TCHAR[_tcslen(*_First)+1]; - _tcscpy(ppsz[i], *_First); - - _First++; - } - - ((vector*)this)->insert(_Where, ppsz, ppsz+_Cnt); - } - catch(...) - { - delete [] ppsz; - throw; - } - delete [] ppsz; - } - else - ((vector*)this)->insert(_Where, _First, _Last); - }; - - void swap_items(iterator _Item1, iterator _Item2) { PTSTR psz=(*_Item1); (*_Item1)=(*_Item2); (*_Item2)=psz; }; - - void pop_back(bool bDelete) { if (bDelete) delete [] (*(end()-1)); ((vector*)this)->pop_back(); }; - void push_back(const PTSTR& _Val, bool bCopy) { insert(end(), 1, _Val, bCopy); }; - void push_back(const PCTSTR& _Val) { insert(end(), 1, _Val); }; -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __CHARVECT_H__ +#define __CHARVECT_H__ + +#include + +using namespace std; + +class char_vector : public vector +{ +public: + char_vector() : vector() { }; + char_vector(const char_vector& cv, bool bCopy) { insert(begin(), cv.begin(), cv.end(), bCopy); }; + ~char_vector() { erase(begin(), end(), true); }; + + void assign(size_type _Count, const PTSTR& _Type, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _Count, _Type, bCopy); }; + template void assign(_It _First, _It _Last, bool bDelete, bool bCopy) { erase(begin(), end(), bDelete); insert(begin(), _First, _Last, bCopy); }; + + void clear(bool bDelete) { erase(begin(), end(), bDelete); }; + + iterator erase(iterator _Where, bool bDelete) { if (bDelete) delete [] (*_Where); return ((vector*)this)->erase(_Where); }; + iterator erase(iterator _First, iterator _Last, bool bDelete) { if (bDelete) for (iterator _Run=_First;_Run != _Last;_Run++) delete [] (*_Run); return ((vector*)this)->erase(_First, _Last); }; + + void replace(iterator _Where, const PTSTR& _Val, bool bDelete, bool bCopy) + { + if (bDelete) + delete [] (*_Where); + if (bCopy) + { + (*_Where)=new TCHAR[_tcslen(_Val)+1]; + _tcscpy(*_Where, _Val); + } + else + (*_Where)=_Val; + }; + iterator insert(iterator _Where, const PTSTR& _Val, bool bCopy) + { + size_type _O = _Where - begin(); + insert(_Where, 1, _Val, bCopy); + return (begin() + _O); + }; + void insert(iterator _Where, size_type _Count, const PTSTR& _Val, bool bCopy) + { + if (bCopy) + { + size_type _Size=_tcslen(_Val)+1; + PTSTR *ppsz=new PTSTR[_Count]; + try + { + for (size_type i=0;i<_Count;i++) + { + ppsz[i]=new TCHAR[_Size]; + _tcscpy(ppsz[i], _Val); + } + + ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); + } + catch(...) + { + delete [] ppsz; + throw; + } + delete [] ppsz; + } + else + ((vector*)this)->insert(_Where, _Count, _Val); + }; + void insert(iterator _Where, size_type _Count, const PCTSTR& _Val) + { + size_type _Size=_tcslen(_Val)+1; + PTSTR *ppsz=new PTSTR[_Count]; + try + { + for(size_type i=0;i<_Count;i++) + { + ppsz[i]=new TCHAR[_Size]; + _tcscpy(ppsz[i], _Val); + } + + ((vector*)this)->insert(_Where, ppsz, ppsz+_Count); + } + catch(...) + { + delete [] ppsz; + } + }; + template void insert(iterator _Where, _It _First, _It _Last, bool bCopy) + { + if (bCopy) + { + size_type _Cnt=_Last-_First; + PTSTR *ppsz=new PTSTR[_Cnt]; + try + { + for (size_type i=0;i<_Cnt;i++) + { + ppsz[i]=new TCHAR[_tcslen(*_First)+1]; + _tcscpy(ppsz[i], *_First); + + _First++; + } + + ((vector*)this)->insert(_Where, ppsz, ppsz+_Cnt); + } + catch(...) + { + delete [] ppsz; + throw; + } + delete [] ppsz; + } + else + ((vector*)this)->insert(_Where, _First, _Last); + }; + + void swap_items(iterator _Item1, iterator _Item2) { PTSTR psz=(*_Item1); (*_Item1)=(*_Item2); (*_Item2)=psz; }; + + void pop_back(bool bDelete) { if (bDelete) delete [] (*(end()-1)); ((vector*)this)->pop_back(); }; + void push_back(const PTSTR& _Val, bool bCopy) { insert(end(), 1, _Val, bCopy); }; + void push_back(const PCTSTR& _Val) { insert(end(), 1, _Val); }; +}; + #endif \ No newline at end of file Index: src/ch/debug.h =================================================================== diff -u -r4c272b19c74694c428c943011f279ec064fbd894 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/ch/debug.h (.../debug.h) (revision 4c272b19c74694c428c943011f279ec064fbd894) +++ src/ch/debug.h (.../debug.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,281 +1,281 @@ -#ifndef __DEBUG_H__ -#define __DEBUG_H__ - -// time measuring macros -#ifdef _DEBUG - static long __dwst, __dwen; - #define MEASURE_TIME(lines, text) __dwst=GetTickCount(); lines __dwen=GetTickCount(); TRACE(text, __dwen-__dwst); -#else - #define MEASURE_TIME(lines, text) lines -#endif - -#ifdef _DEBUG - #define TRACELOGFONT(str, lf)\ - {\ - TRACE( str "\tlfHeight: %ld\n\tlfWidth: %ld\n\tlfEscapement: %ld\n\tlfOrientation: %ld\n\tlfWeight: %ld\n", (lf).lfHeight, (lf).lfWidth, (lf).lfEscapement, (lf).lfOrientation, (lf).lfWeight);\ - TRACE("\tlfItalic: %d\n\tlfUnderline: %d\n\tlfStrikeOut: %d\n\tlfCharSet: %d\n\tlfOutPrecision: %d\n\tlfClipPrecision: %d\n\tlfQuality: %d\n\tlfPitchAndFamily: %d\n\tlfFaceName: %s\n", (lf).lfItalic, (lf).lfUnderline, (lf).lfStrikeOut, (lf).lfCharSet, (lf).lfOutPrecision, (lf).lfClipPrecision, (lf).lfQuality, (lf).lfPitchAndFamily, (lf).lfFaceName);\ - } -#else - #define TRACELOGFONT(lf) -#endif - -// window messages -#ifdef _DEBUG -struct __dbg_msg__ -{ - UINT uiMsg; - TCHAR *pszText; -}; - -////////////////////////////////////// - -#define GEN_PAIR(str) { str, _T(#str) } - -static __dbg_msg__ __msgs__[] = { - GEN_PAIR(WM_NULL), - GEN_PAIR(WM_CREATE), - GEN_PAIR(WM_DESTROY), - GEN_PAIR(WM_MOVE), - GEN_PAIR(WM_SIZE), - GEN_PAIR(WM_ACTIVATE), - GEN_PAIR(WM_SETFOCUS), - GEN_PAIR(WM_KILLFOCUS), - GEN_PAIR(WM_ENABLE), - GEN_PAIR(WM_SETREDRAW), - GEN_PAIR(WM_SETTEXT), - GEN_PAIR(WM_GETTEXT), - GEN_PAIR(WM_GETTEXTLENGTH), - GEN_PAIR(WM_PAINT), - GEN_PAIR(WM_CLOSE), - GEN_PAIR(WM_QUERYENDSESSION), - GEN_PAIR(WM_QUERYOPEN), - GEN_PAIR(WM_ENDSESSION), - GEN_PAIR(WM_QUIT), - GEN_PAIR(WM_ERASEBKGND), - GEN_PAIR(WM_SYSCOLORCHANGE), - GEN_PAIR(WM_SHOWWINDOW), - GEN_PAIR(WM_WININICHANGE), - GEN_PAIR(WM_DEVMODECHANGE), - GEN_PAIR(WM_ACTIVATEAPP), - GEN_PAIR(WM_FONTCHANGE), - GEN_PAIR(WM_TIMECHANGE), - GEN_PAIR(WM_CANCELMODE), - GEN_PAIR(WM_SETCURSOR), - GEN_PAIR(WM_MOUSEACTIVATE), - GEN_PAIR(WM_CHILDACTIVATE), - GEN_PAIR(WM_QUEUESYNC), - GEN_PAIR(WM_GETMINMAXINFO), - GEN_PAIR(WM_PAINTICON), - GEN_PAIR(WM_ICONERASEBKGND), - GEN_PAIR(WM_NEXTDLGCTL), - GEN_PAIR(WM_SPOOLERSTATUS), - GEN_PAIR(WM_DRAWITEM), - GEN_PAIR(WM_MEASUREITEM), - GEN_PAIR(WM_DELETEITEM), - GEN_PAIR(WM_VKEYTOITEM), - GEN_PAIR(WM_CHARTOITEM), - GEN_PAIR(WM_SETFONT), - GEN_PAIR(WM_GETFONT), - GEN_PAIR(WM_SETHOTKEY), - GEN_PAIR(WM_GETHOTKEY), - GEN_PAIR(WM_QUERYDRAGICON), - GEN_PAIR(WM_COMPAREITEM), - { 0x003d, _T("WM_GETOBJECT") }, - GEN_PAIR(WM_COMPACTING), - GEN_PAIR(WM_COMMNOTIFY), - GEN_PAIR(WM_WINDOWPOSCHANGING), - GEN_PAIR(WM_WINDOWPOSCHANGED), - GEN_PAIR(WM_POWER), - GEN_PAIR(WM_COPYDATA), - GEN_PAIR(WM_CANCELJOURNAL), - GEN_PAIR(WM_NOTIFY), - GEN_PAIR(WM_INPUTLANGCHANGEREQUEST), - GEN_PAIR(WM_INPUTLANGCHANGE), - GEN_PAIR(WM_TCARD), - GEN_PAIR(WM_HELP), - GEN_PAIR(WM_USERCHANGED), - GEN_PAIR(WM_NOTIFYFORMAT), - GEN_PAIR(WM_CONTEXTMENU), - GEN_PAIR(WM_STYLECHANGING), - GEN_PAIR(WM_STYLECHANGED), - GEN_PAIR(WM_DISPLAYCHANGE), - GEN_PAIR(WM_GETICON), - GEN_PAIR(WM_SETICON), - GEN_PAIR(WM_NCCREATE), - GEN_PAIR(WM_NCDESTROY), - GEN_PAIR(WM_NCCALCSIZE), - GEN_PAIR(WM_NCHITTEST), - GEN_PAIR(WM_NCPAINT), - GEN_PAIR(WM_NCACTIVATE), - GEN_PAIR(WM_GETDLGCODE), - GEN_PAIR(WM_SYNCPAINT), - GEN_PAIR(WM_NCMOUSEMOVE), - GEN_PAIR(WM_NCLBUTTONDOWN), - GEN_PAIR(WM_NCLBUTTONUP), - GEN_PAIR(WM_NCLBUTTONDBLCLK), - GEN_PAIR(WM_NCRBUTTONDOWN), - GEN_PAIR(WM_NCRBUTTONUP), - GEN_PAIR(WM_NCRBUTTONDBLCLK), - GEN_PAIR(WM_NCMBUTTONDOWN), - GEN_PAIR(WM_NCMBUTTONUP), - GEN_PAIR(WM_NCMBUTTONDBLCLK), - { 0x00AB, _T("WM_NCXBUTTONDOWN") }, - { 0x00AC, _T("WM_NCXBUTTONUP") }, - { 0x00AD, _T("WM_NCXBUTTONDBLCLK") }, - { 0x00FF, _T("WM_INPUT") }, - GEN_PAIR(WM_KEYFIRST), - GEN_PAIR(WM_KEYDOWN), - GEN_PAIR(WM_KEYUP), - GEN_PAIR(WM_CHAR), - GEN_PAIR(WM_DEADCHAR), - GEN_PAIR(WM_SYSKEYDOWN), - GEN_PAIR(WM_SYSKEYUP), - GEN_PAIR(WM_SYSCHAR), - GEN_PAIR(WM_SYSDEADCHAR), - GEN_PAIR(WM_UNICHAR), - GEN_PAIR(WM_KEYLAST), - GEN_PAIR(WM_IME_STARTCOMPOSITION), - GEN_PAIR(WM_IME_ENDCOMPOSITION), - GEN_PAIR(WM_IME_COMPOSITION), - GEN_PAIR(WM_IME_KEYLAST), - GEN_PAIR(WM_INITDIALOG), - GEN_PAIR(WM_COMMAND), - GEN_PAIR(WM_SYSCOMMAND), - GEN_PAIR(WM_TIMER), - GEN_PAIR(WM_HSCROLL), - GEN_PAIR(WM_VSCROLL), - GEN_PAIR(WM_INITMENU), - GEN_PAIR(WM_INITMENUPOPUP), - GEN_PAIR(WM_MENUSELECT), - GEN_PAIR(WM_MENUCHAR), - GEN_PAIR(WM_ENTERIDLE), - { 0x0122, _T("WM_MENURBUTTONUP") }, - { 0x0123, _T("WM_MENUDRAG") }, - { 0x0124, _T("WM_MENUGETOBJECT") }, - { 0x0125, _T("WM_UNINITMENUPOPUP") }, - { 0x0126, _T("WM_MENUCOMMAND") }, - { 0x0127, _T("WM_CHANGEUISTATE") }, - { 0x0128, _T("WM_UPDATEUISTATE") }, - { 0x0129, _T("WM_QUERYUISTATE") }, - GEN_PAIR(WM_CTLCOLORMSGBOX), - GEN_PAIR(WM_CTLCOLOREDIT), - GEN_PAIR(WM_CTLCOLORLISTBOX), - GEN_PAIR(WM_CTLCOLORBTN), - GEN_PAIR(WM_CTLCOLORDLG), - GEN_PAIR(WM_CTLCOLORSCROLLBAR), - GEN_PAIR(WM_CTLCOLORSTATIC), - GEN_PAIR(WM_MOUSEFIRST), - GEN_PAIR(WM_MOUSEMOVE), - GEN_PAIR(WM_LBUTTONDOWN), - GEN_PAIR(WM_LBUTTONUP), - GEN_PAIR(WM_LBUTTONDBLCLK), - GEN_PAIR(WM_RBUTTONDOWN), - GEN_PAIR(WM_RBUTTONUP), - GEN_PAIR(WM_RBUTTONDBLCLK), - GEN_PAIR(WM_MBUTTONDOWN), - GEN_PAIR(WM_MBUTTONUP), - GEN_PAIR(WM_MBUTTONDBLCLK), - GEN_PAIR(WM_MOUSEWHEEL), - { 0x020B, _T("WM_XBUTTONDOWN") }, - { 0x020C, _T("WM_XBUTTONUP") }, - { 0x020D, _T("WM_XBUTTONDBLCLK") }, - GEN_PAIR(WM_MOUSELAST), - GEN_PAIR(WM_MOUSELAST), - GEN_PAIR(WM_MOUSELAST), - GEN_PAIR(WM_PARENTNOTIFY), - GEN_PAIR(WM_ENTERMENULOOP), - GEN_PAIR(WM_EXITMENULOOP), - GEN_PAIR(WM_NEXTMENU), - GEN_PAIR(WM_SIZING), - GEN_PAIR(WM_CAPTURECHANGED), - GEN_PAIR(WM_MOVING), - GEN_PAIR(WM_POWERBROADCAST), - GEN_PAIR(WM_DEVICECHANGE), - GEN_PAIR(WM_MDICREATE), - GEN_PAIR(WM_MDIDESTROY), - GEN_PAIR(WM_MDIACTIVATE), - GEN_PAIR(WM_MDIRESTORE), - GEN_PAIR(WM_MDINEXT), - GEN_PAIR(WM_MDIMAXIMIZE), - GEN_PAIR(WM_MDITILE), - GEN_PAIR(WM_MDICASCADE), - GEN_PAIR(WM_MDIICONARRANGE), - GEN_PAIR(WM_MDIGETACTIVE), - GEN_PAIR(WM_MDISETMENU), - GEN_PAIR(WM_ENTERSIZEMOVE), - GEN_PAIR(WM_EXITSIZEMOVE), - GEN_PAIR(WM_DROPFILES), - GEN_PAIR(WM_MDIREFRESHMENU), - GEN_PAIR(WM_IME_SETCONTEXT), - GEN_PAIR(WM_IME_NOTIFY), - GEN_PAIR(WM_IME_CONTROL), - GEN_PAIR(WM_IME_COMPOSITIONFULL), - GEN_PAIR(WM_IME_SELECT), - GEN_PAIR(WM_IME_CHAR), - { 0x0288, _T("WM_IME_REQUEST") }, - GEN_PAIR(WM_IME_KEYDOWN), - GEN_PAIR(WM_IME_KEYUP), - GEN_PAIR(WM_MOUSEHOVER), - GEN_PAIR(WM_MOUSELEAVE), - { 0x02A0, _T("WM_NCMOUSEHOVER") }, - { 0x02A2, _T("WM_NCMOUSELEAVE") }, - { 0x02B1, _T("WM_WTSSESSION_CHANGE") }, - { 0x02C0, _T("WM_TABLET_FIRST") }, - { 0x02DF, _T("WM_TABLET_LAST") }, - GEN_PAIR(WM_CUT), - GEN_PAIR(WM_COPY), - GEN_PAIR(WM_PASTE), - GEN_PAIR(WM_CLEAR), - GEN_PAIR(WM_UNDO), - GEN_PAIR(WM_RENDERFORMAT), - GEN_PAIR(WM_RENDERALLFORMATS), - GEN_PAIR(WM_DESTROYCLIPBOARD), - GEN_PAIR(WM_DRAWCLIPBOARD), - GEN_PAIR(WM_PAINTCLIPBOARD), - GEN_PAIR(WM_VSCROLLCLIPBOARD), - GEN_PAIR(WM_SIZECLIPBOARD), - GEN_PAIR(WM_ASKCBFORMATNAME), - GEN_PAIR(WM_CHANGECBCHAIN), - GEN_PAIR(WM_HSCROLLCLIPBOARD), - GEN_PAIR(WM_QUERYNEWPALETTE), - GEN_PAIR(WM_PALETTEISCHANGING), - GEN_PAIR(WM_PALETTECHANGED), - GEN_PAIR(WM_HOTKEY), - GEN_PAIR(WM_PRINT), - GEN_PAIR(WM_PRINTCLIENT), - { 0x0319, _T("WM_APPCOMMAND") }, - { 0x031A, _T("WM_THEMECHANGED") }, - GEN_PAIR(WM_HANDHELDFIRST), - GEN_PAIR(WM_HANDHELDLAST), - GEN_PAIR(WM_AFXFIRST), - GEN_PAIR(WM_AFXLAST), - GEN_PAIR(WM_PENWINFIRST), - GEN_PAIR(WM_PENWINLAST), - GEN_PAIR(WM_APP), - GEN_PAIR(WM_USER) - }; -///////////////////////////////// - -static TCHAR* UINTToMsg(UINT uiMsg, TCHAR* szBuffer, size_t stMaxBufferSize) -{ - int iCount=sizeof(__msgs__)/(sizeof(__dbg_msg__)); - for (int i=0;iRelease(); - m_piShellExtControl = NULL; - } -} - -STDMETHODIMP CDropMenuExt::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/) -{ - // check options - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - return hResult; - - // find CH's window - HWND hWnd; - hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if (hWnd) - { - // get state of keys - bool bShift=(GetKeyState(VK_SHIFT) & 0x80) != 0; - bool bCtrl=(GetKeyState(VK_CONTROL) & 0x80) != 0; - bool bAlt=(GetKeyState(VK_MENU) & 0x80) != 0; - -/* OTF2("CDropMenuExt::QueryContextMenu - uFlags=%lu (", uFlags); - if (uFlags & CMF_CANRENAME) - OTF2("CMF_CANRENAME "); - if (uFlags & CMF_DEFAULTONLY) - OTF2("CMF_DEFAULTONLY "); - if (uFlags & CMF_EXPLORE) - OTF2("CMF_EXPLORE "); - if (uFlags & CMF_EXTENDEDVERBS) - OTF2("CMF_EXTENDEDVERBS "); - if (uFlags & CMF_INCLUDESTATIC) - OTF2("CMF_INCLUDESTATIC "); - if (uFlags & CMF_NODEFAULT) - OTF2("CMF_NODEFAULT "); - if (uFlags & CMF_NORMAL) - OTF2("CMF_NORMAL "); - if (uFlags & CMF_NOVERBS) - OTF2("CMF_NOVERBS "); - if (uFlags & CMF_VERBSONLY) - OTF2("CMF_VERBSONLY "); - OTF2(")\r\n"); - OTF2("Keys State: Shift:%u, ctrl:%u, alt:%u\r\n", bShift, bCtrl, bAlt); -*/ - // got a config - _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); - int iCommandCount=0; - - if (g_pscsShared->uiFlags & DD_COPY_FLAG) - { - ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_STRING, idCmdFirst+0, pCommand[0].szCommand); - if (g_pscsShared->bOverrideDefault) - ::SetMenuDefaultItem(hmenu, idCmdFirst+0, FALSE); - iCommandCount++; - } - - if (g_pscsShared->uiFlags & DD_MOVE_FLAG) - { - ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_STRING, idCmdFirst+1, pCommand[1].szCommand); - if (g_pscsShared->bOverrideDefault && (bShift || (m_uiDropEffect == DE_MOVE && (m_bExplorer || !bCtrl))) ) - ::SetMenuDefaultItem(hmenu, idCmdFirst+1, FALSE); - iCommandCount++; - } - - if (g_pscsShared->uiFlags & DD_COPYMOVESPECIAL_FLAG) - { - ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_STRING, idCmdFirst+2, pCommand[2].szCommand); - if (g_pscsShared->bOverrideDefault && (bAlt || (bCtrl && bShift) || m_uiDropEffect == DE_SPECIAL) && !(m_uiDropEffect == DE_MOVE)) - ::SetMenuDefaultItem(hmenu, idCmdFirst+2, FALSE); - iCommandCount++; - } - - if (iCommandCount) - { - ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_SEPARATOR, idCmdFirst+3, NULL); - iCommandCount++; - } - - return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 4); - } - else - return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0); -} - -STDMETHODIMP CDropMenuExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax) -{ - // check options - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - { - pszName[0] = _T('\0'); - return hResult; - } - - if (uFlags == GCS_HELPTEXTW) - { - USES_CONVERSION; - - // find CH's window - HWND hWnd; - hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if (hWnd) - { - _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); - - switch (idCmd) - { - case 0: - case 1: - case 2: - { - CT2W ct2w(pCommand[idCmd].szDesc); - wcsncpy(reinterpret_cast(pszName), ct2w, cchMax); - break; - } - default: - wcsncpy(reinterpret_cast(pszName), L"", cchMax); - break; - } - } - else - wcsncpy(reinterpret_cast(pszName), L"", cchMax); - } - if (uFlags == GCS_HELPTEXTA) - { - // find CH's window - HWND hWnd; - hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - - if (hWnd) - { - _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); - - switch (idCmd) - { - case 0: - case 1: - case 2: - { - CT2A ct2a(pCommand[idCmd].szDesc); - strncpy(pszName, ct2a, cchMax); - break; - } - default: - strncpy(pszName, "", cchMax); - break; - } - } - else - strncpy(pszName, "", cchMax); - } - - return S_OK; -} - -STDMETHODIMP CDropMenuExt::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/) -{ -// OTF2("Initialize cdropmenuext\r\n"); - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - return hResult; - - // find window - HWND hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if (hWnd == NULL) - return E_FAIL; - - // gets the config from CH - ::SendMessage(hWnd, WM_GETCONFIG, GC_DRAGDROP, 0); - -// OTF2("========================================================\r\n"); -// OTF2("Initialize drag&drop context menu handler pidlFolder=%lu, lpdobj=%lu\r\n", pidlFolder, lpdobj); - - // get dest folder - m_szDstPath[0]=_T('\0'); - if (!SHGetPathFromIDList(pidlFolder, m_szDstPath)) - return E_FAIL; - - // get data from IDataObject - files to copy/move - if (lpdobj) - { -// ReportAvailableFormats(lpdobj); - // file list - STGMEDIUM medium; - FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - - HRESULT hr = lpdobj->GetData(&fe, &medium); - if (FAILED(hr)) - return E_FAIL; - - GetDataFromClipboard(static_cast(medium.hGlobal), m_szDstPath, &m_bBuffer.m_pszFiles, &m_bBuffer.m_iDataSize); - - // set std text - switch (g_pscsShared->uiDefaultAction) - { - case 1: - // move action - m_uiDropEffect=DE_MOVE; - break; - case 2: - // special operation - m_uiDropEffect=DE_SPECIAL; - break; - case 3: - { - // autodetecting - copy or move - check the last path - UINT uiCount=DragQueryFile((HDROP)medium.hGlobal, 0xffffffff, NULL, 0); - TCHAR szPath[_MAX_PATH]; - if (DragQueryFile((HDROP)medium.hGlobal, uiCount-1, szPath, _MAX_PATH)) - { - if (_tcsncmp(szPath, _T("\\\\"), 2) == 0) - { - TCHAR* pFnd=_tcsstr(szPath+2, _T("\\")); - - if (pFnd) - { - int iCount; - // find another - TCHAR *pSecond=_tcsstr(pFnd+1, _T("\\")); - if (pSecond) - { - iCount=pSecond-szPath; -// OTF2("Counted: %lu\r\n", iCount); - } - else - iCount=_tcslen(szPath); - - // found - compare -// OTF2("Compare %s and %s\r\n", szPath, m_szDstPath); - if (_tcsnicmp(szPath, m_szDstPath, iCount) == 0) - { -// OTF2("OP: MOVE\r\n"); - m_uiDropEffect=DE_MOVE; - } - else - { -// OTF2("OP: COPY\r\n"); - m_uiDropEffect=DE_COPY; - } - } - else - m_uiDropEffect=DE_COPY; - - } - else - { - // local path - check drive letter - if (m_szDstPath[0] == szPath[0]) - m_uiDropEffect=DE_MOVE; - else - m_uiDropEffect=DE_COPY; - } - } - else - m_uiDropEffect=DE_COPY; - } - break; - - default: - m_uiDropEffect=DE_COPY; // std copying - break; - } - - ReleaseStgMedium(&medium); - - // get operation type - UINT cf=RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT); - fe.cfFormat=(unsigned short)cf; - - // if explorer knows better - change effect - m_bExplorer=false; - hr=lpdobj->GetData(&fe, &medium); - if (SUCCEEDED(hr)) - { - // specify operation - LPVOID lpv=GlobalLock(medium.hGlobal); - if (lpv) - { - UINT uiDrop=*((DWORD*)lpv); - if (uiDrop & DROPEFFECT_MOVE) - m_uiDropEffect=DE_MOVE; - else - m_uiDropEffect=DE_COPY; - m_bExplorer=true; - -// OTF2("Detected operation %lu\r\n", m_uiDropEffect); - GlobalUnlock(medium.hGlobal); - } - - ReleaseStgMedium(&medium); - } - } - - return S_OK; -} - -STDMETHODIMP CDropMenuExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) -{ - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - return E_FAIL; // required to process other InvokeCommand handlers. - - // find window - HWND hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if (hWnd == NULL) - return E_FAIL; - - // commands - _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); - - // IPC struct - COPYDATASTRUCT cds; - cds.dwData=pCommand[LOWORD(lpici->lpVerb)].uiCommandID; // based on command's number (0-copy, 1-move, 2-special (copy), 3-special (move)) - cds.cbData=m_bBuffer.m_iDataSize * sizeof(TCHAR); - cds.lpData=m_bBuffer.m_pszFiles; - - // send a message to ch - ::SendMessage(hWnd, WM_COPYDATA, reinterpret_cast(lpici->hwnd), reinterpret_cast(&cds)); - - m_bBuffer.Destroy(); - - return S_OK; +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "chext.h" +#include "DropMenuExt.h" +#include "clipboard.h" +#include "chext-utils.h" + +///////////////////////////////////////////////////////////////////////////// +// CDropMenuExt + +extern CSharedConfigStruct* g_pscsShared; + +#define DE_COPY 0 +#define DE_MOVE 1 +#define DE_SPECIAL 2 +#define DE_AUTO 3 + +CDropMenuExt::CDropMenuExt() : + m_piShellExtControl(NULL) +{ + CoCreateInstance(CLSID_CShellExtControl, NULL, CLSCTX_ALL, IID_IShellExtControl, (void**)&m_piShellExtControl); +} + +CDropMenuExt::~CDropMenuExt() +{ + if(m_piShellExtControl) + { + m_piShellExtControl->Release(); + m_piShellExtControl = NULL; + } +} + +STDMETHODIMP CDropMenuExt::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/) +{ + // check options + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + return hResult; + + // find CH's window + HWND hWnd; + hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if (hWnd) + { + // get state of keys + bool bShift=(GetKeyState(VK_SHIFT) & 0x80) != 0; + bool bCtrl=(GetKeyState(VK_CONTROL) & 0x80) != 0; + bool bAlt=(GetKeyState(VK_MENU) & 0x80) != 0; + +/* OTF2("CDropMenuExt::QueryContextMenu - uFlags=%lu (", uFlags); + if (uFlags & CMF_CANRENAME) + OTF2("CMF_CANRENAME "); + if (uFlags & CMF_DEFAULTONLY) + OTF2("CMF_DEFAULTONLY "); + if (uFlags & CMF_EXPLORE) + OTF2("CMF_EXPLORE "); + if (uFlags & CMF_EXTENDEDVERBS) + OTF2("CMF_EXTENDEDVERBS "); + if (uFlags & CMF_INCLUDESTATIC) + OTF2("CMF_INCLUDESTATIC "); + if (uFlags & CMF_NODEFAULT) + OTF2("CMF_NODEFAULT "); + if (uFlags & CMF_NORMAL) + OTF2("CMF_NORMAL "); + if (uFlags & CMF_NOVERBS) + OTF2("CMF_NOVERBS "); + if (uFlags & CMF_VERBSONLY) + OTF2("CMF_VERBSONLY "); + OTF2(")\r\n"); + OTF2("Keys State: Shift:%u, ctrl:%u, alt:%u\r\n", bShift, bCtrl, bAlt); +*/ + // got a config + _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); + int iCommandCount=0; + + if (g_pscsShared->uiFlags & DD_COPY_FLAG) + { + ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_STRING, idCmdFirst+0, pCommand[0].szCommand); + if (g_pscsShared->bOverrideDefault) + ::SetMenuDefaultItem(hmenu, idCmdFirst+0, FALSE); + iCommandCount++; + } + + if (g_pscsShared->uiFlags & DD_MOVE_FLAG) + { + ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_STRING, idCmdFirst+1, pCommand[1].szCommand); + if (g_pscsShared->bOverrideDefault && (bShift || (m_uiDropEffect == DE_MOVE && (m_bExplorer || !bCtrl))) ) + ::SetMenuDefaultItem(hmenu, idCmdFirst+1, FALSE); + iCommandCount++; + } + + if (g_pscsShared->uiFlags & DD_COPYMOVESPECIAL_FLAG) + { + ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_STRING, idCmdFirst+2, pCommand[2].szCommand); + if (g_pscsShared->bOverrideDefault && (bAlt || (bCtrl && bShift) || m_uiDropEffect == DE_SPECIAL) && !(m_uiDropEffect == DE_MOVE)) + ::SetMenuDefaultItem(hmenu, idCmdFirst+2, FALSE); + iCommandCount++; + } + + if (iCommandCount) + { + ::InsertMenu(hmenu, indexMenu+iCommandCount, MF_BYPOSITION | MF_SEPARATOR, idCmdFirst+3, NULL); + iCommandCount++; + } + + return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 4); + } + else + return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0); +} + +STDMETHODIMP CDropMenuExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax) +{ + // check options + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + { + pszName[0] = _T('\0'); + return hResult; + } + + if (uFlags == GCS_HELPTEXTW) + { + USES_CONVERSION; + + // find CH's window + HWND hWnd; + hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if (hWnd) + { + _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); + + switch (idCmd) + { + case 0: + case 1: + case 2: + { + CT2W ct2w(pCommand[idCmd].szDesc); + wcsncpy(reinterpret_cast(pszName), ct2w, cchMax); + break; + } + default: + wcsncpy(reinterpret_cast(pszName), L"", cchMax); + break; + } + } + else + wcsncpy(reinterpret_cast(pszName), L"", cchMax); + } + if (uFlags == GCS_HELPTEXTA) + { + // find CH's window + HWND hWnd; + hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + + if (hWnd) + { + _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); + + switch (idCmd) + { + case 0: + case 1: + case 2: + { + CT2A ct2a(pCommand[idCmd].szDesc); + strncpy(pszName, ct2a, cchMax); + break; + } + default: + strncpy(pszName, "", cchMax); + break; + } + } + else + strncpy(pszName, "", cchMax); + } + + return S_OK; +} + +STDMETHODIMP CDropMenuExt::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/) +{ +// OTF2("Initialize cdropmenuext\r\n"); + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + return hResult; + + // find window + HWND hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if (hWnd == NULL) + return E_FAIL; + + // gets the config from CH + ::SendMessage(hWnd, WM_GETCONFIG, GC_DRAGDROP, 0); + +// OTF2("========================================================\r\n"); +// OTF2("Initialize drag&drop context menu handler pidlFolder=%lu, lpdobj=%lu\r\n", pidlFolder, lpdobj); + + // get dest folder + m_szDstPath[0]=_T('\0'); + if (!SHGetPathFromIDList(pidlFolder, m_szDstPath)) + return E_FAIL; + + // get data from IDataObject - files to copy/move + if (lpdobj) + { +// ReportAvailableFormats(lpdobj); + // file list + STGMEDIUM medium; + FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; + + HRESULT hr = lpdobj->GetData(&fe, &medium); + if (FAILED(hr)) + return E_FAIL; + + GetDataFromClipboard(static_cast(medium.hGlobal), m_szDstPath, &m_bBuffer.m_pszFiles, &m_bBuffer.m_iDataSize); + + // set std text + switch (g_pscsShared->uiDefaultAction) + { + case 1: + // move action + m_uiDropEffect=DE_MOVE; + break; + case 2: + // special operation + m_uiDropEffect=DE_SPECIAL; + break; + case 3: + { + // autodetecting - copy or move - check the last path + UINT uiCount=DragQueryFile((HDROP)medium.hGlobal, 0xffffffff, NULL, 0); + TCHAR szPath[_MAX_PATH]; + if (DragQueryFile((HDROP)medium.hGlobal, uiCount-1, szPath, _MAX_PATH)) + { + if (_tcsncmp(szPath, _T("\\\\"), 2) == 0) + { + TCHAR* pFnd=_tcsstr(szPath+2, _T("\\")); + + if (pFnd) + { + int iCount; + // find another + TCHAR *pSecond=_tcsstr(pFnd+1, _T("\\")); + if (pSecond) + { + iCount=pSecond-szPath; +// OTF2("Counted: %lu\r\n", iCount); + } + else + iCount=_tcslen(szPath); + + // found - compare +// OTF2("Compare %s and %s\r\n", szPath, m_szDstPath); + if (_tcsnicmp(szPath, m_szDstPath, iCount) == 0) + { +// OTF2("OP: MOVE\r\n"); + m_uiDropEffect=DE_MOVE; + } + else + { +// OTF2("OP: COPY\r\n"); + m_uiDropEffect=DE_COPY; + } + } + else + m_uiDropEffect=DE_COPY; + + } + else + { + // local path - check drive letter + if (m_szDstPath[0] == szPath[0]) + m_uiDropEffect=DE_MOVE; + else + m_uiDropEffect=DE_COPY; + } + } + else + m_uiDropEffect=DE_COPY; + } + break; + + default: + m_uiDropEffect=DE_COPY; // std copying + break; + } + + ReleaseStgMedium(&medium); + + // get operation type + UINT cf=RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT); + fe.cfFormat=(unsigned short)cf; + + // if explorer knows better - change effect + m_bExplorer=false; + hr=lpdobj->GetData(&fe, &medium); + if (SUCCEEDED(hr)) + { + // specify operation + LPVOID lpv=GlobalLock(medium.hGlobal); + if (lpv) + { + UINT uiDrop=*((DWORD*)lpv); + if (uiDrop & DROPEFFECT_MOVE) + m_uiDropEffect=DE_MOVE; + else + m_uiDropEffect=DE_COPY; + m_bExplorer=true; + +// OTF2("Detected operation %lu\r\n", m_uiDropEffect); + GlobalUnlock(medium.hGlobal); + } + + ReleaseStgMedium(&medium); + } + } + + return S_OK; +} + +STDMETHODIMP CDropMenuExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) +{ + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + return E_FAIL; // required to process other InvokeCommand handlers. + + // find window + HWND hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if (hWnd == NULL) + return E_FAIL; + + // commands + _COMMAND* pCommand = g_pscsShared->GetCommandsPtr(); + + // IPC struct + COPYDATASTRUCT cds; + cds.dwData=pCommand[LOWORD(lpici->lpVerb)].uiCommandID; // based on command's number (0-copy, 1-move, 2-special (copy), 3-special (move)) + cds.cbData=m_bBuffer.m_iDataSize * sizeof(TCHAR); + cds.lpData=m_bBuffer.m_pszFiles; + + // send a message to ch + ::SendMessage(hWnd, WM_COPYDATA, reinterpret_cast(lpici->hwnd), reinterpret_cast(&cds)); + + m_bBuffer.Destroy(); + + return S_OK; } \ No newline at end of file Index: src/chext/DropMenuExt.h =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/DropMenuExt.h (.../DropMenuExt.h) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/chext/DropMenuExt.h (.../DropMenuExt.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,82 +1,82 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __DROPMENUEXT_H_ -#define __DROPMENUEXT_H_ - -#include "resource.h" // main symbols -#include "IShellExtInitImpl.h" -#include "IContextMenuImpl.h" -#include "comdef.h" -#include "..\Common\ipcstructs.h" - -///////////////////////////////////////////////////////////////////////////// -// CDropMenuExt -class ATL_NO_VTABLE CDropMenuExt : - public CComObjectRootEx, - public CComCoClass, - public IObjectWithSiteImpl, - public IDispatchImpl, - public IShellExtInitImpl, - public IContextMenuImpl -{ -public: - CDropMenuExt(); - ~CDropMenuExt(); - -public: - class CBuffer - { - public: - CBuffer() { m_pszFiles=NULL; m_iDataSize=0; }; - void Destroy() { delete [] m_pszFiles; m_pszFiles=NULL; m_iDataSize=0; }; - ~CBuffer() { Destroy(); }; - - public: - TCHAR *m_pszFiles; - UINT m_iDataSize; - } m_bBuffer; - - TCHAR m_szDstPath[_MAX_PATH]; - UINT m_uiDropEffect; - bool m_bExplorer; // if the operation has been retrieved from explorer or from the program - - IShellExtControl* m_piShellExtControl; - -DECLARE_REGISTRY_RESOURCEID(IDR_DROPMENUEXT) -DECLARE_NOT_AGGREGATABLE(CDropMenuExt) - -DECLARE_PROTECT_FINAL_CONSTRUCT() - -BEGIN_COM_MAP(CDropMenuExt) - COM_INTERFACE_ENTRY(IDropMenuExt) - COM_INTERFACE_ENTRY(IDispatch) - COM_INTERFACE_ENTRY(IShellExtInit) - COM_INTERFACE_ENTRY(IContextMenu) - COM_INTERFACE_ENTRY(IObjectWithSite) -END_COM_MAP() - -// IDropMenuExt -public: - STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici); - STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/); - STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax); - STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT uFlags); -}; - -#endif //__DROPMENUEXT_H_ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __DROPMENUEXT_H_ +#define __DROPMENUEXT_H_ + +#include "resource.h" // main symbols +#include "IShellExtInitImpl.h" +#include "IContextMenuImpl.h" +#include "comdef.h" +#include "..\Common\ipcstructs.h" + +///////////////////////////////////////////////////////////////////////////// +// CDropMenuExt +class ATL_NO_VTABLE CDropMenuExt : + public CComObjectRootEx, + public CComCoClass, + public IObjectWithSiteImpl, + public IDispatchImpl, + public IShellExtInitImpl, + public IContextMenuImpl +{ +public: + CDropMenuExt(); + ~CDropMenuExt(); + +public: + class CBuffer + { + public: + CBuffer() { m_pszFiles=NULL; m_iDataSize=0; }; + void Destroy() { delete [] m_pszFiles; m_pszFiles=NULL; m_iDataSize=0; }; + ~CBuffer() { Destroy(); }; + + public: + TCHAR *m_pszFiles; + UINT m_iDataSize; + } m_bBuffer; + + TCHAR m_szDstPath[_MAX_PATH]; + UINT m_uiDropEffect; + bool m_bExplorer; // if the operation has been retrieved from explorer or from the program + + IShellExtControl* m_piShellExtControl; + +DECLARE_REGISTRY_RESOURCEID(IDR_DROPMENUEXT) +DECLARE_NOT_AGGREGATABLE(CDropMenuExt) + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CDropMenuExt) + COM_INTERFACE_ENTRY(IDropMenuExt) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY(IShellExtInit) + COM_INTERFACE_ENTRY(IContextMenu) + COM_INTERFACE_ENTRY(IObjectWithSite) +END_COM_MAP() + +// IDropMenuExt +public: + STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici); + STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/); + STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax); + STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT uFlags); +}; + +#endif //__DROPMENUEXT_H_ Index: src/chext/IContextMenuImpl.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/IContextMenuImpl.h (.../IContextMenuImpl.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/chext/IContextMenuImpl.h (.../IContextMenuImpl.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,67 +1,67 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __ICONTEXTMENUIMPL_H__ -#define __ICONTEXTMENUIMPL_H__ - -// IContextMenuImpl.h -// -////////////////////////////////////////////////////////////////////// -#include -#include - - -class ATL_NO_VTABLE IContextMenuImpl : public IContextMenu3 -{ -public: - - // IUnknown - // - STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) = 0; - _ATL_DEBUG_ADDREF_RELEASE_IMPL( IContextMenuImpl ) - - - // IContextMenu - // - STDMETHOD(GetCommandString)(UINT, UINT, UINT*, LPSTR, UINT) - { - return S_FALSE; - } - - STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO) - { - return S_FALSE; - } - - STDMETHOD(QueryContextMenu)(HMENU, UINT, UINT , UINT, UINT) - { - return S_FALSE; - } - - STDMETHOD(HandleMenuMsg)(UINT, WPARAM, LPARAM) - { - return S_FALSE; - } - - STDMETHOD(HandleMenuMsg2)(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, LRESULT* /*plResult*/) - { - return S_FALSE; - } -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __ICONTEXTMENUIMPL_H__ +#define __ICONTEXTMENUIMPL_H__ + +// IContextMenuImpl.h +// +////////////////////////////////////////////////////////////////////// +#include +#include + + +class ATL_NO_VTABLE IContextMenuImpl : public IContextMenu3 +{ +public: + + // IUnknown + // + STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) = 0; + _ATL_DEBUG_ADDREF_RELEASE_IMPL( IContextMenuImpl ) + + + // IContextMenu + // + STDMETHOD(GetCommandString)(UINT, UINT, UINT*, LPSTR, UINT) + { + return S_FALSE; + } + + STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO) + { + return S_FALSE; + } + + STDMETHOD(QueryContextMenu)(HMENU, UINT, UINT , UINT, UINT) + { + return S_FALSE; + } + + STDMETHOD(HandleMenuMsg)(UINT, WPARAM, LPARAM) + { + return S_FALSE; + } + + STDMETHOD(HandleMenuMsg2)(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, LRESULT* /*plResult*/) + { + return S_FALSE; + } +}; + #endif \ No newline at end of file Index: src/chext/IShellExtInitImpl.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/IShellExtInitImpl.h (.../IShellExtInitImpl.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/chext/IShellExtInitImpl.h (.../IShellExtInitImpl.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,48 +1,48 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __ISHELLEXTINITIMPL_H__ -#define __ISHELLEXTINITIMPL_H__ - -// IShellExtInitImpl.h -// -////////////////////////////////////////////////////////////////////// -#include -#include - - -class ATL_NO_VTABLE IShellExtInitImpl : public IShellExtInit -{ -public: - - // IUnknown - // - STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) = 0; - _ATL_DEBUG_ADDREF_RELEASE_IMPL( IShellExtInitImpl ) - - - // IShellExtInit - // - STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY) - { - return S_FALSE; - }; - -}; - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __ISHELLEXTINITIMPL_H__ +#define __ISHELLEXTINITIMPL_H__ + +// IShellExtInitImpl.h +// +////////////////////////////////////////////////////////////////////// +#include +#include + + +class ATL_NO_VTABLE IShellExtInitImpl : public IShellExtInit +{ +public: + + // IUnknown + // + STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) = 0; + _ATL_DEBUG_ADDREF_RELEASE_IMPL( IShellExtInitImpl ) + + + // IShellExtInit + // + STDMETHOD(Initialize)(LPCITEMIDLIST, LPDATAOBJECT, HKEY) + { + return S_FALSE; + }; + +}; + #endif \ No newline at end of file Index: src/chext/MenuExt.cpp =================================================================== diff -u -r9227280f45190af35bc63d25b0be65681f76de3b -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/MenuExt.cpp (.../MenuExt.cpp) (revision 9227280f45190af35bc63d25b0be65681f76de3b) +++ src/chext/MenuExt.cpp (.../MenuExt.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,670 +1,670 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "chext.h" -#include "MenuExt.h" -#include "clipboard.h" -#include "..\common\ipcstructs.h" -#include "..\common\FileSupport.h" -#include "stdio.h" -#include "memory.h" -#include "StringHelpers.h" -#include "chext-utils.h" - -extern CSharedConfigStruct* g_pscsShared; - -// globals -void CutAmpersands(LPTSTR lpszString) -{ - int iOffset=0; - size_t iLength=_tcslen(lpszString); - for (size_t j=0;jRelease(); - m_piShellExtControl = NULL; - } -} - -HRESULT CMenuExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) -{ -// OTF("CMenuExt::HandleMenuMsg\r\n"); - return HandleMenuMsg2(uMsg, wParam, lParam, NULL); -} - -HRESULT CMenuExt::HandleMenuMsg2(UINT uMsg, WPARAM /*wParam*/, LPARAM lParam, LRESULT* /*plResult*/) -{ - switch(uMsg) - { - case WM_INITMENUPOPUP: - { -// OTF("CMenuExt::HandleMenuMsg2 / Init menu popup\r\n"); - break; - } - - case WM_DRAWITEM: - { -// OTF("CMenuExt::HandleMenuMsg2 / Drawitem\r\n"); - LPDRAWITEMSTRUCT lpdis=(LPDRAWITEMSTRUCT) lParam; - DrawMenuItem(lpdis); - break; - } - - case WM_MEASUREITEM: - { -// OTF("CMenuExt::HandleMenuMsg2 / MeasureItem\r\n"); - LPMEASUREITEMSTRUCT lpmis=(LPMEASUREITEMSTRUCT)lParam; - - // establish display text - int iShortcutIndex=(lpmis->itemID-m_uiFirstID-5)%g_pscsShared->iShortcutsCount; - _SHORTCUT* pShortcuts = g_pscsShared->GetShortcutsPtr(); - - // measure the text - HWND hDesktop=GetDesktopWindow(); - HDC hDC=GetDC(hDesktop); - - // get menu logfont - NONCLIENTMETRICS ncm; - ncm.cbSize=sizeof(NONCLIENTMETRICS); - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0); - - HFONT hFont=CreateFontIndirect(&ncm.lfMenuFont); - HFONT hOldFont=(HFONT)SelectObject(hDC, hFont); - - // calc text size - SIZE size; - GetTextExtentPoint32(hDC, pShortcuts[iShortcutIndex].szName, (int)_tcslen(pShortcuts[iShortcutIndex].szName), &size); - - // restore old settings - SelectObject(hDC, hOldFont); - ReleaseDC(hDesktop, hDC); - - // set - lpmis->itemWidth=size.cx+GetSystemMetrics(SM_CXMENUCHECK)+2*GetSystemMetrics(SM_CXSMICON); - lpmis->itemHeight = __max(size.cy+3, GetSystemMetrics(SM_CYMENU)+3); - - break; - } - } - - return S_OK; -} - -void CMenuExt::DrawMenuItem(LPDRAWITEMSTRUCT lpdis) -{ - // check if menu - if (lpdis->CtlType != ODT_MENU) - return; - - // margins and other stuff - const int iSmallIconWidth=GetSystemMetrics(SM_CXSMICON); - const int iSmallIconHeight=GetSystemMetrics(SM_CYSMICON); - const int iLeftMargin=GetSystemMetrics(SM_CXMENUCHECK)/2; - const int iRightMargin=GetSystemMetrics(SM_CXMENUCHECK)-iLeftMargin; - - int iShortcutIndex=(lpdis->itemID-m_uiFirstID-5)%g_pscsShared->iShortcutsCount; - _SHORTCUT* pShortcuts=g_pscsShared->GetShortcutsPtr(); - - // text color - HBRUSH hbr; - if (lpdis->itemState & ODS_SELECTED) - { - SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT)); - hbr=CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT)); - } - else - { - SetTextColor(lpdis->hDC, GetSysColor(COLOR_MENUTEXT)); - SetBkColor(lpdis->hDC, GetSysColor(COLOR_MENU)); - hbr=CreateSolidBrush(GetSysColor(COLOR_MENU)); - } - - // draw background - RECT rcSelect=lpdis->rcItem; - rcSelect.top++; - rcSelect.bottom--; - - FillRect(lpdis->hDC, &rcSelect, hbr); - DeleteObject(hbr); - - // get img list - SHFILEINFO sfi; - HIMAGELIST himl=(HIMAGELIST)SHGetFileInfo(pShortcuts[iShortcutIndex].szPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_SYSICONINDEX); - ImageList_Draw(himl, sfi.iIcon, lpdis->hDC, lpdis->rcItem.left+iLeftMargin, - lpdis->rcItem.top+(lpdis->rcItem.bottom-lpdis->rcItem.top+1-iSmallIconHeight)/2, ILD_TRANSPARENT); - - RECT rcText; - rcText.left=iLeftMargin+iSmallIconWidth+iRightMargin; - rcText.top=lpdis->rcItem.top; - rcText.right=lpdis->rcItem.right; - rcText.bottom=lpdis->rcItem.bottom; - -// OTF("Drawing text: %s\r\n", pShortcuts[iShortcutIndex].szName); - DrawText(lpdis->hDC, pShortcuts[iShortcutIndex].szName, -1, &rcText, DT_LEFT | DT_SINGLELINE | DT_VCENTER); -} - -STDMETHODIMP CMenuExt::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/) -{ - // check options - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - return hResult; - - // find ch window - HWND hWnd; - hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if(!hWnd) - return S_OK; - -/* OTF("CMenuExt::QueryContextMenu - idCmdFirst=%lu, uFlags=%lu (", idCmdFirst, uFlags); - if (uFlags & CMF_CANRENAME) - OTF("CMF_CANRENAME "); - if (uFlags & CMF_DEFAULTONLY) - OTF("CMF_DEFAULTONLY "); - if (uFlags & CMF_EXPLORE) - OTF("CMF_EXPLORE "); - if (uFlags & CMF_EXTENDEDVERBS) - OTF("CMF_EXTENDEDVERBS "); - if (uFlags & CMF_INCLUDESTATIC) - OTF("CMF_INCLUDESTATIC "); - if (uFlags & CMF_NODEFAULT) - OTF("CMF_NODEFAULT "); - if (uFlags & CMF_NORMAL) - OTF("CMF_NORMAL "); - if (uFlags & CMF_NOVERBS) - OTF("CMF_NOVERBS "); - if (uFlags & CMF_VERBSONLY) - OTF("CMF_VERBSONLY "); - OTF(")\r\n"); -*/ - // remember ID of the first command - m_uiFirstID=idCmdFirst; - - // current commands count in menu - TCHAR szText[_MAX_PATH]; - int iCount=::GetMenuItemCount(hmenu); - - MENUITEMINFO mii; - mii.cbSize=sizeof(mii); - mii.fMask=MIIM_TYPE; - mii.dwTypeData=szText; - mii.cch=_MAX_PATH; - - // find a place where the commands should be inserted - for (int i=0;iGetCommandsPtr(); - - // data about commands - int iCommandCount=0; - - if (!m_bGroupFiles) - { - // paste - if (g_pscsShared->uiFlags & EC_PASTE_FLAG) - { - ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING | (IsClipboardFormatAvailable(CF_HDROP) ? MF_ENABLED : MF_GRAYED), - idCmdFirst+0, pCommand[0].szCommand); - iCommandCount++; - } - - if (g_pscsShared->uiFlags & EC_PASTESPECIAL_FLAG) - { - ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING | (IsClipboardFormatAvailable(CF_HDROP) ? MF_ENABLED : MF_GRAYED), - idCmdFirst+1, pCommand[1].szCommand); - iCommandCount++; - } - } - -// OTF("After group files\r\n"); - - if (!m_bBackground) - { - CreateShortcutsMenu(idCmdFirst+5, g_pscsShared->bShowShortcutIcons); -// OTF("after creating shortcuts menu\r\n"); - - // copy to > - if (g_pscsShared->uiFlags & EC_COPYTO_FLAG) - { - mii.cbSize=sizeof(MENUITEMINFO); - mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; - mii.fType=MFT_STRING; - mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED; - mii.wID=idCmdFirst+2; - mii.hSubMenu=m_mMenus.hShortcuts[0]; - mii.dwTypeData=pCommand[2].szCommand; - mii.cch=_tcslen(pCommand[2].szCommand); - - ::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii); -// ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED), -// (UINT)m_mMenus.hShortcuts[0], pCommand[2].szCommand); - iCommandCount++; -// OTF("added menu item\r\n"); - } - - // move to > - if (g_pscsShared->uiFlags & EC_MOVETO_FLAG) - { - mii.cbSize=sizeof(MENUITEMINFO); - mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; - mii.fType=MFT_STRING; - mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED; - mii.wID=idCmdFirst+3; - mii.hSubMenu=m_mMenus.hShortcuts[1]; - mii.dwTypeData=pCommand[3].szCommand; - mii.cch=_tcslen(pCommand[3].szCommand); - - ::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii); -// ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED), -// (UINT)m_mMenus.hShortcuts[1], pCommand[3].szCommand); - iCommandCount++; - } - - // copy/move to special... > - if (g_pscsShared->uiFlags & EC_COPYMOVETOSPECIAL_FLAG) - { - mii.cbSize=sizeof(MENUITEMINFO); - mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; - mii.fType=MFT_STRING; - mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED; - mii.wID=idCmdFirst+4; - mii.hSubMenu=m_mMenus.hShortcuts[2]; - mii.dwTypeData=pCommand[4].szCommand; - mii.cch=_tcslen(pCommand[4].szCommand); - - ::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii); -// ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED), -// (UINT)m_mMenus.hShortcuts[2], pCommand[4].szCommand); - iCommandCount++; - } - } - -// OTF("before return\r\n"); - return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, g_pscsShared->iCommandCount+(m_bBackground ? 0 : 3*g_pscsShared->iShortcutsCount)); -} - -void CMenuExt::CreateShortcutsMenu(UINT uiIDBase, bool bOwnerDrawn) -{ -// OTF("CreateShortcutsMenu\r\n"); - - // tw�rz puste menu - m_mMenus.hShortcuts[0]=CreatePopupMenu(); - m_mMenus.hShortcuts[1]=CreatePopupMenu(); - m_mMenus.hShortcuts[2]=CreatePopupMenu(); - - // fill with shortcuts - _SHORTCUT* pShortcuts=g_pscsShared->GetShortcutsPtr(); - TCHAR szText[256], szSize[32]; - ull_t ullFree; - - for (int i=0;iiShortcutsCount;i++) - { - // modify text - if (g_pscsShared->bShowFreeSpace && GetDynamicFreeSpace(pShortcuts[i].szPath, &ullFree, NULL)) - { - _sntprintf(szText, 256 - 1, _T("%s (%s)"), pShortcuts[i].szName, GetSizeString(ullFree, szSize, 32)); - szText[256 - 1] = _T('\0'); - _tcsncpy(pShortcuts[i].szName, szText, 127); -// OTF("Text to display=%s\r\n", pShortcuts[i].szName); - pShortcuts[i].szName[127]=_T('\0'); - } - - // add to all menus - for (int j=0;j<3;j++) - ::InsertMenu(m_mMenus.hShortcuts[j], i, MF_BYPOSITION | MF_ENABLED | (bOwnerDrawn ? MF_OWNERDRAW : 0), uiIDBase+i+j*g_pscsShared->iShortcutsCount, (bOwnerDrawn ? NULL : pShortcuts[i].szName)); - } -} - -STDMETHODIMP CMenuExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax) -{ - // check options - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - { - pszName[0] = _T('\0'); - return hResult; - } - - LONG lFlags = eShellExt_None; - hResult = m_piShellExtControl->GetFlags(&lFlags); - if(FAILED(hResult)) - { - pszName[0] = _T('\0'); - return hResult; - } - if(!(lFlags & eShellExt_Enabled)) - { - pszName[0] = _T('\0'); - return S_OK; - } - - if (uFlags == GCS_HELPTEXTW) - { - USES_CONVERSION; - // find window - HWND hWnd; - hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if (!hWnd) - wcscpy(reinterpret_cast(pszName), L""); - - _COMMAND* pCommand=g_pscsShared->GetCommandsPtr(); - - switch (idCmd) - { - case 0: - case 1: - case 2: - case 3: - case 4: - { - CT2W ct2w(pCommand[idCmd].szDesc); - wcsncpy(reinterpret_cast(pszName), ct2w, cchMax); - break; - } - default: - _SHORTCUT* pShortcuts = g_pscsShared->GetShortcutsPtr(); - if ((int)(idCmd-5) < g_pscsShared->iShortcutsCount*3) - { - CT2W ct2w(pShortcuts[(idCmd-5)%g_pscsShared->iShortcutsCount].szPath); - wcsncpy(reinterpret_cast(pszName), ct2w, cchMax); - } - else - wcsncpy(reinterpret_cast(pszName), L"", cchMax); - } - } - if (uFlags == GCS_HELPTEXTA) - { - // find window - HWND hWnd; - hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - - if (!hWnd) - strcpy(pszName, ""); - - _COMMAND* pCommand=g_pscsShared->GetCommandsPtr(); - - switch (idCmd) - { - case 0: - case 1: - case 2: - case 3: - case 4: - { - CT2A ct2a(pCommand[idCmd].szDesc); - strncpy(reinterpret_cast(pszName), ct2a, cchMax); - break; - } - default: // rest of commands - _SHORTCUT* pShortcuts = g_pscsShared->GetShortcutsPtr(); - if ((int)(idCmd-5) < g_pscsShared->iShortcutsCount*3) - { - CT2A ct2a(pShortcuts[(idCmd-5)%g_pscsShared->iShortcutsCount].szPath); - strncpy(pszName, ct2a, cchMax); - } - else - strncpy(pszName, "", cchMax); - } - } - - return S_OK; -} - - -STDMETHODIMP CMenuExt::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/) -{ - // check options - HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); - if(FAILED(hResult) || hResult == S_FALSE) - return hResult; - - // find ch window - HWND hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); - if (hWnd == NULL) - return E_FAIL; - - // get cfg from ch - ::SendMessage(hWnd, WM_GETCONFIG, GC_EXPLORER, 0); - - // read dest folder - m_szDstPath[0]=_T('\0'); - - // TEMP -// OTF("****************************************************************\r\n"); -// OTF("CMenuExt::Initialize: pidlFolder=%lu, lpdobj=%lu\r\n", pidlFolder, lpdobj); - - // get data from IDataObject - files to copy/move - bool bPathFound=false; - m_bGroupFiles=false; - if (lpdobj) - { - STGMEDIUM medium; - FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; - - HRESULT hr = lpdobj->GetData(&fe, &medium); - if (FAILED(hr)) - return E_FAIL; - - // copy all filenames to a table - GetDataFromClipboard(static_cast(medium.hGlobal), NULL, &m_bBuffer.m_pszFiles, &m_bBuffer.m_iDataSize); - - // find the first non-empty entry - UINT fileCount = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0); - TCHAR szPath[_MAX_PATH]; - UINT uiRes; - for (UINT i=0;iGetCommandsPtr(); - -// OTF("Invoke Command\r\n"); - // command type - switch (LOWORD(lpici->lpVerb)) - { - // paste & paste special - case 0: - case 1: - { - // search for data in a clipboard - if (IsClipboardFormatAvailable(CF_HDROP)) - { - bool bMove=false; // 0-copy, 1-move - - // get data - OpenClipboard(lpici->hwnd); - HANDLE handle=GetClipboardData(CF_HDROP); - TCHAR *pchBuffer=NULL; - UINT uiSize; - - GetDataFromClipboard(static_cast(handle), m_szDstPath, &pchBuffer, &uiSize); - - // register clipboard format nad if exists in it - UINT nFormat=RegisterClipboardFormat(_T("Preferred DropEffect")); - if (IsClipboardFormatAvailable(nFormat)) - { - handle=GetClipboardData(nFormat); - LPVOID addr=GlobalLock(handle); - if(!addr) - return E_FAIL; - DWORD dwData=((DWORD*)addr)[0]; - if (dwData & DROPEFFECT_MOVE) - bMove=true; - - GlobalUnlock(handle); - } - - CloseClipboard(); - - // fill struct - COPYDATASTRUCT cds; - cds.dwData=(((DWORD)bMove) << 31) | pCommand[LOWORD(lpici->lpVerb)].uiCommandID; - cds.lpData=pchBuffer; - cds.cbData=uiSize * sizeof(TCHAR); - - // send a message - ::SendMessage(hWnd, WM_COPYDATA, reinterpret_cast(lpici->hwnd), reinterpret_cast(&cds)); - - // delete buffer - delete [] pchBuffer; - } - } - break; - -// case 2: -// case 3: -// case 4: - default: - { - // out of range - may be a shortcut - if (LOWORD(lpici->lpVerb) < g_pscsShared->iCommandCount+(m_bBackground ? 0 : 3*g_pscsShared->iShortcutsCount)) - { - // addr of a table with shortcuts - _SHORTCUT* stShortcuts = g_pscsShared->GetShortcutsPtr(); - - // find command for which this command is generated - int iCommandIndex=(int)(((LOWORD(lpici->lpVerb)-5) / g_pscsShared->iShortcutsCount))+2; // command index - int iShortcutIndex=((LOWORD(lpici->lpVerb)-5) % g_pscsShared->iShortcutsCount); // shortcut index - - // buffer for data - UINT uiSize=_tcslen(stShortcuts[iShortcutIndex].szPath)+1+m_bBuffer.m_iDataSize; - TCHAR *pszBuffer=new TCHAR[uiSize]; - _tcscpy(pszBuffer, stShortcuts[iShortcutIndex].szPath); // �cie�ka docelowa - - // buffer with files - memcpy(pszBuffer+_tcslen(stShortcuts[iShortcutIndex].szPath)+1, m_bBuffer.m_pszFiles, m_bBuffer.m_iDataSize*sizeof(TCHAR)); - - // fill struct - COPYDATASTRUCT cds; - cds.dwData=pCommand[iCommandIndex].uiCommandID; - cds.lpData=pszBuffer; - cds.cbData=uiSize * sizeof(TCHAR); - - // send message - ::SendMessage(hWnd, WM_COPYDATA, reinterpret_cast(lpici->hwnd), reinterpret_cast(&cds)); - - // delete buffer - delete [] pszBuffer; - m_bBuffer.Destroy(); - } - else - return E_FAIL; - } - break; - } - - return S_OK; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "chext.h" +#include "MenuExt.h" +#include "clipboard.h" +#include "..\common\ipcstructs.h" +#include "..\common\FileSupport.h" +#include "stdio.h" +#include "memory.h" +#include "StringHelpers.h" +#include "chext-utils.h" + +extern CSharedConfigStruct* g_pscsShared; + +// globals +void CutAmpersands(LPTSTR lpszString) +{ + int iOffset=0; + size_t iLength=_tcslen(lpszString); + for (size_t j=0;jRelease(); + m_piShellExtControl = NULL; + } +} + +HRESULT CMenuExt::HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ +// OTF("CMenuExt::HandleMenuMsg\r\n"); + return HandleMenuMsg2(uMsg, wParam, lParam, NULL); +} + +HRESULT CMenuExt::HandleMenuMsg2(UINT uMsg, WPARAM /*wParam*/, LPARAM lParam, LRESULT* /*plResult*/) +{ + switch(uMsg) + { + case WM_INITMENUPOPUP: + { +// OTF("CMenuExt::HandleMenuMsg2 / Init menu popup\r\n"); + break; + } + + case WM_DRAWITEM: + { +// OTF("CMenuExt::HandleMenuMsg2 / Drawitem\r\n"); + LPDRAWITEMSTRUCT lpdis=(LPDRAWITEMSTRUCT) lParam; + DrawMenuItem(lpdis); + break; + } + + case WM_MEASUREITEM: + { +// OTF("CMenuExt::HandleMenuMsg2 / MeasureItem\r\n"); + LPMEASUREITEMSTRUCT lpmis=(LPMEASUREITEMSTRUCT)lParam; + + // establish display text + int iShortcutIndex=(lpmis->itemID-m_uiFirstID-5)%g_pscsShared->iShortcutsCount; + _SHORTCUT* pShortcuts = g_pscsShared->GetShortcutsPtr(); + + // measure the text + HWND hDesktop=GetDesktopWindow(); + HDC hDC=GetDC(hDesktop); + + // get menu logfont + NONCLIENTMETRICS ncm; + ncm.cbSize=sizeof(NONCLIENTMETRICS); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0); + + HFONT hFont=CreateFontIndirect(&ncm.lfMenuFont); + HFONT hOldFont=(HFONT)SelectObject(hDC, hFont); + + // calc text size + SIZE size; + GetTextExtentPoint32(hDC, pShortcuts[iShortcutIndex].szName, (int)_tcslen(pShortcuts[iShortcutIndex].szName), &size); + + // restore old settings + SelectObject(hDC, hOldFont); + ReleaseDC(hDesktop, hDC); + + // set + lpmis->itemWidth=size.cx+GetSystemMetrics(SM_CXMENUCHECK)+2*GetSystemMetrics(SM_CXSMICON); + lpmis->itemHeight = __max(size.cy+3, GetSystemMetrics(SM_CYMENU)+3); + + break; + } + } + + return S_OK; +} + +void CMenuExt::DrawMenuItem(LPDRAWITEMSTRUCT lpdis) +{ + // check if menu + if (lpdis->CtlType != ODT_MENU) + return; + + // margins and other stuff + const int iSmallIconWidth=GetSystemMetrics(SM_CXSMICON); + const int iSmallIconHeight=GetSystemMetrics(SM_CYSMICON); + const int iLeftMargin=GetSystemMetrics(SM_CXMENUCHECK)/2; + const int iRightMargin=GetSystemMetrics(SM_CXMENUCHECK)-iLeftMargin; + + int iShortcutIndex=(lpdis->itemID-m_uiFirstID-5)%g_pscsShared->iShortcutsCount; + _SHORTCUT* pShortcuts=g_pscsShared->GetShortcutsPtr(); + + // text color + HBRUSH hbr; + if (lpdis->itemState & ODS_SELECTED) + { + SetTextColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkColor(lpdis->hDC, GetSysColor(COLOR_HIGHLIGHT)); + hbr=CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT)); + } + else + { + SetTextColor(lpdis->hDC, GetSysColor(COLOR_MENUTEXT)); + SetBkColor(lpdis->hDC, GetSysColor(COLOR_MENU)); + hbr=CreateSolidBrush(GetSysColor(COLOR_MENU)); + } + + // draw background + RECT rcSelect=lpdis->rcItem; + rcSelect.top++; + rcSelect.bottom--; + + FillRect(lpdis->hDC, &rcSelect, hbr); + DeleteObject(hbr); + + // get img list + SHFILEINFO sfi; + HIMAGELIST himl=(HIMAGELIST)SHGetFileInfo(pShortcuts[iShortcutIndex].szPath, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_SMALLICON | SHGFI_ICON | SHGFI_SYSICONINDEX); + ImageList_Draw(himl, sfi.iIcon, lpdis->hDC, lpdis->rcItem.left+iLeftMargin, + lpdis->rcItem.top+(lpdis->rcItem.bottom-lpdis->rcItem.top+1-iSmallIconHeight)/2, ILD_TRANSPARENT); + + RECT rcText; + rcText.left=iLeftMargin+iSmallIconWidth+iRightMargin; + rcText.top=lpdis->rcItem.top; + rcText.right=lpdis->rcItem.right; + rcText.bottom=lpdis->rcItem.bottom; + +// OTF("Drawing text: %s\r\n", pShortcuts[iShortcutIndex].szName); + DrawText(lpdis->hDC, pShortcuts[iShortcutIndex].szName, -1, &rcText, DT_LEFT | DT_SINGLELINE | DT_VCENTER); +} + +STDMETHODIMP CMenuExt::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/) +{ + // check options + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + return hResult; + + // find ch window + HWND hWnd; + hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if(!hWnd) + return S_OK; + +/* OTF("CMenuExt::QueryContextMenu - idCmdFirst=%lu, uFlags=%lu (", idCmdFirst, uFlags); + if (uFlags & CMF_CANRENAME) + OTF("CMF_CANRENAME "); + if (uFlags & CMF_DEFAULTONLY) + OTF("CMF_DEFAULTONLY "); + if (uFlags & CMF_EXPLORE) + OTF("CMF_EXPLORE "); + if (uFlags & CMF_EXTENDEDVERBS) + OTF("CMF_EXTENDEDVERBS "); + if (uFlags & CMF_INCLUDESTATIC) + OTF("CMF_INCLUDESTATIC "); + if (uFlags & CMF_NODEFAULT) + OTF("CMF_NODEFAULT "); + if (uFlags & CMF_NORMAL) + OTF("CMF_NORMAL "); + if (uFlags & CMF_NOVERBS) + OTF("CMF_NOVERBS "); + if (uFlags & CMF_VERBSONLY) + OTF("CMF_VERBSONLY "); + OTF(")\r\n"); +*/ + // remember ID of the first command + m_uiFirstID=idCmdFirst; + + // current commands count in menu + TCHAR szText[_MAX_PATH]; + int iCount=::GetMenuItemCount(hmenu); + + MENUITEMINFO mii; + mii.cbSize=sizeof(mii); + mii.fMask=MIIM_TYPE; + mii.dwTypeData=szText; + mii.cch=_MAX_PATH; + + // find a place where the commands should be inserted + for (int i=0;iGetCommandsPtr(); + + // data about commands + int iCommandCount=0; + + if (!m_bGroupFiles) + { + // paste + if (g_pscsShared->uiFlags & EC_PASTE_FLAG) + { + ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING | (IsClipboardFormatAvailable(CF_HDROP) ? MF_ENABLED : MF_GRAYED), + idCmdFirst+0, pCommand[0].szCommand); + iCommandCount++; + } + + if (g_pscsShared->uiFlags & EC_PASTESPECIAL_FLAG) + { + ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_STRING | (IsClipboardFormatAvailable(CF_HDROP) ? MF_ENABLED : MF_GRAYED), + idCmdFirst+1, pCommand[1].szCommand); + iCommandCount++; + } + } + +// OTF("After group files\r\n"); + + if (!m_bBackground) + { + CreateShortcutsMenu(idCmdFirst+5, g_pscsShared->bShowShortcutIcons); +// OTF("after creating shortcuts menu\r\n"); + + // copy to > + if (g_pscsShared->uiFlags & EC_COPYTO_FLAG) + { + mii.cbSize=sizeof(MENUITEMINFO); + mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; + mii.fType=MFT_STRING; + mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED; + mii.wID=idCmdFirst+2; + mii.hSubMenu=m_mMenus.hShortcuts[0]; + mii.dwTypeData=pCommand[2].szCommand; + mii.cch=_tcslen(pCommand[2].szCommand); + + ::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii); +// ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED), +// (UINT)m_mMenus.hShortcuts[0], pCommand[2].szCommand); + iCommandCount++; +// OTF("added menu item\r\n"); + } + + // move to > + if (g_pscsShared->uiFlags & EC_MOVETO_FLAG) + { + mii.cbSize=sizeof(MENUITEMINFO); + mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; + mii.fType=MFT_STRING; + mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED; + mii.wID=idCmdFirst+3; + mii.hSubMenu=m_mMenus.hShortcuts[1]; + mii.dwTypeData=pCommand[3].szCommand; + mii.cch=_tcslen(pCommand[3].szCommand); + + ::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii); +// ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED), +// (UINT)m_mMenus.hShortcuts[1], pCommand[3].szCommand); + iCommandCount++; + } + + // copy/move to special... > + if (g_pscsShared->uiFlags & EC_COPYMOVETOSPECIAL_FLAG) + { + mii.cbSize=sizeof(MENUITEMINFO); + mii.fMask=MIIM_ID | MIIM_STATE | MIIM_SUBMENU | MIIM_TYPE; + mii.fType=MFT_STRING; + mii.fState=(g_pscsShared->iShortcutsCount > 0) ? MFS_ENABLED : MFS_GRAYED; + mii.wID=idCmdFirst+4; + mii.hSubMenu=m_mMenus.hShortcuts[2]; + mii.dwTypeData=pCommand[4].szCommand; + mii.cch=_tcslen(pCommand[4].szCommand); + + ::InsertMenuItem(hmenu, indexMenu++, TRUE, &mii); +// ::InsertMenu(hmenu, indexMenu++, MF_BYPOSITION | MF_POPUP | MF_STRING | ((g_pscsShared->iShortcutsCount > 0) ? MF_ENABLED : MF_GRAYED), +// (UINT)m_mMenus.hShortcuts[2], pCommand[4].szCommand); + iCommandCount++; + } + } + +// OTF("before return\r\n"); + return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, g_pscsShared->iCommandCount+(m_bBackground ? 0 : 3*g_pscsShared->iShortcutsCount)); +} + +void CMenuExt::CreateShortcutsMenu(UINT uiIDBase, bool bOwnerDrawn) +{ +// OTF("CreateShortcutsMenu\r\n"); + + // tw�rz puste menu + m_mMenus.hShortcuts[0]=CreatePopupMenu(); + m_mMenus.hShortcuts[1]=CreatePopupMenu(); + m_mMenus.hShortcuts[2]=CreatePopupMenu(); + + // fill with shortcuts + _SHORTCUT* pShortcuts=g_pscsShared->GetShortcutsPtr(); + TCHAR szText[256], szSize[32]; + ull_t ullFree; + + for (int i=0;iiShortcutsCount;i++) + { + // modify text + if (g_pscsShared->bShowFreeSpace && GetDynamicFreeSpace(pShortcuts[i].szPath, &ullFree, NULL)) + { + _sntprintf(szText, 256 - 1, _T("%s (%s)"), pShortcuts[i].szName, GetSizeString(ullFree, szSize, 32)); + szText[256 - 1] = _T('\0'); + _tcsncpy(pShortcuts[i].szName, szText, 127); +// OTF("Text to display=%s\r\n", pShortcuts[i].szName); + pShortcuts[i].szName[127]=_T('\0'); + } + + // add to all menus + for (int j=0;j<3;j++) + ::InsertMenu(m_mMenus.hShortcuts[j], i, MF_BYPOSITION | MF_ENABLED | (bOwnerDrawn ? MF_OWNERDRAW : 0), uiIDBase+i+j*g_pscsShared->iShortcutsCount, (bOwnerDrawn ? NULL : pShortcuts[i].szName)); + } +} + +STDMETHODIMP CMenuExt::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax) +{ + // check options + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + { + pszName[0] = _T('\0'); + return hResult; + } + + LONG lFlags = eShellExt_None; + hResult = m_piShellExtControl->GetFlags(&lFlags); + if(FAILED(hResult)) + { + pszName[0] = _T('\0'); + return hResult; + } + if(!(lFlags & eShellExt_Enabled)) + { + pszName[0] = _T('\0'); + return S_OK; + } + + if (uFlags == GCS_HELPTEXTW) + { + USES_CONVERSION; + // find window + HWND hWnd; + hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if (!hWnd) + wcscpy(reinterpret_cast(pszName), L""); + + _COMMAND* pCommand=g_pscsShared->GetCommandsPtr(); + + switch (idCmd) + { + case 0: + case 1: + case 2: + case 3: + case 4: + { + CT2W ct2w(pCommand[idCmd].szDesc); + wcsncpy(reinterpret_cast(pszName), ct2w, cchMax); + break; + } + default: + _SHORTCUT* pShortcuts = g_pscsShared->GetShortcutsPtr(); + if ((int)(idCmd-5) < g_pscsShared->iShortcutsCount*3) + { + CT2W ct2w(pShortcuts[(idCmd-5)%g_pscsShared->iShortcutsCount].szPath); + wcsncpy(reinterpret_cast(pszName), ct2w, cchMax); + } + else + wcsncpy(reinterpret_cast(pszName), L"", cchMax); + } + } + if (uFlags == GCS_HELPTEXTA) + { + // find window + HWND hWnd; + hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + + if (!hWnd) + strcpy(pszName, ""); + + _COMMAND* pCommand=g_pscsShared->GetCommandsPtr(); + + switch (idCmd) + { + case 0: + case 1: + case 2: + case 3: + case 4: + { + CT2A ct2a(pCommand[idCmd].szDesc); + strncpy(reinterpret_cast(pszName), ct2a, cchMax); + break; + } + default: // rest of commands + _SHORTCUT* pShortcuts = g_pscsShared->GetShortcutsPtr(); + if ((int)(idCmd-5) < g_pscsShared->iShortcutsCount*3) + { + CT2A ct2a(pShortcuts[(idCmd-5)%g_pscsShared->iShortcutsCount].szPath); + strncpy(pszName, ct2a, cchMax); + } + else + strncpy(pszName, "", cchMax); + } + } + + return S_OK; +} + + +STDMETHODIMP CMenuExt::Initialize(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/) +{ + // check options + HRESULT hResult = IsShellExtEnabled(m_piShellExtControl); + if(FAILED(hResult) || hResult == S_FALSE) + return hResult; + + // find ch window + HWND hWnd=::FindWindow(_T("Copy Handler Wnd Class"), _T("Copy handler")); + if (hWnd == NULL) + return E_FAIL; + + // get cfg from ch + ::SendMessage(hWnd, WM_GETCONFIG, GC_EXPLORER, 0); + + // read dest folder + m_szDstPath[0]=_T('\0'); + + // TEMP +// OTF("****************************************************************\r\n"); +// OTF("CMenuExt::Initialize: pidlFolder=%lu, lpdobj=%lu\r\n", pidlFolder, lpdobj); + + // get data from IDataObject - files to copy/move + bool bPathFound=false; + m_bGroupFiles=false; + if (lpdobj) + { + STGMEDIUM medium; + FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; + + HRESULT hr = lpdobj->GetData(&fe, &medium); + if (FAILED(hr)) + return E_FAIL; + + // copy all filenames to a table + GetDataFromClipboard(static_cast(medium.hGlobal), NULL, &m_bBuffer.m_pszFiles, &m_bBuffer.m_iDataSize); + + // find the first non-empty entry + UINT fileCount = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0); + TCHAR szPath[_MAX_PATH]; + UINT uiRes; + for (UINT i=0;iGetCommandsPtr(); + +// OTF("Invoke Command\r\n"); + // command type + switch (LOWORD(lpici->lpVerb)) + { + // paste & paste special + case 0: + case 1: + { + // search for data in a clipboard + if (IsClipboardFormatAvailable(CF_HDROP)) + { + bool bMove=false; // 0-copy, 1-move + + // get data + OpenClipboard(lpici->hwnd); + HANDLE handle=GetClipboardData(CF_HDROP); + TCHAR *pchBuffer=NULL; + UINT uiSize; + + GetDataFromClipboard(static_cast(handle), m_szDstPath, &pchBuffer, &uiSize); + + // register clipboard format nad if exists in it + UINT nFormat=RegisterClipboardFormat(_T("Preferred DropEffect")); + if (IsClipboardFormatAvailable(nFormat)) + { + handle=GetClipboardData(nFormat); + LPVOID addr=GlobalLock(handle); + if(!addr) + return E_FAIL; + DWORD dwData=((DWORD*)addr)[0]; + if (dwData & DROPEFFECT_MOVE) + bMove=true; + + GlobalUnlock(handle); + } + + CloseClipboard(); + + // fill struct + COPYDATASTRUCT cds; + cds.dwData=(((DWORD)bMove) << 31) | pCommand[LOWORD(lpici->lpVerb)].uiCommandID; + cds.lpData=pchBuffer; + cds.cbData=uiSize * sizeof(TCHAR); + + // send a message + ::SendMessage(hWnd, WM_COPYDATA, reinterpret_cast(lpici->hwnd), reinterpret_cast(&cds)); + + // delete buffer + delete [] pchBuffer; + } + } + break; + +// case 2: +// case 3: +// case 4: + default: + { + // out of range - may be a shortcut + if (LOWORD(lpici->lpVerb) < g_pscsShared->iCommandCount+(m_bBackground ? 0 : 3*g_pscsShared->iShortcutsCount)) + { + // addr of a table with shortcuts + _SHORTCUT* stShortcuts = g_pscsShared->GetShortcutsPtr(); + + // find command for which this command is generated + int iCommandIndex=(int)(((LOWORD(lpici->lpVerb)-5) / g_pscsShared->iShortcutsCount))+2; // command index + int iShortcutIndex=((LOWORD(lpici->lpVerb)-5) % g_pscsShared->iShortcutsCount); // shortcut index + + // buffer for data + UINT uiSize=_tcslen(stShortcuts[iShortcutIndex].szPath)+1+m_bBuffer.m_iDataSize; + TCHAR *pszBuffer=new TCHAR[uiSize]; + _tcscpy(pszBuffer, stShortcuts[iShortcutIndex].szPath); // �cie�ka docelowa + + // buffer with files + memcpy(pszBuffer+_tcslen(stShortcuts[iShortcutIndex].szPath)+1, m_bBuffer.m_pszFiles, m_bBuffer.m_iDataSize*sizeof(TCHAR)); + + // fill struct + COPYDATASTRUCT cds; + cds.dwData=pCommand[iCommandIndex].uiCommandID; + cds.lpData=pszBuffer; + cds.cbData=uiSize * sizeof(TCHAR); + + // send message + ::SendMessage(hWnd, WM_COPYDATA, reinterpret_cast(lpici->hwnd), reinterpret_cast(&cds)); + + // delete buffer + delete [] pszBuffer; + m_bBuffer.Destroy(); + } + else + return E_FAIL; + } + break; + } + + return S_OK; +} Index: src/chext/MenuExt.h =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/MenuExt.h (.../MenuExt.h) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/chext/MenuExt.h (.../MenuExt.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,113 +1,113 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __MENUEXT_H_ -#define __MENUEXT_H_ - -#include "resource.h" // main symbols -#include "comdef.h" -#include -#include - -#include "IShellExtInitImpl.h" -#include "IContextMenuImpl.h" - -/////// -// globals -void CutAmpersands(LPTSTR lpszString); - -///////////////////////////////////////////////////////////////////////////// -// CMenuExt -class ATL_NO_VTABLE CMenuExt : - public CComObjectRootEx, - public CComCoClass, - public IObjectWithSiteImpl, - public IDispatchImpl, - public IShellExtInitImpl, - public IContextMenuImpl -{ -public: - CMenuExt(); - ~CMenuExt(); - -public: - // class for making sure memory is freed - class CBuffer - { - public: - CBuffer() { m_pszFiles=NULL; m_iDataSize=0; }; - void Destroy() { delete [] m_pszFiles; m_pszFiles=NULL; m_iDataSize=0; }; - ~CBuffer() { Destroy(); }; - - public: - TCHAR *m_pszFiles; - UINT m_iDataSize; - } m_bBuffer; - - TCHAR m_szDstPath[_MAX_PATH]; - - // for making sure DestroyMenu would be called - class CSubMenus - { - public: - CSubMenus() { hShortcuts[0]=NULL; hShortcuts[1]=NULL; hShortcuts[2]=NULL; }; - void Destroy() { for (int i=0;i<3;i++) { if (hShortcuts[i] != NULL) DestroyMenu(hShortcuts[i]); } }; - ~CSubMenus() { Destroy(); }; - - public: - HMENU hShortcuts[3]; - } m_mMenus; - - bool m_bBackground; // folder or folder background - bool m_bGroupFiles; // if the group of files have a files in it - - UINT m_uiFirstID; // first menu ID - bool m_bShown; // have the menu been already shown ? - - IShellExtControl* m_piShellExtControl; - -DECLARE_REGISTRY_RESOURCEID(IDR_MENUEXT) -DECLARE_NOT_AGGREGATABLE(CMenuExt) - -DECLARE_PROTECT_FINAL_CONSTRUCT() - -BEGIN_COM_MAP(CMenuExt) - COM_INTERFACE_ENTRY(IMenuExt) - COM_INTERFACE_ENTRY(IDispatch) - COM_INTERFACE_ENTRY(IShellExtInit) - COM_INTERFACE_ENTRY(IContextMenu) - COM_INTERFACE_ENTRY(IContextMenu2) - COM_INTERFACE_ENTRY(IContextMenu3) - COM_INTERFACE_ENTRY(IObjectWithSite) -END_COM_MAP() - -// IMenuExt -public: - STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/); - STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici); - STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax); - STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/); - STDMETHOD(HandleMenuMsg)(UINT uMsg, WPARAM wParam, LPARAM lParam); - STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); - -protected: - void DrawMenuItem(LPDRAWITEMSTRUCT lpdis); - void CreateShortcutsMenu(UINT uiIDBase, bool bOwnerDrawn); -}; - -#endif //__MENUEXT_H_ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __MENUEXT_H_ +#define __MENUEXT_H_ + +#include "resource.h" // main symbols +#include "comdef.h" +#include +#include + +#include "IShellExtInitImpl.h" +#include "IContextMenuImpl.h" + +/////// +// globals +void CutAmpersands(LPTSTR lpszString); + +///////////////////////////////////////////////////////////////////////////// +// CMenuExt +class ATL_NO_VTABLE CMenuExt : + public CComObjectRootEx, + public CComCoClass, + public IObjectWithSiteImpl, + public IDispatchImpl, + public IShellExtInitImpl, + public IContextMenuImpl +{ +public: + CMenuExt(); + ~CMenuExt(); + +public: + // class for making sure memory is freed + class CBuffer + { + public: + CBuffer() { m_pszFiles=NULL; m_iDataSize=0; }; + void Destroy() { delete [] m_pszFiles; m_pszFiles=NULL; m_iDataSize=0; }; + ~CBuffer() { Destroy(); }; + + public: + TCHAR *m_pszFiles; + UINT m_iDataSize; + } m_bBuffer; + + TCHAR m_szDstPath[_MAX_PATH]; + + // for making sure DestroyMenu would be called + class CSubMenus + { + public: + CSubMenus() { hShortcuts[0]=NULL; hShortcuts[1]=NULL; hShortcuts[2]=NULL; }; + void Destroy() { for (int i=0;i<3;i++) { if (hShortcuts[i] != NULL) DestroyMenu(hShortcuts[i]); } }; + ~CSubMenus() { Destroy(); }; + + public: + HMENU hShortcuts[3]; + } m_mMenus; + + bool m_bBackground; // folder or folder background + bool m_bGroupFiles; // if the group of files have a files in it + + UINT m_uiFirstID; // first menu ID + bool m_bShown; // have the menu been already shown ? + + IShellExtControl* m_piShellExtControl; + +DECLARE_REGISTRY_RESOURCEID(IDR_MENUEXT) +DECLARE_NOT_AGGREGATABLE(CMenuExt) + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CMenuExt) + COM_INTERFACE_ENTRY(IMenuExt) + COM_INTERFACE_ENTRY(IDispatch) + COM_INTERFACE_ENTRY(IShellExtInit) + COM_INTERFACE_ENTRY(IContextMenu) + COM_INTERFACE_ENTRY(IContextMenu2) + COM_INTERFACE_ENTRY(IContextMenu3) + COM_INTERFACE_ENTRY(IObjectWithSite) +END_COM_MAP() + +// IMenuExt +public: + STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY /*hkeyProgID*/); + STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici); + STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax); + STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT /*idCmdLast*/, UINT /*uFlags*/); + STDMETHOD(HandleMenuMsg)(UINT uMsg, WPARAM wParam, LPARAM lParam); + STDMETHOD(HandleMenuMsg2)(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); + +protected: + void DrawMenuItem(LPDRAWITEMSTRUCT lpdis); + void CreateShortcutsMenu(UINT uiIDBase, bool bOwnerDrawn); +}; + +#endif //__MENUEXT_H_ Index: src/chext/ShellExtControl.cpp =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/ShellExtControl.cpp (.../ShellExtControl.cpp) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/chext/ShellExtControl.cpp (.../ShellExtControl.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,125 +1,125 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "chext.h" -#include -#include "ShellExtControl.h" -#include "../common/version.h" - -CShellExtControl::CShellExtControl() : - m_pShellExtData(NULL), - m_hMemory(NULL), - m_hMutex(NULL) -{ - // create protection mutex - m_hMutex = ::CreateMutex(NULL, FALSE, _T("CHShellExtControlDataMutex")); - if(!m_hMutex) - return; - - DWORD dwRes = WaitForSingleObject(m_hMutex, 10000); - if(dwRes != WAIT_OBJECT_0) - return; - - // memory mapped file - m_hMemory = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(SHELLEXT_DATA), _T("CHShellExtControlData")); // name of map object - if(!m_hMemory) - { - ReleaseMutex(m_hMutex); - CloseHandle(m_hMutex); - return; - } - - DWORD dwLastError = GetLastError(); - m_pShellExtData = (SHELLEXT_DATA*)MapViewOfFile(m_hMemory, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); - if(!m_pShellExtData) - { - ReleaseMutex(m_hMutex); - CloseHandle(m_hMutex); - CloseHandle(m_hMemory); - m_hMemory = NULL; - return; - } - - if(dwLastError != ERROR_ALREADY_EXISTS) - { - m_pShellExtData->m_lFlags = 0; - m_pShellExtData->m_lID = GetTickCount(); - } - - ReleaseMutex(m_hMutex); -} - -CShellExtControl::~CShellExtControl() -{ - if(m_pShellExtData) - { - UnmapViewOfFile((LPVOID)m_pShellExtData); - - // Close the process's handle to the file-mapping object. - CloseHandle(m_hMemory); - } - - if(m_hMutex) - CloseHandle(m_hMutex); -} - -STDMETHODIMP CShellExtControl::GetVersion(LONG* plVersion, BSTR* pbstrVersion) -{ - if(!plVersion || !pbstrVersion || (*pbstrVersion)) - return E_INVALIDARG; - - (*plVersion) = PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4; - _bstr_t strVer(SHELLEXT_PRODUCT_FULL_VERSION); - pbstrVersion = strVer.GetAddress(); - - return S_OK; -} - -STDMETHODIMP CShellExtControl::SetFlags(LONG lFlags, LONG lMask) -{ - if(!m_hMutex || !m_pShellExtData) - return E_FAIL; - - DWORD dwRes = WaitForSingleObject(m_hMutex, 10000); - if(dwRes != WAIT_OBJECT_0) - return E_FAIL; - m_pShellExtData->m_lFlags = (m_pShellExtData->m_lFlags & ~lMask) | (lFlags & lMask); - - ReleaseMutex(m_hMutex); - - return S_OK; -} - -STDMETHODIMP CShellExtControl::GetFlags(LONG* plFlags) -{ - if(!m_hMutex || !m_pShellExtData) - return E_FAIL; - if(!plFlags) - return E_INVALIDARG; - - DWORD dwRes = WaitForSingleObject(m_hMutex, 10000); - if(dwRes != WAIT_OBJECT_0) - return E_FAIL; - - (*plFlags) = m_pShellExtData->m_lFlags; - - ReleaseMutex(m_hMutex); - - return S_OK; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "chext.h" +#include +#include "ShellExtControl.h" +#include "../common/version.h" + +CShellExtControl::CShellExtControl() : + m_pShellExtData(NULL), + m_hMemory(NULL), + m_hMutex(NULL) +{ + // create protection mutex + m_hMutex = ::CreateMutex(NULL, FALSE, _T("CHShellExtControlDataMutex")); + if(!m_hMutex) + return; + + DWORD dwRes = WaitForSingleObject(m_hMutex, 10000); + if(dwRes != WAIT_OBJECT_0) + return; + + // memory mapped file + m_hMemory = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(SHELLEXT_DATA), _T("CHShellExtControlData")); // name of map object + if(!m_hMemory) + { + ReleaseMutex(m_hMutex); + CloseHandle(m_hMutex); + return; + } + + DWORD dwLastError = GetLastError(); + m_pShellExtData = (SHELLEXT_DATA*)MapViewOfFile(m_hMemory, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); + if(!m_pShellExtData) + { + ReleaseMutex(m_hMutex); + CloseHandle(m_hMutex); + CloseHandle(m_hMemory); + m_hMemory = NULL; + return; + } + + if(dwLastError != ERROR_ALREADY_EXISTS) + { + m_pShellExtData->m_lFlags = 0; + m_pShellExtData->m_lID = GetTickCount(); + } + + ReleaseMutex(m_hMutex); +} + +CShellExtControl::~CShellExtControl() +{ + if(m_pShellExtData) + { + UnmapViewOfFile((LPVOID)m_pShellExtData); + + // Close the process's handle to the file-mapping object. + CloseHandle(m_hMemory); + } + + if(m_hMutex) + CloseHandle(m_hMutex); +} + +STDMETHODIMP CShellExtControl::GetVersion(LONG* plVersion, BSTR* pbstrVersion) +{ + if(!plVersion || !pbstrVersion || (*pbstrVersion)) + return E_INVALIDARG; + + (*plVersion) = PRODUCT_VERSION1 << 24 | PRODUCT_VERSION2 << 16 | PRODUCT_VERSION3 << 8 | PRODUCT_VERSION4; + _bstr_t strVer(SHELLEXT_PRODUCT_FULL_VERSION); + pbstrVersion = strVer.GetAddress(); + + return S_OK; +} + +STDMETHODIMP CShellExtControl::SetFlags(LONG lFlags, LONG lMask) +{ + if(!m_hMutex || !m_pShellExtData) + return E_FAIL; + + DWORD dwRes = WaitForSingleObject(m_hMutex, 10000); + if(dwRes != WAIT_OBJECT_0) + return E_FAIL; + m_pShellExtData->m_lFlags = (m_pShellExtData->m_lFlags & ~lMask) | (lFlags & lMask); + + ReleaseMutex(m_hMutex); + + return S_OK; +} + +STDMETHODIMP CShellExtControl::GetFlags(LONG* plFlags) +{ + if(!m_hMutex || !m_pShellExtData) + return E_FAIL; + if(!plFlags) + return E_INVALIDARG; + + DWORD dwRes = WaitForSingleObject(m_hMutex, 10000); + if(dwRes != WAIT_OBJECT_0) + return E_FAIL; + + (*plFlags) = m_pShellExtData->m_lFlags; + + ReleaseMutex(m_hMutex); + + return S_OK; +} Index: src/chext/ShellExtControl.h =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/ShellExtControl.h (.../ShellExtControl.h) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/chext/ShellExtControl.h (.../ShellExtControl.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,60 +1,60 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __SHELLEXTCONTROL_H_ -#define __SHELLEXTCONTROL_H_ - -#include "resource.h" // main symbols - -///////////////////////////////////////////////////////////////////////////// -// CDropMenuExt -class ATL_NO_VTABLE CShellExtControl : - public CComObjectRootEx, - public CComCoClass, - public IDispatchImpl -{ -public: - CShellExtControl(); - ~CShellExtControl(); - - STDMETHOD(GetVersion)(LONG* plVersion, BSTR* pbstrVersion); - STDMETHOD(SetFlags)(LONG lFlags, LONG lMask); - STDMETHOD(GetFlags)(LONG* plFlags); - -DECLARE_REGISTRY_RESOURCEID(IDR_SHELLEXTCONTROL) - -DECLARE_PROTECT_FINAL_CONSTRUCT() - -BEGIN_COM_MAP(CShellExtControl) - COM_INTERFACE_ENTRY(IUnknown) - COM_INTERFACE_ENTRY(IShellExtControl) -END_COM_MAP() - -protected: - HANDLE m_hMemory; - HANDLE m_hMutex; - struct SHELLEXT_DATA - { - long m_lID; - long m_lFlags; - } *m_pShellExtData; - - CComAutoCriticalSection m_lock; -}; - -#endif //__SHELLEXTCONTROL_H_ +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __SHELLEXTCONTROL_H_ +#define __SHELLEXTCONTROL_H_ + +#include "resource.h" // main symbols + +///////////////////////////////////////////////////////////////////////////// +// CDropMenuExt +class ATL_NO_VTABLE CShellExtControl : + public CComObjectRootEx, + public CComCoClass, + public IDispatchImpl +{ +public: + CShellExtControl(); + ~CShellExtControl(); + + STDMETHOD(GetVersion)(LONG* plVersion, BSTR* pbstrVersion); + STDMETHOD(SetFlags)(LONG lFlags, LONG lMask); + STDMETHOD(GetFlags)(LONG* plFlags); + +DECLARE_REGISTRY_RESOURCEID(IDR_SHELLEXTCONTROL) + +DECLARE_PROTECT_FINAL_CONSTRUCT() + +BEGIN_COM_MAP(CShellExtControl) + COM_INTERFACE_ENTRY(IUnknown) + COM_INTERFACE_ENTRY(IShellExtControl) +END_COM_MAP() + +protected: + HANDLE m_hMemory; + HANDLE m_hMutex; + struct SHELLEXT_DATA + { + long m_lID; + long m_lFlags; + } *m_pShellExtData; + + CComAutoCriticalSection m_lock; +}; + +#endif //__SHELLEXTCONTROL_H_ Index: src/chext/StdAfx.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/StdAfx.cpp (.../StdAfx.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/chext/StdAfx.cpp (.../StdAfx.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,26 +1,26 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" - -#ifdef _ATL_STATIC_REGISTRY -#include -//#include -#endif - -//#include +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" + +#ifdef _ATL_STATIC_REGISTRY +#include +//#include +#endif + +//#include Index: src/chext/StdAfx.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/StdAfx.h (.../StdAfx.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/chext/StdAfx.h (.../StdAfx.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,38 +1,38 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STDAFX_H__ -#define __STDAFX_H__ - -#define STRICT -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0400 -#endif -#define _ATL_APARTMENT_THREADED - - -#include - -#include "resource.h" -#include -#include -#include - -#include "../libicpf/gen_types.h" - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STDAFX_H__ +#define __STDAFX_H__ + +#define STRICT +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0400 +#endif +#define _ATL_APARTMENT_THREADED + + +#include + +#include "resource.h" +#include +#include +#include + +#include "../libicpf/gen_types.h" + +#endif Index: src/chext/StringHelpers.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/StringHelpers.cpp (.../StringHelpers.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/chext/StringHelpers.cpp (.../StringHelpers.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,38 +1,38 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "StringHelpers.h" -#include "stdio.h" - -LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize) -{ - if (dData < 0.0) - dData=0.0; - - if (dData < 1200.0) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), dData, g_pscsShared->szSizes[0]); - else if (dData < 1228800.0) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1024.0, g_pscsShared->szSizes[1]); - else if (dData < 1258291200.0) - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1048576.0, g_pscsShared->szSizes[2]); - else - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1073741824.0, g_pscsShared->szSizes[3]); - - return pszBuffer; -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "StringHelpers.h" +#include "stdio.h" + +LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize) +{ + if (dData < 0.0) + dData=0.0; + + if (dData < 1200.0) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), dData, g_pscsShared->szSizes[0]); + else if (dData < 1228800.0) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1024.0, g_pscsShared->szSizes[1]); + else if (dData < 1258291200.0) + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1048576.0, g_pscsShared->szSizes[2]); + else + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(dData)/1073741824.0, g_pscsShared->szSizes[3]); + + return pszBuffer; +} Index: src/chext/StringHelpers.h =================================================================== diff -u -rd6da900f71c2fb7f65e7443baf279c7f626d057d -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/StringHelpers.h (.../StringHelpers.h) (revision d6da900f71c2fb7f65e7443baf279c7f626d057d) +++ src/chext/StringHelpers.h (.../StringHelpers.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,55 +1,55 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __STRINGHELPERS_H__ -#define __STRINGHELPERS_H__ - -#include "..\common\ipcstructs.h" - -extern CSharedConfigStruct* g_pscsShared; - -LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize); - -template LPTSTR GetSizeString(T tData, LPTSTR pszBuffer, size_t stMaxBufferSize, bool bStrict = false) -{ - if (tData < 0) - tData=0; - - if (tData >= 1258291200 && (!bStrict || (tData % 1073741824) == 0)) - { - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(tData)/1073741824.0, g_pscsShared->szSizes[3]); - return pszBuffer; - } - else if (tData >= 1228800 && (!bStrict || (tData % 1048576) == 0)) - { - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(tData)/1048576.0, g_pscsShared->szSizes[2]); - return pszBuffer; - } - else if (tData >= 1200 && (!bStrict || (tData % 1024) == 0)) - { - _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(tData)/1024.0, g_pscsShared->szSizes[1]); - return pszBuffer; - } - else - { - _sntprintf(pszBuffer, stMaxBufferSize, _T("%d %s"), tData, g_pscsShared->szSizes[0]); - return pszBuffer; - } -} - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __STRINGHELPERS_H__ +#define __STRINGHELPERS_H__ + +#include "..\common\ipcstructs.h" + +extern CSharedConfigStruct* g_pscsShared; + +LPTSTR GetSizeString(double dData, LPTSTR pszBuffer, size_t stMaxBufferSize); + +template LPTSTR GetSizeString(T tData, LPTSTR pszBuffer, size_t stMaxBufferSize, bool bStrict = false) +{ + if (tData < 0) + tData=0; + + if (tData >= 1258291200 && (!bStrict || (tData % 1073741824) == 0)) + { + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(tData)/1073741824.0, g_pscsShared->szSizes[3]); + return pszBuffer; + } + else if (tData >= 1228800 && (!bStrict || (tData % 1048576) == 0)) + { + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(tData)/1048576.0, g_pscsShared->szSizes[2]); + return pszBuffer; + } + else if (tData >= 1200 && (!bStrict || (tData % 1024) == 0)) + { + _sntprintf(pszBuffer, stMaxBufferSize, _T("%.2f %s"), static_cast(tData)/1024.0, g_pscsShared->szSizes[1]); + return pszBuffer; + } + else + { + _sntprintf(pszBuffer, stMaxBufferSize, _T("%d %s"), tData, g_pscsShared->szSizes[0]); + return pszBuffer; + } +} + +#endif Index: src/chext/chext-utils.h =================================================================== diff -u -rbc695e56772e5a5eb4574a17905afafb4c62b6dd -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/chext-utils.h (.../chext-utils.h) (revision bc695e56772e5a5eb4574a17905afafb4c62b6dd) +++ src/chext/chext-utils.h (.../chext-utils.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,38 +1,38 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __CHEXT_UTILS_H__ -#define __CHEXT_UTILS_H__ - -inline HRESULT IsShellExtEnabled(IShellExtControl* piShellExtControl) -{ - if(!piShellExtControl) - return E_FAIL; - - LONG lFlags = eShellExt_None; - HRESULT hResult = piShellExtControl->GetFlags(&lFlags); - if(FAILED(hResult)) - return hResult; - - if(lFlags & eShellExt_Enabled) - return S_OK; - else - return S_FALSE; -} - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __CHEXT_UTILS_H__ +#define __CHEXT_UTILS_H__ + +inline HRESULT IsShellExtEnabled(IShellExtControl* piShellExtControl) +{ + if(!piShellExtControl) + return E_FAIL; + + LONG lFlags = eShellExt_None; + HRESULT hResult = piShellExtControl->GetFlags(&lFlags); + if(FAILED(hResult)) + return hResult; + + if(lFlags & eShellExt_Enabled) + return S_OK; + else + return S_FALSE; +} + +#endif Index: src/chext/chext.cpp =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/chext.cpp (.../chext.cpp) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/chext/chext.cpp (.../chext.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,93 +1,93 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -// Note: Proxy/Stub Information -// To build a separate proxy/stub DLL, -// run nmake -f CopyHandlerShellExtps.mk in the project directory. - -#include "stdafx.h" -#include "resource.h" -#include "chext.h" -#include "dllmain.h" -//#include - -///////////////////////////////////////////////////////////////////////////// -// Used to determine whether the DLL can be unloaded by OLE - -STDAPI DllCanUnloadNow(void) -{ - return _AtlModule.DllCanUnloadNow(); -} - -///////////////////////////////////////////////////////////////////////////// -// Returns a class factory to create an object of the requested type - -STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) -{ - return _AtlModule.DllGetClassObject(rclsid, riid, ppv); -} - -///////////////////////////////////////////////////////////////////////////// -// DllRegisterServer - Adds entries to the system registry - -STDAPI DllRegisterServer() -{ - // registers object, typelib and all interfaces in typelib - return _AtlModule.DllRegisterServer(); -} - -///////////////////////////////////////////////////////////////////////////// -// DllUnregisterServer - Removes entries from the system registry - -STDAPI DllUnregisterServer(void) -{ - return _AtlModule.DllUnregisterServer(); -} - -// DllInstall - Adds/Removes entries to the system registry per user -// per machine. -STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine) -{ - HRESULT hr = E_FAIL; - static const wchar_t szUserSwitch[] = _T("user"); - - if (pszCmdLine != NULL) - { - if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) - { - AtlSetPerUserRegistration(true); - } - } - - if (bInstall) - { - hr = DllRegisterServer(); - if (FAILED(hr)) - { - DllUnregisterServer(); - } - } - else - { - hr = DllUnregisterServer(); - } - - return hr; -} - - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +// Note: Proxy/Stub Information +// To build a separate proxy/stub DLL, +// run nmake -f CopyHandlerShellExtps.mk in the project directory. + +#include "stdafx.h" +#include "resource.h" +#include "chext.h" +#include "dllmain.h" +//#include + +///////////////////////////////////////////////////////////////////////////// +// Used to determine whether the DLL can be unloaded by OLE + +STDAPI DllCanUnloadNow(void) +{ + return _AtlModule.DllCanUnloadNow(); +} + +///////////////////////////////////////////////////////////////////////////// +// Returns a class factory to create an object of the requested type + +STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) +{ + return _AtlModule.DllGetClassObject(rclsid, riid, ppv); +} + +///////////////////////////////////////////////////////////////////////////// +// DllRegisterServer - Adds entries to the system registry + +STDAPI DllRegisterServer() +{ + // registers object, typelib and all interfaces in typelib + return _AtlModule.DllRegisterServer(); +} + +///////////////////////////////////////////////////////////////////////////// +// DllUnregisterServer - Removes entries from the system registry + +STDAPI DllUnregisterServer(void) +{ + return _AtlModule.DllUnregisterServer(); +} + +// DllInstall - Adds/Removes entries to the system registry per user +// per machine. +STDAPI DllInstall(BOOL bInstall, LPCWSTR pszCmdLine) +{ + HRESULT hr = E_FAIL; + static const wchar_t szUserSwitch[] = _T("user"); + + if (pszCmdLine != NULL) + { + if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) + { + AtlSetPerUserRegistration(true); + } + } + + if (bInstall) + { + hr = DllRegisterServer(); + if (FAILED(hr)) + { + DllUnregisterServer(); + } + } + else + { + hr = DllUnregisterServer(); + } + + return hr; +} + + Index: src/chext/clipboard.cpp =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/clipboard.cpp (.../clipboard.cpp) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/chext/clipboard.cpp (.../clipboard.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,52 +1,52 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "clipboard.h" - -void GetDataFromClipboard(HDROP hdrop, LPCTSTR pszDstPath, LPTSTR *pszBuffer, UINT* pSize) -{ - // get clipboard data - UINT uiBufferSize=(pszDstPath == NULL) ? 0 : _tcslen(pszDstPath)+1; - UINT uiFilesCount=DragQueryFile(hdrop, 0xffffffff, NULL, 0); - - // count size - for (UINT i=0;i -{ -public : - DECLARE_LIBID(LIBID_CHEXTLib) - DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHEXT, "{9D4C4C5F-EE90-4a6b-9245-244C369E4FAE}") -}; - -extern class CCHExtModule _AtlModule; + +class CCHExtModule : public CAtlDllModuleT +{ +public : + DECLARE_LIBID(LIBID_CHEXTLib) + DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CHEXT, "{9D4C4C5F-EE90-4a6b-9245-244C369E4FAE}") +}; + +extern class CCHExtModule _AtlModule; Index: src/chext/resource.h =================================================================== diff -u -rd0fdcc905035e648382256101a3d99f429af6d56 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/chext/resource.h (.../resource.h) (revision d0fdcc905035e648382256101a3d99f429af6d56) +++ src/chext/resource.h (.../resource.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,29 +1,29 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by chext.rc -// -#define IDS_COPYBYCH_STRING 1 -#define IDS_MOVEBYCH_STRING 2 -#define IDS_SPECIALCOPYMOVE_STRING 3 -#define IDS_COPYBYCHDESC_STRING 4 -#define IDS_MOVEBYCHDESC_STRING 5 -#define IDS_COPYMOVESPECIALDESC_STRING 6 -#define IDS_PASTEBYCH_STRING 7 -#define IDS_PASTEBYCHSPECIAL_STRING 8 -#define IDS_PASTEBYCHDESC_STRING 9 -#define IDS_PASTEBYCHSPECDESC_STRING 10 -#define IDR_MENUEXT 102 -#define IDR_DROPMENUEXT 103 -#define IDR_SHELLEXTCONTROL 104 -#define IDR_CHEXT 105 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 201 -#define _APS_NEXT_COMMAND_VALUE 32768 -#define _APS_NEXT_CONTROL_VALUE 201 -#define _APS_NEXT_SYMED_VALUE 106 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by chext.rc +// +#define IDS_COPYBYCH_STRING 1 +#define IDS_MOVEBYCH_STRING 2 +#define IDS_SPECIALCOPYMOVE_STRING 3 +#define IDS_COPYBYCHDESC_STRING 4 +#define IDS_MOVEBYCHDESC_STRING 5 +#define IDS_COPYMOVESPECIALDESC_STRING 6 +#define IDS_PASTEBYCH_STRING 7 +#define IDS_PASTEBYCHSPECIAL_STRING 8 +#define IDS_PASTEBYCHDESC_STRING 9 +#define IDS_PASTEBYCHSPECDESC_STRING 10 +#define IDR_MENUEXT 102 +#define IDR_DROPMENUEXT 103 +#define IDR_SHELLEXTCONTROL 104 +#define IDR_CHEXT 105 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 201 +#define _APS_NEXT_COMMAND_VALUE 32768 +#define _APS_NEXT_CONTROL_VALUE 201 +#define _APS_NEXT_SYMED_VALUE 106 +#endif +#endif Index: src/common/FileSupport.cpp =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/common/FileSupport.cpp (.../FileSupport.cpp) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/common/FileSupport.cpp (.../FileSupport.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,107 +1,107 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "wtypes.h" -#include "FileSupport.h" -//#include "tchar.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - -#pragma warning (disable: 4711) - -__int64 SetFilePointer64(HANDLE hFile, __int64 llDistance, DWORD dwMoveMethod) -{ - LARGE_INTEGER li; - - li.QuadPart = llDistance; - - li.LowPart = SetFilePointer(hFile, li.LowPart, &li.HighPart, dwMoveMethod); - - if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) - li.QuadPart = -1; - - return li.QuadPart; -} - -__int64 GetFilePointer64(HANDLE hFile) -{ - return SetFilePointer64(hFile, 0, FILE_CURRENT); -} - -__int64 GetFileSize64(HANDLE hFile) -{ - ULARGE_INTEGER li; - - li.LowPart = GetFileSize(hFile, &li.HighPart); - - // If we failed ... - if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) - li.QuadPart=static_cast(-1); - - return li.QuadPart; -} - -bool SetFileSize64(LPCTSTR lpszFilename, __int64 llSize) -{ - HANDLE hFile=CreateFile(lpszFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return false; - - if (SetFilePointer64(hFile, llSize, FILE_BEGIN) == -1) - { - CloseHandle(hFile); - return false; - } - - if (!SetEndOfFile(hFile)) - { - CloseHandle(hFile); - return false; - } - - if (!CloseHandle(hFile)) - return false; - - return true; -} - -// disk support routines - -bool GetDynamicFreeSpace(LPCTSTR lpszPath, ull_t* pFree, ull_t* pTotal) -{ - ULARGE_INTEGER ui64Available, ui64Total; - if(!GetDiskFreeSpaceEx(lpszPath, &ui64Available, &ui64Total, NULL)) - { - if(pFree) - *pFree=-1; - if(pTotal) - *pTotal=-1; - return false; - } - else - { - if(pFree) - *pFree=ui64Available.QuadPart; - if(pTotal) - *pTotal=ui64Total.QuadPart; - return true; - } -} +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "wtypes.h" +#include "FileSupport.h" +//#include "tchar.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + +#pragma warning (disable: 4711) + +__int64 SetFilePointer64(HANDLE hFile, __int64 llDistance, DWORD dwMoveMethod) +{ + LARGE_INTEGER li; + + li.QuadPart = llDistance; + + li.LowPart = SetFilePointer(hFile, li.LowPart, &li.HighPart, dwMoveMethod); + + if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) + li.QuadPart = -1; + + return li.QuadPart; +} + +__int64 GetFilePointer64(HANDLE hFile) +{ + return SetFilePointer64(hFile, 0, FILE_CURRENT); +} + +__int64 GetFileSize64(HANDLE hFile) +{ + ULARGE_INTEGER li; + + li.LowPart = GetFileSize(hFile, &li.HighPart); + + // If we failed ... + if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) + li.QuadPart=static_cast(-1); + + return li.QuadPart; +} + +bool SetFileSize64(LPCTSTR lpszFilename, __int64 llSize) +{ + HANDLE hFile=CreateFile(lpszFilename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) + return false; + + if (SetFilePointer64(hFile, llSize, FILE_BEGIN) == -1) + { + CloseHandle(hFile); + return false; + } + + if (!SetEndOfFile(hFile)) + { + CloseHandle(hFile); + return false; + } + + if (!CloseHandle(hFile)) + return false; + + return true; +} + +// disk support routines + +bool GetDynamicFreeSpace(LPCTSTR lpszPath, ull_t* pFree, ull_t* pTotal) +{ + ULARGE_INTEGER ui64Available, ui64Total; + if(!GetDiskFreeSpaceEx(lpszPath, &ui64Available, &ui64Total, NULL)) + { + if(pFree) + *pFree=-1; + if(pTotal) + *pTotal=-1; + return false; + } + else + { + if(pFree) + *pFree=ui64Available.QuadPart; + if(pTotal) + *pTotal=ui64Total.QuadPart; + return true; + } +} Index: src/common/FileSupport.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/common/FileSupport.h (.../FileSupport.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/common/FileSupport.h (.../FileSupport.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,31 +1,31 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __FILESUPPORT_ROUTINES_H__ -#define __FILESUPPORT_ROUTINES_H__ - -// file support routines -__int64 SetFilePointer64(HANDLE hFile, __int64 llDistance, DWORD dwMoveMethod); -__int64 GetFilePointer64(HANDLE hFile); -__int64 GetFileSize64(HANDLE hFile); -bool SetFileSize64(LPCTSTR lpszFilename, __int64 llSize); - -// disk support routines -bool GetDynamicFreeSpace(LPCTSTR lpszPath, ull_t* pFree, ull_t* pTotal); - +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __FILESUPPORT_ROUTINES_H__ +#define __FILESUPPORT_ROUTINES_H__ + +// file support routines +__int64 SetFilePointer64(HANDLE hFile, __int64 llDistance, DWORD dwMoveMethod); +__int64 GetFilePointer64(HANDLE hFile); +__int64 GetFileSize64(HANDLE hFile); +bool SetFileSize64(LPCTSTR lpszFilename, __int64 llSize); + +// disk support routines +bool GetDynamicFreeSpace(LPCTSTR lpszPath, ull_t* pFree, ull_t* pTotal); + #endif \ No newline at end of file Index: src/common/ipcstructs.h =================================================================== diff -u -rd2b121c78f510b5384b8ef0ca80afbfd7f77fef7 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/common/ipcstructs.h (.../ipcstructs.h) (revision d2b121c78f510b5384b8ef0ca80afbfd7f77fef7) +++ src/common/ipcstructs.h (.../ipcstructs.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,84 +1,84 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __SHAREDDATA_H__ -#define __SHAREDDATA_H__ - -// drag&drop flags -#define OPERATION_MASK 0x00ffffff -#define DD_COPY_FLAG 0x00000001 -#define DD_MOVE_FLAG 0x00000002 -#define DD_COPYMOVESPECIAL_FLAG 0x00000004 - -#define EC_PASTE_FLAG 0x00000010 -#define EC_PASTESPECIAL_FLAG 0x00000020 -#define EC_COPYTO_FLAG 0x00000040 -#define EC_MOVETO_FLAG 0x00000080 -#define EC_COPYMOVETOSPECIAL_FLAG 0x00000100 - -// messages used -#define WM_GETCONFIG WM_USER+20 - -// config type to get from program -#define GC_DRAGDROP 0x00 -#define GC_EXPLORER 0x01 - -// command properties (used in menu displaying) -#pragma pack(push, 1) -struct _COMMAND -{ - UINT uiCommandID; // command ID - would be send be - TCHAR szCommand[128]; // command name - TCHAR szDesc[128]; // and it's description -}; -#pragma pack(pop) - -#pragma pack(push, 1) -struct _SHORTCUT -{ - TCHAR szName[128]; - TCHAR szPath[_MAX_PATH]; -}; -#pragma pack(pop) - -// shared memory size in bytes -#define SHARED_BUFFERSIZE 65536 - -// structure used for passing data from program to DLL -// the rest is a dynamic texts -class CSharedConfigStruct -{ -public: - _SHORTCUT* GetShortcutsPtr() const { return (_SHORTCUT*)(byData + iCommandCount * sizeof(_COMMAND)); } - _COMMAND* GetCommandsPtr() const { return (_COMMAND*)byData; } - -public: - UINT uiFlags; // what items and how to display in drag&drop ctx menu & explorer.ctx.menu - - bool bShowFreeSpace; // showthe free space by the shortcuts ? - TCHAR szSizes[6][64]; // names of the kB, GB, ... - bool bShowShortcutIcons; // show shell icons with shortcuts ? - bool bOverrideDefault; // only for d&d - want to change menu default item to the one from ch ? - UINT uiDefaultAction; // default action for drag&drop when using above option - int iCommandCount; // count of commands stored at the beginning of a buffer - int iShortcutsCount; // count of shortcuts to display in submenus - - BYTE byData[SHARED_BUFFERSIZE]; // buffer for texts and other stuff -}; - -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __SHAREDDATA_H__ +#define __SHAREDDATA_H__ + +// drag&drop flags +#define OPERATION_MASK 0x00ffffff +#define DD_COPY_FLAG 0x00000001 +#define DD_MOVE_FLAG 0x00000002 +#define DD_COPYMOVESPECIAL_FLAG 0x00000004 + +#define EC_PASTE_FLAG 0x00000010 +#define EC_PASTESPECIAL_FLAG 0x00000020 +#define EC_COPYTO_FLAG 0x00000040 +#define EC_MOVETO_FLAG 0x00000080 +#define EC_COPYMOVETOSPECIAL_FLAG 0x00000100 + +// messages used +#define WM_GETCONFIG WM_USER+20 + +// config type to get from program +#define GC_DRAGDROP 0x00 +#define GC_EXPLORER 0x01 + +// command properties (used in menu displaying) +#pragma pack(push, 1) +struct _COMMAND +{ + UINT uiCommandID; // command ID - would be send be + TCHAR szCommand[128]; // command name + TCHAR szDesc[128]; // and it's description +}; +#pragma pack(pop) + +#pragma pack(push, 1) +struct _SHORTCUT +{ + TCHAR szName[128]; + TCHAR szPath[_MAX_PATH]; +}; +#pragma pack(pop) + +// shared memory size in bytes +#define SHARED_BUFFERSIZE 65536 + +// structure used for passing data from program to DLL +// the rest is a dynamic texts +class CSharedConfigStruct +{ +public: + _SHORTCUT* GetShortcutsPtr() const { return (_SHORTCUT*)(byData + iCommandCount * sizeof(_COMMAND)); } + _COMMAND* GetCommandsPtr() const { return (_COMMAND*)byData; } + +public: + UINT uiFlags; // what items and how to display in drag&drop ctx menu & explorer.ctx.menu + + bool bShowFreeSpace; // showthe free space by the shortcuts ? + TCHAR szSizes[6][64]; // names of the kB, GB, ... + bool bShowShortcutIcons; // show shell icons with shortcuts ? + bool bOverrideDefault; // only for d&d - want to change menu default item to the one from ch ? + UINT uiDefaultAction; // default action for drag&drop when using above option + int iCommandCount; // count of commands stored at the beginning of a buffer + int iShortcutsCount; // count of shortcuts to display in submenus + + BYTE byData[SHARED_BUFFERSIZE]; // buffer for texts and other stuff +}; + +#endif Index: src/common/version.h =================================================================== diff -u -rdde5badabf3ac0e611fdf29e5d436aa0ec505e02 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/common/version.h (.../version.h) (revision dde5badabf3ac0e611fdf29e5d436aa0ec505e02) +++ src/common/version.h (.../version.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,32 +1,32 @@ -#ifndef __VERSION_H__ -#define __VERSION_H__ - -// note that this file is also being used by setup compiler; -// in this case the SETUP_COMPILER is defined with value 1 -// Product name -#define PRODUCT_NAME "Copy Handler" -// shell extension -#define SHELLEXT_PRODUCT_NAME "Copy Handler Shell Extension" - -// Version of program -#define PRODUCT_VERSION1 1 -#define PRODUCT_VERSION2 31 -#define PRODUCT_VERSION3 172 -#define PRODUCT_VERSION4 0 - -#define PRODUCT_VERSION "1.31beta-svn172" - -#if SETUP_COMPILER != 1 - #define SHELLEXT_PRODUCT_FULL_VERSION SHELLEXT_PRODUCT_NAME " " PRODUCT_VERSION - #define SHELLEXT_PRODUCT_FULL_VERSION_T _T(SHELLEXT_PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) - - #define PRODUCT_FULL_VERSION PRODUCT_NAME " " PRODUCT_VERSION - #define PRODUCT_FULL_VERSION_T _T(PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) -#endif - -// copyright information -#define COPYRIGHT_INFO "Copyright (C) 2001-2009 J�zef Starosczyk" -#define PRODUCT_SITE "http://www.copyhandler.com" -#define CONTACT_INFO "ixen@copyhandler.com" - -#endif +#ifndef __VERSION_H__ +#define __VERSION_H__ + +// note that this file is also being used by setup compiler; +// in this case the SETUP_COMPILER is defined with value 1 +// Product name +#define PRODUCT_NAME "Copy Handler" +// shell extension +#define SHELLEXT_PRODUCT_NAME "Copy Handler Shell Extension" + +// Version of program +#define PRODUCT_VERSION1 1 +#define PRODUCT_VERSION2 31 +#define PRODUCT_VERSION3 172 +#define PRODUCT_VERSION4 0 + +#define PRODUCT_VERSION "1.31beta-svn172" + +#if SETUP_COMPILER != 1 + #define SHELLEXT_PRODUCT_FULL_VERSION SHELLEXT_PRODUCT_NAME " " PRODUCT_VERSION + #define SHELLEXT_PRODUCT_FULL_VERSION_T _T(SHELLEXT_PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) + + #define PRODUCT_FULL_VERSION PRODUCT_NAME " " PRODUCT_VERSION + #define PRODUCT_FULL_VERSION_T _T(PRODUCT_NAME) _T(" ") _T(PRODUCT_VERSION) +#endif + +// copyright information +#define COPYRIGHT_INFO "Copyright (C) 2001-2009 J�zef Starosczyk" +#define PRODUCT_SITE "http://www.copyhandler.com" +#define CONTACT_INFO "ixen@copyhandler.com" + +#endif Index: src/libchcore/EngineCfg.cpp =================================================================== diff -u -r6bc9b521ae26321f21d29a1116d052b1b8746498 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/EngineCfg.cpp (.../EngineCfg.cpp) (revision 6bc9b521ae26321f21d29a1116d052b1b8746498) +++ src/libchcore/EngineCfg.cpp (.../EngineCfg.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,43 +1,43 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#include "stdafx.h" -#include "../libicpf/cfg.h" -#include "EngineCfg.h" -#include "../libicpf/exception.h" - -BEGIN_CHCORE_NAMESPACE - -engine_config::engine_config(icpf::config::config_base_types eType) : - icpf::config(eType) -{ -} - -engine_config::~engine_config() -{ -} - -void engine_config::set_base_path(const tchar_t* pszPath) -{ - if(!pszPath) - THROW(_T("Invalid argument"), 0, 0, 0); - m_strBasePath = pszPath; - m_strTasksPath = m_strBasePath + _T("\\tasks\\"); -} - -END_CHCORE_NAMESPACE +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#include "stdafx.h" +#include "../libicpf/cfg.h" +#include "EngineCfg.h" +#include "../libicpf/exception.h" + +BEGIN_CHCORE_NAMESPACE + +engine_config::engine_config(icpf::config::config_base_types eType) : + icpf::config(eType) +{ +} + +engine_config::~engine_config() +{ +} + +void engine_config::set_base_path(const tchar_t* pszPath) +{ + if(!pszPath) + THROW(_T("Invalid argument"), 0, 0, 0); + m_strBasePath = pszPath; + m_strTasksPath = m_strBasePath + _T("\\tasks\\"); +} + +END_CHCORE_NAMESPACE Index: src/libchcore/EngineCfg.h =================================================================== diff -u -r6bc9b521ae26321f21d29a1116d052b1b8746498 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/EngineCfg.h (.../EngineCfg.h) (revision 6bc9b521ae26321f21d29a1116d052b1b8746498) +++ src/libchcore/EngineCfg.h (.../EngineCfg.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,46 +1,46 @@ -/*************************************************************************** -* Copyright (C) 2001-2008 by J�zef Starosczyk * -* ixen@copyhandler.com * -* * -* This program is free software; you can redistribute it and/or modify * -* it under the terms of the GNU Library General Public License * -* (version 2) as published by the Free Software Foundation; * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU Library General Public * -* License along with this program; if not, write to the * -* Free Software Foundation, Inc., * -* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * -***************************************************************************/ -#ifndef __ENGINE_CFG_H__ -#define __ENGINE_CFG_H__ - -#include "libchcore.h" - -BEGIN_CHCORE_NAMESPACE - -// contains everything that could be configured inside the engine. -// supports both the informations contained in the ini file and -// ones related to current instance of CH core -class LIBCHCORE_API engine_config : public icpf::config -{ -public: - engine_config(icpf::config::config_base_types eType); - virtual ~engine_config(); - - // paths handling - void set_base_path(const tchar_t* pszPath); - const tchar_t* get_base_path() { return m_strBasePath.c_str(); } - const tchar_t* get_tasks_path() { return m_strTasksPath.c_str(); } - -private: - tstring_t m_strBasePath; - tstring_t m_strTasksPath; -}; - -END_CHCORE_NAMESPACE -#endif +/*************************************************************************** +* Copyright (C) 2001-2008 by J�zef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ +#ifndef __ENGINE_CFG_H__ +#define __ENGINE_CFG_H__ + +#include "libchcore.h" + +BEGIN_CHCORE_NAMESPACE + +// contains everything that could be configured inside the engine. +// supports both the informations contained in the ini file and +// ones related to current instance of CH core +class LIBCHCORE_API engine_config : public icpf::config +{ +public: + engine_config(icpf::config::config_base_types eType); + virtual ~engine_config(); + + // paths handling + void set_base_path(const tchar_t* pszPath); + const tchar_t* get_base_path() { return m_strBasePath.c_str(); } + const tchar_t* get_tasks_path() { return m_strTasksPath.c_str(); } + +private: + tstring_t m_strBasePath; + tstring_t m_strTasksPath; +}; + +END_CHCORE_NAMESPACE +#endif Index: src/libchcore/FeedbackHandlerBase.h =================================================================== diff -u -re912e0a6b456c2eed24bec7303a908d3ff0aa59a -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/FeedbackHandlerBase.h (.../FeedbackHandlerBase.h) (revision e912e0a6b456c2eed24bec7303a908d3ff0aa59a) +++ src/libchcore/FeedbackHandlerBase.h (.../FeedbackHandlerBase.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,41 +1,41 @@ -/*************************************************************************** - * Copyright (C) 2001-2008 by J�zef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef __FEEDBACKHANDLERBASE_H__ -#define __FEEDBACKHANDLERBASE_H__ - -#include "libchcore.h" -#include "../libicpf/interface.h" - -BEGIN_CHCORE_NAMESPACE - -class IFeedbackHandler : public icpf::IInterface -{ -public: - virtual ull_t RequestFeedback(ull_t ullFeedbackID, ptr_t pFeedbackParam) = 0; -}; - -class IFeedbackHandlerFactory : public icpf::IInterface -{ -public: - virtual IFeedbackHandler* Create() = 0; -}; - -END_CHCORE_NAMESPACE - -#endif +/*************************************************************************** + * Copyright (C) 2001-2008 by J�zef Starosczyk * + * ixen@copyhandler.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License * + * (version 2) as published by the Free Software Foundation; * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef __FEEDBACKHANDLERBASE_H__ +#define __FEEDBACKHANDLERBASE_H__ + +#include "libchcore.h" +#include "../libicpf/interface.h" + +BEGIN_CHCORE_NAMESPACE + +class IFeedbackHandler : public icpf::IInterface +{ +public: + virtual ull_t RequestFeedback(ull_t ullFeedbackID, ptr_t pFeedbackParam) = 0; +}; + +class IFeedbackHandlerFactory : public icpf::IInterface +{ +public: + virtual IFeedbackHandler* Create() = 0; +}; + +END_CHCORE_NAMESPACE + +#endif Index: src/libchcore/dllmain.cpp =================================================================== diff -u -r2eabdea6d63640f34fb1f8bcf928336cc1a660af -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/dllmain.cpp (.../dllmain.cpp) (revision 2eabdea6d63640f34fb1f8bcf928336cc1a660af) +++ src/libchcore/dllmain.cpp (.../dllmain.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,16 +1,16 @@ -// dllmain.cpp : Defines the entry point for the DLL application. -#include "stdafx.h" - -BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ulReasonForCall, LPVOID /*lpReserved*/) -{ - switch (ulReasonForCall) - { - case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: - case DLL_THREAD_DETACH: - case DLL_PROCESS_DETACH: - break; - } - return TRUE; -} - +// dllmain.cpp : Defines the entry point for the DLL application. +#include "stdafx.h" + +BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ulReasonForCall, LPVOID /*lpReserved*/) +{ + switch (ulReasonForCall) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + Index: src/libchcore/libchcore.cpp =================================================================== diff -u -r2eabdea6d63640f34fb1f8bcf928336cc1a660af -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/libchcore.cpp (.../libchcore.cpp) (revision 2eabdea6d63640f34fb1f8bcf928336cc1a660af) +++ src/libchcore/libchcore.cpp (.../libchcore.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,5 +1,5 @@ -// libchcore.cpp : Defines the exported functions for the DLL application. -// - -#include "stdafx.h" -#include "libchcore.h" +// libchcore.cpp : Defines the exported functions for the DLL application. +// + +#include "stdafx.h" +#include "libchcore.h" Index: src/libchcore/libchcore.h =================================================================== diff -u -r6bc9b521ae26321f21d29a1116d052b1b8746498 -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/libchcore.h (.../libchcore.h) (revision 6bc9b521ae26321f21d29a1116d052b1b8746498) +++ src/libchcore/libchcore.h (.../libchcore.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,15 +1,15 @@ -// The following ifdef block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the LIBCHCORE_EXPORTS -// symbol defined on the command line. this symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see -// LIBCHCORE_API functions as being imported from a DLL, whereas this DLL sees symbols -// defined with this macro as being exported. +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the LIBCHCORE_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// LIBCHCORE_API functions as being imported from a DLL, whereas this DLL sees symbols +// defined with this macro as being exported. #if defined(_WIN32) || defined(_WIN64) - #ifdef LIBCHCORE_EXPORTS - #define LIBCHCORE_API __declspec(dllexport) - #else - #define LIBCHCORE_API __declspec(dllimport) - #endif + #ifdef LIBCHCORE_EXPORTS + #define LIBCHCORE_API __declspec(dllexport) + #else + #define LIBCHCORE_API __declspec(dllimport) + #endif #else /** \brief Import/export macros * @@ -19,7 +19,7 @@ */ #define LIBCHCORE_API #endif - + /// Begins ch namespace #define BEGIN_CHCORE_NAMESPACE namespace chcore { /// Ends ch namespace Index: src/libchcore/stdafx.cpp =================================================================== diff -u -r2eabdea6d63640f34fb1f8bcf928336cc1a660af -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/stdafx.cpp (.../stdafx.cpp) (revision 2eabdea6d63640f34fb1f8bcf928336cc1a660af) +++ src/libchcore/stdafx.cpp (.../stdafx.cpp) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,8 +1,8 @@ -// stdafx.cpp : source file that includes just the standard includes -// libchcore.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file +// stdafx.cpp : source file that includes just the standard includes +// libchcore.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file Index: src/libchcore/stdafx.h =================================================================== diff -u -r2eabdea6d63640f34fb1f8bcf928336cc1a660af -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/stdafx.h (.../stdafx.h) (revision 2eabdea6d63640f34fb1f8bcf928336cc1a660af) +++ src/libchcore/stdafx.h (.../stdafx.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,16 +1,16 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - -#pragma once - -#include "targetver.h" - -#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers -// Windows Header Files: -#include - - - -// TODO: reference additional headers your program requires here +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include + + + +// TODO: reference additional headers your program requires here Index: src/libchcore/targetver.h =================================================================== diff -u -r2eabdea6d63640f34fb1f8bcf928336cc1a660af -rd5c3edd0d167db9b5d47d04248820fda49499a5e --- src/libchcore/targetver.h (.../targetver.h) (revision 2eabdea6d63640f34fb1f8bcf928336cc1a660af) +++ src/libchcore/targetver.h (.../targetver.h) (revision d5c3edd0d167db9b5d47d04248820fda49499a5e) @@ -1,24 +1,24 @@ -#pragma once - -// The following macros define the minimum required platform. The minimum required platform -// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run -// your application. The macros work by enabling all features available on platform versions up to and -// including the version specified. - -// Modify the following defines if you have to target a platform prior to the ones specified below. -// Refer to MSDN for the latest info on corresponding values for different platforms. -#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. -#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. -#endif - -#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. -#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. -#endif - -#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. -#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. -#endif - -#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. -#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. -#endif +#pragma once + +// The following macros define the minimum required platform. The minimum required platform +// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run +// your application. The macros work by enabling all features available on platform versions up to and +// including the version specified. + +// Modify the following defines if you have to target a platform prior to the ones specified below. +// Refer to MSDN for the latest info on corresponding values for different platforms. +#ifndef WINVER // Specifies that the minimum required platform is Windows Vista. +#define WINVER 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINNT // Specifies that the minimum required platform is Windows Vista. +#define _WIN32_WINNT 0x0600 // Change this to the appropriate value to target other versions of Windows. +#endif + +#ifndef _WIN32_WINDOWS // Specifies that the minimum required platform is Windows 98. +#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later. +#endif + +#ifndef _WIN32_IE // Specifies that the minimum required platform is Internet Explorer 7.0. +#define _WIN32_IE 0x0700 // Change this to the appropriate value to target other versions of IE. +#endif