From be2c3a0cdc2a4944f131d30ea00436f1902df87b Mon Sep 17 00:00:00 2001 From: Donkey Date: Thu, 21 Dec 2023 21:53:13 +0100 Subject: [PATCH] feat: improved migration support in case that config.json are broken before the migration --- TwinpackShared/Models/Adapter.cs | 2 +- TwinpackVsixShared/Dialogs/CatalogWindow.xaml | 2 +- .../Dialogs/CatalogWindow.xaml.cs | 25 +++++++++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/TwinpackShared/Models/Adapter.cs b/TwinpackShared/Models/Adapter.cs index f12cb7f..9e3216c 100644 --- a/TwinpackShared/Models/Adapter.cs +++ b/TwinpackShared/Models/Adapter.cs @@ -51,7 +51,7 @@ public bool IsUpdateable { try { - return InstalledVersion != null && Update?.Version != null && new Version(InstalledVersion) < new Version(Update?.Version); + return (Installed?.Version == null && Update?.Version != null) || (Update?.Version != null && new Version(Installed?.Version) < new Version(Update?.Version)); } catch { diff --git a/TwinpackVsixShared/Dialogs/CatalogWindow.xaml b/TwinpackVsixShared/Dialogs/CatalogWindow.xaml index 2a6f626..64c2606 100644 --- a/TwinpackVsixShared/Dialogs/CatalogWindow.xaml +++ b/TwinpackVsixShared/Dialogs/CatalogWindow.xaml @@ -212,7 +212,7 @@ diff --git a/TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs b/TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs index edb597e..84e3202 100644 --- a/TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs +++ b/TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs @@ -324,6 +324,11 @@ public bool IsRestoreAllVisible } } + public bool IsRestoreAllEnabled + { + get { return _isRestoreAllEnabled; } + } + public bool IsInitializing { get { return _isInitializing; } @@ -340,7 +345,9 @@ public bool IsCatalogEnabled set { _isCatalogEnabled = value; + _isRestoreAllEnabled = _installedPackages.Any(x => x.PackageId == null) == false; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsCatalogEnabled))); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsRestoreAllEnabled))); } } @@ -505,6 +512,7 @@ private async void Dialog_Loaded(object sender, RoutedEventArgs e) { IsInitializing = false; IsCatalogLoading = false; + IsCatalogEnabled = true; IsPackageVersionPanelEnabled = _plcConfig != null; IsUpdateAvailable = _twinpackServer.IsClientUpdateAvailable == true; btnLogin.Text = _twinpackServer.LoggedIn ? "Logout" : "Login"; @@ -525,17 +533,14 @@ public async Task LoadPlcConfigAsync(CancellationToken cancellationToken) if (config != null) { _plcConfig = ConfigPlcProjectFactory.MapPlcConfigToPlcProj(config, _plc); - IsCreateConfigVisible = false; - IsMigrateConfigVisible = false; - IsMigrateConfigVisible = _plcConfig?.Packages?.Any() == false && _plcConfig.Frameworks?.Zeugwerk?.References?.Any() == true; } else { - IsCreateConfigVisible = true; - IsMigrateConfigVisible = false; _plcConfig = await ConfigPlcProjectFactory.CreateAsync(_context.Solution, _plc, _twinpackServer, cancellationToken); } + IsCreateConfigVisible = config == null; + IsMigrateConfigVisible = config != null && _plcConfig?.Packages?.Any() == false && _plcConfig.Frameworks?.Zeugwerk?.References?.Any() == true; IsConfigured = _plcConfig != null; } catch (Exception ex) @@ -589,6 +594,7 @@ public async void EditPackageButton_Click(object sender, RoutedEventArgs e) } finally { + IsCatalogEnabled = true; IsPackageVersionPanelEnabled = _plcConfig != null; } } @@ -1270,14 +1276,17 @@ private async Task LoadInstalledPackagesAsync(CancellationToken cancellationToke item.Configuration, item.Branch, item.Target, cancellationToken: cancellationToken); - // force the actual references version even if the version was not found + // force the packageVersion references version even if the version was not found if (packageVersion.PackageVersionId != null) { catalogItem = new CatalogItem(packageVersion); catalogItem.Installed = packageVersion; - catalogItem.Update = packageVersionLatest; } + // a package might be updateable but not available on Twinpack + if (packageVersionLatest.PackageVersionId != null) + catalogItem.Update = packageVersionLatest; + var packageId = catalogItem.PackageId ?? packageVersionLatest.PackageId; if (packageId == null || !_installedPackages.Any(x => x.PackageId == packageId)) { @@ -1526,6 +1535,7 @@ public async void ReloadButton_Click(object sender, RoutedEventArgs e) { IsPackageVersionPanelEnabled = _plcConfig != null; IsCatalogLoading = false; + IsCatalogEnabled = true; IsInitializing = false; } } @@ -1591,6 +1601,7 @@ public async void CreateConfig_Click(object sender, RoutedEventArgs e) } finally { + IsCatalogEnabled = true; IsPackageVersionPanelEnabled = _plcConfig != null; } }