]> git.lyx.org Git - lyx.git/blobdiff - src/support/package.C.in
* src/text2.C: deleteEmptyParagraphMechanism(): fix a crash in
[lyx.git] / src / support / package.C.in
index f666e6eceb9a3852e011f4004704bda9b7e2b347..efe19c62727696173219dfe66d18032765d3f468 100644 (file)
@@ -22,6 +22,7 @@
 #include "support/environment.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
+#include "support/ExceptionMessage.h"
 #include "support/os.h"
 
 #if defined (USE_WINDOWS_PACKAGING)
@@ -124,7 +125,8 @@ Package::Package(string const & command_line_arg0,
        : explicit_user_support_dir_(false)
 {
        home_dir_ = get_home_dir();
-       temp_dir_ = get_temp_dir();
+       system_temp_dir_ = get_temp_dir();
+       temp_dir_ = system_temp_dir_;
        document_dir_ = get_document_dir(home_dir_);
 
        string const abs_binary = abs_path_from_binary_name(command_line_arg0);
@@ -171,28 +173,28 @@ namespace {
 // configuration-time.
 string const top_srcdir()
 {
-       static string const dir("%TOP_SRCDIR%");
+       static string const dir("@TOP_SRCDIR@");
        return dir;
 }
 
 
 string const hardcoded_localedir()
 {
-       return string("%LOCALEDIR%");
+       return string("@LOCALEDIR@");
 }
 
 
 string const hardcoded_system_support_dir()
 {
-       return string("%LYX_DIR%");
+       return string("@LYX_DIR@");
 }
 
 
 string const & with_version_suffix()
 {
-       static string const program_suffix("%PROGRAM_SUFFIX%");
+       static string const program_suffix("@PROGRAM_SUFFIX@");
        static string const
-               with_version_suffix(" --with-version-suffix=%PROGRAM_SUFFIX%");
+               with_version_suffix(" --with-version-suffix=@PROGRAM_SUFFIX@");
        return program_suffix.empty() ? program_suffix : with_version_suffix;
 }
 
@@ -201,7 +203,7 @@ string const & with_version_suffix()
 
 string const & Package::top_srcdir() const
 {
-       static string const dir("%TOP_SRCDIR%");
+       static string const dir("@TOP_SRCDIR@");
        return dir;
 }
 
@@ -279,7 +281,7 @@ get_build_dirs(string const & abs_binary,
 
                // Check whether binary is a symbolic link.
                // If so, resolve it and repeat the exercise.
-               if (!fs::symbolic_link_exists(binary))
+               if (!fs::symbolic_link_exists(FileName(binary).toFilesystemEncoding()))
                        break;
 
                string link;
@@ -330,22 +332,24 @@ string const get_home_dir()
 string const get_locale_dir(string const & system_support_dir)
 {
        // 1. Use the "LYX_LOCALEDIR" environment variable.
-       string path = extract_env_var_dir("LYX_LOCALEDIR");
-       if (!path.empty() && check_env_var_dir(path, "LYX_LOCALEDIR"))
-               return path;
+       string const path_env = extract_env_var_dir("LYX_LOCALEDIR");
+       if (!path_env.empty() && check_env_var_dir(path_env, "LYX_LOCALEDIR"))
+               return path_env;
 
        // 2. Search for system_support_dir / <relative locale dir>
        // The <relative locale dir> is OS-dependent. (On Unix, it will
        // be "../locale/".)
-       path = normalizePath(addPath(system_support_dir, relative_locale_dir()));
+       FileName path(normalizePath(addPath(system_support_dir, relative_locale_dir())));
 
-       if (fs::exists(path) && fs::is_directory(path))
-               return path;
+       if (fs::exists(path.toFilesystemEncoding()) &&
+           fs::is_directory(path.toFilesystemEncoding()))
+               return path.absFilename();
 
        // 3. Fall back to the hard-coded LOCALEDIR.
-       path = hardcoded_localedir();
-       if (fs::exists(path) && fs::is_directory(path))
-               return path;
+       path = FileName(hardcoded_localedir());
+       if (fs::exists(path.toFilesystemEncoding()) &&
+           fs::is_directory(path.toFilesystemEncoding()))
+               return path.absFilename();
 
        return string();
 }
@@ -366,15 +370,6 @@ string const get_temp_dir()
 }
 
 
-void bail_out()
-{
-#ifndef CXX_GLOBAL_CSTD
-       using std::exit;
-#endif
-       exit(1);
-}
-
-
 // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
 string const abs_path_from_command_line(string const & command_line)
 {
@@ -382,7 +377,7 @@ string const abs_path_from_command_line(string const & command_line)
                return string();
 
        string const path = os::internal_path(command_line);
-       return os::is_absolute_path(path) ? path : makeAbsPath(path);
+       return os::is_absolute_path(path) ? path : makeAbsPath(path).absFilename();
 }
 
 
@@ -404,8 +399,8 @@ string const get_binary_path(string const & exe)
 
        // Two possibilities present themselves.
        // 1. The binary is relative to the CWD.
-       string const abs_exe_path = makeAbsPath(exe_path);
-       if (fs::exists(abs_exe_path))
+       string const abs_exe_path = makeAbsPath(exe_path).absFilename();
+       if (fs::exists(FileName(abs_exe_path).toFilesystemEncoding()))
                return abs_exe_path;
 
        // 2. exe must be the name of the binary only and it
@@ -419,10 +414,10 @@ string const get_binary_path(string const & exe)
        std::vector<string>::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);
+               string const exe_dir = makeAbsPath(*it).absFilename();
 
                string const exe_path = addName(exe_dir, exe_name);
-               if (fs::exists(exe_path))
+               if (fs::exists(FileName(exe_path).toFilesystemEncoding()))
                        return exe_path;
        }
 
@@ -437,11 +432,10 @@ string const abs_path_from_binary_name(string const & exe)
        string const abs_binary = get_binary_path(exe);
        if (abs_binary.empty()) {
                // FIXME UNICODE
-               lyxerr << lyx::to_utf8(bformat(_("Unable to determine the path to the "
-                                                "LyX binary from the command line %1$s"),
-                                                lyx::from_utf8(exe)))
-                      << std::endl;
-               bail_out();
+               throw ExceptionMessage(ErrorException,
+                       _("LyX binary not found"),
+                       bformat(_("Unable to determine the path to the LyX binary from the command line %1$s"),
+                               lyx::from_utf8(exe)));
        }
        return abs_binary;
 }
