Jump to content
LordJashin

How does try except finally work again? finally executes twice

Recommended Posts

I did the step thing with this and it went through everything then after the Exit; did the finally again. Why is this happening? Someone explain to me how nesting works with Try, except, finally. If I just do If then Report, it works fine, does it once.

 

Need to make some custom stuff to make this updater cleaner. Any suggestions welcome.

[sCAR] finally

SetArrayLength(po, 5);

po[0] := Pos('script.name', Page);

po[1] := PosEx(':=', Page, po[0]);

po[2] := PosEx(Script.Name, Page, po[1]);

if po[2] = 0 then

begin

ReportAll('Updater: Current Script.Name does not match the one at the Update URL', false);

Exit;

end;

 

// if Copy(Page, po[2], Length(Script.Name)) = Script.Name then

end;[/sCAR]

 

---------- Post added at 01:50 AM ---------- Previous post was at 12:45 AM ----------

 

I fixed the problem, but why can't I use begin end in finally?

Link to comment
Share on other sites

Try Except and finally are error containment methods but also have alot of other good uses.

the basic syntax is

[scar]

Procedure Test;

Begin

Try

//Code you want normally executed

Except

// if an error occurs above this will be executed

finally

// this is always executed even if a exit command was called within the try

end;

end;

[/scar]

 

---------- Post added at 04:01 AM ---------- Previous post was at 03:54 AM ----------

 

As far as your updating method here is my method i created.

Instructions

Change the url to the path where you data is saved.

Add a file called versions < has to be a txt file inside this file just add your verison numbers like example


1.0 1.1 2.0
[/Code]

When the script is ran it will download version 2.0 not any of the others

 

then name your script what ever your version number is so like 2.0.txt <- also has to be a txt file..

 

[scar]

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Contributors: ShadowRecon,RSutton

Description: Global varaibles for Updating Script.

Date Created: February 25th 2012.

Last Modification: February 25th 2012. By ShadowRecon RS2 Build 701.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

var

CheckVer, URL, DLVer, Latest,Old: string;

 

Const

ScriptName = 'UB_Willow_Pro'; // name u want it saved as

DataLoc = 'Wj37H36if'; // Folder

 

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

procedure UB_DownloadScript;

Description: Downloads most recent version.

Date Created: February 25th 2012.

Last Modification: February 25th 2012. By ShadowRecon RS2 Build 701.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

procedure UB_DownloadScript;

var

NewFile: Integer;

NewScript: string;

begin

if (GetApplication.MessageBox('Do you wish to continue with the download? ', 'Download '+ScriptName+'?', 4) <> 6) then

begin

WriteLn('Download cancelled....');

Exit;

end;

WriteLn('Please accept the SCAR Firewall''s request to allow the new version to be downloaded');

Status('Downloading script and other required files... please wait.');

NewScript := GetPage(URL);

if (NewScript = '') then

begin

WriteLn('Could not get the requested script.');

Writeln('Please Post This On UnitedBots.Net Forums.');

Exit;

end;

SaveSetting(ScriptName,'Version',Latest);

NewFile := RewriteFile(ScriptPath + ScriptName+' Ver ' + Trim(DLVer) + '.scar', False);

WriteFileString(NewFile, NewScript);

WriteLn('Script successfully downloaded to: ' + ScriptPath + ScriptName+' ver ' + Trim(DLVer) + '.scar');

WriteLn('Thank You');

ShowMessage('Please open new downloaded version '+Trim(DLVer));

TerminateScript;

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

procedure UB_GetDetails;

Contributors: ShadowRecon

Description: Gets most recent script version.

Date Created: February 25th 2012.

Last Modification: February 25th 2012. By ShadowRecon RS2 Build 701.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

procedure UB_GetDetails;

begin

ClearDebug;

WriteLn('Please accept the SCAR Firewall''s request to allow us to check the version.');

DLVer := ' ' + '0.0' + ' ';

OLD := LoadSetting(ScriptName,'Version');

CheckVer := GetPage('http://www.unitedbots.net/PaidScripts/'+DataLoc+'/Version.txt');

Latest := Trim(Right(CheckVer, 4));

if Latest = OLD then

Begin

Writeln('Your Script Is Currently Up To Date!');

Exit;

end;

if (Pos(DLVer, CheckVer) = 0) then

DLVer := Latest;

URL := 'http://www.unitedbots.net/PaidScripts/'+DataLoc+'/' + Trim(DLVer) + '.txt';

UB_DownloadScript;

end;

[/scar]

 

Note: This saves the current version that was downloaded and if when it checks the version file if its the same as the old version downloaded it wont download anything. only when a new version is posted will it download anything. Just put the GetDetails function in the start of your script and it will do the rest =p[color=Silver]

 

[size=1]---------- Post added at 04:30 AM ---------- Previous post was at 04:01 AM ----------[/size]

 

[/color]

I fixed the problem, but why can't I use begin end in finally?

Because it doesnt work like that. =p Ive added a very simple method for adding script updating to the GMRL include it uses pastebin you may want to take a look at it. Its under the Core folder in the GMRL include.

Edited by shadowrecon
Link to comment
Share on other sites

Note: Finally will repeat itself once if you put exit; in it.

 

Your way works, Looks scary though. It needs parameters D:

 

Check the scriptname and version inside the script that is in scar and on the web. Easy. If someone changes the version on the script to the latest version without updating the script, you can make scar check for script size too, aka how many characters or w/e from program to end.

 

So this is how it would work: Checks for different ScriptVersion at URL. The URL will be a page that has the scar script inside the Source. If less than w/e update, if greater than say error and ask them to update. If ScriptVersion is the same along with ScriptName ofc, then check the script size. If Script size is significantly different then update.

 

For script size it might be tricky. If user's have to fill out things in your script you might have to adjust this. Usually this isn't the case though.

Then just save in a string from program to end., then save as file. Or I was thinking there might be a way to overwrite the current script. Maybe only if it was already saved though.

--------

 

That's my idea for it, it has to be perfect :P.

Going to integrate this with my script info include.

Edited by LordJashin
Link to comment
Share on other sites

Check my posted example within the GRML include under CORE folder the name is web. That shows a simpler example.

 

That posted example works flawlessly and with an FTP client you can update scripts quickly. The scriptname in that example is only used for saving the script file. All of the strings are just for user clarification of whats going on. if the script version is different than the current one it will download the latest version. which is the far right version or you can simply just put one version at a time but this gives you the ability to have multiple scripts and i had another example that could download any version the user wanted to.

Link to comment
Share on other sites

Check my posted example within the GRML include under CORE folder the name is web. That shows a simpler example.

 

That posted example works flawlessly and with an FTP client you can update scripts quickly. The scriptname in that example is only used for saving the script file. All of the strings are just for user clarification of whats going on. if the script version is different than the current one it will download the latest version. which is the far right version or you can simply just put one version at a time but this gives you the ability to have multiple scripts and i had another example that could download any version the user wanted to.

Well when you make the scar script ask them if they want to update, you can make it save the script somewhere, or overwrite the current one (maybe), and with this they can get multiple script versions. For old script versions you could just make an archive or w/e. I'd make a second way to get the older versions, updates are updates, if you want older version then current updated then your not really updating. Make like a script downloader or something.

Edited by LordJashin
Link to comment
Share on other sites

Well when you make scar ask them if they want to update, you can make it save the script somewhere, or overwrite the current one (maybe), and with this they can get multiple script versions. For old script versions you could just make an archive or w/e. I'd make a second way to get the older versions, updates are updates, if you want older version then current updated then your not really updating. Make like a script downloader or something.

 

just to clarify i dont make "Scar" =p Thats all on Freddy. but essentially thats what i did, i had 2 separate functions one to update and one to revert to previous script versions.

Link to comment
Share on other sites

just to clarify i dont make "Scar" =p Thats all on Freddy. but essentially thats what i did, i had 2 separate functions one to update and one to revert to previous script versions.
Well you did it with two files I want to do it with one xD. My bad on the make scar. Edited by LordJashin
Link to comment
Share on other sites

Here you go nothing fancy but it will either download the most recent version of a script if it is not up todate if version is set to '0.0' or it can download a particular version

like '1.1' Heres a working example

[scar]

Procedure ScriptUpdating(URL, Name, Version: String);

Var

Script,Latest,CurVersion: String;

NewFile: Integer;

Begin

Script := GetPage(URL);

Latest := Trim(Right(Between('<Versions>','</Versions>',Script),4));

CurVersion := LoadSetting(Name,'Version');

If (CurVersion = Latest) and (Version = '0.0') then

Exit

else

Begin

SaveSetting(Name,'Version',Latest);

Version := Latest;

end;

Script := Between('<V'+Version+'>','</V'+Version+'>',Script)

NewFile := RewriteFile(ScriptPath + Name+' Ver ' + Trim(Latest) + '.scar', False);

WriteFileString(NewFile, Script);

TerminateScript;

end;

[/scar]

 

Example uploaded script / downloaded script

[scar]

//<Versions> 1.0 1.1 </Versions>

//<V1.0>

Program Test1.0;

 

Begin

Writeln('Version 1.0');

end.

//</V1.0>

 

//<V1.1>

Program Test1.1;

 

Begin

Writeln('Version 1.1');

end.

//</V1.1>

[/scar]

Edited by shadowrecon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...