Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get exported application version / product version #372

Closed
sriedi7 opened this issue Jan 11, 2020 · 15 comments · Fixed by godotengine/godot#35555
Closed

Comments

@sriedi7
Copy link

sriedi7 commented Jan 11, 2020

Describe the project you are working on:
Irrelevant

Describe the problem or limitation you are having in your project:
You can't get the version of the app or game that you export.

Describe how this feature / enhancement will help you overcome this problem or limitation:
Make it easier to get version of my exported app.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
Irrelevant

Describe implementation detail for your proposal (in code), if possible:
In the export preset there is a version field, example:
Android: Preset > Options > Version > Name
Windows: Preset > Options > Application > Product Version
etc
So these version should be available to get from Godot API.
My suggestion would be:
OS.get_product_version()
or
OS.get_application_version()

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Right now I use the project setting to make custom string field to write my game version and get it using ProjectSettings.get_setting(). But is not so effective because I have to edit it manually whenever I update my app version in export preset.

Is there a reason why this should be core and not an add-on in the asset library?:
Because it is important.

@clayjohn
Copy link
Member

Is that not what Engine.get_version_info().build returns?

@sriedi7
Copy link
Author

sriedi7 commented Jan 11, 2020

Is that not what Engine.get_version_info().build returns?

tested just now on 3.2b5 it return 'official'

And I mean is not the engine version but version of the game you exported. The version that you type in Export Preset > Options

@Calinou
Copy link
Member

Calinou commented Jan 11, 2020

You can define a custom project setting for this purpose (e.g. application/config/version). I'm not sure if it's technically feasible to return information from export presets at run-time, since export_presets.cfg isn't included in the exported PCK.

@sriedi7
Copy link
Author

sriedi7 commented Jan 12, 2020

Maybe store the value somewhere on export?
Or read from executable?

@Calinou
Copy link
Member

Calinou commented Jan 12, 2020

Reading from the executable is something I'd consider overkill. It's also not possible on all platforms in the first place 🙂

Either way, my issue with this proposal is that not all platforms define the same metadata for each platform. If you want to access this metadata in a consistent manner cross platforms, you should define a project setting. To avoid repetition in export presets, we could do the following:

  • Add a built-in application/config/version project setting which defaults to something like 0.1.0. It can be changed by the user at any time.
  • Rename version fields to "custom version" fields in export presets. If those fields are left empty (which is the default), the value in the project settings will be used by default. This means there's now a "single source of truth" for the project version, which can be easily read in a script by using ProjectSettings.get_setting("application/config/version").

If this sounds good to you, I can look into implementing this.

@sriedi7
Copy link
Author

sriedi7 commented Jan 13, 2020

Yes, that's sounds good!

@SilvanaP
Copy link

SilvanaP commented Jun 22, 2021

From which version on is this available? It would be really nice to have access to the version code that is defined in the "export" panel in Android. I don't really want to have to set it in the ProjectSettings, additionally.

Forget what I wrote, this works like a charm on droid. Only thing to do is to add export_presets.cfg to the exported files in the export dialog:

if OS.get_name() == "Android":
    var export_config: ConfigFile = ConfigFile.new()
    var err = export_config.load("res://export_presets.cfg")
    if err == OK:
        print(export_config.get_value("preset.1.options", 'version/code'))
        print(export_config.get_value("preset.1.options", 'version/name'))
    else:
        print('[engine_root] Error open export_presets.cfgs')

@Calinou
Copy link
Member

Calinou commented Jun 22, 2021

Forget what I wrote, this works like a charm on droid. Only thing to do is to add export_presets.cfg to the exported files in the export dialog:

If you have an Android export preset, export_presets.cfg contains sensitive information like Android keystore credentials. If you add export_presets.cfg to the non-resource export filter, you will leak your release keystore credentials! Release keystores cannot be reset once your application is published on Google Play, so you need to be very careful around this.

@KoBeWi
Copy link
Member

KoBeWi commented Dec 3, 2021

Only thing to do is to add export_presets.cfg to the exported files in the export dialog:

You don't need to include the whole export presets, you can create EditorExporPlugin that extracts version information to a file that will then be included with the build:

	func _export_begin(features: PoolStringArray, is_debug: bool, path: String, flags: int):
                var version = ""
                var export_config: ConfigFile = ConfigFile.new()
                var err = export_config.load("res://export_presets.cfg")
                if err == OK:
                    version = export_config.get_value("preset.1.options", 'version/code') + export_config.get_value("preset.1.options", 'version/name')

		var script = GDScript.new()
		script.source_code = str("extends Reference\nconst VERSION = ", version, "\n")
		ResourceSaver.save("res://version.gd", script)

Then anywhere in the project you can do print(load("res://version.gd").VERSION)

@KoBeWi
Copy link
Member

KoBeWi commented Jan 11, 2022

Ok here's a plugin based on the above code:
https://github.com/KoBeWi/Godot-Auto-Export-Version
It will automatically fetch your project version from the profile whenever you export the project.

@blurrred
Copy link

blurrred commented Oct 14, 2022

Here's a little method that should give the Android app version with an Android plugin. It's pretty simple and straightforward if you're already using a custom Android plugin.

public int getVersion() throws PackageManager.NameNotFoundException {
		PackageManager manager = getActivity().getPackageManager();
		PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), PackageManager.GET_ACTIVITIES);
		return info.versionCode;
	}

@SteveSmith16384
Copy link

This issue does beg the question, what is/was the point of the File Version/Product version fields when exporting to (say) Windows? Is it actually shown or used anywhere?

@YuriSizov
Copy link
Contributor

It is available in the "Properties" dialog, if you right click on the executable. It is useful in some cases, but it's mostly useful to you as a developer, so you can attribute bugs and issues to a specific version.

@SteveSmith16384
Copy link

SteveSmith16384 commented Jan 5, 2023

When I view my exe's properties I get the Godot version, and even the Product Name says "Godot Engine", even though I've specified my own in the Export settings. (Godot v3.4.2 in case it's relevant).

@YuriSizov
Copy link
Contributor

If you've specified them but they don't get written, that's probably because you don't have rcedit, or it just doesn't work (because it's not very reliable).

But I can confirm that it should work in principle:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants