Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[EO,CS:DE,C#] Auto Updater *Hot Tutorial*


Recommended Posts

This is my new AutoUpdater which you can use any free webhost with ftp to use it, or use Apache, Warmpserver etc. to use it. so this is the auto updater logic:
Open client -> run Autoupdater -> if new update found close the client -> download the updater -> updater auto runable after downloded open the client again -> redo until there is no new version.
if you have 0.2 and the global version is 0.4 it will download 0.3 and then automatically will download 0.4 :)!
How to setup the updater:

First of all, create a Data folder and put inside two images, the form background image and name it: "bg2.png" and an icon and name it "2.co". Also create a "Version.txt" in the main folder and write inside a "0".

now download c# (it's free) from the next link:
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-csharp-express
now create a new project.
Here is the code i made for the autoupdater:

```
//Created by ShowLoco
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string clientname = "Showloco",clientname2 = "Showloco - the best mmorpg"; // the name of your game (Window name to close).
        string url = "www.showloco.com/"; // here put youre webhost url, or your ip if your using Apache Wampserver or w/e, don't forget the '/' in the end!!!!
        string versionlocation = "patch/version.txt"; // here you put  the version file location on the url. in this file write your correct global version.
        string patcheslocation = "paches/"; //This is the location where we going to save the patches, again don't forget the '/' in the end!!!
        string filename = "showloco.rar"; // the name of the files to .rar.
        double version,version2; // here we will save the current client version. version2 is the global version.
        [DllImport("user32.dll")] // import dll.
        public static extern int FindWindow(string ipclass, string windowname); // make a find Windows function
        [DllImport("user32.dll")] // import dll.
        public static extern int SendMessage(int hw, uint message, int wpa, int ipa); // message the windows.
        public const int syscom = 0x0112;  // sys command.
        public const int closewin = 0xF060; // close command.
        WebClient versionserverdownloder = new WebClient(); // our Downloder basec webclient, this one we will use to check the global version.
        WebClient downloader = new WebClient(); //Our Downloder basic webclient, this one we will use to download the new version.
        Label status = new Label(); // We will create a new label named status.
        ProgressBar downloadstatus = new ProgressBar();// we will create a new progress bar.
        DateTime beforedownload, now; // Saveing the time for the download speed.
        string folderlocation = Application.ExecutablePath.ToString().Replace(Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location), ""); // getting folder location.
        private void Form1_Load(object sender, EventArgs e)
        {        status.Location = new Point (0,20); // we will place status in x 0 y 20.
          Controls.Add(status); // we will add status as a new control(Create it on a form).
            this.Name = "ShowLoco Auto Update"; // The name of the form that you want.
            this.BackgroundImage = Image.FromFile(folderlocation + @"\Data\bg2.png"); // Your Background image location (Create a Data folder and put your background image and name it "bg2.png".
            this.Icon =  new Icon("Data/2.ico"); // Your icon for the form. put one on the Data folder and name it 2.ico.
            // Form size.
            this.Width = 300;
            this.Height = 200;
            try
            {
                StreamReader read1 = new StreamReader(folderlocation + @"Version.txt"); // try to read our version.txt file.
                version = double.Parse(read1.ReadLine()); //Get the version and save it on the version double. we gonna save it as a double.
                read1.Close(); // we will close the reader.
            }
            catch
            {
                MessageBox.Show("Error to get to the Version.txt file"); // Ths file may be deleted or in use.
                Application.Exit(); // we will exit the application.
            }
            try
            {
                version2 = double.Parse(versionserverdownloder.DownloadString(url + versionlocation)); // Here we will take our global version and save it in version2.
            }
            catch
            {
                MessageBox.Show("Error to get to the version file"); // in this case it may be a wrong url, or version file doesn't exist.
                Application.Exit();// we will exit the application.
            }

            if (version == version2) //If the versions are equal, that mean we don't have any new version.
            {
                Application.Exit(); // We will close the updater.
            }
            else //if they aren't equal, so we do have a new version.
            {

                downloader.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(downloaderinprogress); // While downloding, we want to print information like speed and etc.
                downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloadcomplete); //Add the download complete sub.
                status.Location = new Point(0, 20); // we will place status in x 0 y 20.
                status.Height = 10; // add some height.
                status.Width = 100;// add some wight.
                Controls.Add(status); // we will add status as a new control(Create it on a form).
                downloadstatus.Location = new Point(0, 60);// We will place the progressBar.
                downloadstatus.Width = 300; // we will add some width;.
                downloadstatus.Height = 30; // we will ad some height.
                Controls.Add(downloadstatus); // we will add the progressbar to form.
                beforedownload = DateTime.Now; // take time for the download speed.
                version = version + 0.1;
                downloader.DownloadFileAsync(new Uri(url + patcheslocation + version + "/" +  filename), "newpatch.exe"); // we will download a new patch and save it as "newpatch.exe".
            }

        }
        private void downloaderinprogress(object sender, DownloadProgressChangedEventArgs e)
        {
            downloadstatus.Value = e.ProgressPercentage; // Progressbar will work by the precentage of the download.
            now = DateTime.Now; // take the time now for the download speed.
            FileInfo getfileinfo = new FileInfo("newpatch.exe"); // making a fileinfo to take information from the newpatch.exe file.
            double speed = (getfileinfo.Length * 8) / (beforedownload - now).TotalSeconds; // calculate the download speed (file length * by 8 (We want it to in larger bytes) and divide it by the seconds we had from the time we started to downlaod the file.
            status.Text = "Downloading a new patch " + e.ProgressPercentage.ToString() + "% Speed: " + speed + "Correct version: " + (version - 0.1).ToString() + "Global Version: " + version2; // print information in status label.
        }
        private void downloadcomplete(object sender, AsyncCompletedEventArgs e)
        {
            Process.Start("newpatch.exe"); // we will run the new patch.
            Application.Exit(); // exit the auto updater.
        }
        private void Closewindow()
        {

            int getclose = FindWindow(clientname,clientname2); // find the Window to close
            if (getclose > 0)
            {
                SendMessage(getclose,syscom, closewin, 0); // sent message 'close' to  the window
            }
        }
    }
}
//Created by ShowLoco
```

