8
8
using System . Windows ;
9
9
using JetBrains . Annotations ;
10
10
using Squirrel ;
11
- using Newtonsoft . Json ;
12
11
using Flow . Launcher . Core . Resource ;
13
12
using Flow . Launcher . Plugin . SharedCommands ;
14
13
using Flow . Launcher . Infrastructure ;
15
14
using Flow . Launcher . Infrastructure . Http ;
16
15
using Flow . Launcher . Infrastructure . Logger ;
17
- using System . IO ;
18
16
using Flow . Launcher . Infrastructure . UserSettings ;
19
17
using Flow . Launcher . Plugin ;
18
+ using System . Text . Json . Serialization ;
20
19
21
20
namespace Flow . Launcher . Core
22
21
{
@@ -29,101 +28,80 @@ public Updater(string gitHubRepository)
29
28
GitHubRepository = gitHubRepository ;
30
29
}
31
30
32
- public async Task UpdateApp ( IPublicAPI api , bool silentUpdate = true )
31
+ public async Task UpdateApp ( IPublicAPI api , bool silentUpdate = true )
33
32
{
34
- UpdateManager updateManager ;
35
- UpdateInfo newUpdateInfo ;
36
-
37
- if ( ! silentUpdate )
38
- api . ShowMsg ( "Please wait..." , "Checking for new update" ) ;
39
-
40
33
try
41
34
{
42
- updateManager = await GitHubUpdateManager ( GitHubRepository ) ;
43
- }
44
- catch ( Exception e ) when ( e is HttpRequestException || e is WebException || e is SocketException )
45
- {
46
- Log . Exception ( $ "|Updater.UpdateApp|Please check your connection and proxy settings to api.github.com." , e ) ;
47
- return ;
48
- }
35
+ UpdateInfo newUpdateInfo ;
36
+
37
+ if ( ! silentUpdate )
38
+ api . ShowMsg ( "Please wait..." , "Checking for new update" ) ;
39
+
40
+ using var updateManager = await GitHubUpdateManager ( GitHubRepository ) . ConfigureAwait ( false ) ;
41
+
49
42
50
- try
51
- {
52
43
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
53
- newUpdateInfo = await updateManager . CheckForUpdate ( ) . NonNull ( ) ;
54
- }
55
- catch ( Exception e ) when ( e is HttpRequestException || e is WebException || e is SocketException )
56
- {
57
- Log . Exception ( $ "|Updater.UpdateApp|Check your connection and proxy settings to api.github.com.", e ) ;
58
- updateManager . Dispose ( ) ;
59
- return ;
60
- }
44
+ newUpdateInfo = await updateManager . CheckForUpdate ( ) . NonNull ( ) . ConfigureAwait ( false ) ;
61
45
62
- var newReleaseVersion = Version . Parse ( newUpdateInfo . FutureReleaseEntry . Version . ToString ( ) ) ;
63
- var currentVersion = Version . Parse ( Constant . Version ) ;
46
+ var newReleaseVersion = Version . Parse ( newUpdateInfo . FutureReleaseEntry . Version . ToString ( ) ) ;
47
+ var currentVersion = Version . Parse ( Constant . Version ) ;
64
48
65
- Log . Info ( $ "|Updater.UpdateApp|Future Release <{ newUpdateInfo . FutureReleaseEntry . Formatted ( ) } >") ;
49
+ Log . Info ( $ "|Updater.UpdateApp|Future Release <{ newUpdateInfo . FutureReleaseEntry . Formatted ( ) } >") ;
50
+
51
+ if ( newReleaseVersion <= currentVersion )
52
+ {
53
+ if ( ! silentUpdate )
54
+ MessageBox . Show ( "You already have the latest Flow Launcher version" ) ;
55
+ return ;
56
+ }
66
57
67
- if ( newReleaseVersion <= currentVersion )
68
- {
69
58
if ( ! silentUpdate )
70
- MessageBox . Show ( "You already have the latest Flow Launcher version" ) ;
71
- updateManager . Dispose ( ) ;
72
- return ;
73
- }
59
+ api . ShowMsg ( "Update found" , "Updating..." ) ;
74
60
75
- if ( ! silentUpdate )
76
- api . ShowMsg ( "Update found" , "Updating..." ) ;
61
+ await updateManager . DownloadReleases ( newUpdateInfo . ReleasesToApply ) . ConfigureAwait ( false ) ;
77
62
78
- try
79
- {
80
- await updateManager . DownloadReleases ( newUpdateInfo . ReleasesToApply ) ;
81
- }
82
- catch ( Exception e ) when ( e is HttpRequestException || e is WebException || e is SocketException )
83
- {
84
- Log . Exception ( $ "|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e ) ;
85
- updateManager . Dispose ( ) ;
86
- return ;
87
- }
88
-
89
- await updateManager . ApplyReleases ( newUpdateInfo ) ;
63
+ await updateManager . ApplyReleases ( newUpdateInfo ) . ConfigureAwait ( false ) ;
90
64
91
- if ( DataLocation . PortableDataLocationInUse ( ) )
92
- {
93
- var targetDestination = updateManager . RootAppDirectory + $ "\\ app-{ newReleaseVersion . ToString ( ) } \\ { DataLocation . PortableFolderName } ";
94
- FilesFolders . CopyAll ( DataLocation . PortableDataPath , targetDestination ) ;
95
- if ( ! FilesFolders . VerifyBothFolderFilesEqual ( DataLocation . PortableDataPath , targetDestination ) )
96
- MessageBox . Show ( "Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
97
- $ "move your profile data folder from { DataLocation . PortableDataPath } to { targetDestination } ") ;
98
- }
99
- else
100
- {
101
- await updateManager . CreateUninstallerRegistryEntry ( ) ;
102
- }
65
+ if ( DataLocation . PortableDataLocationInUse ( ) )
66
+ {
67
+ var targetDestination = updateManager . RootAppDirectory + $ "\\ app-{ newReleaseVersion . ToString ( ) } \\ { DataLocation . PortableFolderName } ";
68
+ FilesFolders . CopyAll ( DataLocation . PortableDataPath , targetDestination ) ;
69
+ if ( ! FilesFolders . VerifyBothFolderFilesEqual ( DataLocation . PortableDataPath , targetDestination ) )
70
+ MessageBox . Show ( "Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
71
+ $ "move your profile data folder from { DataLocation . PortableDataPath } to { targetDestination } ") ;
72
+ }
73
+ else
74
+ {
75
+ await updateManager . CreateUninstallerRegistryEntry ( ) . ConfigureAwait ( false ) ;
76
+ }
103
77
104
- var newVersionTips = NewVersinoTips ( newReleaseVersion . ToString ( ) ) ;
105
-
106
- Log . Info ( $ "|Updater.UpdateApp|Update success:{ newVersionTips } ") ;
78
+ var newVersionTips = NewVersinoTips ( newReleaseVersion . ToString ( ) ) ;
107
79
108
- // always dispose UpdateManager
109
- updateManager . Dispose ( ) ;
80
+ Log . Info ( $ "|Updater.UpdateApp|Update success:{ newVersionTips } ") ;
110
81
111
- if ( MessageBox . Show ( newVersionTips , "New Update" , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
82
+ if ( MessageBox . Show ( newVersionTips , "New Update" , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
83
+ {
84
+ UpdateManager . RestartApp ( Constant . ApplicationFileName ) ;
85
+ }
86
+ }
87
+ catch ( Exception e ) when ( e is HttpRequestException || e is WebException || e is SocketException )
112
88
{
113
- UpdateManager . RestartApp ( Constant . ApplicationFileName ) ;
89
+ Log . Exception ( $ "|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e ) ;
90
+ api . ShowMsg ( "Update Failed" , "Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com." ) ;
91
+ return ;
114
92
}
115
93
}
116
94
117
95
[ UsedImplicitly ]
118
96
private class GithubRelease
119
97
{
120
- [ JsonProperty ( "prerelease" ) ]
98
+ [ JsonPropertyName ( "prerelease" ) ]
121
99
public bool Prerelease { get ; [ UsedImplicitly ] set ; }
122
100
123
- [ JsonProperty ( "published_at" ) ]
101
+ [ JsonPropertyName ( "published_at" ) ]
124
102
public DateTime PublishedAt { get ; [ UsedImplicitly ] set ; }
125
103
126
- [ JsonProperty ( "html_url" ) ]
104
+ [ JsonPropertyName ( "html_url" ) ]
127
105
public string HtmlUrl { get ; [ UsedImplicitly ] set ; }
128
106
}
129
107
@@ -133,13 +111,13 @@ private async Task<UpdateManager> GitHubUpdateManager(string repository)
133
111
var uri = new Uri ( repository ) ;
134
112
var api = $ "https://api.github.com/repos{ uri . AbsolutePath } /releases";
135
113
136
- var json = await Http . Get ( api ) ;
114
+ var jsonStream = await Http . GetStreamAsync ( api ) . ConfigureAwait ( false ) ;
137
115
138
- var releases = JsonConvert . DeserializeObject < List < GithubRelease > > ( json ) ;
116
+ var releases = await System . Text . Json . JsonSerializer . DeserializeAsync < List < GithubRelease > > ( jsonStream ) . ConfigureAwait ( false ) ;
139
117
var latest = releases . Where ( r => ! r . Prerelease ) . OrderByDescending ( r => r . PublishedAt ) . First ( ) ;
140
118
var latestUrl = latest . HtmlUrl . Replace ( "/tag/" , "/download/" ) ;
141
119
142
- var client = new WebClient { Proxy = Http . WebProxy ( ) } ;
120
+ var client = new WebClient { Proxy = Http . WebProxy } ;
143
121
var downloader = new FileDownloader ( client ) ;
144
122
145
123
var manager = new UpdateManager ( latestUrl , urlDownloader : downloader ) ;
0 commit comments