C# parchive/quickpar/par2 修复实现?

发布于 2024-07-21 04:10:26 字数 298 浏览 12 评论 0原文

我正在编写一个 C# 应用程序,需要能够使用 par2 奇偶校验文件修复一组文件。 对于 C++,有很多东西可以做到这一点,但对于 C#,我找不到本机实现。

一种选择是使用 C# 中的 C++ DLL, 但我不想这样做,因为不可能在 x64 应用程序中使用 32 位 dll,所以我将我的应用程序限制为 32 位模式。

另一种选择是在后台执行 shellexecute par2cmdline, 但我宁愿对流程有更多的控制权(进度、取消等)。

有谁知道可以使用 par2 集修复文件的本机 C# 实现吗?

I'm writing a C# app that needs to be able to repair a set of files using par2 parity files.
For C++ there is lots to be found that'll do exactly that, but for C# I can't find a native implementation.

One option would be using a C++ DLL from C#,
but I'd rather not do that since it's not possible to use a 32bits dll in an x64 app so I'd be limiting my app to 32bits mode.

Another option is to shellexecute par2cmdline in the background,
but I'd rather have more control over the process (progress, cancelling etc.).

Does anyone know of a native C# implementation that'll repair files using a par2 set ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

夏花。依旧 2024-07-28 04:10:26

您想坚持使用 PAR 本身吗? 我有一个完全原生的 Reed/Solomon implementation,如果它有帮助的话我会发布(PAR 所基于的匹配),但我没有任何用于所有文件处理和分解的东西。

我的代码是 Stream 的实现,并生成一个包含所有纠错数据的字符串。 然后,您可以损坏该数据并将其发回,系统将自动恢复它。 我只想发布它,但它很长,而且我懒得写一篇博客文章并链接到它。

为了使其像 PAR 一样工作,您必须将其分解为文件,然后构建一个可以识别丢失卷并为所有丢失数据“添加”损坏数据的系统(数学无法处理丢失数据,只能处理损坏数据)。

另外,作为性能方面的说明,其构建的系统相当“突发”,它一次会接收大量 100k 流,但也会等待很长时间而不执行任何操作。 C# 版本的数学计算速度比纯 C 版本快约 6%。 如果我仅使用不间断负载进行性能测试,C# 的运行速度大约会慢 1-2%。 根据我的经验,大多数 C 到 C# 数学转换都具有相同的性能结果。

Do you want to stick with PARs themselves? I have a fully native Reed/Solomon implimentation I would post if it will help (the match that PARs are based on), but I don't have anything for all the file handling and breakup.

My code is an implementation of Stream and produces a string with all the error correcting data included. You can then corrupt that data and send it back and it system will automatically recover it. I would just post it but it is long and I am too lazy to make a blog post and link to it.

To make that work like PAR, you would have to break that up into files, then build a system that can identify missing volumes and 'adds in' corrupt data for all the missing data (the math cannot handle missing data, only corrupt).

Also, as a note on performance, the system this was built for was rather 'bursty', it would get in lots of 100k streams at a time, but also have long waits of doing nothing. The C# version of the math worked about 6% faster then the pure C version. If I did performance testing using just non-stop load, the C# runs about 1-2% slower. In my experience, most C to C# math conversions have the same performance results.

櫻之舞 2024-07-28 04:10:26

这不是一个直接的答案,但我认为有一种方法可以将 32 位 dll 加载到 64 位应用程序中:

http://dnjonline.com/article.aspx?ID=jun07_access3264

来自文章:

此解决方案需要额外的工作,因为必须创建加载 32 位 DLL 并公开其 API 的 32 位代理进程。 此外,64 位方面也需要进行一些更改,因为消费者必须使用其中一种 IPC 技术,而不是直接访问 32 位 DLL。 值得注意的是,在极端情况下,这项额外工作可以与从头开始开发 32 位 DLL 的 64 位版本所涉及的工作相当。

降低这些成本的一种可能方法是实现一个 64 位包装器 DLL,它公开与原始 32 位 DLL 相同的函数、参数、类型等。 然后,该包装器 DLL 可以对已加载到代理进程中的原始 32 位 DLL 进行基于 IPC 的调用。

It's not a direct answer but I think there is a way to load a 32 bit dll into a 64bit app:

http://dnjonline.com/article.aspx?ID=jun07_access3264

From the article:

This solution requires additional work as the 32-bit surrogate process that loads the 32-bit DLL and exposes its API must be created. Also, some changes will be necessary on the 64-bit side as the consumer must use one of the IPC techniques instead of directly accessing the 32-bit DLL. It is worth noting that, in extreme cases, this additional work could be comparable to the work involved in developing a 64-bit version of the 32-bit DLL from scratch.

One possible way of reducing these costs is to implement a 64-bit wrapper' DLL that exposes the same functions, parameters, types and so forth as the original 32-bit DLL. This wrapper DLL can then make IPC-based calls to the original 32-bit DLL, which has been loaded into a surrogate process.

待天淡蓝洁白时 2024-07-28 04:10:26

不久前我正在做这样的事情。 如果您查看 par2 源代码,就会发现这并不简单。 你也许可以将它移植到 C# 而不会有太多麻烦。 可悲的是,所有需要付出的努力都会让你付出高昂的性能代价(如果你不相信我,可以尝试一下)。

我最终通过 CreateProcess 调用 par2 可执行文件。 您可以获得 stdin、stdout 和 strerr 的句柄。 由于可执行文件是控制台应用程序,因此您可以解析输出以获取进度。 如果您想“取消”操作,您可以随时终止该进程。

这是一种马虎的方法。

“正确”的方法是获取 par2 源并将其移植到 64 位 dll(出于性能原因,坚持使用非托管 C/C++ DLL)。

I was doing something like this a while back. If you look at the par2 source code, it's not trivial. You could probably port it to c# without much trouble. Sadly, all the effort that would take would cost you dearly in performance (try it if you don't believe me).

I ended up calling par2 executable via CreateProcess. You can get handles to stdin, stdout and strerr. Because the executable is a console app, you can parse the output to get the progress. If you want to "cancel" the operation you can always kill the process.

It's a sloppy method.

The "right" way would be to take the par2 source and port it to a 64-bit dll (stick with unmanaged C/C++ DLL for performance reasons).

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