@@ -108,6 +108,76 @@ private async void gameListView_SelectionChanged(object sender, SelectionChanged
108108 _configService . SelectingGame = gameListView . SelectedIndex ;
109109 await SetPageAsync ( gameListView . SelectedItem as GameMenuItem ) ;
110110 }
111+
112+ private async void InstallLatestBuildFromVersionDropdown ( )
113+ {
114+ if ( _selectedMenuItem == null )
115+ return ;
116+
117+ var selectedItem = versionDropdown . SelectedItem as ComboBoxItem ;
118+ if ( selectedItem ? . Tag is Build build )
119+ {
120+ var currentVersion = await _selectedMenuItem . InstallService . GetCurrentVersionAsync ( ) ;
121+ if ( build . Version == currentVersion )
122+ return ;
123+
124+ try
125+ {
126+ downloadProgress . IsVisible = true ;
127+ SetAllInteractionEnabled ( false ) ;
128+
129+ var assets = build . Assets
130+ . Where ( x => x . IsPortable )
131+ . Where ( x => x . IsApplicableForCurrentPlatform ( ) )
132+ . OrderBy ( x => x , BuildAssetComparer . Default )
133+ . ToArray ( ) ;
134+
135+ var asset = assets . FirstOrDefault ( ) ;
136+ if ( asset == null )
137+ {
138+ return ;
139+ }
140+
141+ var progress = new Progress < DownloadProgressReport > ( ) ;
142+ progress . ProgressChanged += ( s , report ) =>
143+ {
144+ Dispatcher . UIThread . Post ( ( ) =>
145+ {
146+ downloadButton . Content = report . Status ;
147+ if ( report . Value is float value )
148+ {
149+ downloadProgress . IsIndeterminate = false ;
150+ downloadProgress . Value = value ;
151+ }
152+ else
153+ {
154+ downloadProgress . IsIndeterminate = true ;
155+ }
156+ } ) ;
157+ } ;
158+
159+ var cts = new CancellationTokenSource ( ) ;
160+ await _selectedMenuItem . InstallService . DownloadVersion (
161+ new DownloadService ( ) ,
162+ new Shell ( ) ,
163+ build . Version ,
164+ asset . Uri ,
165+ progress ,
166+ cts . Token ) ;
167+ await RefreshInstalledVersionAsync ( ) ;
168+ }
169+ catch ( Exception ex )
170+ {
171+ ShowError ( StringResources . DownloadBuildFailedTitle , ex ) ;
172+ }
173+ finally
174+ {
175+ downloadButton . Content = StringResources . Download ;
176+ downloadProgress . IsVisible = false ;
177+ SetAllInteractionEnabled ( true ) ;
178+ }
179+ }
180+ }
111181
112182 private async void showDevelopmentVersionsCheckbox_Changed ( object sender , RoutedEventArgs e )
113183 {
@@ -123,81 +193,16 @@ private void autoUpdateGameCheckbox_Changed(object sender, RoutedEventArgs e)
123193 return ;
124194 _configService . AutoUpdateGame = autoUpdateGameCheckbox . IsChecked ?? false ;
125195 SetAllInteractionEnabled ( true ) ;
126- }
127-
128- private async void DownloadBuild ( Build build )
129- {
130- if ( _selectedMenuItem == null )
131- return ;
132-
133- var currentVersion = await _selectedMenuItem . InstallService . GetCurrentVersionAsync ( ) ;
134- if ( build . Version == currentVersion )
135- return ;
136-
137- try
196+
197+ if ( _configService . AutoUpdateGame )
138198 {
139- downloadProgress . IsVisible = true ;
140- SetAllInteractionEnabled ( false ) ;
141-
142- var assets = build . Assets
143- . Where ( x => x . IsPortable )
144- . Where ( x => x . IsApplicableForCurrentPlatform ( ) )
145- . OrderBy ( x => x , BuildAssetComparer . Default )
146- . ToArray ( ) ;
147-
148- var asset = assets . FirstOrDefault ( ) ;
149- if ( asset == null )
150- {
151- return ;
152- }
153-
154- var progress = new Progress < DownloadProgressReport > ( ) ;
155- progress . ProgressChanged += ( s , report ) =>
156- {
157- Dispatcher . UIThread . Post ( ( ) =>
158- {
159- downloadButton . Content = report . Status ;
160- if ( report . Value is float value )
161- {
162- downloadProgress . IsIndeterminate = false ;
163- downloadProgress . Value = value ;
164- }
165- else
166- {
167- downloadProgress . IsIndeterminate = true ;
168- }
169- } ) ;
170- } ;
171-
172- var cts = new CancellationTokenSource ( ) ;
173- await _selectedMenuItem . InstallService . DownloadVersion (
174- new DownloadService ( ) ,
175- new Shell ( ) ,
176- build . Version ,
177- asset . Uri ,
178- progress ,
179- cts . Token ) ;
180- await RefreshInstalledVersionAsync ( ) ;
181- }
182- catch ( Exception ex )
183- {
184- ShowError ( StringResources . DownloadBuildFailedTitle , ex ) ;
185- }
186- finally
187- {
188- downloadButton . Content = StringResources . Download ;
189- downloadProgress . IsVisible = false ;
190- SetAllInteractionEnabled ( true ) ;
199+ InstallLatestBuildFromVersionDropdown ( ) ;
191200 }
192201 }
193-
202+
194203 private void downloadButton_Click ( object sender , RoutedEventArgs e )
195204 {
196- var selectedItem = versionDropdown . SelectedItem as ComboBoxItem ;
197- if ( selectedItem ? . Tag is Build build )
198- {
199- DownloadBuild ( build ) ;
200- }
205+ InstallLatestBuildFromVersionDropdown ( ) ;
201206 }
202207
203208 private async void playButton_Click ( object sender , RoutedEventArgs e )
@@ -288,9 +293,9 @@ private async Task RefreshAvailableVersionsAsync()
288293 {
289294 downloadButton . IsEnabled = ! _configService . AutoUpdateGame ;
290295 versionDropdown . IsHitTestVisible = true ;
291- if ( _configService . AutoUpdateGame && builds . Length > 0 )
296+ if ( _configService . AutoUpdateGame )
292297 {
293- DownloadBuild ( builds [ 0 ] ) ;
298+ InstallLatestBuildFromVersionDropdown ( ) ;
294299 }
295300 }
296301 }
0 commit comments