Murat
Murat

Reputation: 149

What happens the Files when i update the app?

I'm developing a simple Windows Phone 8 game and suddenly a question popped up in my mind? What happens to files (ex: Score.xml) when i update the app. Update overwrites all the files or keeps them or what?

Say you have an xml (Score.xml) file which keeps the scores. This is the orginal file:

<Score>
    <LevelOne Score="0"/>
    <LevelTwo Score="0"/>
</Score>

User keeps playing the game, as you guess those Score attributes increases. After few months later, think you will gone update your game with new xml file (Score.xml):

<Score>
    <LevelOne Score="0" HowManyTimesPlayed="0"/>
    <LevelTwo Score="0" HowManyTimesPlayed="0"/>
</Score>

What happens in this situation? Now we have old Score.xml that keeps users current score information and we have new Score.xml in the update that starts from scratch with new attributes? I made my apps with database before but in this game i don't need it. I need simple xml files. Very confused right now and don't know how to search even this situation in holly google. Did i misundestood something? Guys i really need your help :/

Upvotes: 1

Views: 96

Answers (3)

yasen
yasen

Reputation: 3580

As Romasz said, you have to handle all old files in IsolatedStorage yourself. I just wanted to add a few suggestions/hints about how to do it:

  1. Know when the version has changed.
    • Keep the app's previous run version in a file. When you run the app, check if the new version is higher than the one from the file and if so - update what you need and then update the version stored in the file.
    • In some cases it's good to know by which version of the app was a file last modified. You can store the app version in that file and add some logic when the file is deserialized and the version in it is old.
  2. In some cases you may need to make changes that will make the new class incompatible with the old file. Of course, you will still want the data from the old file, so here are two ways (I can think of at the moment) that you can handle this:
    • On update, open the file as XmlDocument/XDocument and modify it accordingly to make it compatible with the new class.
    • If there are a lot of changes, create a completely new class with the new data that you want to serialize, and leave the old one untouched. Then, on update, convert the old files to the new files. (You'll be deserializing the old file as the old class and then saving a new file with the new class.)
  3. Triple check everything in the update. Deploy the old version, use it for a little and then deploy the new version to see if the update is handled correctly. (Okay that's not about handling but it's very very important.)

I hope this helps someone. :)

Update //Thanks to Romasz

You should keep update code for previous versions. Someone may for example update from version 1.3 to version 1.6, without going through versions 1.4 and 1.5. In this case, you may have several things to do on update.

Basically the code for update ends up being something like:

if (oldVersion < new Version(1, 4)) {
    //update what changed from version 1.3 to version 1.4
}
//no need to update anything from version 1.4 to 1.5
if (oldVersion < new Version(1, 6)) {
    //update what changed from version 1.5 to version 1.6
}

So, when someone updates from 1.3 to 1.6, both update procedures will be executed, with the older one being first, as it should be.

Upvotes: 2

Romasz
Romasz

Reputation: 29790

Your data will be preserved during the update procedure - MSDN:

When you update your app, any data in the isolated storage is preserved. However, data in the isolated storage is deleted if the user uninstalls and then reinstalls your app. For more information, see Data for Windows Phone 8.

It's your responsibility to correctly handle all old files.

I would advise you to publish (after succefull testing with deployment via VS) a beta version (for example limited only to you) and test updating procedures. From my experince it is very important thing to do - there may be many pitfalls and there is nothing worse than the app that fails after the update - so check as many times as possible.

Upvotes: 4

MVarman
MVarman

Reputation: 549

It really depends on where and how you are storing the XML file. But because you are modifying the file at runtime I am assuming you are storing it in the isolated storage. In that case the file will not get overwritten when you update the app.

If you want to be 100% sure, - deploy the debug version of the app, using Application Deployment tool, to your test mobile/emulator - use the app for a while so that the xml file gets updated - recompile (not Rebuild) and redeploy. If the changes remains intact after redeploy, you are good!

Upvotes: 1

Related Questions