Przeglądaj źródła

Added new GetPackedVersion, ComparePackedVersion, and SamePackedVersion to both [Code] and ISPP.

Martijn Laan 5 lat temu
rodzic
commit
fe636c4fcd

+ 7 - 3
Files/ISPPBuiltins.iss

@@ -172,10 +172,14 @@
   Warning("Function ""ParseVersion"" has been renamed. Use ""GetVersionComponents"" instead."), \
   Warning("Function ""ParseVersion"" has been renamed. Use ""GetVersionComponents"" instead."), \
   GetVersionComponents(FileName, Major, Minor, Rev, Build)
   GetVersionComponents(FileName, Major, Minor, Rev, Build)
 //
 //
-#define GetVersionNumbers(str FileName, *MS, *LS) \
+#define GetPackedVersion(str FileName, *Version) \
   Local[0] = GetVersionComponents(FileName, Local[1], Local[2], Local[3], Local[4]), \
   Local[0] = GetVersionComponents(FileName, Local[1], Local[2], Local[3], Local[4]), \
-  Local[5] = PackVersionComponents(Local[1], Local[2], Local[3], Local[4]), \
-  UnpackVersionNumbers(Local[5], MS, LS), \
+  Version = PackVersionComponents(Local[1], Local[2], Local[3], Local[4]), \
+  Local[0]
+//
+#define GetVersionNumbers(str FileName, *MS, *LS) \
+  Local[0] = GetPackedVersion(FileName, Local[1]), \
+  UnpackVersionNumbers(Local[1], MS, LS), \
   Local[0]
   Local[0]
 //
 //
 #define PackVersionNumbers(int VersionMS, int VersionLS) \
 #define PackVersionNumbers(int VersionMS, int VersionLS) \

+ 23 - 2
ISHelp/isxfunc.xml

@@ -2001,12 +2001,20 @@ end;</pre>
         <prototype>function GetVersionNumbersString(const Filename: String; var Version: String): Boolean;</prototype>
         <prototype>function GetVersionNumbersString(const Filename: String; var Version: String): Boolean;</prototype>
         <description><p>Gets the version of the specified file as a string (in "0.0.0.0" format). Returns True if successful, False otherwise.</p></description>
         <description><p>Gets the version of the specified file as a string (in "0.0.0.0" format). Returns True if successful, False otherwise.</p></description>
       </function>
       </function>
+      <function>
+        <name>GetPackedVersion</name>
+        <prototype>function GetPackedVersion(const Filename: String; var Version: Int64): Boolean;</prototype>
+        <description><p>Gets the packed version of the specified file. Returns True if successful, False otherwise.</p>
+<p>Always use <link topic="isxfunc_ComparePackedVersion">ComparePackedVersion</link> or <link topic="isxfunc_SamePackedVersion">SamePackedVersion</link> to compare packed versions.</p></description>
+        <seealso><p><link topic="isxfunc_PackVersionComponents">PackVersionComponents</link></p></seealso>
+      </function>
     </subcategory>
     </subcategory>
     <subcategory>
     <subcategory>
       <function>
       <function>
         <name>PackVersionNumbers</name>
         <name>PackVersionNumbers</name>
         <prototype>function PackVersionNumbers(const VersionMS, VersionLS: Cardinal): Int64;</prototype>
         <prototype>function PackVersionNumbers(const VersionMS, VersionLS: Cardinal): Int64;</prototype>
-        <description><p>Packs version numbers into a single value.</p></description>
+        <description><p>Packs version numbers into a single value.</p>
+<p>Always use <link topic="isxfunc_ComparePackedVersion">ComparePackedVersion</link> or <link topic="isxfunc_SamePackedVersion">SamePackedVersion</link> to compare packed versions.</p></description>
         <seealso><p><link topic="isxfunc_GetVersionNumbers">GetVersionNumbers</link><br />
         <seealso><p><link topic="isxfunc_GetVersionNumbers">GetVersionNumbers</link><br />
 <link topic="isxfunc_PackVersionComponents">PackVersionComponents</link><br />
 <link topic="isxfunc_PackVersionComponents">PackVersionComponents</link><br />
 <link topic="isxfunc_UnpackVersionNumbers">UnpackVersionNumbers</link></p></seealso>
 <link topic="isxfunc_UnpackVersionNumbers">UnpackVersionNumbers</link></p></seealso>
