Ver código fonte

Bug fix: Version check did not work with five digit build number

(as a solution, the build number is explicitly ignored in the check - technically is was ignored already, were it not for the bug, as the server provides the versions without build the build number)

Source commit: 060f4a536c15ae4fe54581e07a93716cb52fc2a0
Martin Prikryl 5 anos atrás
pai
commit
98fa08c5c5

+ 1 - 1
source/core/Configuration.cpp

@@ -896,7 +896,7 @@ int __fastcall TConfiguration::GetCompoundVersion()
   TVSFixedFileInfo * FileInfo = FixedApplicationInfo;
   return CalculateCompoundVersion(
     HIWORD(FileInfo->dwFileVersionMS), LOWORD(FileInfo->dwFileVersionMS),
-    HIWORD(FileInfo->dwFileVersionLS), LOWORD(FileInfo->dwFileVersionLS));
+    HIWORD(FileInfo->dwFileVersionLS));
 }
 //---------------------------------------------------------------------------
 UnicodeString __fastcall TConfiguration::ModuleFileName()

+ 8 - 6
source/core/FileInfo.cpp

@@ -261,21 +261,23 @@ UnicodeString __fastcall GetFileInfoString(void * FileInfo,
   return Result;
 }
 //---------------------------------------------------------------------------
-int __fastcall CalculateCompoundVersion(int MajorVer,
-  int MinorVer, int Release, int Build)
+int __fastcall CalculateCompoundVersion(int MajorVer, int MinorVer, int Release)
 {
-  int CompoundVer = Build + 10000 * (Release + 100 * (MinorVer +
-    100 * MajorVer));
+  int CompoundVer = 10000 * (Release + 100 * (MinorVer + 100 * MajorVer));
   return CompoundVer;
 }
 //---------------------------------------------------------------------------
+int ZeroBuildNumber(int CompoundVersion)
+{
+  return (CompoundVersion / 10000 * 10000);
+}
+//---------------------------------------------------------------------------
 int __fastcall StrToCompoundVersion(UnicodeString S)
 {
   int MajorVer = Min(StrToInt(CutToChar(S, L'.', false)), 99);
   int MinorVer = Min(StrToInt(CutToChar(S, L'.', false)), 99);
   int Release = S.IsEmpty() ? 0 : Min(StrToInt(CutToChar(S, L'.', false)), 99);
-  int Build = S.IsEmpty() ? 0 : Min(StrToInt(CutToChar(S, L'.', false)), 9999);
-  return CalculateCompoundVersion(MajorVer, MinorVer, Release, Build);
+  return CalculateCompoundVersion(MajorVer, MinorVer, Release);
 }
 //---------------------------------------------------------------------------
 int __fastcall CompareVersion(UnicodeString V1, UnicodeString V2)

+ 2 - 2
source/core/FileInfo.h

@@ -28,8 +28,8 @@ UnicodeString __fastcall GetLanguage(Word Language);
 UnicodeString __fastcall GetFileInfoString(void * FileInfo,
   TTranslation Translation, UnicodeString StringName, bool AllowEmpty = false);
 
-int __fastcall CalculateCompoundVersion(int MajorVer,
-  int MinorVer, int Release, int Build);
+int __fastcall CalculateCompoundVersion(int MajorVer, int MinorVer, int Release);
+int ZeroBuildNumber(int CompoundVersion);
 
 int __fastcall StrToCompoundVersion(UnicodeString S);
 

+ 4 - 1
source/core/Usage.cpp

@@ -6,6 +6,7 @@
 #include <CoreMain.h>
 #include <Common.h>
 #include <Usage.h>
+#include <FileInfo.h>
 //---------------------------------------------------------------------------
 #pragma package(smart_init)
 //---------------------------------------------------------------------------
@@ -170,7 +171,9 @@ void __fastcall TUsage::UpdateCurrentVersion()
 {
   TGuard Guard(FCriticalSection);
   int CompoundVersion = FConfiguration->CompoundVersion;
-  int PrevVersion = StrToIntDef(Get(L"CurrentVersion"), 0);
+  DebugAssert(ZeroBuildNumber(CompoundVersion) == CompoundVersion);
+  // ZeroBuildNumber for compatibility with versions that stored build number into the compound version
+  int PrevVersion = ZeroBuildNumber(StrToIntDef(Get(L"CurrentVersion"), 0));
   if (PrevVersion != CompoundVersion)
   {
     Set(L"Installed", StandardTimestamp());

+ 7 - 3
source/windows/WinConfiguration.cpp

@@ -1587,6 +1587,7 @@ void __fastcall TWinConfiguration::ClearTemporaryLoginData()
 void __fastcall TWinConfiguration::AddVersionToHistory()
 {
   int CurrentVersion = CompoundVersion;
+  DebugAssert(ZeroBuildNumber(CurrentVersion) == CurrentVersion);
 
   int From = 1;
   bool CurrentVersionPresent = false;
@@ -1596,10 +1597,13 @@ void __fastcall TWinConfiguration::AddVersionToHistory()
     UnicodeString VersionStr = CutToChar(VersionInfo, L',', true);
     int Version;
 
-    if (TryStrToInt(VersionStr, Version) &&
-        (Version == CurrentVersion))
+    if (TryStrToInt(VersionStr, Version))
     {
-      CurrentVersionPresent = true;
+      Version = ZeroBuildNumber(Version);
+      if (Version == CurrentVersion)
+      {
+        CurrentVersionPresent = true;
+      }
     }
   }
 

+ 2 - 1
source/windows/WinConfiguration.h

@@ -5,6 +5,7 @@
 //---------------------------------------------------------------------------
 #include "CustomWinConfiguration.h"
 #include "CustomDirView.hpp"
+#include "FileInfo.h"
 //---------------------------------------------------------------------------
 enum TEditor { edInternal, edExternal, edOpen };
 enum TGenerateUrlCodeTarget { guctUrl, guctScript, guctAssembly };
@@ -230,7 +231,7 @@ struct TUpdatesConfiguration
     return
       HaveResults &&
       (double(Period) > 0) &&
-      (Results.ForVersion == CompoundVersion);
+      (ZeroBuildNumber(Results.ForVersion) == CompoundVersion);
   }
 };
 //---------------------------------------------------------------------------