]> git.lyx.org Git - lyx.git/blob - src/support/Path.cpp
Update my email and status.
[lyx.git] / src / support / Path.cpp
1 /**
2  * \file Path.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/Path.h"
14
15 // undef PathChanger macro when building PathChanger
16 #undef PathChanger
17
18
19 namespace lyx {
20 namespace support {
21
22 PathChanger::PathChanger(FileName const & path)
23         : popped_(false)
24 {
25         if (!path.empty()) {
26                 pushedDir_ = FileName::getcwd();
27
28                 if (pushedDir_.empty() || !path.chdir()) {
29                         /* FIXME: throw */
30                 }
31         } else {
32                 popped_ = true;
33         }
34 }
35
36
37 PathChanger::~PathChanger()
38 {
39         if (!popped_)
40                 pop();
41 }
42
43
44 int PathChanger::pop()
45 {
46         if (popped_) {
47                 // should throw an exception
48                 // throw logical_error();
49                 return 0;
50         }
51
52         if (!pushedDir_.chdir()) {
53                 // should throw an exception
54                 // throw DirChangeError();
55         }
56         popped_ = true;
57
58         return 0;
59 }
60
61 } // namespace support
62 } // namespace lyx
63
64
65 #define PathChanger(x) unnamed_PathChanger;
66
67 #ifdef __APPLE__
68
69 #include <CoreServices/CoreServices.h>
70
71 int getPrivateFrameworkPathName(char * buf, unsigned len, char const * framework)
72 {
73         // Get our application's main bundle from Core Foundation
74         CFBundleRef myAppsBundle = CFBundleGetMainBundle();
75         int result = 0 ;
76         if (NULL != myAppsBundle) {
77                 CFURLRef baseURL = CFBundleCopyPrivateFrameworksURL( myAppsBundle );
78                 if (NULL != baseURL) {
79                         CFURLRef bundleURL = CFURLCreateCopyAppendingPathComponent( kCFAllocatorSystemDefault, baseURL,
80                                 CFStringCreateWithCString( kCFAllocatorSystemDefault, framework, CFStringGetSystemEncoding() ),
81                                 false );
82                         if (NULL != bundleURL) {
83                                 result = CFURLGetFileSystemRepresentation( bundleURL, TRUE, (UInt8*)buf, len );
84                         }
85                 }
86         }
87         return result;
88 }
89
90 #endif
91
92 // in merged builds this is not the last line.