Basic/Simple Updater

Posts 13 of 3 · Page 1 of 1
Basic/Simple Updater
Code:
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****;
using System.Net;
using System.Security.Cryptography;


namespace Updater
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

      

        private void Form1_Load(object sender, EventArgs e)
            
        {

            try
            {
                timer1.Start();
                //======================================


                HttpWebRequest Requestzz = (HttpWebRequest)WebRequest.Create("https://dl.dropbo*****m/u/78998523/name.txt"); //Creates a httpwebrequest to post to the login.php




                HttpWebResponse Responsezz = (HttpWebResponse)Requestzz.GetResponse(); //After writing data to the stream get the response

                StreamReader resReaderzz = new StreamReader(Responsezz.GetResponseStream()); //Convert to response to string

                String strzz = resReaderzz.ReadLine();



                //======================================


                //=======================================
                StreamReader sr = new StreamReader("version.txt");


                HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://dl.dropbo*****m/u/78998523/latestversion.txt"); //Creates a httpwebrequest to post to the login.php




                HttpWebResponse Response = (HttpWebResponse)Request.GetResponse(); //After writing data to the stream get the response

                StreamReader resReader = new StreamReader(Response.GetResponseStream()); //Convert to response to string

                String str = resReader.ReadLine(); //Read contents of the whole string (Which is the same if you view source of php script
                //=========================================

                //=========================================

                HttpWebRequest Requestz = (HttpWebRequest)WebRequest.Create("https://dl.dropbo*****m/u/78998523/url.txt"); //Creates a httpwebrequest to post to the login.php




                HttpWebResponse Responsez = (HttpWebResponse)Requestz.GetResponse(); //After writing data to the stream get the response

                StreamReader resReaderz = new StreamReader(Responsez.GetResponseStream()); //Convert to response to string

                String strz = resReaderz.ReadLine();
                //=======================================
                String latest = str;
                int latestz = int.Parse(latest);   //latest version
                int latestversion = latestz;

                string number = sr.ReadLine();
                int currentversion = int.Parse(number); //current version

                //======================================
                if (currentversion < latestversion) // if current version is < (down) than latest version
                {
                    sr.Close();
                    resReader.Close();
                    WebClient wc = new WebClient();
                    wc.DownloadFileAsync(new Uri(strz), strzz); //download the file 
                    //strz = URL
                    //strzz = File Name


                    wc.DownloadProgressChanged += (s, x) => progressBar1.Value = x.ProgressPercentage; // show progress in progressbar in percentage
                    wc.DownloadProgressChanged += (s, x) => label1.Text = "%" + x.ProgressPercentage.ToString(); //show progress in percentage in label1

                    StreamWriter sw = new StreamWriter("version.txt");


                    sw.WriteLine(latestversion); //write latest version to version.txt
                    sw.Close(); //close streamReader

                }
                else
                {
                    MessageBox.Show("No Updates are Currently available"); //show the message that you already have the latest version
                    this.Close(); //close form
                }

            }
            catch (Exception ex) //If there is an error, display what was wrong with a message box 
            {
                MessageBox.Show(ex.Message, "Error : Updater");
                this.Close();
                
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (label1.Text == "%100")
            {

                this.Close();
            }
        }
    }
}
I was bored so though why not Make an simple updater?
be sure to edit URLs
I hope you understand the code..
Why do it so hard?
Download a string from example: PasteBin
Check version number, on second line, the download link stands.
Go to that, and download the file using the Download function.


Think this would be like.. min 20 lines of code


Snippets:
Code:
WebClient Cli = new WebClient();
if(CLi.DownloadString(PasteBin Link) != Properties.Settings.Default.VersionNum)
{
MessageBox.Show("New Update, downloading now...");
Cli.DownloadFile(My File);
//* Make File *
MessageBox.Show("File downloaded :D");
Process.Start(New File);
Application.Exit();
}
else MessageBox.Show("No new updates :D");
Or something like that, just made something with my hands and no testing but
Still used it 1 or 2 times
Quote Originally Posted by Jorndel View Post
Why do it so hard?
Download a string from example: PasteBin
Check version number, on second line, the download link stands.
Go to that, and download the file using the Download function.


Think this would be like.. min 20 lines of code


Snippets:
Code:
WebClient Cli = new WebClient();
if(CLi.DownloadString(PasteBin Link) != Properties.Settings.Default.VersionNum)
{
MessageBox.Show("New Update, downloading now...");
Cli.DownloadFile(My File);
//* Make File *
MessageBox.Show("File downloaded :D");
Process.Start(New File);
Application.Exit();
}
else MessageBox.Show("No new updates :D");
Or something like that, just made something with my hands and no testing but
Still used it 1 or 2 times
I like how yours is so small lol
I used xml to do mine

Code:
 public void myshit()
        {
           
            try
            {
                reader = new XmlTextReader(xmlUrl);
                reader.MoveToContent();

                string elementName = "";
                if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "DevConnect"))
                {
                    while (reader.Read())
                    {

                        if (reader.NodeType == XmlNodeType.Element)
                        {

                            elementName = reader.Name;
                        }
                        else
                        {
                            if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
                            {
                                switch (elementName)
                                {
                                    case "Version":
                                        newVersion = new Version(reader.Value);
                                        break;                            


                                }
                            }
                        }
                    }                    
                }
            }

            catch (Exception)
            {
                MessageBox.Show("Problems Found", "AHDEVConnect",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
              
            }
            finally    
            {
                if (reader != null)
                    reader.Close();
            }
 private void button1_Click_1(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(downloadURL);
            this.Close();
        }
the way mine was setup is i had 2 buttons "Update" and "continue" and a label the label said your Version number and said weather or not it was the latest
if it wasnt the "update" button was displayed you clicked on that to download the new update.
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?