]> err.no Git - scalable-opengroupware.org/blob - SOGo/Main/SOGoProductLoader.m
changes to use NGLogging in all places
[scalable-opengroupware.org] / SOGo / Main / SOGoProductLoader.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "SOGoProductLoader.h"
24 #include "common.h"
25
26 @implementation SOGoProductLoader
27
28 + (id)productLoader {
29   return [[[self alloc] init] autorelease];
30 }
31
32 - (id)init {
33   if ((self = [super init])) {
34     self->productDirectoryName = @"SOGo";
35   }
36   return self;
37 }
38
39 - (void)dealloc {
40   [self->productDirectoryName release];
41   [super dealloc];
42 }
43
44 /* loading */
45
46 - (NSArray *)productSearchPathes {
47   static NSArray *searchPathes = nil;
48   NSMutableArray *ma;
49   NSDictionary   *env;
50   id tmp;
51   
52   if (searchPathes)
53     return searchPathes;
54   
55   env = [[NSProcessInfo processInfo] environment];
56   ma  = [NSMutableArray arrayWithCapacity:6];
57
58 #if COCOA_Foundation_LIBRARY
59   tmp = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory,
60                                             NSAllDomainsMask,
61                                             YES);
62   if ([tmp count] > 0) {
63     NSEnumerator *e;
64       
65     e = [tmp objectEnumerator];
66     while ((tmp = [e nextObject])) {
67       tmp = [tmp stringByAppendingPathComponent:self->productDirectoryName];
68       if (![ma containsObject:tmp])
69         [ma addObject:tmp];
70     }
71   }
72 #else
73   if ((tmp = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil)
74     tmp = [env objectForKey:@"GNUSTEP_PATHLIST"];
75   
76   tmp = [tmp componentsSeparatedByString:@":"];
77   if ([tmp count] > 0) {
78     NSEnumerator *e;
79       
80     e = [tmp objectEnumerator];
81     while ((tmp = [e nextObject])) {
82       tmp = [tmp stringByAppendingPathComponent:@"Library"];
83       tmp = [tmp stringByAppendingPathComponent:self->productDirectoryName];
84       if (![ma containsObject:tmp])
85         [ma addObject:tmp];
86     }
87   }
88   else {
89     NSLog(@"%s: empty library search path !", __PRETTY_FUNCTION__);
90   }
91 #endif
92     
93   searchPathes = [ma copy];
94     
95   if ([searchPathes count] == 0)
96     NSLog(@"%s: no search pathes were found !", __PRETTY_FUNCTION__);
97   
98   return searchPathes;
99 }
100
101 - (void)loadProducts {
102   SoProductRegistry *registry = nil;
103   NSFileManager *fm;
104   NSEnumerator  *pathes;
105   NSString      *lpath;
106   
107   registry = [SoProductRegistry sharedProductRegistry];
108   fm       = [NSFileManager defaultManager];
109   
110   pathes = [[self productSearchPathes] objectEnumerator];
111   while ((lpath = [pathes nextObject])) {
112     NSEnumerator *productNames;
113     NSString *productName;
114
115     productNames = [[fm directoryContentsAtPath:lpath] objectEnumerator];
116     
117     while ((productName = [productNames nextObject])) {
118       NSString *bpath;
119       
120       bpath = [lpath stringByAppendingPathComponent:productName];
121       [self logWithFormat:@"register SOGo product: %@", 
122               [bpath lastPathComponent]];
123       [registry registerProductAtPath:bpath];
124     }
125   }
126   
127   if (![registry loadAllProducts])
128     [self warnWithFormat:@"could not load all products !"];
129 }
130
131 @end /* SOGoProductLoader */