Skip to content
Permalink
Browse files

Fix issue with folders not being created on startup

  • Loading branch information...
imothee committed Aug 23, 2018
1 parent 3894fd6 commit de8b1279e563240ef23af70cde580ec210c33b89
Showing with 318 additions and 307 deletions.
  1. +4 −2 TmpDisk.xcodeproj/project.pbxproj
  2. +98 −98 TmpDisk/AppDelegate.m
  3. +213 −204 TmpDisk/Classes/TmpDiskManager.m
  4. +3 −3 TmpDisk/TmpDisk-Info.plist
@@ -596,8 +596,9 @@
baseConfigurationReference = 00F4F36CB9136F2BB1F0A497 /* Pods-TmpDisk.debug.xcconfig */;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_IDENTITY = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = B79ZU76C43;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)\"",
@@ -618,8 +619,9 @@
baseConfigurationReference = 9CD599E58C7540A97A750EFD /* Pods-TmpDisk.release.xcconfig */;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_IDENTITY = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = B79ZU76C43;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)\"",
@@ -29,131 +29,131 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application

// Check if TmpDisk was launched with command line args
NSArray *arguments = [NSProcessInfo processInfo].arguments;

NSString *argName = nil;
NSString *argSize = nil;
// TODO: There's likely a better way to parse command line args
for (NSUInteger i=0, n=arguments.count; i<n; i++) {
NSString *s = arguments[i];

// We expect args in the format -argname=argval

NSArray *arg = [s componentsSeparatedByString:@"="];
if (arg.count == 2) {
if ([arg[0] isEqualToString:@"-name"]) {
argName = [NSString stringWithString:arg[1]];
} else if ([arg[0] isEqualToString:@"-size"]) {
argSize = [NSString stringWithString:arg[1]];
}
// Insert code here to initialize your application

// Check if TmpDisk was launched with command line args
NSArray *arguments = [NSProcessInfo processInfo].arguments;

NSString *argName = nil;
NSString *argSize = nil;
// TODO: There's likely a better way to parse command line args
for (NSUInteger i=0, n=arguments.count; i<n; i++) {
NSString *s = arguments[i];

// We expect args in the format -argname=argval

NSArray *arg = [s componentsSeparatedByString:@"="];
if (arg.count == 2) {
if ([arg[0] isEqualToString:@"-name"]) {
argName = [NSString stringWithString:arg[1]];
} else if ([arg[0] isEqualToString:@"-size"]) {
argSize = [NSString stringWithString:arg[1]];
}
}
}
}

if (argName != nil && argSize != nil) {

int dsize = argSize.intValue;
u_int64_t size = (((u_int64_t) dsize) * 1024 * 1024 / 512);

if(![[NSFileManager defaultManager] fileExistsAtPath:[TmpDiskManager pathForName:argName] isDirectory:nil]) {
[TmpDiskManager createTmpDiskWithName:argName size:size autoCreate:NO indexed:NO hidden:NO folders:[[NSArray alloc] init] onSuccess:nil];

if (argName != nil && argSize != nil) {

int dsize = argSize.intValue;
u_int64_t size = (((u_int64_t) dsize) * 1024 * 1024 / 512);

if(![[NSFileManager defaultManager] fileExistsAtPath:[TmpDiskManager pathForName:argName] isDirectory:nil]) {
[TmpDiskManager createTmpDiskWithName:argName size:size autoCreate:NO indexed:NO hidden:NO folders:[[NSArray alloc] init] onSuccess:nil];
}

}

}

[TmpDiskManager autoCreateVolumesWithNames:nil];
[TmpDiskManager autoCreateVolumesWithNames:nil];
}

- (void)awakeFromNib {
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
statusItem.menu = statusMenu;
statusItem.image = [NSImage imageNamed:@"status.png"];
[statusItem setHighlightMode:YES];
[self newTmpDiskCreated:nil];
// Add a notification watcher to watch for disks added to refresh the menu
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newTmpDiskCreated:) name:@"TmpDiskCreated" object:nil];
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(diskUnmounted:) name:NSWorkspaceDidUnmountNotification object:nil];

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
statusItem.menu = statusMenu;
statusItem.image = [NSImage imageNamed:@"status.png"];
[statusItem setHighlightMode:YES];

