Post: [C#] Auto Updater - Tutorial
09-25-2015, 02:35 AM #1
Hash847
Purple God
(adsbygoogle = window.adsbygoogle || []).push({}); I've seen in the programming inquery section that there's a few people wanting an auto updater for their tools and stuff.


What you need
  • A direct download file host (dropbox)
  • A pastebin account
  • C#
  • a brain


We'll need a file host. I would personally suggest dropbox for this and that's what we'll be using for this tutorial.

After you've assumingly downloaded and installed dropbox + made an account, you can go to C:\Users\YOURUSERNAME\Dropbox and copy your updated file in there.

right click on it and press Shark Dropbox link. Keep it in your clipboard, we're now going to create a .txt in that same directory (if you're not using dropbox then use pastebin, make sure you use an account when you paste it because you'll need to edit the link)

on the first line put your latest version number
paste the link on the second line at the end of the link change dl=0 to dl=1, this is crucial to the dropbox download.
if you're using pastebin make sure you get the raw link

now with all that out of the way, we can begin adding our auto updater in.

    
int thisVersion = 1;
void checkForUpdates() {
string[] lns = new System.Net.WebClient().DownloadString("TXT FILE LINK OR DROPBOX LINK THAT ENDS IN DL=1").Split('\n'Winky Winky;
if (int.Parse(lns[0]) > thisVersion) {
new System.Net.WebClient().DownloadFile(lns[1], Application.ExecutablePath.Insert(Application.ExecutablePath.Length - 4, " " + thisVersion.ToString())); //this isn't async so it'll pause the thread
System.Diagnostics.Process.Start(Application.ExecutablePath.Insert(Application.ExecutablePath.Length - 4, " " + thisVersion.ToString()));
Application.Exit();//I know it's not pretty but I'm doing this on a website so clearly it wont be pretty
}
}


So at the end you should have a txt file that looks a bit like this
    
1
https://www.dropbox.com/s/gawykghypvbnda5/whatyoucalledit.txt?dl=1


If you want to update your application just edit the .txt and change 1 to 2 and so on and make sure in your updated version you change thisVersion to whatever the latest version is. (it can't be like 1.1 it has to be a whole number like 2 and 3)
I hope this helps anyone that requires it.

The following user thanked Hash847 for this useful post:

RTE
09-25-2015, 11:35 AM #2
Mango_Knife
In my man cave
Originally posted by Winter View Post
I've seen in the programming inquery section that there's a few people wanting an auto updater for their tools and stuff.


What you need
  • A direct download file host (dropbox)
  • A pastebin account
  • C#
  • a brain


We'll need a file host. I would personally suggest dropbox for this and that's what we'll be using for this tutorial.

After you've assumingly downloaded and installed dropbox + made an account, you can go to C:\Users\YOURUSERNAME\Dropbox and copy your updated file in there.

right click on it and press Shark Dropbox link. Keep it in your clipboard, we're now going to create a .txt in that same directory (if you're not using dropbox then use pastebin, make sure you use an account when you paste it because you'll need to edit the link)

on the first line put your latest version number
paste the link on the second line at the end of the link change dl=0 to dl=1, this is crucial to the dropbox download.
if you're using pastebin make sure you get the raw link

now with all that out of the way, we can begin adding our auto updater in.

    
int thisVersion = 1;
void checkForUpdates() {
string[] lns = new System.Net.WebClient().DownloadString("TXT FILE LINK OR DROPBOX LINK THAT ENDS IN DL=1").Split('\n'Winky Winky;
if (int.Parse(lns[0]) > thisVersion) {
new System.Net.WebClient().DownloadFile(lns[1], Application.ExecutablePath.Insert(Application.ExecutablePath.Length - 4, " " + thisVersion.ToString())); //this isn't async so it'll pause the thread
System.Diagnostics.Process.Start(Application.ExecutablePath.Insert(Application.ExecutablePath.Length - 4, " " + thisVersion.ToString()));
Application.Exit();//I know it's not pretty but I'm doing this on a website so clearly it wont be pretty
}
}


So at the end you should have a txt file that looks a bit like this
    
1
https://www.dropbox.com/s/gawykghypvbnda5/whatyoucalledit.txt?dl=1


If you want to update your application just edit the .txt and change 1 to 2 and so on and make sure in your updated version you change thisVersion to whatever the latest version is. (it can't be like 1.1 it has to be a whole number like 2 and 3)
I hope this helps anyone that requires it.


Baisicly you just need to know C#
I mean System.Net and arrays and everything are stuff in C# That people should know..
Then it's just working on logic like
If version on pastebin is bigger than the tool version -> Do something..

The following user thanked Mango_Knife for this useful post:

Luckeyy
09-25-2015, 01:12 PM #3
Hash847
Purple God
Originally posted by Knife View Post
Baisicly you just need to know C#
I mean System.Net and arrays and everything are stuff in C# That people should know..
Then it's just working on logic like
If version on pastebin is bigger than the tool version -> Do something..


There are multiple people asking how to make an auto updater, this is NGU mango, not stackexchange.
09-25-2015, 01:16 PM #4
Mango_Knife
In my man cave
Originally posted by Winter View Post
There are multiple people asking how to make an auto updater, this is NGU mango, not stackexchange.


Stil, they can expand their knowledge and learn how to do it
It's not that hard...
09-25-2015, 01:19 PM #5
Hash847
Purple God
Originally posted by Knife View Post
Stil, they can expand their knowledge and learn how to do it
It's not that hard...


I gave up trying to teach people a while back. I was going to make a C++ tutorial on how to do something interesting in the hope that people would try C++ and try to expand off it but I know no one will.

The following 2 users say thank you to Hash847 for this useful post:

Boliberrys, jagex
09-25-2015, 03:16 PM #6
Mango_Knife
In my man cave
Originally posted by Winter View Post
I gave up trying to teach people a while back. I was going to make a C++ tutorial on how to do something interesting in the hope that people would try C++ and try to expand off it but I know no one will.


Ha, if they dont try to learn new stuff in C#
They will definitely not going to learn C++.

The following user thanked Mango_Knife for this useful post:

jagex
09-29-2015, 06:10 PM #7
DSS Tools
Save Point
cant open the link
09-29-2015, 06:42 PM #8
Hash847
Purple God
Originally posted by DSS
cant open the link


What link?
09-29-2015, 08:34 PM #9
DS
Error… Cat invasion!
Originally posted by DSS
cant open the link


If your talking about the drop box link Facepalm it's not a real link he made that as an example

The following user thanked DS for this useful post:

Hash847
09-29-2015, 09:44 PM #10
jagex
Gym leader
Lolll

Copyright © 2025, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo