don't download automatically, only when a new button is pressed
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user