126
126
#include < boost/version.hpp>
127
127
#include < QDir>
128
128
#include < QFileInfo>
129
+ #include < QProcessEnvironment>
129
130
130
131
using namespace App ;
131
132
using namespace std ;
@@ -2018,8 +2019,7 @@ void Application::initConfig(int argc, char ** argv)
2018
2019
#endif
2019
2020
}
2020
2021
2021
- // Set application tmp. directory
2022
- mConfig [" AppTempPath" ] = Base::FileInfo::getTempPath ();
2022
+ // Change application tmp. directory
2023
2023
std::string tmpPath = _pcUserParamMngr->GetGroup (" BaseApp/Preferences/General" )->GetASCII (" TempPath" );
2024
2024
Base::FileInfo di (tmpPath);
2025
2025
if (di.exists () && di.isDir ()) {
@@ -2696,20 +2696,70 @@ void Application::ExtractUserPath()
2696
2696
mConfig [" BinPath" ] = mConfig [" AppHomePath" ] + " bin" + PATHSEP;
2697
2697
mConfig [" DocPath" ] = mConfig [" AppHomePath" ] + " doc" + PATHSEP;
2698
2698
2699
+ // Set application tmp. directory
2700
+ mConfig [" AppTempPath" ] = Base::FileInfo::getTempPath ();
2701
+
2702
+ // this is to support a portable version of FreeCAD
2703
+ QProcessEnvironment env (QProcessEnvironment::systemEnvironment ());
2704
+ QString userHome = env.value (QString::fromLatin1 (" FREECAD_USER_HOME" ));
2705
+ QString userData = env.value (QString::fromLatin1 (" FREECAD_USER_DATA" ));
2706
+ QString userTemp = env.value (QString::fromLatin1 (" FREECAD_USER_TEMP" ));
2707
+
2708
+ // verify env. variables
2709
+ if (!userHome.isEmpty ()) {
2710
+ QDir dir (userHome);
2711
+ if (dir.exists ())
2712
+ userHome = QDir::toNativeSeparators (dir.canonicalPath ());
2713
+ else
2714
+ userHome.clear ();
2715
+ }
2716
+
2717
+ if (!userData.isEmpty ()) {
2718
+ QDir dir (userData);
2719
+ if (dir.exists ())
2720
+ userData = QDir::toNativeSeparators (dir.canonicalPath ());
2721
+ else
2722
+ userData.clear ();
2723
+ }
2724
+ else if (!userHome.isEmpty ()) {
2725
+ // if FREECAD_USER_HOME is set but not FREECAD_USER_DATA
2726
+ userData = userHome;
2727
+ }
2728
+
2729
+ // override temp directory if set by env. variable
2730
+ if (!userTemp.isEmpty ()) {
2731
+ QDir dir (userTemp);
2732
+ if (dir.exists ()) {
2733
+ userTemp = dir.canonicalPath ();
2734
+ userTemp += QDir::separator ();
2735
+ userTemp = QDir::toNativeSeparators (userTemp);
2736
+ mConfig [" AppTempPath" ] = userTemp.toUtf8 ().data ();
2737
+ }
2738
+ }
2739
+ else if (!userHome.isEmpty ()) {
2740
+ // if FREECAD_USER_HOME is set but not FREECAD_USER_TEMP
2741
+ QDir dir (userHome);
2742
+ dir.mkdir (QString::fromLatin1 (" temp" ));
2743
+ QFileInfo fi (dir, QString::fromLatin1 (" temp" ));
2744
+ QString tmp (fi.absoluteFilePath ());
2745
+ tmp += QDir::separator ();
2746
+ tmp = QDir::toNativeSeparators (tmp);
2747
+ mConfig [" AppTempPath" ] = tmp.toUtf8 ().data ();
2748
+ }
2749
+
2699
2750
#if defined(FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_BSD)
2700
2751
// Default paths for the user specific stuff
2701
2752
struct passwd *pwd = getpwuid (getuid ());
2702
2753
if (pwd == NULL )
2703
2754
throw Base::RuntimeError (" Getting HOME path from system failed!" );
2704
2755
mConfig [" UserHomePath" ] = pwd->pw_dir ;
2756
+ if (!userHome.isEmpty ()) {
2757
+ mConfig [" UserHomePath" ] = userHome.toUtf8 ().data ();
2758
+ }
2705
2759
2706
- char *path = pwd->pw_dir ;
2707
- char *fc_user_data;
2708
- if ((fc_user_data = getenv (" FREECAD_USER_DATA" ))) {
2709
- QString env = QString::fromUtf8 (fc_user_data);
2710
- QDir dir (env);
2711
- if (!env.isEmpty () && dir.exists ())
2712
- path = fc_user_data;
2760
+ std::string path = pwd->pw_dir ;
2761
+ if (!userData.isEmpty ()) {
2762
+ path = userData.toUtf8 ().data ();
2713
2763
}
2714
2764
2715
2765
std::string appData (path);
@@ -2764,7 +2814,14 @@ void Application::ExtractUserPath()
2764
2814
if (pwd == NULL )
2765
2815
throw Base::RuntimeError (" Getting HOME path from system failed!" );
2766
2816
mConfig [" UserHomePath" ] = pwd->pw_dir ;
2817
+ if (!userHome.isEmpty ()) {
2818
+ mConfig [" UserHomePath" ] = userHome.toUtf8 ().data ();
2819
+ }
2820
+
2767
2821
std::string appData = pwd->pw_dir ;
2822
+ if (!userData.isEmpty ()) {
2823
+ appData = userData.toUtf8 ().data ();
2824
+ }
2768
2825
appData += PATHSEP;
2769
2826
appData += " Library" ;
2770
2827
appData += PATHSEP;
@@ -2823,8 +2880,13 @@ void Application::ExtractUserPath()
2823
2880
WideCharToMultiByte (CP_UTF8, 0 , szPath, -1 ,dest, 256 , NULL , NULL );
2824
2881
mConfig [" UserHomePath" ] = dest;
2825
2882
}
2826
- else
2883
+ else {
2827
2884
mConfig [" UserHomePath" ] = mConfig [" AppHomePath" ];
2885
+ }
2886
+
2887
+ if (!userHome.isEmpty ()) {
2888
+ mConfig [" UserHomePath" ] = userHome.toUtf8 ().data ();
2889
+ }
2828
2890
2829
2891
// In the second step we want the directory where user settings of the application can be
2830
2892
// kept. There we create a directory with name of the vendor and a sub-directory with name
@@ -2834,6 +2896,9 @@ void Application::ExtractUserPath()
2834
2896
WideCharToMultiByte (CP_UTF8, 0 , szPath, -1 ,dest, 256 , NULL , NULL );
2835
2897
2836
2898
std::string appData = dest;
2899
+ if (!userData.isEmpty ()) {
2900
+ appData = userData.toUtf8 ().data ();
2901
+ }
2837
2902
Base::FileInfo fi (appData.c_str ());
2838
2903
if (!fi.exists ()) {
2839
2904
// This should never ever happen
0 commit comments