-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathVersionChecker.cs
More file actions
84 lines (74 loc) · 2.88 KB
/
VersionChecker.cs
File metadata and controls
84 lines (74 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
namespace RatioMaster_source
{
using System;
using System.IO;
using System.Net;
public class VersionChecker
{
public const string LocalVersion = "0440";
public const string PublicVersion = "0.44";
public const string ReleaseDate = "04-07-2025";
private const string ProgramPageVersion = "http://ratiomaster.net/vc.php?v=";
private readonly string userAgent;
public VersionChecker(string log)
{
this.userAgent = "RatioMaster.NET"
+ $"/{LocalVersion} ({Environment.OSVersion}; .NET CLR {Environment.Version}; {Environment.UserName}.{Environment.ProcessorCount})";
this.Log = log;
}
// TODO: Replace with StringBuilder
public string Log { get; private set; }
internal string RemoteVersion { get; private set; }
public bool CheckNewVersion()
{
try
{
bool result = false;
this.Log = this.Log + ("Local Version: " + LocalVersion + "\n");
this.Log = this.Log + ("Checking for new version..." + "\n");
this.RemoteVersion = this.GetServerVersionId();
//// mainForm.txtRemote.Text = remoteVersion;
if (this.RemoteVersion.Length != 4)
{
this.RemoteVersion = "error";
this.Log = this.Log + ("Error checking new version!!!" + "\n" + "\n");
return false;
}
this.Log = this.Log + ("Remote Version: " + this.RemoteVersion + "\n" + "\n");
if (string.Compare(this.RemoteVersion, LocalVersion, StringComparison.Ordinal) > 0)
{
result = true;
}
return result;
}
catch (Exception exception1)
{
this.Log = this.Log + ("Error checking for new version:\n" + exception1.Message + "\n");
return false;
}
}
public string GetServerVersionId()
{
var url = ProgramPageVersion + LocalVersion;
try
{
var request1 = (HttpWebRequest)WebRequest.Create(url);
request1.UserAgent = this.userAgent;
request1.Timeout = 2500;
using (var response1 = (HttpWebResponse)request1.GetResponse())
{
using (var reader1 = new StreamReader(response1.GetResponseStream()))
{
var data = reader1.ReadToEnd();
return data;
}
}
}
catch (Exception exception1)
{
this.Log = this.Log + "Error in GetVersion(string url):\n" + exception1.Message + "\n";
}
return string.Empty;
}
}
}