unit plug_misc;

interface

uses Windows,SysUtils,Classes,Forms,Masks;

function addbackslash(s:widestring):widestring;
function codepass(pass: string):string;
function decodepass(pass: string):string;
procedure FindFiles(StartFolder, Mask: string; List: TStrings; ScanSubFolders: Boolean = True);
function abs_path(src: string):string;
var
 BaseName,INIFile,sqlpath: widestring;


implementation

function abs_path(src: string):string;
begin
 if src<>''
  then
   begin
    if src[1]='.'
     then
      begin
       result:=src;
       delete(result,1,2);
       result:= extractfilepath(Application.ExeName)+result;
      end
     else result:=src;
   end
  else result:='';
end;

procedure FindFiles(StartFolder, Mask: string; List: TStrings; ScanSubFolders: Boolean = True);
var
 SearchRec: TSearchRec;
 FindResult: Integer;
begin
 List.BeginUpdate;
 try
  StartFolder := IncludeTrailingBackslash(StartFolder);
  FindResult := FindFirst(StartFolder + '*', faAnyFile, SearchRec);
  try
   while FindResult = 0 do
    with SearchRec do
     begin
      Application.ProcessMessages;
      if (Attr and faDirectory) <> 0
       then
        begin
         if ScanSubFolders and (Name <> '.') and (Name <> '..')
          then FindFiles(StartFolder + Name, Mask, List, ScanSubFolders);
        end
       else
        begin
         if MatchesMask(AnsiLowerCase(Name), AnsiLowerCase(Mask)) then List.Add(StartFolder + Name);
        end;
      FindResult := FindNext(SearchRec);
     end;
  finally
   FindClose(SearchRec);
  end;
 finally
  List.EndUpdate;
 end;
end;

function addbackslash(s:widestring):widestring;
begin
 result:=s;
 if (s='')  then exit;
 if s[length(s)]<>'/' then result:=(result+'/');
end;

function codepass(pass: string):string;
var
 i: Integer;
 s: string;
begin
 result:='';
 if pass='' then Exit;
 s:='';
 for i:=1 to Length(pass) do s:=s+IntToHex(ord(Pass[i])-8,2);
 result:=s;
end;

function decodepass(pass: string):string;
var
 i: Integer;
 s: string;
begin
 result:='';
 if pass='' then Exit;
 if length(pass) mod 2 <> 0 then Exit;
 s:='';
 for i:=1 to Length(pass) div 2 do
  begin
   s:=s+chr(strtoint('$'+copy(pass,i*2-1,2))+8);
  end;
 result:=s;
end;

end.


