在Ruby中解析CArchive(MFC类)文件 [英] Parsing CArchive (MFC classes) files in Ruby

查看:107
本文介绍了在Ruby中解析CArchive(MFC类)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧版应用程序,似乎正在使用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?

根据 XML序列化用于MFC 包括: 非强壮性-如果您阅读由另一个版本的程序生成的归档文件,则您的程序可能会崩溃.可以通过繁琐的版本管理来避免这种情况.通过使用XML,可以在很大程度上避免这种情况. -程序对象模型与归档数据之间的大量依赖关系.更改程序模型,几乎不可能从以前的版本读取数据. -除关联的应用程序外,已存档的数据无法编辑,.

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没有可解析的格式.这只是一个二进制文件.您必须知道其中的内容才能知道如何阅读.库可以使读取某些数据类型(CStringCArray等)更容易,但是我不确定您会找到类似的内容.

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知道如何序列化类型,包括CStringCArray之类的复杂类型.但是您必须使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