Skip to content

Commit

Permalink
Merge pull request #516 from ghutchis/create-directories-for-scripts
Browse files Browse the repository at this point in the history
Make sure to create directories for drag-and-drop scripts
  • Loading branch information
ghutchis authored Oct 29, 2024
2 parents 19bda73 + 331ff73 commit 13e2a9f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,25 @@ bool MainWindow::addScript(const QString& filePath)

QFileInfo info(filePath);

QString destinationPath(stdPaths[0] + '/' + typePath + '/' + info.fileName());
// check if the directory structure exists first
// and if not, create what we need
int i = 0;
bool createDir = true;
for (i = 0; i < stdPaths.size(); ++i) {
if (QDir(stdPaths[i] + '/' + typePath).exists()) {
createDir = false;
break;
}
}
if (createDir) {
// find a path we can create (e.g., first path might be admin-only)
for (i = 0; i < stdPaths.size(); ++i) {
if (QDir().mkpath(stdPaths[i] + '/' + typePath))
break;
}
}

QString destinationPath(stdPaths[i] + '/' + typePath + '/' + info.fileName());
qDebug() << " copying " << filePath << " to " << destinationPath;
QFile::remove(destinationPath); // silently fail if there's nothing to remove
QFile::copy(filePath, destinationPath);
Expand Down

0 comments on commit 13e2a9f

Please sign in to comment.