Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
fix: check path existence
Browse files Browse the repository at this point in the history
 (#55)
  • Loading branch information
BLumia authored Apr 22, 2019
1 parent 9f1df85 commit d8431cc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QDBusInterface>
#include <QDir>

#include <DApplication>

Expand Down Expand Up @@ -1337,12 +1338,20 @@ bool MainWindow::saveAction(const QPixmap &pix)
if (!screenShotPix.save(m_saveFileName, QFileInfo(m_saveFileName).suffix().toLocal8Bit()))
return false;
} else if (saveOption != QStandardPaths::TempLocation && m_saveFileName.isEmpty()) {
QString savePath = QStandardPaths::writableLocation(saveOption);
QDir saveDir(savePath);
if (!saveDir.exists()) {
bool mkdirSucc = saveDir.mkpath(".");
if (!mkdirSucc) {
qCritical() << "Save path not exist and cannot be created:" << savePath;
qCritical() << "Fall back to temp location!";
savePath = QDir::tempPath();
}
}
if (m_selectAreaName.isEmpty()) {
m_saveFileName = QString("%1/%2_%3.png").arg(QStandardPaths::writableLocation(
saveOption)).arg(tr("DeepinScreenshot")).arg(currentTime);
m_saveFileName = QString("%1/%2_%3.png").arg(savePath, tr("DeepinScreenshot"), currentTime);
} else {
m_saveFileName = QString("%1/%2_%3_%4.png").arg(QStandardPaths::writableLocation(
saveOption)).arg(tr("DeepinScreenshot")).arg(m_selectAreaName).arg(currentTime);
m_saveFileName = QString("%1/%2_%3_%4.png").arg(savePath, tr("DeepinScreenshot"), m_selectAreaName, currentTime);
}
if (!screenShotPix.save(m_saveFileName, "PNG"))
return false;
Expand Down

0 comments on commit d8431cc

Please # to comment.