如何在UWP项目中监视文件更改? [英] How can I watch for file changes in a UWP project?

查看:51
本文介绍了如何在UWP项目中监视文件更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将游戏从完整的桌面.net移植到UWP,我需要解决的一件事是如何将纹理,着色器等实时加载到游戏的UWP版本中.

I am porting my game to UWP from the full desktop .net and one thing I need to work out is how to live load texture, shaders etc... into the UWP version of the game.

在台式机版本中,我使用FileSystemWatcher来执行此操作,但是FileSystemWatcher在UWP中并不存在,即使在我完全控制的目录中也是如此.

In the desktop version I use a FileSystemWatcher to do this but FileSystemWatcher doesn't exist in UWP, even on directory's that I have full control over.

UWP是否等效?

在UWP中使用有限的一组API来实现此目的的最佳方法是什么?

What is the best way to implement this with the limited set of API's in UWP?

推荐答案

UWP是否等效?

Is there an equivalent for UWP?

您可以订阅

You can subscribe the ContentChanged event for the queried storage files.

例如:

List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".txt");
fileTypeFilter.Add(".png");
var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);
var query = ApplicationData.Current.LocalFolder.CreateFileQueryWithOptions(options);
//subscribe on query's ContentsChanged event
query.ContentsChanged += Query_ContentsChanged;
var files = await query.GetFilesAsync();

private void Query_ContentsChanged(Windows.Storage.Search.IStorageQueryResultBase sender, object args)
{
    //TODO:
}

此操作将搜索并返回应用程序本地文件夹中的所有.txt和.png文件,如果将查询中的文件添加,删除或修改,则将触发此事件.

This searches and returns all .txt and .png files in app's local folder, if the files in the query are added to, deleted from, or modified, this event will be fired.

这篇关于如何在UWP项目中监视文件更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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