don't download automatically, only when a new button is pressed
This commit is contained in:
		
							parent
							
								
									9f3632650f
								
							
						
					
					
						commit
						9f447473a2
					
				
							
								
								
									
										33
									
								
								EDDB/API.cs
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								EDDB/API.cs
									
									
									
									
									
								
							| @ -43,15 +43,27 @@ namespace NonaBGS.EDDB { | |||||||
| 
 | 
 | ||||||
|         private void DownloadFile(string url, string file, DatabaseAvailableDelegate notifier) { |         private void DownloadFile(string url, string file, DatabaseAvailableDelegate notifier) { | ||||||
|             WebClient client = new WebClient(); |             WebClient client = new WebClient(); | ||||||
|             client.DownloadDataCompleted += Client_DownloadDataCompleted; |             client.DownloadFileCompleted += Client_DownloadFileCompleted; | ||||||
|             client.DownloadFileAsync(new Uri(url), file, notifier); |             client.DownloadFileAsync(new Uri(url), file, notifier); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         private void Client_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { | ||||||
|  |             DatabaseAvailableDelegate notifier = e.UserState as DatabaseAvailableDelegate; | ||||||
|  |             notifier?.Invoke(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         private void TranslateStations() { |         private void TranslateStations() { | ||||||
|             if (!HaveStationsFile) { |             if (!HaveStationsFile) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             var short_time = File.GetLastWriteTimeUtc(StationsFileShort); | ||||||
|  |             var long_time = File.GetLastWriteTimeUtc(StationsFile); | ||||||
|  | 
 | ||||||
|  |             if (HaveStationsFileShort && long_time <= short_time) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             Dictionary<int, List<string>> systems = new Dictionary<int, List<string>>(); |             Dictionary<int, List<string>> systems = new Dictionary<int, List<string>>(); | ||||||
| 
 | 
 | ||||||
|             using (var str = new StreamReader(StationsFile)) { |             using (var str = new StreamReader(StationsFile)) { | ||||||
| @ -89,6 +101,16 @@ namespace NonaBGS.EDDB { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         public void CheckDatabases() { | ||||||
|  |             if (HaveSystemsFile) { | ||||||
|  |                 SystemsAvailable?.Invoke(); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (HaveStationsFile) { | ||||||
|  |                 StationsAvailable?.Invoke(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         public void Download(bool force) { |         public void Download(bool force) { | ||||||
|             if (!HaveSystemsFile || force) { |             if (!HaveSystemsFile || force) { | ||||||
|                 DownloadFile(EDDB_SYSTEMS_ARCHIVE, systems_file, SystemsAvailable); |                 DownloadFile(EDDB_SYSTEMS_ARCHIVE, systems_file, SystemsAvailable); | ||||||
| @ -132,16 +154,9 @@ namespace NonaBGS.EDDB { | |||||||
|                 throw new InvalidOperationException("no local systems file downloaded"); |                 throw new InvalidOperationException("no local systems file downloaded"); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (!HaveStationsFileShort) { |             TranslateStations(); | ||||||
|                 TranslateStations(); |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             return Stations.FromFile(StationsFileShort); |             return Stations.FromFile(StationsFileShort); | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         private void Client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { |  | ||||||
|             DatabaseAvailableDelegate notifier = e.UserState as DatabaseAvailableDelegate; |  | ||||||
|             notifier?.Invoke(); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -99,10 +99,11 @@ | |||||||
|                                 <RowDefinition Height="Auto"/> |                                 <RowDefinition Height="Auto"/> | ||||||
|                             </Grid.RowDefinitions> |                             </Grid.RowDefinitions> | ||||||
|                             <Grid.ColumnDefinitions> |                             <Grid.ColumnDefinitions> | ||||||
|                                 <ColumnDefinition Width="26*"/> |                                 <ColumnDefinition Width="*"/> | ||||||
|                                 <ColumnDefinition Width="285*"/> |                                 <ColumnDefinition Width="Auto"/> | ||||||
|                             </Grid.ColumnDefinitions> |                             </Grid.ColumnDefinitions> | ||||||
|                             <CheckBox x:Name="useeddb" Content="Use eddb station and system data for autocompletion" HorizontalAlignment="Left" Margin="0,10,0,10" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Click="useeddb_Click"/> |                             <CheckBox x:Name="useeddb" Content="Use eddb station and system data for autocompletion" HorizontalAlignment="Left" Margin="0,10,0,10" VerticalAlignment="Top" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" Click="useeddb_Click"/> | ||||||
|  |                             <Button x:Name="DownloadData" Content="Download Data" HorizontalAlignment="Center" Grid.Column="1" VerticalAlignment="Center" Width="Auto" Click="DownloadData_Click"/> | ||||||
|                         </Grid> |                         </Grid> | ||||||
|                     </GroupBox> |                     </GroupBox> | ||||||
|                 </Grid> |                 </Grid> | ||||||
|  | |||||||
| @ -59,7 +59,7 @@ namespace NonaBGS { | |||||||
|             api.StationsAvailable += Api_StationsAvailable; |             api.StationsAvailable += Api_StationsAvailable; | ||||||
| 
 | 
 | ||||||
|             try { |             try { | ||||||
|                 SyncDatabases(); |                 api.CheckDatabases(); | ||||||
|             } catch (Exception e) { |             } catch (Exception e) { | ||||||
|                 Log(e.Message); |                 Log(e.Message); | ||||||
|             } |             } | ||||||
| @ -97,14 +97,6 @@ namespace NonaBGS { | |||||||
|             Report_OnLog(message); |             Report_OnLog(message); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void SyncDatabases() { |  | ||||||
|             if (!config.Global.UseEDDB) { |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             api.Download(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         private void RefreshObjectives() { |         private void RefreshObjectives() { | ||||||
|             entries.Items.Clear(); |             entries.Items.Clear(); | ||||||
| 
 | 
 | ||||||
| @ -213,7 +205,6 @@ namespace NonaBGS { | |||||||
| 
 | 
 | ||||||
|         private void useeddb_Click(object sender, RoutedEventArgs e) { |         private void useeddb_Click(object sender, RoutedEventArgs e) { | ||||||
|             Config.Global.UseEDDB = (bool)useeddb.IsChecked; |             Config.Global.UseEDDB = (bool)useeddb.IsChecked; | ||||||
|             SyncDatabases(); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void Filter_KeyDown(object sender, KeyEventArgs e) { |         private void Filter_KeyDown(object sender, KeyEventArgs e) { | ||||||
| @ -239,5 +230,14 @@ namespace NonaBGS { | |||||||
|                 Log(exc.Message); |                 Log(exc.Message); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         private void DownloadData_Click(object sender, RoutedEventArgs e) { | ||||||
|  |             if (!Config.Global.UseEDDB) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             // Force download | ||||||
|  |             api.Download(true); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user