Advertisement
Guest User

Untitled

a guest
Aug 24th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Net;
  11.  
  12. namespace Updater
  13. {
  14.     public partial class frmMainWindow : Form
  15.     {
  16.         public frmMainWindow()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.        
  21.         WebClient myWebclient = new WebClient();
  22.         string Temp;
  23.         string checkversion;
  24.        
  25.        
  26.         private void btnUpdate_Click(object sender, EventArgs e)
  27.         {
  28.             myWebclient.DownloadFileCompleted += OnDownloadComplete;
  29.             myWebclient.DownloadFileAsync(new Uri("https://dl.dropbox.com/s/ahysy3ppgbewznb/Version.txt?dl=1"), Temp + "VersionNumber.txt");
  30.         }
  31.  
  32.         private void OnDownloadComplete(object sender, AsyncCompletedEventArgs e)
  33.         {
  34.             myWebclient.Dispose();
  35.             var reader = new System.IO.StreamReader(Temp + "VersionNumber.txt");
  36.             checkversion = reader.ReadToEnd();
  37.             reader.Dispose();
  38.             DownloadNewVersion();
  39.         }
  40.         private void DownloadNewVersion()
  41.         {
  42.             if (checkversion.Contains(Application.ProductVersion))
  43.             {
  44.                 MessageBox.Show("You have the latest version!", "Updater", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  45.                
  46.             }
  47.             else
  48.             {
  49.                
  50.                        myWebclient.DownloadFile("https://dl.dropbox.com/s/30pbkeg3nfr662y/NewVersion.txt?dl=1", Temp + "Downloadlink.txt");
  51.                        myWebclient.Dispose();
  52.                        var Downloadlink = new System.IO.StreamReader(Temp + "Downloadlink.txt");
  53.                        string Link = Downloadlink.ReadToEnd();
  54.                        Downloadlink.Dispose();
  55.                        FolderBrowserDialog SelectFolder = new FolderBrowserDialog();
  56.                        SelectFolder.ShowDialog();
  57.                        string Location = SelectFolder.SelectedPath;
  58.                        System.IO.Directory.CreateDirectory(Location + @"\NewVersion");
  59.                        myWebclient.DownloadFile(Link, Location + "Update.exe");
  60.                        myWebclient.Dispose();
  61.                        }
  62.             }
  63.        
  64.        
  65.        
  66.         private void frmMainWindow_Load(object sender, EventArgs e)
  67.         {
  68.             Temp = System.IO.Path.GetTempPath();
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement