从文件 URL 确定 AFP 共享

发布于 2024-08-21 06:27:08 字数 592 浏览 2 评论 0原文

我编写一个应用程序将一些文件复制到某个位置。它允许用户选择始终位于 AFP 共享上的目的地。这是通过 NSOpenPanel 完成的。返回的 URL 为:file://localhost/Volumes/Oliver%20Legg's%20Backup/

我想要完成的是当应用程序启动时,如果未安装 AFP 共享,我希望它自动安装。最好的方法是什么?

“获取信息”命令将服务器列出为:afp://Power Mac G5._afpovertcp.local/Oliver%20Legg's%20Backup。如何以编程方式从文件 URL 获取此 URL?我想如果我可以获得该 URL,我可以使用 FSMountServerVolumeAsync。这是最好的(最简单、最抽象的)API 吗?

I writing an application to copy some files to a certain location. It allows the user to choose the destination, which is always on an AFP share. This is done with a NSOpenPanel. The URL that gets returned is: file://localhost/Volumes/Oliver%20Legg's%20Backup/.

What I want to accomplish is when the application is started, if the AFP share isn't mounted I want it to automatically mount it. What is the best way to do this?

The Get Info command lists the server as: afp://Power Mac G5._afpovertcp.local/Oliver%20Legg's%20Backup. How can I programatically get this URL from a file URL? I think if I could get that URL I could mount it using FSMountServerVolumeAsync. Is that the best (easiest, most abstracted) API to use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半透明的墙 2024-08-28 06:27:08

您需要使用一些较低级别的文件管理器例程来获取此信息,常规 Cocoa 调用无法做到这一点。 URL 是使用 FSCopyURLForVolume() 获取的,但您需要获取已挂载卷的卷参考号才能使用它:

#import <CoreServices/CoreServices.h>

//this is the path to the mounted network volume
NSString* pathToVolume = @"/Volumes/MountedNetworkVolume/";

//get the volume reference number
FSRef pathRef;
FSPathMakeRef((UInt8*)[pathToVolume fileSystemRepresentation],&pathRef,NULL);
FSCatalogInfo catalogInfo;
OSErr osErr = FSGetCatalogInfo(
                               &pathRef,
                               kFSCatInfoVolume,
                               &catalogInfo,
                               NULL,
                               NULL,
                               NULL
                               ) ;
FSVolumeRefNum volumeRefNum = 0;
if(osErr == noErr) 
    volumeRefNum = catalogInfo.volume;

//get the server URL for the volume
CFURLRef serverLocation;
OSStatus result = FSCopyURLForVolume (volumeRefNum,&serverLocation);
if(result == noErr)
    NSLog(@"The server location is: %@",serverLocation);
else
    NSLog(@"An error occurred: %i",result);
CFRelease(serverLocation);

FSMountServerVolumeAsync 绝对是挂载卷的正确方法远程音量。

You need to use some lower-level File Manager routines to get this information, there's no way to do it with regular Cocoa calls. The URL is obtained using FSCopyURLForVolume() but you need to get a volume reference number for the mounted volume in order to use it:

#import <CoreServices/CoreServices.h>

//this is the path to the mounted network volume
NSString* pathToVolume = @"/Volumes/MountedNetworkVolume/";

//get the volume reference number
FSRef pathRef;
FSPathMakeRef((UInt8*)[pathToVolume fileSystemRepresentation],&pathRef,NULL);
FSCatalogInfo catalogInfo;
OSErr osErr = FSGetCatalogInfo(
                               &pathRef,
                               kFSCatInfoVolume,
                               &catalogInfo,
                               NULL,
                               NULL,
                               NULL
                               ) ;
FSVolumeRefNum volumeRefNum = 0;
if(osErr == noErr) 
    volumeRefNum = catalogInfo.volume;

//get the server URL for the volume
CFURLRef serverLocation;
OSStatus result = FSCopyURLForVolume (volumeRefNum,&serverLocation);
if(result == noErr)
    NSLog(@"The server location is: %@",serverLocation);
else
    NSLog(@"An error occurred: %i",result);
CFRelease(serverLocation);

FSMountServerVolumeAsync is definitely the correct way to mount a remote volume.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文