[UWP] [C ++] WinRT文件访问 [英] [UWP][C++] WinRT file access

查看:98
本文介绍了[UWP] [C ++] WinRT文件访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中是否有WinRT文件访问指南?我想了解一下可以访问哪些文件,每个平台的具体内容等等?

Is there a guide to file access from WinRT in C++? I would like to read about what kinds of files can be accessed, what is specific to each platform, etc?

通用应用程序应该在台式机/笔记本电脑上运行(在Windows 10上), 平板电脑和手机上。每种情况都有哪些限制?例如,如果应用程序在台式机/笔记本电脑上运行,那么能够从
a桌面应用程序访问相同的文件是合理的吗?

Universal apps are supposed to run (on windows 10) on desktop/laptops,  tablets and on phones. What are the restrictions in every case? For example if the app runs on a desktop/laptop, it is reasonable to be able to access the same files I can from a desktop application isn't it?

另外,我正在寻找一个API来接受一个文件名并返回一个StorageFolder对象。我不希望任何异步方式加载文件,或打开文件的异步方式等。 如果我需要,我可以自己进行异步处理。

Also, I was looking for an API to just accept a file name and return an object of StorageFolder. I do not want any async way of loading the file, or async way of opening the file, etc.  I can do async handling myself if I need it.

顺便说一句,我在WinRT中看到(几乎)一切都是异步的?!为什么我需要启动任何异步操作(例如)读取一个小配置文件,只读它会更快?

BTW, I read that in WinRT (almost) everything is async?! Why would I for example need to start any async operation to (for example) read a small config file, when just read it will be faster?

我想我需要一些文档来真正理解WinRT背后的概念,更具体地说是文件IO!

I guess I need some docs to really understand the concepts behind the WinRT and more specifically file IO!

谢谢,

G。

推荐答案

欢迎来到开发通用Windows应用论坛! 

请阅读粘性帖子,特别是  发布指南:主题行标签 &absp; 已知的
Windows 10 SDK和工具的问题 

Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools 

您可以在文件中找到文档处理
访问数据和文件
部分文档。

You can find documentation on file handling in the Accessing data and files section of the documentation.

通用应用程序运行沙盒并且对文件系统的访问权限非常有限。在大多数情况下,他们只能直接访问他们的安装文件夹和他们的应用程序数据文件夹。他们无权访问其他地方的文件系统(请参阅
文件访问权限和权限以获取更多详细信息。)

Universal apps run sandboxed and have very limited access to the file system. For the most part, they can directly access only their install folder and their application data folder. They do not have permission to access the file system elsewhere (see File access and permissions for more details).

在这些位置内,您的应用可以使用普通的C ++(fopen等)或Win32(CreateFile2等)调用。在这些位置之外,应用程序需要用户的许可才能通过StorageItem API获得代理访问权限。我在
中更详细地讨论了这个我的博客条目 跳过路径:坚持使用StorageFile

Inside those locations your app can use normal C++ (fopen, etc.) or Win32 (CreateFile2, etc.) calls. Outside of those locations the app needs permission from the user to get brokered access via the StorageItem API. I discuss this in more detail in my blog entry Skip the path: stick to the StorageFile .

之所以可以花费超过50毫秒是异步的是因为用户的一个主要抱怨是应用UI没有响应。虽然顶级开发人员可以处理将可能冗长的同步操作移动到工作线程
本身,但这样做很复杂并且让操作系统处理这种操作要简单得多。如果你知道你打开一个小的本地文件并且它总是很快,或者如果你知道你已经在工作线程上进行了文件访问,那么你可以使用同步API
在您的应用数据和已安装的位置。


这篇关于[UWP] [C ++] WinRT文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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