PageRenderTime 47ms CodeModel.GetById 7ms app.highlight 37ms RepoModel.GetById 1ms app.codeStats 0ms

/filesystems-objc/HelloFS/HelloController.m

http://macfuse.googlecode.com/
Objective C | 66 lines | 38 code | 7 blank | 21 comment | 0 complexity | 8284b70a7ec163cd707b76991ed2c28a MD5 | raw file
 1// ================================================================
 2// Copyright (C) 2008 Google Inc.
 3// 
 4// Licensed under the Apache License, Version 2.0 (the "License");
 5// you may not use this file except in compliance with the License.
 6// You may obtain a copy of the License at
 7// 
 8//      http://www.apache.org/licenses/LICENSE-2.0
 9// 
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15// ================================================================
16//
17//  HelloController
18//  HelloFS
19//
20//  Created by ted on 1/3/08.
21//
22#import "HelloController.h"
23#import "HelloFuseFileSystem.h"
24#import <MacFUSE/MacFUSE.h>
25
26@implementation HelloController
27
28- (void)didMount:(NSNotification *)notification {
29  NSDictionary* userInfo = [notification userInfo];
30  NSString* mountPath = [userInfo objectForKey:kGMUserFileSystemMountPathKey];
31  NSString* parentPath = [mountPath stringByDeletingLastPathComponent];
32  [[NSWorkspace sharedWorkspace] selectFile:mountPath
33                   inFileViewerRootedAtPath:parentPath];
34}
35
36- (void)didUnmount:(NSNotification*)notification {
37  [[NSApplication sharedApplication] terminate:nil];
38}
39
40- (void)applicationDidFinishLaunching:(NSNotification *)notification {
41  NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
42  [center addObserver:self selector:@selector(didMount:)
43                 name:kGMUserFileSystemDidMount object:nil];
44  [center addObserver:self selector:@selector(didUnmount:)
45                 name:kGMUserFileSystemDidUnmount object:nil];
46  
47  NSString* mountPath = @"/Volumes/Hello";
48  HelloFuseFileSystem* hello = [[HelloFuseFileSystem alloc] init];
49  fs_ = [[GMUserFileSystem alloc] initWithDelegate:hello isThreadSafe:YES];
50  NSMutableArray* options = [NSMutableArray array];
51  [options addObject:@"rdonly"];
52  [options addObject:@"volname=HelloFS"];
53  [options addObject:[NSString stringWithFormat:@"volicon=%@", 
54    [[NSBundle mainBundle] pathForResource:@"Fuse" ofType:@"icns"]]];
55  [fs_ mountAtPath:mountPath withOptions:options];
56}
57
58- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
59  [[NSNotificationCenter defaultCenter] removeObserver:self];
60  [fs_ unmount];  // Just in case we need to unmount;
61  [[fs_ delegate] release];  // Clean up HelloFS
62  [fs_ release];
63  return NSTerminateNow;
64}
65
66@end