summaryrefslogtreecommitdiff
path: root/muse2/muse/globals.cpp
diff options
context:
space:
mode:
authorRobert Jonsson <spamatica@gmail.com>2011-02-27 21:21:15 +0000
committerRobert Jonsson <spamatica@gmail.com>2011-02-27 21:21:15 +0000
commit5524994708ff00769777f423c681faaa3c2af314 (patch)
tree910a59d34f1c546b313f8c3413618918d72fbf5d /muse2/muse/globals.cpp
parent1a4f5609b180772326e48aaca43b0ac02ff8f268 (diff)
D&D fixes ...dungeons and dragons?! better check the changelog
Diffstat (limited to 'muse2/muse/globals.cpp')
-rw-r--r--muse2/muse/globals.cpp47
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;
+ }