问题
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