在Ruby中解析CArchive(MFC类)文件 [英] Parsing CArchive (MFC classes) files in Ruby
问题描述
我有一个旧版应用程序,似乎正在使用CArchive(旧版MFC应用程序)导出/保存文件.
I have a legacy app that seems to be exporting/saving files with CArchive (legacy MFC application).
我们目前正在重构网络工具.我可以在Ruby中找到一个库来解析和加载这些旧文件吗?
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.
也-有4个版本的旧版软件,我如何能够克服不同版本的ObjectModel,存档数据问题?总共需要反向(导入)功能.
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.
推荐答案
CArchive没有可解析的格式.这只是一个二进制文件.您必须知道其中的内容才能知道如何阅读.库可以使读取某些数据类型(CString
,CArray
等)更容易,但是我不确定您会找到类似的内容.
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的工作方式如下(存储部分):
CArchive works like this (storing part):
CArchive ar;
int i = 5;
float f = 5.42f;
CString str("string");
ar << i << f << str;
然后将所有这些都转储到二进制文件中.您将不得不读取二进制数据并以某种方式对其进行解释.在C ++中,这很容易,因为MFC知道如何序列化类型,包括CString
和CArray
之类的复杂类型.但是您必须使用Ruby自行完成此操作.
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.
例如,您可能会读取4个字节(因为您知道int
很大)并将其解释为整数. float
的后四个字节.然后,您必须查看如何加载CString,它首先存储长度,然后存储数据,但是您必须查看它使用的确切格式.您可以为每种类型创建实用程序功能,以使您的生活更轻松,但是不要指望它这么简单.
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.
这篇关于在Ruby中解析CArchive(MFC类)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!