diff --git a/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFile.java b/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFile.java index 06a11cae99a..d79fb3d9566 100644 --- a/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFile.java +++ b/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFile.java @@ -87,9 +87,10 @@ private Thread newDownloadThread() { return; } - final DownloadFileProperties props = new DownloadFileProperties(); - props.setFrom(download); - DownloadFileProperties.saveForZip(download.getInstallLocation(), props); + if (download.getVersion() != null) { + new DownloadFileProperties(download.getVersion()) + .saveForZip(download.getInstallLocation()); + } downloadListener.downloadStopped(download); }); diff --git a/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFileProperties.java b/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFileProperties.java index 8d68512105e..4122bdaf6ea 100644 --- a/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFileProperties.java +++ b/game-core/src/main/java/games/strategy/engine/framework/map/download/DownloadFileProperties.java @@ -1,26 +1,29 @@ package games.strategy.engine.framework.map.download; -import games.strategy.engine.ClientContext; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.util.Optional; import java.util.Properties; import java.util.logging.Level; +import lombok.NoArgsConstructor; import lombok.extern.java.Log; -import org.triplea.java.DateTimeFormatterUtil; import org.triplea.util.Version; /** Properties file used to know which map versions have been installed. */ @Log +@NoArgsConstructor class DownloadFileProperties { static final String VERSION_PROPERTY = "map.version"; private final Properties props = new Properties(); + DownloadFileProperties(final Version mapVersion) { + props.put(VERSION_PROPERTY, mapVersion.toString()); + } + static DownloadFileProperties loadForZip(final File zipFile) { if (!fromZip(zipFile).exists()) { return new DownloadFileProperties(); @@ -35,9 +38,9 @@ static DownloadFileProperties loadForZip(final File zipFile) { return downloadFileProperties; } - static void saveForZip(final File zipFile, final DownloadFileProperties props) { + void saveForZip(final File zipFile) { try (OutputStream fos = new FileOutputStream(fromZip(zipFile))) { - props.props.store(fos, null); + props.store(fos, null); } catch (final IOException e) { log.log( Level.SEVERE, @@ -50,25 +53,7 @@ private static File fromZip(final File zipFile) { return new File(zipFile.getAbsolutePath() + ".properties"); } - Version getVersion() { - if (!props.containsKey(VERSION_PROPERTY)) { - return null; - } - return new Version(props.getProperty(VERSION_PROPERTY)); - } - - private void setVersion(final Version v) { - if (v != null) { - props.put(VERSION_PROPERTY, v.toString()); - } - } - - void setFrom(final DownloadFileDescription selected) { - setVersion(selected.getVersion()); - props.setProperty("map.url", selected.getUrl()); - props.setProperty( - "download.time", - DateTimeFormatterUtil.toDateString(LocalDateTime.now(ZoneId.systemDefault()))); - props.setProperty("engine.version", ClientContext.engineVersion().toString()); + Optional getVersion() { + return Optional.ofNullable(props.getProperty(VERSION_PROPERTY)).map(Version::new); } } diff --git a/game-core/src/main/java/games/strategy/engine/framework/map/download/FileSystemAccessStrategy.java b/game-core/src/main/java/games/strategy/engine/framework/map/download/FileSystemAccessStrategy.java index faf451564d8..3d75e9ea238 100644 --- a/game-core/src/main/java/games/strategy/engine/framework/map/download/FileSystemAccessStrategy.java +++ b/game-core/src/main/java/games/strategy/engine/framework/map/download/FileSystemAccessStrategy.java @@ -24,8 +24,7 @@ Optional getMapVersion(final String mapName) { return Optional.empty(); } - final DownloadFileProperties props = DownloadFileProperties.loadForZip(potentialFile); - return (props.getVersion() == null) ? Optional.empty() : Optional.of(props.getVersion()); + return DownloadFileProperties.loadForZip(potentialFile).getVersion(); } static void remove( diff --git a/game-core/src/main/java/games/strategy/engine/framework/map/download/MapDownloadController.java b/game-core/src/main/java/games/strategy/engine/framework/map/download/MapDownloadController.java index 1c6102d30f0..4f1d4684f74 100644 --- a/game-core/src/main/java/games/strategy/engine/framework/map/download/MapDownloadController.java +++ b/game-core/src/main/java/games/strategy/engine/framework/map/download/MapDownloadController.java @@ -96,7 +96,7 @@ private static DownloadedMaps getDownloadedMaps() { return new DownloadedMaps() { @Override public Optional getVersionForZipFile(final File mapZipFile) { - return Optional.ofNullable(DownloadFileProperties.loadForZip(mapZipFile).getVersion()); + return DownloadFileProperties.loadForZip(mapZipFile).getVersion(); } @Override