PDA

View Full Version : How to add Auto Updater to all of your scripts



Semtex
09-25-2015, 04:43 PM
Semtex Auto Updater Tutorial

Last Updated: September 25th, 2015

Introduction

Hello, welcome to my very first tutorial. I decided to make this tutorial because the tutorials available regarding Auto Updater are somewhat outdated. I myself spent quite some time figuring out how it worked. Therefor I wanted to make this guide, so you would avoid spending the amount of time that I did. This tutorial will guide you step by step how to add Auto Updater to your script and how to manage your script.

For this tutorial, we will be using GitHub. Our very own The Mayor; provided the code we will be using in the actual script.

Table of Contents

Step 1: Registering at GitHub
Step 2: Creating your repository
Step 3: Downloading and setting up GitHub Desktop
Step 4: The script and the code
Step 5: Maintaining Script updates


Step 1: Registering at GitHub

The first thing you need to do is go to https://github.com/ and register.

On the front page in the right side, you will see three boxes labeled, Pick a username, your email and create a Password.

It looks as follows:
http://i62.tinypic.com/2wqv7ud.png
Fill out the boxes. (Example for username could be SRL (Account name), like mine “SRLTest”)
After you have filled out all three boxes, click “Sign up for GitHub”.
The next page is where you choose a plan. Just click the green button Finish sign up at the bottom.

You have now registered and before continuing, I recommend verifying your email address. Log unto your email and should have gotten two emails from GitHub. A welcome mail and the mail where you verify your email address. Open then one with verify email.


You should now see something like this:
http://i62.tinypic.com/ix5f9z.png
Click the button “Verify email Address”. We are now ready to continue.



Step 2: Creating your repository

When you log into GitHub it should look something like the picture below:
http://i62.tinypic.com/10qjp6r.png
Click the green button “New repository”

You can now see the following page:
http://i60.tinypic.com/2jhdeb.png
Repository name, can be anything. For this example, we will name it “SRLScripts”. We will make folders for the script we are adding auto updater to later on.

In the description box, you can fill out anything you want or nothing at all. I decided to leave it blank in this example, but you could write “All my SRL Scripts”.

Leave it on public. If you choose private (only paying users can choose this option), no one would be able to see the content added to the repository.

Now check the box “Initialize this repository with a README”. We will not be using it, but it is easier if we add it when we create the repository.

When you have filled out all the information, click the green button “Create repository”. We have now created the repository.

You should now see the following page:
http://i57.tinypic.com/219xbbr.png
In case you were wondering, a repository is a directory of files (In this case).

Onward to the next step.



Step 3: Downloading and setting up GitHub Desktop

Click the following link https://desktop.github.com/
Click the big blue button “Download GitHub Desktop” it should look like the following:
http://i60.tinypic.com/2rhpojm.png
Double click the file when it is finished downloading and click Install. It will now download the required files for the installation (this could take some time depending on how high your bandwidth is).
GitHub runs by itself when the installation is finished.

You should now see the following:
http://i61.tinypic.com/2zzstx1.png
Enter the username you chose earlier and the password you chose, and then click Log in.
Just click Continue on the next page and finally click “dashboard” in the line: Head over to your dashboard to get started!”

Now click the plus in the left top side and choose “Clone”. Click then one showing, it will have the name of the repository that we created earlier on, in this example it is SRLScripts. It should look like the following:
http://i57.tinypic.com/1608uno.png
Click the button at the bottom “Clone SRLScripts (or whatever you named it)”. You will have to choose a directory. I use the default one, but you choose whatever. Wait for it to finish.

Right click “SRLScripts (or whatever you named it) in the top left corner and choose open in explorer.
Delete the README file and add a new folder. Name it after your script. I will name mine SemtexFishingGuild.
Now make a new text file document within the newly created folder, name it “Version”.

Open up the text document file and input version number of your script. In my case, it is 1.2
It should look like this:
http://i58.tinypic.com/21c75sp.png
Save the file and close it.

Now move your script within the folder, like this:
http://i60.tinypic.com/10xfwiw.png
We are now ready to continue to the next step.



Step 4: The script and the code

The first thing you need to do is add a constant to your script.
Like so:
program SemtexFishingGuild;
{$DEFINE SMART}
{$i srl-6/srl.simba}
{$i sps/lib/sps-rs3.simba}
{$i srl-6/lib/misc/srlplayerform.simba}

const
Version = 1.2;


The procedure for auto updating is like this:
procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/version.txt'));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);

