#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>

@implementation NSWorkspace(AdditionalMethods)
- (NSString *)findSystemFolderType:(int)folderType forDomain:(int)domain
{
  FSRef folder;
  OSErr err = noErr;
  CFURLRef url;
  NSString *result = nil;

  err = FSFindFolder(domain, folderType, kCreateFolder, &folder);

  if (err == noErr) {
    url = CFURLCreateFromFSRef(kCFAllocatorDefault, &folder);
    result = [(NSURL *)url path];
    CFRelease(url);
  }

  return result;
}

- (NSString*)applicationSupportDirectory
{
    NSString *path = [[self findSystemFolderType: kApplicationSupportFolderType forDomain: kUserDomain] stringByAppendingPathComponent: @"ReSTedit"];
    
    if (![[NSFileManager defaultManager] fileExistsAtPath:path])
        [[NSFileManager defaultManager] createDirectoryAtPath: path attributes: nil];
    
    return path;
}
@end
