ItsMods

Full Version: Making a "Check on updates" form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Fuu , me no leecher @OrangePL

hey guys,

This is my first tutorial about C#, i will explain easy thing, which allows you make things like - check on updates, or just download bar.

You need:
  • Visual C#
  • FTP or file hoster

Usage:
That's just easy code which checks number, and downloads file.
When you updated your program, you should re-upload it to SAME address and edit your prog.rtf file - make first line number bigger, and make same number in new program version. ( ex: string CurrentVersion = "22"; and first line in prog.rtf must be 22 )

First of all you need to make good interface, like:
[Image: o3345aaaaaaaaaaaaaaaaaaaaag8.png]

Now make file prog.rtf and add into file, upload to your ftp(ex: www.blablalba.com/files/prog/ )
that file must have 2 lines: first line - version, second line - link to file
Ex:
Code:
22
www.blalblalba.com/files/prog/myprog.rar

Now need to make main checking.....
1. Double click on your "Check" button. Code will looks like:
Code:
private void checkForUpdatesButton_Click(object sender, EventArgs e)
{
          
}
2. Now need to add "file checking" thing which reads txt file.
NOTE: Current version value must be bigger than number in .txt file! That's main thing...
That's reads your rtf file from ftp and checks if current version less than num in file.
Code:
private void checkForUpdatesButton_Click(object sender, EventArgs e)
        {
            string CurrentVersion = "21";  // CURRENT VERSION MUST BE LESS OR SAME
            WebRequest request = WebRequest.Create("http://blablabla.com/files/prog/prog.rtf");
            WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string NewestVersion = reader.ReadLine();
            string Link = reader.ReadLine();
            if (NewestVersion != CurrentVersion)
            {
                // continue
            }
            else
            {
                MessageBox.Show("Can't find any update.",
            "Update");
            }
        }
That's checks on update by checking values...

Now i need to add downloading thing. That's checks SECOND line and downloads it.
Code:
WebRequest request = WebRequest.Create("http://blablalba.com/files/prog/prog.rtf");
            WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string NewestVersion = reader.ReadLine();
            string Link = reader.ReadLine();
                MessageBox.Show("A new version is available! Version: " + NewestVersion + "",
            "Updating");
                WebClient wc = new WebClient();
                wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
                wc.DownloadFileAsync(new Uri(Link), @Directory.GetCurrentDirectory() + "/myprogram.rar");

4. Making moving bar.
Now add:
Code:
public void wc_DownloadProgressChanged(Object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar2.Value = e.ProgressPercentage;
        }
That's already called.

Result code:
Code:
private void checkForUpdatesButton_Click(object sender, EventArgs e)
        {
            string CurrentVersion = "21";  // CURRENT VERSION MUST BE LESS OR SAME
            WebRequest request = WebRequest.Create("http://blablabla.com/files/prog/prog.rtf");
            WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string NewestVersion = reader.ReadLine();
            string Link = reader.ReadLine();
            if (NewestVersion != CurrentVersion)
            {
            string Link = reader.ReadLine();
                MessageBox.Show("A new version is available! Version: " + NewestVersion + "",
            "Updating");
                WebClient wc = new WebClient();
                wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
                wc.DownloadFileAsync(new Uri(Link), @Directory.GetCurrentDirectory() + "/myprogram.rar");
            }
            else
            {
                MessageBox.Show("Can't find any update.",
            "Update");
            }
        }
       public void wc_DownloadProgressChanged(Object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar2.Value = e.ProgressPercentage;
        }


lol, a irl friend (@Back2Real ) of mine (which you know) just told me that he told you how to do this Tongue
He also said that he doesn't care, according to him, "it's common knowledge which everyone should know"

Good job on the tutorial, though.
(02-01-2012, 10:04)Rendflex Wrote: [ -> ]lol, a irl friend (@Back2Real ) of mine (which you know) just told me that he told you how to do this Tongue
He also said that he doesn't care, according to him, "it's common knowledge which everyone should know"

Good job on the tutorial, though.

he didnt tell it to me. he just said reader code

me no leecher ftw1
Leecher.
Here's an idea, use pastebin (you'll need an account) to store that data. Just make sure to put the link to the raw link in the program. Nyan Cat
thanks, i rearry rike it
I will make "How to create a autoupdate - the way microsoft wants you to do it" this evening
(02-01-2012, 10:14)Se7en Wrote: [ -> ]
(02-01-2012, 10:04)Rendflex Wrote: [ -> ]lol, a irl friend (@Back2Real ) of mine (which you know) just told me that he told you how to do this Tongue
He also said that he doesn't care, according to him, "it's common knowledge which everyone should know"

Good job on the tutorial, though.

he didnt tell it to me. he just said reader code

me no leecher ftw1

Someone always tells you something before you do something, Troll

Good job