瀏覽代碼

压缩文件,检查文件压缩完毕

MaiXinRong 8 年之前
父節點
當前提交
f84470f835
共有 1 個文件被更改,包括 19 次插入1 次删除
  1. 19 1
      Units/UtilMethods.pas

+ 19 - 1
Units/UtilMethods.pas

@@ -4,7 +4,8 @@ interface
 
 uses
   Controls, ZhAPI, ActnList, ZjIDTree, DB, ZjGridDBA, ZjGrid, Windows, Messages,
-  sdDB, VCLZip, VCLUnZip, Dialogs, Forms, ShlObj, Classes, StrUtils, Math, ADODB;
+  sdDB, VCLZip, VCLUnZip, Dialogs, Forms, ShlObj, Classes, StrUtils, Math, ADODB,
+  IdGlobal;
 
 type
   TBookmarkRefreshEvent = procedure (AExpandFrame: Boolean) of object;
@@ -870,13 +871,25 @@ begin
 end;
 
 {Zip}
+function ZipComplete(const AFileName: string): Boolean;
+var
+  iSize1, iSize2: Integer;
+begin
+  iSize1 := FileSizeByName(AFileName);
+  Sleep(200);
+  iSize2 := FileSizeByName(AFileName);
+  Result := iSize1 = iSize2;
+end;
+
 procedure ZipFolder(AFileFolder, AFileName: string);
 var
   sTempFile: string;
   vZip: TVCLZip;
+  iCount: Integer;
 begin
   sTempFile := GetTempFileName;
   vZip := TVCLZip.Create(nil);
+  iCount := 0;
   try
     vZip.FilesList.Clear;
     vZip.ZipName := sTempFile;
@@ -887,6 +900,11 @@ begin
     //vZip.RecreateDirs := True;
     vZip.FilesList.Add(AFileFolder + '\*.*');
     vZip.Zip;
+    while not ZipComplete(sTempFile) and (iCount < 10) do
+    begin
+      Sleep(200);
+      Inc(iCount);
+    end;
     CopyFileOrFolder(sTempFile, AFileName);
   finally
     vZip.Free;