if newVer > Version then
begin
printf('Updating (Script Name Here).simba from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + '(Script Name Here).simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/(Script Name Here).simba'));
closeFile(newFile);
print('Please reopen this file');
terminateScript();
end;
end;

Fill in the (Name) in the throughout the code, with your own information. In my case the code would be like this:

Another way of getting the URL that needs to be used is to, is by logging into the GitHub Webpage, enter "SRLScripts" under "Your Repositories".
Then click the script folder, in my case it's SemtexFishingGuild.

You should see 2-3 files here, Version.txt and scriptname.simba and the updater.

Click on "scriptname.simba"

Now click the button "Raw" and copy the URL from the page you are taken to.

It is very important that you add the http:/ /tomstewart.net/proxy.php?url= in front of the URL.

So the URL isn't just: https:/ /raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild/SemtexFishingGuild.simba

but: http:/ /tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild/SemtexFishingGuild.simba

If you don't add http:/ /tomstewart.net/proxy.php?url= then the script won't be able to get the data it needs.

procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild/version.txt'));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);

if newVer > Version then
begin
printf('Updating (Script Name Here).simba from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + 'SemtexFishingGuild.simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/SRLTest/SRLScripts/master/SemtexFishingGuild.simba'));
closeFile(newFile);
print('Please reopen this file');
terminateScript();
end;
end;

The next thing you need to do is call the procedure in your Setup loop.
I call it here, at the begging of the Setup Loop and before all the playerform procedure etc.:


clearDebug();
getUpdate();
getMap();
initPlayerForm();
runPlayerForm();

Save the program and exit it.

Now for the file you attach to your thread on Villavu.
Start a new simba program.
Put in the following code:

program (Script Name Here)Updater;
{$i srl-6/srl.simba}

(* Auto-Updater file:

Run to get latest version of the script.
The script will appear in the same directory as this script.
*)
const
Version = 0.0;

procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/version.txt '));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);

if newVer > Version then
begin
printf('Updating ' + 'SemtexFishingGuild.simba' + ' from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + '(Script Name Here).simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/(GitHub Username Here)/(Repository Name Here)/master/(Script Name Folder Here)/(Script Name Here).simba'));
closeFile(newFile);
print('New script saved to: ' + scriptPath);
terminateScript();
end;
end;

begin
clearDebug();
disableSRLLog := True;
getUpdate();
end.

Fill in the (Name) in the throughout the code, with your own information. In my case the code would be like this:

program SemtexFishingGuildUpdater;
{$i srl-6/srl.simba}

(* Auto-Updater file:

Run to get latest version of the script.
The script will appear in the same directory as this script.
*)
const
Version = 0.0;

procedure getUpdate();
var
newFile: Integer;
newVer: Extended;
begin
newVer := strToFloat(getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/ SRLTest/SRLScripts/master/SemtexFishingGuild/version.txt '));
printf('Current script Version: %f || Online script Version: %f', [Version, newVer]);

if newVer > Version then
begin
printf('Updating ' + 'SemtexFishingGuild.simba' + ' from Version %f to %f', [Version, newVer]);
newFile := rewriteFile(scriptPath + 'SemtexFishingGuild.simba', false);
writeFileString(newFile, getPage('http://tomstewart.net/proxy.php?url=https://raw.githubusercontent.com/ SRLTest/SRLScripts/master/SemtexFishingGuild/SemtexFishingGuild.simba '));
closeFile(newFile);
print('New script saved to: ' + scriptPath);
terminateScript();
end;
end;

begin
clearDebug();
disableSRLLog := True;
getUpdate();
end.

Save the program within the Repository Directory, you chose in Step 3, where we created the Version text document and you put the script.

Now you have created the means to auto update your script. HOWEVER GitHub have not yet received any of files you put in your script folder. We need to synchronize GitHub Desktop with the GitHub Website.

Open up GitHub Desktop and go into you repository. Right under where it says Sync, click the larger ring there is and you will now see the following (with your information of course):
http://i60.tinypic.com/33cvhtx.png
Fill out Summary and optionally Description.
You write what changes you made since the last time you synchronized your script. In this case, it is the initial release.
Click “Commit to Master” followed by clicking on “Sync”

You can now attach the AutoUpdater file we created to your thread and you will never have to change again.



Step 5: Maintaining Script updates

The hard part is over and the rest is quite easy.
When you need to update a script, all you have to do is change the version number in your Version.txt file, and make sure you change the program.simba file with all the changes you made.

Remember to change the const version to the version number you wrote in the version.txt file.

If I wanted to update my script, I would change the version.txt file to 1.3 and change the const within the script to 1.3.

When you have made the desired changes, you will have to commit the changes and synchronize them just as you did in the last part of Step 4.

Now you should know everything about adding auto updater to your script and maintaining new updates.

Please feel free to ask questions if you are having trouble or just curious.
If you have any suggestions to this guide, please share them as well :)

I hope you like this guide and I wish you the best of luck with adding auto updater to all of your scripts!

StickToTheScript
09-25-2015, 06:28 PM
Nice tutorial! Very useful to people who have wanted to use github, but havent bothered.

Semtex
09-25-2015, 06:55 PM
Nice tutorial! Very useful to people who have wanted to use github, but havent bothered.

My thought exactly :P

i have never used GitHub, so it was a challenge learning how the heck it worked, but once i got that down it was really easy :)

So i just wanted to help others achieve it even easier

yourule97
09-25-2015, 08:10 PM
+rep Great guide! Just fyi, you can also use pastebin :D

Semtex
09-25-2015, 08:12 PM
+rep Great guide! Just fyi, you can also use pastebin :D

Thanks :)

Ah i didn't think about that :P

does pastebin have the feature showing changes?

EDIT: Next tutorial will be about how to add stats to any script, i just need to learn how before i can write a tutorial about it xD

Just haven't had the time to learn it yet

Incurable
09-25-2015, 11:12 PM
It's quite a lot faster to use a raw txt from Pastebin, but Github allows you to control old versions a lot better so it's great either way.

Great tutorial, +rep to you my fine Sir. :)