[self newTmpDiskCreated:nil];


// Add a notification watcher to watch for disks added to refresh the menu
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newTmpDiskCreated:) name:@"TmpDiskCreated" object:nil];

[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(diskUnmounted:) name:NSWorkspaceDidUnmountNotification object:nil];

}

- (void)diskUnmounted:(NSNotification *)notification {
// Piggyback off a new disk created call when we hear the system unmounted a disk
// Clear the menu and redraw with al the valid volumes, sans any that were removed in finder or another app
[self newTmpDiskCreated:notification];

// Piggyback off a new disk created call when we hear the system unmounted a disk
// Clear the menu and redraw with al the valid volumes, sans any that were removed in finder or another app
[self newTmpDiskCreated:notification];

}

- (void)newTmpDiskCreated:(NSNotification *)notification {

NSError *e = nil;
NSArray *volumes = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Volumes" error:&e];

if (e != nil) {
NSAlert *a = [NSAlert alertWithError:e];
[a runModal];
return;
}

// We have a new disk so remove all the old ones and rebuild the menu
[diskMenu removeAllItems];

for (NSString *s in volumes) {

if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/Volumes/%@/.tmpdisk", s]]) {
continue;
}

NSMenuItem *mi = [[TmpDiskMenuItem alloc] initWithTitle:s action:@selector(tmpDiskSelected:) keyEquivalent:@""
recreateBlock:^(NSString* s){

// Recreate Block passed to menu to run when the recreate button is clicked for a TmpDisk

[statusMenu cancelTrackingWithoutAnimation];

[self ejectVolumeWithName:s recreate:YES];

return;

}
ejectBlock:^(NSString* s){

// Eject Block passed to menu to run when the eject button is clicked for a TmpDisk

[statusMenu cancelTrackingWithoutAnimation];

[self ejectVolumeWithName:s recreate:NO];

return;
NSError *e = nil;
NSArray *volumes = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Volumes" error:&e];

if (e != nil) {
NSAlert *a = [NSAlert alertWithError:e];
[a runModal];
return;
}
];

[diskMenu addItem:mi];
// We have a new disk so remove all the old ones and rebuild the menu
[diskMenu removeAllItems];

for (NSString *s in volumes) {

}
if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/Volumes/%@/.tmpdisk", s]]) {
continue;
}

NSMenuItem *mi = [[TmpDiskMenuItem alloc] initWithTitle:s action:@selector(tmpDiskSelected:) keyEquivalent:@""
recreateBlock:^(NSString* s){

// Recreate Block passed to menu to run when the recreate button is clicked for a TmpDisk

[statusMenu cancelTrackingWithoutAnimation];

[self ejectVolumeWithName:s recreate:YES];

return;

}
ejectBlock:^(NSString* s){

// Eject Block passed to menu to run when the eject button is clicked for a TmpDisk

[statusMenu cancelTrackingWithoutAnimation];

[self ejectVolumeWithName:s recreate:NO];

return;

}
];

[diskMenu addItem:mi];

}

}

- (void)ejectVolumeWithName:(NSString *)name recreate:(BOOL)recreate {
[TmpDiskManager ejectVolumesWithNames:[NSSet setWithObject:name]
recreate:recreate];
[TmpDiskManager ejectVolumesWithNames:[NSSet setWithObject:name]
recreate:recreate];
}

- (void)tmpDiskSelected:(id)sender {

// When a tmpDisk menu option is selected, we open the volume in Finder
// When a tmpDisk menu option is selected, we open the volume in Finder

NSString *s = [sender title];
NSString *s = [sender title];

[TmpDiskManager openVolumeWithName:s];
[TmpDiskManager openVolumeWithName:s];
}

@end
Oops, something went wrong.

0 comments on commit de8b127

Please sign in to comment.
You can’t perform that action at this time.