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