using System.Windows.Forms;
using System.Net;
using System.IO.Compression;
WebClient myWebclient = new WebClient();
string Temp;
string checkversion;
myWebclient.DownloadFileCompleted += OnDownloadComplete;
myWebclient.DownloadFileAsync(new Uri("URL for Version Number txt file goes here"), Temp + "VersionNumber.txt");
private void OnDownloadComplete(object sender, AsyncCompletedEventArgs e)
{
myWebclient.Dispose();
var reader = new System.IO.StreamReader(Temp + "VersionNumber.txt");
checkversion = reader.ReadToEnd();
reader.Dispose();
DownloadNewVersion();
}
private void DownloadNewVersion()
{
if (checkversion.Contains(Application.ProductVersion) )
{
MessageBox.Show("You have the latest version!", "Updater", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
MessageBox.Show("Update Found!" + "\n" + "Current Version:" + " " + Application.ProductVersion + "\n" +
"New Version:" + " " + checkversion, "Updater", MessageBoxButtons.OK, MessageBoxIcon.Information);
myWebclient.DownloadFile("URL for Downloadlink txt file goes here", Temp + "Downloadlink.txt");
var Downloadlink = new System.IO.StreamReader(Temp + "Downloadlink.txt");
string Link = Downloadlink.ReadToEnd();
Downloadlink.Dispose();
FolderBrowserDialog SelectFolder = new FolderBrowserDialog();
SelectFolder.ShowDialog();
string Location = SelectFolder.SelectedPath;
if (Location == "")
{
MessageBox.Show("No Directory Selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else
{
try {
MessageBox.Show("Update Found!" + "\n" + "Current Version:" + " " + Application.ProductVersion + "\n" +
"New Version:" + " " + checkversion, "Updater", MessageBoxButtons.OK, MessageBoxIcon.Information);
myWebclient.DownloadFile("https://dl.dropbox.com/s/30pbkeg3nfr662y/NewVersion.txt?dl=1", Temp + "Downloadlink.txt");
var Downloadlink = new System.IO.StreamReader(Temp + "Downloadlink.txt");
string Link = Downloadlink.ReadToEnd();
Downloadlink.Dispose();
FolderBrowserDialog SelectFolder = new FolderBrowserDialog();
SelectFolder.ShowDialog();
string Location = SelectFolder.SelectedPath;
if (Location == "")
{
MessageBox.Show("No Directory Selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
System.IO.Directory.CreateDirectory(Location + @"\NewVersion");
myWebclient.DownloadFile(Link, Location + @"\NewVersion\Update.zip");
myWebclient.Dispose();
string path = Location;
Location = "";
string zipPath = path + @"\NewVersion\Update.zip";
string extractPath = path + @"\NewVersion";
ZipFile.ExtractToDirectory(zipPath, extractPath);
System.IO.File.Delete(path + @"\NewVersion\Update.zip");
MessageBox.Show("Download Complete!" + "\n" + "Download Destination:" + " " + path, "Updater", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
System.Diagnostics.Process.Start(path);
/*Application.Exit()*/
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.