views:

36

answers:

2

I have a legacy app that seems to be exporting/saving files with CArchive (legacy MFC application).

We're currently refactoring the tool for the web. Is there a library I can look at in Ruby for parsing and loading these legacy files?

What possible libraries could I look into?

Problems with the file format according to XML serialization for MFC include: Non-robustness—your program will probably crash if you read an archive produced by another version of your program. This can be avoided by complex and unwieldly version management. By using XML, this can be largely avoided. - Heavy dependencies between your program object model and the archived data. Change the program model and it is almost impossible to read data from a previous version. - Archived data cannot be edited, understood, and changed, except with the associated application.

Also - 4 versions of the legacy software exists, how would I be able to overcome this ObjectModel, Archived data problem for the different versions? Total backward (import) capabilities are required.

Any help much appreciated.

+2  A: 

CArchive doesn't have a format that you can parse. It's just a binary file. You have to know what is in it to know how to read it. A library could make it easier to read some data types (CString, CArray, etc.) but I'm not sure you'll find anything like this.

CArchive works like this (storing part):

CArchive ar;
int i = 5;
float f = 5.42f;
CString str("string");
ar << i << f << str;

Then all this is dumped into binary file. You would have to read binary data and somehow interpret it. This is easy in C++ because MFC knows how to serialize types, including complex types like CString and CArray. But you'll have to do this on your own using Ruby.

For example you might read 4 bytes (because you know that int is that big) and interpret it as integer. Next four bytes for float. And then you have to see how to load CString, it stores the length first and then data, but you'll have to take a look at the exact format it uses. You could create utility functions for each type to make your life easier but don't expect this to be simple.

Nikola Smiljanić
So CArchive is just the binary story space for serialized data types?
Forkrul Assail
I have all the code for the older versions of the software. I can get the data types and and such.Still, how would I go ahead opening the legacy files with this knowledge?
Forkrul Assail
So I have to be aware of first, structure, and the format. Thanks.
Forkrul Assail
The format is binary, but you have to replicate the structure.
Nikola Smiljanić
+1  A: 

You could write an exporter in C++ using the old functionality, that would read in the CArchive and then output an xml file or whatever of the contents. Reading CArchives directly from Ruby (or any other language than C++/MFC) is going to be a major project. Maybe you can get away with it if the data that is written is just a struct with a few ints or longs, but as soon as your CArchive contains UDT's you're in for a world of pain. For example I don't even think CArchive makes promises on alignment.

Roel