|
3 | 3 | using System.Diagnostics;
|
4 | 4 | using System.IO;
|
5 | 5 | using System.Linq;
|
| 6 | +using System.Net.Http; |
6 | 7 | using System.Reflection;
|
7 | 8 | using System.Threading.Tasks;
|
8 | 9 | using IxMilia.BCad.Display;
|
@@ -34,7 +35,6 @@ public class ServerAgent
|
34 | 35 |
|
35 | 36 | private bool _readyEventFired;
|
36 | 37 | public event EventHandler IsReady;
|
37 |
| - private string _versionHtml = null; |
38 | 38 |
|
39 | 39 | public ServerAgent(LispWorkspace workspace, JsonRpc rpc)
|
40 | 40 | {
|
@@ -545,30 +545,55 @@ public void SetSetting(string name, string value)
|
545 | 545 | Workspace.SettingsService.SetValueFromString(name, value);
|
546 | 546 | }
|
547 | 547 |
|
548 |
| - public string GetVersionInformation() |
| 548 | + public async Task<VersionInformation> GetVersionInformation() |
549 | 549 | {
|
550 |
| - if (_versionHtml is null) |
| 550 | + // get currently running version |
| 551 | + var candidateAssemblyNames = new[] |
551 | 552 | {
|
552 |
| - // published app names |
553 |
| - var candidateAssemblyNames = new[] |
554 |
| - { |
555 |
| - "bcad.exe", |
556 |
| - "bcad.dll", |
557 |
| - "bcad" |
558 |
| - }; |
559 |
| - var assemblyPath = candidateAssemblyNames |
560 |
| - .Select(name => Path.Combine(AppContext.BaseDirectory, name)) |
561 |
| - .FirstOrDefault(File.Exists) |
562 |
| - ?? Assembly.GetExecutingAssembly().Location; // fall back to using reflection |
563 |
| - var versionString = assemblyPath is { } |
564 |
| - ? FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion |
565 |
| - : "<unknown>"; |
566 |
| - _versionHtml = $""" |
567 |
| - Version: {versionString}<br /> |
| 553 | + "bcad.exe", |
| 554 | + "bcad.dll", |
| 555 | + "bcad" |
| 556 | + }; |
| 557 | + var assemblyPath = candidateAssemblyNames |
| 558 | + .Select(name => Path.Combine(AppContext.BaseDirectory, name)) |
| 559 | + .FirstOrDefault(File.Exists) |
| 560 | + ?? Assembly.GetExecutingAssembly().Location; // fall back to using reflection |
| 561 | + var versionString = assemblyPath is { } |
| 562 | + ? FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion |
| 563 | + : "<unknown>"; |
| 564 | + var plusIndex = versionString.IndexOf('+'); |
| 565 | + var versionShortString = plusIndex >= 0 |
| 566 | + ? versionString.Substring(0, plusIndex) |
| 567 | + : versionString; |
| 568 | + |
| 569 | + // get available version |
| 570 | + var versionUrl = "https://pkgs.ixmilia.com/bcad/version.txt"; |
| 571 | + using var httpClient = new HttpClient(); |
| 572 | + string availableVersion = null; |
| 573 | + try |
| 574 | + { |
| 575 | + availableVersion = (await httpClient.GetStringAsync(versionUrl)).Trim(); |
| 576 | + } |
| 577 | + catch (Exception) |
| 578 | + { |
| 579 | + // couldn't query |
| 580 | + } |
| 581 | + |
| 582 | + string upgradeString = null; |
| 583 | + if (availableVersion is not null && availableVersion != versionShortString) |
| 584 | + { |
| 585 | + upgradeString = $""" |
| 586 | + New version available: {availableVersion}</br /> |
| 587 | + Please click "Close and update" to get the latest version. |
568 | 588 | """;
|
569 | 589 | }
|
570 | 590 |
|
571 |
| - return _versionHtml; |
| 591 | + var aboutString = $""" |
| 592 | + Version: {versionString}<br /> |
| 593 | + {upgradeString} |
| 594 | + """; |
| 595 | + var information = new VersionInformation(aboutString, versionShortString, availableVersion); |
| 596 | + return information; |
572 | 597 | }
|
573 | 598 | }
|
574 | 599 | }
|
0 commit comments