0

I have a Windows Phone app that relies on an XML data file that comes packaged with the app. When the app is ran the first time on a phone, I load the file into isolated storage. Once the file is loaded into isolated storage, the app uses the isolated storage version of data. In the next version of my app (the Marketplace update), the XML file will have more elements, how do I update the data file once per app update (new version on the Marketplace)?

I thought I could change the file name in the isolated storage, but that would leave trash behind. I could also check for exceptions when I load the XML file, but are there any other, more elegant ways? I do not want to check for the old file in the isolated storage every time my app runs.

The ideal scenario would be to put a piece of code that would be executed once when the new version of the app is loaded onto the phone, is there a way to do that?

Eugene
  • 2,965
  • 2
  • 34
  • 39
  • 1
    If the XML file comes packaged in the app, when you update the app (and the new package will have the new XML file), it will just be there. Not really sure I understand the issue. – Shahar Prish Apr 15 '12 at 01:09
  • Good point. The first time the app is ran, I read the XML file into isolated storage, and then the app only uses the file in the isolated storage. – Eugene Apr 15 '12 at 01:12
  • Unless by 'app update' at the end of the first paragraph, you don't mean a Marketplace update, but app launch or something? – Shahar Prish Apr 15 '12 at 01:13
  • Sorry -- still not entirely sure about what you mean... What does 'app update' at the end of your first paragraph mean? A Marketplace update? If so, just read the XML file again and overwrite the file in iso storage. If you mean something else (every time the app launches), then read the file from the web, and overwrite the XML you have in iso-storage. – Shahar Prish Apr 15 '12 at 01:16
  • Marketplace update. How do I read the XML file once when the app is updated? Is there a way to do that? I don't want to read the file into isolated storage every time the app starts. – Eugene Apr 15 '12 at 01:21
  • @Eugene - Don't you have some way to version, hash, date, or otherwise identify the file and see that it needs update? – Ritch Melton Apr 15 '12 at 01:22
  • @RitchMelton Not yet, I am not sure how to do that. – Eugene Apr 15 '12 at 01:23

3 Answers3

1

To my knowledge there isn't an "out of the box" event that will run a single time at the first run of an app after it was installed/updated.

You'd have to flag the run your self, like you are already stating (save the current version, compare version at each run of the app to see if app was updated!)

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
0

I think I now understand what you want.

  1. Add the XML file as a resource.
  2. Use GetResourceStream to get the content of the XML.

Note that the name for the resource would be something like /DllName;component/Folder/ResourceName

Shahar Prish
  • 4,838
  • 3
  • 26
  • 47
  • Can you please elaborate on why GetResourceStream will work for this scenario? – Eugene Apr 15 '12 at 01:34
  • @Shahar - He just wants a way to version and update the file. – Ritch Melton Apr 15 '12 at 01:34
  • @Eugene: It will just give you a stream ref to the file that's in your XAP - I guess I am still missing what it is you are trying to do. – Shahar Prish Apr 15 '12 at 04:55
  • @RitchMelton: So I guess I still don't understand what he's trying to do. What do you mean "version and update the file". If the file is part of his XAP, then there's nothing he needs to do - it will just be there (I am aware that I must be missing something, but can't figure out what). – Shahar Prish Apr 15 '12 at 04:55
  • @Shahar - Yea, its really a non-issue. He's extracting the file to isolated storage when the app first runs. Now he wants to update that file but isn't sure how to determine if the file needs updated. – Ritch Melton Apr 15 '12 at 05:04
  • @RitchMelton Okay - so if he just reads the file directly from content/resource, he won't have the issue, right? That's what you mean by non-issue. He can then have a if (exists(iso)) delete(iso) to clean up the previous file he had there. – Shahar Prish Apr 15 '12 at 05:10
  • @Shaahar - That's an option. Since we don't know why its extracted to isolated storage, he might need something. If he hashes the file and uses that to key his logic for extraction. Or if he adds a version to the file. Or.... there's a million simple solutions. – Ritch Melton Apr 15 '12 at 05:36
0

Here is what I did:

In the constructor method of my DataLayer class, I added the following code:

private bool AppIsOld
{
    get
    {
        string storedVersion = GetStoredAppVersion(); //stored previously "seen" version
        string currentVersion = GetCurrentlyRunningAppVersion();
        return !(storedVersion == currentVersion);
    }
}


private string GetCurrentlyRunningAppVersion()
{
    var asm = Assembly.GetExecutingAssembly();
    var parts = asm.FullName.Split(',');
    return parts[1].Split('=')[1].ToString();
}

And then I run the following check:

if (AppIsOld)
    RefreshResources(); //do whatever to refresh resources

The code for GetCurrentlyRunningAppVersion() function is taken from here.

This solution is not what I had in mind because it runs every time the class constructor is called while I wanted something that would run once upon version update.

Community
  • 1
  • 1
Eugene
  • 2,965
  • 2
  • 34
  • 39