Results 1 to 6 of 6

Thread: File Versions (data files)

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    File Versions (data files)

    I am in the middle of a large project that outputs a heirarchical data structure to a binary file.

    Sometimes when I rebuild part of the project, the older data files from a previous build won't load any more.

    What is the standard procedure for making data file future proof as much as possible? I will be making many alterations to my data structure in the coming weeks and I don't want to re-enter all the data over and over again.

    What to do? Hmmm.
    I don't live here any more.

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Instead of using binary you could use XMLSerializer.

    If a public variable exists in the class, but not in the file, it will just use the default value.
    If a value exists in the file, but there is no variable to put it in, it will just be ignored.

    This way you can add and remove variables as you wish, and still be able to load you files.

    The downside is, that the file will be in XML format, but maybe you could serialize it to a memorystream, and write that memorystream to a binaryformatter. Then load the binary file back into a memorystream, and deserialize it using XMLSerializer.

    You could also encrypt the file after saving, en decrypt it to a temp file when loading. Then the data will still be XML, but it will not be readable for users.

    Just a thought.

    Hope it helps.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Unfortunately there is not one single public variable in the entire data structure, so the XML would be sparse to say the least.

    I was wondering about programs like MS Word or AutoCAD that have a fairly long history of backwards compatibility with their old and obsolete versions.

    IE, word 2002 can load word 97 files and so on.

    There must be some way to get around this problem. When I come to revise the app in 2 years there will be a hell of a lot of data that needs re-entering
    I don't live here any more.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Can't you just keep a legacy version of your data class and just use it for loading and upgrade purposes? Just come up with a conversion routine that switches from the old to new format.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    The hierarchy is 3 classes deep that would become a problem after only the first new revision.

    Can't help the feeling that I have painted myself into a corner.
    I don't live here any more.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It isn't perfect and still requires some work but you can inherit from the previous version of the output class to make a new one. Then you have to do some error catching or type checking to figure out at runtime which to load it as.

    The other option is to handle the serialization manually which can be a pain in the arse.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width