使用cpp在WP8上升级应用程序时如何防止丢失保存数据 [英] How to prevent lost save data when upgrade app on WP8 using cpp

查看:35
本文介绍了使用cpp在WP8上升级应用程序时如何防止丢失保存数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cpp 没有隔离存储设置或隔离存储文件.所以我只是使用FILE"和fopen"来存储游戏数据.

cpp has no IsolatedStorageSettings or IsolatedStorageFile. so i simply using "FILE" and "fopen" to store a game data.

但是当我使用Xapdeploy"重新安装或升级应用程序或使用 vs.保存数据将丢失.那么我如何将它标记为一个孤立的存储文件.我的意思是当我升级应用程序时,该文件不会被系统删除.

but when i reinstall or upgrade the apps using "Xapdeploy" or debug with vs. the save data will lost. so how can i mark it is as a IsolatedStorageFile. I mean when I upgrade the app, the file will not deleted by system.

推荐答案

您需要将数据保存在 LocalFolder(独立存储的新名称)中才能持久保存.

You need to save data in the LocalFolder (new name for Isolated Storage) for it to be persisted.

您可以从 C++/CX 使用 Windows 运行时 API,这可能是最好的方法(特别是寻找 StorageFolder 和 StorageFile),特别是如果您想保持 Windows 应用商店应用程序的便携性.

There are Windows Runtime APIs you can use from C++/CX for this which are probably the best way to go (look for StorageFolder and StorageFile in particular), especially if you want to stay portable with Windows Store apps.

但是,如果您想使用 fopen,主要问题是这需要一个 char[],而不是 wchar_t[] 文件名,该文件名由其余部分使用平台.要解决这个问题,您需要...

However if you want to use fopen the main issue is that this takes a char[], not wchar_t[] file name that is used by the rest of the platform. To get around this you will need...

void SaveToFile()
{
    // get local folder (= isolated storage)
    auto local = Windows::Storage::ApplicationData::Current->LocalFolder;
    auto localFileNamePlatformString = local->Path + "\\game.sav";

    FILE* pFile;
    auto f = _wfopen_s(&pFile, localFileNamePlatformString->Data(), L"w");
    auto res1 = fprintf(pFile, "123456789");
    auto res2 = fclose(pFile);
}

这篇关于使用cpp在WP8上升级应用程序时如何防止丢失保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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