fpzipper.lpr 1.5 KB

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