diff options
Diffstat (limited to 'muse2/muse/globals.cpp')
-rw-r--r-- | muse2/muse/globals.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/muse2/muse/globals.cpp b/muse2/muse/globals.cpp index f53846f9..80990f0e 100644 --- a/muse2/muse/globals.cpp +++ b/muse2/muse/globals.cpp @@ -397,3 +397,50 @@ void undoSetuid() #endif } +//--------------------------------------------------------- +// getUniqueTmpfileName +//--------------------------------------------------------- +bool getUniqueTmpfileName(QString subDir, QString ext,QString& newFilename) + { + // Check if tmp-directory exists under project path + QString tmpInDir = museProject + "/" + subDir; + QFileInfo tmpdirfi(tmpInDir); + if (!tmpdirfi.isDir()) { + // Try to create a tmpdir + QDir projdir(museProject); + if (!projdir.mkdir(subDir)) { + printf("Could not create tmp dir %s!\n", tmpInDir.toLatin1().data() ); + return false; + } + } + + + tmpdirfi.setFile(tmpInDir); + + if (!tmpdirfi.isWritable()) { + printf("Temp directory is not writable - aborting\n"); + return false; + } + + QDir tmpdir = tmpdirfi.dir(); + + // Find a new filename + for (int i=0; i<10000; i++) { + QString filename = "muse_tmp"; + filename.append(QString::number(i)); + if (!ext.startsWith(".")) + filename.append("."); + filename.append(ext); + + if (!tmpdir.exists(tmpInDir +"/" + filename)) { + newFilename = tmpInDir + "/" + filename; + if (debugMsg) + printf("returning temporary filename %s\n", newFilename.toLatin1().data()); + return true; + } + + } + + printf("Could not find a suitable tmpfilename (more than 10000 tmpfiles in tmpdir - clean up!\n"); + return false; + } |