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.