unit Loader;



interface
uses
  Mform, SysUtils, ZipMstr, Forms, Dialogs;

function UnZ(FN : string) : boolean;
function INCDir (Dir : string ) : Boolean;

implementation

function DelFileInDir(Dir : String) : Boolean;
var
  IIN : Integer;
  sFN, sDir : String;
  SR : TSearchRec;
begin
  Result:=False;
  sDir:=Dir + '\*.*';
  IIN:=FindFirst(sDir, faAnyFile, SR);

  while IIN=0 do
    begin
      sFN := ExtractFileDir(sDir)+'\'+SR.Name;
      if SR.Attr = faDirectory then
        begin
          if (SR.Name <> '' )
          and (SR.Name <> '.')
          and (SR.Name <> '..') then
            DelFileInDir(sFN);
        end
      else
        begin
          if SR.Attr <> faArchive then
          FileSetAttr(sFN, faArchive);
          DeleteFile(sFN);
     //   ShowMessage('Игра Отшельник : невозможно удалить файл ' + sFN);  }
        end;
      IIN:= FindNext(SR);
    end;
  FindClose(SR);
  Result := True
end;

function INCDir (Dir : string ) : Boolean;
begin
  DelFileInDir(Dir);
  if not DirectoryExists(Dir) then
  CreateDir(Dir);
  result:=DirectoryExists(Dir);
end;


function UnZ(FN : string) : boolean;
var
 tdir: string;
begin
  tdir:=ExtractFilePath(Application.ExeName)+'Data\temp\';
  FN:=ExtractFilePath(Application.ExeName)+'\'+FN;
  if (FileExists(FN)) and (INCDir(tdir)) then
  with OForm.Zip do
    begin
      ZipFileName:=FN;
      FSpecArgs.Add('*.*');
      ExtrBaseDir:=tdir;
      ExtrOptions:=ExtrOptions+[ExtrOverwrite];
      Extract;
      result:=true;
    end
  else
  result:=false;
end;


end.
