在 Ruby 中解析 CArchive(MFC 类)文件
我有一个遗留应用程序,似乎正在使用 CArchive(遗留 MFC 应用程序)导出/保存文件。
我们目前正在为网络重构该工具。我可以在 Ruby 中查看一个库来解析和加载这些遗留文件吗?
我可以研究哪些可能的库?
另外 - 遗留软件有 4 个版本,我如何才能克服不同版本的 ObjectModel、存档数据问题?需要全面的向后(导入)能力。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CArchive 没有可以解析的格式。它只是一个二进制文件。您必须知道其中的内容才能知道如何阅读它。库可以使读取某些数据类型(
CString
、CArray
等)变得更容易,但我不确定您是否会找到类似的东西。CArchive 的工作方式如下(存储部分):
然后将所有这些都转储到二进制文件中。您必须读取二进制数据并以某种方式解释它。这在 C++ 中很容易,因为 MFC 知道如何序列化类型,包括复杂类型,例如
CString
和CArray
。但您必须使用 Ruby 自行完成此操作。例如,您可能会读取 4 个字节(因为您知道
int
有那么大)并将其解释为整数。接下来的四个字节为float
。然后您必须了解如何加载 CString,它首先存储长度,然后存储数据,但您必须查看它使用的确切格式。您可以为每种类型创建实用函数,以使您的生活更轻松,但不要指望这会很简单。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):
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
andCArray
. 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 forfloat
. 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.您可以使用旧功能在 C++ 中编写导出器,该导出器将读取 CArchive,然后输出 xml 文件或任何内容。直接从 Ruby(或 C++/MFC 以外的任何其他语言)读取 CArchives 将是一个重大项目。如果写入的数据只是一个带有几个 int 或 long 的结构,也许您可以逃脱它,但一旦您的 CArchive 包含 UDT,您就会陷入痛苦的世界。例如,我什至不认为 CArchive 对对齐做出承诺。
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.