Skip to content

Commit

Permalink
better tmp path determining in portable mode #14
Browse files Browse the repository at this point in the history
  • Loading branch information
krzemin committed Aug 6, 2015
1 parent bb80af2 commit 1670734
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/qnapiconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ void QNapiConfig::reload()
if(settings) delete settings;

QString localQNapiIniPath = QCoreApplication::applicationDirPath() + QDir::separator() + "qnapi.ini";
isPortableMode = QFileInfo(localQNapiIniPath).exists();

if(QFileInfo(localQNapiIniPath).exists())
if(isPortableMode)
{
settings = new QSettings(localQNapiIniPath, QSettings::IniFormat);
}
Expand Down Expand Up @@ -110,7 +111,13 @@ void QNapiConfig::setP7zipPath(const QString & path)

QString QNapiConfig::tmpPath()
{
return settings->value("qnapi/tmp_path", QDir::tempPath()).toString();
QString tmpPath = settings->value("qnapi/tmp_path", QDir::tempPath()).toString();
if(!QFileInfo(tmpPath).exists() || !QFileInfo(tmpPath).isWritable()) {
if(isPortableMode) {
tmpPath = QDir::tempPath();
}
}
return tmpPath;
}

void QNapiConfig::setTmpPath(const QString & path)
Expand Down
1 change: 1 addition & 0 deletions src/qnapiconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class QNapiConfig
~QNapiConfig();

QSettings *settings;
bool isPortableMode;

friend QNapiConfig& GlobalConfig();
};
Expand Down

0 comments on commit 1670734

Please sign in to comment.