2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <NGObjWeb/WOCoreApplication.h>
25 @implementation WOCoreApplication(Bundle)
27 + (BOOL)didLoadDaemonBundle:(NSBundle *)_bundle {
31 + (int)loadApplicationBundle:(NSString *)_bundleName
32 domainPath:(NSString *)_domain
34 // TODO: is this actually used somewhere?
38 NSMutableArray *chkPathes;
41 fm = [NSFileManager defaultManager];
43 if ([[_bundleName pathExtension] length] == 0)
44 _bundleName = [_bundleName stringByAppendingPathExtension:@"sxa"];
46 chkPathes = [NSMutableArray arrayWithCapacity:16];
48 if ([_bundleName isAbsolutePath]) {
49 [chkPathes addObject:_bundleName];
56 env = [[NSProcessInfo processInfo] environment];
58 [chkPathes addObject:@"."];
60 bp = [env objectForKey:@"HOME"];
61 bp = [bp stringByAppendingPathComponent:@"Library"];
62 bp = [bp stringByAppendingPathComponent:_domain];
63 [chkPathes addObject:bp];
65 bp = [bp stringByAppendingPathComponent:_domain];
66 [chkPathes addObject:bp];
67 bp = @"/System/Library";
68 bp = [bp stringByAppendingPathComponent:_domain];
69 [chkPathes addObject:bp];
71 if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil)
72 tmp = [env objectForKey:@"GNUSTEP_PATHLIST"];
73 tmp = [tmp componentsSeparatedByString:@":"];
74 e = [tmp objectEnumerator];
75 while ((tmp = [e nextObject])) {
76 bp = [tmp stringByAppendingPathComponent:@"Library"];
77 bp = [bp stringByAppendingPathComponent:_domain];
78 if ([chkPathes containsObject:bp]) continue;
80 [chkPathes addObject:bp];
85 e = [chkPathes objectEnumerator];
86 while ((bp = [e nextObject])) {
89 bp = [bp stringByAppendingPathComponent:_bundleName];
90 if (![fm fileExistsAtPath:bp isDirectory:&isDir]) continue;
95 if ([bp length] == 0) {
96 [self debugWithFormat:
97 @"%s: did not find the bundle '%@' in search list %@",
98 __PRETTY_FUNCTION__, _bundleName, chkPathes];
102 if ((bundle = [NGBundle bundleWithPath:bp]) == nil) {
103 [self debugWithFormat:@"%s: did not find %@ at %@ ...",
104 __PRETTY_FUNCTION__, _bundleName, bp];
108 if (![bundle load]) {
109 [self errorWithFormat:@"%s: could not load %@ %@ (path=%@)...",
110 __PRETTY_FUNCTION__, _bundleName, bundle, bp];
114 if (![self didLoadDaemonBundle:bundle]) {
118 [self debugWithFormat:@"hosting bundle: %@", [bundle bundleName]];
123 + (int)runApplicationBundle:(NSString *)_bundleName
124 domainPath:(NSString *)_p
125 arguments:(void *)_argv count:(int)_argc
127 NSAutoreleasePool *pool = nil;
129 NSString *appClassName, *bundleName;
131 pool = [[NSAutoreleasePool alloc] init];
133 #if LIB_FOUNDATION_LIBRARY
135 extern char **environ;
136 [NSProcessInfo initializeWithArguments:_argv
138 environment:environ];
142 if ((rc = [self loadApplicationBundle:_bundleName
143 domainPath:_p]) != 0)
146 bundleName = [_bundleName lastPathComponent];
147 bundleName = [bundleName stringByDeletingPathExtension];
149 appClassName = [bundleName stringByAppendingString:@"Application"];
151 rc = WOWatchDogApplicationMain(appClassName, _argc, _argv);
153 RELEASE(pool); pool = nil;
158 + (int)runApplicationBundle:(NSString *)_bundleName
159 arguments:(void *)_args count:(int)_argc
161 return [self runApplicationBundle:_bundleName
163 arguments:_args count:_argc];
166 @end /* WOApplication */