@@ -468,11 +462,11 @@ get_system_support_dir(string const & abs_binary,
                        return path;
        }
 
-       // 2. Use the "LYX_DIR_14x" environment variable.
-       path = extract_env_var_dir("LYX_DIR_14x");
+       // 2. Use the "LYX_DIR_15x" environment variable.
+       path = extract_env_var_dir("LYX_DIR_15x");
        if (!path.empty()) {
                searched_dirs.push_back(path);
-               if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_14x"))
+               if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_15x"))
                        return path;
        }
 
@@ -501,7 +495,7 @@ get_system_support_dir(string const & abs_binary,
 
                // Check whether binary is a symbolic link.
                // If so, resolve it and repeat the exercise.
-               if (!fs::symbolic_link_exists(binary))
+               if (!fs::symbolic_link_exists(FileName(binary).toFilesystemEncoding()))
                        break;
 
                string link;
@@ -519,7 +513,7 @@ get_system_support_dir(string const & abs_binary,
                // This time test whether the directory is a symbolic link
                // *before* looking for "chkconfig.ltx".
                // (We've looked relative to the original already.)
-               if (!fs::symbolic_link_exists(binary))
+               if (!fs::symbolic_link_exists(FileName(binary).toFilesystemEncoding()))
                        break;
 
                string link;
@@ -559,17 +553,16 @@ get_system_support_dir(string const & abs_binary,
        }
 
        // FIXME UNICODE
-       lyxerr << lyx::to_utf8(bformat(_("Unable to determine the system directory "
+       throw ExceptionMessage(ErrorException, _("No system directory"),
+               bformat(_("Unable to determine the system directory "
                                         "having searched\n"
                                         "\t%1$s\n"
                                         "Use the '-sysdir' command line parameter or "
-                                        "set the environment variable LYX_DIR_14x to "
+                                        "set the environment variable LYX_DIR_15x to "
                                         "the LyX system directory containing the file "
                                         "`chkconfig.ltx'."),
-                         lyx::from_utf8(searched_dirs_str)))
-              << std::endl;
+                         lyx::from_utf8(searched_dirs_str)));
 
-       bail_out();
        // Keep the compiler happy.
        return string();
 }
@@ -590,8 +583,8 @@ get_user_support_dir(string const & default_user_support_dir,
        if (!path.empty())
                return std::make_pair(path, explicit_userdir);
 
-       // 2. Use the LYX_USERDIR_14x environment variable.
-       path = extract_env_var_dir("LYX_USERDIR_14x");
+       // 2. Use the LYX_USERDIR_15x environment variable.
+       path = extract_env_var_dir("LYX_USERDIR_15x");
        if (!path.empty())
                return std::make_pair(path, explicit_userdir);
 
@@ -642,14 +635,13 @@ bool check_command_line_dir(string const & dir,
                            string const & file,
                            string const & command_line_switch)
 {
-       string const abs_path = fileSearch(dir, file);
+       FileName const abs_path = fileSearch(dir, file);
        if (abs_path.empty()) {
                // FIXME UNICODE
-               lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s switch.\n"
-                                                "Directory %2$s does not contain %3$s."),
-                                 lyx::from_utf8(command_line_switch), lyx::from_utf8(dir),
-                                 lyx::from_utf8(file)))
-                      << std::endl;
+               throw ExceptionMessage(WarningException, _("File not found"), bformat(
+                       _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
+                       lyx::from_utf8(command_line_switch), lyx::from_utf8(dir),
+                       lyx::from_utf8(file)));
        }
 
        return !abs_path.empty();
@@ -660,7 +652,7 @@ bool check_command_line_dir(string const & dir,
 string const extract_env_var_dir(string const & env_var)
 {
        string const dir = os::internal_path(getEnv(env_var));
-       return dir.empty() ? dir : makeAbsPath(dir);
+       return dir.empty() ? dir : makeAbsPath(dir).absFilename();
 }
 
 
@@ -670,13 +662,14 @@ bool check_env_var_dir(string const & dir,
                       string const & file,
                       string const & env_var)
 {
-       string const abs_path = fileSearch(dir, file);
+       FileName const abs_path = fileSearch(dir, file);
        if (abs_path.empty()) {
                // FIXME UNICODE
-               lyxerr << lyx::to_utf8(bformat(_("Invalid %1$s environment variable.\n"
-                                                "Directory %2$s does not contain %3$s."),
-                                 lyx::from_utf8(env_var), lyx::from_utf8(dir), lyx::from_utf8(file)))
-                      << std::endl;
+               throw ExceptionMessage(WarningException, _("File not found"), bformat(
+                       _("Invalid %1$s environment variable.\n"
+                               "Directory %2$s does not contain %3$s."),
+                       lyx::from_utf8(env_var), lyx::from_utf8(dir),
+                       lyx::from_utf8(file)));
        }
 
        return !abs_path.empty();
@@ -688,7 +681,8 @@ bool check_env_var_dir(string const & dir,
 bool check_env_var_dir(string const & dir,
                       string const & env_var)
 {
-       bool const success = (fs::exists(dir) && fs::is_directory(dir));
+       string const encoded(FileName(dir).toFilesystemEncoding());
+       bool const success = (fs::exists(encoded) && fs::is_directory(encoded));
 
        if (!success) {
                // Put this string on a single line so that the gettext
@@ -699,8 +693,8 @@ bool check_env_var_dir(string const & dir,
                docstring const fmt =
                        _("Invalid %1$s environment variable.\n%2$s is not a directory.");
 
-               lyxerr << lyx::to_utf8(bformat(fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)))
-                      << std::endl;
+               throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
+                       fmt, lyx::from_utf8(env_var), lyx::from_utf8(dir)));
        }
 
        return success;