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);
}
}
}
public static double localVersion = 1.0;
void update_app()
{
try
{
System.Net.WebClient client = new System.Net.WebClient();
System.IO.Stream stream = client.OpenRead("https://www.website.com/fileversion.txt");
System.IO.StreamReader reader = new System.IO.StreamReader(stream);
double liveVersion = Convert.ToDouble(reader.ReadToEnd());
DialogResult dialogResult = MessageBox.Show("Would you like to download the newest update?", "Update " + liveVersion.ToString() + " Available", MessageBoxButtons.YesNo);
if (liveVersion > localVersion)
if (dialogResult == DialogResult.Yes)
System.Diagnostics.Process.Start("https://www.website.com/file.zip");
else
MessageBox.Show("You are running: " + localVersion.ToString() + "\nThis is the current version.");
stream.Close();
stream.Dispose();
client.Dispose();
}
catch
{
MessageBox.Show("Cannot Update. Check your connection.");
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.