[C# Rynosce Updater] C# WebClient FileInfo and HttpWebRequest HttpWebResponse FileInfo
using System;
using System.Net;
using System.IO;
using System.Windows.Forms;
using System.Globalization;
public class Update
{
public static string url = "http://127.0.0.1/update.exe";
static Int64 thisSize, newSize;
static DateTime thisTime, newTime;
public static void Version1()
{
try
{
WebClient temp = new WebClient();
temp.OpenRead(url);
newSize = Convert.ToInt64(temp.ResponseHeaders["Content-Length"]);
newTime = DateTime.Parse(temp.ResponseHeaders["Last-Modified"]);
// if (DateTime.TryParseExact(temp.ResponseHeaders["Last-Modified"], "r", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out newTime)) { }
// [url]https://msdn.microsoft.com/en-us/library/az4se3k1.aspx#RFC1123[/url]
}
catch { Console.WriteLine("Server Not Found"); }
try
{
FileInfo file = new FileInfo(Application.ExecutablePath);
thisTime = file.LastWriteTime;
thisSize = file.Length;
}
catch { Console.WriteLine("Local Not Found"); }
Inspection();
}
public static void Version2()
{
try
{
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
if (Response.StatusCode == HttpStatusCode.OK)
{
newTime = Response.LastModified;
newSize = Response.ContentLength;
// newSize = Convert.ToInt64(Response.Headers.Get("Content-Length"));
}
Response.Close();
}
catch { Console.WriteLine("Server Not Found"); } // Обработка ошибок = [url]https://msdn.microsoft.com/ru-ru/library/es54hw8e(v=vs.110).aspx[/url]
try
{
FileInfo file = new FileInfo(Application.ExecutablePath);
thisTime = file.LastWriteTime;
thisSize = file.Length;
}
catch { Console.WriteLine("Local Not Found"); }
Inspection();
}
static void Inspection()
{
if (thisTime >= newTime && thisSize == newSize)
{
Console.WriteLine("Run this Update");
}
else
{
Console.WriteLine("Download new Update");
}
}
}