Solved Modify Metadata programmatically?

Discussion forum about all things Team Developer 7.x
memic
Germany
Posts: 21
Joined: 07 Mar 2017, 08:51
Location: Germany

Modify Metadata programmatically?

Post by memic » 20 Jun 2017, 13:30

Hi All,

does anybody know a way to edit the Metadata programmatically when making Executables?
Image

I'm building all my Applications automatically like this: SalLoadAppAndProcessMsgs('cbi70.exe -b "' || sApp || '" "' || sExe || '"', Window_Normal, nRet)

I would like to get the value from a User Constant and change the Build Settings and update the "File Version" :D
Last edited by memic on 20 Jun 2017, 14:18, edited 1 time in total.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1083
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Modify Metadata programmatically?

Post by Dave Rabelink » 20 Jun 2017, 14:14

Include cdk.apl.

Here a small sample function:

Code: Select all

!!CB!! 278
Function: SetBuildSettings
	Description:
	Returns
	Parameters
	Static Variables
	Local variables
		FunctionalVar: uBuildSettings
			Class: cdkBuildSettings
		FunctionalVar: uApp
			Class: cdkApplication
	Actions
		If uApp.InitFromFile( "source file name here.apt")
			Call uBuildSettings.RetrieveBuildSettings( uApp )
			Call uBuildSettings.SetVersionString( CDK_COMPANYNAME, "MyCompany" )
			Call uBuildSettings.SetVersionString( CDK_PRODUCTNAME, "MyProduct" )
			Call uBuildSettings.SetVersionString( CDK_PRODUCTVERSION, "1.0.0" )
			Call uBuildSettings.SetVersionString( CDK_INTERNALNAME, "Project X" )
			Call uBuildSettings.SetVersionString( CDK_ORIGINALFILENAME, "x.exe" )
			Call uBuildSettings.SetVersionString( CDK_FILEDESCRIPTION, "This is my app" )
			Call uBuildSettings.SetVersionString( CDK_FILEVERSION, "1.0.0" )
			Call uBuildSettings.SetVersionString( CDK_LEGALCOPYRIGHT, "It is all mine" )
			Call uBuildSettings.SetVersionString( CDK_LEGALTRADEMARKS, "My mark" )
			Call uBuildSettings.UpdateBuildSettings( uApp )
			Call uApp.SaveOutlineAsText( "destination file name here.apt", FALSE )
			Call uApp.CloseApp()
(press the select all link in the code block and copy the function to clipboard and paste it into your application)
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

memic
Germany
Posts: 21
Joined: 07 Mar 2017, 08:51
Location: Germany

Modify Metadata programmatically?

Post by memic » 20 Jun 2017, 14:18

Thanks Dave!

this is exactly what I needed!

alisa.nua
Thailand
Posts: 8
Joined: 10 Aug 2017, 08:24
Location: Thailand

Modify Metadata programmatically?

Post by alisa.nua » 15 Aug 2017, 06:07

This is very useful.

How about if I want to get the metadata information from .EXE to display to users on screen (not from clicking properties) ?
Any thoughts ?

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1083
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Modify Metadata programmatically?

Post by Dave Rabelink » 15 Aug 2017, 11:05

There are some samples on this here, but are old and only working in ANSI TD versions.

http://samples.tdcommunity.net/index ... rch_mode=f

I quickly hacked one sample to be working on UNICODE TD versions and shows most of the file version strings.
(sample needs to be checked to see everything is working).

FileVersion_UNICODE.zip
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

alisa.nua
Thailand
Posts: 8
Joined: 10 Aug 2017, 08:24
Location: Thailand

Modify Metadata programmatically?

Post by alisa.nua » 16 Aug 2017, 09:32

I try to run it, it works!
Thank you lots and lots.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1083
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Modify Metadata programmatically?

Post by Dave Rabelink » 16 Aug 2017, 11:15

The FileVersion_UNICODE sample is in fact able to get version details from any executable or dll.
So not specifically for TD build applications only.

But when you need to display the version info from the running TD application (so version info of itself), you can also use the CDK to access it.

To do this you will have to initialize the CDK application object using:

Code: Select all

uApp.InitApp( SalOutlineCurrent( ) )
This will enable you to access the Build Settings for the currently running application.

So this will be:

Code: Select all

