Permalink
Browse files

Work on a function to maintain the version sync of macfusion's multip…

…le parts
  • Loading branch information...
1 parent 8a1d8ca commit f49f0da944fad5b49591c3b96e33e3975c3f744c Michael Gorbach committed May 29, 2008
Showing with 78 additions and 55 deletions.
  1. +0 −2 FTPFS/FTPFSDelegate.m
  2. +1 −3 MFCore.h
  3. +77 −50 MFCore.m
View
@@ -55,7 +55,6 @@ - (NSArray*)secretsClientsList;
#pragma mark Mounting
- (NSArray*)taskArgumentsForParameters:(NSDictionary*)parameters
{
- // MFLogS(self, @"Parameters received %@", parameters);
NSMutableArray* arguments = [NSMutableArray array];
[arguments addObject: [NSString stringWithFormat:@"%@:%@/%@",
[parameters objectForKey: kNetFSHostParameter],
@@ -85,7 +84,6 @@ - (NSDictionary*)taskEnvironmentForParameters:(NSDictionary*)params
forKey: @"FTPFS_TOKEN"];
[env setObject: [self askpassPath] forKey:@"FTPFS_ASKPASS"];
- // MFLogS(self, @"Returning environment %@", env);
return [env copy];
}
View
@@ -31,13 +31,11 @@ NSString* mfcAgentBundlePath();
// Launch Services and Login Items Control
BOOL mfcGetStateForAgentLoginItem();
BOOL mfcSetStateForAgentLoginItem(BOOL state);
-BOOL mfcGetStateForMenulingLoginItem();
-BOOL mfcSetStateForMenulingLoginItem(BOOL state);
// Clients
BOOL mfcClientIsUIElement();
void mfcLaunchAgent();
-
+void mfcLaunchMenuling();
// FUSE versioning
NSString* mfcGetMacFuseVersion();
View
127 MFCore.m
@@ -32,7 +32,6 @@
pathToReturn = [fullPath stringByStandardizingPath];
}
- // MFLogS(self, @"Returning %@ for main bundle path", pathToReturn);
return pathToReturn;
}
@@ -63,13 +62,11 @@
NSBundle* menulingUIBundle = [NSBundle bundleWithPath: mfcMenulingBundlePath()];
[clientList addObject: [menulingUIBundle executablePath]];
[clientList addObject: mfcAgentBundlePath()];
- // MFLogS(self, @"Client list for fs %@ is %@", fs, clientList);
return [clientList copy];
}
BOOL mfcGetStateOfLoginItemWithPath( NSString* path )
{
- // MFLogS(self, @"Querying for %@", path);
LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
BOOL present = FALSE;
UInt32 seedValue;
@@ -80,12 +77,10 @@ BOOL mfcGetStateOfLoginItemWithPath( NSString* path )
NSURL* theURL = [NSURL new];
LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*)&theURL, NULL);
present = ([[theURL path] isEqualToString: path]);
- // MFLogS(self, @"Found %@", [theURL path]);
if (present)
break;
}
- // MFLogS(self, @"Returning state %d for %@", present, path);
CFRelease(loginItemsRef);
return present;
}
@@ -96,18 +91,10 @@ BOOL mfcGetStateForAgentLoginItem()
return mfcGetStateOfLoginItemWithPath( agentPath );
}
-BOOL mfcGetStateForMenulingLoginItem()
-{
- NSString* menulingBundlePath = mfcMenulingBundlePath();
- return mfcGetStateOfLoginItemWithPath(menulingBundlePath);
-}
-
-# pragma mark TODO: Unify these two functions
BOOL mfcSetStateForAgentLoginItem(BOOL state)
{
NSString* agentPath = mfcAgentBundlePath();
LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
- // MFLogS(self, @"agentBundlePath set %@", agentPath);
if (mfcGetStateOfLoginItemWithPath(agentPath) == state)
return NO;
@@ -122,7 +109,6 @@ BOOL mfcSetStateForAgentLoginItem(BOOL state)
NSString* checkPath = [[theURL path] lastPathComponent];
if ([checkPath isLike: @"*macfusionAgent*"])
{
- // MFLogS(self, @"Removing %@", theURL);
LSSharedFileListItemRemove(loginItemsRef, itemRef);
}
}
@@ -137,41 +123,6 @@ BOOL mfcSetStateForAgentLoginItem(BOOL state)
return YES;
}
-
-
-BOOL mfcSetStateForMenulingLoginItem(BOOL state)
-{
- NSString* menulingBundlePath = mfcMenulingBundlePath();
- LSSharedFileListRef loginItemsRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
-
- if (mfcGetStateOfLoginItemWithPath(menulingBundlePath) == state)
- return NO;
-
- UInt32 seedValue;
- NSArray *loginItems = (NSArray *)LSSharedFileListCopySnapshot(loginItemsRef, &seedValue);
- for(id loginItem in loginItems)
- {
- LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)loginItem;
- NSURL* theURL = [NSURL new];
- LSSharedFileListItemResolve(itemRef, 0, (CFURLRef*)&theURL, NULL);
- NSString* checkPath = [[theURL path] lastPathComponent];
- if ([checkPath isEqualToString: @"MacfusionMenuling.app"])
- {
- // MFLogS(self, @"Removing %@", theURL);
- LSSharedFileListItemRemove(loginItemsRef, itemRef);
- }
- }
-
- if(state == YES)
- {
- LSSharedFileListInsertItemURL(loginItemsRef, kLSSharedFileListItemLast, NULL, NULL,
- (CFURLRef)[NSURL fileURLWithPath: menulingBundlePath], NULL, NULL);
- }
-
- CFRelease(loginItemsRef);
- return YES;
-}
-
NSString* mfcGetMacFuseVersion()
{
NSDictionary* fuseData = [NSDictionary dictionaryWithContentsOfFile:
@@ -190,4 +141,80 @@ void mfcLaunchAgent()
{
NSString* path = mfcAgentBundlePath();
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:[NSArray arrayWithObject: path]];
-}
+}
+
+void mfcLaunchMenuling()
+{
+ NSString* path = mfcMenulingBundlePath();
+ [NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:[NSArray arrayWithObject: path]];
+}
+
+// Checks the integrity of Macfusion2's multi-process system
+// Make sure we are all running from the same bundle and speaking the same language
+void mfcCheckIntegrity()
+{
+ ProcessSerialNumber currentPSN = { 0, kNoProcess };
+ CFStringRef processName;
+ FSRef bundleFSRef;
+ OSErr getBundleError;
+ id runningAgentPath, runningMenulingPath;
+ pid_t runningAgentPID, runningMenulingPID;
+
+ while(GetNextProcess( &currentPSN ) == noErr
+ && currentPSN.lowLongOfPSN != kNoProcess )
+ {
+ NSString* processPath;
+ CopyProcessName( &currentPSN, &processName );
+ pid_t processPID;
+
+ if ( [ (NSString*)processName isEqualToString: @"macfusionAgent" ] ||
+ [ (NSString*)processName isEqualToString: @"macfusionMenuling"] )
+ {
+ getBundleError = GetProcessBundleLocation( &currentPSN, &bundleFSRef);
+ GetProcessPID( &currentPSN , &processPID);
+
+ if (getBundleError == noErr)
+ {
+ CFURLRef bundleURLRef = CFURLCreateFromFSRef( kCFAllocatorDefault, &bundleFSRef);
+ processPath = [ (NSURL*)bundleURLRef path ];
+ CFRelease( bundleURLRef );
+ }
+ else
+ {
+ processPath = (NSString*)[NSNull null];
+ // Set the processPath to NSNull if we failed getting it
+ // This can happen if the process is running from the trash (i.e. it's been deleted)
+ }
+ }
+
+ if ( [ (NSString*)processName isEqualToString: @"macfusionAgent"] )
+ {
+ runningAgentPath = processPath;
+ runningAgentPID = processPID;
+ }
+
+ if ( [ (NSString*)processName isEqualToString: @"macfusionMenuling"] )
+ {
+ runningMenulingPath = processPath;
+ runningMenulingPID = processPID;
+ }
+
+ CFRelease( processName );
+ }
+
+ if (runningAgentPath == [NSNull null] ||
+ ( runningAgentPath && ![runningAgentPath isEqualToString: mfcAgentBundlePath()] ) )
+ {
+ // Agent is in the trash or running from the wrong path. Kill it & restart it.
+ kill( runningAgentPID, SIGKILL);
+ mfcLaunchAgent();
+ }
+
+ if (runningMenulingPath == [NSNull null] ||
+ (runningMenulingPath && ![runningMenulingPath isEqualToString: mfcMenulingBundlePath()] ) )
+ {
+ // Menuling is in the trash or running from the wrong path. Kill it & restart it.
+ kill( runningMenulingPID, SIGKILL );
+ mfcLaunchMenuling();
+ }
+}

0 comments on commit f49f0da

Please sign in to comment.