diff --git a/vasl_templates/webapp/file_server/vasl_mod.py b/vasl_templates/webapp/file_server/vasl_mod.py index f91936d..a878f98 100644 --- a/vasl_templates/webapp/file_server/vasl_mod.py +++ b/vasl_templates/webapp/file_server/vasl_mod.py @@ -25,7 +25,9 @@ class VaslMod: # parse the VASL module file _logger.info( "Loading VASL module: %s", fname ) self.zip_file = zipfile.ZipFile( fname, "r" ) - self._parse_vmod( data_dir ) + self.vasl_version = self._parse_vmod( data_dir ) + if self.vasl_version not in SUPPORTED_VASL_MOD_VERSIONS: + _logger.warning( "Unsupported VASL version: %s", self.vasl_version ) def get_piece_image( self, gpid, side, index ): """Get the image for the specified piece.""" @@ -92,8 +94,6 @@ class VaslMod: # parse the VASL build info build_info = self.zip_file.read( "buildFile" ) doc = xml.etree.ElementTree.fromstring( build_info ) - if doc.attrib.get( "version" ) not in SUPPORTED_VASL_MOD_VERSIONS: - _logger.warning( "Unsupported VASL version: %s", doc.attrib.get("version") ) for node in doc.iter( "VASSAL.build.widget.PieceSlot" ): # load the next entry @@ -149,6 +149,8 @@ class VaslMod: gpids = ", ".join( expected_multiple_images.keys() ) _logger.warning( "Expected multiple images but didn't find them: %s", gpids ) + return doc.attrib.get( "version" ) + @staticmethod def _get_image_paths( gpid, val ): #pylint: disable=too-many-branches """Get the image path(s) for a piece.""" diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 6899c61..e65e793 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -268,6 +268,21 @@ $(document).ready( function () { showErrorMsg( "Can't get the template pack:
" + escapeHTML(errorMsg) + "
" ) ; } ) ; + // check the VASSAL/VASL versions + $.get( gCheckVassalVersionUrl, function( resp ) { + if ( resp ) + showWarningMsg( resp ) ; + } ).fail( function( xhr, status, errorMsg ) { + showErrorMsg( "Can't check the VASSAL version:
" + escapeHTML(errorMsg) + "
" ) ; + } ) ; + $.get( gCheckVaslVersionUrl, function( resp ) { + if ( resp ) + showWarningMsg( resp ) ; + } ).fail( function( xhr, status, errorMsg ) { + showErrorMsg( "Can't check the VASL version:
" + escapeHTML(errorMsg) + "
" ) ; + } ) ; + + // fixup the layout var prevHeight = [] ; $(window).resize( function() { // FUDGE! CSS grids don't seem to update their layout vertically when diff --git a/vasl_templates/webapp/templates/index.html b/vasl_templates/webapp/templates/index.html index 2acc181..092290e 100644 --- a/vasl_templates/webapp/templates/index.html +++ b/vasl_templates/webapp/templates/index.html @@ -88,6 +88,8 @@ gAppName = "{{APP_NAME}}" ; gAppVersion = "{{APP_VERSION}}" ; gImagesBaseUrl = "{{url_for('static',filename='images')}}" ; +gCheckVassalVersionUrl = "{{url_for('check_vassal_version')}}" ; +gCheckVaslVersionUrl = "{{url_for('check_vasl_version')}}" ; gGetTemplatePackUrl = "{{url_for('get_template_pack')}}" ; gGetDefaultScenarioUrl = "{{url_for('get_default_scenario')}}" ; gVehicleListingsUrl = "{{url_for('get_vehicle_listings',merge_common=1)}}" ; diff --git a/vasl_templates/webapp/vassal.py b/vasl_templates/webapp/vassal.py index 6cd2dc8..818c666 100644 --- a/vasl_templates/webapp/vassal.py +++ b/vasl_templates/webapp/vassal.py @@ -16,6 +16,8 @@ from flask import request from vasl_templates.webapp import app from vasl_templates.webapp.config.constants import BASE_DIR, IS_FROZEN +from vasl_templates.webapp.files import vasl_mod +from vasl_templates.webapp.file_server.vasl_mod import SUPPORTED_VASL_MOD_VERSIONS from vasl_templates.webapp.utils import TempFile, HtmlScreenshots, SimpleError _logger = logging.getLogger( "update_vsav" ) @@ -252,6 +254,15 @@ class VassalShim: if not os.path.isfile( self.shim_jar ): raise SimpleError( "Can't find the VASSAL shim JAR." ) + def get_version( self ): + """Get the VASSAL version.""" + # FUDGE! We can't capture the output on Windows, get the result in a temp file instead :-/ + with TempFile() as temp_file: + temp_file.close() + self._run_vassal_shim( "version", temp_file.name ) + with open( temp_file.name, "r" ) as fp: + return fp.read() + def dump_scenario( self, fname ): """Dump a scenario file.""" return self._run_vassal_shim( "dump", fname ) @@ -279,8 +290,10 @@ class VassalShim: class_path = sep.join( class_path ) args2 = [ java_path, "-classpath", class_path, "vassal_shim.Main", - args[0], self.vasl_mod + args[0] ] + if args[0] in ("dump","update"): + args2.append( self.vasl_mod ) args2.extend( args[1:] ) # figure out how long to the let the VASSAL shim run @@ -347,3 +360,25 @@ class VassalShimError( Exception ): self.retcode = retcode self.stdout = stdout self.stderr = stderr + +# --------------------------------------------------------------------- + +@app.route( "/check-vassal-version" ) +def check_vassal_version(): + """Check if we're running a supported version of VASSAL.""" + vassal_dir = app.config.get( "VASSAL_DIR" ) + if vassal_dir: + vassal_shim = VassalShim() + version = vassal_shim.get_version() + if version not in SUPPORTED_VASSAL_VERSIONS: + return "VASSAL {} is unsupported.

