fpzipper.lpr 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. program fpzipper;
  2. {$mode objfpc}{$H+}
  3. uses
  4. {$IFDEF UNIX}{$IFDEF UseCThreads}
  5. cthreads,
  6. {$ENDIF}{$ENDIF}
  7. Classes, SysUtils, CustApp, zipper;
  8. type
  9. { TFPZipApplication }
  10. TFPZipApplication = class(TCustomApplication)
  11. Private
  12. FZipper: TZipper;
  13. protected
  14. procedure DoRun; override;
  15. public
  16. constructor Create(TheOwner: TComponent); override;
  17. destructor Destroy; override;
  18. procedure WriteHelp; virtual;
  19. end;
  20. { TFPZipApplication }
  21. procedure TFPZipApplication.DoRun;
  22. Var
  23. I : Integer;
  24. F : TFileStream;
  25. begin
  26. If ParamCount<=1 then
  27. begin
  28. Writeln('Usage ',ParamStr(0),' zipfile file1 [file2 [...]]');
  29. Terminate;
  30. exit;
  31. end;
  32. FZipper.FileName:=ParamStr(1);
  33. For I:=2 to ParamCount do
  34. begin
  35. F:=TFileStream.Create(ParamStr(i),fmOpenRead);
  36. FZipper.Entries.AddFileEntry(F,ParamStr(i));
  37. end;
  38. FZipper.ZipAllFiles;
  39. For I:=0 to FZipper.Entries.Count-1 do
  40. FZipper.Entries[I].Stream.Free;
  41. Terminate;
  42. end;
  43. constructor TFPZipApplication.Create(TheOwner: TComponent);
  44. begin
  45. inherited Create(TheOwner);
  46. StopOnException:=True;
  47. FZipper:=TZipper.Create;
  48. end;
  49. destructor TFPZipApplication.Destroy;
  50. begin
  51. FreeAndNil(FZipper);
  52. inherited Destroy;
  53. end;
  54. procedure TFPZipApplication.WriteHelp;
  55. begin
  56. { add your help code here }
  57. writeln('Usage: ',ExeName,' -h');
  58. end;
  59. var
  60. Application: TFPZipApplication;
  61. begin
  62. Application:=TFPZipApplication.Create(nil);
  63. Application.Title:='Zip application';
  64. Application.Run;
  65. Application.Free;
  66. end.