Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

readDirectory enhancements

shun_iwasawaf5f4afa9d06c
diff --git a/toonz/sources/common/tsound/tsound_nt.cpp b/toonz/sources/common/tsound/tsound_nt.cpp
index 2ff35fa3d..89554bb16 100644
--- a/toonz/sources/common/tsound/tsound_nt.cpp
+++ b/toonz/sources/common/tsound/tsound_nt.cpp
@@ -1915,7 +1915,7 @@ std::string getMixerLineName(DWORD lineID) {
assert(false);
return "";
#else
- return std::string(mxl.szName);
+ return QString::fromWCharArray(mxl.szName).toStdString();
#endif
}
diff --git a/toonz/sources/common/tsystem/tsystem.cpp b/toonz/sources/common/tsystem/tsystem.cpp
index a8b772465..c67c081db 100644
--- a/toonz/sources/common/tsystem/tsystem.cpp
+++ b/toonz/sources/common/tsystem/tsystem.cpp
@@ -32,7 +32,6 @@ using namespace std;
#include <winnt.h>
#endif
-
namespace {
inline QString toQString(const TFilePath &path) {
@@ -437,29 +436,63 @@ public:
};
//------------------------------------------------------------
-/*! return the file list which is readable and executable
+/*! return the folder path list which is readable and executable
*/
void TSystem::readDirectory_Dir_ReadExe(TFilePathSet &dst,
const TFilePath &path) {
- if (!TFileStatus(path).isDirectory())
- throw TSystemException(path, " is not a directory");
-
- std::set<TFilePath, CaselessFilepathLess> fileSet;
+ QStringList dirItems;
+ readDirectory_DirItems(dirItems, path);
- QStringList fil =
- QDir(toQString(path))
- .entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable);
+ for (const QString &item : dirItems) {
+ TFilePath son = path + TFilePath(item.toStdWString());
+ dst.push_back(son);
+ }
+}
- int i;
- for (i = 0; i < fil.size(); i++) {
- QString fi = fil.at(i);
+//------------------------------------------------------------
+// return the folder item list which is readable and executable
+// (returns only names, not full path)
+void TSystem::readDirectory_DirItems(QStringList &dst, const TFilePath &path) {
+ if (!TFileStatus(path).isDirectory())
+ throw TSystemException(path, " is not a directory");
- TFilePath son = path + TFilePath(fi.toStdWString());
+ QDir dir(toQString(path));
- fileSet.insert(son);
+#ifdef _WIN32
+ // equivalent to sorting with QDir::LocaleAware
+ struct strCompare {
+ bool operator()(const QString &s1, const QString &s2) {
+ return QString::localeAwareCompare(s1, s2) < 0;
+ }
+ };
+
+ std::set<QString, strCompare> entries;
+
+ WIN32_FIND_DATA find_dir_data;
+ QString dir_search_path = dir.absolutePath() + "\\*";
+ auto addEntry = [&]() {
+ // QDir::NoDotAndDotDot condition
+ if (wcscmp(find_dir_data.cFileName, L".") != 0 &&
+ wcscmp(find_dir_data.cFileName, L"..") != 0) {
+ // QDir::AllDirs condition
+ if (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
+ (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) {
+ entries.insert(QString::fromWCharArray(find_dir_data.cFileName));
+ }
+ }
+ };
+ HANDLE hFind =
+ FindFirstFile((const wchar_t *)dir_search_path.utf16(), &find_dir_data);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ addEntry();
+ while (FindNextFile(hFind, &find_dir_data)) addEntry();
}
+ for (const QString &name : entries) dst.push_back(QString(name));
- dst.insert(dst.end(), fileSet.begin(), fileSet.end());
+#else
+ dst = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Readable,
+ QDir::Name | QDir::LocaleAware);
+#endif
}
//------------------------------------------------------------
@@ -473,10 +506,31 @@ void TSystem::readDirectory(TFilePathSet &groupFpSet, TFilePathSet &allFpSet,
std::set<TFilePath, CaselessFilepathLess> fileSet_group;
std::set<TFilePath, CaselessFilepathLess> fileSet_all;
- QStringList fil =
- QDir(toQString(path))
- .entryList(QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
-
+ QStringList fil;
+#ifdef _WIN32
+ WIN32_FIND_DATA find_dir_data;
+ QString dir_search_path = QDir(toQString(path)).absolutePath() + "\\*";
+ auto addEntry = [&]() {
+ // QDir::NoDotAndDotDot condition
+ if (wcscmp(find_dir_data.cFileName, L".") != 0 &&
+ wcscmp(find_dir_data.cFileName, L"..") != 0) {
+ // QDir::Files condition
+ if ((find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 &&
+ (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) {
+ fil.append(QString::fromWCharArray(find_dir_data.cFileName));
+ }
+ }
+ };
+ HANDLE hFind =
+ FindFirstFile((const wchar_t *)dir_search_path.utf16(), &find_dir_data);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ addEntry();
+ while (FindNextFile(hFind, &find_dir_data)) addEntry();
+ }
+#else
+ fil = QDir(toQString(path))
+ .entryList(QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
+#endif
if (fil.size() == 0) return;
for (int i = 0; i < fil.size(); i++) {
@@ -506,8 +560,40 @@ void TSystem::readDirectory(TFilePathSet &dst, const QDir &dir,
if (!(dir.exists() && QFileInfo(dir.path()).isDir()))
throw TSystemException(TFilePath(dir.path().toStdWString()),
" is not a directory");
+ QStringList entries;
+#ifdef _WIN32
+ WIN32_FIND_DATA find_dir_data;
+ QString dir_search_path = dir.absolutePath() + "\\*";
+ QDir::Filters filter = dir.filter();
+ auto addEntry = [&]() {
+ // QDir::NoDotAndDotDot condition
+ if (wcscmp(find_dir_data.cFileName, L".") != 0 &&
+ wcscmp(find_dir_data.cFileName, L"..") != 0) {
+ // QDir::Files condition
+ if ((filter & QDir::Files) == 0 &&
+ (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
+ return;
+ // QDir::Dirs condition
+ if ((filter & QDir::Dirs) == 0 &&
+ (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
+ return;
+ // QDir::Hidden condition
+ if ((filter & QDir::Hidden) == 0 &&
+ (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
+ return;
+ entries.append(QString::fromWCharArray(find_dir_data.cFileName));
+ }
+ };
+ HANDLE hFind =
+ FindFirstFile((const wchar_t *)dir_search_path.utf16(), &find_dir_data);
+ if (hFind != INVALID_HANDLE_VALUE) {
+ addEntry();
+ while (FindNextFile(hFind, &find_dir_data)) addEntry();
+ }
+#else
+ entries = (dir.entryList(dir.filter() | QDir::NoDotAndDotDot));
+#endif
- QStringList entries(dir.entryList(dir.filter() | QDir::NoDotAndDotDot));
TFilePath dirPath(dir.path().toStdWString());
std::set<TFilePath, CaselessFilepathLess> fpSet;
diff --git a/toonz/sources/include/tsystem.h b/toonz/sources/include/tsystem.h
index 1c2e8cab3..ddd01ae71 100644
--- a/toonz/sources/include/tsystem.h
+++ b/toonz/sources/include/tsystem.h
@@ -115,9 +115,12 @@ DVAPI void readDirectoryTree(TFilePathSet &fpset, const TFilePathSet &pathSet,
DVAPI void readDirectory(TFilePathSet &groupFpSet, TFilePathSet &allFpSet,
const TFilePath &path);
-// return the file list which is readable and executable
+// return the folder path list which is readable and executable
DVAPI void readDirectory_Dir_ReadExe(TFilePathSet &dst, const TFilePath &path);
+// return the folder item list which is readable and executable (only names)
+DVAPI void readDirectory_DirItems(QStringList &dst, const TFilePath &path);
+
// creano un set nuovo
DVAPI TFilePathSet readDirectory(const TFilePath &path, bool groupFrames = true,
bool onlyFiles = false,
diff --git a/toonz/sources/tnzcore/CMakeLists.txt b/toonz/sources/tnzcore/CMakeLists.txt
index 658c70e26..6873c4721 100644
--- a/toonz/sources/tnzcore/CMakeLists.txt
+++ b/toonz/sources/tnzcore/CMakeLists.txt
@@ -290,6 +290,13 @@ add_definitions(
-DTSTREAM_EXPORTS
)
+if(BUILD_TARGET_WIN)
+ add_definitions(
+ -DUNICODE
+ -D_UNICODE
+ )
+endif()
+
message("subdir: tnzcore")
#message("Sources:" ${SOURCES})
diff --git a/toonz/sources/toonz/filebrowser.cpp b/toonz/sources/toonz/filebrowser.cpp
index c0a4675e3..1202b326e 100644
--- a/toonz/sources/toonz/filebrowser.cpp
+++ b/toonz/sources/toonz/filebrowser.cpp
@@ -579,6 +579,17 @@ void FileBrowser::refreshCurrentFolderItems() {
}
TFilePathSet::iterator it;
for (it = files.begin(); it != files.end(); ++it) {
+#ifdef _WIN32
+ // include folder shortcut items
+ if (it->getType() == "lnk") {
+ TFileStatus info(*it);
+ if (info.isLink() && info.isDirectory()) {
+ m_items.push_back(
+ Item(*it, true, true, QString::fromStdString((*it).getName())));
+ }
+ continue;
+ }
+#endif
// skip the plt file (Palette file for TOONZ 4.6 and earlier)
if (it->getType() == "plt") continue;
@@ -733,6 +744,17 @@ void FileBrowser::setUnregisteredFolder(const TFilePath &fp) {
}
for (it = files.begin(); it != files.end(); ++it) {
+#ifdef _WIN32
+ // include folder shortcut items
+ if (it->getType() == "lnk") {
+ TFileStatus info(*it);
+ if (info.isLink() && info.isDirectory()) {
+ m_items.push_back(
+ Item(*it, true, true, QString::fromStdString((*it).getName())));
+ }
+ continue;
+ }
+#endif
// skip the plt file (Palette file for TOONZ 4.6 and earlier)
if (it->getType() == "plt") continue;
diff --git a/toonz/sources/toonz/filebrowsermodel.cpp b/toonz/sources/toonz/filebrowsermodel.cpp
index cdf093707..0b8a47b36 100644
--- a/toonz/sources/toonz/filebrowsermodel.cpp
+++ b/toonz/sources/toonz/filebrowsermodel.cpp
@@ -316,46 +316,11 @@ void DvDirModelFileFolderNode::getChildrenNames(
if (!folderPathStatus.isDirectory()) return;
- QDir dir(toQString(m_path));
+ QStringList dirItems;
+ TSystem::readDirectory_DirItems(dirItems, m_path);
+ for (const QString &name : dirItems) names.push_back(name.toStdWString());
-#ifdef _WIN32
- // equivalent to sorting with QDir::LocaleAware
- struct strCompare {
- bool operator()(const QString &s1, const QString &s2) {
- return QString::localeAwareCompare(s1, s2) < 0;
- }
- };
-
- std::set<QString, strCompare> entries;
-
- WIN32_FIND_DATA find_dir_data;
- QString dir_search_path = dir.absolutePath() + "\\*";
- auto addEntry = [&]() {
- // QDir::NoDotAndDotDot condition
- if (wcscmp(find_dir_data.cFileName, L".") != 0 &&
- wcscmp(find_dir_data.cFileName, L"..") != 0) {
- // QDir::AllDirs condition
- if (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
- (find_dir_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) {
- entries.insert(QString::fromWCharArray(find_dir_data.cFileName));
- }
- }
- };
- HANDLE hFind =
- FindFirstFile((const wchar_t *)dir_search_path.utf16(), &find_dir_data);
- if (hFind != INVALID_HANDLE_VALUE) {
- addEntry();
- while (FindNextFile(hFind, &find_dir_data)) addEntry();
- }
- for (const QString &name : entries) names.push_back(name.toStdWString());
-
-#else
- QStringList entries = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot,
- QDir::Name | QDir::LocaleAware);
-
- int e, eCount = entries.size();
- for (e = 0; e != eCount; ++e) names.push_back(entries[e].toStdWString());
-#endif
+ QDir dir(toQString(m_path));
}
//-----------------------------------------------------------------------------