Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add directory creation support #51

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ - (NSString*)currentXcodePath {

NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
// Ensures that the current tasks output doesn't get hijacked
[task setStandardInput:[NSPipe pipe]];

NSFileHandle *file = [pipe fileHandleForReading];

Expand Down Expand Up @@ -432,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 @@ -444,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