MacGapProject / MacGap2

MacGap 2
MIT License
1.19k stars 85 forks source link

Contribution? #107

Open justin-souter opened 3 years ago

justin-souter commented 3 years ago

I have added these functions to the File interface and I'm willing to contribute them. How is that done?

jeff-h commented 3 years ago

Sounds great! Just open a Pull Request, I'll review your code and if all is well I'll commit it.

If you're new to Github PRs the whole process will involve a bit of a learning curve, but if that's the case you should be able to find some good tutorials out there.

justin-souter commented 3 years ago

Unfortunately I have my hands full with learning curves at the moment. It's just a small amount of code so I'll just post here and hopefully someone else can bake it in for the common good.

- (NSString*) resourceDirectory {

    NSBundle* myBundle = [NSBundle mainBundle];
    return [myBundle resourcePath];
}

- (NSString*) homeDirectory {
    return NSHomeDirectory();
}

- (BOOL) createDirectory:(NSString*)path {

    NSFileManager *fileManager= [NSFileManager defaultManager];
    NSError *error = nil;

    if(![fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {

        NSLog(@"Failed to create directory \"%@\". Error: %@", path, error);
        return false;
    }
    return true;
}

- (void) delete:(NSString*)path {
    NSFileManager *fileManager= [NSFileManager defaultManager];
    [fileManager removeItemAtPath:path error:nil];
}
jeff-h commented 3 years ago

Thanks for this!

justin-souter commented 3 years ago

Well, turns out that a couple of things I added (home and resources directories) are already covered as properties of the MagGap object, which I hadn't found before. My createDirectory and delete are still useful though.