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) {
|
||||
WebClient client = new WebClient();
|
||||
client.DownloadDataCompleted += Client_DownloadDataCompleted;
|
||||
client.DownloadFileCompleted += Client_DownloadFileCompleted;
|
||||
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() {
|
||||
if (!HaveStationsFile) {
|
||||
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>>();
|
||||
|
||||
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) {
|
||||
if (!HaveSystemsFile || force) {
|
||||
DownloadFile(EDDB_SYSTEMS_ARCHIVE, systems_file, SystemsAvailable);
|
||||
@ -132,16 +154,9 @@ namespace NonaBGS.EDDB {
|
||||
throw new InvalidOperationException("no local systems file downloaded");
|
||||
}
|
||||
|
||||
if (!HaveStationsFileShort) {
|
||||
TranslateStations();
|
||||
}
|
||||
TranslateStations();
|
||||
|
||||
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"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="26*"/>
|
||||
<ColumnDefinition Width="285*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</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>
|
||||
</GroupBox>
|
||||
</Grid>
|
||||
|
@ -59,7 +59,7 @@ namespace NonaBGS {
|
||||
api.StationsAvailable += Api_StationsAvailable;
|
||||
|
||||
try {
|
||||
SyncDatabases();
|
||||
api.CheckDatabases();
|
||||
} catch (Exception e) {
|
||||
Log(e.Message);
|
||||
}
|
||||
@ -97,14 +97,6 @@ namespace NonaBGS {
|
||||
Report_OnLog(message);
|
||||
}
|
||||
|
||||
private void SyncDatabases() {
|
||||
if (!config.Global.UseEDDB) {
|
||||
return;
|
||||
}
|
||||
|
||||
api.Download();
|
||||
}
|
||||
|
||||
private void RefreshObjectives() {
|
||||
entries.Items.Clear();
|
||||
|
||||
@ -213,7 +205,6 @@ namespace NonaBGS {
|
||||
|
||||
private void useeddb_Click(object sender, RoutedEventArgs e) {
|
||||
Config.Global.UseEDDB = (bool)useeddb.IsChecked;
|
||||
SyncDatabases();
|
||||
}
|
||||
|
||||
private void Filter_KeyDown(object sender, KeyEventArgs e) {
|
||||
@ -239,5 +230,14 @@ namespace NonaBGS {
|
||||
Log(exc.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void DownloadData_Click(object sender, RoutedEventArgs e) {
|
||||
if (!Config.Global.UseEDDB) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Force download
|
||||
api.Download(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user