From 2991bbf033020d577ff859efa6521c8f2619117b Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 19 Sep 2015 16:07:33 +0200 Subject: [PATCH] + fixes #0001238: Preferences: set temp files directory --- src/App/Application.cpp | 19 +++++++++++++++++++ src/App/Application.h | 9 +++++++++ src/App/Document.cpp | 2 +- src/Gui/Application.cpp | 4 ++-- src/Gui/AutoSaver.cpp | 3 +++ src/Gui/CommandDoc.cpp | 2 +- .../DlgEditFileIncludeProptertyExternal.cpp | 3 ++- src/Gui/MainWindow.cpp | 2 +- src/Mod/Fem/App/FemMesh.cpp | 5 +++-- src/Mod/Part/App/PropertyTopoShape.cpp | 5 +++-- 10 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 927f577e2..bbed61b22 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -505,6 +505,16 @@ const char* Application::getExecutableName(void) const return _mConfig["ExeName"].c_str(); } +std::string Application::getTempPath() +{ + return mConfig["AppTempPath"]; +} + +std::string Application::getTempFileName(const char* FileName) +{ + return Base::FileInfo::getTempFileName(FileName, getTempPath().c_str()); +} + std::string Application::getUserAppDataDir() { return mConfig["UserAppData"]; @@ -1193,6 +1203,15 @@ void Application::initConfig(int argc, char ** argv) LoadParameters(); + // Set application tmp. directory + mConfig["AppTempPath"] = Base::FileInfo::getTempPath(); + std::string tmpPath = _pcUserParamMngr->GetGroup("BaseApp/Preferences/General")->GetASCII("TempPath"); + Base::FileInfo di(tmpPath); + if (di.exists() && di.isDir()) { + mConfig["AppTempPath"] = tmpPath + "/"; + } + + // capture python variables SaveEnv("PYTHONPATH"); SaveEnv("PYTHONHOME"); diff --git a/src/App/Application.h b/src/App/Application.h index dd109789e..b1e64c213 100644 --- a/src/App/Application.h +++ b/src/App/Application.h @@ -223,11 +223,20 @@ public: static char** GetARGV(void){return _argv;} //@} + /** @name Application directories */ + //@{ const char* getHomePath(void) const; const char* getExecutableName(void) const; + /*! + Returns the temporary directory. By default, this is set to the + system's temporary directory but can be customized by the user. + */ + static std::string getTempPath(); + static std::string getTempFileName(const char* FileName=0); static std::string getUserAppDataDir(); static std::string getResourceDir(); static std::string getHelpDir(); + //@} friend class App::Document; diff --git a/src/App/Document.cpp b/src/App/Document.cpp index c539fdc32..77f0201e0 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -731,7 +731,7 @@ std::string Document::getTransientDirectoryName(const std::string& uuid, const s std::stringstream s; QCryptographicHash hash(QCryptographicHash::Sha1); hash.addData(filename.c_str(), filename.size()); - s << Base::FileInfo::getTempPath() << GetApplication().getExecutableName() + s << App::Application::getTempPath() << GetApplication().getExecutableName() << "_Doc_" << uuid << "_" << hash.result().toHex().left(6).constData() << "_" << QCoreApplication::applicationPid(); diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 70843f039..38f35ff81 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1841,7 +1841,7 @@ void Application::runApplication(void) try { std::stringstream s; - s << Base::FileInfo::getTempPath() << App::GetApplication().getExecutableName() + s << App::Application::getTempPath() << App::GetApplication().getExecutableName() << "_" << QCoreApplication::applicationPid() << ".lock"; // open a lock file with the PID Base::FileInfo fi(s.str()); @@ -1875,7 +1875,7 @@ void Application::runApplication(void) void Application::checkForPreviousCrashes() { - QDir tmp = QDir::temp(); + QDir tmp = QString::fromUtf8(App::Application::getTempPath().c_str()); tmp.setNameFilters(QStringList() << QString::fromAscii("*.lock")); tmp.setFilter(QDir::Files); diff --git a/src/Gui/AutoSaver.cpp b/src/Gui/AutoSaver.cpp index 37f40b261..30f885a9d 100644 --- a/src/Gui/AutoSaver.cpp +++ b/src/Gui/AutoSaver.cpp @@ -310,6 +310,9 @@ public: , writer(dir) { writer.setModes(modes); + // always force binary format because ASCII + // is not reentrant. See PropertyPartShape::SaveDocFile + write.setMode("BinaryBrep"); writer.putNextEntry(file); } virtual ~RecoveryRunnable() diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index f89dd9189..76c7501ac 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -925,7 +925,7 @@ void StdCmdDuplicateSelection::activated(int iMsg) if (objs.empty()) return; - Base::FileInfo fi(Base::FileInfo::getTempFileName()); + Base::FileInfo fi(App::Application::getTempFileName()); { std::vector sel; // selected std::vector all; // object sub-graph diff --git a/src/Gui/DlgEditFileIncludeProptertyExternal.cpp b/src/Gui/DlgEditFileIncludeProptertyExternal.cpp index 860bd66a9..5d66d274d 100644 --- a/src/Gui/DlgEditFileIncludeProptertyExternal.cpp +++ b/src/Gui/DlgEditFileIncludeProptertyExternal.cpp @@ -65,7 +65,8 @@ int DlgEditFileIncludePropertyExternal::Do(void) QFileInfo file = QString::fromUtf8(Prop.getValue()); assert(file.exists()); - QString TempFile = QDir::temp().absolutePath() + QString::fromAscii("/") + file.fileName(); + QDir tmp = QString::fromUtf8(App::Application::getTempPath().c_str()); + QString TempFile = tmp.absoluteFilePath(file.fileName()); QFile::remove(TempFile); QFile::copy(file.absoluteFilePath(),TempFile); diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index d51856c06..c1735a4d1 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1334,7 +1334,7 @@ QMimeData * MainWindow::createMimeDataFromSelection () const } else { mime = QLatin1String("application/x-documentobject-file"); - static Base::FileInfo fi(Base::FileInfo::getTempFileName()); + static Base::FileInfo fi(App::Application::getTempFileName()); Base::ofstream str(fi, std::ios::out | std::ios::binary); // need this instance to call MergeDocuments::Save() App::Document* doc = sel.front()->getDocument(); diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 1de9bae4b..6f574e677 100755 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -1125,7 +1126,7 @@ void FemMesh::Restore(Base::XMLReader &reader) void FemMesh::SaveDocFile (Base::Writer &writer) const { // create a temporary file and copy the content to the zip stream - Base::FileInfo fi(Base::FileInfo::getTempFileName().c_str()); + Base::FileInfo fi(App::Application::getTempFileName().c_str()); myMesh->ExportUNV(fi.filePath().c_str()); @@ -1154,7 +1155,7 @@ void FemMesh::SaveDocFile (Base::Writer &writer) const void FemMesh::RestoreDocFile(Base::Reader &reader) { // create a temporary file and copy the content from the zip stream - Base::FileInfo fi(Base::FileInfo::getTempFileName().c_str()); + Base::FileInfo fi(App::Application::getTempFileName().c_str()); // read in the ASCII file and write back to the file stream Base::ofstream file(fi, std::ios::out | std::ios::binary); diff --git a/src/Mod/Part/App/PropertyTopoShape.cpp b/src/Mod/Part/App/PropertyTopoShape.cpp index ed4059ed0..8c3766f01 100644 --- a/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/src/Mod/Part/App/PropertyTopoShape.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include "PropertyTopoShape.h" @@ -277,7 +278,7 @@ void PropertyPartShape::SaveDocFile (Base::Writer &writer) const // create a temporary file and copy the content to the zip stream // once the tmp. filename is known use always the same because otherwise // we may run into some problems on the Linux platform - static Base::FileInfo fi(Base::FileInfo::getTempFileName()); + static Base::FileInfo fi(App::Application::getTempFileName()); if (!BRepTools::Write(myShape,(const Standard_CString)fi.filePath().c_str())) { // Note: Do NOT throw an exception here because if the tmp. file could @@ -330,7 +331,7 @@ void PropertyPartShape::RestoreDocFile(Base::Reader &reader) BRep_Builder builder; // create a temporary file and copy the content from the zip stream - Base::FileInfo fi(Base::FileInfo::getTempFileName()); + Base::FileInfo fi(App::Application::getTempFileName()); // read in the ASCII file and write back to the file stream Base::ofstream file(fi, std::ios::out | std::ios::binary);