📄 itignet.pas
字号:
end;
end;
{ case ThreadAction of
wtCheckVersion:
begin
ActionCheck;
end;
wtDownload:
begin
ActionDownload;
end;
wtGetHelper:
begin
ActionDownloadHelper;
end;
wtGetFile:
begin
ActionDownloadFile;
end;
wtExit:
begin
Quit := True;
DebugMethod := nil; // the debug form is about to be deleted...
end;
end;}
if ThreadAction = 'EXIT' then
begin
Quit := True;
DebugMethod := nil; // the debug form is about to be deleted...
end;
if ResultCode = irReady then
begin
// the action has not set a code....
ResultCode := irError;
ErrorMessage := 'Unimplemented Function';
end;
Done;
//MessageBeep(MB_ICONEXCLAMATION);
except
on E : InetException do
begin
Debug('Exception in helper thread ' + E.Message);
if (E.Error = ERROR_INTERNET_SEC_CERT_CN_INVALID) or (E.Error = ERROR_INTERNET_INVALID_CA) then
begin
ResultCode := irTryAgain;
ErrorMessage := E.Message + 'The InfoIn certificate has not been installed';
end
else if E.Error = 0 then
begin
ResultCode := irTryAgain;
ErrorMessage := '';
end
else
begin
ErrorMessage := E.Message;
ResultCode := irError;
end;
end;
on E : CancelException do
begin
ResultCode := irCancel;
end;
on E : Exception do
begin
Debug('Exception in helper thread ' + E.Message);
ErrorMessage := E.Message;
ResultCode := irError;
end;
end;
Prog := nil;
if not Quit then
begin
//if we have not exited then
Debug('Sending done message');
PostMessage(Handle, WM_THREAD_COMPLETE, Integer(self), 0);
Debug('Set E1');
SetEvent(Event1);
WaitEvent(Event2);
end;
end;
// signal E1 for the last time. This way the destructor knows it is safe to delete us...
SetEvent(Event1);
end;
{procedure TItigNet.ActionDownload;
var
Post : TPostFile;
Results : TStringList;
Keys : TStringList;
Values : TStringList;
begin
Results := TStringList.Create;
Post := TPostFile.Create(Option, DebugMethod, self);
try
Keys := TStringList.Create;
Values := TStringList.Create;
Keys.Add('action');
Values.Add('download');
Keys.Add('application');
Values.Add(Option.ApplicationName);
//Keys.Add('version');
//Values.Add(Option.CurrentVersion);
//Keys.Add('versionno');
//Values.Add(IntToStr(Option.VersionNumber));
Post.ScriptName := Option.GetScriptName;
Option.DownloadedFile := Option.GetTempPath + Option.ApplicationName + '.autoupgrade';
Post.ReceiveFile(Keys, Values, '', Option.DownloadedFile, Results);
Debug(Results.Text);
ResultCode := irOK;
Keys.Free;
Values.Free;
Results.Free;
finally
Post.Free;
end;
end;}
{procedure TItigNet.ActionDownloadHelper;
var
Post : TPostFile;
Results : TStringList;
Keys : TStringList;
Values : TStringList;
begin
Results := TStringList.Create;
Post := TPostFile.Create(Option, DebugMethod, self);
try
Keys := TStringList.Create;
Values := TStringList.Create;
Keys.Add('action');
Values.Add('gethelper');
Keys.Add('application');
Values.Add(Option.ApplicationName);
Post.ScriptName := Option.GetScriptName;
Post.ReceiveFile(Keys, Values, '', Option.DownloadedFile, Results);
Debug(Results.Text);
ResultCode := irOK;
Keys.Free;
Values.Free;
Results.Free;
finally
Post.Free;
end;
end;}
{procedure TItigNet.ActionDownloadFile;
var
Post : TPostFile;
Results : TStringList;
Keys : TStringList;
Values : TStringList;
begin
Results := TStringList.Create;
Post := TPostFile.Create(Option, DebugMethod, self);
try
Keys := TStringList.Create;
Values := TStringList.Create;
Keys.Add('action');
Values.Add('getfile');
Keys.Add('application');
Values.Add(Option.ApplicationName);
Keys.Add('filename');
Values.Add(Option.DownloadedFile);
Post.ScriptName := Option.GetScriptName;
Post.ReceiveFile(Keys, Values, '', Option.DownloadedFile, Results);
Debug(Results.Text);
DecodeResults(Keys, Values, Results);
// ResultCode := irOK;
Keys.Free;
Values.Free;
Results.Free;
finally
Post.Free;
end;
end;}
{procedure TItigNet.ActionReportBug;
begin
end;}
function TItigNet.GetResult : Integer;
begin
Result := ResultCode;
end;
procedure TItigNet.ClearResult;
begin
ResultCode := irReady;
end;
function TItigNet.GetErrorMsg: String;
begin
Result := ErrorMessage;//'An error occured';
end;
function TItigNet.IsConnected : Boolean;
var
Flags : DWORD;
begin
Result := False;
if InternetGetConnectedState(@Flags, 0) then
begin
if (Flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM then
begin
option.Hangup := false;
Result := True;
end;
if (Flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then
begin
option.Hangup := false;
Result := True;
end;
end;
end;
function TItigNet.Dial: Boolean;
begin
Result := InternetAttemptConnect(0) = ERROR_SUCCESS;
option.Hangup := Result;//true;
//Result := InternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED, Handle)
end;
procedure TItigNet.Hangup;
var
CommandLine : String;
StartupInfo : TStartupInfo;
ProcessInfo : TProcessInformation;
begin
ZeroMemory(@StartupInfo, sizeof(TStartupInfo));
ZeroMemory(@ProcessInfo, sizeof(TProcessInformation));
CommandLine := ExtractFilePath(Application.ExeName) + 'hup.exe /hup';
if CreateProcess (nil,
PChar (Commandline),
nil, nil, False, 0, nil, nil,
StartupInfo,
ProcessInfo) then
begin
CloseHandle (ProcessInfo.hThread);
CloseHandle (ProcessInfo.hProcess);
end
else
begin
ShowMessage(IntToStr(GetLastError));
end;
// Result := InternetAutodialHangup(0)
// Result := True;
end;
procedure TItigNet.setMessage(msg: String);
begin
if Prog.isCancelled then
begin
raise CancelException.Create('');
end;
ptMsg := Msg;
Synchronize(ptSetMessage);
end;
procedure TItigNet.setNoActions(toVal: Integer);
begin
if Prog.isCancelled then
begin
raise CancelException.Create('');
end;
ptVal := toVal;
Synchronize(ptSetNoAct);
end;
procedure TItigNet.setPos(Position: Integer);
begin
if Prog.isCancelled then
begin
raise CancelException.Create('');
end;
ptVal := Position;
Synchronize(ptSetPos);
end;
procedure TItigNet.actionDone();
begin
if Prog.isCancelled then
begin
raise CancelException.Create('');
end;
Synchronize(ptActionDone);
end;
function TItigNet.GetHandle : hWnd;
begin
if Assigned(Prog) then
begin
Result := Prog.GetHandle;
end
else
begin
Result := 0;
end;
end;
function TItigNet.IsCancelled : Boolean;
begin
if Assigned(Prog) then
begin
Result := Prog.IsCancelled;
end
else
begin
Result := False;
end;
end;
procedure TItigNet.Done;
begin
Synchronize(ptDone);
end;
procedure TItigNet.setPhases(toPhases: integer);
begin
ptVal := toPhases;
Synchronize(tpSetPhases);
end;
procedure TItigNet.phaseDone;
begin
Synchronize(tpPhaseDone);
end;
function TItigNet.QueryInterface(const IID: TGUID; out Obj): HResult;
const
E_NOINTERFACE = HResult($80004002);
begin
if GetInterface(IID, Obj) then Result := 0 else Result := E_NOINTERFACE;
end;
function TItigNet._AddRef: Integer;
begin
Result := 1;
end;
function TItigNet._Release: Integer;
begin
Result := 1;
end;
procedure TItigNet.ptSetMessage;
begin
if Assigned(Prog) then
begin
Prog.setMessage(ptMsg);
end;
end;
procedure TItigNet.ptSetNoAct;
begin
if Assigned(Prog) then
begin
Prog.setNoActions(ptVal);
end;
end;
procedure TItigNet.ptSetPos;
begin
if Assigned(Prog) then
begin
Prog.setPos(ptVal);
end;
end;
procedure TItigNet.ptActionDone;
begin
if Assigned(Prog) then
begin
Prog.actionDone;
end;
end;
procedure TItigNet.ptDone;
begin
if Assigned(Prog) then
begin
Prog.Done;
end;
end;
procedure TItigNet.tpSetPhases;
begin
if Assigned(Prog) then
begin
Prog.setPhases(ptVal);
end;
end;
procedure TItigNet.tpPhaseDone;
begin
if Assigned(Prog) then
begin
Prog.phaseDone;
end;
end;
procedure TItigNet.OpenLogFile;
begin
{ AssignFile(LogFile, 'itigbackup.log');
try
Append(LogFile);
except
Rewrite(LogFile);
end;
Writeln(LogFile, '');
Log('Program startup');}
end;
procedure TItigNet.Log(S : String);
begin
{ Writeln(LogFile, DateTimeToStr(now) + ' - ' + S);
Flush(LogFile);}
Debug(S);
end;
procedure TItigNet.CloseLogFile;
begin
{ CloseFile(LogFile);}
end;
procedure TItigNet.RegisterRPC(Name : String; Method : TRPCMethod);
var
MethodPointer : TMethodPointer;
begin
MethodPointer := TMethodPointer.Create;
MethodPointer.SetMethod(@@Method);
RPCMethods.AddObject(Name, MethodPointer);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -