]> git.lyx.org Git - lyx.git/blobdiff - src/support/Package.cpp
Fix samba related crashes
[lyx.git] / src / support / Package.cpp
index 6939dc77c7aae9c592c9d2c2b9f98ab556cc9410..a2e8b17ebfcb72ccbc9bdf350378c0f486749f49 100644 (file)
@@ -18,6 +18,7 @@
 #include "support/ExceptionMessage.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/os.h"
 
@@ -56,10 +57,6 @@ void init_package(string const & command_line_arg0,
                  string const & command_line_user_support_dir,
                  exe_build_dir_to_top_build_dir top_build_dir_location)
 {
-       // Can do so only once.
-       if (initialised_)
-               return;
-
        package_ = Package(command_line_arg0,
                           command_line_system_support_dir,
                           command_line_user_support_dir,
@@ -70,10 +67,7 @@ void init_package(string const & command_line_arg0,
 
 Package const & package()
 {
-       // Commented out because package().locale_dir() can be called
-       // from the message translation code in Messages.cpp before
-       // init_package() is called. Lars is on the case...
-       // LASSERT(initialised_, /**/);
+       LASSERT(initialised_, /**/);
        return package_;
 }
 
@@ -122,6 +116,10 @@ Package::Package(string const & command_line_arg0,
        FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
        binary_dir_ = FileName(onlyPath(abs_binary.absFileName()));
 
+       // the LyX package directory
+       lyx_dir_ = FileName(addPath(binary_dir_.absFileName(), "../"));
+       lyx_dir_ = FileName(lyx_dir_.realPath());
+
        // Is LyX being run in-place from the build tree?
        buildDirs(abs_binary, top_build_dir_location,
                build_support_dir_, system_support_dir_);
@@ -131,6 +129,24 @@ Package::Package(string const & command_line_arg0,
                        get_system_support_dir(abs_binary,
                                               command_line_system_support_dir);
 
+       // The LyX executable is one level above binary_dir_ if we are running
+       // tex2lyx in place. Otherwise it is in binary_dir_.
+       string abs_lyx_dir;
+       if (build_support_dir_.empty() ||
+           top_build_dir_location == top_build_dir_is_one_level_up)
+               abs_lyx_dir = binary_dir_.absFileName();
+       else {
+               FileName fn(addPath(binary_dir_.absFileName(), "../"));
+               abs_lyx_dir = fn.realPath();
+       }
+       // The LyX executable may have a package suffix if we are not running
+       // in place.
+       if (build_support_dir_.empty())
+               lyx_binary_ = FileName(addName(abs_lyx_dir,
+                                              "lyx" + string(PROGRAM_SUFFIX)));
+       else
+               lyx_binary_ = FileName(addName(abs_lyx_dir, "lyx"));
+
        locale_dir_ = get_locale_dir(system_support_dir_);
 
        FileName const default_user_support_dir =
@@ -394,7 +410,7 @@ FileName const get_binary_path(string const & exe)
 
        // 2. exe must be the name of the binary only and it
        // can be found on the PATH.
-       string const exe_name = onlyFilename(exe_path);
+       string const exe_name = onlyFileName(exe_path);
        if (exe_name != exe_path)
                return FileName();