| 769 | } |
| 770 | |
| 771 | StrList FileSystemManager::getDirectoryContents(QString dirPath, QString filter) |
| 772 | { |
| 773 | #ifdef WIN32 |
| 774 | WIN32_FIND_DATA ffd; |
| 775 | vector<QString> listing; |
| 776 | HANDLE hFind = NULL; |
| 777 | |
| 778 | // Return early if no directory |
| 779 | if (!isValidFileName(dirPath)) |
| 780 | { |
| 781 | return listing; |
| 782 | } |
| 783 | |
| 784 | if (!dirPath.endsWith("\\")) |
| 785 | { |
| 786 | // Add a slash to the end of the Path |
| 787 | dirPath.append("\\"); |
| 788 | } |
| 789 | |
| 790 | hFind = FindFirstFile((LPCTSTR) (dirPath + filter).utf16(), &ffd); |
| 791 | if (hFind != INVALID_HANDLE_VALUE) |
| 792 | { |
| 793 | do |
| 794 | { |
| 795 | // Add the filename to the list |
| 796 | bool isHidden = (ffd.dwFileAttributes & Hidden) > 0; |
| 797 | if (!isHidden || GLOBAL(settings).LoadHiddenFiles) |
| 798 | { |
| 799 | QString fileName = QString::fromUtf16((const ushort *) ffd.cFileName); |
| 800 | if (fileName != "." && |
| 801 | fileName != "..") |
| 802 | { |
| 803 | listing.push_back(dirPath + fileName); |
| 804 | } |
| 805 | } |
| 806 | } while (FindNextFile(hFind, &ffd)); |
| 807 | |
| 808 | FindClose(hFind); |
| 809 | } |
| 810 | |
| 811 | return listing; |
| 812 | #else |
| 813 | vector<QString> fileListing; |
| 814 | |
| 815 | QStringList filters; |
| 816 | filters << filter; |
| 817 | QDir directory(dirPath); |
| 818 | if (exists(directory)) |
| 819 | { |
| 820 | directory.setNameFilters(filters); |
| 821 | directory.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); |
| 822 | directory.setSorting(QDir::Name | QDir::DirsFirst); |
| 823 | |
| 824 | QFileInfoList list = directory.entryInfoList(); |
| 825 | for (int i = 0; i < list.size(); ++i) |
| 826 | { |
| 827 | fileListing.push_back(native(list[i])); |
| 828 | } |