home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 January / Chip_1999-01_cd.bin / zkuste / delphi / D1 / DRBOBC.ZIP / TBUUCODE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-20  |  5.8 KB  |  207 lines

  1. unit TBUUCode;
  2. { TBUUCode version 2.1 }
  3. interface
  4. uses
  5.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms,
  6.   DrBob;
  7.  
  8. type
  9.   EUUCode = class(Exception);
  10.  
  11.   TErrorEvent = procedure(Error: Word) of Object;
  12.   TSuccessEvent = procedure of Object;
  13.  
  14.  
  15.   TBUUEncode = class(TDrBob)
  16.   public
  17.   { Public class declarations (override) }
  18.     constructor Create(AOwner: TComponent); override;
  19.  
  20.   private
  21.   { Private field declarations }
  22.     FActivate: Boolean;
  23.     FOnError: TErrorEvent;
  24.     FOnSuccess: TSuccessEvent;
  25.     FInputFileName: TFileName;
  26.     FOutputFileName: TFileName;
  27.  
  28.   protected
  29.   { Protected method declarations }
  30.     function InputFilePChar: PChar;
  31.     function OutputFilePChar: PChar;
  32.  
  33.   protected
  34.   { Protected activation methods }
  35.     procedure Activation(Engage: Boolean);
  36.  
  37.   public
  38.   { Public interface declarations }
  39.     procedure UUEncode;
  40.  
  41.   published
  42.   { Published design declarations }
  43.     property InputFile:  TFileName read FInputFileName write FInputFileName;
  44.     property OutputFile: TFileName read FOutputFileName write FOutputFileName;
  45.  
  46.   published
  47.   { Published activation properties }
  48.     property Activate: Boolean read FActivate write Activation;
  49.  
  50.   published
  51.   { Published Event properties }
  52.     property OnError: TErrorEvent read FOnError write FOnError;
  53.     property OnSuccess: TSuccessEvent read FOnSuccess write FOnSuccess;
  54.   end;
  55.  
  56.  
  57.   TBUUDeCode = class(TDrBob)
  58.   public
  59.   { Public class declarations (override) }
  60.     constructor Create(AOwner: TComponent); override;
  61.  
  62.   private
  63.   { Private field declarations }
  64.     FActivate: Boolean;
  65.     FOnError: TErrorEvent;
  66.     FOnSuccess: TSuccessEvent;
  67.     FInputFileName: TFileName;
  68.  
  69.   protected
  70.   { Protected method declarations }
  71.     function InputFilePChar: PChar;
  72.  
  73.   protected
  74.   { Protected activation methods }
  75.     procedure Activation(Engage: Boolean);
  76.  
  77.   public
  78.   { Public interface declarations }
  79.     procedure UUDecode;
  80.  
  81.   published
  82.   { Published design declarations }
  83.     property InputFile:  TFileName read FInputFileName write FInputFileName;
  84.  
  85.   published
  86.   { Published activation properties }
  87.     property Activate: Boolean read FActivate write Activation;
  88.  
  89.   published
  90.   { Published Event properties }
  91.     property OnError: TErrorEvent read FOnError write FOnError;
  92.     property OnSuccess: TSuccessEvent read FOnSuccess write FOnSuccess;
  93.   end;
  94.  
  95. implementation
  96. uses UUCode, FileName, DsgnIntf;
  97.  
  98.  
  99.   constructor TBUUEnCode.Create(AOwner: TComponent);
  100.   begin
  101.     if not UUCodeLoaded then
  102.       raise EUUCode.Create('TBUUEnCode: UUCode.DLL not loaded');
  103.     inherited Create(AOwner);
  104.     FActivate := False;
  105.     FAbout := 'TBUUEnCode 2.1 (c) 1996 by Bob Swart (aka Dr.Bob - 100434,2072)'
  106.   end {Create};
  107.  
  108.   function TBUUEnCode.InputFilePChar: PChar;
  109.   begin
  110.     Result := StrPCopy(@FInputFileName[1],FInputFileName)
  111.   end {InputFilePChar};
  112.  
  113.   function TBUUEnCode.OutputFilePChar: PChar;
  114.   begin
  115.     Result := StrPCopy(@FOutputFileName[1],FOutputFileName)
  116.   end {OutputFilePChar};
  117.  
  118.   procedure TBUUEnCode.Activation(Engage: Boolean);
  119.   begin
  120.     if Engage then
  121.     begin
  122.       FActivate := True;
  123.       Application.ProcessMessages;
  124.       UUEncode;
  125.       FActivate := False
  126.     end
  127.   end {Activate};
  128.  
  129.   procedure TBUUEnCode.UUEncode;
  130.   var Error: Word;
  131.   begin
  132.     if FInputFileName = '' then raise EUUCode.Create('InputFileName is empty');
  133.     if FOutputFileName = '' then raise EUUCode.Create('OutputFileName is empty');
  134.     Error := UUEncoder(InputFilePChar,OutputFilePChar,664,False,nil);
  135.     if Error <> 0 then
  136.     begin
  137.       if Assigned(FOnError) then FOnError(Error)
  138.       else
  139.       begin
  140.         case Error of
  141.           1: raise EUUCode.Create('UUEnCode: input file is output file');
  142.           2: raise EUUCode.Create('UUEnCode: input file does not exist');
  143.           3: raise EUUCode.Create('UUEnCode: output file exists');
  144.           4: raise EUUCode.Create('UUEnCode: could not create output file');
  145.           5: raise EUUCode.Create('UUEnCode: DLL bussy, try again later (shared buffers)')
  146.         end
  147.       end
  148.     end
  149.     else { sucess! }
  150.       if Assigned(FOnSuccess) then FOnSuccess
  151.   end {UUEncode};
  152.  
  153.  
  154.  
  155.   constructor TBUUDeCode.Create(AOwner: TComponent);
  156.   begin
  157.     if not UUCodeLoaded then
  158.       raise EUUCode.Create('TBUUDeCode: UUCode.DLL not loaded');
  159.     inherited Create(AOwner);
  160.     FActivate := False;
  161.     FAbout := 'TBUUDeCode 2.1 (c) 1996 by Bob Swart (aka Dr.Bob - 100434,2072)'
  162.   end {Create};
  163.  
  164.   function TBUUDeCode.InputFilePChar: PChar;
  165.   begin
  166.     Result := StrPCopy(@FInputFileName[1],FInputFileName)
  167.   end {InputFilePChar};
  168.  
  169.   procedure TBUUDeCode.Activation(Engage: Boolean);
  170.   begin
  171.     if Engage then
  172.     begin
  173.       FActivate := True;
  174.       Application.ProcessMessages;
  175.       UUDecode;
  176.       FActivate := False
  177.     end
  178.   end {Activate};
  179.  
  180.   procedure TBUUDeCode.UUDecode;
  181.   var WorkDir: String;
  182.       Error: Word;
  183.   begin
  184.     if FInputFileName = '' then raise EUUCode.Create('InputFileName is empty');
  185.     WorkDir := ExtractFilePath(FInputFileName);
  186.     if WorkDir[Length(WorkDir)] = '\' then Delete(WorkDir,Length(WorkDir),1);
  187.     ChDir(WorkDir);
  188.     Error := UUDecoder(InputFilePChar,nil);
  189.     if Error <> 0 then
  190.     begin
  191.       if Assigned(FOnError) then FOnError(Error)
  192.       else
  193.       begin
  194.         case Error of
  195.           1: raise EUUCode.Create('UUDeCode: input file is output file');
  196.           2: raise EUUCode.Create('UUDeCode: input file does not exist');
  197.           3: raise EUUCode.Create('UUDeCode: output file exists');
  198.           4: raise EUUCode.Create('UUDeCode: could not create output file');
  199.           5: raise EUUCode.Create('UUDeCode: DLL bussy, try again later (shared buffers)')
  200.         end
  201.       end
  202.     end
  203.     else { sucess! }
  204.       if Assigned(FOnSuccess) then FOnSuccess
  205.   end {UUDecode};
  206. end.
  207.