!!CB!! 278
Function: GetBuildSettingsCurrentApplication
	Description:
	Returns
	Parameters
	Static Variables
	Local variables
		FunctionalVar: uApp
			Class: cdkApplication
		FunctionalVar: uBuildSettings
			Class: cdkBuildSettings
		String: sValue
	Actions
		If uApp.InitApp( SalOutlineCurrent( ) )
			Call uBuildSettings.RetrieveBuildSettings( uApp )
			!
			! Ways to get the version info values:
					1) By function uBuildSettings.GetVersionString foir each value separately
					
					2) Use the populated array uBuildSettings.m_saVersionStringNames etc directly
			!
			! 1)
			Call uBuildSettings.GetVersionString( sValue, CDK_PRODUCTNAME )
			! etc etc
			!
			Call uApp.CloseApp()
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

efarina
France
Posts: 6
Joined: 09 Mar 2017, 07:47
Location: Paris, France

Modify Metadata programmatically?

Post by efarina » 16 Aug 2017, 14:01

Hi Dave,

Is there a way for a dynalib (APD) to manage a version number?

best regards
Eric
Best regards,

Eric Farina
Research and Development deputy Director
www.aareon.fr

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 1083
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Modify Metadata programmatically?

Post by Dave Rabelink » 16 Aug 2017, 15:19

efarina wrote:
16 Aug 2017, 14:01
Is there a way for a dynalib (APD) to manage a version number?
Interesting question...

I was curious, so did a small investigation to see

Well, first of all, the Version part (extra tab page) of the TD build settings is only visible when the build type is EXE or DLL.
When selecting APD or APL, the version tab page is not present.

This makes sense at first glance, as the version info is written to the EXE or DLL when build. The version block header is defined by Microsoft.
So, when building EXE or DLL from TD, the official version block is written when TD creates the EXE or DLL.

Then, when showing the file properties from Windows Explorer, the version info details are displayed.

A dynalib (APD) is a custom TD file format. It is not specified by Microsoft and is pure to be used in TD applications.
A dynalib does not have this default version block in the header. For Windows this is just a file, like others.

So trying to write version info to a dynalib file will fail. The version block is not there.

BUT, and that is a nice conclusion I found:

The version info which is entered in the TD build settings are retained when switching between targettype EXE and APD.
So, when the type is EXE, the version tabpage is present and you can fill in the version details.
Now, when you switch to build type APD, the version tabpage is not shown. But when switching back to EXE, the previously entered data is still there.
Even when you save the source, when the type is APD and reopen again, switching back to EXE still has the version info.

So that means that the CDK version info is available in EXE and APD.

Next I checked if it is possible to get the version info at runtime for an APD. And that actually works !!!!

BUT, and that is annoying: the function GetVersionString and SetVersionString have this check:

Code: Select all

If ((m_nTargetType = CDK_MAKERUN_DYNALIB) OR (m_nTargetType = CDK_MAKERUN_APL))
	Return FALSE
Meaning, when you call this function on a dynalib, these functions will return FALSE straight away.

BUT: and that is very fortunate, the version strings ARE fetched in the class and are present in the array of string values.
By removing the targettype check, these Get and Set functions work normally.

I checked this:

Test.exe is using MyApd.apd.
I have set different version info strings for the EXE and for the APD and I can query both the EXE and APD version strings.
Each having their own values.


So conclusion is:

No, you can not set version info on the APD file itself so that Windows can show them (file properties).
Yes, you can set version info strings by the workaround to switch to EXE Target type, fill in your strings and switch back to APD target type.
Yes, you can get and set the version strings from APD if you alter the CDK functions GetVersionString and SetVersionString and remove the target type check.
Yes, you can programmatically add version info to APD's as long as the Set function is altered.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

efarina
France
Posts: 6
Joined: 09 Mar 2017, 07:47
Location: Paris, France

Modify Metadata programmatically?

Post by efarina » 17 Aug 2017, 07:47

Thank you for this detailed explanation as always :) .
We use for dynalib a version management with the verbuild addon that we have customized.
However the technique used does not allow us without launching the application to know the version number.
It might be interesting to ask OpenText to develop a version management for dynalibs.
Best regards,

Eric Farina
Research and Development deputy Director
www.aareon.fr

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot], Nils Jänicke and 1 guest