PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/core/sdk-objc/ProjectTemplates/Objective-C Command Line File System/main.m

http://macfuse.googlecode.com/
Objective C | 65 lines | 45 code | 7 blank | 13 comment | 9 complexity | 495ff485ba45dd7bb0ecb79647412a21 MD5 | raw file
 1//
 2//  main.m
 3//  ÇPROJECTNAME?
 4//
 5//  Created by ÇFULLUSERNAME? on ÇDATE?.
 6//  Copyright ÇYEAR? ÇORGANIZATIONNAME?. All rights reserved.
 7//
 8// Compile on the command line as follows:
 9//  gcc -oPROJECTNAME?" ÇPROJECTNAMEASIDENTIFIER?_Filesystem.m main.m 
10//      -framework MacFUSE -framework Foundation
11//
12#import <sys/stat.h>
13#import <Foundation/Foundation.h>
14#import <MacFUSE/GMUserFileSystem.h>
15#importPROJECTNAMEASIDENTIFIER?_Filesystem.h"
16
17int main(int argc, char* argv[], char* envp[], char** exec_path) {
18  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
19  
20  NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
21  NSString* mountPath = [args stringForKey:@"mountPath"];
22  NSString* iconPath = [args stringForKey:@"volicon"];
23  if (!mountPath || [mountPath isEqualToString:@""]) {
24    printf("\nUsage: %s -mountPath <path> [-volicon <path>]\n", argv[0]);
25    printf("  -mountPath: Mount point to use.\n");
26    printf("Ex: %s -mountPath /Volumes/ÇPROJECTNAME?\n\n", argv[0]);
27    return 0;
28  }
29  if (!iconPath) {
30    // We check for a volume icon embedded as our resource fork.
31    char program_path[PATH_MAX] = { 0 };
32    if (realpath(*exec_path, program_path)) {
33      iconPath = [NSString stringWithFormat:@"%s/..namedfork/rsrc", program_path];
34      struct stat stat_buf;
35      memset(&stat_buf, 0, sizeof(stat_buf));
36      if (stat([iconPath UTF8String], &stat_buf) != 0 || stat_buf.st_size <= 0) {
37        iconPath = nil;  // We found an exec path, but the resource fork is empty.
38      }
39    }
40  }
41  
42  ÇPROJECTNAMEASIDENTIFIER?_Filesystem* fs = 
43  [[ÇPROJECTNAMEASIDENTIFIER?_Filesystem alloc] init];
44  GMUserFileSystem* userFS = [[GMUserFileSystem alloc] initWithDelegate:fs 
45                                                           isThreadSafe:NO];
46  
47  NSMutableArray* options = [NSMutableArray array];
48  if (iconPath != nil) {
49    NSString* volArg = [NSString stringWithFormat:@"volicon=%@", iconPath];
50    [options addObject:volArg];
51  }
52  [options addObject:@"volname=ÇPROJECTNAME?"];
53  // [options addObject:@"rdonly"];  <-- Uncomment to mount read-only.
54  
55  [userFS mountAtPath:mountPath 
56          withOptions:options 
57     shouldForeground:YES 
58      detachNewThread:NO];
59  
60  [userFS release];
61  [fs release];
62  
63  [pool release];
64  return 0;
65}