forked from plenteum/plenteum-wallet-winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdatePrompt.cs
120 lines (105 loc) · 4.46 KB
/
UpdatePrompt.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using Newtonsoft.Json.Linq;
using System;
using System.ComponentModel;
using System.Net;
using System.Windows.Forms;
namespace PlenteumWallet
{
public partial class UpdatePrompt : PlenteumWalletForm
{
public UpdatePrompt()
{
InitializeComponent();
this.Text = Application.ProductName;
}
private void UpdatePrompt_Load(object sender, EventArgs e)
{
updateWorker.RunWorkerAsync();
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
Utilities.CloseProgram(e);
}
private void UpdateRequest()
{
/*TODO: Fix Update */
//try
//{
// System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
// string thisVersionString = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
// bool needsUpdate = false;
// var builtURL = "https://api.github.com/repos/turtlecoin/desktop-xamarin/releases/latest";
// var cli = new WebClient();
// cli.Headers[HttpRequestHeader.ContentType] = "application/json";
// cli.Headers[HttpRequestHeader.UserAgent] = "Plenteum Wallet " + thisVersionString;
// string response = cli.DownloadString(new Uri(builtURL));
// var jobj = JObject.Parse(response);
// string gitVersionString = jobj["tag_name"].ToString();
// var gitVersion = new Version(gitVersionString);
// var thisVersion = new Version(thisVersionString);
// var result = gitVersion.CompareTo(thisVersion);
// if (result > 0)
// {
// needsUpdate = true;
// }
// else
// {
// needsUpdate = false;
// }
// if (needsUpdate)
// {
// foreach (var item in jobj["assets"])
// {
// string name = item["name"].ToString();
// if (name.Contains("PlenteumWallet.exe"))
// {
// DialogResult dialogResult = MessageBox.Show("A new version of Plenteum Wallet is out. Download?", "Plenteum Wallet", MessageBoxButtons.YesNo);
// if (dialogResult == DialogResult.No)
// {
// return;
// }
// var dl = new WebClient();
// dl.Headers[HttpRequestHeader.UserAgent] = "Plenteum Wallet " + thisVersionString;
// dl.DownloadFile(item["browser_download_url"].ToString(), "PlenteumWallet_update.exe");
// System.Diagnostics.Process.Start("PlenteumWallet_update.exe");
// Environment.Exit(0);
// }
// }
// }
//}
//catch (Exception ex)
//{
// MessageBox.Show("Failed to check for updates! " + ex.Message + Environment.NewLine + ex.InnerException, "Plenteum Wallet");
//}
}
private void UpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Utilities.Close(this);
}
private void UpdateWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
if (System.AppDomain.CurrentDomain.FriendlyName == "PlenteumWallet_update.exe")
{
System.Threading.Thread.Sleep(500);
System.IO.File.Copy("PlenteumWallet_update.exe", "PlenteumWallet.exe", true);
System.Diagnostics.Process.Start("PlenteumWallet.exe");
Environment.Exit(0);
}
else if (System.AppDomain.CurrentDomain.FriendlyName == "PlenteumWallet.exe")
{
if (System.IO.File.Exists("PlenteumWallet_update.exe"))
{
System.IO.File.Delete("PlenteumWallet_update.exe");
}
}
}
catch
{
MessageBox.Show("Failed to check for updates!", "Plenteum Wallet");
}
UpdateRequest();
}
}
}