unit uFileTypeServer;

interface

uses
  System.SysUtils, System.Classes;

type
  TFileTypeServer = class(TDataModule)
  private
    { Private declarations }

    FPictureAllowedExtensionsSL:TStringList;
    FVideoAllowedExtensionsSL:TStringList;
    FAudioAllowedExtensionsSL:TStringList;

    FForbiddenExtensionsSL:TStringList;



  public
    { Public declarations }

    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;

    function IsFilePicture(AFilePath:string):boolean;
    function IsFileVideo(AFilePath: string): boolean;
    function IsFileAudio(AFilePath: string): boolean;

    function IsForbiddenExtensions(AFilePath: string): boolean;

  end;

//var
//  FileType: TFileType;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

{ TFileType }

uses uDataBaseUnitServer;

var DataBaseUnitServer_UnitVar:TDataBaseUnitServer;



constructor TFileTypeServer.Create(AOwner: TComponent);
begin
  inherited;


  if (AOwner is TDataBaseUnitServer) then
  DataBaseUnitServer_UnitVar:=(AOwner as TDataBaseUnitServer);



    FPictureAllowedExtensionsSL:=TStringList.Create;
    FVideoAllowedExtensionsSL:=TStringList.Create;
    FAudioAllowedExtensionsSL:=TStringList.Create;
    FForbiddenExtensionsSL:=TStringList.Create;

    //Picture Extensions
    FPictureAllowedExtensionsSL.Add('.jpg');
    FPictureAllowedExtensionsSL.Add('.jpeg');
    FPictureAllowedExtensionsSL.Add('.png');
    FPictureAllowedExtensionsSL.Add('.tiff');


    //Video Extensions
    FVideoAllowedExtensionsSL.Add('.mp4');
    FVideoAllowedExtensionsSL.Add('.avi');

    //AudioExtensions
    FVideoAllowedExtensionsSL.Add('.mp3');
    FVideoAllowedExtensionsSL.Add('.wav');

    //Forbidden Extensions

    FForbiddenExtensionsSL.Add('.exe');
    FForbiddenExtensionsSL.Add('.php');

end;

destructor TFileTypeServer.Destroy;
begin

FreeAndNil(FPictureAllowedExtensionsSL);
FreeAndNil(FVideoAllowedExtensionsSL);
FreeAndNil(FAudioAllowedExtensionsSL);
FreeAndNil(FForbiddenExtensionsSL);


  inherited;
end;



function TFileTypeServer.IsFilePicture(AFilePath: string): boolean;

var Extension:string;


  begin

  Result:=false;
  Extension:=LowerCase(ExtractFileExt(AFilePath));


   with DataBaseUnitServer_UnitVar.qSelectFileExtensionsByType do begin

   Params.ParamValues['FileType']:='Picture';

    Open();

     while not EOF  do begin

     if FieldByName('FileExtension').AsString=Extension then Result:=true;

     Next();
     end;



    Close();


   end;



  {
   Extension:=LowerCase(ExtractFileExt(FilePath));

   if FPictureAllowedExtensionsSL.IndexOf(Extension)<>-1 then
   Result:=true;

  }

end;



function TFileTypeServer.IsFileVideo(AFilePath: string): boolean;

var Extension:string;


  begin

  Result:=false;

   Extension:=LowerCase(ExtractFileExt(AFilePath));


        with DataBaseUnitServer_UnitVar.qSelectFileExtensionsByType do begin

     Params.ParamValues['FileType']:='Video';

      Open();

       while not EOF  do begin

       if FieldByName('FileExtension').AsString=Extension then Result:=true;

       Next();
       end;



      Close();


     end;



  // if FVideoAllowedExtensionsSL.IndexOf(Extension)<>-1 then
  // Result:=true;


  end;




function TFileTypeServer.IsFileAudio(AFilePath: string): boolean;

var Extension:string;


  begin

  Result:=false;

   Extension:=LowerCase(ExtractFileExt(AFilePath));

        with DataBaseUnitServer_UnitVar.qSelectFileExtensionsByType do begin

     Params.ParamValues['FileType']:='Audio';

      Open();

       while not EOF  do begin

       if FieldByName('FileExtension').AsString=Extension then Result:=true;

       Next();
       end;



      Close();


     end;



  // if FAudioAllowedExtensionsSL.IndexOf(Extension)<>-1 then
  // Result:=true;


  end;



function TFileTypeServer.IsForbiddenExtensions(AFilePath: string): boolean;

var Extension:string;


  begin

  Result:=false;

   Extension:=LowerCase(ExtractFileExt(AFilePath));


      with DataBaseUnitServer_UnitVar.qSelectFileExtensionsByType do begin

   Params.ParamValues['FileType']:='ForbiddenExtensions';

    Open();

     while not EOF  do begin

     if FieldByName('FileExtension').AsString=Extension then Result:=true;

     Next();
     end;



    Close();


   end;



  // if FForbiddenExtensionsSL.IndexOf(Extension)<>-1 then
  // Result:=true;


  end;





end.
