Skip to content

Loading…

Add directory creation support #51

Closed
wants to merge 2 commits into from

2 participants

@lksoft

Here are the changes to present error messages when the directories cannot be created and also it will now create the output directories automatically. Also fixed a logging bug.

@rentzsch
Owner

Thanks, pulled! Your code will be in the next release :-)

@rentzsch rentzsch closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 41 additions and 1 deletion.
  1. +41 −1 mogenerator.m
View
42 mogenerator.m
@@ -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];
@@ -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;
{
@@ -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)
Something went wrong with that request. Please try again.