HandleDialupConnectionsV2
From 40tude Dialog Wiki
Contents |
Handle dialup connections Version2
The script presented below automates the periodic retrieval of news and emails.
When called for the first time, it will check if there is an active RAS-connection, and will establish one if there isn't. Furthermore, it starts timers that will retrieve new news every 30 minutes and new emails every 10 minutes (By default. Please be considerate about net resources and don't lower these numbers unless there is a very specific reason to do so).
On second call, it will stop the automatic retrieval and ask you to decide whether the RAS connection shall be torn down, too.
Subsequent calls will repeat this process.
Installation
To make this script work for you, you need to create two custom scripts and create/extend three event scripts.
Event script "OnStartup"
program OnStartup; procedure OnStartup; begin //Set timer for mails, in millisceonds timer1.interval:=60000*10; //Set timer for news, in millisceonds timer2.interval:=60000*30; end; begin end.
Event script "OnTimer1"
program OnTimer1;
procedure OnTimer1;
begin
ADo('GetNewEmailsForAllIdentities');
end;
begin
end.
Event script "OnTimer2"
program OnTimer2;
procedure OnTimer2;
begin
ADo('GetNewHeadersInSubscribedGroups');
end;
begin
end.
Custom script "zRas.ds"
This script uses zRas.ds, a library that provides functions to handle dialup connections in Dialog scripts. You need to create a custom script called zRas.ds containing the script linked here.
Custom script "StartStopRasTimer"
Program StartStopRasTimer;
uses Forms;
function GetTickCount : cardinal; external 'GetTickCount@kernel32.dll stdcall';
function messageBox(hWnd: Cardinal; lpText, lpCaption: PChar; uType: longword): Integer; external 'MessageBoxA@user32.dll stdcall';
procedure Delay(const Milliseconds: Word);
var DelayTill: LongWord;
begin
DelayTill := GetTickCount + Milliseconds;
while ((GetTickCount) < DelayTill) do begin
Application.ProcessMessages;
Sleep(0);
end;
end;
{$I zRas}
var myProvider, myUsername, myPassword: String;
connection: LongWord;
dialedByScript: Boolean;
messageBoxResult : Integer;
const
cMBoxTitle = 'Timer anhalten?'; //"Stop timer?"
cMBoxPrompt = 'Soll die Internetverbindung getrennt werden'; //"Shall the dialup connection be cut?"
MB_YESNO = 3;
IDYES = 6;
IDNO = 7;
MB_SYSTEMMODAL = 4096;
MB_ICONQUESTION = 32;
Begin
// dial-up parameters
myProvider := 'NameDeinerDFUeVerbindung'; //Name of the RAS connection
myUsername := 'Username'; //Login of the connection
myPassword := 'DeinPassword'; //Password of the connection
// check, if already connected
connection := RasGetConnection();
lockdisplay;
if timer1.enabled then
begin
messageBoxResult := messageBox(0, cMBoxPrompt + ' ?', CMBoxTitle, MB_YESNO+MB_SYSTEMMODAL+MB_ICONQUESTION);
if (messageBoxResult = IDYES) then
begin
timer1.enabled := not(timer1.enabled)
timer2.enabled := not(timer2.enabled)
WriteToLog ('Automatisches Laden neuer Artikel ausgeschaltet...',4);
RasHangup( connection );
end
else if (messageBoxResult = IDNO) then
begin
messageBox(0,'Es wurde nur der Timer gestoppt!', 'Hinweis', 0+MB_SYSTEMMODAL);
timer1.enabled := not(timer1.enabled)
timer2.enabled := not(timer2.enabled)
WriteToLog ('Automatisches Laden neuer Artikel ausgeschaltet...',4);
end;
end
else
begin
if not timer1.enabled then
begin
timer1.enabled := not(timer1.enabled);
timer2.enabled := not(timer2.enabled);
if connection = 0 then
begin
dialedByScript := True;
connection := RasDial( myProvider, myUsername, myPassword );
if connection = 0 then
begin
Application.MessageBox( 'Dialing failed! Error: '
+ RasErrorText(RasLastError), 'Dial', 0 );
unlockdisplay;
exit;
end
end
end
if timer1.enabled then
WriteToLog ('Timer eingeschaltet...',4);
if connection <> 0 then
Delay( 2000 );
if connection <> 0 then
ADo('GetNewHeadersInSubscribedGroups');
ADo('GetNewEmailsForAllIdentities');
end
unlockdisplay;
End.
Maik Prinz