FlightGear version check

From FlightGear wiki
Jump to navigation Jump to search
This article or section contains out-of-date information

Please help improve this article by updating it. There may be additional information on the talk page.

Note  When installing/using aircraft the FlightGear version and the aircraft version must match. Otherwise strange bugs should be expected and the version-mismatch combination will not be supported by the FlightGear community.
PUI dialog showing a version conflict between the FlightGear version and aircraft version
The same dialog as processed by pui2canvas

If in doubt, people should check the about dialog or /sim/version/ in the property tree using the property browser.

For aircraft developers

This article describes content/features that may not yet be available in the latest stable version of FlightGear (2020.3).
You may need to install some extra components, use the latest development (Git) version or even rebuild FlightGear from source, possibly from a custom topic branch using special build settings: .

This feature is scheduled for FlightGear (unknown). 10}% completed

If you'd like to learn more about getting your own ideas into FlightGear, check out Implementing new features for FlightGear.

<minimum-flightgear-version>4.0.0</minimum-flightgear-version>

Minimum FlightGear version required for this aircraft, note that this is a "soft" requirement — i.e., it will not necessarily terminate FlightGear or trigger an error, but will only show a warning in the console/log file using a Nasal script that checks if the property is set.

This is mainly intended to make compatibility issues more obvious, such as end-users downloading new aircraft and wanting to use them in conjunction with an old version of FlightGear, which is causing quite a bit of workload on the support forum. We are hoping to also display this info in the about dialog.

The Saab JA-37 Viggen is a good example of using Nasal and properties to provide backwards-compatibility. See ja37.nas for the relevant code.

FGData

Note  This is currently just proof-of-concept code which will need to be refined/reviewed to be committed to FGData.
Property browser showing the /sim/version properties.

Translations

A critical error dialog should preferably support localized error messages. However, PUI XML dialogs cannot directly support translations, so we need to emulate that using property overlays.

Cquote1.png names/strings would need to be resolved by using translations as an overlay
— Hooray (Feb 23rd, 2014). Re: Multi screen configuration not working.
(powered by Instant-Cquotes)
Cquote2.png
Cquote1.png There's no C++ code handling that stuff directly - it's all PropertyList-encoded XML files in $FG_ROOT/Translations - menubar.xml/options.xml etc will typically not contain hard-coded "strings" but rather references that are resolved by loading the proper language.xml as an overlay, i.e. key=value during startup - see locale.xml and

$FG_SRC//Main:

  • locale.cxx:191: // load resource for system messages (translations for fgfs internal messages)
  • options.cxx:316: // $FG_ROOT/data/Translations/string-default.xml
  • options.cxx:2310: // There may be more than one translation line.
    — Hooray (Feb 21st, 2014). Re: Where's translation?.
    (powered by Instant-Cquotes)
Cquote2.png

The easiest way to accomplish this is using the existing format tag to display properties that can be resolved from $FG_ROOT/Translations.

For this to work, we need to create a new file and add it $FG_ROOT/Translations/locale.xml:

diff --git a/Translations/locale.xml b/Translations/locale.xml
index 6fa8f66..68d9e62 100644
--- a/Translations/locale.xml
+++ b/Translations/locale.xml
@@ -15,6 +15,7 @@
                <strings>
                        <options>Translations/en/options.xml</options>
                        <menu>Translations/en/menu.xml</menu>
+                       <dialogs include="Translations/en/dialogs.xml"/>
                        <sys>Translations/en/sys.xml</sys>
                        <atc>Translations/en/atc.xml</atc>
                </strings>



$FG_ROOT/Translations/en/dialogs.xml

<?xml version="1.0"?>

<!-- FlightGear dialog texts: English (=default) language resource -->

<PropertyList>

<version-mismatch>
  <error-version-conflict>Error: Version Conflict !</error-version-conflict>
  <flightgear-version>FlightGear Version</flightgear-version>
  <aircraft>Aircraft</aircraft>
  <aircraft-version>Aircraft Version</aircraft-version>
  <required-flightgear-version>Required FlightGear Version</required-flightgear-version>
  <incompatibility-reason>Reason for incompatibility</incompatibility-reason>
  <solution>Solution</solution>
</version-mismatch>

</PropertyList>

Dialog

$FG_ROOT/gui/dialogs/version-mismatch.xml

<?xml version="1.0"?>

<PropertyList>

<name>version-mismatch</name>
<modal>false</modal>
<layout>vbox</layout>

<text>
  <color>
    <red>1.0</red>
    <green>0.0</green>
    <blue>0.0</blue>
  </color> 
  <label>MMMMMMM</label>
  <property>/sim/intl/locale/strings/dialogs/version-mismatch/error-version-conflict</property>
  <format>%s:</format>
