Skip to content

Commit de8b127

Browse files
committed
Fix issue with folders not being created on startup
1 parent 3894fd6 commit de8b127

File tree

4 files changed

+318
-307
lines changed

4 files changed

+318
-307
lines changed

TmpDisk.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,9 @@
596596
baseConfigurationReference = 00F4F36CB9136F2BB1F0A497 /* Pods-TmpDisk.debug.xcconfig */;
597597
buildSettings = {
598598
CLANG_ENABLE_OBJC_ARC = YES;
599-
CODE_SIGN_IDENTITY = "Developer ID Application";
599+
CODE_SIGN_IDENTITY = "Mac Developer";
600600
COMBINE_HIDPI_IMAGES = YES;
601+
DEVELOPMENT_TEAM = B79ZU76C43;
601602
FRAMEWORK_SEARCH_PATHS = (
602603
"$(inherited)",
603604
"\"$(SRCROOT)\"",
@@ -618,8 +619,9 @@
618619
baseConfigurationReference = 9CD599E58C7540A97A750EFD /* Pods-TmpDisk.release.xcconfig */;
619620
buildSettings = {
620621
CLANG_ENABLE_OBJC_ARC = YES;
621-
CODE_SIGN_IDENTITY = "Developer ID Application";
622+
CODE_SIGN_IDENTITY = "Mac Developer";
622623
COMBINE_HIDPI_IMAGES = YES;
624+
DEVELOPMENT_TEAM = B79ZU76C43;
623625
FRAMEWORK_SEARCH_PATHS = (
624626
"$(inherited)",
625627
"\"$(SRCROOT)\"",

TmpDisk/AppDelegate.m

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -29,131 +29,131 @@ @implementation AppDelegate
2929

3030
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
3131
{
32-
// Insert code here to initialize your application
33-
34-
// Check if TmpDisk was launched with command line args
35-
NSArray *arguments = [NSProcessInfo processInfo].arguments;
36-
37-
NSString *argName = nil;
38-
NSString *argSize = nil;
39-
// TODO: There's likely a better way to parse command line args
40-
for (NSUInteger i=0, n=arguments.count; i<n; i++) {
41-
NSString *s = arguments[i];
42-
43-
// We expect args in the format -argname=argval
44-
45-
NSArray *arg = [s componentsSeparatedByString:@"="];
46-
if (arg.count == 2) {
47-
if ([arg[0] isEqualToString:@"-name"]) {
48-
argName = [NSString stringWithString:arg[1]];
49-
} else if ([arg[0] isEqualToString:@"-size"]) {
50-
argSize = [NSString stringWithString:arg[1]];
51-
}
32+
// Insert code here to initialize your application
33+
34+
// Check if TmpDisk was launched with command line args
35+
NSArray *arguments = [NSProcessInfo processInfo].arguments;
36+
37+
NSString *argName = nil;
38+
NSString *argSize = nil;
39+
// TODO: There's likely a better way to parse command line args
40+
for (NSUInteger i=0, n=arguments.count; i<n; i++) {
41+
NSString *s = arguments[i];
42+
43+
// We expect args in the format -argname=argval
44+
45+
NSArray *arg = [s componentsSeparatedByString:@"="];
46+
if (arg.count == 2) {
47+
if ([arg[0] isEqualToString:@"-name"]) {
48+
argName = [NSString stringWithString:arg[1]];
49+
} else if ([arg[0] isEqualToString:@"-size"]) {
50+
argSize = [NSString stringWithString:arg[1]];
51+
}
52+
}
5253
}
53-
}
54-
55-
if (argName != nil && argSize != nil) {
56-
57-
int dsize = argSize.intValue;
58-
u_int64_t size = (((u_int64_t) dsize) * 1024 * 1024 / 512);
59-
60-
if(![[NSFileManager defaultManager] fileExistsAtPath:[TmpDiskManager pathForName:argName] isDirectory:nil]) {
61-
[TmpDiskManager createTmpDiskWithName:argName size:size autoCreate:NO indexed:NO hidden:NO folders:[[NSArray alloc] init] onSuccess:nil];
54+
55+
if (argName != nil && argSize != nil) {
56+
57+
int dsize = argSize.intValue;
58+
u_int64_t size = (((u_int64_t) dsize) * 1024 * 1024 / 512);
59+
60+
if(![[NSFileManager defaultManager] fileExistsAtPath:[TmpDiskManager pathForName:argName] isDirectory:nil]) {
61+
[TmpDiskManager createTmpDiskWithName:argName size:size autoCreate:NO indexed:NO hidden:NO folders:[[NSArray alloc] init] onSuccess:nil];
62+
}
63+
6264
}
63-
64-
}
6565

66-
[TmpDiskManager autoCreateVolumesWithNames:nil];
66+
[TmpDiskManager autoCreateVolumesWithNames:nil];
6767
}
6868

6969
- (void)awakeFromNib {
70-
71-
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
72-
statusItem.menu = statusMenu;
73-
statusItem.image = [NSImage imageNamed:@"status.png"];
74-
[statusItem setHighlightMode:YES];
75-
76-
[self newTmpDiskCreated:nil];
77-
78-
79-
// Add a notification watcher to watch for disks added to refresh the menu
80-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newTmpDiskCreated:) name:@"TmpDiskCreated" object:nil];
81-
82-
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(diskUnmounted:) name:NSWorkspaceDidUnmountNotification object:nil];
83-
70+
71+
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
72+
statusItem.menu = statusMenu;
73+
statusItem.image = [NSImage imageNamed:@"status.png"];
74+
[statusItem setHighlightMode:YES];
75+
76+
[self newTmpDiskCreated:nil];
77+
78+
79+
// Add a notification watcher to watch for disks added to refresh the menu
80+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newTmpDiskCreated:) name:@"TmpDiskCreated" object:nil];
81+
82+
[[NSWorkspace sharedWorkspace].notificationCenter addObserver:self selector:@selector(diskUnmounted:) name:NSWorkspaceDidUnmountNotification object:nil];
83+
8484
}
8585

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

9494
- (void)newTmpDiskCreated:(NSNotification *)notification {
95-
96-
NSError *e = nil;
97-
NSArray *volumes = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Volumes" error:&e];
98-
99-
if (e != nil) {
100-
NSAlert *a = [NSAlert alertWithError:e];
101-
[a runModal];
102-
return;
103-
}
104-
105-
// We have a new disk so remove all the old ones and rebuild the menu
106-
[diskMenu removeAllItems];
107-
108-
for (NSString *s in volumes) {
109-
110-
if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/Volumes/%@/.tmpdisk", s]]) {
111-
continue;
112-
}
113-
114-
NSMenuItem *mi = [[TmpDiskMenuItem alloc] initWithTitle:s action:@selector(tmpDiskSelected:) keyEquivalent:@""
115-
recreateBlock:^(NSString* s){
116-
117-
// Recreate Block passed to menu to run when the recreate button is clicked for a TmpDisk
118-
119-
[statusMenu cancelTrackingWithoutAnimation];
120-
121-
[self ejectVolumeWithName:s recreate:YES];
122-
123-
return;
12495

125-
}
126-
ejectBlock:^(NSString* s){
127-
128-
// Eject Block passed to menu to run when the eject button is clicked for a TmpDisk
129-
130-
[statusMenu cancelTrackingWithoutAnimation];
131-
132-
[self ejectVolumeWithName:s recreate:NO];
133-
134-
return;
96+
NSError *e = nil;
97+
NSArray *volumes = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/Volumes" error:&e];
13598

99+
if (e != nil) {
100+
NSAlert *a = [NSAlert alertWithError:e];
101+
[a runModal];
102+
return;
136103
}
137-
];
138104

139-
[diskMenu addItem:mi];
105+
// We have a new disk so remove all the old ones and rebuild the menu
106+
[diskMenu removeAllItems];
107+
108+
for (NSString *s in volumes) {
140109

141-
}
110+
if (![[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"/Volumes/%@/.tmpdisk", s]]) {
111+
continue;
112+
}
113+
114+
NSMenuItem *mi = [[TmpDiskMenuItem alloc] initWithTitle:s action:@selector(tmpDiskSelected:) keyEquivalent:@""
115+
recreateBlock:^(NSString* s){
116+
117+
// Recreate Block passed to menu to run when the recreate button is clicked for a TmpDisk
118+
119+
[statusMenu cancelTrackingWithoutAnimation];
120+
121+
[self ejectVolumeWithName:s recreate:YES];
122+
123+
return;
124+
125+
}
126+
ejectBlock:^(NSString* s){
127+
128+
// Eject Block passed to menu to run when the eject button is clicked for a TmpDisk
129+
130+
[statusMenu cancelTrackingWithoutAnimation];
131+
132+
[self ejectVolumeWithName:s recreate:NO];
133+
134+
return;
135+
136+
}
137+
];
138+
139+
[diskMenu addItem:mi];
140+
141+
}
142142

143143
}
144144

145145
- (void)ejectVolumeWithName:(NSString *)name recreate:(BOOL)recreate {
146-
[TmpDiskManager ejectVolumesWithNames:[NSSet setWithObject:name]
147-
recreate:recreate];
146+
[TmpDiskManager ejectVolumesWithNames:[NSSet setWithObject:name]
147+
recreate:recreate];
148148
}
149149

150150
- (void)tmpDiskSelected:(id)sender {
151151

152-
// When a tmpDisk menu option is selected, we open the volume in Finder
152+
// When a tmpDisk menu option is selected, we open the volume in Finder
153153

154-
NSString *s = [sender title];
154+
NSString *s = [sender title];
155155

156-
[TmpDiskManager openVolumeWithName:s];
156+
[TmpDiskManager openVolumeWithName:s];
157157
}
158158

159159
@end

0 commit comments

Comments
 (0)