]> err.no Git - sope/blob - sope-gdl1/GDLContentStore/gcs_mkdir.m
added OGoContentStore library to sope-gdl1
[sope] / sope-gdl1 / GDLContentStore / gcs_mkdir.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 #import <Foundation/NSObject.h>
23
24 @class NSUserDefaults, NSArray;
25 @class GCSFolderManager;
26
27 @interface Tool : NSObject
28 {
29   NSUserDefaults   *ud;
30   GCSFolderManager *folderManager;
31 }
32
33 + (int)runWithArgs:(NSArray *)_args;
34 - (int)run;
35
36 @end
37
38 #include <GDLContentStore/GCSFolder.h>
39 #include <GDLContentStore/GCSFolderManager.h>
40 #include "common.h"
41
42 @implementation Tool
43
44 - (id)init {
45   if ((self = [super init])) {
46     self->ud            = [[NSUserDefaults standardUserDefaults]   retain];
47     self->folderManager = [[GCSFolderManager defaultFolderManager] retain];
48   }
49   return self;
50 }
51 - (void)dealloc {
52   [self->ud            release];
53   [self->folderManager release];
54   [super dealloc];
55 }
56
57 /* operation */
58
59 - (int)runOnPath:(NSString *)_path type:(NSString *)_type {
60   NSException *error;
61   
62   [self logWithFormat:@"mkdir %@ at path: '%@'", _type, _path];
63   
64   if ([self->folderManager folderExistsAtPath:_path]) {
65     [self logWithFormat:@"folder already exist at path: '%@'", _path];
66     return 1;
67   }
68   
69   if ((error = [self->folderManager createFolderOfType:_type atPath:_path])) {
70     [self logWithFormat:@"creation of folder %@ at %@ failed: %@",
71             _type, _path, error];
72     return 1;
73   }
74   
75   if ([self->folderManager folderExistsAtPath:_path])
76     [self logWithFormat:@"CREATED."];
77   else
78     [self logWithFormat:@"cannot find fresh folder?"];
79   
80   return 0;
81 }
82
83 - (int)run {
84   NSEnumerator *e;
85   NSString *type;
86   NSString *path;
87   
88   [self logWithFormat:@"manager: %@", self->folderManager];
89   
90   if (![self->folderManager canConnect]) {
91     [self logWithFormat:@"cannot connect folder-info database!"];
92     return 1;
93   }
94   
95   e = [[[NSProcessInfo processInfo] argumentsWithoutDefaults] 
96                        objectEnumerator];
97   [e nextObject]; // skip tool name
98   
99   type = [[[e nextObject] copy] autorelease];
100   
101   while ((path = [e nextObject]))
102     [self runOnPath:path type:type];
103   
104   return 0;
105 }
106 + (int)runWithArgs:(NSArray *)_args {
107   return [(Tool *)[[[self alloc] init] autorelease] run];
108 }
109
110 @end /* Tool */
111
112 int main(int argc, char **argv, char **env) {
113   NSAutoreleasePool *pool;
114   int rc;
115
116   pool = [[NSAutoreleasePool alloc] init];
117 #if LIB_FOUNDATION_LIBRARY  
118   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
119 #endif
120
121   rc = [Tool runWithArgs:
122                [[NSProcessInfo processInfo] argumentsWithoutDefaults]];
123   
124   [pool release];
125   return rc;
126 }