Updating PredefinedSetups

I am having trouble getting the refresh of PredefinedSetups to work. Principally because I am reworking it to fit with the needs of my module and am obviously doing something wrong. I have an extension (.vmdx) that contains a number of PredefinedSetups and I want to batch update them every time a new version of our module (VASL) comes out.

The problem is arising in PredefinedSetups.refreshWithStatus(), and more specifically in the following lines of code:

// call the gameRefresher
gameRefresher.execute(refresherOptions, null);

// save the refreshed game into a temporary file
final File tmpFile = File.createTempFile("vassal", null);
final ZipArchive tmpZip = new ZipArchive(tmpFile);
gs.saveGameRefresh(tmpZip);
gs.updateDone();

// write the updated saved game file into the module file
final ArchiveWriter aw = mod.getArchiveWriter();
aw.removeFile(fileName);
aw.addFile(tmpZip.getFile().getPath(), fileName);
gs.closeGame();

In my code I replace " gameRefresher.execute(refresherOptions, null);" with custom code. This code is doing what it is supposed to do.

The next 3 lines of code, which create a temp file and saved the updated game to that temp file are all working. The temp file is created in my APPDATA.Local.Temp directory and after running the code I can find those files, rename them to .vsav files and open them in my module - they are updated as expected.

The problem is with the final lines of code which are to write the saved game file for the PrefdefinedSetup back to the module (or in my case the extension). This is not happening. After running the batch update, if I then open one of the PredefinedSetups, it is unchanged. My debugging suggests that " aw.addFile(tmpZip.getFile().getPath(), fileName);" is failing. I am probably using the wrong pointer to something. Below you can see typical values for PredefinedSetps going through this code.

I have the extension file as the archive in ArchiveWriter. Is this a possible error as I have to add it specially? The code " final ArchiveWriter aw = mod.getArchiveWriter();" produces null so I had to set the value of ArchiveWriter at the start of the update process. I have “tmpZip” pointing to the temporary file and I have fileName pointing to the name of the PredefinedSetup to be replaced with tmpZip.

Any thoughts about where my error might be?

When I refresh the PreDefinedSetup extension using the VASSAL.Editor functionality, it works as it is supposed to - so the files in the extension do get changed. However, the VASSAL refresh counters functionality does things to the counters that we don’t want hence the need for a customized version.

Not sure why your custom refresher replacement isn’t working.

I’m curious if it might be feasible to cater for the requirement with different refresh option. What functions do you need to suppress for VASL?

Sorry to be slow in replying. Normally I get a notice when a reply is sent. I must have just missed it.

I appreciate the help.

As to your question, in particular we have a problem with refreshing Label counters. Not counters with a label trait but counters which are used by players to display just text information. We have created a series of these and they have one, two or three lines of text capacity. Often users will pull one with a two-line capacity and use only one line, deleting the default text in the 2nd and/or 3rd lines. If we put those counters through the standard vassal counter updater, empty lines of text will be refreshed with the default text. That is a deal-breaker for us.

Since these Label counters themselves never need to be changed, I simply created a test to ignore such counters during refresh.

The other issue that we had is that it was not easy to tell which counters had not been updated by the refresh process. The output to chat is pretty thin. I have added some additional code to try and make it clearer which counters failed to refresh and why. I am still not satisfied with what I have done but it makes sorting out problems a little easier.

The end goal of all this is to be able to do batch updates of literally hundreds of .vsav files when new VASL versions are produced (we are currently on a twice-a-year cycle of mod updates).

Thanks again.

I have continued to try and parse out what is happening.

I now believe that " aw.addFile(tmpZip.getFile().getPath(), fileName);" is actually working. As you can see from this image, taken as the code loops through the list of PreDefinedSetups in the extension, new versions (highlighted in blue) of the files are being added by aw.addFile() to the .vmdx extension.

If I watch this loop, all of the files are replaced.

However, when I open up the .vmdx file after the update has finished, no changes have been made to it. I assume this means that the changes I see as the code runs are all held in memory and are not being saved to the hard drive.

There is also the issue that when the updated PredefinedScenario is put back into the -n-memory version of the .vmdx, it is being given a bizarre filename as you can see for the highlighted entry in the image. Perhaps this is preventing the save? Or maybe it is just a separate issue. The filename is being created by ZipArchive.getOutputStream() and specifically this line: File tf = makeTempFileFor(path) as you can see in the following image:

Does anything leap out as being not-what-should-be-happening-here?

I have just gone and read the help file for refreshing PredefinedSetups in Ediotor.mode. The last line is instructive: “You will need to save the module to complete the update.”

Clearly, I have not built that into my code! Sigh. I will give it a try.

1 Like

Once I actually had code that tried to save the updated extension things seemed to work a whole lot better!

Had to use "Save As . . . " and give the extension a new file name but that actually turns out to be what needs to be done anyway.

So, problem solved!

1 Like