@@ -2014,12 +2022,25 @@ end;</pre>
       <function>
       <function>
         <name>PackVersionComponents</name>
         <name>PackVersionComponents</name>
         <prototype>function PackVersionComponents(const Major, Minor, Revision, Build: Word): Int64;</prototype>
         <prototype>function PackVersionComponents(const Major, Minor, Revision, Build: Word): Int64;</prototype>
-        <description><p>Packs individual version components into a single value.</p></description>
+        <description><p>Packs individual version components into a single value.</p>
+<p>Always use <link topic="isxfunc_ComparePackedVersion">ComparePackedVersion</link> or <link topic="isxfunc_SamePackedVersion">SamePackedVersion</link> to compare packed versions.</p></description>
         <seealso><p><link topic="isxfunc_GetVersionComponents">GetVersionComponents</link><br />
         <seealso><p><link topic="isxfunc_GetVersionComponents">GetVersionComponents</link><br />
 <link topic="isxfunc_PackVersionNumbers">PackVersionNumbers</link><br />
 <link topic="isxfunc_PackVersionNumbers">PackVersionNumbers</link><br />
 <link topic="isxfunc_UnpackVersionComponents">UnpackVersionComponents</link></p></seealso>
 <link topic="isxfunc_UnpackVersionComponents">UnpackVersionComponents</link></p></seealso>
       </function>
       </function>
     </subcategory>
     </subcategory>
+    <subcategory>
+      <function>
+        <name>ComparePackedVersion</name>
+        <prototype>function ComparePackedVersion(const Version1, Version2: Int64): Integer;</prototype>
+        <description><p>Compares Version1 to Version2. The return value is less than 0 if Version1 is less than Version2, 0 if Version1 equals Version2, or greater than 0 if Version1 is greater than Version2.</p></description>
+      </function>
+      <function>
+        <name>SamePackedVersion</name>
+        <prototype>function SamePackedVersion(const Version1, Version2: Int64): Boolean;</prototype>
+        <description><p>Compares the packed versions Version1 and Version2 and returns True if they are equal.</p></description>
+      </function>
+    </subcategory>
     <subcategory>
     <subcategory>
       <function>
       <function>
         <name>UnpackVersionNumbers</name>
         <name>UnpackVersionNumbers</name>

+ 40 - 0
Projects/ISPP/Help/ispp.xml

@@ -1352,6 +1352,22 @@ The list of options is provided at the end of this topic.</para>
 					<para>Also see <link href="GetStringFileInfo">GetStringFileInfo</link>, which can also be used to retrieve file versions using "FileVersion" or "ProductVersion" as the second parameter. The difference is that GetVersionNumbersString takes it from the fixed block of version info, unlike GetStringFileInfo which extracts string from the language specific block.</para>
 					<para>Also see <link href="GetStringFileInfo">GetStringFileInfo</link>, which can also be used to retrieve file versions using "FileVersion" or "ProductVersion" as the second parameter. The difference is that GetVersionNumbersString takes it from the fixed block of version info, unlike GetStringFileInfo which extracts string from the language specific block.</para>
 				</description>
 				</description>
 			</topic>
 			</topic>
+			<topic id="GetPackedVersion">
+				<title>GetPackedVersion</title>
+				<section title="Prototype">
+					<pre>
+						<line><b>str</b> GetPackedVersion(<b>str</b> Filename, <b>int</b> *Version)</line>
+					</pre>
+				</section>
+				<description>
+					<para>Gets the packed version of the specified file. Returns the version as a string (in "0.0.0.0" format) if successful, an empty string otherwise.</para>
+          <para>Always use <synel><link href="ComparePackedVersion">ComparePackedVersion</link></synel> or <synel><link href="SamePackedVersion">SamePackedVersion</link></synel> to compare packed versions.</para>
+          <para>Declared in &builtins;.</para>
+				</description>
+				<section title="See also">
+					<para><synel><link href="PackVersionComponents">PackVersionComponents</link></synel></para>
+				</section>
+			</topic>
 			<topic id="PackVersionNumbers">
 			<topic id="PackVersionNumbers">
 				<title>PackVersionNumbers</title>
 				<title>PackVersionNumbers</title>
 				<section title="Prototype">
 				<section title="Prototype">