</text>

<canvas>
  <name>logo</name>
  <halign>right</halign>
  <pref-width>100</pref-width>
  <pref-height>100</pref-height>
  <nasal>
    <load><![CDATA[
      var my_canvas = canvas.get(cmdarg());
      var root = my_canvas.createGroup();

      var image = getprop("/sim/startup/splash-texture") or getprop("/sim/splash-texture") or "Textures/Splash1.png";

      var logo = root.createChild("image")
          .setFile(image)
          .setSize(512, 512);
    ]]></load>
  </nasal>
</canvas>
 
<group>
  <layout>vbox</layout>
  <halign>fill</halign>
  <default-padding>10</default-padding>
  <empty><stretch>true</stretch></empty>

  <group>
    <layout>hbox</layout>
    <halign>fill</halign>
    <default-padding>5</default-padding>

    <text>
      <halign>left</halign>
      <label>MMMMMMM</label>
      <property>/sim/intl/locale/strings/dialogs/version-mismatch/aircraft</property>
      <format>%s:</format>
    </text>

    <text>
      <halign>left</halign>
      <label>MMMMMMMMMMMM</label>
      <property>/sim/aircraft</property>
      <format>%s</format>
    </text>

  </group>

  <group>
    <layout>hbox</layout>
    <halign>fill</halign>
    <default-padding>5</default-padding>

    <text>    
      <halign>left</halign>
      <label>MMMMMMM</label>
      <property>/sim/intl/locale/strings/dialogs/version-mismatch/aircraft-version</property>
      <format>%s:</format>
    </text>

    <text>
      <halign>left</halign>
      <label>MMMMMMMMMMMM</label>
      <property>/sim/aircraft-version</property>
      <format>%s</format>
    </text>

  </group>
 
  <group>
    <layout>hbox</layout>
    <halign>fill</halign>
    <default-padding>5</default-padding>

    <text>
      <halign>left</halign>
      <label>MMMMMMM</label>
      <property>/sim/intl/locale/strings/dialogs/version-mismatch/required-flightgear-version</property>
      <format>%s:</format>
    </text>

    <text>
      <halign>left</halign>
      <label>MMMMMMMMMMMM</label>
      <property>/sim/aircraft-version</property>
      <format>%s</format>
    </text>

  </group>
 
  <group>
    <layout>hbox</layout>
    <halign>fill</halign>
    <default-padding>5</default-padding>

    <text>
      <halign>left</halign>
      <label>MMMMMMM</label>
      <property>/sim/intl/locale/strings/dialogs/version-mismatch/incompatibility-reason</property>
      <format>%s:</format>
    </text>

    <text>
      <halign>left</halign>
      <label>Outdated binary</label>
    </text>

  </group>
 
  <group>
    <layout>hbox</layout>
    <halign>fill</halign>
    <default-padding>5</default-padding>

    <text>
      <halign>left</halign>
      <label>MMMMMMM</label>
      <property>/sim/intl/locale/strings/dialogs/version-mismatch/solution</property>
      <format>%s:</format>
    </text>

    <text>
      <halign>left</halign>
      <label>Upgrade FlightGear or downgrade aircraft</label>
    </text>

  </group>
 
  <button>
    <legend>Exit FlightGear</legend>
    <default>true</default>
    <equal>true</equal>
    <binding>
      <command>exit</command>
    </binding>
  </button>

  <empty>
    <stretch>true</stretch>
  </empty>

</group>

</PropertyList>

Nasal module

This script ensures that the check will be executed for each loaded aircraft, without having to touch any aircraft-set.xml files, and it will also work with reset & re-init.

# $FG_ROOT/Nasal/version_check.nas
# anonymous function that will be called directly
if (getprop("/sim/version/do-compatibility-check",1))
(func() {
    # get current aircraft
    var ac = getprop("/sim/aircraft");
    var url = 'http://wiki.flightgear.org/FlightGear_Version_Check';
    var fgversion = getprop("/sim/version/flightgear");

    logprint(3, "FlightGear v" ~ fgversion);

    var acversion = getprop("/sim/minimum-flightgear-version");

    if (acversion == nil) {
        logprint(4, ac ~ "-set.xml file missing version info, see " ~ url);
        return; # version not specified 
    }

    logprint(3, "Aircraft requires FlightGear v" ~ acversion);

    # parse the version number into major/minor and patch level
    # http://wiki.flightgear.org/Nasal_library#split.28.29
    var (major, minor, patch) = split(".", acversion);
})();

If the check failed, we can directly show the corresponding dialog, while logging everything to the console/log file:

fgcommand('dialog-show', props.Node.new({'dialog-name':'version-mismatch'}) );

Why is this necessary?

Related content

Forum topics