Linux中的SHGetKnownFolderPath等效API [英] SHGetKnownFolderPath equivalent API in Linux

查看:79
本文介绍了Linux中的SHGetKnownFolderPath等效API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Windows的某些功能移植到linux,并且发现在Linux中很难匹配SHGetKnownFolderPath的功能.其实glib中有一个API负责这部分,但是我不想在这里使用该库.另外,链接通过在.bashrc中导出变量来做到这一点,但我很喜欢linux API这样做的.

此处它的解释方式类似于如何访问xdg-user-dir.还有其他方法可以这样做吗,否则我会坚持下去.请对此有所了解.

解决方案

Linux桌面的状态令人难过,特别是对于这种情况.有 一些FreeDesktop标准,但是在一致性和向后兼容性方面都没有Windows Shell API.

话虽如此,以我的经验,最安全的方法是依赖XDG的实用程序,尤其是您所用的xdg-user-dir( 的测试(IOW:如果有人编写的配置使xdg utils收支平衡,则很可能会对其进行修复;如果这是不合规格的垃圾,恰好与xdg utils一起使用时,他们可能不会注意到).

请不要尝试对此类内容过于机灵. Firefox试图与Linux上的文件关联变得更聪明,单击它中的打开文件夹"会打开随机应用程序已有10年了(据记录,在我的盒子里,它非常喜欢打开Gwenview;过去它更喜欢FileLight). /p>

I'm porting some functionality from windows to linux and I'm finding it harder to match the functionality of SHGetKnownFolderPath in linux. Actually there is an API in glib which dose this part but I do not want to use that library here. Also the link does that by exporting variables in .bashrc but I fancy about linux API which does this.

Also the here it is explained like how to access xdg-user-dir. IS there any other way of doing this otherwise I'll stick to this.Please shed some light on this.

解决方案

The status of the Linux desktop is a sad mess, especially for this kind of stuff. There are some FreeDesktop standards, but nothing close to Windows Shell APIs for both consistency and commitment to backwards compatibility.

That being said, in my experience the safest thing to do is relying on utilities from XDG, in particular xdg-user-dir in your case (xdg utils can come in handy in other cases); nowadays they are almost universally installed, and they usually do the "right" thing. Also, many packages rely on them, so it's likely that any DE tests the integration at least on them (IOW: if someone writes configuration that breaks even xdg utils it's likely that they'll fix it; if it's out of spec garbage that happens to work with xdg utils they may not notice).

Please don't try to be too clever with this kind of stuff. Firefox tries to be clever with file associations on Linux and it's 10 years that clicking "open folder" in it opens random applications (for the record, on my box it's extremely fond of opening Gwenview; in the past it liked more FileLight).

这篇关于Linux中的SHGetKnownFolderPath等效API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