@@ -1361,6 +1377,7 @@ The list of options is provided at the end of this topic.</para>
 				</section>
 				</section>
 				<description>
 				<description>
 					<para>Packs version numbers into a single value.</para>
 					<para>Packs version numbers into a single value.</para>
+          <para>Always use <synel><link href="ComparePackedVersion">ComparePackedVersion</link></synel> or <synel><link href="SamePackedVersion">SamePackedVersion</link></synel> to compare packed versions.</para>
 					<para>Declared in &builtins;.</para>
 					<para>Declared in &builtins;.</para>
 				</description>
 				</description>
 				<section title="See also">
 				<section title="See also">
@@ -1376,12 +1393,35 @@ The list of options is provided at the end of this topic.</para>
 				</section>
 				</section>
 				<description>
 				<description>
 					<para>Packs individual version components into a single value.</para>
 					<para>Packs individual version components into a single value.</para>
+          <para>Always use <synel><link href="ComparePackedVersion">ComparePackedVersion</link></synel> or <synel><link href="SamePackedVersion">SamePackedVersion</link></synel> to compare packed versions.</para>
 					<para>Declared in &builtins;.</para>
 					<para>Declared in &builtins;.</para>
 				</description>
 				</description>
 				<section title="See also">
 				<section title="See also">
 					<para><synel><link href="GetVersionComponents">GetVersionComponents</link></synel>, <synel><link href="PackVersionNumbers">PackVersionNumbers</link></synel>, <synel><link href="UnpackVersionComponents">UnpackVersionComponents</link></synel></para>
 					<para><synel><link href="GetVersionComponents">GetVersionComponents</link></synel>, <synel><link href="PackVersionNumbers">PackVersionNumbers</link></synel>, <synel><link href="UnpackVersionComponents">UnpackVersionComponents</link></synel></para>
 				</section>
 				</section>
 			</topic>
 			</topic>
+			<topic id="ComparePackedVersion">
+				<title>ComparePackedVersion</title>
+				<section title="Prototype">
+					<pre>
+						<line><b>int</b> ComparePackedVersion(<b>int</b> Version1, <b>int</b> Version2)</line>
+					</pre>
+				</section>
+				<description>
+					<para>Compares Version1 to Version2. The return value is less than 0 if Version1 is less than Version2, 0 if Version1 equals Version2, or greater than 0 if Version1 is greater than Version2.</para>
+				</description>
+			</topic>
+			<topic id="SamePackedVersion">
+				<title>SamePackedVersion</title>
+				<section title="Prototype">
+					<pre>
+						<line><b>int</b> SamePackedVersion(<b>int</b> Version1, <b>int</b> Version2)</line>
+					</pre>
+				</section>
+				<description>
+					<para>Compares the packed versions Version1 and Version2 and returns True if they are equal.</para>
+				</description>
+			</topic>
 			<topic id="UnpackVersionNumbers">
 			<topic id="UnpackVersionNumbers">
 				<title>UnpackVersionNumbers</title>
 				<title>UnpackVersionNumbers</title>
 				<section title="Prototype">
 				<section title="Prototype">

+ 42 - 3
Projects/ISPP/IsppFuncs.pas

@@ -9,14 +9,16 @@ interface
 
 
 {$I ..\Version.inc}
 {$I ..\Version.inc}
 
 
-uses Windows, Classes, IsppVarUtils, IsppIntf, IsppTranslate, IsppParser;
+uses
+  Windows, Classes, IsppVarUtils, IsppIntf, IsppTranslate, IsppParser;
 
 
 procedure Register(Preproc: TPreprocessor);
 procedure Register(Preproc: TPreprocessor);
 
 
 implementation
 implementation
 
 
