void ProjectPanel::recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTreeItem)
{
    bool isRecursive = true;
    bool isInHiddenDir = false;
    generic_string dirFilter(folderPath);
    if (folderPath[lstrlen(folderPath)-1] != '\\')
        dirFilter += TEXT("\\");

    dirFilter += TEXT("*.*");
    WIN32_FIND_DATA foundData;
    std::vector<generic_string> files;

    HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData);

    do {
        if (hFile == INVALID_HANDLE_VALUE)
            break;

        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
        {
            files.push_back(foundData.cFileName);
        }
    } while (::FindNextFile(hFile, &foundData));

    for (size_t i = 0, len = files.size() ; i < len ; ++i)
    {
        generic_string pathFile(folderPath);
        if (folderPath[lstrlen(folderPath)-1] != '\\')
            pathFile += TEXT("\\");
        pathFile += files[i];
        _treeView.addItem(files[i].c_str(), hTreeItem, INDEX_LEAF, pathFile.c_str());
    }

    ::FindClose(hFile);
}
Exemple #2
0
static DirPtr dirSearchSubdir(DirPtr dir, String dirname, DirPtr *ret)
{
  DirPtr ret1, ret2;

  if (!dirExpandSubdir(dir, dirname, &ret1)) {
  retry:
    if (!ret1)
      return (*ret = NULL);
    else if (dirFilter(ret1)) {
      dirSetFilter(ret1, NULL);
      if (dirExpandSubdir(dir, dirname, &ret2))
	return (*ret = ret2);
      else if (ret2 == ret1) {
	*ret = ret1;
	return NULL;
      } else {
	ret1 = ret2;
	goto retry;
      }
    } else if (!(dirOptions(ret1) & INCLUDE_HIDDEN)) {
      dirSetOptions(ret1, INCLUDE_HIDDEN);
      if (dirExpandSubdir(dir, dirname, &ret2))
	return (*ret = ret2);
      else if (ret2 == ret1) {
	*ret = ret1;
	return NULL;
      } else {
	ret1 = ret2;
	goto retry;
      }
    } else {
      *ret = ret1;
      return NULL;
    }
  } else
    return (*ret = ret1);
}
void FileBrowser::getDirectoryStructure(const TCHAR *dir, const std::vector<generic_string> & patterns, FolderInfo & directoryStructure, bool isRecursive, bool isInHiddenDir)
{
	if (directoryStructure._parent == nullptr) // Root!
		directoryStructure.setRootPath(dir);

	generic_string dirFilter(dir);
	if (dirFilter[dirFilter.length() - 1] != '\\')
		dirFilter += TEXT("\\");
	dirFilter += TEXT("*.*");
	WIN32_FIND_DATA foundData;

	HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData);

	if (hFile != INVALID_HANDLE_VALUE)
	{

		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(dir);
					if (pathDir[pathDir.length() - 1] != '\\')
						pathDir += TEXT("\\");
					pathDir += foundData.cFileName;
					pathDir += TEXT("\\");

					FolderInfo subDirectoryStructure(foundData.cFileName, &directoryStructure);
					getDirectoryStructure(pathDir.c_str(), patterns, subDirectoryStructure, isRecursive, isInHiddenDir);
					directoryStructure.addSubFolder(subDirectoryStructure);
				}
			}
		}
		else
		{
			if (matchInList(foundData.cFileName, patterns))
			{
				directoryStructure.addFile(foundData.cFileName);
			}
		}
	}

	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(dir);
					if (pathDir[pathDir.length() - 1] != '\\')
						pathDir += TEXT("\\");
					pathDir += foundData.cFileName;
					pathDir += TEXT("\\");

					FolderInfo subDirectoryStructure(foundData.cFileName, &directoryStructure);
					getDirectoryStructure(pathDir.c_str(), patterns, subDirectoryStructure, isRecursive, isInHiddenDir);
					directoryStructure.addSubFolder(subDirectoryStructure);
				}
			}
		}
		else
		{
			if (matchInList(foundData.cFileName, patterns))
			{
				directoryStructure.addFile(foundData.cFileName);
			}
		}
	}
	::FindClose(hFile);
}