2 Copyright (C) 2004-2005 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 #import <Foundation/NSArray.h>
23 #import <Foundation/NSDictionary.h>
24 #import <Foundation/NSFileManager.h>
25 #import <Foundation/NSPathUtilities.h>
26 #import <Foundation/NSProcessInfo.h>
28 #import <NGObjWeb/SoProductRegistry.h>
29 #import <NGExtensions/NSObject+Logs.h>
31 #import "SOGoProductLoader.h"
33 @implementation SOGoProductLoader
35 + (int)sogoMajorVersion {
36 return SOGO_MAJOR_VERSION;
38 + (int)sogoMinorVersion {
39 return SOGO_MINOR_VERSION;
43 return [[[self alloc] init] autorelease];
47 if ((self = [super init])) {
48 self->productDirectoryName =
49 [[NSString alloc] initWithFormat:@"SOGo-%i.%i",
50 [[self class] sogoMajorVersion],
51 [[self class] sogoMinorVersion]];
57 [self->productDirectoryName release];
58 [self->searchPathes release];
64 - (void)_addCocoaSearchPathesToArray:(NSMutableArray *)ma {
67 tmp = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory,
70 if ([tmp count] > 0) {
73 e = [tmp objectEnumerator];
74 while ((tmp = [e nextObject])) {
75 tmp = [tmp stringByAppendingPathComponent:self->productDirectoryName];
76 if (![ma containsObject:tmp])
82 - (void)_addGNUstepSearchPathesToArray:(NSMutableArray *)ma {
86 env = [[NSProcessInfo processInfo] environment];
87 if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil)
88 tmp = [env objectForKey:@"GNUSTEP_PATHLIST"];
90 tmp = [tmp componentsSeparatedByString:@":"];
91 if ([tmp count] > 0) {
94 e = [tmp objectEnumerator];
95 while ((tmp = [e nextObject])) {
96 tmp = [tmp stringByAppendingPathComponent:@"Library"];
97 tmp = [tmp stringByAppendingPathComponent:self->productDirectoryName];
98 if (![ma containsObject:tmp])
103 NSLog(@"%s: empty library search path !", __PRETTY_FUNCTION__);
107 - (void)_addFHSPathesToArray:(NSMutableArray *)ma {
111 [ma addObject:[@"/usr/local/lib/" stringByAppendingString:s]];
112 [ma addObject:[@"/usr/lib/" stringByAppendingString:s]];
115 - (NSArray *)productSearchPathes {
119 if (self->searchPathes != nil)
120 return self->searchPathes;
122 hasGNUstepEnv = [[[[NSProcessInfo processInfo] environment]
123 objectForKey:@"GNUSTEP_USER_ROOT"] length] > 0 ? YES : NO;
125 ma = [NSMutableArray arrayWithCapacity:6];
128 [self _addGNUstepSearchPathesToArray:ma];
129 #if COCOA_Foundation_LIBRARY
131 [self _addCocoaSearchPathesToArray:ma];
134 [self _addFHSPathesToArray:ma];
136 self->searchPathes = [ma copy];
138 if ([self->searchPathes count] == 0) {
139 [self logWithFormat:@"%s: no search pathes were found !",
140 __PRETTY_FUNCTION__];
143 return self->searchPathes;
146 - (void)loadProducts {
147 SoProductRegistry *registry = nil;
149 NSEnumerator *pathes;
150 NSString *lpath, *bpath, *extension;
151 NSEnumerator *productNames;
152 NSString *productName;
154 registry = [SoProductRegistry sharedProductRegistry];
155 fm = [NSFileManager defaultManager];
157 pathes = [[self productSearchPathes] objectEnumerator];
158 lpath = [pathes nextObject];
161 [self logWithFormat:@"scanning SOGo products in: %@", lpath];
163 productNames = [[fm directoryContentsAtPath: lpath] objectEnumerator];
165 productName = [productNames nextObject];
168 extension = [productName pathExtension];
169 if ([extension length] > 0
170 && [extension isEqualToString: @"SOGo"])
172 bpath = [lpath stringByAppendingPathComponent: productName];
173 [self logWithFormat:@" register SOGo product: %@",
175 [registry registerProductAtPath: bpath];
177 productName = [productNames nextObject];
180 lpath = [pathes nextObject];
183 if (![registry loadAllProducts])
184 [self warnWithFormat:@"could not load all products !"];
187 @end /* SOGoProductLoader */