Skip to content

Commit

Permalink
Add automatic creation of output directories if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
lksoft committed Apr 7, 2011
1 parent 5c52175 commit b080a24
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion mogenerator.m
Expand Up @@ -434,6 +434,39 @@ - (void)setModel:(NSString*)path;
assert(model);
}

- (void)validateOutputPath:(NSString *)path forType:(NSString *)type
{
// Ignore nil ones
if (path == nil) {
return;
}

NSString *errorString = nil;
NSError *error = nil;
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir = NO;

// Test to see if the path exists
if ([fm fileExistsAtPath:path isDirectory:&isDir]) {
if (!isDir) {
errorString = [NSString stringWithFormat:@"%@ Directory path (%@) exists as a file.", type, path];
}
}
// Try to create path
else {
if (![fm createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {
errorString = [NSString stringWithFormat:@"Couldn't create %@ Directory (%@):%@", type, path, [error localizedDescription]];
}
}

if (errorString != nil) {

// Print error message and exit with IO error
ddprintf(errorString);
exit(EX_IOERR);
}
}

- (int) application: (DDCliApplication *) app
runWithArguments: (NSArray *) arguments;
{
Expand All @@ -446,10 +479,15 @@ - (int) application: (DDCliApplication *) app
printf("mogenerator 1.22. By Jonathan 'Wolf' Rentzsch + friends.\n");
return EXIT_SUCCESS;
}
gCustomBaseClass = [baseClass retain];
NSString * mfilePath = includem;
NSMutableString * mfileContent = [NSMutableString stringWithString:@""];

[self validateOutputPath:outputDir forType:@"Output"];
[self validateOutputPath:machineDir forType:@"Machine Output"];
[self validateOutputPath:humanDir forType:@"Human Output"];

if (outputDir == nil)
outputDir = @"";
if (machineDir == nil)
Expand Down

0 comments on commit b080a24

Please sign in to comment.