StrPCopy(POpenDir,Dir);
FindExecutable(PChar(FileName),PChar(Dir),PPath);
Res:=ShellExecute(Application.Handle,'open',PPath,PChar(FileName),
POpenDir,SW_SHOWNORMAL);
if Res<32 then
ShowMessage(ErrorMsg[3]);
FreeMem(POpenDir);
FreeMem(PPath);
end;
function PackFiles(ArcName, Path: ANSIString): Boolean;
var
Param : ShortString;
Res : DWORD;
PPath : PChar;
F : TFileStream;
FName : TFileName;
begin
FName:=Concat(Root,TmpDir,TmpFile,'1',ArcExt);
F:=TFileStream.Create(FName,fmCreate);
GetMem(PPath, PathLen);
if FindExecutable(PChar(FName),PChar(0),PPath)>32 then
begin
Param:=Concat(WinRARName,Bl,PackKey,Bl,ArcName,Bl,Path);
Res:=RunApp('',PPath,Param);
end
else
begin
Res:=0;
end;
if (Res<>0) then
begin
DeleteFiles(Application.Handle,ArcName);
ShowMessage(ErrorMsg[1]);
Result:=False;
end
else
Result:=True;
FreeMem(PPath);
F.Free;
DeleteFiles(Application.Handle,FName);
end;
function RunApp(Title, Name, CmdLn: ANSIString):DWORD;
var
Startup: TStartupInfo;
Process: TProcessInformation;
Status : DWORD;
Env : Pointer;
begin
ChDir(Root);
New(Env);
Startup.lpReserved := PChar(0);
Startup.lpDesktop := PChar(0);
Startup.lpTitle := PChar(Title);
Startup.dwFlags := STARTF_USESHOWWINDOW;
Startup.wShowWindow := SW_SHOWNORMAL;
Startup.cbReserved2 := 0;
Startup.lpReserved2 := PByte(0);
if CreateProcess(
PChar(Name), // lpApplicationName
PChar(CmdLn), // lpCommandLine
PSecurityAttributes(0), // lpProcessAttributes
PSecurityAttributes(0), // lpThreadAttributes
False, // bInheritHandles
NORMAL_PRIORITY_CLASS, // dwCreationFlags
Env, // lpEnvironment
PChar(0), // lpCurrentDirectory
Startup, // lpStartupInfo
Process // lpProcessInformation
)then
begin
GetExitCodeProcess(Process.hProcess, Status);
while Status = STILL_ACTIVE do
begin
Sleep(10);
GetExitCodeProcess(Process.hProcess, Status);
end;
end;
Dispose(Env);
Result:=Status;
end;
function UnPackFiles(ArcName, Dir: ANSIString): Boolean;
var
PPath : PChar;
Param : ShortString;
Res : DWORD;
begin
ArcName:=Concat('"',ArcName,'"');
GetMem(PPath, PathLen);
if FindExecutable(PChar(ArcName),PChar(0),PPath)>32 then
begin
Param:=Concat(WinRARName,Bl,UnPackKey,Bl,ArcName,Bl,Dir);
Res:=RunApp('',PPath,Param);
end
else
begin
Res:=0;
end;
FreeMem(PPath);
if Res<>0 then
begin
DeleteFiles(Application.Handle,Dir+'*.*');
ShowMessage(ErrorMsg[2]);
Result:=False;
end
else
Result:=True;
end;
end.