Author: akhaldi Date: Sun Feb 2 23:40:01 2014 New Revision: 61933
URL: http://svn.reactos.org/svn/reactos?rev=61933&view=rev Log: [SHELL32] * Multithread the calculation of a folder's size when the properties box is opened to increase the responsiveness of the shell. * Brought to you by Huw Campbell. CORE-7829 #resolve #comment Committed in r61933. Thanks !
Modified: trunk/reactos/dll/win32/shell32/filedefext.cpp trunk/reactos/dll/win32/shell32/filedefext.h
Modified: trunk/reactos/dll/win32/shell32/filedefext.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/filedefex... ============================================================================== --- trunk/reactos/dll/win32/shell32/filedefext.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/filedefext.cpp [iso-8859-1] Sun Feb 2 23:40:01 2014 @@ -531,10 +531,18 @@ if (m_bDir) { /* For directories files have to be counted */ - StringCchCopyW(wszBuf, _countof(wszBuf), m_wszPath); - CountFolderAndFiles(wszBuf, _countof(wszBuf)); - - /* Update size filed */ + + _CountFolderAndFilesData *data = reinterpret_cast<_CountFolderAndFilesData*> (HeapAlloc(GetProcessHeap(), 0, sizeof(_CountFolderAndFilesData))); + data->This = this; + data->pwszBuf = reinterpret_cast<LPWSTR> (HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * MAX_PATH)); + data->cchBufMax = MAX_PATH; + data->hwndDlg = hwndDlg; + this->AddRef(); + StringCchCopyW(data->pwszBuf, MAX_PATH, m_wszPath); + + SHCreateThread(reinterpret_cast<LPTHREAD_START_ROUTINE> (CFileDefExt::_CountFolderAndFilesThreadProc), reinterpret_cast<LPVOID> (data), NULL, NULL); + + /* Update size field */ if (SH_FormatFileSizeWithBytes(&m_DirSize, wszBuf, _countof(wszBuf))) SetDlgItemTextW(hwndDlg, 14011, wszBuf);
@@ -635,7 +643,7 @@ } else if (LOWORD(wParam) == 14021 || LOWORD(wParam) == 14022 || LOWORD(wParam) == 14023) /* checkboxes */ PropSheet_Changed(GetParent(hwndDlg), hwndDlg); - else if (LOWORD(wParam) == 14001) /* Name */ + else if (LOWORD(wParam) == 14001) /* Name */ { if (HIWORD(wParam) == EN_CHANGE) PropSheet_Changed(GetParent(hwndDlg), hwndDlg); @@ -968,8 +976,23 @@ return E_NOTIMPL; }
+DWORD +CFileDefExt::_CountFolderAndFilesThreadProc(LPVOID lpParameter) +{ + _CountFolderAndFilesData *data = reinterpret_cast<_CountFolderAndFilesData*>(lpParameter); + DWORD ticks = 0; + data->This->CountFolderAndFiles(data->hwndDlg, data->pwszBuf, data->cchBufMax, &ticks); + + //Release the CFileDefExt and data object holds in the copying thread. + data->This->Release(); + HeapFree(GetProcessHeap(), 0, data->pwszBuf); + HeapFree(GetProcessHeap(), 0, data); + + return 0; +} + BOOL -CFileDefExt::CountFolderAndFiles(LPWSTR pwszBuf, UINT cchBufMax) +CFileDefExt::CountFolderAndFiles(HWND hwndDlg, LPWSTR pwszBuf, UINT cchBufMax, DWORD *ticks) { /* Find filename position */ UINT cchBuf = wcslen(pwszBuf); @@ -991,6 +1014,12 @@ return FALSE; }
+ BOOL root = FALSE; + if (*ticks == 0) { + *ticks = GetTickCount(); + root = TRUE; + } + do { if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) @@ -1002,7 +1031,7 @@ ++m_cFolders;
StringCchCopyW(pwszFilename, cchFilenameMax, wfd.cFileName); - CountFolderAndFiles(pwszBuf, cchBufMax); + CountFolderAndFiles(hwndDlg, pwszBuf, cchBufMax, ticks); } else { @@ -1013,7 +1042,41 @@ FileSize.u.HighPart = wfd.nFileSizeHigh; m_DirSize.QuadPart += FileSize.QuadPart; } + if (GetTickCount() - *ticks > (DWORD) 300) + { + /* FIXME Using IsWindow is generally ill advised */ + if (IsWindow(hwndDlg)) + { + WCHAR wszBuf[MAX_PATH]; + + if (SH_FormatFileSizeWithBytes(&m_DirSize, wszBuf, _countof(wszBuf))) + SetDlgItemTextW(hwndDlg, 14011, wszBuf); + + /* Display files and folders count */ + WCHAR wszFormat[256]; + LoadStringW(shell32_hInstance, IDS_FILE_FOLDER, wszFormat, _countof(wszFormat)); + StringCchPrintfW(wszBuf, _countof(wszBuf), wszFormat, m_cFiles, m_cFolders); + SetDlgItemTextW(hwndDlg, 14027, wszBuf); + *ticks = GetTickCount(); + } + else + break; + } } while(FindNextFileW(hFind, &wfd)); + + if (root && IsWindow(hwndDlg)) + { + WCHAR wszBuf[MAX_PATH]; + + if (SH_FormatFileSizeWithBytes(&m_DirSize, wszBuf, _countof(wszBuf))) + SetDlgItemTextW(hwndDlg, 14011, wszBuf); + + /* Display files and folders count */ + WCHAR wszFormat[256]; + LoadStringW(shell32_hInstance, IDS_FILE_FOLDER, wszFormat, _countof(wszFormat)); + StringCchPrintfW(wszBuf, _countof(wszBuf), wszFormat, m_cFiles, m_cFolders); + SetDlgItemTextW(hwndDlg, 14027, wszBuf); + }
FindClose(hFind); return TRUE;
Modified: trunk/reactos/dll/win32/shell32/filedefext.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/filedefex... ============================================================================== --- trunk/reactos/dll/win32/shell32/filedefext.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/filedefext.h [iso-8859-1] Sun Feb 2 23:40:01 2014 @@ -73,7 +73,7 @@ BOOL InitVersionPage(HWND hwndDlg); static INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK VersionPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - BOOL CountFolderAndFiles(LPWSTR pwszBuf, UINT cchBufMax); + BOOL CountFolderAndFiles(HWND hwndDlg, LPWSTR pwszBuf, UINT cchBufMax, LPDWORD ticks);
WCHAR m_wszPath[MAX_PATH]; CFileVersionInfo m_VerInfo; @@ -82,6 +82,8 @@ DWORD m_cFiles; DWORD m_cFolders; ULARGE_INTEGER m_DirSize; + + static DWORD _CountFolderAndFilesThreadProc(LPVOID lpParameter);
public: CFileDefExt(); @@ -116,4 +118,11 @@ END_COM_MAP() };
-#endif /* _FILE_DEF_EXT_H_ */ +struct _CountFolderAndFilesData { + CFileDefExt *This; + HWND hwndDlg; + LPWSTR pwszBuf; + UINT cchBufMax; +}; + +#endif /* _FILE_DEF_EXT_H_ */