SRL Archive - SRL Archives

Function UpdateScript(Name, UpdateWebsite: String; Version: Integer): Boolean;


Floor66

2008-12-07 05:50:45

This function will check if you have the correct script by VersionChecking. It also downloads the correct script.

Program New;
{.include SRL\SRL.scar}

{*******************************************************************************
Function UpdateScript(Name, UpdateWebsite, Version: String): Boolean;
by: Floor66
Description: Auto-updates (any) script.
You _need_ to make a const like:
Const
Version = '1.00'; // MUST BE A STRING!
*******************************************************************************}

Function UpdateScript(Name, UpdateWebsite, Version: String): Boolean;
Var
Script, NewVersion : String;
NewS : Integer;
Begin
Script := GetPage(UpdateWebsite);
If Script <> '' Then
Begin
NewVersion := Between('Version = ''', ''';', Script);
WriteLn('Script version: '+ Version);
WriteLn('Latest version: '+ NewVersion);
If Version > NewVersion Then
Begin
WriteLn('Error. Please notify the script creator. Version is set incorrectly!');
Result := False;
Exit;
End;
If Not (Version = NewVersion) Then
Begin
WriteLn('Getting the latest script...');
NewS := RewriteFile(AppPath + 'Scripts\'+ Name +'.scar', False);
If WriteFileString(NewS, Script) Then
Begin
WriteLn('Successfully updated script to v'+ NewVersion +'!');
Result := True;
Exit;
End;
End;
End Else
Begin
WriteLn('Failed to get script.');
Result := False;
Exit;
End;
End;

{*******************************************************************************
Procedure EmptyLn;
By: Floor66
Description: Inserts an empty line in the debug box.
*******************************************************************************}

Procedure EmptyLn;
Begin
WriteLn('');
End;

Begin
SetupSRL;
ClearDebug;
UpdateScript('ScriptName', 'http://website.com/ScriptName.scar', '0.00');
EmptyLn;
End.

Wizzup?

2008-12-07 05:57:14

From: floor66
This function will check if you have the correct script by VersionChecking. It also downloads the correct script.

Program New;
{.include SRL\SRL.scar}

{*******************************************************************************
Function UpdateScript(Name, UpdateWebsite: String; Version: Integer): Boolean;
by: Floor66
Description: Auto-updates (any) script.
You _need_ to make a const like:
Const
Version = '1.00'; // MUST BE A STRING!
*******************************************************************************}

Function UpdateScript(Name, UpdateWebsite, Version: String): Boolean;
Var
Script, NewVersion : String;
NewS : Integer;
Begin
Script := GetPage(UpdateWebsite);
If Script <> '' Then
Begin
NewVersion := Between('Version = ''', ''';', Script);
WriteLn('Script version: '+ Version);
WriteLn('Latest version: '+ NewVersion);
If Version > NewVersion Then
Begin
WriteLn('Error. Please notify the script creator. Version is set incorrectly!');
Result := False;
Exit;
End;
If Not (Version = NewVersion) Then
Begin
WriteLn('Getting the latest script...');
NewS := RewriteFile(AppPath + 'Scripts\'+ Name +'.scar', False);
If WriteFileString(NewS, Script) Then
Begin
WriteLn('Successfully updated script to v'+ NewVersion +'!');
Result := True;
Exit;
End;
End;
End Else
Begin
WriteLn('Failed to get script.');
Result := False;
Exit;
End;
End;

{*******************************************************************************
Procedure EmptyLn;
By: Floor66
Description: Inserts an empty line in the debug box.
*******************************************************************************}

Procedure EmptyLn;
Begin
WriteLn('');
End;

Begin
SetupSRL;
ClearDebug;
UpdateScript('ScriptName', 'http://website.com/ScriptName.scar', '0.00');
EmptyLn;
End.


Wow, I never knew Pascal Script allowed you to compare strings with > and <…

Anyway, you better use StrToInt to turn the Version to an integer (or extended, for that matter), because this current comparison method doesn't work:

program New;

var
s, s2: string;
begin
s := '2.2';
s2 := '2.C';
if s > s2 then writeln('hoi');
end.

The following one works, but it's just not good practice to compare strings. Since they will most likely give you weird results.
program New;

var
s, s2: string;
begin
s := '2.2';
s2 := '2.1';
if s > s2 then writeln('hoi');
end.

Floor66

2008-12-07 06:23:56

I was doubting about that.. but how do I make it check if it's an int or ext…
And.. why can't we edit the topic title as it is in the thread list.. it's so anoying if you make a change and you can't add it so it's a misleading title >.<

Sandstorm

2008-12-07 13:24:21

Sweet, this is just about what I needed. Edited it a bit, as I use two different files (one for checking version, one for grabbing the script). :).

Quickmarch

2008-12-10 10:17:16

Maybe change the

If WriteFileString(NewS, Script) Then
Begin
WriteLn('Successfully updated script to v'+ NewVersion +'!');
Result := True;
Exit;
End;

To:


Result := WriteFileString(NewS, Script);
If Result Then
Begin
WriteLn('Successfully updated script to v'+ NewVersion +'!');
Exit;
End;

Just a suggestion :)