+2005-07-11 Helge Hess <helge.hess@opengroupware.org>
+
+ * NGResourceLocator.m: added -description, added method
+ -lookupAllFilesWithExtension:doReturnFullPath: to discover all
+ available files in a search hierarchy (v4.5.161)
+
2005-05-20 Helge Hess <helge.hess@skyrix.com>
* moved NGStringScanEnumerator to Recycler (was not in makefile)
- (NSString *)lookupFileWithName:(NSString *)_name;
- (NSString *)lookupFileWithName:(NSString *)_name extension:(NSString *)_ext;
+- (NSArray *)lookupAllFilesWithExtension:(NSString *)_ext
+ doReturnFullPath:(BOOL)_withPath;
+
@end
#endif /* __NGExtensions_NGResourceLocator_H__ */
return [p isNotNull] ? p : nil;
e = [[self searchPathes] objectEnumerator];
- while ((p = [e nextObject])) {
+ while ((p = [e nextObject]) != nil) {
p = [p stringByAppendingPathComponent:_name];
if (![self->fileManager fileExistsAtPath:p])
return [self lookupFileWithName:_name];
}
+- (NSArray *)lookupAllFilesWithExtension:(NSString *)_ext
+ doReturnFullPath:(BOOL)_withPath
+{
+ /* only deliver each filename once */
+ NSMutableArray *pathes;
+ NSMutableSet *uniquer;
+ NSArray *lSearchPathes;
+ unsigned i, count;
+
+ _ext = [_ext length] > 0 ? [@"." stringByAppendingString:_ext] :nil;
+ uniquer = [NSMutableSet setWithCapacity:128];
+ pathes = _withPath ? [NSMutableArray arrayWithCapacity:64] : nil;
+ lSearchPathes = [self searchPathes];
+
+ for (i = 0, count = [lSearchPathes count]; i < count; i++) {
+ NSArray *filenames;
+ unsigned j, jcount;
+
+ filenames = [self->fileManager directoryContentsAtPath:
+ [lSearchPathes objectAtIndex:i]];
+
+ for (j = 0, jcount = [filenames count]; j < jcount; j++) {
+ NSString *fn, *pn;
+
+ fn = [filenames objectAtIndex:j];
+ if (_ext != nil) {
+ if (![fn hasSuffix:_ext])
+ continue;
+ }
+
+ if ([uniquer containsObject:fn])
+ continue;
+
+ [uniquer addObject:fn];
+
+ /* build and cache path */
+ pn = [[lSearchPathes objectAtIndex:i] stringByAppendingPathComponent:fn];
+ [self cachePath:pn forName:fn];
+ if (_withPath) [pathes addObject:pn];
+ }
+ }
+
+ return _withPath ? pathes : [uniquer allObjects];
+}
+
+/* description */
+
+- (NSString *)description {
+ NSMutableString *ms;
+
+ ms = [NSMutableString stringWithCapacity:128];
+ [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
+
+ [ms appendFormat:@" gs=%@ fhs=%@", self->gsSubPath, self->fhsSubPath];
+
+ [ms appendString:@" cache"];
+ if (self->flags.cacheSearchPathes)
+ [ms appendString:@":pathes"];
+ if (self->flags.cachePathHits)
+ [ms appendString:@":hits"];
+ if (self->flags.cachePathMisses)
+ [ms appendString:@":misses"];
+ [ms appendFormat:@":#%d", [self->nameToPathCache count]];
+
+ [ms appendString:@">"];
+ return ms;
+}
+
@end /* NGResourceLocator */
# version
-SUBMINOR_VERSION:=160
+SUBMINOR_VERSION:=161
# v4.3.115 requires libFoundation v1.0.59
# v4.2.72 requires libEOControl v4.2.39
+2005-07-11 Helge Hess <helge.hess@opengroupware.org>
+
+ * GCSFolderManager.m: added automatic discovery of folder types by
+ scanning for .ocs files (v4.5.29)
+
2005-04-25 Helge Hess <helge.hess@opengroupware.org>
* fixed gcc 4.0 warnings (v4.5.28)
#include "EOAdaptorChannel+GCS.h"
#include "common.h"
#include <GDLAccess/EOAdaptorChannel.h>
+#include <NGExtensions/NGResourceLocator.h>
/*
Required database schema:
return fm;
}
+- (NSDictionary *)loadDefaultFolderTypes {
+ NSMutableDictionary *typeMap;
+ NSArray *types;
+ unsigned i, count;
+
+
+ types = [[GCSFolderType resourceLocator] lookupAllFilesWithExtension:@"ocs"
+ doReturnFullPath:NO];
+ if ((count = [types count]) == 0) {
+ [self logWithFormat:@"Note: no GCS folder types found."];
+ return nil;
+ }
+
+ typeMap = [NSMutableDictionary dictionaryWithCapacity:count];
+
+ [self logWithFormat:@"Note: loading %d GCS folder types:", count];
+ for (i = 0, count = [types count]; i < count; i++) {
+ NSString *type;
+ GCSFolderType *typeObject;
+
+ type = [[types objectAtIndex:i] stringByDeletingPathExtension];
+ typeObject = [[GCSFolderType alloc] initWithFolderTypeName:type];
+
+ [self logWithFormat:@" %@: %s",
+ type, [typeObject isNotNull] ? "OK" : "FAIL"];
+ [typeMap setObject:typeObject forKey:type];
+ [typeObject release];
+ }
+
+ return typeMap;
+}
+
- (id)initWithFolderInfoLocation:(NSURL *)_url {
if (_url == nil) {
[self logWithFormat:@"ERROR(%s): missing folder info url!",
return nil;
}
if ((self = [super init])) {
- GCSFolderType *cal, *contact;
-
self->channelManager = [[GCSChannelManager defaultChannelManager] retain];
self->folderInfoLocation = [_url retain];
}
/* register default folder types */
-
- cal = [[GCSFolderType alloc] initWithFolderTypeName:@"appointment"];
- contact = [[GCSFolderType alloc] initWithFolderTypeName:@"contact"];
- self->nameToType = [[NSDictionary alloc] initWithObjectsAndKeys:
- cal, @"appointment",
- contact, @"contact",
- nil];
- [cal release]; cal = nil;
- [contact release]; contact = nil;
+ self->nameToType = [[self loadDefaultFolderTypes] copy];
}
return self;
}
@class NSString, NSArray, NSDictionary;
@class EOQualifier;
+@class NGResourceLocator;
@class GCSFolder, GCSFieldExtractor;
@interface GCSFolderType : NSObject
- (GCSFieldExtractor *)quickExtractor;
+/* locator used to find .ocs files */
+
++ (NGResourceLocator *)resourceLocator;
+
@end
#endif /* __GDLContentStore_GCSFolderType_H__ */
MAJOR_VERSION:=4
MINOR_VERSION:=5
-SUBMINOR_VERSION:=28
+SUBMINOR_VERSION:=29
+# v4.5.29 requires libNGExtensions v4.5.161
# v4.5.26 does not require libNGiCal anymore
# v0.9.19 requires libNGiCal v4.5.40
# v0.9.18 requires libNGiCal v4.5.38