#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)
}
-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)
{
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();
}
// Two possibilities present themselves.
// 1. The binary is relative to the CWD.
- string const abs_exe_path = makeAbsPath(exe_path);
+ string const abs_exe_path = makeAbsPath(exe_path).absFilename();
if (fs::exists(FileName(abs_exe_path).toFilesystemEncoding()))
return abs_exe_path;
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(FileName(exe_path).toFilesystemEncoding()))
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;
}
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;
}
}
// 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();
}
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);
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();
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();
}
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();
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;