原文链接: http://www.cnblogs.com/zouzf/p/3972457.html

读写文件Cocos已经用fopen fwrite来做好了,这里说的主要是文件和文件夹的创建、删除、判断是否存在等。

本来打算把把这部分代码放到C#工程来做,然后通过上一篇说到的C++和C#交互的那个通道来调用的,但是wp8里很多东西都被做成异步的形式了,文件的读写操作也被设计成了异步的形式,但是在C++这边发起调用的方法是需要同步调用的,这里如何转换是一个难题,由于对task PPL 那一套不熟悉,最后没办法只能放到C++工程来做。

另外,在task里那个捕获异常也是很痛苦的一件事情——一直没研究透彻task,所以代码实现得比较挫

 bool WZFileUtilWP8::makeDirectory(const std::string& dirPath)
{ auto localFolder = Windows::Storage::ApplicationData::Current->LocalFolder;
Platform::String ^pStr_FileName = ref new Platform::String(WZCallCS_And_Back_CommonFunc::stringToWString(dirPath.c_str()).c_str()); create_task(localFolder->CreateFolderAsync(pStr_FileName, CreationCollisionOption::ReplaceExisting)).wait(); CCLog("craete folder: %s success\n", dirPath.c_str());
return true; } bool WZFileUtilWP8::removeDirectory(const std::string& dirName)
{
//return callCS->FunCallCS_RemoveDirectory(dirName.c_str()); //删除不存在的文件夹会抛出异常,但这异常在task里捕获真TM蛋疼
//现在通过先创建一个和要删除的文件夹同名的文件夹再删除来间接实现 auto localFolder = Windows::Storage::ApplicationData::Current->LocalFolder;
Platform::String ^pStr_dirName = ref new Platform::String(WZCallCS_And_Back_CommonFunc::stringToWString(dirName.c_str()).c_str()); this->makeDirectory(dirName); create_task(localFolder->GetFolderAsync(pStr_dirName)).then([](StorageFolder^ folder)
{
folder->DeleteAsync();
}).wait(); CCLog("remove folder: %s success\n", dirName.c_str());
return true;
} bool WZFileUtilWP8::isFullPathExist(const std::string &fullPath)
{
auto localFolder = Windows::Storage::ApplicationData::Current->LocalFolder;
Platform::String ^pStr_fulaPathName = ref new Platform::String(WZCallCS_And_Back_CommonFunc::stringToWString(fullPath.c_str()).c_str()); //还是异常捕获太蛋疼,直接创建吧,总是返回true
create_task(localFolder->CreateFileAsync(pStr_fulaPathName, CreationCollisionOption::OpenIfExists)).wait(); CCLog("file: %s is exist\n", fullPath.c_str());
return true;
} //根据一个多级 目录 的字符串创建目录及文件
bool WZFileUtilWP8::makeFullPath(const std::string& fullTargetPath)
{ //wp8可以直接创建多级目录
//return callCS->FunCallCS_CreateFullPathFile(fullPath.c_str()); auto localFolder = Windows::Storage::ApplicationData::Current->LocalFolder;
Platform::String ^pStr_fullPathName = ref new Platform::String(WZCallCS_And_Back_CommonFunc::stringToWString(fullTargetPath.c_str()).c_str());
create_task(localFolder->CreateFileAsync(pStr_fullPathName, CreationCollisionOption::ReplaceExisting)).wait(); CCLog("create file: %s success\n", fullTargetPath.c_str()); return true; }

原文链接: http://www.cnblogs.com/zouzf/p/3972457.html

最新文章

  1. Design Tic-Tac Toe
  2. 关于Bugzilla WebService接口
  3. 报表开发工具中开放的部分图表js接口列表
  4. mvn生成runnablejar 的方法
  5. 【转载】一步一步搭建自己的iOS网络请求库
  6. JavaScript正则表达式之分组匹配 / 反向引用
  7. Java多线程学习之线程池源码详解
  8. ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十七节--Quartz与ABP框架Abp.Quartz及扩展
  9. python_如何实现可迭代对象和迭代器对象?
  10. cryptoJS
  11. How to remove popup on boot on Windows 2003
  12. 异步ztree 加复选框 及相应后台处理
  13. spring cloud: 使用consul来替换eureka
  14. ueditor上传图片配置成功,但是如何删除无用的图片
  15. Ubuntu/CentOs 搭建SVN服务器
  16. 小试maven工程
  17. 安装SQL2008时显示必须重启计算机才可以继续安装的错误—解决办法
  18. ps切图步骤
  19. JQuery中的动画(ppt)
  20. linux ip别名和辅助ip地址

热门文章

  1. 内存空间申请(C)
  2. js yield
  3. OpenGL ES andoid学习————2
  4. C++中的return返回值:return0 or return -1?
  5. Django项目笔记:sessions处理以及复杂对象序列化
  6. Achartengine.jar绘制动态图形-饼图
  7. Win7系统安装 MySQL 5.7.23
  8. IDEA错误的将所有代码文件都加入版本控制
  9. C++常备知识总结
  10. Bootstrap支持的JavaScript插件