From 9f447473a2fb32b65c63a7afb3eb312f0fdfdccd Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sun, 1 Aug 2021 15:26:33 +0200 Subject: [PATCH] don't download automatically, only when a new button is pressed --- EDDB/API.cs | 33 ++++++++++++++++++++++++--------- MainWindow.xaml | 7 ++++--- MainWindow.xaml.cs | 20 ++++++++++---------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/EDDB/API.cs b/EDDB/API.cs index ea350bb..0209546 100644 --- a/EDDB/API.cs +++ b/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> systems = new Dictionary>(); 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(); - } } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 1010bd5..b44a078 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -99,10 +99,11 @@ - - + + - + +