What's new

.NET [FULL] Auto Updater

pLTPF

pLTPF

I am NOT LeafyIsHere
Messages
2,281
Reaction score
558
Points
325
Sin$
0
Here's a quick run down of what the the code's doing
1. Checks the current version with the newest which is stored on a pastebin(can be any raw text viewer)
2. If they don't match, it'll open the updater then close the current program(out of date program)
3. The updater will delete the outdated version then download the new version.
4. After it's downloaded it will close and open the updated version of the original tool.


Console Application Code
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Updater
{
    class Program
    {
        // Credits to LTPF
        static void Main(string[] args)
        {
            WebClient wc = new WebClient();
            if (File.Exists("AutoUpdater.exe")) // Should be the pld out dated version.
                File.Delete("AutoUpdater.exe");
            File.WriteAllBytes("AutoUpdater.exe", wc.DownloadData("http://1.3.3.7/AutoUpdater.exe")); // Creates and writes a file as it reads from the newest verison.
            Process.Start("AutoUpdater.exe"); // Launches the original program.
            Console.WriteLine("Update downloaded!\n");
        }
    }
}

For the 1.3.3.7 URL I used my server, I don't know of any file storage online where you can just type the URL in and it will immediately download.

Form Code
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Diagnostics;

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

        string currentVersion = "1.0.0.0";

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = "Version: " + currentVersion;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            WebClient wc = new WebClient();
            string newVersion = wc.DownloadString("https:\\(raw text viewer containing only version, e.g. 1.0.0.0)"); // Downloads the newest version.
            if (currentVersion != newVersion)
            {
                if (!File.Exists("Updater.exe")) // Checks if the updater file doesn't exist or is renamed.
                    MessageBox.Show("Updater not found! Please redownload the program!");
                else
                {
                    Process.Start("Updater.exe"); // Launches the updater if the file DOES exist.
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Up to date!");
            }
        }
    }
}

For you code monkeys here's the sources to the applications I made
Download | Virus Scan | Photo Of Scan

Insane amount of false positives on the virus total, I have no idea why there's no obfuscation on the source.​
 
D

Deleted member 847964

No sympathy for the Devil; keep that in mind
Seasoned Veteran Grizzled Veteran
Messages
1,172
Solutions
6
Reaction score
275
Points
220
Sin$
0
I'm sure people have found ways around it by now but I ran into issues using a different method by Immense (the same concept using pastebin to pull the URL) and most file hosters like mediafire won't work consistently because it will generate a new variant of the URL or either download the html page. With Dropbox there is something like "?dl=0" at the very end of the share link and I changed the 0 to 1 which made it download directly every time. Using mediafire I tried to right click the download button and use that link but it only works once. Just in case anyone else runs into the same issue.

Good tutorial btw
 
Top Bottom
Login
Register