void FileBrowser::addRootFolder(generic_string rootFolderPath) { // make sure there's no '\' at the end if (rootFolderPath[rootFolderPath.length() - 1] == '\\') { rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } size_t nbFolderUpdaters = _folderUpdaters.size(); for (size_t i = 0; i < nbFolderUpdaters; ++i) { if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) return; else { size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); if (pos == 0) { //do nothing, go down to select the dir generic_string rootPath = _folderUpdaters[i]->_rootFolder._rootPath; generic_string pathSuffix = rootFolderPath.substr(rootPath.size() + 1, rootFolderPath.size() - rootPath.size()); vector<generic_string> linarPathArray = split(pathSuffix, '\\'); HTREEITEM foundItem = findInTree(rootPath, nullptr, linarPathArray); if (foundItem) _treeView.selectItem(foundItem); return; } pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); if (pos == 0) { ::MessageBox(_hParent, TEXT("A sub-folder of the folder you want to open exists.\rPlease remove it from the panel before you add this one."), rootFolderPath.c_str(), MB_OK); return; } } } std::vector<generic_string> patterns2Match; patterns2Match.push_back(TEXT("*.*")); TCHAR *label = ::PathFindFileName(rootFolderPath.c_str()); TCHAR rootLabel[MAX_PATH]; lstrcpy(rootLabel, label); size_t len = lstrlen(rootLabel); if (rootLabel[len - 1] == '\\') rootLabel[len - 1] = '\0'; FolderInfo directoryStructure(rootLabel, nullptr); getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false); HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure); _treeView.expand(hRootItem); _folderUpdaters.push_back(new FolderUpdater(directoryStructure, this)); _folderUpdaters[_folderUpdaters.size() - 1]->startWatcher(); }
void FileBrowser::addRootFolder(generic_string rootFolderPath) { // make sure there's no '\' at the end if (rootFolderPath[rootFolderPath.length() - 1] == '\\') { rootFolderPath = rootFolderPath.substr(0, rootFolderPath.length() - 1); } size_t nbFolderUpdaters = _folderUpdaters.size(); for (size_t i = 0; i < nbFolderUpdaters; ++i) { if (_folderUpdaters[i]->_rootFolder._rootPath == rootFolderPath) return; else { size_t pos = rootFolderPath.find(_folderUpdaters[i]->_rootFolder._rootPath); if (pos == 0) { printStr(TEXT("do nothing, go down to select the dir.")); return; } pos = _folderUpdaters[i]->_rootFolder._rootPath.find(rootFolderPath); if (pos == 0) { printStr(TEXT("remove old, add this one")); return; } } } std::vector<generic_string> patterns2Match; patterns2Match.push_back(TEXT("*.*")); TCHAR *label = ::PathFindFileName(rootFolderPath.c_str()); TCHAR rootLabel[MAX_PATH]; lstrcpy(rootLabel, label); size_t len = lstrlen(rootLabel); if (rootLabel[len - 1] == '\\') rootLabel[len - 1] = '\0'; FolderInfo directoryStructure(rootLabel, nullptr); getDirectoryStructure(rootFolderPath.c_str(), patterns2Match, directoryStructure, true, false); HTREEITEM hRootItem = createFolderItemsFromDirStruct(nullptr, directoryStructure); _treeView.expand(hRootItem); _folderUpdaters.push_back(new FolderUpdater(directoryStructure, this)); _folderUpdaters[_folderUpdaters.size() - 1]->startWatcher(); }