@@ -29,89 +29,69 @@ public Updater(string gitHubRepository)
29
29
GitHubRepository = gitHubRepository ;
30
30
}
31
31
32
- public async Task UpdateApp ( IPublicAPI api , bool silentUpdate = true )
32
+ public async Task UpdateApp ( IPublicAPI api , bool silentUpdate = true )
33
33
{
34
- UpdateManager updateManager ;
35
- UpdateInfo newUpdateInfo ;
36
-
37
- if ( ! silentUpdate )
38
- api . ShowMsg ( "Please wait..." , "Checking for new update" ) ;
39
-
40
34
try
41
35
{
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
- }
36
+ UpdateInfo newUpdateInfo ;
37
+
38
+ if ( ! silentUpdate )
39
+ api . ShowMsg ( "Please wait..." , "Checking for new update" ) ;
40
+
41
+ using var updateManager = await GitHubUpdateManager ( GitHubRepository ) ;
42
+
49
43
50
- try
51
- {
52
44
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
53
45
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
- }
61
46
62
- var newReleaseVersion = Version . Parse ( newUpdateInfo . FutureReleaseEntry . Version . ToString ( ) ) ;
63
- var currentVersion = Version . Parse ( Constant . Version ) ;
47
+ var newReleaseVersion = Version . Parse ( newUpdateInfo . FutureReleaseEntry . Version . ToString ( ) ) ;
48
+ var currentVersion = Version . Parse ( Constant . Version ) ;
64
49
65
- Log . Info ( $ "|Updater.UpdateApp|Future Release <{ newUpdateInfo . FutureReleaseEntry . Formatted ( ) } >") ;
50
+ Log . Info ( $ "|Updater.UpdateApp|Future Release <{ newUpdateInfo . FutureReleaseEntry . Formatted ( ) } >") ;
66
51
67
- if ( newReleaseVersion <= currentVersion )
68
- {
69
- if ( ! silentUpdate )
70
- MessageBox . Show ( "You already have the latest Flow Launcher version" ) ;
71
- updateManager . Dispose ( ) ;
72
- return ;
73
- }
52
+ if ( newReleaseVersion <= currentVersion )
53
+ {
54
+ if ( ! silentUpdate )
55
+ MessageBox . Show ( "You already have the latest Flow Launcher version" ) ;
56
+ updateManager . Dispose ( ) ;
57
+ return ;
58
+ }
74
59
75
- if ( ! silentUpdate )
76
- api . ShowMsg ( "Update found" , "Updating..." ) ;
60
+ if ( ! silentUpdate )
61
+ api . ShowMsg ( "Update found" , "Updating..." ) ;
77
62
78
- try
79
- {
80
63
await updateManager . DownloadReleases ( newUpdateInfo . ReleasesToApply ) ;
64
+
65
+ await updateManager . ApplyReleases ( newUpdateInfo ) ;
66
+
67
+ if ( DataLocation . PortableDataLocationInUse ( ) )
68
+ {
69
+ var targetDestination = updateManager . RootAppDirectory + $ "\\ app-{ newReleaseVersion . ToString ( ) } \\ { DataLocation . PortableFolderName } ";
70
+ FilesFolders . CopyAll ( DataLocation . PortableDataPath , targetDestination ) ;
71
+ if ( ! FilesFolders . VerifyBothFolderFilesEqual ( DataLocation . PortableDataPath , targetDestination ) )
72
+ MessageBox . Show ( "Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
73
+ $ "move your profile data folder from { DataLocation . PortableDataPath } to { targetDestination } ") ;
74
+ }
75
+ else
76
+ {
77
+ await updateManager . CreateUninstallerRegistryEntry ( ) ;
78
+ }
79
+
80
+ var newVersionTips = NewVersinoTips ( newReleaseVersion . ToString ( ) ) ;
81
+
82
+ Log . Info ( $ "|Updater.UpdateApp|Update success:{ newVersionTips } ") ;
83
+
84
+ if ( MessageBox . Show ( newVersionTips , "New Update" , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
85
+ {
86
+ UpdateManager . RestartApp ( Constant . ApplicationFileName ) ;
87
+ }
81
88
}
82
89
catch ( Exception e ) when ( e is HttpRequestException || e is WebException || e is SocketException )
83
90
{
84
91
Log . Exception ( $ "|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e ) ;
85
- updateManager . Dispose ( ) ;
92
+ api . ShowMsg ( "Update Fail!" , "Check your connection and proxy settings to github-cloud.s3.amazonaws.com." ) ;
86
93
return ;
87
94
}
88
-
89
- await updateManager . ApplyReleases ( newUpdateInfo ) ;
90
-
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
- }
103
-
104
- var newVersionTips = NewVersinoTips ( newReleaseVersion . ToString ( ) ) ;
105
-
106
- Log . Info ( $ "|Updater.UpdateApp|Update success:{ newVersionTips } ") ;
107
-
108
- // always dispose UpdateManager
109
- updateManager . Dispose ( ) ;
110
-
111
- if ( MessageBox . Show ( newVersionTips , "New Update" , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
112
- {
113
- UpdateManager . RestartApp ( Constant . ApplicationFileName ) ;
114
- }
115
95
}
116
96
117
97
[ UsedImplicitly ]
0 commit comments