-uses SysUtils, IniFiles, Registry, IsppConsts, IsppBase, IsppIdentMan,
-  IsppSessions, DateUtils, FileClass, MD5, SHA1, PathFunc, CmnFunc2;
+uses
+  SysUtils, IniFiles, Registry, IsppConsts, IsppBase, IsppIdentMan,
+  IsppSessions, DateUtils, FileClass, MD5, SHA1, PathFunc, CmnFunc2, Int64Em;
   
   
 var
 var
   IsWin64: Boolean;
   IsWin64: Boolean;
@@ -936,6 +938,41 @@ begin
   end;
   end;
 end;
 end;
 
 
+function ComparePackedVersionFunc(Ext: Longint; const Params: IIsppFuncParams;
+  const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
+begin
+  if CheckParams(Params, [evInt, evInt], 2, Result) then
+  try
+    with IInternalFuncParams(Params) do
+      MakeInt(ResPtr^, Compare64(Integer64(Get(0).AsInt), Integer64(Get(1).AsInt)));
+  except
+    on E: Exception do
+    begin
+      FuncResult.Error(PChar(E.Message));
+      Result.Error := ISPPFUNC_FAIL
+    end;
+  end;
+end;
+
+function SamePackedVersionFunc(Ext: Longint; const Params: IIsppFuncParams;
+  const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
+begin
+  if CheckParams(Params, [evInt, evInt], 2, Result) then
+  try
+    with IInternalFuncParams(Params) do
+      if Compare64(Integer64(Get(0).AsInt), Integer64(Get(1).AsInt)) = 0 then
+        MakeInt(ResPtr^, 1)
+      else
+        MakeInt(ResPtr^, 0)
+  except
+    on E: Exception do
+    begin
+      FuncResult.Error(PChar(E.Message));
+      Result.Error := ISPPFUNC_FAIL
+    end;
+  end;
+end;
+
 {str GetStringFileInfo(str FileName, str StringName, int Lang)}
 {str GetStringFileInfo(str FileName, str StringName, int Lang)}
 function GetFileVersionInfoItem(Ext: Longint; const Params: IIsppFuncParams;
 function GetFileVersionInfoItem(Ext: Longint; const Params: IIsppFuncParams;
   const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
   const FuncResult: IIsppFuncResult): TIsppFuncResult; stdcall;
@@ -1828,6 +1865,8 @@ begin
     RegisterFunction('Len', LenFunc, -1);
     RegisterFunction('Len', LenFunc, -1);
     RegisterFunction('GetVersionNumbersString', GetVersionNumbersStringFunc, -1);
     RegisterFunction('GetVersionNumbersString', GetVersionNumbersStringFunc, -1);
     RegisterFunction('GetFileVersion', GetFileVersionFunc, -1);
     RegisterFunction('GetFileVersion', GetFileVersionFunc, -1);
+    RegisterFunction('ComparePackedVersion', ComparePackedVersionFunc, -1);
+    RegisterFunction('SamePackedVersion', SamePackedVersionFunc, -1);
     RegisterFunction('GetStringFileInfo', GetFileVersionInfoItem, -1);
     RegisterFunction('GetStringFileInfo', GetFileVersionInfoItem, -1);
     RegisterFunction('SaveToFile', IsppFuncs.SaveToFile, -1);
     RegisterFunction('SaveToFile', IsppFuncs.SaveToFile, -1);
     RegisterFunction('Find', FindLine, -1);
     RegisterFunction('Find', FindLine, -1);

+ 4 - 1
Projects/ScriptFunc.pas

@@ -296,13 +296,16 @@ const
   );
   );
 
 
   { VerInfo }
   { VerInfo }
-  VerInfoTable: array [0..7] of AnsiString =
+  VerInfoTable: array [0..10] of AnsiString =
   (
   (
     'function GetVersionNumbers(const Filename: String; var VersionMS, VersionLS: Cardinal): Boolean;',
     'function GetVersionNumbers(const Filename: String; var VersionMS, VersionLS: Cardinal): Boolean;',
     'function GetVersionComponents(const Filename: String; var Major, Minor, Revision, Build: Word): Boolean;',
     'function GetVersionComponents(const Filename: String; var Major, Minor, Revision, Build: Word): Boolean;',
     'function GetVersionNumbersString(const Filename: String; var Version: String): Boolean;',
     'function GetVersionNumbersString(const Filename: String; var Version: String): Boolean;',
+    'function GetPackedVersion(const Filename: String; var Version: Int64): Boolean;',
     'function PackVersionNumbers(const VersionMS, VersionLS: Cardinal): Int64;',
     'function PackVersionNumbers(const VersionMS, VersionLS: Cardinal): Int64;',
     'function PackVersionComponents(const Major, Minor, Revision, Build: Word): Int64;',
     'function PackVersionComponents(const Major, Minor, Revision, Build: Word): Int64;',
+    'function ComparePackedVersion(const Version1, Version2: Int64): Integer;',
+    'function SamePackedVersion(const Version1, Version2: Int64): Boolean;',
     'procedure UnpackVersionNumbers(const Version: Int64; var VersionMS, VersionLS: Cardinal);',
     'procedure UnpackVersionNumbers(const Version: Int64; var VersionMS, VersionLS: Cardinal);',
     'procedure UnpackVersionComponents(const Version: Int64; var Major, Minor, Revision, Build: Word);',
     'procedure UnpackVersionComponents(const Version: Int64; var Major, Minor, Revision, Build: Word);',
     'function VersionToStr(const Version: Int64): String;'
     'function VersionToStr(const Version: Int64): String;'

+ 10 - 0
Projects/ScriptFunc_R.pas

@@ -1526,12 +1526,22 @@ begin
       Stack.SetBool(PStart, True);
       Stack.SetBool(PStart, True);
     end else
     end else
       Stack.SetBool(PStart, False);
       Stack.SetBool(PStart, False);
+  end else if Proc.Name = 'GETPACKEDVERSION' then begin
+    if GetVersionNumbersRedir(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), VersionNumbers) then begin
+      Stack.SetInt64(PStart-2, (Int64(VersionNumbers.MS) shl 32) or VersionNumbers.LS);
+      Stack.SetBool(PStart, True);
+    end else
+      Stack.SetBool(PStart, False);
   end else if Proc.Name = 'PACKVERSIONNUMBERS' then begin
   end else if Proc.Name = 'PACKVERSIONNUMBERS' then begin
     Stack.SetInt64(PStart, Int64((UInt64(Stack.GetUInt(PStart-1)) shl 32) or Stack.GetUInt(PStart-2)));
     Stack.SetInt64(PStart, Int64((UInt64(Stack.GetUInt(PStart-1)) shl 32) or Stack.GetUInt(PStart-2)));
   end else if Proc.Name = 'PACKVERSIONCOMPONENTS' then begin
   end else if Proc.Name = 'PACKVERSIONCOMPONENTS' then begin
     VersionNumbers.MS := (Stack.GetUInt(PStart-1) shl 16) or (Stack.GetUInt(PStart-2) and $FFFF);
     VersionNumbers.MS := (Stack.GetUInt(PStart-1) shl 16) or (Stack.GetUInt(PStart-2) and $FFFF);
     VersionNumbers.LS := (Stack.GetUInt(PStart-3) shl 16) or (Stack.GetUInt(PStart-4) and $FFFF);
     VersionNumbers.LS := (Stack.GetUInt(PStart-3) shl 16) or (Stack.GetUInt(PStart-4) and $FFFF);
     Stack.SetInt64(PStart, Int64((UInt64(VersionNumbers.MS) shl 32) or VersionNumbers.LS));
     Stack.SetInt64(PStart, Int64((UInt64(VersionNumbers.MS) shl 32) or VersionNumbers.LS));
+  end else if Proc.Name = 'COMPAREPACKEDVERSION' then begin
+    Stack.SetInt(PStart, Compare64(Integer64(Stack.GetInt64(PStart-1)), Integer64(Stack.GetInt64(PStart-2))));
+  end else if Proc.Name = 'SAMEPACKEDVERSION' then begin
+    Stack.SetBool(PStart, Compare64(Integer64(Stack.GetInt64(PStart-1)), Integer64(Stack.GetInt64(PStart-2))) = 0);
   end else if Proc.Name = 'UNPACKVERSIONNUMBERS' then begin
   end else if Proc.Name = 'UNPACKVERSIONNUMBERS' then begin
     VersionNumbers.MS := UInt64(Stack.GetInt64(PStart)) shr 32;
     VersionNumbers.MS := UInt64(Stack.GetInt64(PStart)) shr 32;
     VersionNumbers.LS := UInt64(Stack.GetInt64(PStart)) and $FFFFFFFF;
     VersionNumbers.LS := UInt64(Stack.GetInt64(PStart)) and $FFFFFFFF;

+ 2 - 2
whatsnew.htm

@@ -69,13 +69,13 @@ For conditions of distribution and use, see <a href="https://jrsoftware.org/file
 <ul>
 <ul>
   <li>ISPP's <tt>int</tt> type is now a signed 64-bit integer type.</tt>
   <li>ISPP's <tt>int</tt> type is now a signed 64-bit integer type.</tt>
   <li>Support function <tt>FileSize</tt> now supports 64-bit file sizes.</li>
   <li>Support function <tt>FileSize</tt> now supports 64-bit file sizes.</li>
-  <li>Added new <tt>PackVersionNumbers</tt>, <tt>PackVersionComponents</tt>, <tt>UnpackVersionNumbers</tt>, <tt>UnpackVersionComponents</tt>, and <tt>VersionToStr</tt> support functions.</li>
+  <li>Added new <tt>GetPackedVersion</tt>, <tt>PackVersionNumbers</tt>, <tt>PackVersionComponents</tt>, <tt>ComparePackedVersion</tt>, <tt>SamePackedVersion</tt>, <tt>UnpackVersionNumbers</tt>, <tt>UnpackVersionComponents</tt>, and <tt>VersionToStr</tt> support functions.</li>
   <li>Support function <tt>GetFileVersion</tt> and <tt>ParseVersion</tt> have been renamed to <tt>GetVersionNumbersString</tt> and <tt>GetVersionComponents</tt> respectively. The old names are still supported, but it is recommended to update your scripts to the new names and the compiler will issue a warning if you don't.</li>
   <li>Support function <tt>GetFileVersion</tt> and <tt>ParseVersion</tt> have been renamed to <tt>GetVersionNumbersString</tt> and <tt>GetVersionComponents</tt> respectively. The old names are still supported, but it is recommended to update your scripts to the new names and the compiler will issue a warning if you don't.</li>
 </ul>
 </ul>
 <p>Similar Pascal Scripting changes have been done for [Code]:</p>
 <p>Similar Pascal Scripting changes have been done for [Code]:</p>
 <ul>
 <ul>
   <li>Added new <tt>FileSize64</tt> support function.</li>
   <li>Added new <tt>FileSize64</tt> support function.</li>
-  <li>Added new <tt>PackVersionNumbers</tt>, <tt>PackVersionComponents</tt>, <tt>UnpackVersionNumbers</tt>, <tt>UnpackVersionComponents</tt>, <tt>GetVersionComponents</tt>, and <tt>VersionToStr</tt> support functions. This makes ISPP and [Code] support the same list of version related functions.</li>
+  <li>Added new <tt>GetPackedVersion</tt>, <tt>PackVersionNumbers</tt>, <tt>PackVersionComponents</tt>, <tt>ComparePackedVersion</tt>, <tt>SamePackedVersion</tt>, <tt>UnpackVersionNumbers</tt>, <tt>UnpackVersionComponents</tt>, <tt>GetVersionComponents</tt>, and <tt>VersionToStr</tt> support functions. This makes ISPP and [Code] support the same list of version related functions.</li>
 </ul>
 </ul>
 <p><span class="head2">Other changes</span></p>
 <p><span class="head2">Other changes</span></p>
 <ul>
 <ul>