Advertisement
Spectrewiz

Web Version Checker

Apr 15th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System.Net;
  2.  
  3.         public static int update = 0;
  4.  
  5.         public void OnUpdate()
  6.         {
  7.             if (update == 0)
  8.             {
  9.                 if (UpdateChecker())
  10.                     update++;
  11.                 else
  12.                     update--;
  13.             }
  14.         }
  15.  
  16.         public override Version Version
  17.         {
  18.             get { return new Version(1, 1, 1); }
  19.         }
  20.  
  21.         public bool UpdateChecker()
  22.         {
  23.             string raw;
  24.             try
  25.             {
  26.                 raw = new WebClient().DownloadString("https://github.com/Spectrewiz/Ticket-System/raw/master/README.txt");
  27.             }
  28.             catch (Exception e)
  29.             {
  30.                 Log.Error(e.Message);
  31.                 return false;
  32.             }
  33.             string[] readme = raw.Split('\n');
  34.             string[] download = readme[2].Split('-');
  35.             Version version;
  36.             if (!Version.TryParse(readme[0], out version)) return false;
  37.             if (Version.CompareTo(version) >= 0) return false;
  38.             Console.ForegroundColor = ConsoleColor.Yellow;
  39.             Console.WriteLine("New Ticket System version: " + readme[0].Trim());
  40.             Console.WriteLine("Download here: " + download[1].Trim());
  41.             Console.ResetColor();
  42.             Log.Info(string.Format("NEW VERSION: {0}  |  Download here: {1}", readme[0].Trim(), download[1].Trim()));
  43.             return true;
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement