forked from IcemanF1/ALTTPRCropDashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.vb
118 lines (93 loc) · 4.02 KB
/
Program.vb
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
Imports System.Configuration
Imports System.IO
Imports System.Linq
Imports System.Reflection
Imports Squirrel
Public Module Program
' <summary>
' Make a backup of our settings.
' Used to persist settings across updates.
' </summary>
Public Sub BackupSettings()
Dim settingsFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath
Dim destination = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\last.config"
File.Copy(settingsFile, destination, True)
End Sub
' <summary>
' Restore our settings backup if any.
' Used to persist settings across updates.
' </summary>
Private Sub RestoreSettings()
'Restore settings after application update
Dim destFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath
Dim sourceFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\..\\last.config"
' Check if we have settings that we need to restore
If Not File.Exists(sourceFile) Then
Exit Sub
End If
' Create directory as needed
Try
Directory.CreateDirectory(Path.GetDirectoryName(destFile))
Catch e As Exception
End Try
' Copy our backup file in place
Try
File.Copy(sourceFile, destFile, True)
Catch e As Exception
End Try
' Delete backup file
Try
File.Delete(sourceFile)
Catch e As Exception
End Try
My.Settings.Reload()
End Sub
Private Sub CheckForUpdate(updatePath As String)
Task.Run(Async Sub()
Try
Using updateMgr = New UpdateManager(updatePath)
Await updateMgr.UpdateApp()
End Using
Catch ex As Exception
MessageBox.Show($"Error checking for update: ${ex}")
End Try
End Sub)
End Sub
Private Sub CreateShortcuts(mgr As UpdateManager)
Dim thePath = Path.Combine(Path.GetDirectoryName(Application.StartupPath), $"app-{mgr.CurrentlyInstalledVersion()}", "dashboard.exe")
mgr.CreateShortcutsForExecutable(thePath, ShortcutLocation.Desktop Or ShortcutLocation.StartMenu, False)
mgr.CreateShortcutForThisExe()
End Sub
Private Sub DeleteShortcuts(mgr As UpdateManager)
Dim thePath = Path.Combine(Path.GetDirectoryName(Application.StartupPath), $"app-{mgr.CurrentlyInstalledVersion()}", "dashboard.exe")
mgr.RemoveShortcutsForExecutable(thePath, ShortcutLocation.Desktop Or ShortcutLocation.StartMenu)
mgr.RemoveShortcutForThisExe()
End Sub
Public Sub Main()
If My.Settings.UpgradeRequired = True Then
My.Settings.Upgrade()
My.Settings.UpgradeRequired = False
My.Settings.Save()
End If
Dim testFolder = "C:\TestReleases"
Dim updatePath = If(ConfigurationManager.AppSettings("ReleasesURL"), testFolder)
If updatePath <> testFolder OrElse System.IO.Directory.Exists(testFolder) Then
Try
Using updateMgr = New UpdateManager(updatePath)
' ReSharper disable AccessToDisposedClosure
SquirrelAwareApp.HandleEvents(
onInitialInstall:=Sub(v) CreateShortcuts(updateMgr),
onAppUpdate:=Sub(v) CreateShortcuts(updateMgr),
onAppUninstall:=Sub(v) DeleteShortcuts(updateMgr))
' ReSharper enable AccessToDisposedClosure
End Using
CheckForUpdate(updatePath)
Catch ex As Exception
MessageBox.Show($"Error checking for update: ${ex}")
End Try
End If
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New ObsWebSocketCropper)
End Sub
End Module