gpt4 book ai didi

objective-c - "/Volumes"名称是否会根据系统语言而变化,如果是,如何调整?

转载 作者:行者123 更新时间:2023-12-03 17:46:31 24 4
gpt4 key购买 nike

我使用此代码来检查客户端是否从 DMG/Volume 运行,并显示警报并退出。

private void IsRunningFromDMG()
{
var currentPath = NSBundle.MainBundle.BundlePath;

if (currentPath.StartsWith("/Volumes", StringComparison.Ordinal))
{
using (var alert = new NSAlert
{
MessageText = "Warning",
InformativeText = "You cannot run this application from DMG, drag move to the " +
"\"/Applications\" folder"
})

{
alert.RunModal();
NSApplication.SharedApplication.Terminate(null);
}
}
}

如果系统语言设置为英语,则可以。我怀疑/Volumes 是否对本地化有反应,在这种情况下该怎么做?

应该有一个系统定义的常量来处理它吗?如果是的话请帮我看看这是什么。

最佳答案

文件系统路径不会根据本地化而改变,但它们已本地化为“显示”(即图片、音乐等...将在 Finder 中本地化以显示给用户,但文件系统路径仍然是 /User/xxx/Pictures 等...)

Localized names. The system provides localized names for many system directories, such as Applications, Library, Music, Movies. An app may similarly provide localized names for itself and for any directories it creates.

Display names do not affect the actual name of the file in the file system. Code that accesses a file or directory programmatically must specify the item’s actual name when opening or manipulating the item using the file system interfaces. The only time your app should ever use display names is when displaying the name of a file or directory to the user. You can get the display name for any file or directory using the displayNameAtPath: method of NSFileManager.

var urls = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.ApplicationsDirectory, NSSearchPathDomain.System);
var applicationDisplayName = NSFileManager.DefaultManager.DisplayName(urls[0].AbsoluteString);

注意:您应该在 NSSearchPathDomain.All 域中使用 NSSearchPathDirectory.AllApplicationsDirectory 来获取您的应用程序可能/应该位于的有效“应用程序”url 列表,而不是将其硬编码到“系统”应用程序位置。

关于objective-c - "/Volumes"名称是否会根据系统语言而变化,如果是,如何调整?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56132264/

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