unit _i_dl_explorer;
interface
uses
SysUtils, Classes,ScktComp,ComCtrls,forms;
type
T_i_dl_explorer_THREAD = class(TThread)
private
FCCC : TClientSocket;
//FLastError :Exception;
K_anceled :boolean;
K_stoped :boolean;
K_cpu_kk :Boolean;
K_f_is_end :Boolean;
kudit :Boolean;
NOACCESS :Boolean;
_data_file :TFileStream;
rcv :Int64;
ini_A,out_A:Int64; // detection of the kk_dl progress
_strERROR : string;
protected
procedure Execute; override;
procedure _shawa_OK_Downloading;
procedure shawa_c_Process;
procedure shawaError;
procedure On_CC_AA_thread_terminated(Sender: TObject);
public
_ip :string;
_full_file :string;
_pn :string[2];
_tp :char;
_sav_file :string;
_c_item :TListItem;
constructor Create;
destructor Destroy; override;
end;
implementation
uses unit1,_uc_funcs,_uc_refs_consts,_uc_crypto,_uc_refs_vars,_uc_GuiLanG;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
constructor T_i_dl_explorer_THREAD.Create;
begin
// before creation
//inc(_ACTIVE_DOWNLOADS_COUNT);
//_fgui.CC1.Caption:=IntToStr(_ACTIVE_DOWNLOADS_COUNT);
inherited Create(True); // Intially suspended
FreeOnTerminate := True;
OnTerminate := On_CC_AA_thread_terminated;
FCCC := TClientSocket.Create(Application);
FCCC.ClientType := ctBlocking;
end;
//------------------------------------------------------------------------------
destructor T_i_dl_explorer_THREAD.Destroy;
begin
FCCC.Free;
inherited;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD._shawa_OK_Downloading;
begin
_c_item.SubItems[5]:=___ccc__0092__Downloading;
Application.ProcessMessages;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.shawa_c_Process;
begin
K_anceled :=_c_item.set_cancel;
K_stoped :=_c_item.set_stop;
K_f_is_end :=_c_item.ITM_READEN=_c_item.ITM_F_SIZE;
// direct here to show speed and exo works
_c_item.SubItems[1]:=_octos(_c_item.ITM_READEN); //read
Application.ProcessMessages;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.On_CC_AA_thread_terminated(Sender: TObject);
begin
if (_FXOC_MAIN.izDebugerON.Checked) then _FXOC_MAIN.TheLOGGER.Log('_strERROR:'+_strERROR);
//dec(_ACTIVE_THREADS_COUNT);
//dec(_ACTIVE_DOWNLOADS_COUNT);
//_fgui.CC1.Caption:=IntToStr(_ACTIVE_DOWNLOADS_COUNT);
if _c_item=nil then exit;
if K_stoped then _c_item._Pozo:=13;
if K_cpu_kk then begin
inc(_c_item._ReCont); // count how many kk found
_c_item._Pozo:=19;
if ini_A<>out_A then _c_item._ReCont:=1;// progress detected, dont inc the killing
end;
if kudit then begin
_c_item._ReCont:=0;
_c_item._Pozo :=12;
end;
if K_anceled then begin
DeleteFile(_sav_file);
_c_item._Pozo :=45; // go show canceled to delete in 46
end;
if K_f_is_end then begin // file is end successfully
_c_item._Pozo :=14; // completed !!!
_c_item.sava_f_thr :=_sav_file;
end;
if (not K_f_is_end) and (_c_item._Pozo=11) then _c_item._Pozo :=15;
if NOACCESS then _c_item._Pozo:=18; // 18 new for no access to del file !
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.shawaError;
begin
if _c_item<>nil then begin
//_LoG('the_DL error : '+_strERR,0,true);
_c_item._Pozo :=16;
end;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.Execute;
var
sk: TWinSocketStream;
SIZIN, BufSize: Int64;
PBuf: PByteArray;
s:string;
begin
//inc(_ACTIVE_THREADS_COUNT);
K_anceled :=false;
K_cpu_kk :=false;
K_f_is_end :=false;
kudit :=false;
NOACCESS :=false;
try //----------------t1
FCCC.Host__ip := _ip; // a must here
FCCC.Port := _C_EXOSEE_MASTER_SERVER_PORT; // a must here
FCCC.Active := True;
sk := TWinSocketStream.Create(FCCC.Socket, 20000);
try ////----------------t2
FCCC.Socket.SendText(TCrypto._BarzaToon(_EXO_iDL_EXPL));
if sk.WaitForData(10000) then // wait 10 sec
begin
s:=FCCC.Socket.ReceiveText;
if (s[2]='G') and (s[4]='g') then // info_signal given ... then go ....
begin
_strERROR:='22';
if s[3]='0' then kudit:=true; // will disable FCC in code fmOpenReadWrite or
if s[3]='1' then
begin
_c_item._Pozo:=11; // fmShareDenyWrite
if not FileExists(_sav_file) then FileClose(FileCreate(_sav_file));
_data_file :=TFileStream.Create(_sav_file,fmOpenWrite or fmShareDenyWrite);
try //----------------t3
s:=format('_DW_%s_%s_%s_%.16x_%s',[_tp,_pn,_VV_LOCAL_USER_PC_ID,_data_file.Size,_full_file]);
_data_file.Position :=_data_file.Size;
_c_item.ITM_READEN :=_data_file.Size; // it is 0 if just created
ini_A :=_c_item.ITM_READEN; // stok ini_size
out_A :=ini_A; // reper the stok
_strERROR:=_strERROR+'33';
s:=TCrypto._BarzaToon(s);
sk.Write(s[1], Length(s)); // Send request
sk.WaitForData(20000); // wait
sk.Read(SIZIN, SizeOf(SIZIN)); // read size offseted !!!
_strERROR:='s:'+TCrypto._SimSim(s)+'.';
// _strERROR:s:_DW_0_02_1E98BA345D_0000000000000000_\en_windows_vista_x86_dvd_X12-34293.iso.-1616353280
//* error -1
//------------------------
if (SIZIN<>-777) then
begin
//----------------------------
_strERROR:=_strERROR+IntToStr(SIZIN);
Synchronize(_shawa_OK_Downloading); // to caption only once 1
if SIZIN < MAX_BUFFER_EXPLOLRER_DOWNLOADING then BufSize := SIZIN else BufSize := MAX_BUFFER_EXPLOLRER_DOWNLOADING;
GetMem(PBuf, BufSize);
try //----------------t4
while (SIZIN >0) and (FCCC.Socket.Connected) do // (not _cc_kk)
begin
if SIZIN > BufSize then rcv := BufSize else rcv := SIZIN;
if (sk.WaitForData(10000)) then
begin
rcv := sk.Read(PBuf^, rcv);
_data_file.Write(PBuf^, rcv);
Dec(SIZIN, rcv);
inc(_c_item.ITM_READEN,rcv); // for per%
end;
if rcv=0 then K_cpu_kk:=true;
Synchronize(shawa_c_Process);
if (K_anceled or K_stoped or K_cpu_kk or _THE_EXOSEE_APPLICATION_IS_TERMINATED) then break;
end;
finally FreeMem(PBuf); end; //----------------t4 , freemem(...,BufSize) was in >=17-pr3
end//-777 control
else NOACCESS:=true; // set no access for stat
finally _data_file.Free; end; //----------------t3
end; // GO_ON end
end;
end;
finally
FCCC.Socket.Close;
sk.Free;
end; //----------------t2 FCCC.Socket.Close;
(*
except
on E: Exception do
begin
_strERR:=E.Message;
Synchronize(shawaError);
end;
end;
*)
Except Synchronize(shawaError); end; //----------------t1
end;
//------------------------------------------------------------------------------
end.
interface
uses
SysUtils, Classes,ScktComp,ComCtrls,forms;
type
T_i_dl_explorer_THREAD = class(TThread)
private
FCCC : TClientSocket;
//FLastError :Exception;
K_anceled :boolean;
K_stoped :boolean;
K_cpu_kk :Boolean;
K_f_is_end :Boolean;
kudit :Boolean;
NOACCESS :Boolean;
_data_file :TFileStream;
rcv :Int64;
ini_A,out_A:Int64; // detection of the kk_dl progress
_strERROR : string;
protected
procedure Execute; override;
procedure _shawa_OK_Downloading;
procedure shawa_c_Process;
procedure shawaError;
procedure On_CC_AA_thread_terminated(Sender: TObject);
public
_ip :string;
_full_file :string;
_pn :string[2];
_tp :char;
_sav_file :string;
_c_item :TListItem;
constructor Create;
destructor Destroy; override;
end;
implementation
uses unit1,_uc_funcs,_uc_refs_consts,_uc_crypto,_uc_refs_vars,_uc_GuiLanG;
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
constructor T_i_dl_explorer_THREAD.Create;
begin
// before creation
//inc(_ACTIVE_DOWNLOADS_COUNT);
//_fgui.CC1.Caption:=IntToStr(_ACTIVE_DOWNLOADS_COUNT);
inherited Create(True); // Intially suspended
FreeOnTerminate := True;
OnTerminate := On_CC_AA_thread_terminated;
FCCC := TClientSocket.Create(Application);
FCCC.ClientType := ctBlocking;
end;
//------------------------------------------------------------------------------
destructor T_i_dl_explorer_THREAD.Destroy;
begin
FCCC.Free;
inherited;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD._shawa_OK_Downloading;
begin
_c_item.SubItems[5]:=___ccc__0092__Downloading;
Application.ProcessMessages;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.shawa_c_Process;
begin
K_anceled :=_c_item.set_cancel;
K_stoped :=_c_item.set_stop;
K_f_is_end :=_c_item.ITM_READEN=_c_item.ITM_F_SIZE;
// direct here to show speed and exo works
_c_item.SubItems[1]:=_octos(_c_item.ITM_READEN); //read
Application.ProcessMessages;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.On_CC_AA_thread_terminated(Sender: TObject);
begin
if (_FXOC_MAIN.izDebugerON.Checked) then _FXOC_MAIN.TheLOGGER.Log('_strERROR:'+_strERROR);
//dec(_ACTIVE_THREADS_COUNT);
//dec(_ACTIVE_DOWNLOADS_COUNT);
//_fgui.CC1.Caption:=IntToStr(_ACTIVE_DOWNLOADS_COUNT);
if _c_item=nil then exit;
if K_stoped then _c_item._Pozo:=13;
if K_cpu_kk then begin
inc(_c_item._ReCont); // count how many kk found
_c_item._Pozo:=19;
if ini_A<>out_A then _c_item._ReCont:=1;// progress detected, dont inc the killing
end;
if kudit then begin
_c_item._ReCont:=0;
_c_item._Pozo :=12;
end;
if K_anceled then begin
DeleteFile(_sav_file);
_c_item._Pozo :=45; // go show canceled to delete in 46
end;
if K_f_is_end then begin // file is end successfully
_c_item._Pozo :=14; // completed !!!
_c_item.sava_f_thr :=_sav_file;
end;
if (not K_f_is_end) and (_c_item._Pozo=11) then _c_item._Pozo :=15;
if NOACCESS then _c_item._Pozo:=18; // 18 new for no access to del file !
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.shawaError;
begin
if _c_item<>nil then begin
//_LoG('the_DL error : '+_strERR,0,true);
_c_item._Pozo :=16;
end;
end;
//------------------------------------------------------------------------------
procedure T_i_dl_explorer_THREAD.Execute;
var
sk: TWinSocketStream;
SIZIN, BufSize: Int64;
PBuf: PByteArray;
s:string;
begin
//inc(_ACTIVE_THREADS_COUNT);
K_anceled :=false;
K_cpu_kk :=false;
K_f_is_end :=false;
kudit :=false;
NOACCESS :=false;
try //----------------t1
FCCC.Host__ip := _ip; // a must here
FCCC.Port := _C_EXOSEE_MASTER_SERVER_PORT; // a must here
FCCC.Active := True;
sk := TWinSocketStream.Create(FCCC.Socket, 20000);
try ////----------------t2
FCCC.Socket.SendText(TCrypto._BarzaToon(_EXO_iDL_EXPL));
if sk.WaitForData(10000) then // wait 10 sec
begin
s:=FCCC.Socket.ReceiveText;
if (s[2]='G') and (s[4]='g') then // info_signal given ... then go ....
begin
_strERROR:='22';
if s[3]='0' then kudit:=true; // will disable FCC in code fmOpenReadWrite or
if s[3]='1' then
begin
_c_item._Pozo:=11; // fmShareDenyWrite
if not FileExists(_sav_file) then FileClose(FileCreate(_sav_file));
_data_file :=TFileStream.Create(_sav_file,fmOpenWrite or fmShareDenyWrite);
try //----------------t3
s:=format('_DW_%s_%s_%s_%.16x_%s',[_tp,_pn,_VV_LOCAL_USER_PC_ID,_data_file.Size,_full_file]);
_data_file.Position :=_data_file.Size;
_c_item.ITM_READEN :=_data_file.Size; // it is 0 if just created
ini_A :=_c_item.ITM_READEN; // stok ini_size
out_A :=ini_A; // reper the stok
_strERROR:=_strERROR+'33';
s:=TCrypto._BarzaToon(s);
sk.Write(s[1], Length(s)); // Send request
sk.WaitForData(20000); // wait
sk.Read(SIZIN, SizeOf(SIZIN)); // read size offseted !!!
_strERROR:='s:'+TCrypto._SimSim(s)+'.';
// _strERROR:s:_DW_0_02_1E98BA345D_0000000000000000_\en_windows_vista_x86_dvd_X12-34293.iso.-1616353280
//* error -1
//------------------------
if (SIZIN<>-777) then
begin
//----------------------------
_strERROR:=_strERROR+IntToStr(SIZIN);
Synchronize(_shawa_OK_Downloading); // to caption only once 1
if SIZIN < MAX_BUFFER_EXPLOLRER_DOWNLOADING then BufSize := SIZIN else BufSize := MAX_BUFFER_EXPLOLRER_DOWNLOADING;
GetMem(PBuf, BufSize);
try //----------------t4
while (SIZIN >0) and (FCCC.Socket.Connected) do // (not _cc_kk)
begin
if SIZIN > BufSize then rcv := BufSize else rcv := SIZIN;
if (sk.WaitForData(10000)) then
begin
rcv := sk.Read(PBuf^, rcv);
_data_file.Write(PBuf^, rcv);
Dec(SIZIN, rcv);
inc(_c_item.ITM_READEN,rcv); // for per%
end;
if rcv=0 then K_cpu_kk:=true;
Synchronize(shawa_c_Process);
if (K_anceled or K_stoped or K_cpu_kk or _THE_EXOSEE_APPLICATION_IS_TERMINATED) then break;
end;
finally FreeMem(PBuf); end; //----------------t4 , freemem(...,BufSize) was in >=17-pr3
end//-777 control
else NOACCESS:=true; // set no access for stat
finally _data_file.Free; end; //----------------t3
end; // GO_ON end
end;
end;
finally
FCCC.Socket.Close;
sk.Free;
end; //----------------t2 FCCC.Socket.Close;
(*
except
on E: Exception do
begin
_strERR:=E.Message;
Synchronize(shawaError);
end;
end;
*)
Except Synchronize(shawaError); end; //----------------t1
end;
//------------------------------------------------------------------------------
end.