Pergunta

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:

  • How can I mount the .dmg file without automatically open the mounted .dmg file
  • How can I copy the content of the mounted .dmg file to the Application folder
  • After all this is done, how can I run with Objective-C the .exe file

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);
}
Foi útil?

Solução

  • About the mount: see the man hdiutil, looks like you need to pass -nobrowse argument.
  • Copying: I suggest you to pass the third parameter to the method (error:) and see what it says.
  • To run the .exe file you probably need to run the wine executable passing the .exe file as an argument. Same approach as in first scenario: use NSTask
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top