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"
|
2010-08-07 11:42:27 +00:00
|
|
|
#include "support/lassert.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "support/os.h"
|
2014-12-29 22:46:25 +00:00
|
|
|
#include "support/PathChanger.h"
|
|
|
|
#include "support/Systemcall.h"
|
2005-01-10 19:17:43 +00:00
|
|
|
|
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
|
|
|
|
2014-12-29 22:46:25 +00:00
|
|
|
#include <iostream>
|
2005-01-10 19:17:43 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#if !defined (USE_WINDOWS_PACKAGING) && \
|
|
|
|
!defined (USE_MACOSX_PACKAGING) && \
|
2015-06-05 10:40:35 +00:00
|
|
|
!defined (USE_HAIKU_PACKAGING) && \
|
2005-01-10 19:17:43 +00:00
|
|
|
!defined (USE_POSIX_PACKAGING)
|
2015-06-05 10:40:35 +00:00
|
|
|
#error USE_FOO_PACKAGING must be defined for FOO = WINDOWS, MACOSX, HAIKU or POSIX.
|
2005-01-10 19:17:43 +00:00
|
|
|
#endif
|
|
|
|
|
2005-10-02 21:49:52 +00:00
|
|
|
#if defined (USE_MACOSX_PACKAGING)
|
2012-09-23 13:27:36 +00:00
|
|
|
# include "support/qstring_helpers.h"
|
|
|
|
# include <QDir>
|
|
|
|
# include <QDesktopServices>
|
2005-01-10 19:17:43 +00:00
|
|
|
#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;
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
void init_package(string const & command_line_arg0,
|
|
|
|
string const & command_line_system_support_dir,
|
2011-05-14 12:26:11 +00:00
|
|
|
string const & command_line_user_support_dir)
|
2005-01-10 19:17:43 +00:00
|
|
|
{
|
|
|
|
package_ = Package(command_line_arg0,
|
|
|
|
command_line_system_support_dir,
|
2011-05-14 12:26:11 +00:00
|
|
|
command_line_user_support_dir);
|
2005-01-10 19:17:43 +00:00
|
|
|
initialised_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Package const & package()
|
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LAPPERR(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
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
|
|
|
|
bool inBuildDir(FileName const & abs_binary, FileName &, FileName &);
|
|
|
|
|
2011-05-14 13:03:48 +00:00
|
|
|
FileName findLyxBinary(FileName const & abs_binary);
|
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_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();
|
|
|
|
|
2011-04-13 19:11:55 +00:00
|
|
|
string const fix_dir_name(string const & name);
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
Package::Package(string const & command_line_arg0,
|
|
|
|
string const & command_line_system_support_dir,
|
2011-05-14 12:26:11 +00:00
|
|
|
string const & command_line_user_support_dir)
|
2005-01-10 19:17:43 +00:00
|
|
|
: explicit_user_support_dir_(false)
|
|
|
|
{
|
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_;
|
2011-04-13 19:11:55 +00:00
|
|
|
document_dir_ = get_document_dir(get_home_dir());
|
2005-01-10 19:17:43 +00:00
|
|
|
|
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
|
|
|
|
2011-01-25 21:10:49 +00:00
|
|
|
// the LyX package directory
|
|
|
|
lyx_dir_ = FileName(addPath(binary_dir_.absFileName(), "../"));
|
|
|
|
lyx_dir_ = FileName(lyx_dir_.realPath());
|
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
// Is LyX being run in-place from the build tree?
|
2013-05-14 14:35:34 +00:00
|
|
|
in_build_dir_ = inBuildDir(abs_binary, build_support_dir_, system_support_dir_);
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2013-05-14 14:35:34 +00:00
|
|
|
if (!in_build_dir_) {
|
2005-01-10 19:17:43 +00:00
|
|
|
system_support_dir_ =
|
|
|
|
get_system_support_dir(abs_binary,
|
|
|
|
command_line_system_support_dir);
|
2013-03-31 13:33:26 +00:00
|
|
|
}
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
// Find the LyX executable
|
2011-05-14 13:03:48 +00:00
|
|
|
lyx_binary_ = findLyxBinary(abs_binary);
|
2010-12-30 20:29:33 +00:00
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
locale_dir_ = get_locale_dir(system_support_dir_);
|
|
|
|
|
2007-04-06 13:09:54 +00:00
|
|
|
FileName const default_user_support_dir =
|
2011-04-13 19:11:55 +00:00
|
|
|
get_default_user_support_dir(get_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
|
|
|
|
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'
|
2011-04-13 19:11:55 +00:00
|
|
|
<< "\thome_dir " << get_home_dir().absFileName() << '\n'
|
2007-11-27 21:09:14 +00:00
|
|
|
<< "</package>\n");
|
2005-01-10 19:17:43 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 22:46:25 +00:00
|
|
|
|
|
|
|
int Package::reconfigureUserLyXDir(string const & option) const
|
2014-03-14 10:48:40 +00:00
|
|
|
{
|
|
|
|
if (configure_command_.empty()) {
|
|
|
|
FileName const configure_script(addName(system_support().absFileName(), "configure.py"));
|
2014-03-21 17:38:09 +00:00
|
|
|
configure_command_ = os::python() + ' ' +
|
2014-03-14 10:48:40 +00:00
|
|
|
quoteName(configure_script.toFilesystemEncoding()) +
|
|
|
|
with_version_suffix() + " --binary-dir=" +
|
|
|
|
quoteName(FileName(binary_dir().absFileName()).toFilesystemEncoding());
|
|
|
|
}
|
2014-12-29 22:46:25 +00:00
|
|
|
|
|
|
|
lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
|
|
|
|
PathChanger p(user_support());
|
|
|
|
Systemcall one;
|
|
|
|
int const ret = one.startscript(Systemcall::Wait, configure_command_ + option);
|
|
|
|
lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string Package::getConfigureLockName() const
|
|
|
|
{
|
2015-07-20 23:05:04 +00:00
|
|
|
return addName(user_support().absFileName(), ".lyx_configure_lock");
|
2014-03-14 10:48:40 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-14 14:35:34 +00:00
|
|
|
|
|
|
|
FileName Package::messages_file(string const & c) const
|
|
|
|
{
|
2013-06-02 09:38:27 +00:00
|
|
|
if (in_build_dir_) {
|
2017-08-04 14:06:32 +00:00
|
|
|
FileName res = FileName(lyx_dir().absFileName() + "/po/" + c + ".gmo");
|
|
|
|
if (!res.isReadableFile())
|
2017-08-04 14:16:08 +00:00
|
|
|
res = FileName(lyx_dir().absFileName() + "../po/" + c + ".gmo");
|
2013-06-02 13:11:37 +00:00
|
|
|
if (!res.isReadableFile())
|
|
|
|
res = FileName(top_srcdir().absFileName() + "/po/" + c + ".gmo");
|
2013-06-02 09:38:27 +00:00
|
|
|
return res;
|
2013-06-02 13:11:37 +00:00
|
|
|
} else
|
2013-05-14 14:35:34 +00:00
|
|
|
return FileName(locale_dir_.absFileName() + "/" + c
|
|
|
|
+ "/LC_MESSAGES/" PACKAGE ".mo");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-13 19:11:55 +00:00
|
|
|
// 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"));
|
2012-09-23 13:27:36 +00:00
|
|
|
#elif defined (USE_MACOSX_PACKAGING)
|
|
|
|
static FileName const home_dir(fromqstr(QDir::homePath()));
|
2011-04-13 19:11:55 +00:00
|
|
|
#else // Posix-like.
|
|
|
|
static FileName const home_dir(getEnv("HOME"));
|
|
|
|
#endif
|
|
|
|
return home_dir;
|
|
|
|
}
|
|
|
|
|
2008-06-09 13:05:24 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
|
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), "/");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
|
|
|
|
bool isBuildDir(FileName const & abs_binary, string const & dir_location,
|
|
|
|
FileName & build_support_dir)
|
2005-01-31 19:57:03 +00:00
|
|
|
{
|
2011-05-14 12:26:11 +00:00
|
|
|
string search_dir = onlyPath(abs_binary.absFileName()) + dir_location;
|
|
|
|
|
|
|
|
// Makefile by automake
|
|
|
|
build_support_dir = FileName(addPath(search_dir, "lib"));
|
|
|
|
if (!fileSearch(build_support_dir.absFileName(), "Makefile").empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// cmake file, no Makefile in lib
|
2017-08-02 16:44:32 +00:00
|
|
|
FileName build_src_dir = FileName(addPath(search_dir, "src"));
|
|
|
|
if (!fileSearch(build_src_dir.absFileName(), "cmake_install.cmake").empty()) {
|
2011-05-14 12:26:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2005-01-31 19:57:03 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
bool inBuildDir(FileName const & abs_binary,
|
2007-11-25 23:25:00 +00:00
|
|
|
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.
|
2011-05-14 12:26:11 +00:00
|
|
|
FileName binary = abs_binary;
|
2005-01-10 19:17:43 +00:00
|
|
|
while (true) {
|
|
|
|
// Try and find "lyxrc.defaults".
|
2011-05-14 12:26:11 +00:00
|
|
|
if( isBuildDir(binary, "../", build_support_dir) ||
|
|
|
|
isBuildDir(binary, "../../", build_support_dir))
|
|
|
|
{
|
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");
|
2011-05-14 12:26:11 +00:00
|
|
|
return true;
|
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();
|
2011-05-14 12:26:11 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool doesFileExist(FileName & result, string const & search_dir, string const & name)
|
|
|
|
{
|
|
|
|
result = fileSearch(search_dir, name);
|
|
|
|
if (!result.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool lyxBinaryPath(FileName & lyx_binary, string const & search_dir, string const & ext)
|
|
|
|
{
|
|
|
|
lyx_binary = FileName();
|
2017-07-03 17:53:14 +00:00
|
|
|
if(false) {
|
2011-05-14 12:26:11 +00:00
|
|
|
} else if (doesFileExist(lyx_binary, search_dir, "lyx" + ext)) {
|
|
|
|
} else if (doesFileExist(lyx_binary, search_dir, "LyX" + ext)) {
|
|
|
|
} else if (doesFileExist(lyx_binary, search_dir, "lyx" + string(PROGRAM_SUFFIX) + ext)) {
|
|
|
|
} else if (doesFileExist(lyx_binary, search_dir, "LyX" + string(PROGRAM_SUFFIX) + ext)){
|
|
|
|
}
|
|
|
|
return !lyx_binary.empty() ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-14 13:03:48 +00:00
|
|
|
FileName findLyxBinary(FileName const & abs_binary)
|
2011-05-14 12:26:11 +00:00
|
|
|
{
|
|
|
|
string ext;
|
2013-01-04 10:05:12 +00:00
|
|
|
string checkname = abs_binary.toFilesystemEncoding();
|
|
|
|
int check_len = checkname.length();
|
|
|
|
int prgsuffixlen = string(PROGRAM_SUFFIX).length();
|
|
|
|
if ((prgsuffixlen > 0) && (check_len > prgsuffixlen) &&
|
|
|
|
(checkname.substr(check_len-prgsuffixlen) == string(PROGRAM_SUFFIX))) {
|
|
|
|
ext = "";
|
|
|
|
}
|
|
|
|
else if (!abs_binary.extension().empty()) {
|
2011-05-14 12:26:11 +00:00
|
|
|
ext = "." + abs_binary.extension();
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
string binary_dir = onlyPath(abs_binary.absFileName());
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
FileName lyx_binary;
|
|
|
|
if (lyxBinaryPath(lyx_binary, binary_dir, ext))
|
|
|
|
return lyx_binary;
|
|
|
|
|
|
|
|
string search_dir = onlyPath(FileName(addPath(binary_dir, "/../")).absFileName());
|
|
|
|
if (lyxBinaryPath(lyx_binary, search_dir, ext))
|
|
|
|
return lyx_binary;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2011-05-14 12:26:11 +00:00
|
|
|
return 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));
|
2013-02-03 11:23:31 +00:00
|
|
|
#elif defined (USE_MACOSX_PACKAGING) && (QT_VERSION >= 0x050000)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
|
|
|
return FileName(fromqstr(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)));
|
2012-09-23 13:27:36 +00:00
|
|
|
#elif defined (USE_MACOSX_PACKAGING)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
|
|
|
return FileName(fromqstr(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)));
|
2005-01-10 19:17:43 +00:00
|
|
|
#else // Posix-like.
|
|
|
|
return home_dir;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2013-02-03 11:23:31 +00:00
|
|
|
#elif defined (USE_MACOSX_PACKAGING) && (QT_VERSION >= 0x050000)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
2016-01-24 14:19:54 +00:00
|
|
|
return FileName(addPath(fromqstr(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)), PACKAGE));
|
2013-02-03 11:23:31 +00:00
|
|
|
|
2005-01-10 19:17:43 +00:00
|
|
|
#elif defined (USE_MACOSX_PACKAGING)
|
|
|
|
(void)home_dir; // Silence warning about unused variable.
|
2012-09-23 13:27:36 +00:00
|
|
|
return FileName(addPath(fromqstr(QDesktopServices::storageLocation(QDesktopServices::DataLocation)), PACKAGE));
|
2005-01-10 19:17:43 +00:00
|
|
|
|
2015-06-05 10:40:35 +00:00
|
|
|
#elif defined (USE_HAIKU_PACKAGING)
|
|
|
|
return FileName(addPath(home_dir.absFileName(), string("/config/settings/") + 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;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2005-01-10 19:17:43 +00:00
|
|
|
|
|
|
|
} // namespace support
|
|
|
|
} // namespace lyx
|