2005-01-10 19:17:43 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2007-11-29 07:04:28 +00:00
|
|
|
* \file package.cpp
|
2005-01-10 19:17:43 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
Rename files in src/support, step one.
src/support/package.h src/support/Package.h Package
src/support/package.C.in src/support/Package.C.in Package
src/support/path.h src/support/Path.h Path
src/support/fs_extras.h src/support/fs_extras.h NOCLASSES
src/support/RandomAccessList.h src/support/RandomAccessList.h RandomAccessList
src/support/lyxmanip.h src/support/lyxmanip.h NOCLASSES
src/support/rename.C src/support/rename.cpp NOCLASSES
src/support/abort.C src/support/abort.cpp NOCLASSES
src/support/lyxlib.h src/support/lyxlib.h NOCLASSES
src/support/ExceptionMessage.h src/support/ExceptionMessage.h ExceptionMessage
src/support/copy.C src/support/copy.cpp NOCLASSES
src/support/limited_stack.h src/support/limited_stack.h limited_stack
src/support/filefilterlist.C src/support/FileFilterList.cpp ['FileFilterList', 'Filter']
src/support/cow_ptr.h src/support/cow_ptr.h cow_ptr
src/support/os_unix.C src/support/os_unix.cpp NOCLASSES
src/support/socktools.h src/support/socktools.h NOCLASSES
src/support/forkedcontr.h src/support/ForkedcallsController.h ForkedcallsController
src/support/os.h src/support/os.h NOCLASSES
src/support/FileMonitor.h src/support/FileMonitor.h FileMonitor
src/support/copied_ptr.h src/support/copied_ptr.h copied_ptr
src/support/translator.h src/support/Translator.h Translator
src/support/filetools.C src/support/filetools.cpp NOCLASSES
src/support/unlink.C src/support/unlink.cpp NOCLASSES
src/support/os_win32.C src/support/os_win32.cpp GetFolderPath
src/support/lstrings.C src/support/lstrings.cpp NOCLASSES
src/support/qstring_helpers.C src/support/qstring_helpers.cpp NOCLASSES
src/support/getcwd.C src/support/getcwd.cpp NOCLASSES
src/support/systemcall.C src/support/Systemcall.cpp Systemcall
src/support/lyxalgo.h src/support/lyxalgo.h NOCLASSES
src/support/filefilterlist.h src/support/FileFilterList.h ['FileFilterList', 'Filter']
src/support/unicode.C src/support/unicode.cpp IconvProcessor
src/support/userinfo.C src/support/userinfo.cpp NOCLASSES
src/support/lyxtime.C src/support/lyxtime.cpp NOCLASSES
src/support/kill.C src/support/kill.cpp NOCLASSES
src/support/docstring.C src/support/docstring.cpp to_local8bit_failure
src/support/os_cygwin.C src/support/os_cygwin.cpp NOCLASSES
src/support/lyxsum.C src/support/lyxsum.cpp NOCLASSES
src/support/environment.C src/support/environment.cpp NOCLASSES
src/support/filetools.h src/support/filetools.h NOCLASSES
src/support/textutils.C src/support/textutils.cpp NOCLASSES
src/support/mkdir.C src/support/mkdir.cpp NOCLASSES
src/support/forkedcall.C src/support/Forkedcall.cpp ['ForkedProcess', 'Forkedcall']
src/support/tempname.C src/support/tempname.cpp NOCLASSES
src/support/os_win32.h src/support/os_win32.h GetFolderPath
src/support/types.h src/support/types.h NOCLASSES
src/support/lstrings.h src/support/lstrings.h NOCLASSES
src/support/forkedcallqueue.C src/support/ForkedCallQueue.cpp ForkedCallQueue
src/support/qstring_helpers.h src/support/qstring_helpers.h NOCLASSES
src/support/convert.C src/support/convert.cpp NOCLASSES
src/support/filename.C src/support/FileName.cpp ['FileName', 'DocFileName']
src/support/tests/convert.C src/support/tests/convert.cpp NOCLASSES
src/support/tests/filetools.C src/support/tests/filetools.cpp NOCLASSES
src/support/tests/lstrings.C src/support/tests/lstrings.cpp NOCLASSES
src/support/tests/boost.C src/support/tests/boost.cpp NOCLASSES
src/support/docstream.C src/support/docstream.cpp ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/std_istream.h src/support/std_istream.h NOCLASSES
src/support/systemcall.h src/support/Systemcall.h Systemcall
src/support/chdir.C src/support/chdir.cpp NOCLASSES
src/support/std_ostream.h src/support/std_ostream.h NOCLASSES
src/support/unicode.h src/support/unicode.h IconvProcessor
src/support/path.C src/support/Path.cpp Path
src/support/fs_extras.C src/support/fs_extras.cpp NOCLASSES
src/support/userinfo.h src/support/userinfo.h NOCLASSES
src/support/lyxtime.h src/support/lyxtime.h NOCLASSES
src/support/docstring.h src/support/docstring.h to_local8bit_failure
src/support/debugstream.h src/support/debugstream.h basic_debugstream
src/support/environment.h src/support/environment.h NOCLASSES
src/support/textutils.h src/support/textutils.h NOCLASSES
src/support/forkedcall.h src/support/Forkedcall.h ['ForkedProcess', 'Forkedcall']
src/support/socktools.C src/support/socktools.cpp NOCLASSES
src/support/forkedcallqueue.h src/support/ForkedCallQueue.h ForkedCallQueue
src/support/forkedcontr.C src/support/ForkedcallsController.cpp ForkedcallsController
src/support/os.C src/support/os.cpp NOCLASSES
src/support/convert.h src/support/convert.h NOCLASSES
src/support/filename.h src/support/FileName.h ['FileName', 'DocFileName']
src/support/docstream.h src/support/docstream.h ['iconv_codecvt_facet_exception', 'idocfstream', 'odocfstream']
src/support/FileMonitor.C src/support/FileMonitor.cpp FileMonitor
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18024 a592a061-630c-0410-9148-cb99ea01b6c8
2007-04-26 05:12:52 +00:00
|
|
|
#include "support/Package.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2005-02-15 13:45:41 +00:00
|
|
|
#include "support/environment.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
#include "support/filetools.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/os.h"
|
|
|
|
|
2005-09-30 12:24:50 +00:00
|
|
|
#if defined (USE_WINDOWS_PACKAGING)
|
|
|
|
# include "support/os_win32.h"
|
|
|
|
#endif
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#if !defined (USE_WINDOWS_PACKAGING) && \
|
|
|
|
!defined (USE_MACOSX_PACKAGING) && \
|
|
|
|
!defined (USE_POSIX_PACKAGING)
|
|
|
|
#error USE_FOO_PACKAGING must be defined for FOO = WINDOWS, MACOSX or POSIX.
|
|
|
|
#endif
|
|
|
|
|
2005-10-02 21:49:52 +00:00
|
|
|
#if defined (USE_MACOSX_PACKAGING)
|
2005-01-10 19:17:43 +00:00
|
|
|
# include <CoreServices/CoreServices.h> // FSFindFolder, FSRefMakePath
|
|
|
|
#endif
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace support {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
Package package_;
|
|
|
|
bool initialised_ = false;
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
void init_package(string const & command_line_arg0,
|
|
|
|
string const & command_line_system_support_dir,
|
2005-01-31 19:57:03 +00:00
|
|
|
string const & command_line_user_support_dir,
|
|
|
|
exe_build_dir_to_top_build_dir top_build_dir_location)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
// Can do so only once.
|
|
|
|
if (initialised_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
package_ = Package(command_line_arg0,
|
|
|
|
command_line_system_support_dir,
|
2005-01-31 19:57:03 +00:00
|
|
|
command_line_user_support_dir,
|
|
|
|
top_build_dir_location);
|
2005-01-10 19:17:43 +00:00
|
|
|
initialised_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Package const & package()
|
|
|
|
{
|
2005-01-17 11:50:16 +00:00
|
|
|
// Commented out because package().locale_dir() can be called
|
2007-04-26 04:41:58 +00:00
|
|
|
// from the message translation code in Messages.cpp before
|
2005-01-17 11:50:16 +00:00
|
|
|
// init_package() is called. Lars is on the case...
|
2008-04-10 21:49:34 +00:00
|
|
|
// LASSERT(initialised_, /**/);
|
2005-01-10 19:17:43 +00:00
|
|
|
return package_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const abs_path_from_binary_name(string const & exe);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-11-25 23:25:00 +00:00
|
|
|
void buildDirs(FileName const & abs_binary,
|
|
|
|
exe_build_dir_to_top_build_dir top_build_dir_location,
|
|
|
|
FileName &, FileName &);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_document_dir(FileName const & home_dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_home_dir();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_locale_dir(FileName const & system_support_dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_system_support_dir(FileName const & abs_binary,
|
2005-01-12 12:25:30 +00:00
|
|
|
string const & command_line_system_support_dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_default_user_support_dir(FileName const & home_dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-11-25 23:25:00 +00:00
|
|
|
bool userSupportDir(FileName const & default_user_support_dir,
|
|
|
|
string const & command_line_user_support_dir, FileName & result);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2006-04-22 11:58:02 +00:00
|
|
|
|
|
|
|
string const & with_version_suffix();
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
Package::Package(string const & command_line_arg0,
|
|
|
|
string const & command_line_system_support_dir,
|
2005-01-31 19:57:03 +00:00
|
|
|
string const & command_line_user_support_dir,
|
|
|
|
exe_build_dir_to_top_build_dir top_build_dir_location)
|
2005-01-10 19:17:43 +00:00
|
|
|
: explicit_user_support_dir_(false)
|
|
|
|
{
|
|
|
|
home_dir_ = get_home_dir();
|
2008-07-22 17:45:40 +00:00
|
|
|
// Specification of temp_dir_ may be reset by LyXRC,
|
|
|
|
// but the default is fixed for a given OS.
|
|
|
|
system_temp_dir_ = FileName::tempPath();
|
2006-12-17 21:52:40 +00:00
|
|
|
temp_dir_ = system_temp_dir_;
|
2005-01-10 19:17:43 +00:00
|
|
|
document_dir_ = get_document_dir(home_dir_);
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
|
2010-04-21 01:19:09 +00:00
|
|
|
binary_dir_ = FileName(onlyPath(abs_binary.absFileName()));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// Is LyX being run in-place from the build tree?
|
2007-11-25 23:25:00 +00:00
|
|
|
buildDirs(abs_binary, top_build_dir_location,
|
|
|
|
build_support_dir_, system_support_dir_);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
if (build_support_dir_.empty())
|
|
|
|
system_support_dir_ =
|
|
|
|
get_system_support_dir(abs_binary,
|
|
|
|
command_line_system_support_dir);
|
|
|
|
|
|
|
|
locale_dir_ = get_locale_dir(system_support_dir_);
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const default_user_support_dir =
|
2005-01-10 19:17:43 +00:00
|
|
|
get_default_user_support_dir(home_dir_);
|
2007-11-26 10:22:28 +00:00
|
|
|
|
2007-11-25 23:25:00 +00:00
|
|
|
explicit_user_support_dir_ = userSupportDir(default_user_support_dir,
|
|
|
|
command_line_user_support_dir, user_support_dir_);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const configure_script(addName(system_support().absFileName(), "configure.py"));
|
2007-04-06 13:09:54 +00:00
|
|
|
configure_command_ = os::python() + ' ' +
|
2009-05-11 22:03:52 +00:00
|
|
|
quoteName(configure_script.toFilesystemEncoding(), quote_python) +
|
2007-04-06 13:09:54 +00:00
|
|
|
with_version_suffix();
|
2006-04-22 11:58:02 +00:00
|
|
|
|
2007-11-27 21:09:14 +00:00
|
|
|
LYXERR(Debug::INIT, "<package>\n"
|
2010-04-21 01:19:09 +00:00
|
|
|
<< "\tbinary_dir " << binary_dir().absFileName() << '\n'
|
|
|
|
<< "\tsystem_support " << system_support().absFileName() << '\n'
|
|
|
|
<< "\tbuild_support " << build_support().absFileName() << '\n'
|
|
|
|
<< "\tuser_support " << user_support().absFileName() << '\n'
|
|
|
|
<< "\tlocale_dir " << locale_dir().absFileName() << '\n'
|
|
|
|
<< "\tdocument_dir " << document_dir().absFileName() << '\n'
|
|
|
|
<< "\ttemp_dir " << temp_dir().absFileName() << '\n'
|
|
|
|
<< "\thome_dir " << home_dir().absFileName() << '\n'
|
2007-11-27 21:09:14 +00:00
|
|
|
<< "</package>\n");
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-09 13:05:24 +00:00
|
|
|
void Package::set_temp_dir(FileName const & temp_dir) const
|
|
|
|
{
|
|
|
|
if (temp_dir.empty())
|
|
|
|
temp_dir_ = system_temp_dir_;
|
|
|
|
else
|
|
|
|
temp_dir_ = temp_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-04-06 09:39:05 +00:00
|
|
|
// These next functions contain the stuff that is substituted at
|
2005-01-10 19:17:43 +00:00
|
|
|
// configuration-time.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const hardcoded_localedir()
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
// The build system needs to make sure that this is in utf8 encoding.
|
2007-08-27 21:29:56 +00:00
|
|
|
return FileName(LYX_ABS_INSTALLED_LOCALEDIR);
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const hardcoded_system_support_dir()
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
// The build system needs to make sure that this is in utf8 encoding.
|
2007-08-27 21:29:56 +00:00
|
|
|
return FileName(LYX_ABS_INSTALLED_DATADIR);
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 11:58:02 +00:00
|
|
|
|
|
|
|
string const & with_version_suffix()
|
|
|
|
{
|
2007-08-27 21:29:56 +00:00
|
|
|
static string const program_suffix = PROGRAM_SUFFIX;
|
|
|
|
static string const with_version_suffix =
|
|
|
|
" --with-version-suffix=" PROGRAM_SUFFIX;
|
2006-04-22 11:58:02 +00:00
|
|
|
return program_suffix.empty() ? program_suffix : with_version_suffix;
|
|
|
|
}
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const & Package::top_srcdir()
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
// The build system needs to make sure that this is in utf8 encoding.
|
2007-08-27 21:29:56 +00:00
|
|
|
static FileName const dir(LYX_ABS_TOP_SRCDIR);
|
2005-01-10 19:17:43 +00:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool check_command_line_dir(string const & dir,
|
|
|
|
string const & file,
|
|
|
|
string const & command_line_switch);
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const extract_env_var_dir(string const & env_var);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
bool check_env_var_dir(FileName const & dir,
|
2005-01-10 19:17:43 +00:00
|
|
|
string const & env_var);
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
bool check_env_var_dir(FileName const & dir,
|
2005-01-10 19:17:43 +00:00
|
|
|
string const & file,
|
|
|
|
string const & env_var);
|
|
|
|
|
|
|
|
string const relative_locale_dir();
|
|
|
|
|
|
|
|
string const relative_system_support_dir();
|
|
|
|
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
/**
|
|
|
|
* Convert \p name to internal path and strip a trailing slash, since it
|
|
|
|
* comes from user input (commandline or environment).
|
|
|
|
* \p name is encoded in utf8.
|
|
|
|
*/
|
|
|
|
string const fix_dir_name(string const & name)
|
|
|
|
{
|
|
|
|
return rtrim(os::internal_path(name), "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-25 23:25:00 +00:00
|
|
|
FileName buildSupportDir(string const & binary_dir,
|
2005-01-31 19:57:03 +00:00
|
|
|
exe_build_dir_to_top_build_dir top_build_dir_location)
|
|
|
|
{
|
|
|
|
string indirection;
|
|
|
|
switch (top_build_dir_location) {
|
|
|
|
case top_build_dir_is_one_level_up:
|
|
|
|
indirection = "../lib";
|
|
|
|
break;
|
|
|
|
case top_build_dir_is_two_levels_up:
|
|
|
|
indirection = "../../lib";
|
|
|
|
break;
|
|
|
|
}
|
2007-11-27 10:01:34 +00:00
|
|
|
return FileName(addPath(binary_dir, indirection));
|
2005-01-31 19:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-25 23:25:00 +00:00
|
|
|
void buildDirs(FileName const & abs_binary,
|
|
|
|
exe_build_dir_to_top_build_dir top_build_dir_location,
|
|
|
|
FileName & build_support_dir, FileName & system_support_dir)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
string const check_text = "Checking whether LyX is run in place...";
|
|
|
|
|
2006-04-27 16:44:43 +00:00
|
|
|
// We're looking for "Makefile" in a directory
|
2005-01-10 19:17:43 +00:00
|
|
|
// binary_dir/../lib
|
|
|
|
// We're also looking for "chkconfig.ltx" in a directory
|
2006-04-27 16:44:43 +00:00
|
|
|
// top_srcdir()/lib
|
2005-01-10 19:17:43 +00:00
|
|
|
// If both are found, then we're running LyX in-place.
|
|
|
|
|
|
|
|
// Note that the name of the lyx binary may be a symbolic link.
|
|
|
|
// If that is the case, then we follow the links too.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName binary = abs_binary;
|
2005-01-10 19:17:43 +00:00
|
|
|
while (true) {
|
|
|
|
// Try and find "lyxrc.defaults".
|
2010-04-21 01:19:09 +00:00
|
|
|
string binary_dir = onlyPath(binary.absFileName());
|
2007-11-25 23:25:00 +00:00
|
|
|
build_support_dir = buildSupportDir(binary_dir, top_build_dir_location);
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!fileSearch(build_support_dir.absFileName(), "Makefile").empty()) {
|
2005-01-10 19:17:43 +00:00
|
|
|
// Try and find "chkconfig.ltx".
|
2007-11-25 23:25:00 +00:00
|
|
|
system_support_dir =
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName(addPath(Package::top_srcdir().absFileName(), "lib"));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!fileSearch(system_support_dir.absFileName(), "chkconfig.ltx").empty()) {
|
2007-11-27 21:09:14 +00:00
|
|
|
LYXERR(Debug::INIT, check_text << " yes");
|
2007-11-25 23:25:00 +00:00
|
|
|
return;
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether binary is a symbolic link.
|
|
|
|
// If so, resolve it and repeat the exercise.
|
2007-11-25 21:21:03 +00:00
|
|
|
if (!binary.isSymLink())
|
2005-01-10 19:17:43 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName link;
|
|
|
|
if (readLink(binary, link)) {
|
2005-01-10 19:17:43 +00:00
|
|
|
binary = link;
|
|
|
|
} else {
|
|
|
|
// Unable to resolve the link.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-27 21:09:14 +00:00
|
|
|
LYXERR(Debug::INIT, check_text << " no");
|
2007-11-25 23:25:00 +00:00
|
|
|
system_support_dir = FileName();
|
|
|
|
build_support_dir = FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Specification of document_dir_ may be reset by LyXRC,
|
|
|
|
// but the default is fixed for a given OS.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_document_dir(FileName const & home_dir)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
#if defined (USE_WINDOWS_PACKAGING)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
2005-09-30 12:24:50 +00:00
|
|
|
os::GetFolderPath win32_folder_path;
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName(win32_folder_path(os::GetFolderPath::PERSONAL));
|
2005-01-10 19:17:43 +00:00
|
|
|
#else // Posix-like.
|
|
|
|
return home_dir;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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".
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_home_dir()
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
#if defined (USE_WINDOWS_PACKAGING)
|
2005-02-15 13:45:41 +00:00
|
|
|
string const home_dir = getEnv("USERPROFILE");
|
2005-01-10 19:17:43 +00:00
|
|
|
#else // Posix-like.
|
2005-02-15 13:45:41 +00:00
|
|
|
string const home_dir = getEnv("HOME");
|
2005-01-10 19:17:43 +00:00
|
|
|
#endif
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName(fix_dir_name(home_dir));
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Several sources are probed to ascertain the locale directory.
|
|
|
|
// The only requirement is that the result is indeed a directory.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_locale_dir(FileName const & system_support_dir)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
// 1. Use the "LYX_LOCALEDIR" environment variable.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const path_env = extract_env_var_dir("LYX_LOCALEDIR");
|
2006-12-17 09:46:04 +00:00
|
|
|
if (!path_env.empty() && check_env_var_dir(path_env, "LYX_LOCALEDIR"))
|
|
|
|
return path_env;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// 2. Search for system_support_dir / <relative locale dir>
|
|
|
|
// The <relative locale dir> is OS-dependent. (On Unix, it will
|
|
|
|
// be "../locale/".)
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName path(addPath(system_support_dir.absFileName(),
|
2007-11-27 10:01:34 +00:00
|
|
|
relative_locale_dir()));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-11-25 21:21:03 +00:00
|
|
|
if (path.exists() && path.isDirectory())
|
2007-04-06 13:09:54 +00:00
|
|
|
return path;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// 3. Fall back to the hard-coded LOCALEDIR.
|
2007-04-06 13:09:54 +00:00
|
|
|
path = hardcoded_localedir();
|
2007-11-25 21:21:03 +00:00
|
|
|
if (path.exists() && path.isDirectory())
|
2007-04-06 13:09:54 +00:00
|
|
|
return path;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const abs_path_from_command_line(string const & command_line)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
if (command_line.empty())
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-12-17 15:15:37 +00:00
|
|
|
string const str_path = fix_dir_name(command_line);
|
2009-05-02 17:12:31 +00:00
|
|
|
return makeAbsPath(str_path);
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Does the grunt work for abs_path_from_binary_name()
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_binary_path(string const & exe)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
2005-04-22 20:32:57 +00:00
|
|
|
#if defined (USE_WINDOWS_PACKAGING)
|
|
|
|
// The executable may have been invoked either with or
|
|
|
|
// without the .exe extension.
|
|
|
|
// Ensure that it is present.
|
|
|
|
string const as_internal_path = os::internal_path(exe);
|
|
|
|
string const exe_path = suffixIs(as_internal_path, ".exe") ?
|
|
|
|
as_internal_path : as_internal_path + ".exe";
|
|
|
|
#else
|
2005-01-10 19:17:43 +00:00
|
|
|
string const exe_path = os::internal_path(exe);
|
2005-04-22 20:32:57 +00:00
|
|
|
#endif
|
2009-05-02 17:12:31 +00:00
|
|
|
if (FileName::isAbsolute(exe_path))
|
|
|
|
return FileName(exe_path);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// Two possibilities present themselves.
|
|
|
|
// 1. The binary is relative to the CWD.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const abs_exe_path = makeAbsPath(exe_path);
|
2007-10-18 19:29:32 +00:00
|
|
|
if (abs_exe_path.exists())
|
2005-01-10 19:17:43 +00:00
|
|
|
return abs_exe_path;
|
|
|
|
|
|
|
|
// 2. exe must be the name of the binary only and it
|
|
|
|
// can be found on the PATH.
|
2010-04-21 01:19:28 +00:00
|
|
|
string const exe_name = onlyFileName(exe_path);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (exe_name != exe_path)
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
vector<string> const path = getEnvPath("PATH");
|
|
|
|
vector<string>::const_iterator it = path.begin();
|
|
|
|
vector<string>::const_iterator const end = path.end();
|
2005-01-10 19:17:43 +00:00
|
|
|
for (; it != end; ++it) {
|
2005-01-17 11:50:16 +00:00
|
|
|
// This will do nothing if *it is already absolute.
|
2010-04-21 01:19:09 +00:00
|
|
|
string const exe_dir = makeAbsPath(*it).absFileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const exe_path(addName(exe_dir, exe_name));
|
2007-10-18 19:29:32 +00:00
|
|
|
if (exe_path.exists())
|
2005-01-10 19:17:43 +00:00
|
|
|
return exe_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Didn't find anything.
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Extracts the absolute path to the binary name received as argv[0].
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const abs_path_from_binary_name(string const & exe)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const abs_binary = get_binary_path(exe);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (abs_binary.empty()) {
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2007-01-24 15:49:20 +00:00
|
|
|
throw ExceptionMessage(ErrorException,
|
|
|
|
_("LyX binary not found"),
|
|
|
|
bformat(_("Unable to determine the path to the LyX binary from the command line %1$s"),
|
2007-04-06 11:20:09 +00:00
|
|
|
from_utf8(exe)));
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
return abs_binary;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// A plethora of directories is searched to ascertain the system
|
|
|
|
// lyxdir which is defined as the first directory to contain
|
|
|
|
// "chkconfig.ltx".
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const
|
|
|
|
get_system_support_dir(FileName const & abs_binary,
|
2005-01-10 19:17:43 +00:00
|
|
|
string const & command_line_system_support_dir)
|
|
|
|
{
|
|
|
|
string const chkconfig_ltx = "chkconfig.ltx";
|
|
|
|
|
|
|
|
// searched_dirs is used for diagnostic purposes only in the case
|
|
|
|
// that "chkconfig.ltx" is not found.
|
2007-12-12 19:28:07 +00:00
|
|
|
list<FileName> searched_dirs;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// 1. Use the -sysdir command line parameter.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName path = abs_path_from_command_line(command_line_system_support_dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (!path.empty()) {
|
|
|
|
searched_dirs.push_back(path);
|
2010-04-21 01:19:09 +00:00
|
|
|
if (check_command_line_dir(path.absFileName(), chkconfig_ltx, "-sysdir"))
|
2005-01-10 19:17:43 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:38 +00:00
|
|
|
// 2. Use the "LYX_DIR_${major}${minor}x" environment variable.
|
|
|
|
path = extract_env_var_dir(LYX_DIR_VER);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (!path.empty()) {
|
|
|
|
searched_dirs.push_back(path);
|
2008-07-26 10:45:38 +00:00
|
|
|
if (check_env_var_dir(path, chkconfig_ltx, LYX_DIR_VER))
|
2005-01-10 19:17:43 +00:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. Search relative to the lyx binary.
|
|
|
|
// We're looking for "chkconfig.ltx" in a directory
|
|
|
|
// OnlyPath(abs_binary) / <relative dir> / PACKAGE /
|
|
|
|
// PACKAGE is hardcoded in config.h. Eg "lyx" or "lyx-1.3.6cvs".
|
|
|
|
// <relative dir> is OS-dependent; on Unix, it will be "../share/".
|
|
|
|
string const relative_lyxdir = relative_system_support_dir();
|
|
|
|
|
|
|
|
// One subtlety to be aware of. The name of the lyx binary may be
|
|
|
|
// a symbolic link. If that is the case, then we follow the links too.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName binary = abs_binary;
|
2005-01-10 19:17:43 +00:00
|
|
|
while (true) {
|
|
|
|
// Try and find "chkconfig.ltx".
|
2010-04-21 01:19:09 +00:00
|
|
|
string const binary_dir = onlyPath(binary.absFileName());
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-11-27 10:01:34 +00:00
|
|
|
FileName const lyxdir(addPath(binary_dir, relative_lyxdir));
|
2005-01-10 19:17:43 +00:00
|
|
|
searched_dirs.push_back(lyxdir);
|
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!fileSearch(lyxdir.absFileName(), chkconfig_ltx).empty()) {
|
2005-01-10 19:17:43 +00:00
|
|
|
// Success! "chkconfig.ltx" has been found.
|
|
|
|
return lyxdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether binary is a symbolic link.
|
|
|
|
// If so, resolve it and repeat the exercise.
|
2007-11-25 21:21:03 +00:00
|
|
|
if (!binary.isSymLink())
|
2005-01-10 19:17:43 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName link;
|
|
|
|
if (readLink(binary, link)) {
|
2005-01-10 19:17:43 +00:00
|
|
|
binary = link;
|
|
|
|
} else {
|
|
|
|
// Unable to resolve the link.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4. Repeat the exercise on the directory itself.
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName binary_dir(onlyPath(abs_binary.absFileName()));
|
2005-01-10 19:17:43 +00:00
|
|
|
while (true) {
|
|
|
|
// This time test whether the directory is a symbolic link
|
|
|
|
// *before* looking for "chkconfig.ltx".
|
|
|
|
// (We've looked relative to the original already.)
|
2007-11-25 21:21:03 +00:00
|
|
|
if (!binary.isSymLink())
|
2005-01-10 19:17:43 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName link;
|
|
|
|
if (readLink(binary_dir, link)) {
|
2005-01-10 19:17:43 +00:00
|
|
|
binary_dir = link;
|
|
|
|
} else {
|
|
|
|
// Unable to resolve the link.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try and find "chkconfig.ltx".
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const lyxdir(addPath(binary_dir.absFileName(),
|
2007-11-27 10:01:34 +00:00
|
|
|
relative_lyxdir));
|
2005-01-10 19:17:43 +00:00
|
|
|
searched_dirs.push_back(lyxdir);
|
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!fileSearch(lyxdir.absFileName(), chkconfig_ltx).empty()) {
|
2005-01-10 19:17:43 +00:00
|
|
|
// Success! "chkconfig.ltx" has been found.
|
|
|
|
return lyxdir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 5. In desparation, try the hard-coded system support dir.
|
|
|
|
path = hardcoded_system_support_dir();
|
2010-04-21 01:19:09 +00:00
|
|
|
if (!fileSearch(path.absFileName(), chkconfig_ltx).empty())
|
2005-01-10 19:17:43 +00:00
|
|
|
return path;
|
|
|
|
|
|
|
|
// Everything has failed :-(
|
|
|
|
// So inform the user and exit.
|
|
|
|
string searched_dirs_str;
|
2007-12-12 19:28:07 +00:00
|
|
|
typedef list<FileName>::const_iterator iterator;
|
2005-01-10 19:17:43 +00:00
|
|
|
iterator const begin = searched_dirs.begin();
|
|
|
|
iterator const end = searched_dirs.end();
|
|
|
|
for (iterator it = begin; it != end; ++it) {
|
|
|
|
if (it != begin)
|
|
|
|
searched_dirs_str += "\n\t";
|
2010-04-21 01:19:09 +00:00
|
|
|
searched_dirs_str += it->absFileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2007-01-24 15:49:20 +00:00
|
|
|
throw ExceptionMessage(ErrorException, _("No system directory"),
|
|
|
|
bformat(_("Unable to determine the system directory "
|
2008-07-26 10:45:38 +00:00
|
|
|
"having searched\n"
|
|
|
|
"\t%1$s\n"
|
|
|
|
"Use the '-sysdir' command line parameter or "
|
2008-07-29 15:25:26 +00:00
|
|
|
"set the environment variable\n%2$s "
|
2008-07-26 10:45:38 +00:00
|
|
|
"to the LyX system directory containing the "
|
|
|
|
"file `chkconfig.ltx'."),
|
2008-07-29 15:25:26 +00:00
|
|
|
from_utf8(searched_dirs_str), from_ascii(LYX_DIR_VER)));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// Keep the compiler happy.
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the absolute path to the user lyxdir, together with a flag
|
|
|
|
// indicating whether this directory was specified explicitly (as -userdir
|
|
|
|
// or through an environment variable) or whether it was deduced.
|
2007-11-25 23:25:00 +00:00
|
|
|
bool userSupportDir(FileName const & default_user_support_dir,
|
|
|
|
string const & command_line_user_support_dir, FileName & result)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
// 1. Use the -userdir command line parameter.
|
2007-11-25 23:25:00 +00:00
|
|
|
result = abs_path_from_command_line(command_line_user_support_dir);
|
|
|
|
if (!result.empty())
|
|
|
|
return true;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2008-07-26 10:45:38 +00:00
|
|
|
// 2. Use the LYX_USERDIR_${major}${minor}x environment variable.
|
|
|
|
result = extract_env_var_dir(LYX_USERDIR_VER);
|
2007-11-25 23:25:00 +00:00
|
|
|
if (!result.empty())
|
|
|
|
return true;
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
// 3. Use the OS-dependent default_user_support_dir
|
2007-11-25 23:25:00 +00:00
|
|
|
result = default_user_support_dir;
|
|
|
|
return false;
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-10 21:54:38 +00:00
|
|
|
// $HOME/.lyx on POSIX but on Win32 it will be something like
|
|
|
|
// "C:/Documents and Settings/USERNAME/Application Data/LyX"
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const get_default_user_support_dir(FileName const & home_dir)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
#if defined (USE_WINDOWS_PACKAGING)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
|
|
|
|
2005-09-30 12:24:50 +00:00
|
|
|
os::GetFolderPath win32_folder_path;
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName(addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
#elif defined (USE_MACOSX_PACKAGING)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
|
|
|
|
|
|
|
FSRef fsref;
|
|
|
|
OSErr const error_code =
|
|
|
|
FSFindFolder(kUserDomain, kApplicationSupportFolderType,
|
|
|
|
kDontCreateFolder, &fsref);
|
|
|
|
if (error_code != 0)
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
// FSRefMakePath returns the result in utf8
|
2005-01-12 23:43:38 +00:00
|
|
|
char store[PATH_MAX + 1];
|
2005-01-10 19:17:43 +00:00
|
|
|
OSStatus const status_code =
|
|
|
|
FSRefMakePath(&fsref,
|
2005-01-12 23:43:38 +00:00
|
|
|
reinterpret_cast<UInt8*>(store), PATH_MAX);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (status_code != 0)
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
return FileName(addPath(reinterpret_cast<char const *>(store), PACKAGE));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
#else // USE_POSIX_PACKAGING
|
2010-04-21 01:19:09 +00:00
|
|
|
return FileName(addPath(home_dir.absFileName(), string(".") + PACKAGE));
|
2005-01-10 19:17:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check that directory @c dir contains @c file.
|
2008-04-25 08:34:09 +00:00
|
|
|
// Else emit an error message about an invalid @c command_line_switch.
|
2005-01-10 19:17:43 +00:00
|
|
|
bool check_command_line_dir(string const & dir,
|
|
|
|
string const & file,
|
|
|
|
string const & command_line_switch)
|
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const abs_path = fileSearch(dir, file);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (abs_path.empty()) {
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2008-04-25 08:34:09 +00:00
|
|
|
throw ExceptionMessage(ErrorException, _("File not found"), bformat(
|
2007-01-24 15:49:20 +00:00
|
|
|
_("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
|
2007-04-06 11:20:09 +00:00
|
|
|
from_utf8(command_line_switch), from_utf8(dir),
|
|
|
|
from_utf8(file)));
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return !abs_path.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The environment variable @c env_var expands to a (single) file path.
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const extract_env_var_dir(string const & env_var)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
2007-04-06 13:09:54 +00:00
|
|
|
string const dir = fix_dir_name(getEnv(env_var));
|
|
|
|
return dir.empty() ? FileName() : makeAbsPath(dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check that directory @c dir contains @c file.
|
|
|
|
// Else emit a warning about an invalid @c env_var.
|
2007-04-06 13:09:54 +00:00
|
|
|
bool check_env_var_dir(FileName const & dir,
|
2005-01-10 19:17:43 +00:00
|
|
|
string const & file,
|
|
|
|
string const & env_var)
|
|
|
|
{
|
2010-04-21 01:19:09 +00:00
|
|
|
FileName const abs_path = fileSearch(dir.absFileName(), file);
|
2005-01-10 19:17:43 +00:00
|
|
|
if (abs_path.empty()) {
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2007-01-24 15:49:20 +00:00
|
|
|
throw ExceptionMessage(WarningException, _("File not found"), bformat(
|
|
|
|
_("Invalid %1$s environment variable.\n"
|
|
|
|
"Directory %2$s does not contain %3$s."),
|
2010-04-21 01:19:09 +00:00
|
|
|
from_utf8(env_var), from_utf8(dir.absFileName()),
|
2007-04-06 11:20:09 +00:00
|
|
|
from_utf8(file)));
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return !abs_path.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check that directory @c dir is indeed a directory.
|
|
|
|
// Else emit a warning about an invalid @c env_var.
|
2007-04-06 13:09:54 +00:00
|
|
|
bool check_env_var_dir(FileName const & dir,
|
2005-01-10 19:17:43 +00:00
|
|
|
string const & env_var)
|
|
|
|
{
|
2007-10-18 21:10:35 +00:00
|
|
|
bool const success = dir.exists() && dir.isDirectory();
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
if (!success) {
|
2005-01-12 12:25:30 +00:00
|
|
|
// Put this string on a single line so that the gettext
|
|
|
|
// search mechanism in po/Makefile.in.in will register
|
2007-04-28 15:05:08 +00:00
|
|
|
// Package.cpp.in as a file containing strings that need
|
2005-01-12 12:25:30 +00:00
|
|
|
// translation.
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2006-09-11 08:54:10 +00:00
|
|
|
docstring const fmt =
|
|
|
|
_("Invalid %1$s environment variable.\n%2$s is not a directory.");
|
2005-01-31 19:31:11 +00:00
|
|
|
|
2007-01-24 15:49:20 +00:00
|
|
|
throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
|
2010-04-21 01:19:09 +00:00
|
|
|
fmt, from_utf8(env_var), from_utf8(dir.absFileName())));
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The locale directory relative to the LyX system directory.
|
|
|
|
string const relative_locale_dir()
|
|
|
|
{
|
2006-04-27 12:57:30 +00:00
|
|
|
#if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
|
|
|
|
return "locale/";
|
|
|
|
#else
|
2005-01-10 19:17:43 +00:00
|
|
|
return "../locale/";
|
2006-04-27 12:57:30 +00:00
|
|
|
#endif
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The system lyxdir is relative to the directory containing the LyX binary.
|
|
|
|
string const relative_system_support_dir()
|
|
|
|
{
|
|
|
|
string result;
|
|
|
|
|
|
|
|
#if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
|
2006-02-12 20:29:52 +00:00
|
|
|
result = "../Resources/";
|
2005-01-10 19:17:43 +00:00
|
|
|
#else // Posix-like.
|
2006-04-08 22:31:11 +00:00
|
|
|
result = addPath("../share/", PACKAGE);
|
2005-01-10 19:17:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|