From f640c211fe3d7289fdac910bb8261dbe17bf0eec Mon Sep 17 00:00:00 2001 From: sriram Date: Thu, 14 Oct 2021 21:41:03 -0500 Subject: [PATCH 1/2] use generic_wstring instead of generic_string --- .../components/directorymanager/directorymanager.cpp | 12 ++++++------ .../watchers/windows/windowsworker.h | 2 +- qimgv/components/scriptmanager/scriptmanager.cpp | 2 +- qimgv/sourcecontainers/fsentry.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/qimgv/components/directorymanager/directorymanager.cpp b/qimgv/components/directorymanager/directorymanager.cpp index 849d5e15..41d49a81 100644 --- a/qimgv/components/directorymanager/directorymanager.cpp +++ b/qimgv/components/directorymanager/directorymanager.cpp @@ -321,13 +321,13 @@ void DirectoryManager::loadEntryList(QString directoryPath, bool recursive) { void DirectoryManager::addEntriesFromDirectory(std::vector &entryVec, QString directoryPath) { QRegularExpressionMatch match; for(const auto & entry : fs::directory_iterator(toStdString(directoryPath))) { - QString name = QString::fromStdString(entry.path().filename().generic_string()); + QString name = QString::fromStdWString(entry.path().filename().generic_wstring()); #ifndef Q_OS_WIN32 // ignore hidden files if(name.startsWith(".")) continue; #endif - QString path = QString::fromStdString(entry.path().generic_string()); + QString path = QString::fromStdWString(entry.path().generic_wstring()); match = regex.match(name); if(entry.is_directory()) { // this can still throw std::bad_alloc .. FSEntry newEntry; @@ -362,8 +362,8 @@ void DirectoryManager::addEntriesFromDirectory(std::vector &entryVec, Q void DirectoryManager::addEntriesFromDirectoryRecursive(std::vector &entryVec, QString directoryPath) { QRegularExpressionMatch match; for(const auto & entry : fs::recursive_directory_iterator(toStdString(directoryPath))) { - QString name = QString::fromStdString(entry.path().filename().generic_string()); - QString path = QString::fromStdString(entry.path().generic_string()); + QString name = QString::fromStdWString(entry.path().filename().generic_wstring()); + QString path = QString::fromStdWString(entry.path().generic_wstring()); match = regex.match(name); if(!entry.is_directory() && match.hasMatch()) { FSEntry newEntry; @@ -414,7 +414,7 @@ bool DirectoryManager::forceInsertFileEntry(const QString &filePath) { if(!this->isFile(filePath) || containsFile(filePath)) return false; std::filesystem::directory_entry stdEntry(toStdString(filePath)); - QString fileName = QString::fromStdString(stdEntry.path().filename().generic_string()); // isn't it beautiful + QString fileName = QString::fromStdWString(stdEntry.path().filename().generic_wstring()); // isn't it beautiful FSEntry FSEntry(filePath, fileName, stdEntry.file_size(), stdEntry.last_write_time(), stdEntry.is_directory()); insert_sorted(fileEntryVec, FSEntry, std::bind(compareFunction(), this, std::placeholders::_1, std::placeholders::_2)); qDebug() << "fileIns" << filePath; @@ -478,7 +478,7 @@ bool DirectoryManager::insertDirEntry(const QString &dirPath) { if(containsDir(dirPath)) return false; std::filesystem::directory_entry stdEntry(toStdString(dirPath)); - QString dirName = QString::fromStdString(stdEntry.path().filename().generic_string()); // isn't it beautiful + QString dirName = QString::fromStdWString(stdEntry.path().filename().generic_wstring()); // isn't it beautiful FSEntry FSEntry; FSEntry.name = dirName; FSEntry.path = dirPath; diff --git a/qimgv/components/directorymanager/watchers/windows/windowsworker.h b/qimgv/components/directorymanager/watchers/windows/windowsworker.h index 82dea637..cb407ab5 100644 --- a/qimgv/components/directorymanager/watchers/windows/windowsworker.h +++ b/qimgv/components/directorymanager/watchers/windows/windowsworker.h @@ -17,7 +17,7 @@ class WindowsWorker : public WatcherWorker { void notifyEvent(PFILE_NOTIFY_INFORMATION); private: - HANDLE hDir; + HANDLE hDir = NULL; WCHAR buffer[1024]; DWORD bytesReturned; uint POLL_RATE_MS = 1000; diff --git a/qimgv/components/scriptmanager/scriptmanager.cpp b/qimgv/components/scriptmanager/scriptmanager.cpp index 0c1418d7..6ac69478 100644 --- a/qimgv/components/scriptmanager/scriptmanager.cpp +++ b/qimgv/components/scriptmanager/scriptmanager.cpp @@ -68,7 +68,7 @@ void ScriptManager::runCommandDetached(QString cmd) { #else void ScriptManager::runScript(const QString &scriptName, std::shared_ptr img) {} -QString ScriptManager::runCommand(QString cmd) {} +QString ScriptManager::runCommand(QString cmd) { return QString(""); } void ScriptManager::runCommandDetached(QString cmd) {} #endif diff --git a/qimgv/sourcecontainers/fsentry.cpp b/qimgv/sourcecontainers/fsentry.cpp index 6d483bee..e7560d72 100644 --- a/qimgv/sourcecontainers/fsentry.cpp +++ b/qimgv/sourcecontainers/fsentry.cpp @@ -5,7 +5,7 @@ FSEntry::FSEntry() { FSEntry::FSEntry(const QString &path) { std::filesystem::directory_entry stdEntry(toStdString(path)); - QString name = QString::fromStdString(stdEntry.path().filename().generic_string()); + QString name = QString::fromStdWString(stdEntry.path().filename().generic_wstring()); if(stdEntry.is_directory()) { try { this->name = name; From 6542284f5e114d3d7ff25ead04a4f88bf83edeb9 Mon Sep 17 00:00:00 2001 From: sriram Date: Thu, 14 Oct 2021 21:43:03 -0500 Subject: [PATCH 2/2] fix crash if source is null --- qimgv/utils/imagelib.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qimgv/utils/imagelib.cpp b/qimgv/utils/imagelib.cpp index c43ba6cd..0d0ed5b0 100644 --- a/qimgv/utils/imagelib.cpp +++ b/qimgv/utils/imagelib.cpp @@ -159,7 +159,9 @@ QImage* ImageLib::scaled(std::shared_ptr source, QSize destSize, S QImage* ImageLib::scaled_Qt(std::shared_ptr source, QSize destSize, bool smooth) { QImage *dest = new QImage(); Qt::TransformationMode mode = smooth ? Qt::SmoothTransformation : Qt::FastTransformation; - *dest = source->scaled(destSize.width(), destSize.height(), Qt::IgnoreAspectRatio, mode); + if (source) { + *dest = source->scaled(destSize.width(), destSize.height(), Qt::IgnoreAspectRatio, mode); + } return dest;