]> git.lyx.org Git - lyx.git/blob - src/support/Package.cpp.in
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / support / Package.cpp.in
1 // -*- C++ -*-
2 /**
3  * \file package.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * Warning! This file is autogenerated from Package.cpp.in.
12  * All changes to this file will be lost.
13  */
14
15 #include <config.h>
16
17 #include "support/Package.h"
18
19 #include "debug.h"
20 #include "gettext.h"
21
22 #include "support/environment.h"
23 #include "support/filetools.h"
24 #include "support/lstrings.h"
25 #include "support/ExceptionMessage.h"
26 #include "support/os.h"
27
28 #if defined (USE_WINDOWS_PACKAGING)
29 # include "support/os_win32.h"
30 #endif
31
32 #include <boost/filesystem/operations.hpp>
33 #include <boost/tuple/tuple.hpp>
34
35 #include <list>
36 #include <utility>
37
38 #if !defined (USE_WINDOWS_PACKAGING) && \
39     !defined (USE_MACOSX_PACKAGING) && \
40     !defined (USE_POSIX_PACKAGING)
41 #error USE_FOO_PACKAGING must be defined for FOO = WINDOWS, MACOSX or POSIX.
42 #endif
43
44 #if defined (USE_MACOSX_PACKAGING)
45 # include <CoreServices/CoreServices.h> // FSFindFolder, FSRefMakePath
46 #endif
47
48 using std::string;
49
50 namespace fs = boost::filesystem;
51
52 namespace lyx {
53 namespace support {
54
55 namespace {
56
57 Package package_;
58 bool initialised_ = false;
59
60 } // namespace anon
61
62
63 void init_package(string const & command_line_arg0,
64                   string const & command_line_system_support_dir,
65                   string const & command_line_user_support_dir,
66                   exe_build_dir_to_top_build_dir top_build_dir_location)
67 {
68         // Can do so only once.
69         if (initialised_)
70                 return;
71
72         package_ = Package(command_line_arg0,
73                            command_line_system_support_dir,
74                            command_line_user_support_dir,
75                            top_build_dir_location);
76         initialised_ = true;
77 }
78
79
80 Package const & package()
81 {
82         // Commented out because package().locale_dir() can be called
83         // from the message translation code in Messages.cpp before
84         // init_package() is called. Lars is on the case...
85         // BOOST_ASSERT(initialised_);
86         return package_;
87 }
88
89
90 namespace {
91
92 FileName const abs_path_from_binary_name(string const & exe);
93
94 std::pair<FileName, FileName> const
95 get_build_dirs(FileName const & abs_binary,
96                exe_build_dir_to_top_build_dir top_build_dir_location);
97
98 FileName const get_document_dir(FileName const & home_dir);
99
100 FileName const get_home_dir();
101
102 FileName const get_locale_dir(FileName const & system_support_dir);
103
104 FileName const get_system_support_dir(FileName const & abs_binary,
105                                     string const & command_line_system_support_dir);
106
107 FileName const get_temp_dir();
108
109 FileName const get_default_user_support_dir(FileName const & home_dir);
110
111 std::pair<FileName, bool> const
112 get_user_support_dir(FileName const & default_user_support_dir,
113                      string const & command_line_user_support_dir);
114
115
116 string const & with_version_suffix();
117
118 } // namespace anon
119
120
121 Package::Package(string const & command_line_arg0,
122                  string const & command_line_system_support_dir,
123                  string const & command_line_user_support_dir,
124                  exe_build_dir_to_top_build_dir top_build_dir_location)
125         : explicit_user_support_dir_(false)
126 {
127         home_dir_ = get_home_dir();
128         system_temp_dir_ = get_temp_dir();
129         temp_dir_ = system_temp_dir_;
130         document_dir_ = get_document_dir(home_dir_);
131
132         FileName const abs_binary = abs_path_from_binary_name(command_line_arg0);
133         string const bdir = onlyPath(abs_binary.absFilename());
134         // We may be using libtools
135         if (suffixIs(bdir, ".libs/"))
136                 binary_dir_ = FileName(addPath(bdir, "../"));
137         else
138                 binary_dir_ = FileName(bdir);
139
140         // Is LyX being run in-place from the build tree?
141         boost::tie(build_support_dir_, system_support_dir_) =
142                 get_build_dirs(abs_binary, top_build_dir_location);
143
144         if (build_support_dir_.empty())
145                 system_support_dir_ =
146                         get_system_support_dir(abs_binary,
147                                                command_line_system_support_dir);
148
149         locale_dir_ = get_locale_dir(system_support_dir_);
150
151         FileName const default_user_support_dir =
152                 get_default_user_support_dir(home_dir_);
153         boost::tie(user_support_dir_, explicit_user_support_dir_) =
154                 get_user_support_dir(default_user_support_dir,
155                                      command_line_user_support_dir);
156
157         FileName const configure_script(addName(system_support().absFilename(), "configure.py"));
158         configure_command_ = os::python() + ' ' +
159                         quoteName(configure_script.toFilesystemEncoding()) +
160                         with_version_suffix();
161
162         lyxerr[Debug::INIT]
163                 << "<package>\n"
164                 << "\tbinary_dir " << binary_dir().absFilename() << '\n'
165                 << "\tsystem_support " << system_support().absFilename() << '\n'
166                 << "\tbuild_support " << build_support().absFilename() << '\n'
167                 << "\tuser_support " << user_support().absFilename() << '\n'
168                 << "\tlocale_dir " << locale_dir().absFilename() << '\n'
169                 << "\tdocument_dir " << document_dir().absFilename() << '\n'
170                 << "\ttemp_dir " << temp_dir().absFilename() << '\n'
171                 << "\thome_dir " << home_dir().absFilename() << '\n'
172                 << "</package>\n" << std::endl;
173 }
174
175
176 namespace {
177
178 // These next functions contain the stuff that is substituted at
179 // configuration-time.
180 FileName const hardcoded_localedir()
181 {
182         // FIXME UNICODE
183         // The build system needs to make sure that this is in utf8 encoding.
184         return FileName("@LOCALEDIR@");
185 }
186
187
188 FileName const hardcoded_system_support_dir()
189 {
190         // FIXME UNICODE
191         // The build system needs to make sure that this is in utf8 encoding.
192         return FileName("@LYX_DIR@");
193 }
194
195
196 string const & with_version_suffix()
197 {
198         static string const program_suffix("@PROGRAM_SUFFIX@");
199         static string const
200                 with_version_suffix(" --with-version-suffix=@PROGRAM_SUFFIX@");
201         return program_suffix.empty() ? program_suffix : with_version_suffix;
202 }
203
204 } // namespace anon
205
206
207 FileName const & Package::top_srcdir()
208 {
209         // FIXME UNICODE
210         // The build system needs to make sure that this is in utf8 encoding.
211         static FileName const dir("@TOP_SRCDIR@");
212         return dir;
213 }
214
215
216 namespace {
217
218 bool check_command_line_dir(string const & dir,
219                             string const & file,
220                             string const & command_line_switch);
221
222 FileName const extract_env_var_dir(string const & env_var);
223
224 bool check_env_var_dir(FileName const & dir,
225                        string const & env_var);
226
227 bool check_env_var_dir(FileName const & dir,
228                        string const & file,
229                        string const & env_var);
230
231 string const relative_locale_dir();
232
233 string const relative_system_support_dir();
234
235
236 /**
237  * Convert \p name to internal path and strip a trailing slash, since it
238  * comes from user input (commandline or environment).
239  * \p name is encoded in utf8.
240  */
241 string const fix_dir_name(string const & name)
242 {
243         return rtrim(os::internal_path(name), "/");
244 }
245
246
247 FileName const
248 get_build_support_dir(string const & binary_dir,
249                       exe_build_dir_to_top_build_dir top_build_dir_location)
250 {
251         string indirection;
252         switch (top_build_dir_location) {
253         case top_build_dir_is_one_level_up:
254                 indirection = "../lib";
255                 break;
256         case top_build_dir_is_two_levels_up:
257                 indirection = "../../lib";
258                 break;
259         }
260         return FileName(normalizePath(addPath(binary_dir, indirection)));
261 }
262
263
264 std::pair<FileName, FileName> const
265 get_build_dirs(FileName const & abs_binary,
266                exe_build_dir_to_top_build_dir top_build_dir_location)
267 {
268         string const check_text = "Checking whether LyX is run in place...";
269
270         // We're looking for "Makefile" in a directory
271         //   binary_dir/../lib
272         // We're also looking for "chkconfig.ltx" in a directory
273         //   top_srcdir()/lib
274         // If both are found, then we're running LyX in-place.
275
276         // Note that the name of the lyx binary may be a symbolic link.
277         // If that is the case, then we follow the links too.
278         FileName binary = abs_binary;
279         while (true) {
280                 // Try and find "lyxrc.defaults".
281                 string binary_dir = onlyPath(binary.absFilename());
282                 // We may be using libtools with static linking.
283                 if (suffixIs(binary_dir, ".libs/"))
284                         binary_dir = addPath(binary_dir, "../");
285                 FileName const build_support_dir =
286                         get_build_support_dir(binary_dir, top_build_dir_location);
287                 if (!fileSearch(build_support_dir.absFilename(), "Makefile").empty()) {
288                         // Try and find "chkconfig.ltx".
289                         string const system_support_dir =
290                                 addPath(Package::top_srcdir().absFilename(), "lib");
291
292                         if (!fileSearch(system_support_dir, "chkconfig.ltx").empty()) {
293                                 lyxerr[Debug::INIT] << check_text << " yes"
294                                                     << std::endl;
295                                 return std::make_pair(build_support_dir, system_support_dir);
296                         }
297                 }
298
299                 // Check whether binary is a symbolic link.
300                 // If so, resolve it and repeat the exercise.
301                 if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
302                         break;
303
304                 FileName link;
305                 if (readLink(binary, link)) {
306                         binary = link;
307                 } else {
308                         // Unable to resolve the link.
309                         break;
310                 }
311         }
312
313         lyxerr[Debug::INIT] << check_text << " no" << std::endl;
314         return std::make_pair(FileName(), FileName());
315 }
316
317
318 // Specification of document_dir_ may be reset by LyXRC,
319 // but the default is fixed for a given OS.
320 FileName const get_document_dir(FileName const & home_dir)
321 {
322 #if defined (USE_WINDOWS_PACKAGING)
323         (void)home_dir; // Silence warning about unused variable.
324         os::GetFolderPath win32_folder_path;
325         return FileName(win32_folder_path(os::GetFolderPath::PERSONAL));
326 #else // Posix-like.
327         return home_dir;
328 #endif
329 }
330
331
332 // The specification of home_dir_ is fixed for a given OS.
333 // A typical example on Windows: "C:/Documents and Settings/USERNAME"
334 // and on a Posix-like machine: "/home/USERNAME".
335 FileName const get_home_dir()
336 {
337 #if defined (USE_WINDOWS_PACKAGING)
338         string const home_dir = getEnv("USERPROFILE");
339 #else // Posix-like.
340         string const home_dir = getEnv("HOME");
341 #endif
342
343         return FileName(fix_dir_name(home_dir));
344 }
345
346
347 // Several sources are probed to ascertain the locale directory.
348 // The only requirement is that the result is indeed a directory.
349 FileName const get_locale_dir(FileName const & system_support_dir)
350 {
351         // 1. Use the "LYX_LOCALEDIR" environment variable.
352         FileName const path_env = extract_env_var_dir("LYX_LOCALEDIR");
353         if (!path_env.empty() && check_env_var_dir(path_env, "LYX_LOCALEDIR"))
354                 return path_env;
355
356         // 2. Search for system_support_dir / <relative locale dir>
357         // The <relative locale dir> is OS-dependent. (On Unix, it will
358         // be "../locale/".)
359         FileName path(normalizePath(addPath(system_support_dir.absFilename(),
360                                             relative_locale_dir())));
361
362         if (fs::exists(path.toFilesystemEncoding()) &&
363             fs::is_directory(path.toFilesystemEncoding()))
364                 return path;
365
366         // 3. Fall back to the hard-coded LOCALEDIR.
367         path = hardcoded_localedir();
368         if (fs::exists(path.toFilesystemEncoding()) &&
369             fs::is_directory(path.toFilesystemEncoding()))
370                 return path;
371
372         return FileName();
373 }
374
375
376 // Specification of temp_dir_ may be reset by LyXRC,
377 // but the default is fixed for a given OS.
378 FileName const get_temp_dir()
379 {
380 #if defined (USE_WINDOWS_PACKAGING)
381         // Typical example: C:/TEMP/.
382         char path[MAX_PATH];
383         GetTempPath(MAX_PATH, path);
384         return FileName(os::internal_path(to_utf8(from_local8bit(path))));
385 #else // Posix-like.
386         return FileName("/tmp");
387 #endif
388 }
389
390
391 // Extracts the absolute path from the foo of "-sysdir foo" or "-userdir foo"
392 FileName const abs_path_from_command_line(string const & command_line)
393 {
394         if (command_line.empty())
395                 return FileName();
396
397         string const path = fix_dir_name(command_line);
398         return os::is_absolute_path(path) ? FileName(path) : makeAbsPath(path);
399 }
400
401
402 // Does the grunt work for abs_path_from_binary_name()
403 FileName const get_binary_path(string const & exe)
404 {
405 #if defined (USE_WINDOWS_PACKAGING)
406         // The executable may have been invoked either with or
407         // without the .exe extension.
408         // Ensure that it is present.
409         string const as_internal_path = os::internal_path(exe);
410         string const exe_path = suffixIs(as_internal_path, ".exe") ?
411                 as_internal_path : as_internal_path + ".exe";
412 #else
413         string const exe_path = os::internal_path(exe);
414 #endif
415         if (os::is_absolute_path(exe_path))
416                 return FileName(exe_path);
417
418         // Two possibilities present themselves.
419         // 1. The binary is relative to the CWD.
420         FileName const abs_exe_path = makeAbsPath(exe_path);
421         if (fs::exists(abs_exe_path.toFilesystemEncoding()))
422                 return abs_exe_path;
423
424         // 2. exe must be the name of the binary only and it
425         // can be found on the PATH.
426         string const exe_name = onlyFilename(exe_path);
427         if (exe_name != exe_path)
428                 return FileName();
429
430         std::vector<string> const path = getEnvPath("PATH");
431         std::vector<string>::const_iterator it = path.begin();
432         std::vector<string>::const_iterator const end = path.end();
433         for (; it != end; ++it) {
434                 // This will do nothing if *it is already absolute.
435                 string const exe_dir = makeAbsPath(*it).absFilename();
436
437                 FileName const exe_path(addName(exe_dir, exe_name));
438                 if (fs::exists(exe_path.toFilesystemEncoding()))
439                         return exe_path;
440         }
441
442         // Didn't find anything.
443         return FileName();
444 }
445
446
447 // Extracts the absolute path to the binary name received as argv[0].
448 FileName const abs_path_from_binary_name(string const & exe)
449 {
450         FileName const abs_binary = get_binary_path(exe);
451         if (abs_binary.empty()) {
452                 // FIXME UNICODE
453                 throw ExceptionMessage(ErrorException,
454                         _("LyX binary not found"),
455                         bformat(_("Unable to determine the path to the LyX binary from the command line %1$s"),
456                                 from_utf8(exe)));
457         }
458         return abs_binary;
459 }
460
461
462 // A plethora of directories is searched to ascertain the system
463 // lyxdir which is defined as the first directory to contain
464 // "chkconfig.ltx".
465 FileName const
466 get_system_support_dir(FileName const & abs_binary,
467                   string const & command_line_system_support_dir)
468 {
469         string const chkconfig_ltx = "chkconfig.ltx";
470
471         // searched_dirs is used for diagnostic purposes only in the case
472         // that "chkconfig.ltx" is not found.
473         std::list<FileName> searched_dirs;
474
475         // 1. Use the -sysdir command line parameter.
476         FileName path = abs_path_from_command_line(command_line_system_support_dir);
477         if (!path.empty()) {
478                 searched_dirs.push_back(path);
479                 if (check_command_line_dir(path.absFilename(), chkconfig_ltx, "-sysdir"))
480                         return path;
481         }
482
483         // 2. Use the "LYX_DIR_15x" environment variable.
484         path = extract_env_var_dir("LYX_DIR_15x");
485         if (!path.empty()) {
486                 searched_dirs.push_back(path);
487                 if (check_env_var_dir(path, chkconfig_ltx, "LYX_DIR_15x"))
488                         return path;
489         }
490
491         // 3. Search relative to the lyx binary.
492         // We're looking for "chkconfig.ltx" in a directory
493         //   OnlyPath(abs_binary) / <relative dir> / PACKAGE /
494         // PACKAGE is hardcoded in config.h. Eg "lyx" or "lyx-1.3.6cvs".
495         // <relative dir> is OS-dependent; on Unix, it will be "../share/".
496         string const relative_lyxdir = relative_system_support_dir();
497
498         // One subtlety to be aware of. The name of the lyx binary may be
499         // a symbolic link. If that is the case, then we follow the links too.
500         FileName binary = abs_binary;
501         while (true) {
502                 // Try and find "chkconfig.ltx".
503                 string const binary_dir = onlyPath(binary.absFilename());
504
505                 FileName const lyxdir(
506                         normalizePath(addPath(binary_dir, relative_lyxdir)));
507                 searched_dirs.push_back(lyxdir);
508
509                 if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
510                         // Success! "chkconfig.ltx" has been found.
511                         return lyxdir;
512                 }
513
514                 // Check whether binary is a symbolic link.
515                 // If so, resolve it and repeat the exercise.
516                 if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
517                         break;
518
519                 FileName link;
520                 if (readLink(binary, link)) {
521                         binary = link;
522                 } else {
523                         // Unable to resolve the link.
524                         break;
525                 }
526         }
527
528         // 4. Repeat the exercise on the directory itself.
529         FileName binary_dir(onlyPath(abs_binary.absFilename()));
530         while (true) {
531                 // This time test whether the directory is a symbolic link
532                 // *before* looking for "chkconfig.ltx".
533                 // (We've looked relative to the original already.)
534                 if (!fs::symbolic_link_exists(binary.toFilesystemEncoding()))
535                         break;
536
537                 FileName link;
538                 if (readLink(binary_dir, link)) {
539                         binary_dir = link;
540                 } else {
541                         // Unable to resolve the link.
542                         break;
543                 }
544
545                 // Try and find "chkconfig.ltx".
546                 FileName const lyxdir(
547                         normalizePath(addPath(binary_dir.absFilename(), relative_lyxdir)));
548                 searched_dirs.push_back(lyxdir);
549
550                 if (!fileSearch(lyxdir.absFilename(), chkconfig_ltx).empty()) {
551                         // Success! "chkconfig.ltx" has been found.
552                         return lyxdir;
553                 }
554         }
555
556         // 5. In desparation, try the hard-coded system support dir.
557         path = hardcoded_system_support_dir();
558         if (!fileSearch(path.absFilename(), chkconfig_ltx).empty())
559                 return path;
560
561         // Everything has failed :-(
562         // So inform the user and exit.
563         string searched_dirs_str;
564         typedef std::list<FileName>::const_iterator iterator;
565         iterator const begin = searched_dirs.begin();
566         iterator const end = searched_dirs.end();
567         for (iterator it = begin; it != end; ++it) {
568                 if (it != begin)
569                         searched_dirs_str += "\n\t";
570                 searched_dirs_str += it->absFilename();
571         }
572
573         // FIXME UNICODE
574         throw ExceptionMessage(ErrorException, _("No system directory"),
575                 bformat(_("Unable to determine the system directory "
576                                          "having searched\n"
577                                          "\t%1$s\n"
578                                          "Use the '-sysdir' command line parameter or "
579                                          "set the environment variable LYX_DIR_15x to "
580                                          "the LyX system directory containing the file "
581                                          "`chkconfig.ltx'."),
582                           from_utf8(searched_dirs_str)));
583
584         // Keep the compiler happy.
585         return FileName();
586 }
587
588
589 // Returns the absolute path to the user lyxdir, together with a flag
590 // indicating whether this directory was specified explicitly (as -userdir
591 // or through an environment variable) or whether it was deduced.
592 std::pair<FileName, bool> const
593 get_user_support_dir(FileName const & default_user_support_dir,
594                      string const & command_line_user_support_dir)
595 {
596         bool explicit_userdir = true;
597
598         // 1. Use the -userdir command line parameter.
599         FileName path =
600                 abs_path_from_command_line(command_line_user_support_dir);
601         if (!path.empty())
602                 return std::make_pair(path, explicit_userdir);
603
604         // 2. Use the LYX_USERDIR_15x environment variable.
605         path = extract_env_var_dir("LYX_USERDIR_15x");
606         if (!path.empty())
607                 return std::make_pair(path, explicit_userdir);
608
609         // 3. Use the OS-dependent default_user_support_dir
610         explicit_userdir = false;
611         return std::make_pair(default_user_support_dir, explicit_userdir);
612 }
613
614
615 // $HOME/.lyx on POSIX but on Win32 it will be something like
616 // "C:/Documents and Settings/USERNAME/Application Data/LyX"
617 FileName const get_default_user_support_dir(FileName const & home_dir)
618 {
619 #if defined (USE_WINDOWS_PACKAGING)
620         (void)home_dir; // Silence warning about unused variable.
621
622         os::GetFolderPath win32_folder_path;
623         return FileName(addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE));
624
625 #elif defined (USE_MACOSX_PACKAGING)
626         (void)home_dir; // Silence warning about unused variable.
627
628         FSRef fsref;
629         OSErr const error_code =
630                 FSFindFolder(kUserDomain, kApplicationSupportFolderType,
631                              kDontCreateFolder, &fsref);
632         if (error_code != 0)
633                 return FileName();
634
635         // FSRefMakePath returns the result in utf8
636         char store[PATH_MAX + 1];
637         OSStatus const status_code =
638                 FSRefMakePath(&fsref,
639                               reinterpret_cast<UInt8*>(store), PATH_MAX);
640         if (status_code != 0)
641                 return FileName();
642
643         return FileName(addPath(reinterpret_cast<char const *>(store), PACKAGE));
644
645 #else // USE_POSIX_PACKAGING
646         return FileName(addPath(home_dir.absFilename(), string(".") + PACKAGE));
647 #endif
648 }
649
650
651 // Check that directory @c dir contains @c file.
652 // Else emit a warning about an invalid @c command_line_switch.
653 bool check_command_line_dir(string const & dir,
654                             string const & file,
655                             string const & command_line_switch)
656 {
657         FileName const abs_path = fileSearch(dir, file);
658         if (abs_path.empty()) {
659                 // FIXME UNICODE
660                 throw ExceptionMessage(WarningException, _("File not found"), bformat(
661                         _("Invalid %1$s switch.\nDirectory %2$s does not contain %3$s."),
662                         from_utf8(command_line_switch), from_utf8(dir),
663                         from_utf8(file)));
664         }
665
666         return !abs_path.empty();
667 }
668
669
670 // The environment variable @c env_var expands to a (single) file path.
671 FileName const extract_env_var_dir(string const & env_var)
672 {
673         string const dir = fix_dir_name(getEnv(env_var));
674         return dir.empty() ? FileName() : makeAbsPath(dir);
675 }
676
677
678 // Check that directory @c dir contains @c file.
679 // Else emit a warning about an invalid @c env_var.
680 bool check_env_var_dir(FileName const & dir,
681                        string const & file,
682                        string const & env_var)
683 {
684         FileName const abs_path = fileSearch(dir.absFilename(), file);
685         if (abs_path.empty()) {
686                 // FIXME UNICODE
687                 throw ExceptionMessage(WarningException, _("File not found"), bformat(
688                         _("Invalid %1$s environment variable.\n"
689                                 "Directory %2$s does not contain %3$s."),
690                         from_utf8(env_var), from_utf8(dir.absFilename()),
691                         from_utf8(file)));
692         }
693
694         return !abs_path.empty();
695 }
696
697
698 // Check that directory @c dir is indeed a directory.
699 // Else emit a warning about an invalid @c env_var.
700 bool check_env_var_dir(FileName const & dir,
701                        string const & env_var)
702 {
703         string const encoded(dir.toFilesystemEncoding());
704         bool const success = (fs::exists(encoded) && fs::is_directory(encoded));
705
706         if (!success) {
707                 // Put this string on a single line so that the gettext
708                 // search mechanism in po/Makefile.in.in will register
709                 // Package.cpp.in as a file containing strings that need
710                 // translation.
711                 // FIXME UNICODE
712                 docstring const fmt =
713                         _("Invalid %1$s environment variable.\n%2$s is not a directory.");
714
715                 throw ExceptionMessage(WarningException, _("Directory not found"), bformat(
716                         fmt, from_utf8(env_var), from_utf8(dir.absFilename())));
717         }
718
719         return success;
720 }
721
722
723 // The locale directory relative to the LyX system directory.
724 string const relative_locale_dir()
725 {
726 #if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
727         return "locale/";
728 #else
729         return "../locale/";
730 #endif
731 }
732
733
734 // The system lyxdir is relative to the directory containing the LyX binary.
735 string const relative_system_support_dir()
736 {
737         string result;
738
739 #if defined (USE_WINDOWS_PACKAGING) || defined (USE_MACOSX_PACKAGING)
740         result = "../Resources/";
741 #else // Posix-like.
742         result = addPath("../share/", PACKAGE);
743 #endif
744
745         return result;
746 }
747
748 } // namespace anon
749
750 } // namespace support
751 } // namespace lyx