]> git.lyx.org Git - features.git/commitdiff
#7407, home_dir could be a static function and also be called by the
authorPeter Kümmel <syntheticpp@gmx.net>
Wed, 13 Apr 2011 19:11:55 +0000 (19:11 +0000)
committerPeter Kümmel <syntheticpp@gmx.net>
Wed, 13 Apr 2011 19:11:55 +0000 (19:11 +0000)
Package constructor

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38370 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/support/Package.cpp
src/support/Package.h
src/support/filetools.cpp

index d6bc6d579b3101b1faa78c24d969e0928a22f8d6..e4457431dd3bab31fe7b670f628798e3f55920a2 100644 (file)
@@ -1147,7 +1147,7 @@ docstring Buffer::emergencyWrite()
        }
 
        // 2) In HOME directory.
-       string s = addName(package().home_dir().absFileName(), absFileName());
+       string s = addName(Package::get_home_dir().absFileName(), absFileName());
        s += ".emergency";
        lyxerr << ' ' << s << endl;
        if (writeFile(FileName(s))) {
index 485846d8004d7a7315ed393ba61f46046d5ece70..61bce681e75baa7dcf691f522d4d56d1453f6421 100644 (file)
@@ -88,8 +88,6 @@ void buildDirs(FileName const & abs_binary,
 
 FileName const get_document_dir(FileName const & home_dir);
 
-FileName const get_home_dir();
-
 FileName const get_locale_dir(FileName const & system_support_dir);
 
 FileName const get_system_support_dir(FileName const & abs_binary,
@@ -100,9 +98,10 @@ FileName const get_default_user_support_dir(FileName const & home_dir);
 bool userSupportDir(FileName const & default_user_support_dir,
                     string const & command_line_user_support_dir, FileName & result);
 
-
 string const & with_version_suffix();
 
+string const fix_dir_name(string const & name);
+
 } // namespace anon
 
 
@@ -112,12 +111,11 @@ Package::Package(string const & command_line_arg0,
                 exe_build_dir_to_top_build_dir top_build_dir_location)
        : explicit_user_support_dir_(false)
 {
-       home_dir_ = get_home_dir();
        // Specification of temp_dir_ may be reset by LyXRC,
        // but the default is fixed for a given OS.
        system_temp_dir_ = FileName::tempPath();
        temp_dir_ = system_temp_dir_;
-       document_dir_ = get_document_dir(home_dir_);
+       document_dir_ = get_document_dir(get_home_dir());
 
        FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
        binary_dir_ = FileName(onlyPath(abs_binary.absFileName()));
@@ -156,7 +154,7 @@ Package::Package(string const & command_line_arg0,
        locale_dir_ = get_locale_dir(system_support_dir_);
 
        FileName const default_user_support_dir =
-               get_default_user_support_dir(home_dir_);
+               get_default_user_support_dir(get_home_dir());
 
        explicit_user_support_dir_ = userSupportDir(default_user_support_dir,
                                     command_line_user_support_dir, user_support_dir_);
@@ -174,7 +172,7 @@ Package::Package(string const & command_line_arg0,
                << "\tlocale_dir " << locale_dir().absFileName() << '\n'
                << "\tdocument_dir " << document_dir().absFileName() << '\n'
                << "\ttemp_dir " << temp_dir().absFileName() << '\n'
-               << "\thome_dir " << home_dir().absFileName() << '\n'
+               << "\thome_dir " << get_home_dir().absFileName() << '\n'
                << "</package>\n");
 }
 
@@ -187,6 +185,19 @@ void Package::set_temp_dir(FileName const & temp_dir) const
                temp_dir_ = temp_dir;
 }
 
+// The specification of home_dir_ is fixed for a given OS.
+// A typical example on Windows: "C:/Documents and Settings/USERNAME"
+// and on a Posix-like machine: "/home/USERNAME".
+FileName const & Package::get_home_dir()
+{
+#if defined (USE_WINDOWS_PACKAGING)
+       static FileName const home_dir(getEnv("USERPROFILE"));
+#else // Posix-like.
+       static FileName const home_dir(getEnv("HOME"));
+#endif
+       return home_dir;
+}
+
 
 namespace {
 
@@ -339,20 +350,6 @@ FileName const get_document_dir(FileName const & home_dir)
 }
 
 
-// The specification of home_dir_ is fixed for a given OS.
-// A typical example on Windows: "C:/Documents and Settings/USERNAME"
-// and on a Posix-like machine: "/home/USERNAME".
-FileName const get_home_dir()
-{
-#if defined (USE_WINDOWS_PACKAGING)
-       string const home_dir = getEnv("USERPROFILE");
-#else // Posix-like.
-       string const home_dir = getEnv("HOME");
-#endif
-
-       return FileName(fix_dir_name(home_dir));
-}
-
 
 // Several sources are probed to ascertain the locale directory.
 // The only requirement is that the result is indeed a directory.
index b8eb197fc4ef1d02fb420ca8a881f21be5112a34..94e191ca576482b7e45d1db4da0c17e5758c2502 100644 (file)
@@ -138,7 +138,7 @@ public:
         *  for the dump.
         *  This may be empty (e. g. when run under a CGI environment)
         */
-       FileName const & home_dir() const { return home_dir_; }
+       static FileName const & get_home_dir();
 
        /** Command to run the configure script.
         *  Caution: This is "ready-to-run", i.e. in the locale encoding, not
@@ -157,7 +157,6 @@ private:
        mutable FileName document_dir_;
        mutable FileName temp_dir_;
        FileName system_temp_dir_;
-       FileName home_dir_;
        std::string configure_command_;
        bool explicit_user_support_dir_;
 };
index d31926556dea3b826f83b5fd41a83af1418b5bea..10387de4221e4cdb5fc82dbf730be4f86995f96f 100644 (file)
@@ -444,7 +444,7 @@ FileName const makeAbsPath(string const & relPath, string const & basePath)
        // Split by first /
        rTemp = split(rTemp, temp, '/');
        if (temp == "~") {
-               tempBase = package().home_dir().absFileName();
+               tempBase = Package::get_home_dir().absFileName();
                tempRel = rTemp;
        }
 
@@ -540,7 +540,7 @@ string const expandPath(string const & path)
                return FileName::getcwd().absFileName() + '/' + rTemp;
 
        if (temp == "~")
-               return package().home_dir().absFileName() + '/' + rTemp;
+               return Package::get_home_dir().absFileName() + '/' + rTemp;
 
        if (temp == "..")
                return makeAbsPath(copy).absFileName();
@@ -726,7 +726,7 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
                return from_utf8("[" + str.erase(0, system.length()) + "]");
 
        // replace /home/blah with ~/
-       string const home = package().home_dir().absFileName();
+       string const home = Package::get_home_dir().absFileName();
        if (!home.empty() && prefixIs(str, home))
                str = subst(str, home, "~");