Skip to content

fix crash with some filenames (windows) #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions qimgv/components/directorymanager/directorymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ void DirectoryManager::loadEntryList(QString directoryPath, bool recursive) {
void DirectoryManager::addEntriesFromDirectory(std::vector<FSEntry> &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;
Expand Down Expand Up @@ -362,8 +362,8 @@ void DirectoryManager::addEntriesFromDirectory(std::vector<FSEntry> &entryVec, Q
void DirectoryManager::addEntriesFromDirectoryRecursive(std::vector<FSEntry> &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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion qimgv/components/scriptmanager/scriptmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void ScriptManager::runCommandDetached(QString cmd) {

#else
void ScriptManager::runScript(const QString &scriptName, std::shared_ptr<Image> img) {}
QString ScriptManager::runCommand(QString cmd) {}
QString ScriptManager::runCommand(QString cmd) { return QString(""); }
void ScriptManager::runCommandDetached(QString cmd) {}
#endif

Expand Down
2 changes: 1 addition & 1 deletion qimgv/sourcecontainers/fsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion qimgv/utils/imagelib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ QImage* ImageLib::scaled(std::shared_ptr<const QImage> source, QSize destSize, S
QImage* ImageLib::scaled_Qt(std::shared_ptr<const QImage> 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;
Expand Down