First useful piece of Mac Code!
Hey everybody...
Today in response to some of my own tinkering and the forum at http://discussions.apple.com/thread.jspa?messageID=6978579#6978579 I have created my first useful program in Objective-C and MacOS. The utility is a command line application that will mount and return the path to the Leopard time machine volume.
The utility can be downloaded here http://rapidshare.de/files/39024900/GetTimeMachinePath.html
The souce code is as follows:
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#import <CoreData/CoreData.h>
FSRef* getTimeMachineVolume()
{
NSData *timeMachinePList = [NSData dataWithContentsOfFile:@"/Library/Preferences/com.apple.TimeMachine.plist"];
NSDictionary *timeMachineProperties = [NSPropertyListSerialization propertyListFromData:timeMachinePList mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:&errorText];
AliasHandle aliasHandle = (AliasHandle)NewHandle([backupAlias length]);
[backupAlias getBytes: *aliasHandle];
Boolean wasChanged;
OSErr resultOfResolve = FSResolveAlias(NULL, aliasHandle, volumePath, &wasChanged);
if (resultOfResolve != noErr)
return nil;
DisposeHandle((Handle)aliasHandle);
return volumePath;
}
int main (int argc, const char * argv[]) {
// insert code here...
FSRef *timeMachineFSRef = getTimeMachineVolume();
[pool drain];
return 0;
}
Labels: Development
1 Comments:
I wouldn't use printf directly on an unknown string: it might crash if that string contains a percent character. I'd write something like printf("%s",str) or call directly fwrite.
By Yves, at 30/5/08 3:00 AM
Post a Comment
<< Home