设为首页 加入收藏

TOP

学习笔记:7z在delphi的应用(二)
2017-10-10 12:07:23 】 浏览:6894
Tags:学习 笔记 delphi 应用
d
;

解压时是调用ExtractTo来解压的,简单。只不过要通过后缀来选择特定的解压对象需要单独处理一下,写了个方法:

function TForm1.GetInArchiveByFileExt(AExt: string): I7zInArchive;
var
  sExt: string;
begin
  sExt := UpperCase(AExt);
  if (sExt='.ZIP') or (sExt='.JAR') or (sExt='.XPI') then
    Result := CreateInArchive(CLSID_CFormatZip)
  else if (sExt='.BZ2') or (sExt='.BZIP2') or (sExt='.TBZ2') or (sExt='.TBZ') then
    Result := CreateInArchive(CLSID_CFormatBZ2)
  else if (sExt='.RAR') or (sExt='.R00') then
    Result := CreateInArchive(CLSID_CFormatRar)
  else if (sExt='.ARJ') then
    Result := CreateInArchive(CLSID_CFormatArj)
  else if (sExt='.Z') or (sExt='.TAZ') then
    Result := CreateInArchive(CLSID_CFormatZ)
  else if (sExt='.LZH') or (sExt='.LHA') then
    Result := CreateInArchive(CLSID_CFormatLzh)
  else if (sExt='.7Z') then
    Result := CreateInArchive(CLSID_CFormat7z)
  else if (sExt='.CAB') then
    Result := CreateInArchive(CLSID_CFormatCab)
  else if (sExt='.NSIS') then
    Result := CreateInArchive(CLSID_CFormatNsis)
  else if (sExt='.LZMA') then
    Result := CreateInArchive(CLSID_CFormatLzma)
  else if (sExt='.LZMA86') then
    Result := CreateInArchive(CLSID_CFormatLzma86)
  else if (sExt='.EXE') then
    Result := CreateInArchive(CLSID_CFormatPe)
  else if (sExt='.PE') or (sExt='.DLL') or (sExt='.SYS') then
    Result := CreateInArchive(CLSID_CFormatPe)
  else if (sExt='.ELF') then
    Result := CreateInArchive(CLSID_CFormatElf)
  else if (sExt='.MACHO') then
    Result := CreateInArchive(CLSID_CFormatMacho)
  else if (sExt='.UDF') then
    Result := CreateInArchive(CLSID_CFormatUdf)
  else if (sExt='.XAR') then
    Result := CreateInArchive(CLSID_CFormatXar)
  else if (sExt='.MUB') then
    Result := CreateInArchive(CLSID_CFormatMub)
  else if (sExt='.HFS') or (sExt='.CD') then
    Result := CreateInArchive(CLSID_CFormatHfs)
  else if (sExt='.DMG') then
    Result := CreateInArchive(CLSID_CFormatDmg)
  else if (sExt='.MSI') or (sExt='.DOC') or (sExt='.XLS') or (sExt='.PPT') then
    Result := CreateInArchive(CLSID_CFormatCompound)
  else if (sExt='.WIM') or (sExt='.SWM') then
    Result := CreateInArchive(CLSID_CFormatWim)
  else if (sExt='.ISO') then
    Result := CreateInArchive(CLSID_CFormatIso)
  else if (sExt='.BKF') then
    Result := CreateInArchive(CLSID_CFormatBkf)
  else if (sExt='.CHM') or (sExt='.CHI') or (sExt='.CHQ') or (sExt='.CHW')
          or (sExt='.HXS') or (sExt='.HXI') or (sExt='.HXR') or (sExt='.HXQ')
          or (sExt='.HXW') or (sExt='.LIT') then
    Result := CreateInArchive(CLSID_CFormatChm)
  else if  (sExt='.001') then
    Result := CreateInArchive(CLSID_CFormatSplit)
  else if  (sExt='.RPM') then
    Result := CreateInArchive(CLSID_CFormatRpm)
  else if  (sExt='.DEB') then
    Result := CreateInArchive(CLSID_CFormatDeb)
  else if  (sExt='.CPIO') then
    Result := CreateInArchive(CLSID_CFormatCpio)
  else if  (sExt='.TAR') then
    Result := CreateInArchive(CLSID_CFormatTar)
  else if  (sExt='.GZ') or (sExt='.GZIP') or (sExt='.TGZ') or (sExt='.TPZ') then
    Result := CreateInArchive(CLSID_CFormatGZip)
  else
    Result := CreateInArchive(CLSID_CFormatZip);
end;

没想到7z的完成度这么高,还是非常方便的。

 

后记:以前在.net平台上调用过7z,只不过是使用shell方式调用的7z.exe。用命令感觉会麻烦一些,使用dll集成在程序中还是挺方便的。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[Django]模型学习记录篇--基础 下一篇Firemonkey TComboBox 下拉菜单字..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目