在 Ruby 中解析 CArchive(MFC 类)文件

发布于 2024-08-28 11:17:15 字数 558 浏览 9 评论 0原文

我有一个遗留应用程序,似乎正在使用 CArchive(遗留 MFC 应用程序)导出/保存文件。

我们目前正在为网络重构该工具。我可以在 Ruby 中查看一个库来解析和加载这些遗留文件吗?

我可以研究哪些可能的库?

根据 MFC XML 序列化的文件格式问题< /a> 包括: 非鲁棒性——如果您读取由您的程序的另一个版本生成的存档,您的程序可能会崩溃。这可以通过复杂且笨重的版本管理来避免。通过使用 XML,可以在很大程度上避免这种情况。 - 程序对象模型和存档数据之间存在严重依赖性。改变程序模型,几乎不可能读取以前版本的数据。 - 存档数据无法编辑、理解和更改,除非使用关联的应用程序。

另外 - 遗留软件有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟─花易冷 2024-09-04 11:17:15

CArchive 没有可以解析的格式。它只是一个二进制文件。您必须知道其中的内容才能知道如何阅读它。库可以使读取某些数据类型(CStringCArray 等)变得更容易,但我不确定您是否会找到类似的东西。

CArchive 的工作方式如下(存储部分):

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

然后将所有这些都转储到二进制文件中。您必须读取二进制数据并以某种方式解释它。这在 C++ 中很容易,因为 MFC 知道如何序列化类型,包括复杂类型,例如 CStringCArray。但您必须使用 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):

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.

慕巷 2024-09-04 11:17:15

您可以使用旧功能在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文