KaZip for C++Builder2009/Delphi

发布于 2024-09-01 07:30:00 字数 663 浏览 11 评论 0原文

我已经在 C++Builder2009 上下载并安装了 KaZip2.0(有一些小的更改=>仅将类型 String 设置为 AnsiString)。我写过:

KAZip1->FileName = "test.zip";
KAZip1->CreateZip("test.zip");
KAZip1->Active = true;
KAZip1->Entries->AddFile("pack\\text.txt","xxx.txt");
KAZip1->Active = false;
KAZip1->Close();

现在他创建了一个 test.zip,其中包含 xxx.txt(59 字节原始,21 字节打包)。我在 WinRAR 中成功打开存档并想要打开 xxx.txt,但 WinRAR 说文件已损坏。 :(

出了什么问题?有人可以帮助我吗?

提取无法工作,因为文件已损坏?

KAZip1->FileName = "test.zip";
KAZip1->Active = true;
KAZip1->Entries->ExtractToFile("xxx.txt","zzz.txt");
KAZip1->Active = false;
KAZip1->Close();

I have download and install KaZip2.0 on C++Builder2009 (with little minor changes => only set type String to AnsiString). I have write:

KAZip1->FileName = "test.zip";
KAZip1->CreateZip("test.zip");
KAZip1->Active = true;
KAZip1->Entries->AddFile("pack\\text.txt","xxx.txt");
KAZip1->Active = false;
KAZip1->Close();

now he create a test.zip with included xxx.txt (59byte original, 21byte packed). I open the archiv in WinRAR successful and want open the xxx.txt, but WinRAR says file is corrupt. :(

What is wrong? Can somebody help me?

Extract not working, because file is corrupt?

KAZip1->FileName = "test.zip";
KAZip1->Active = true;
KAZip1->Entries->ExtractToFile("xxx.txt","zzz.txt");
KAZip1->Active = false;
KAZip1->Close();

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

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

发布评论

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

评论(5

南街九尾狐 2024-09-08 07:30:00

有一些小的改变=>只设置
将 String 类型转换为 AnsiString

使用 RawByteString 而不是 AnsiString。

with little minor changes => only set
type String to AnsiString

Use RawByteString instead of AnsiString.

安人多梦 2024-09-08 07:30:00

我不知道 KaZip2.0 是如何实现的,但一般来说,要使一个在设计时没有考虑到 Unicode 支持的 Delphi/C++ 库正常工作,您需要做两件事:

  • 用 AnsiChar 替换所有 Char,用 AnsiString
  • 替换 所有字符串所有 Win API 调用及其 Ansi 变体,即用 AWin32FunctionA 替换 AWin32Function。

在德尔福< 2009,Char = AnsiChar,String = AnsiString,AWin32Function = AWin32FunctionA,但在Delphi >= 2009中,默认情况下,Char = WideChar,String = UnicodeString,AWin32Function = AWin32FunctionW。

I have no idea how KaZip2.0 is implemented, but in general, to make a Delphi/C++ library that was designed without Unicode support in mind working properly you need to do two things:

  • Replace all Char with AnsiChar and all string to AnsiString
  • Replace all Win API calls with their Ansi variant, i.e. replace AWin32Function with AWin32FunctionA.

In Delphi < 2009, Char = AnsiChar, String = AnsiString, AWin32Function = AWin32FunctionA, but in Delphi >= 2009, by default, Char = WideChar, String = UnicodeString, AWin32Function = AWin32FunctionW.

孤独患者 2024-09-08 07:30:00

WinRAR 可能只是无法识别标头。尝试在 Windows 或其他一些 zip 程序中打开它。

WinRAR could be simply failing to recognize the header. Try opening it in Windows or some other zip programs.

怀中猫帐中妖 2024-09-08 07:30:00

有一些小的改变=>只设置
将 String 类型转换为 AnsiString

这并不总是正确的,它可能会编译,但这并不意味着它在 D2009 或 CB2009 中可以正常工作,您需要显示将字符串转换为 AnsiStrings 的位置,特别是代码处理:缓冲区、流和 I/O。

with little minor changes => only set
type String to AnsiString

That's doesn't work always right, it may compile but it doesn't mean it will work right in D2009 or CB2009, you need to show the places that you convert Strings to AnsiStrings, specially the code deal with : Buffers, Streams and I/O.

风苍溪 2024-09-08 07:30:00

你的代码是错误的,这并不奇怪; KaZip 没有文档。

正确的代码是:

//Create a new empty zip file
KAZip1->CreateZip("test.zip");

//Open our newly created zip file so we can add files to it
KAZIP1->Open("test.zip");

//Compress text.txt  into  xxx.txt
KAZip1->Entries->AddFile("pack\\text.txt","xxx.txt");

//Close the file stream 
KAZip1->Close();

It's not surprising that your code is wrong; KaZip has no documentation.

Proper code is:

//Create a new empty zip file
KAZip1->CreateZip("test.zip");

//Open our newly created zip file so we can add files to it
KAZIP1->Open("test.zip");

//Compress text.txt  into  xxx.txt
KAZip1->Entries->AddFile("pack\\text.txt","xxx.txt");

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