Skip to content

Commit 13e2a9f

Browse files
authored
Merge pull request #516 from ghutchis/create-directories-for-scripts
Make sure to create directories for drag-and-drop scripts
2 parents 19bda73 + 331ff73 commit 13e2a9f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

avogadro/mainwindow.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,25 @@ bool MainWindow::addScript(const QString& filePath)
874874

875875
QFileInfo info(filePath);
876876

877-
QString destinationPath(stdPaths[0] + '/' + typePath + '/' + info.fileName());
877+
// check if the directory structure exists first
878+
// and if not, create what we need
879+
int i = 0;
880+
bool createDir = true;
881+
for (i = 0; i < stdPaths.size(); ++i) {
882+
if (QDir(stdPaths[i] + '/' + typePath).exists()) {
883+
createDir = false;
884+
break;
885+
}
886+
}
887+
if (createDir) {
888+
// find a path we can create (e.g., first path might be admin-only)
889+
for (i = 0; i < stdPaths.size(); ++i) {
890+
if (QDir().mkpath(stdPaths[i] + '/' + typePath))
891+
break;
892+
}
893+
}
894+
895+
QString destinationPath(stdPaths[i] + '/' + typePath + '/' + info.fileName());
878896
qDebug() << " copying " << filePath << " to " << destinationPath;
879897
QFile::remove(destinationPath); // silently fail if there's nothing to remove
880898
QFile::copy(filePath, destinationPath);

0 commit comments

Comments
 (0)