Things might work, but they might not...".format( version ) + return "" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +@app.route( "/check-vasl-version" ) +def check_vasl_version(): + """Check if we're running a supported version of VASL.""" + if vasl_mod and vasl_mod.vasl_version not in SUPPORTED_VASL_MOD_VERSIONS: + return "VASL {} is unsupported.

Things might work, but they might not...".format( vasl_mod.vasl_version ) + return "" diff --git a/vassal-shim/release/vassal-shim.jar b/vassal-shim/release/vassal-shim.jar index e1d4324..9c45bc3 100644 Binary files a/vassal-shim/release/vassal-shim.jar and b/vassal-shim/release/vassal-shim.jar differ diff --git a/vassal-shim/src/vassal_shim/Main.java b/vassal-shim/src/vassal_shim/Main.java index f8ba7e6..299a215 100644 --- a/vassal-shim/src/vassal_shim/Main.java +++ b/vassal-shim/src/vassal_shim/Main.java @@ -1,5 +1,10 @@ package vassal_shim ; +import java.io.BufferedWriter ; +import java.io.FileWriter ; + +import VASSAL.Info ; + import vassal_shim.VassalShim ; // -------------------------------------------------------------------- @@ -29,6 +34,15 @@ public class Main shim.updateScenario( args[3], args[4], args[5], args[6] ) ; System.exit( 0 ) ; } + else if ( cmd.equals( "version" ) ) { + checkArgs( args, 2, "the output file" ) ; + System.out.println( Info.getVersion() ) ; + // FUDGE! The Python web server can't capture output on Windows - save the result to a file as well :-/ + BufferedWriter writer = new BufferedWriter( new FileWriter( args[1] ) ) ; + writer.write( Info.getVersion() ) ; + writer.close() ; + System.exit( 0 ) ; + } else { System.out.println( "Unknown command: " + cmd ) ; System.exit( 1 ) ;