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 {
83 NSEnumerator *libraryPaths;
86 libraryPaths = [NSStandardLibraryPaths() objectEnumerator];
87 while ((directory = [libraryPaths nextObject]))
88 [ma addObject: [directory stringByAppendingPathComponent:self->productDirectoryName]];
91 - (void)_addFHSPathesToArray:(NSMutableArray *)ma {
95 [ma addObject:[@"/usr/local/lib/" stringByAppendingString:s]];
96 [ma addObject:[@"/usr/lib/" stringByAppendingString:s]];
99 - (NSArray *)productSearchPathes {
103 if (self->searchPathes != nil)
104 return self->searchPathes;
106 hasGNUstepEnv = [[[[NSProcessInfo processInfo] environment]
107 objectForKey:@"GNUSTEP_USER_ROOT"] length] > 0 ? YES : NO;
109 ma = [NSMutableArray arrayWithCapacity:6];
112 [self _addGNUstepSearchPathesToArray:ma];
113 #if COCOA_Foundation_LIBRARY
115 [self _addCocoaSearchPathesToArray:ma];
118 [self _addFHSPathesToArray:ma];
120 self->searchPathes = [ma copy];
122 if ([self->searchPathes count] == 0) {
123 [self logWithFormat:@"%s: no search pathes were found !",
124 __PRETTY_FUNCTION__];
127 return self->searchPathes;
130 - (void)loadProducts {
131 SoProductRegistry *registry = nil;
133 NSEnumerator *pathes;
134 NSString *lpath, *bpath, *extension;
135 NSEnumerator *productNames;
136 NSString *productName;
138 registry = [SoProductRegistry sharedProductRegistry];
139 fm = [NSFileManager defaultManager];
141 pathes = [[self productSearchPathes] objectEnumerator];
142 lpath = [pathes nextObject];
145 [self logWithFormat:@"scanning SOGo products in: %@", lpath];
147 productNames = [[fm directoryContentsAtPath: lpath] objectEnumerator];
149 productName = [productNames nextObject];
152 extension = [productName pathExtension];
153 if ([extension length] > 0
154 && [extension isEqualToString: @"SOGo"])
156 bpath = [lpath stringByAppendingPathComponent: productName];
157 [self logWithFormat:@" register SOGo product: %@",
159 [registry registerProductAtPath: bpath];
161 productName = [productNames nextObject];
164 lpath = [pathes nextObject];
167 if (![registry loadAllProducts])
168 [self warnWithFormat:@"could not load all products !"];
171 @end /* SOGoProductLoader */