gpt4 book ai didi

objective-c - 为 Wine 和一些 .exe 文件创建包装器应用程序

转载 作者:搜寻专家 更新时间:2023-10-30 20:19:30 25 4
gpt4 key购买 nike

我正在尝试编写一个将 wine 和一些 .exe 文件包装在一起的应用程序。该应用程序将挂载 WineBottlerCombo_1.2.5.dmg 文件,然后它应自动将已挂载 Wine 的正确内容复制到应用程序文件夹。完成后,它应该运行一个 .exe 文件(由我指定)。

我的问题是:

  • 如何在不自动打开已挂载的 .dmg 文件的情况下挂载 .dmg 文件
  • 如何将安装的 .dmg 文件的内容复制到应用程序文件夹
  • 完成所有这些后,如何使用 Objective-C 运行 .exe 文件

我真的是Objective-C的初学者,但我正在努力解决这个问题。我首先在 Xcode 中创建 Cocoa 应用程序。在此之后,我设法使用此代码挂载 .dmg 文件(它会自动打开已挂载的 .dmg 文件,最好阻止它):

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];

在此之后,我尝试借助以下代码将挂载的 .dmg 文件内容复制到应用程序文件夹:

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);
}

不幸的是,这不会将这些文件移动到应用程序文件夹中。我调试了它,它进入了 if 语句,所以它为真,但没有文件被移动到应用程序文件夹。

这就是我被卡住的地方。我试图在互联网上搜索,但我无法获得任何关于如何继续前进的信息,所以我想我在这里问一下。

在此先感谢您的帮助。

编辑:

我检查了 NSFileManager copyItemPath 中的第三个参数,它表示如下:

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"}

我不明白为什么它说没有这样的文件或目录,因为在程序挂载它之后我在终端中检查了这个路径并且路径是正确的,文件在那里。

编辑编辑:

第一个EDIT报错的解决方法:

我注意到我留下了要复制的文件的扩展名。所以正确的代码看起来像这样:

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);
}

最佳答案

  • 关于挂载:参见man hdiutil,看起来您需要传递-nobrowse 参数。
  • 复制:我建议您将第三个参数传递给该方法 (error:),看看它说了什么。
  • 要运行 .exe 文件,您可能需要运行将 .exe 文件作为参数传递的 wine 可执行文件。与第一种情况相同的方法:使用 NSTask

关于objective-c - 为 Wine 和一些 .exe 文件创建包装器应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16361912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com