Guest User

Untitled

a guest
Aug 6th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System.Net;
  2. using System.IO;
  3. using System;
  4. using System.Globalization;
  5.  
  6. namespace Update_V1
  7. {
  8. public partial class Form1
  9. {
  10. public static string updateServer = "http://caimanssoft.do.am/Programm/";
  11. public static int currentVersion = 0;
  12. static void Main()
  13. {
  14. string[] UpdateInfo;
  15. UpdateInfo = GetUpdateInfo(updateServer);
  16. if (currentVersion < Convert.ToDouble(UpdateInfo[0], CultureInfo.InvariantCulture))
  17. {
  18. Console.WriteLine("Обнаружена новая версия программы, начинается загрузка файлов!");
  19. for (int i = 1; i < UpdateInfo.Length; i++)
  20. {
  21. File.WriteAllBytes(UpdateInfo[i].Replace("\r", ""), DownloadFile(updateServer + UpdateInfo[i].Replace("\r", "")));
  22. }
  23. Console.WriteLine("Обновление успешно скачалось");
  24. }
  25. else
  26. {
  27. Console.WriteLine("Обновление не требуется");
  28. }
  29. Console.ReadKey();
  30.  
  31. }
  32. public static byte[] DownloadFile(string url)
  33. {
  34. var wc = new WebClient();
  35. return wc.DownloadData(url);
  36. }
  37. public static string[] GetUpdateInfo(string url)
  38. {
  39. var wc = new WebClient();
  40. wc.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36";
  41. return wc.DownloadString(updateServer + "update_info.txt").Split('\n');
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment