PDA

View Full Version : How to create a version checker



Rich
06-20-2009, 10:14 PM
In this tutorial I am going to teach you how to create a version checker for your scripts. First off, you are going to need to create a Notepad file. In this, you will type the version of your script. Example:

1.1
Then save it as Version.txt.

Now you will need to create a webpage to host this on. For my version checker, I use Webs. (www.webs.com/)

Once on Webs, (www.webs.com/) you will see a screen with this
http://g.imagehost.org/0238/1_80.jpg (http://g.imagehost.org/download/0238/1_80)
on it.

Enter what you want your website to be called. This is normally something to do with the script itself. Also enter a password. You must remember both of these for future reference.

After the form completion, you will see this
http://g.imagehost.org/0901/2_14.jpg (http://g.imagehost.org/download/0901/2_14)
Click on the circle tick box.

Now, near the top of the screen, there is
http://f.imagehost.org/0200/3_13.jpg (http://f.imagehost.org/download/0200/3_13)
Click on the circled area.

Somewhere on your screen, there is this
http://f.imagehost.org/0017/4_18.jpg (http://f.imagehost.org/download/0017/4_18)
Click on "File Manage" (the circled area).

Now click on "Single File Uploader".
http://g.imagehost.org/0310/5_3.jpg (http://g.imagehost.org/download/0310/5_3)

Now this pop-up will show.
http://g.imagehost.org/0713/6_3.jpg (http://g.imagehost.org/download/0713/6_3)
Find where you saved Version.txt, click on it, the press "Open".

Then press "Upload File".
http://g.imagehost.org/0610/7_13.jpg (http://g.imagehost.org/download/0610/7_13)

Now you should see something like this
http://g.imagehost.org/0763/8_1.jpg (http://g.imagehost.org/download/0763/8_1)
If you need to edit the version, then click on the circled area, and change
1.1to
1.2
That's the web-page related bit done. Now for the SCAR part.

Start of by declaring your procedure, and two string variables.
procedure VerCheck;
var
Version, Ver : string;

Then you begin the procedure, and tell the script what version it is.
begin
Ver:= '1.1'; //DO NOT CHANGE UNLESS YOU WANT AN OUTDATED VERSION!
Write in the "DO NOT CHANGE...", because someone out there will change it, and then start complaining that it is telling them they have an outdated version, when they don't.

Anyway, now we find the version of the web-page you set up earlier, from Version.txt, and check whether it matches the version declared in the script.

Version:= GetPage('http://WhatYouTypedInForYourAddress.webs.com/Version.txt');
if Version <> Ver then

What this does is gets what Version.txt says, and check whether they don't match. That's what <> does. If the version declared in the script doesn't match with the one it finds in Version.txt, it will
begin
ClearDebug;
WriteLn('');
WriteLn('Your version is not the latest. Get the latest version from:');
WriteLn('The Link To The Thread Of Your Script');
WriteLn('');
TerminateScript;
end else
And if they do match...
WriteLn('You are up to date!');
Wait(3500);
ClearDebug;
end;

What about news?

Have you seen scripts which come up with the updates from that version, and thought it was amazing? Well, it makes the script look good, but it is soooo easy.

Like for the version checker, open Notepad. Put in your news.

Updates:
- Added news!
- Fixed bugs.
- Other updates you might have made!
Save it as News.txt.

Upload it onto your website, just like with Version.txt. Again, you can edit it with the edit button.

Now open SCAR, and make a procedure like this. procedure NewsFlash;
var
News : string;

begin
News:= GetPage('http://WhatYouTypedInForYourAddress.webs.com/News.txt');
WriteLn(News);
Wait(10000);
ClearDebug;
end;

Easy!

Well, that's all from me for this tutorial. I hope it helped you, and if you need any help, please let me know.

Thanks,
Richard

Naum
06-21-2009, 08:45 PM
One of your examples needs a ' after the WriteLn..
Good tutorial though, I made one as well :)

caused
06-21-2009, 08:55 PM
Thanks : 'D. I'll be sure to add this =).

BTW: Is it also possible to directly download the latest version, (if not up to date), and move it to the scripts folder and overwrite the old one ?

Da 0wner
06-21-2009, 10:17 PM
Yes it is.

Macro_FTW
06-21-2009, 10:50 PM
Great tutorial. I've always wondered how to use this. Definitely going to use it in my next public script. o.o

~Macro_FTW

Rich
06-21-2009, 11:43 PM
Thanks for the great feedback guys. Any improvements you could suggest?


Yes it is.

Care to enlighten me? :)

Da 0wner
06-21-2009, 11:50 PM
I am on my iPod currently, so I cannot code yet :p. I will when I get on computer.

Rich
06-22-2009, 01:13 AM
Thanks. I'm surprised many (if any) scripts don't use it already.

