Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Runtime/XSharp.VFP.Tests/FileVersionTests.prg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
USING System
USING System.Collections.Generic
USING System.Text
USING XUnit

BEGIN NAMESPACE XSharp.VFP.Tests
CLASS FileVersionTests
[Fact, Trait("Category", "AGetFileVersion")];
METHOD BasicSystemDllTest AS VOID
VAR cFile := typeof(System.String):Assembly:Location

DIMENSION aVer(1)
VAR nCount := AGetFileVersion(aVer, cFile)

Assert.Equal(15, (INT)nCount)
Assert.Equal(15, (INT)ALen(aVer))

// element 2: Company Name
Assert.Contains("Microsoft", (String)aVer[2])

// element 4: File version (should not be empty)
Assert.False(String.IsNullOrEmpty((String)aVer[4]))

// element 10: Product Name (Microsoft® .NET Framework or similar)
Assert.False(String.IsNullOrEmpty((String)aVer[10]))
END METHOD

[Fact, Trait("Category", "AGetFileVersion")];
METHOD FileNotFoundTest AS VOID
DIMENSION aVer(1)
VAR nCount := AGetFileVersion(aVer, "c:\non_existent_file.exe")
Assert.Equal(0, (INT)nCount)
Assert.Equal(1, (INT)ALen(aVer))
END METHOD
END CLASS
END NAMESPACE // XSharp.VFP.Tests
1 change: 1 addition & 0 deletions src/Runtime/XSharp.VFP.Tests/XSharp.VFP.Tests.xsproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<ItemGroup>
<Compile Include="AMembersTests.prg" />
<Compile Include="CopyToTests.prg" />
<Compile Include="FileVersionTests.prg" />
<Compile Include="FinancialTests.prg" />
<Compile Include="SQLStatementTests.prg" />
<Compile Include="StrConvTests.prg" />
Expand Down
43 changes: 43 additions & 0 deletions src/Runtime/XSharp.VFP/ArrayFunctions.prg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ USING System.Collections.Generic
USING System.Text
USING System.Reflection
USING System.Linq
USING System.Diagnostics
USING System.IO


INTERNAL FUNCTION FoxALen(a as ARRAY) AS DWORD
Expand Down Expand Up @@ -422,3 +424,44 @@ FUNCTION AMembers (ArrayName AS ARRAY, oObjectOrClass AS USUAL, nArrayContentsID

RETURN nRows
END FUNCTION

/// <include file="VfpRuntimeDocs.xml" path="Runtimefunctions/agetfileversion/*" />
FUNCTION AGetFileVersion (ArrayName AS ARRAY, cFileName AS STRING) AS DWORD
IF String.IsNullOrEmpty(cFileName) .OR. !File.Exists(cFileName)
RETURN 0
ENDIF

LOCAL oInfo AS FileVersionInfo
TRY
oInfo := FileVersionInfo.GetVersionInfo(cFileName)
CATCH
RETURN 0
END TRY

IF String.IsNullOrEmpty(oInfo:FileVersion)
RETURN 0
ENDIF

ASize(ArrayName, 15)

ArrayName[1] := oInfo:Comments ?? "" // 1. Comments
ArrayName[2] := oInfo:CompanyName ?? "" // 2. Company Name
ArrayName[3] := oInfo:FileDescription ?? "" // 3. File Description
ArrayName[4] := oInfo:FileVersion ?? "" // 4. File Version
ArrayName[5] := oInfo:InternalName ?? "" // 5. Internal Name
ArrayName[6] := oInfo:LegalCopyright ?? "" // 6. Legal Copyright
ArrayName[7] := oInfo:LegalTrademarks ?? "" // 7. Legal Trademarks
ArrayName[8] := oInfo:OriginalFilename ?? "" // 8. Original File Name
ArrayName[9] := oInfo:PrivateBuild ?? "" // 9. Private Build
ArrayName[10] := oInfo:ProductName ?? "" // 10. Product Name
ArrayName[11] := oInfo:ProductVersion ?? "" // 11. Product Version
ArrayName[12] := oInfo:SpecialBuild ?? "" // 12. Special Build
ArrayName[13] := "" // 13. OLE Self Registration (Not available in FileVersionInfo)
ArrayName[14] := oInfo:Language ?? "" // 14. Language
ArrayName[15] := "" // 15. Translation Code (this is complex and requires Win32 API)

// TODO(irwin): Elements 13, 15 require low-level Win32 VerQueryValue API logic
// which FileVersionInfo wraps but does not expose fully.

RETURN 15
END FUNCTION
7 changes: 0 additions & 7 deletions src/Runtime/XSharp.VFP/ToDo-A.prg
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ FUNCTION ADBObjects(ArrayName, cSetting)
THROW NotImplementedException{}
//RETURN 0


/// <summary>-- todo --</summary>
/// <include file="VFPDocs.xml" path="Runtimefunctions/agetfileversion/*" />
FUNCTION AGetFileVersion (ArrayName, cFileName)
THROW NotImplementedException{}
//RETURN 0

/// <summary>-- todo --</summary>
/// <include file="VFPDocs.xml" path="Runtimefunctions/anetresources/*" />
FUNCTION ANetResources (ArrayName, cNetworkName, nResourceType)
Expand Down