Reputation: 2713
I am trying to write an application which wraps wine and some .exe file together. The application would mount the WineBottlerCombo_1.2.5.dmg file and then it should copy the right contents of the mounted Wine to the Application folder automatically. After this is done, it should run a .exe file (specified by me).
My questions are:
I am really a beginner in Objective-C, but I am trying to solve this problem. I started this by creating Cocoa application in Xcode. After this I manged to mount the .dmg file with this code (tho it opens automatically the mounted .dmg file, would be great to block that):
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/hdiutil"];
[task setArguments:
[NSArray arrayWithObjects: @"attach", @"/Users/<myusername>/Documents/temporary/WineBottlerCombo_1.2.5.dmg", nil]];
[task launch];
[task waitUntilExit];
if (0 != [task terminationStatus])
NSLog(@"Mount failed.");
[task release];
After this I tried to copy the mounted .dmg file content to the Application folder with the help of this code:
if( [[NSFileManager defaultManager] isReadableFileAtPath: @"/Volumes/WineBottler Combo"] ) {
[[NSFileManager defaultManager] copyItemAtPath: @"/Volumes/WineBottler Combo/Wine" toPath: @"/Volumes/WineBottler Combo/Applications" error:nil];
[[NSFileManager defaultManager] copyItemAtPath: @"/Volumes/WineBottler Combo/WineBottler" toPath: @"/Volumes/WineBottler Combo/Applications" error:nil];
}
else {
NSString* message = @"ERROR while moving file!";
NSLog(@"%@", message);
}
Unfortunetly this doesn't moves those files to the Application folder. I debuged it, and it gets into the if statment, so it gets true, but no files are moved to the Application folder.
This is where I got stucked. I tried to search the internet, but I couldn't get any information how to move on yet, so I thought I ask it here.
Thanks in advance for any help.
EDIT:
I checked the third parameter in NSFileManager copyItemPath and it says the following:
2013-05-04 11:16:03.493 TestApp_MacOSX_installer[10284:303] Write failed with error: Error Domain=NSCocoaErrorDomain Code=260 "The file “Wine” couldn’t be opened because there is no such file." UserInfo=0x10015a530 {NSFilePath=/Volumes/WineBottler Combo/Wine, NSUnderlyingError=0x10015a430 "The operation couldn’t be completed. No such file or directory"}
I don't why it says no such file or directory, because after the program mounts it I checked this path in terminal and the path is correct, the file is there.
EDIT EDIT:
Solution to the first EDIT error message:
I noticed that I left the extension of the file which I wanted to copy. So the right code looks like this:
if( [[NSFileManager defaultManager] isReadableFileAtPath: @"/Volumes/WineBottler Combo"] ) {
[[NSFileManager defaultManager] copyItemAtPath: @"/Volumes/WineBottler Combo/Wine.app" toPath: @"/Volumes/WineBottler Combo/Applications/Wine.app" error:&anyError];
NSLog(@"Write failed with error: %@", anyError);
[[NSFileManager defaultManager] copyItemAtPath: @"/Volumes/WineBottler Combo/WineBottler.app" toPath: @"/Volumes/WineBottler Combo/Applications/WineBottler.app" error:nil];
NSLog(@"Write failed with error: %@", anyError);
}
else {
NSString* message = @"ERROR while moving file!";
NSLog(@"%@", message);
}
Upvotes: 3
Views: 835
Reputation: 3277
man hdiutil
, looks like you need to pass -nobrowse
argument.error:
) and see what it says.Upvotes: 2