#import <Foundation/Foundation.h>
// This helper application haves the functionality needed under root for the main installer application.
// Basically, it is a clone of the "mv" utility, with some tweaks for setting permissions and ownership on the files.
// This code (c) by The MacVidia Project - 2006.
// DiegoMax - August 2006
// Compiled with Intel compiler.
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
{
// Here im being sure that i have 3 args (1: path 2: source 3: destination).
// Quiting if NOT and logging error.
if (argc != 3) return -1;
NSString * source = [NSString stringWithUTF8String:argv[1]];
NSString * destination = [NSString stringWithUTF8String:argv[2]];
NSString * owner;
owner = @"system";
NSMutableDictionary * attribs = [NSMutableDictionary dictionaryWithCapacity: 2];
// I should improve this part later, but it does the job right now.
[attribs setObject: [NSString stringWithString:@"root"] forKey: NSFileOwnerAccountName];
[attribs setObject: [NSString stringWithString:@"wheel"] forKey: NSFileGroupOwnerAccountName];
source = [source stringByStandardizingPath];
destination = [destination stringByStandardizingPath];
printf("Moving \"%s\" to \"%s\"...",[source UTF8String],[destination UTF8String]);
// REMEMBER: Calling this on a separate thread from the main installer, careful what you do here!
// REMEMBER: Should add later some improvments to these routines, like double checking permissions and backup of old files
// on a repository container.
NSFileManager * manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:source])
{
printf("failed\n***No source file at \"%s\".\n",[source UTF8String]);
return -1;
}
if ([manager fileExistsAtPath:destination]){
[manager removeFileAtPath:destination handler:nil];
NSLog(@"Found old MacVidia Kext....deleting");
if ([manager movePath:source toPath:destination handler:nil]){
NSLog(@"New kext copied OK.");
}
printf("done\n");
} else {
NSLog(@"No old kexts were found, copying new ones!");
if ([manager movePath:source toPath:destination handler:nil]){
NSLog(@"New kext copied OK.");
}
printf("done\n");
}
// MAYBE ANOTHER API BUG HERE ? ? ? ? ? ?
// THIS ROUTINE SOMETIMES DONT WORK; I need to debug a lot yet, but i think its not MY fault.
if ([manager changeFileAttributes:attribs atPath:destination])
{
NSLog(@"Permissions applied OK to %@", destination);
}
}
[pool release];
// Everything is OK.
return 0;
}