senrath
06-22-2009, 01:16 AM
Thanks. I'm surprised many (if any) scripts don't use it already.

Because it can be a pain if it messes up and corrupts the file instead. It's not likely, but it can happen.

Edit: Anyway, here's how to do it:
procedure UpdateScript;
var
NewVersion, NewScript: String;
scriptFile: Integer;
begin
newVersion := GetPage('Whatever');
if Version <> newVersion then
begin
newScript := GetPage('Whatever part 2');
scriptFile := RewriteFile('Path to the script', True);
WriteFileString(scriptFile, newScript);
CloseFile(scriptFile);
end;
end;

Naum
06-22-2009, 11:29 PM
Also, use Try, except and finally to avoid getting errors :)

ian.
06-27-2009, 07:05 PM
Writeln(GetPage(http://themanscripts.webs.com/Version.txt)); puts out..



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Webs - Free website, free hosting, free webpage - Make a web site with photo albums, blogs, videos, forums and more!</title>
<meta name="Description" content="Make a website in minutes with simple tools for individuals, groups, or small businesses to share photos and videos, open a store, and build a member community.">
<meta name="Keywords" content="Webs, Free Website, Free Webpage, Free Web Hosting, Free hosting, make a website, how to make a website, free webpages, free websites, free website, free webpage, web hosting, free blog, online photo album, free online photo album, free online journal">

<meta name="verify-v1" content="UxO5L+cNDonE/AmYKOMyi7cUPUb9O/yDoPDA/FQFuFs=">
<meta name="robots" content="noodp">

<link rel="stylesheet" type="text/css" href="http://images.freewebs.com/static/global/theme/css/reset.css" media="screen">
<link rel="stylesheet" type="text/css" href="http://images.freewebs.com/static/global/theme/css/base.css" media="screen">
<link rel="stylesheet" type="text/css" href="http://images.freewebs.com/static/projects/public/css/public.css" media="screen">

<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="http://images.freewebs.com/static/projects/public/css/ie6fixes.css" media="screen">
<![endif]-->

<script type="text/javascript" src="http://images.freewebs.com/static/global/js/webs/evolve.js"></script>
<script type="text/javascript" src="http://images.freewebs.com/JS/Tracker.js"></script>

<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>

<script type="text/javascript">_qacct="p-44naSaXtNJt26";quantserve();</script>

<script type="text/javascript" src="http://partner.googleadservices.com/gampad/google_service.js"></script>
<script type="text/javascript">
GS_googleAddAdSenseService("ca-pub-4763110844767107");
GS_googleEnableAllServices();
</script>
<script type="text/javascript">
if (document.referrer) GA_googleAddAdSensePageAttr("google_page_url",document.referrer);
else GA_googleAddAdSensePageAttr("google_page_url","http://www.webs.com");

GA_googleAddSlot("ca-pub-4763110844767107", "external_notfound_300x250");
GA_googleAddSlot("ca-pub-4763110844767107", "external_notfound_728x90_frame");
</script>
<script type="text/javascript">
GA_googleFetchAds();
</script>
</head>

<body id="subpage">
<noscript>
<div id="quantcast_noscript">
<a href="http://www.quantcast.com/p-44naSaXtNJt26">
<img src="http://pixel.quantserve.com/pixel/p-44naSaXtNJt26.gif" style="display: none;" alt="Quantcast">
</a>
</div>
</noscript>

<div id="tree_top">
<div class="clearfix center960">
<h1 class="formally"><a href="http://www.webs.com/" title="Webs.com - grow a site, grow a community">Webs.com - grow a site, grow a community</a></h1>

<script type="text/javascript">
function focusInput(theOne) {
document.getElementById(theOne).className = "";
}
function blurInput(theOne) {
var el = document.getElementById(theOne);
if(el.value == '') {
el.className = theOne + '_background';
}
}
</script>
<form action="http://members.webs.com/login.jsp" method="post" id="login_leaf">

<p class="clearfix sign_in_fields">
<label for="FWloginUsername">Username:</label>
<input type="text" id="FWloginUsername" class="FWloginUsername_background" name="username" value="" onfocus="focusInput('FWloginUsername');" onblur="blurInput('FWloginUsername')">

<label for="FWloginPassword">Password:</label>
<input type="password" id="FWloginPassword" class="FWloginPassword_background" name="password" value="" onfocus="focusInput('FWloginPassword');" onblur="blurInput('FWloginPassword')">

<span id="sign_in_rearrange">
<input title="Sign in to your website" type="image" src="http://images.freewebs.com/static/projects/public/images/top_sign_in.png" id="sign_in_leaf">

</span>
</p>

<p class="clearfix login_extra">
<span id="remember_me_checkbox">
<input type="checkbox" id="FWloginRemember" name="remember">
</span>

<span id="remember_me">
Remember me
</span>

<span id="lost_password">
<a href="http://members.webs.com/lostPassword.jsp" title="Forgot your Password?">Forgot your Password?</a>
</span>
</p>
</form>
<ul id="navigation_tabs">
<li id="home"><a href="http://www.webs.com/" title="Home">Home</a></li>
<li id="personal"><a href="http://www.webs.com/pages/personal/" title="Personal">Personal</a></li>

<li id="groups"><a href="http://www.webs.com/pages/groups/" title="Groups">Groups</a></li>
<li id="business"><a href="http://www.webs.com/pages/business/" title="Business">Business</a></li>
</ul>
</div>

<div class="clearfix blackbar_minimal">
<div class="center960">
<h2>Page Not Found</h2>

</div>
</div>

<div id="tree_trunk">
<div class="clearfix center960">
<div class="clearfix public_content">
<div class="error_left">
<h3>What is Webs?</h3>

<p>

Webs is a free, do-it-yourself website publishing tool.
<a href="http://members.webs.com/Signup/" title="Sign up!">Sign up now</a> for free and get a free website, online photo album, blog, and more, PLUS, gain access to millions of websites within our network.
</p>


</div>
<div class="error_right" style="padding: 0 0 20px 0;">
<script type="text/javascript">
GA_googleFillSlot("external_notfound_300x250");
</script>


</div>

<div style="width: 100%; text-align: center;">
<script type="text/javascript">
GA_googleFillSlot("external_notfound_728x90_frame");
</script>
</div>

</div>


</div>
</div>

</div>

<div id="tree_roots" class="clearfix">
<div id="root_cluster">

<dl class="left">
<dt>About Us</dt>
<dd><a href="http://www.webs.com/pages/overview/" title="Overview">Overview</a></dd>
<dd><a href="http://www.webs.com/pages/team/" title="Management Team">Management Team</a></dd>
<dd><a href="http://www.webs.com/Careers/" title="Careers">Careers</a></dd>
<dd><a href="http://www.webs.com/websblog/" title="Company Blog">Company Blog</a></dd>

</dl>

<dl class="left">
<dt>Company Relations</dt>
<dd><a href="http://members.webs.com/PR/" title="Press Room">Press Room</a></dd>
<dd><a href="http://www.webs.com/pages/partners/" title="Partners" rel="nofollow">Partners</a></dd>
<dd><a href="http://www.webs.com/pages/advertising/" title="Advertising" rel="nofollow">Advertising</a></dd>

<dd><a href="http://developers.freewebs.com/" title="Developers">Developers</a></dd>
</dl>

<dl class="left">
<dt>Explore</dt>
<dd><a href="http://www.webs.com/pages/features/" title="Features">Features</a></dd>
<dd><a href="http://www.webs.com/premium.jsp" title="Premium Services">Premium Services</a></dd>

<dd><a href="http://www.webs.com/pages/faqs/" title="FAQ &amp; Help">FAQ &amp; Help</a></dd>
</dl>

<dl class="right">
<dt>&copy;2008 Webs.com. All Rights Reserved.</dt>
<dd><a href="http://www.webs.com/pages/terms/" title="Terms of Service" rel="nofollow">Terms of Service</a></dd>
<dd><a href="http://www.webs.com/pages/privacy/" title="Privacy Policy" rel="nofollow">Privacy Policy</a></dd>

<dd><a href="http://www.webs.com/pages/abuse/" title="Abuse Policy" rel="nofollow">Abuse Policy</a></dd>
<dd><a href="http://www.webs.com/pages/contact/" title="Contact Us" rel="nofollow">Contact Us</a></dd>
</dl>
</div>
</div>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-230305-2");
pageTracker._setDomainName("none");
pageTracker._setAllowHash(false);
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
} catch(err) {}</script>

</body>
</html>

Rich
06-27-2009, 08:02 PM
I tried it with the 's around the URL...Hmm, PM me the login and password for your Webs account, and I'll see if I can sort it out. Don't worry, I won't mess it all up.

senrath
06-27-2009, 08:58 PM
Make sure that you're using the source editor, not the WYSIWYG editor.

Rich
06-27-2009, 09:22 PM
Senna, did you write the version in Wordpad or Notepad?

Anyway, I've fixed the problem.

Dynamite
06-27-2009, 09:23 PM
Notepad

Come on msn

T~M

Awkwardsaw
07-04-2009, 12:44 PM
program New;
{.include SRL/SRL.scar}

const
update = true;

function getversion: boolean;
var Version, Ver : string;
begin
Ver:= '1.0'; //DO NOT CHANGE UNLESS YOU WANT AN OUTDATED VERSION!
Version:= GetPage('http://akwardversions.webs.com/TestVersion.txt');
if Version <> Ver then
result:= false
else
result:= true;
end;

procedure NewsFlash;
var
News : string;
begin
News:= GetPage('http://akwardversions.webs.com/TestNews.txt');
WriteLn(News);
Wait(10000);
end;

procedure UpdateScript;
var
NewScript: String;
scriptFile: Integer;
begin
if not update then exit;
newScript := GetPage('http://akwardversions.webs.com/testupdate.txt');
scriptFile := RewriteFile(ScriptPath, True);
WriteFileString(scriptFile, newScript);
alert('Shutting down. Restart script');
wait(5000);
CloseFile(scriptFile);
end;

begin
if getversion then newsflash else UpdateScript;
writeln('lolwut');
end.

when i run the updater i get a file access error, all of my firewalls and api calls are enabled, so whats the proper way to do it?

Rich
07-05-2009, 04:23 AM
Take out the UpdateScript procedure, and then see if it works. When I tried that, I got an error, but I can't remember what it was, so that may be your problem.

Awkwardsaw
07-05-2009, 04:37 AM
when i took it out it worked, it has to do with the updatescript

Sabzi
07-05-2009, 04:46 AM
I don't realy know scar file functions. But can you edit a file while you are using it? I think no.
If you are not trying to edit the file you are using than sorry.

EDIT after next post: Well I have learned a new thing. Thx akwardsaw.

Awkwardsaw
07-05-2009, 04:48 AM
well, it can, but the script has to refresh to take effect. there was a script somewhere that did this

ZaSz
07-05-2009, 04:56 AM
procedure webconnect(typess:string);
var
Contents,bt: string;
i: integer;
begin
Contents := GetPage('http://zaszmedia.com/ZAF-Details.html');
case typess of
'version' : begin
bt := Between('<latestversion>', '</latestversion>', Contents);
latestversion := StrToFloat(bt);
end;
'news' : begin
for i:= 0 to 10 do
if pos('<line'+inttostr(i)+'>', Contents) > 0 then
writeln(Between('<line'+inttostr(i)+'>', '</line'+inttostr(i)+'>', Contents));
end;
end;
end;
begin
webconnect('version');
if Version < latestversion then
begin
case lowercase(Readln('You do not have the latest version of the script, which means the script could be broken, do you wish to use this lower version? (yes,no)')) of
'no': downloadscript;
end;
end;
end.


I just put <latestversion>0.04</latestversion> for the scripts latest version. I prefer news like that, so you can have versions plus news.

Awkwardsaw
07-05-2009, 04:59 AM
may i see the downloadscript procedure? :D

ZaSz
07-05-2009, 05:03 AM
III := RewriteFile(AppPath + '\scripts\Zaszs_Alpha_Fighter\Zasz''s Alpha Fighter.scar', false);
WriteFileString(III, GetPage('http://www.zaszmedia.com/Zaszs_Alpha_Fighter.scar'));
CloseFile(III);

Tidbit from my alpha fighter (all of code I show here). (well thats in the newer version, The old 1 is in downloader.scar for my script.

Awkwardsaw
07-05-2009, 05:26 AM
hmm, i still get the same error.

Rich
07-05-2009, 10:07 PM
procedure webconnect(typess:string);
var
Contents,bt: string;
i: integer;
begin
Contents := GetPage('http://zaszmedia.com/ZAF-Details.html');
case typess of
'version' : begin
bt := Between('<latestversion>', '</latestversion>', Contents);
latestversion := StrToFloat(bt);
end;
'news' : begin
for i:= 0 to 10 do
if pos('<line'+inttostr(i)+'>', Contents) > 0 then
writeln(Between('<line'+inttostr(i)+'>', '</line'+inttostr(i)+'>', Contents));
end;
end;
end;
begin
webconnect('version');
if Version < latestversion then
begin
case lowercase(Readln('You do not have the latest version of the script, which means the script could be broken, do you wish to use this lower version? (yes,no)')) of
'no': downloadscript;
end;
end;
end.


I just put <latestversion>0.04</latestversion> for the scripts latest version. I prefer news like that, so you can have versions plus news.

Hmm...I like the way you do it, but since ours pretty much do the same, I'll stick to my way. However, I may make a few changes.


hmm, i still get the same error.

To be honest, all I know is what's in the first post. Post in Scripting Help for advice.

Richard.

Da 0wner
07-05-2009, 11:10 PM
hmm, i still get the same error.

It is because you are trying to write to a folder not a file.

ScriptPath does not contain the path to the file. It contains the folder path.

i.e you have a file in C:\ called blah.scar.

ScriptPath of it would not be C:\blah.scar but C:\.

So try ScriptPath + 'SomeString' (like '1.5.scar').