X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2FPackage.cpp;h=51b9ea2d84a0ea09fd15c4df2bcccea2936dcc3b;hb=2f2886b0946f87750d90aeae97a88d6571e0e22b;hp=6231a660ac69b067452af5d283f34937741c004d;hpb=c23db901ece8b4e21121e43fc2562ac73e79fc98;p=lyx.git diff --git a/src/support/Package.cpp b/src/support/Package.cpp index 6231a660ac..51b9ea2d84 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -1,6 +1,6 @@ // -*- C++ -*- /** - * \file package.C + * \file package.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * @@ -13,13 +13,12 @@ #include "support/Package.h" -#include "debug.h" -#include "gettext.h" - +#include "support/debug.h" #include "support/environment.h" +#include "support/ExceptionMessage.h" #include "support/filetools.h" +#include "support/gettext.h" #include "support/lstrings.h" -#include "support/ExceptionMessage.h" #include "support/os.h" #if defined (USE_WINDOWS_PACKAGING) @@ -39,7 +38,7 @@ # include // FSFindFolder, FSRefMakePath #endif -using std::string; +using namespace std; namespace lyx { namespace support { @@ -74,7 +73,7 @@ Package const & package() // Commented out because package().locale_dir() can be called // from the message translation code in Messages.cpp before // init_package() is called. Lars is on the case... - // BOOST_ASSERT(initialised_); + // LASSERT(initialised_, /**/); return package_; } @@ -96,8 +95,6 @@ FileName const get_locale_dir(FileName const & system_support_dir); FileName const get_system_support_dir(FileName const & abs_binary, string const & command_line_system_support_dir); -FileName const get_temp_dir(); - FileName const get_default_user_support_dir(FileName const & home_dir); bool userSupportDir(FileName const & default_user_support_dir, @@ -116,7 +113,9 @@ Package::Package(string const & command_line_arg0, : explicit_user_support_dir_(false) { home_dir_ = get_home_dir(); - system_temp_dir_ = get_temp_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_); @@ -150,8 +149,7 @@ Package::Package(string const & command_line_arg0, quoteName(configure_script.toFilesystemEncoding()) + with_version_suffix(); - lyxerr[Debug::INIT] - << "\n" + LYXERR(Debug::INIT, "\n" << "\tbinary_dir " << binary_dir().absFilename() << '\n' << "\tsystem_support " << system_support().absFilename() << '\n' << "\tbuild_support " << build_support().absFilename() << '\n' @@ -160,7 +158,16 @@ Package::Package(string const & command_line_arg0, << "\tdocument_dir " << document_dir().absFilename() << '\n' << "\ttemp_dir " << temp_dir().absFilename() << '\n' << "\thome_dir " << home_dir().absFilename() << '\n' - << "\n" << std::endl; + << "\n"); +} + + +void Package::set_temp_dir(FileName const & temp_dir) const +{ + if (temp_dir.empty()) + temp_dir_ = system_temp_dir_; + else + temp_dir_ = temp_dir; } @@ -279,8 +286,7 @@ void buildDirs(FileName const & abs_binary, FileName(addPath(Package::top_srcdir().absFilename(), "lib")); if (!fileSearch(system_support_dir.absFilename(), "chkconfig.ltx").empty()) { - lyxerr[Debug::INIT] << check_text << " yes" - << std::endl; + LYXERR(Debug::INIT, check_text << " yes"); return; } } @@ -299,7 +305,7 @@ void buildDirs(FileName const & abs_binary, } } - lyxerr[Debug::INIT] << check_text << " no" << std::endl; + LYXERR(Debug::INIT, check_text << " no"); system_support_dir = FileName(); build_support_dir = FileName(); } @@ -361,29 +367,15 @@ FileName const get_locale_dir(FileName const & system_support_dir) } -// Specification of temp_dir_ may be reset by LyXRC, -// but the default is fixed for a given OS. -FileName const get_temp_dir() -{ -#if defined (USE_WINDOWS_PACKAGING) - // Typical example: C:/TEMP/. - char path[MAX_PATH]; - GetTempPath(MAX_PATH, path); - return FileName(os::internal_path(to_utf8(from_local8bit(path)))); -#else // Posix-like. - return FileName("/tmp"); -#endif -} - - // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo" FileName const abs_path_from_command_line(string const & command_line) { if (command_line.empty()) return FileName(); - string const path = fix_dir_name(command_line); - return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path); + string const str_path = fix_dir_name(command_line); + FileName path(str_path); + return path.isAbsolute() ? path : makeAbsPath(str_path); } @@ -400,8 +392,9 @@ FileName const get_binary_path(string const & exe) #else string const exe_path = os::internal_path(exe); #endif - if (os::is_absolute_path(exe_path)) - return FileName(exe_path); + FileName exepath(exe_path); + if (exepath.isAbsolute()) + return exepath; // Two possibilities present themselves. // 1. The binary is relative to the CWD. @@ -415,9 +408,9 @@ FileName const get_binary_path(string const & exe) if (exe_name != exe_path) return FileName(); - std::vector const path = getEnvPath("PATH"); - std::vector::const_iterator it = path.begin(); - std::vector::const_iterator const end = path.end(); + vector const path = getEnvPath("PATH"); + vector::const_iterator it = path.begin(); + vector::const_iterator const end = path.end(); for (; it != end; ++it) { // This will do nothing if *it is already absolute. string const exe_dir = makeAbsPath(*it).absFilename(); @@ -458,7 +451,7 @@ get_system_support_dir(FileName const & abs_binary, // searched_dirs is used for diagnostic purposes only in the case // that "chkconfig.ltx" is not found. - std::list searched_dirs; + list searched_dirs; // 1. Use the -sysdir command line parameter. FileName path = abs_path_from_command_line(command_line_system_support_dir); @@ -468,11 +461,13 @@ get_system_support_dir(FileName const & abs_binary, return path; } - // 2. Use the "LYX_DIR_15x" environment variable. - path = extract_env_var_dir("LYX_DIR_15x"); + // 2. Use the "LYX_DIR_16x" environment variable. + // FIXME We need to iherit the actual version number from elsewhere + // otherwise we will forget to update this for new major releases + path = extract_env_var_dir("LYX_DIR_16x"); if (!path.empty()) { searched_dirs.push_back(path); - if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_15x")) + if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_16x")) return path; } @@ -548,7 +543,7 @@ get_system_support_dir(FileName const & abs_binary, // Everything has failed :-( // So inform the user and exit. string searched_dirs_str; - typedef std::list::const_iterator iterator; + typedef list::const_iterator iterator; iterator const begin = searched_dirs.begin(); iterator const end = searched_dirs.end(); for (iterator it = begin; it != end; ++it) { @@ -563,7 +558,7 @@ get_system_support_dir(FileName const & abs_binary, "having searched\n" "\t%1$s\n" "Use the '-sysdir' command line parameter or " - "set the environment variable LYX_DIR_15x to " + "set the environment variable LYX_DIR_16x to " "the LyX system directory containing the file " "`chkconfig.ltx'."), from_utf8(searched_dirs_str))); @@ -584,8 +579,8 @@ bool userSupportDir(FileName const & default_user_support_dir, if (!result.empty()) return true; - // 2. Use the LYX_USERDIR_15x environment variable. - result = extract_env_var_dir("LYX_USERDIR_15x"); + // 2. Use the LYX_USERDIR_16x environment variable. + result = extract_env_var_dir("LYX_USERDIR_16x"); if (!result.empty()) return true; @@ -632,7 +627,7 @@ FileName const get_default_user_support_dir(FileName const & home_dir) // Check that directory @c dir contains @c file. -// Else emit a warning about an invalid @c command_line_switch. +// Else emit an error message about an invalid @c command_line_switch. bool check_command_line_dir(string const & dir, string const & file, string const & command_line_switch) @@ -640,7 +635,7 @@ bool check_command_line_dir(string const & dir, FileName const abs_path = fileSearch(dir, file); if (abs_path.empty()) { // FIXME UNICODE - throw ExceptionMessage(WarningException, _("File not found"), bformat( + throw ExceptionMessage(ErrorException, _("File not found"), bformat( _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."), from_utf8(command_line_switch), from_utf8(dir), from_utf8(file)));