you have comments on most of the things, but still here are the improtant things:
```
//Created by: ShowLoco
        string clientname = "Showloco",clientname2 = "Showloco - the best mmorpg"; // the name of your game (Window name to close).
        string url = "www.showloco.com/"; // here put youre webhost url, or your ip if your using Apache Wampserver or w/e, don't forget the '/' in the end!!!!
        string versionlocation = "patch/version.txt"; // here you put  the version file location on the url. in this file write your correct global version.
        string patcheslocation = "paches/"; //This is the location where we going to save the patches, again don't forget the '/' in the end!!!
        string filename = "showloco.rar"; // the name of the files to .rar.
this.Name = "ShowLoco Auto Update"; // The name of the form that you want.
            this.BackgroundImage = Image.FromFile(folderlocation + @"\Data\bg2.png"); // Your Background image location (Create a Data folder and put your background image and name it "bg2.png".
            this.Icon =  new Icon("Data/2.ico"); // Your icon for the form. put one on the Data folder and name it 2.ico.
            // Form size.
            this.Width = 300;
            this.Height = 200;

```Compile the Autoupdater, name it "Autoupdater.exe" and put it in your game folder.
Ok now open your client files and go to frmMain look for:
```
Private Sub Form_Load()
```and under it write:
```
Shell App.path & "/Autoupdater.exe"
```
Now you have an auto updater :)!

Ok, now how to make a new Update:
first, create a new Version.txt which is 0.1 more than your client version. (This is important, every new version will be only 0.1 more than the older one, or it won't work).
If you want the updater to download to folders, just add the folders and the file inside (it won't replace the folder, it will add them, it will replace only old files to old files for example if i have showloco.exe on the client and i added a new showloco.exe it will replace them).

ok After you have the new Version.txt and your new files you ready to make a new update! open new .rar file and add your new versions files with the new Version.txt.
click on SFX
![](http://gyazo.com/f85ab06ffc2065bbc76fb7316edc0463.png?1329416833)
go to SFX tub, tick "Add new new SFX Module"  and go to Advanced SFX options".
![](http://gyazo.com/b397563872a91d286559d4e732e966b9.png?1329416889)
now go to General and do this:
![](http://i.imgur.com/mLShg.png)
(If you can't tick the "Create in Current folder" just type something in the Patch to extract then tick it and remove the thing you wrote in Patch to extract).
now go  to Setup tub and in Run After Extraction add your .exe client file name.
![](http://gyazo.com/71e78bb46ea33a478707ff6258b6bd5d.png?1329417228)
now go to Update tub and do this:
![](http://i.imgur.com/WWZNN.png)

Now press OK and OK again.
Go to your desktop and you will have your file as .exe, rename it to .rar (Because some freehost won't allowed you to upload .exe but don't worrie, the updater will rename to .exe again before running it).

Upload your new upload to the server (Your patches directory you used in the code and don't forget to create a folder of this version and put the .rar inside). add 0.1 more to your version.txt on the host and enjoy the new update! :)

**I created all the codes and the pictures, do not copy this tutorial!**
It took me a few hourse so please comment :)!
Link to post
Share on other sites
Stop telling people to comment on your tutorial.
It sounds like you're making the tutorial to get attention, but that isn't the point.
You do it to help people, and isn't that attention better than telling people to give it attention?

Anyhow, maybe this will be helpful for someone who has problems with Robins updater.
Link to post
Share on other sites
@♥:

> Stop telling people to comment on your tutorial.
> It sounds like you're making the tutorial to get attention, but that isn't the point.
> You do it to help people, and isn't that attention better than telling people to give it attention?
>
> Anyhow, maybe this will be helpful for someone who has problems with Robins updater.

Attention for his work is nothing bad.
Link to post
Share on other sites
No its not, but its not the right attention. Its a good tutorial, and will get attention from those who want to make their own updater, but there isn't much reason to tell random people to comment.

The attention you get naturally is better than asking for it.
Link to post
Share on other sites
  • 4 weeks later...
  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...