From dd64477e3b32903f7663f2f1ec02f12ade1c0dec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Wed, 13 Apr 2011 19:11:55 +0000 Subject: [PATCH] #7407, home_dir could be a static function and also be called by the Package constructor git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38370 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 2 +- src/support/Package.cpp | 39 ++++++++++++++++++--------------------- src/support/Package.h | 3 +-- src/support/filetools.cpp | 6 +++--- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d6bc6d579b..e4457431dd 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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))) { diff --git a/src/support/Package.cpp b/src/support/Package.cpp index 485846d800..61bce681e7 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -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' << "\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. diff --git a/src/support/Package.h b/src/support/Package.h index b8eb197fc4..94e191ca57 100644 --- a/src/support/Package.h +++ b/src/support/Package.h @@ -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_; }; diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index d31926556d..10387de422 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -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, "~"); -- 2.39.2