How to prevent lost save data when upgrade app on WP8 using cpp

徘徊边缘 提交于 2019-12-08 09:16:40

问题


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

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.


回答1:


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

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.

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);
}


来源:https://stackoverflow.com/questions/15977509/how-to-prevent-lost-save-data-when-upgrade-app-on-wp8-using-cpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!