-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateManagerConsole.cs
206 lines (190 loc) · 7.54 KB
/
UpdateManagerConsole.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.ComponentModel;
using System.Net;
using System.Windows.Forms;
using UpdateManager.Languages;
namespace UpdateManager
{
public class UpdateManagerConsole
{
private readonly string productName = Application.ProductName;
private readonly string productVersion = Application.ProductVersion;
private readonly bool is64BitProcess = Environment.Is64BitProcess;
private string UrlGitHubReleases;
private string urlDownload;
private string UrlVersion;
private string UrlSHA256;
private static string path;
private string AppTitle;
private double FileSize;
private double Percentage;
public UpdateManagerConsole(string appName, string urlVersion, string urlGitHubReleases, string urlSHA256)
{
Console.Clear();
AppTitle = Console.Title;
Console.Title = Localization.UpdateManager;
UrlVersion = urlVersion;
UrlGitHubReleases = urlGitHubReleases;
UrlSHA256 = urlSHA256;
if (appName != null && appName != "")
{
productName = appName;
}
CheckUpdate();
}
private void CheckUpdate()
{
try
{
bool ass = UpdateManager.Update.Check(productVersion, is64BitProcess, UrlVersion, UrlGitHubReleases + "download/", productName + ".Setup", Environment.GetEnvironmentVariable("USERPROFILE") + @"\Downloads", out string newVersion, out urlDownload, out path);
if (ass)
{
Console.WriteLine(Localization.LastVersion + " " + newVersion);
Console.WriteLine(Localization.lblANewVersionAva + "\n" + Localization.lblANewVersionAva2);
Console.WriteLine("1: " + Localization.Yes);
Console.WriteLine("2: " + Localization.Exit);
var ad = Console.ReadLine();
if (ad == "1")
{
Download.DownloadUpdates(urlDownload, path, WebDownloadFileCompleted, WebDownloadProgressChanged);
var f = Console.ReadLine();
}
else if (ad == "2")
{
Console.Clear();
Console.Title = AppTitle;
}
else
{
Console.Clear();
CheckUpdate();
}
}
else
{
Console.WriteLine(Localization.LastVersion + " " + productVersion);
Console.WriteLine(Localization.NoNewVersion);
Console.WriteLine("1: " + Localization.CheckUpdates_CA);
Console.WriteLine("2: " + Localization.Exit);
var ad = Console.ReadLine();
if (ad == "1")
{
Console.Clear();
CheckUpdate();
}
else if (ad == "2")
{
Console.Clear();
Console.Title = AppTitle;
}
else
{
Console.Clear();
CheckUpdate();
}
}
}
catch (Exception ex)
{
Console.BackgroundColor = ConsoleColor.DarkRed;
Console.WriteLine(Localization.ERROR_2 + " " + ex.Message);
Console.WriteLine(Localization.LastVersion + " " + Localization.ERROR_2 + " " + Localization.LatestVersionNotDetected);
Console.WriteLine(Localization.ERROR_2 + " " + Localization.LatestVersionNotDetected);
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("1: " + Localization.CheckUpdates_CA);
Console.WriteLine("2: " + Localization.Exit);
var ad = Console.ReadLine();
if (ad == "1")
{
Console.Clear();
CheckUpdate();
}
else if (ad == "2")
{
Console.Clear();
Console.Title = AppTitle;
}
else
{
Console.Clear();
CheckUpdate();
}
}
}
private void WebDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double receive = double.Parse(e.BytesReceived.ToString());
FileSize = double.Parse(e.TotalBytesToReceive.ToString());
Percentage = receive / FileSize * 100;
Console.WriteLine(Localization.Downloading + $" { string.Format("{0:0.##}%", Percentage)}");
}
private void WebDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
try
{
if (e.Error != null)
{
Console.WriteLine(Localization.ERROR_2 + " " + e.Error.Message);
//var ad = Console.ReadLine();
}
else
{
Console.Clear();
Console.WriteLine(Localization.Downloaded + " " + "100%" + " " + Localization.TotalSize + $" {string.Format("{0:0.##} KB", FileSize / Percentage)}");
if (Hash.CheckHash(UrlSHA256, path, is64BitProcess))
{
Console.WriteLine(path);
InstallUpdates_CA();
}
else
{
Console.WriteLine(path);
Console.BackgroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("\n" + Localization.ERROR_2 + " " + Localization.DownloadedFileDontTrue);
Console.BackgroundColor = ConsoleColor.Black;
InstallUpdates_CA();
}
}
}
catch (Exception ex)
{
//Console.Clear();
Console.WriteLine(path);
Console.BackgroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("\n\n" + Localization.ERROR_2 + " " + Localization.VerificationFileNo + "\n" + Localization.ERROR_2 + " " + ex.Message);
Console.BackgroundColor = ConsoleColor.Black;
InstallUpdates_CA();
}
}
private void InstallUpdates_CA()
{
#region Install Updates
Console.WriteLine("1: " + Localization.InstallUpdates_CA);
//if (read == "1")
//{
try
{
Install.InstallUpdates_CA(path, productName);
Application.Restart();
Environment.Exit(0);
}
catch (Exception ex)
{
Console.BackgroundColor = ConsoleColor.DarkRed;
Console.WriteLine(Localization.ERROR_2 + " " + ex.Message);
Console.BackgroundColor = ConsoleColor.Black;
var ad2 = Console.ReadLine();
}
//}
//else if (read == "2")
//{
// var ad2 = Console.ReadLine();
//}
//else
//{
// var ad2 = Console.ReadLine();
//}
#endregion
}
}
}