From 2158a119c829dd64b0f377db98e7546e61b4e020 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 3 Nov 2011 01:49:33 +0000 Subject: [PATCH] [OPTIMIZE] Compact recursiveAddFilesFrom function. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@836 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../WinControls/ProjectPanel/ProjectPanel.cpp | 41 +++---------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index 550bf6dea..4ccf0996a 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -1022,9 +1022,10 @@ void ProjectPanel::recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTre HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData); - if (hFile != INVALID_HANDLE_VALUE) - { - + do { + if (hFile == INVALID_HANDLE_VALUE) + break; + if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) @@ -1054,39 +1055,7 @@ void ProjectPanel::recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTre TCHAR *strValueLabel = ::PathFindFileName(pathFile.c_str()); _treeView.addItem(strValueLabel, hTreeItem, INDEX_LEAF, pathFile.c_str()); } - } - while (::FindNextFile(hFile, &foundData)) - { - if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) - { - // do nothing - } - else if (isRecursive) - { - if ((lstrcmp(foundData.cFileName, TEXT("."))) && (lstrcmp(foundData.cFileName, TEXT("..")))) - { - generic_string pathDir(folderPath); - if (folderPath[lstrlen(folderPath)-1] != '\\') - pathDir += TEXT("\\"); - pathDir += foundData.cFileName; - pathDir += TEXT("\\"); - HTREEITEM addedItem = addFolder(hTreeItem, foundData.cFileName); - recursiveAddFilesFrom(pathDir.c_str(), addedItem); - } - } - } - else - { - generic_string pathFile(folderPath); - if (folderPath[lstrlen(folderPath)-1] != '\\') - pathFile += TEXT("\\"); - pathFile += foundData.cFileName; - TCHAR *strValueLabel = ::PathFindFileName(pathFile.c_str()); - _treeView.addItem(strValueLabel, hTreeItem, INDEX_LEAF, pathFile.c_str()); - } - } + } while (::FindNextFile(hFile, &foundData)); ::FindClose(hFile); }