/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. @implementation HelloController
  26. - (void)didMount:(NSNotification *)notification {
  27. NSDictionary* userInfo = [notification userInfo];
  28. NSString* mountPath = [userInfo objectForKey:kGMUserFileSystemMountPathKey];
  29. NSString* parentPath = [mountPath stringByDeletingLastPathComponent];
  30. [[NSWorkspace sharedWorkspace] selectFile:mountPath
  31. inFileViewerRootedAtPath:parentPath];
  32. }
  33. - (void)didUnmount:(NSNotification*)notification {
  34. [[NSApplication sharedApplication] terminate:nil];
  35. }
  36. - (void)applicationDidFinishLaunching:(NSNotification *)notification {
  37. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  38. [center addObserver:self selector:@selector(didMount:)
  39. name:kGMUserFileSystemDidMount object:nil];
  40. [center addObserver:self selector:@selector(didUnmount:)
  41. name:kGMUserFileSystemDidUnmount object:nil];
  42. NSString* mountPath = @"/Volumes/Hello";
  43. HelloFuseFileSystem* hello = [[HelloFuseFileSystem alloc] init];
  44. fs_ = [[GMUserFileSystem alloc] initWithDelegate:hello isThreadSafe:YES];
  45. NSMutableArray* options = [NSMutableArray array];
  46. [options addObject:@"rdonly"];
  47. [options addObject:@"volname=HelloFS"];
  48. [options addObject:[NSString stringWithFormat:@"volicon=%@",
  49. [[NSBundle mainBundle] pathForResource:@"Fuse" ofType:@"icns"]]];
  50. [fs_ mountAtPath:mountPath withOptions:options];
  51. }
  52. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
  53. [[NSNotificationCenter defaultCenter] removeObserver:self];
  54. [fs_ unmount]; // Just in case we need to unmount;
  55. [[fs_ delegate] release]; // Clean up HelloFS
  56. [fs_ release];
  57. return NSTerminateNow;
  58. }
  59. @end