-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUpdateService.cs
75 lines (63 loc) · 2.31 KB
/
UpdateService.cs
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
using System;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Text;
namespace OnTopper
{
public class UpdateService
{
private readonly string currentVersion;
private readonly string webVersion;
private static UpdateService _updateService;
private readonly WebClient web = new WebClient();
public event EventHandler UpdateDownloaded;
private readonly string zipFilePath = Environment.ExpandEnvironmentVariables(@"C:\Users\hgt16\AppData\Roaming\DeMmAge Inc\OnTopper\update.zip");
private UpdateService()
{
currentVersion = typeof(Program).Assembly.GetName().Version.ToString();
web.DownloadFileCompleted += OnDownloadCompleted;
try
{
webVersion = Encoding.UTF8.GetString(web.DownloadData("https://pastebin.com/raw/PyGgwApk"));
}
catch (Exception)
{
// ignored
}
}
private void OnDownloadCompleted(object sender, EventArgs e)
{
//ZipFile.ExtractToDirectory(zipPath, extractPath);
var handler = UpdateDownloaded;
handler?.Invoke(this, e);
}
public void DownloadUpdate()
{
web.DownloadFileAsync(new Uri("https://sourceforge.net/projects/testprojtopper/files/OnTopper.zip/download"),
zipFilePath);
}
public static UpdateService GetInstance()
{
return _updateService ?? (_updateService = new UpdateService());
}
public bool UpdateAvailable()
{
var request = WebRequest.Create("https://pastebin.com/raw/PyGgwApk");
try
{
var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var _webVersion = reader.ReadToEnd();
int parsedWebVersion = Convert.ToInt16(_webVersion.Replace(".", ""));
int parsedCurrentVersion = Convert.ToInt16(currentVersion.Replace(".", ""));
return parsedWebVersion > parsedCurrentVersion;
}
catch (Exception)
{
return false;
}
}
public string GetWebVersion() => webVersion;
}
}