Skip to content

Commit 30381ce

Browse files
committed
feat: Improve version compare
1 parent 2fe124a commit 30381ce

File tree

2 files changed

+21
-52
lines changed

2 files changed

+21
-52
lines changed

src/Atc.Installer.Wpf.ComponentProvider/ComponentProviderViewModel_LogicBase.cs

+17-25
Original file line numberDiff line numberDiff line change
@@ -1000,13 +1000,14 @@ private void WorkOnAnalyzeAndUpdateStatesForDotNetVersion()
10001000
installationMainFile = Path.Combine(installationMainPath, $"{Name}.dll");
10011001
}
10021002

1003-
if (!File.Exists(InstalledMainFilePath.GetValueAsString()))
1003+
var resolvedInstalledMainFilePath = InstalledMainFilePath.GetValueAsString();
1004+
if (!File.Exists(resolvedInstalledMainFilePath))
10041005
{
10051006
InstallationState = ComponentInstallationState.NotInstalled;
10061007
}
10071008

10081009
if (File.Exists(installationMainFile) &&
1009-
File.Exists(InstalledMainFilePath.GetValueAsString()))
1010+
File.Exists(resolvedInstalledMainFilePath))
10101011
{
10111012
Version? sourceVersion = null;
10121013
var installationMainFileVersion = FileVersionInfo.GetVersionInfo(installationMainFile);
@@ -1017,16 +1018,23 @@ private void WorkOnAnalyzeAndUpdateStatesForDotNetVersion()
10171018
}
10181019

10191020
Version? destinationVersion = null;
1020-
var installedMainFileVersion = FileVersionInfo.GetVersionInfo(InstalledMainFilePath.GetValueAsString());
1021+
var installedMainFileVersion = FileVersionInfo.GetVersionInfo(resolvedInstalledMainFilePath);
10211022
if (installedMainFileVersion?.FileVersion is not null)
10221023
{
10231024
destinationVersion = new Version(installedMainFileVersion.FileVersion);
10241025
InstalledVersion = installedMainFileVersion.FileVersion;
10251026
}
10261027

1027-
if (sourceVersion is not null &&
1028-
destinationVersion is not null &&
1029-
sourceVersion.IsNewerThan(destinationVersion))
1028+
if (VersionHelper.IsDefault(sourceVersion, destinationVersion))
1029+
{
1030+
var sourcePath = new DirectoryInfo(installationMainFile).Parent!;
1031+
var destinationPath = new DirectoryInfo(resolvedInstalledMainFilePath).Parent!;
1032+
if (sourcePath.GetTotalFilesLength("*.dll") != destinationPath.GetTotalFilesLength("*.dll"))
1033+
{
1034+
InstallationState = ComponentInstallationState.InstalledWithOldVersion;
1035+
}
1036+
}
1037+
else if (VersionHelper.IsSourceNewerThanDestination(sourceVersion, destinationVersion))
10301038
{
10311039
InstallationState = ComponentInstallationState.InstalledWithOldVersion;
10321040
}
@@ -1083,25 +1091,9 @@ private void WorkOnAnalyzeAndUpdateStatesForNodeJsVersion()
10831091
}
10841092
else
10851093
{
1086-
try
1087-
{
1088-
var isNewerThan = new Version(sourceVersion).IsNewerThan(new Version(destinationVersion));
1089-
InstallationState = isNewerThan
1090-
? ComponentInstallationState.InstalledWithOldVersion
1091-
: ComponentInstallationState.Installed;
1092-
}
1093-
catch
1094-
{
1095-
var sortedSet = new SortedSet<string>(StringComparer.Ordinal)
1096-
{
1097-
sourceVersion,
1098-
destinationVersion,
1099-
};
1100-
1101-
InstallationState = destinationVersion == sortedSet.First()
1102-
? ComponentInstallationState.InstalledWithOldVersion
1103-
: ComponentInstallationState.Installed;
1104-
}
1094+
InstallationState = VersionHelper.IsSourceNewerThanDestination(sourceVersion, destinationVersion)
1095+
? ComponentInstallationState.InstalledWithOldVersion
1096+
: ComponentInstallationState.Installed;
11051097
}
11061098
}
11071099
}

src/Atc.Installer.Wpf.ComponentProvider/ValueConverters/ComponentProviderVersionCompareVisibilityVisibleValueConverter.cs

+4-27
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ HostingFrameworkType.DonNetFramework48 or
2525
HostingFrameworkType.DotNet7 or
2626
HostingFrameworkType.DotNet8)
2727
{
28-
return AnalyzeForForDotNet(vm);
28+
return AnalyzeVersion(vm);
2929
}
3030

3131
return vm.ComponentType == ComponentType.InternetInformationService
32-
? AnalyzeForJsVersion(vm)
32+
? AnalyzeVersion(vm)
3333
: Visibility.Collapsed;
3434
}
3535

@@ -39,32 +39,9 @@ HostingFrameworkType.DotNet7 or
3939
object? parameter,
4040
CultureInfo culture) => null;
4141

42-
private static Visibility AnalyzeForJsVersion(
42+
private static Visibility AnalyzeVersion(
4343
ComponentProviderViewModel vm)
44-
{
45-
if (vm.InstallationVersion == vm.InstalledVersion)
46-
{
47-
return Visibility.Collapsed;
48-
}
49-
50-
var sortedSet = new SortedSet<string>(StringComparer.Ordinal)
51-
{
52-
vm.InstallationVersion!,
53-
vm.InstalledVersion!,
54-
};
55-
56-
return vm.InstalledVersion == sortedSet.First()
44+
=> VersionHelper.IsSourceNewerThanDestination(vm.InstallationVersion, vm.InstalledVersion)
5745
? Visibility.Visible
5846
: Visibility.Collapsed;
59-
}
60-
61-
private static Visibility AnalyzeForForDotNet(
62-
ComponentProviderViewModel vm)
63-
{
64-
var sourceVersion = new Version(vm.InstallationVersion!);
65-
var destinationVersion = new Version(vm.InstalledVersion!);
66-
return sourceVersion.IsNewerThan(destinationVersion)
67-
? Visibility.Visible
68-
: Visibility.Collapsed;
69-
}
7047
}

0 commit comments

Comments
 (0)