-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
87 lines (80 loc) · 3.48 KB
/
Utils.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
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace TimeWidget.Utils
{
public class Util
{
static readonly string version = Application.ProductVersion;
private static readonly WebClient wc = new WebClient();
public static string UrlVersion = "https://raw.githubusercontent.com/Stive99/TimeWidget/master/Properties/AssemblyInfo.cs";
private static readonly string VersionUpdateUrl = wc.DownloadString(UrlVersion);
public static string VersionUpdate = Regex.Match(VersionUpdateUrl, @"\[assembly\: AssemblyFileVersion\(""(\d+\.\d+\.\d+\.\d+)""\)\]").Groups[1].Value;
public static string UrlDownload = $"https://github.com/Stive99/TimeWidget/releases/download/{VersionUpdate}/TimeWidget.exe";
public static void CheckUpdate()
{
try
{
if (String.Compare(VersionUpdate, version) == 0)
{
// MessageBox.Show("У вас установлена последняя версия программы!", "Обновления не найдены", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (MessageBox.Show("Текущая версия программы " + version + "\nНовое обновление доступно " + VersionUpdate + "\n\nТребуется обновление.\nОбновить программу до актуальной версии?", "Найдено новое обновление!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
DownloadUpdate();
}
}
}
catch
{
// MessageBox.Show("Отсутствует подключение к интернету!", "Проверте подключение!");
}
}
public static void DownloadUpdate()
{
File.Move("TimeWidget.exe", "TimeWidgetOldVersion.exe");
using (WebClient wc = new WebClient())
{
string fileName = Path.Combine(Environment.CurrentDirectory, "TimeWidget.exe");
wc.DownloadFileAsync(new Uri(UrlDownload), fileName);
wc.DownloadFileCompleted += (s, e) =>
{
if (e.Error != null)
{
MessageBox.Show("Ошибка загрузки файла!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
Process.Start(fileName);
Application.Exit();
}
};
}
}
public static void SetApplicationOnLeftTop(Form1 form1)
{
/*var monitors = Screen.AllScreens;
foreach (var monitor in monitors)
{
if (monitor.DeviceName == form1.Monitor)
{
form1.Location = new Point(monitor.Bounds.X, monitor.Bounds.Y);
}
}*/
Screen.AllScreens.ToList().ForEach(x =>
{
if (x.Primary)
{
form1.Location = new Point(x.Bounds.X, x.Bounds.Y);
}
});
}
}
}