Changeset 1160

Show
Ignore:
Timestamp:
02/23/2010 02:27:17 PM (2 years ago)
Author:
gbooker
Message:

Added code to install passthrough component

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/PlayerFramework/CommonMediaPlayer/Classes/CMPPlayerManager.h

    r1152 r1160  
    2323#import "CMPTypesDefines.h" 
    2424 
     25#include <sys/mount.h> 
     26 
    2527@protocol CMPPlayerController, CMPPlayer; 
    2628 
     
    7779           return NO; 
    7880        return [fm createDirectoryAtPath:directory attributes:nil]; 
     81} 
     82 
     83static inline BOOL installPassthroughComponent(NSFileManager *fm, NSString *passPath) 
     84{ 
     85        //We have a copy, must have had permission to distribute it 
     86        struct statfs slashStat; 
     87        if(statfs("/", &slashStat) == -1) 
     88                return NO; 
     89         
     90        BOOL success = YES; 
     91        int status; 
     92        AuthorizationItem authItems[2] = { 
     93                {kAuthorizationEnvironmentUsername, strlen("frontrow"), "frontrow", 0}, 
     94                {kAuthorizationEnvironmentPassword, strlen("frontrow"), "frontrow", 0}, 
     95        }; 
     96        AuthorizationEnvironment environ = {2, authItems}; 
     97        AuthorizationItem rightSet[] = {{kAuthorizationRightExecute, 0, NULL, 0}}; 
     98        AuthorizationRights rights = {1, rightSet}; 
     99        AuthorizationRef auth; 
     100        OSStatus result = AuthorizationCreate(&rights, &environ, kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights, &auth); 
     101        if(result == errAuthorizationSuccess) 
     102        { 
     103                BOOL readonly = slashStat.f_flags & MNT_RDONLY; 
     104                 
     105                if(readonly) 
     106                { 
     107                        char *command = "mount -uw /"; 
     108                        char *arguments[] = {"-c", command, NULL}; 
     109                        result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); 
     110                        wait(&status); 
     111                        FrameworkLoadPrint(@"Set to read-write with status %d", status); 
     112                } 
     113                 
     114                NSString *passDest = @"/Library/Audio/Plug-Ins/HAL/"; 
     115                NSString *existingPath = [passDest stringByAppendingPathComponent:@"AC3PassthroughDevice.plugin"]; 
     116                int status = 0; 
     117                if([fm fileExistsAtPath:existingPath]) 
     118                { 
     119                        char *command = "rm -Rf \"$EXISTING\""; 
     120                        setenv("EXISTING", [existingPath fileSystemRepresentation], 1); 
     121                        char *arguments[] = {"-c", command, NULL}; 
     122                        result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); 
     123                        wait(&status); 
     124                        unsetenv("EXISTING"); 
     125                        FrameworkLoadPrint(@"Removed existing with status %d", status); 
     126                } 
     127                char *command = "cp -r \"$PASSPATH\" \"$PASSDEST\""; 
     128                setenv("PASSPATH", [passPath fileSystemRepresentation], 1); 
     129                setenv("PASSDEST", [passDest fileSystemRepresentation], 1); 
     130                char *arguments[] = {"-c", command, NULL}; 
     131                result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); 
     132                wait(&status); 
     133                unsetenv("PASSPATH"); 
     134                unsetenv("PASSDEST"); 
     135                 
     136                if(readonly) 
     137                { 
     138                        char *command = "mount -ur /"; 
     139                        char *arguments[] = {"-c", command, NULL}; 
     140                        result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); 
     141                        wait(&status); 
     142                        FrameworkLoadPrint(@"Set to read-only with status %d", status); 
     143                } 
     144        } 
     145        if(result != errAuthorizationSuccess) 
     146        { 
     147                success = NO; 
     148                FrameworkLoadPrint(@"Failed to install Passthrough component"); 
     149        } 
     150        AuthorizationFree(auth, kAuthorizationFlagDefaults); 
     151        return success; 
    79152} 
    80153 
     
    134207                success = [fm copyPath:frameworkInFrap toPath:frameworkPath handler:nil]; 
    135208                FrameworkLoadPrint(@"Copy success is %d", success); 
     209                //Check if we were allowed to distribute the passthrough component 
     210                NSString *passPath = [frameworkPath stringByAppendingPathComponent:@"Resources/AC3PassthroughDevice.plugin"]; 
     211                if([fm fileExistsAtPath:passPath]) 
     212                        installPassthroughComponent(fm, passPath); 
    136213                if(!success || needCopy(frameworkPath)) 
    137214                        //We failed in our copy too!