superuser
09-26-2015, 12:26 AM
I suggest using git cli instead. You might learn something :)

Semtex
09-26-2015, 06:36 AM
It's quite a lot faster to use a raw txt from Pastebin, but Github allows you to control old versions a lot better so it's great either way.

Great tutorial, +rep to you my fine Sir. :)

Thanks alot mate! i'll check it out and make a tutorial if i like it :)


I suggest using git cli instead. You might learn something :)

Git CLI looks alot like powershell and is rather advanced for beginners, but i suppose i could make a tutorial for it for intermediate or advanced scripting:P
I never worked much with powershell, only CISCO IOS CLI but that's an entirely different thing!

scob
07-06-2016, 07:31 PM
Semtex it looks like http://tomstewart.net/proxy.php?url= doesn't work anymore :c. On one of my computers it works well when I just paste direct link, but on another I get this error:


Error: "" is an invalid float at line 72
Execution failed.

and it looks like getPage function also doesn't work on the 2nd computer. Any ideas why?


PS great guide

Laquisha
07-06-2016, 11:31 PM
Semtex it looks like http://tomstewart.net/proxy.php?url= doesn't work anymore :c. On one of my computers it works well when I just paste direct link, but on another I get this error:


Error: "" is an invalid float at line 72
Execution failed.

and it looks like getPage function also doesn't work on the 2nd computer. Any ideas why?


PS great guide

Mayor's site is no longer online, so use Frement's: http://static.frement.net/proxy.php?u=

scob
07-07-2016, 07:05 AM
Mayor's site is no longer online, so use Frement's: http://static.frement.net/proxy.php?u=

Thanks, works great :) and thanks to The Mayor ofc

BTW why does it need proxy?

Harrier
07-07-2016, 09:46 AM
Thanks, works great :) and thanks to The Mayor ofc

BTW why does it need proxy?
Simba doesn't support https/ssl natively without some dll been shipped with it and wizzup doesn't want to ship a openssl plugin with simba since it would need constant updating (iirc)

scob
07-07-2016, 10:04 AM
Thanks for explanation Harrier!

Lama
07-17-2018, 04:45 AM
I know this is an old thread, but I'm looking to do something like this once again - however it seems this tomstewart proxy stuff is no longer a thing, so this exact implementation is outdated - does anyone know of another url to route through for Github?

acow
07-17-2018, 04:17 PM
I know this is an old thread, but I'm looking to do something like this once again - however it seems this tomstewart proxy stuff is no longer a thing, so this exact implementation is outdated - does anyone know of another url to route through for Github?

I didnt read the OP fully, but looking at the tomstewart part that seems to be just for getting HTTPS data via an HTTP connection. Simba I believe natively supports HTTPS now. Just tested on a simba I had installed and getpage worked for https github.

Lama
07-17-2018, 04:57 PM
I didnt read the OP fully, but looking at the tomstewart part that seems to be just for getting HTTPS data via an HTTP connection. Simba I believe natively supports HTTPS now. Just tested on a simba I had installed and getpage worked for https github.

Hmm it doesn't seem to be returning anything for me, just an empty string. Here's the link I'm using which is just a version.txt of my RoguesCooker (https://raw.githubusercontent.com/SRL-Lama/SRL-6-Scripts/master/roguescooker/version.txt).

acow
07-17-2018, 05:11 PM
Hmm it doesn't seem to be returning anything for me, just an empty string. Here's the link I'm using which is just a version.txt of my RoguesCooker (https://raw.githubusercontent.com/SRL-Lama/SRL-6-Scripts/master/roguescooker/version.txt).

Interesting. Here's me trying it with simba 1100 https://i.imgur.com/N5jcu43.png
Maybe I installed openssl stuff and have forgotten about it? Maybe other simba installs installed it? I have no idea.

Olly might know more, I'll @him on discord.

edit for anybody who reads this later: ssl was working on my end because I had another piece of software installed. simba was using the dlls from it for ssl.