forked from Screeder/SAwareness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.cs
79 lines (71 loc) · 2.76 KB
/
Updater.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
76
77
78
79
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeagueSharp;
namespace SAwareness
{
public static class SUpdater
{
private const int localmajorversion = 0;
private const int localversion = 7;
public static void UpdateCheck()
{
var bgw = new BackgroundWorker();
bgw.DoWork += bgw_DoWork;
bgw.RunWorkerAsync();
}
private static void bgw_DoWork(object sender, DoWorkEventArgs e)
{
var myUpdater = new Updater("https://raw.githubusercontent.com/Screeder/SAwareness/master/Properties/Version", "https://github.com/Screeder/SAwareness/releases/download/", "SAwareness.exe", localmajorversion, localversion);
if (myUpdater.NeedUpdate)
{
Game.PrintChat("SAwareness Updating ...");
if (myUpdater.Update())
{
Game.PrintChat("SAwareness updated, reload please");
}
}
}
}
class Updater
{
private readonly string _updatelink;
private readonly System.Net.WebClient _wc = new System.Net.WebClient { Proxy = null };
public bool NeedUpdate = false;
public Updater(string versionlink, string updatelink, String assemblyName, int localmajorversion, int localversion)
{
_updatelink = updatelink;
String str = _wc.DownloadString(versionlink);
_updatelink = updatelink + "v" + str + "/" + assemblyName;
if(Convert.ToInt32(str.Remove(str.IndexOf("."))) > localmajorversion)
NeedUpdate = true;
if (Convert.ToInt32(str.Remove(0, str.IndexOf(".") + 1)) > localversion)
NeedUpdate = true;
}
public bool Update()
{
try
{
if (
System.IO.File.Exists(
System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location) + ".bak"))
{
System.IO.File.Delete(
System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location) + ".bak");
}
System.IO.File.Move(System.Reflection.Assembly.GetExecutingAssembly().Location,
System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location) + ".bak");
_wc.DownloadFile(_updatelink,
System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location));
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}