-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (101 loc) · 4.94 KB
/
Copy pathProgram.cs
File metadata and controls
110 lines (101 loc) · 4.94 KB
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
using System.Diagnostics;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Windows;
using Velopack;
using Velopack.Sources;
namespace Mapper_v1
{
public class Program
{
[STAThread]
public static void Main(string[] args)
{
try
{
VelopackApp.Build()
.OnFirstRun(v => MessageBox.Show("Thanks for installing RNav !"))
.SetAutoApplyOnStartup(false)
//.WithAfterInstallFastCallback(v => AddFontResource(@"./Fonts/RNav.ttf"))
//.WithBeforeUninstallFastCallback(v => RemoveFontResource(@"./Fonts/RNav.ttf"))
.Run();
if (IsFontInstalled("RNav") == false)
{
var result = AddFontResource(@"./Fonts/RNav.ttf");
//MessageBox.Show($"Added {result} new font");
//Trace.WriteLine($"Added {result} new font");
}
//_ = UpdateMyApp();
var app = new App();
app.InitializeComponent();
app.Run();
}
catch (Exception ex)
{
MessageBox.Show($"Unhandeled exception: {ex}");
}
}
private static bool IsFontInstalled(string name)
{
using (InstalledFontCollection fontsCollection = new InstalledFontCollection())
{
return fontsCollection.Families
.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
}
[DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);
[DllImport("gdi32.dll", EntryPoint = "RemoveFontResourceW", SetLastError = true)]
public static extern int RemoveFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
string lpFileName);
private static async Task UpdateMyApp()
{
var mgr = new UpdateManager(new GithubSource("https://github.com/MorgothT/RNav", "", false));
var newVersion = await mgr.CheckForUpdatesAsync();
if (newVersion == null)
return;
await mgr.DownloadUpdatesAsync(newVersion);
var result = MessageBox.Show($"Version {newVersion.TargetFullRelease.Version} is available.{Environment.NewLine}Do you wish to restart the application ?",
"New version found",
button: MessageBoxButton.YesNo,
icon: MessageBoxImage.Question,
defaultResult: MessageBoxResult.No);
if (result == MessageBoxResult.Yes)
mgr.ApplyUpdatesAndRestart(newVersion);
else
mgr.WaitExitThenApplyUpdates(newVersion.TargetFullRelease, restart: false);
}
// private static async Task UpdateMyApp()
// {
// try
// {
//#pragma warning disable CS0618 // Type or member is obsolete
// using (var mgr = await UpdateManager.GitHubUpdateManager("https://github.com/MorgothT/RNav"))
// //using (var mgr = await UpdateManager(new GithubSource("https://github.com/MorgothT/RNav")))
// {
// var newVersion = await mgr.UpdateApp();
// // optionally restart the app automatically, or ask the user if/when they want to restart
// if (newVersion != null)
// {
// var result = MessageBox.Show($"Version {newVersion.Version} is available.{Environment.NewLine}Do you wish to restart the application ?",
// "New version found",
// button: MessageBoxButton.YesNo,
// icon: MessageBoxImage.Question,
// defaultResult: MessageBoxResult.No);
// if (result == MessageBoxResult.Yes) UpdateManager.RestartApp();
// }
// else
// {
// MessageBox.Show("RNav is running the latest version");
// }
// }
//#pragma warning restore CS0618 // Type or member is obsolete
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
// }
}
}