From 3329795aa713532bef80f556cfc089c87da685d8 Mon Sep 17 00:00:00 2001 From: lantzelot-swe Date: Wed, 2 Jun 2021 22:56:30 +0200 Subject: [PATCH] fix: export cjm files wip --- .../java/se/lantz/manager/ExportManager.java | 33 ++++++++++++++++--- src/main/java/se/lantz/util/FileManager.java | 6 ++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/main/java/se/lantz/manager/ExportManager.java b/src/main/java/se/lantz/manager/ExportManager.java index 3890340..164f714 100644 --- a/src/main/java/se/lantz/manager/ExportManager.java +++ b/src/main/java/se/lantz/manager/ExportManager.java @@ -9,6 +9,7 @@ import java.nio.file.StandardCopyOption; import java.util.Comparator; import java.util.List; +import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -202,20 +203,42 @@ public class ExportManager } for (GameDetails gameDetails : gameDetailsList) { - Path gamePath = Paths.get("./games/" + gameDetails.getGame()); + String gameName = gameDetails.getGame(); - //TODO: Unzip if needed, rename vsf files to prg according to Spannernick + Path gamePath = Paths.get("./games/" + gameName); + String extension = FilenameUtils.getExtension(gameName); + boolean zipped = false; + if (extension.equalsIgnoreCase("gz")) + { + gameName = FilenameUtils.removeExtension(gameName); + //Get next extension + extension = FilenameUtils.getExtension(gameName); + if (extension.equalsIgnoreCase("vsf")) + { + //Rename to prg so that it works in the file loader + extension = "prg"; + } + zipped = true; + } + Path targetGamePath = targetDir.toPath().resolve(FileManager.generateFileNameFromTitleForFileLoader(gameDetails.getTitle(), gameDetails.getDuplicateIndex()) + "." + extension); - Path targetGamePath = targetDir.toPath().resolve(gameDetails.getGame()); - try { if (!gameDetails.getGame().isEmpty()) { infoBuilder.append("Copying game file from "); infoBuilder.append(gamePath.toString()); + infoBuilder.append(" to "); + infoBuilder.append(targetGamePath); infoBuilder.append("\n"); - Files.copy(gamePath, targetGamePath, StandardCopyOption.REPLACE_EXISTING); + if (zipped) + { + FileManager.decompressGzip(gamePath, targetGamePath); + } + else + { + Files.copy(gamePath, targetGamePath, StandardCopyOption.REPLACE_EXISTING); + } } } catch (IOException e) diff --git a/src/main/java/se/lantz/util/FileManager.java b/src/main/java/se/lantz/util/FileManager.java index c45e0c4..7eb66d4 100644 --- a/src/main/java/se/lantz/util/FileManager.java +++ b/src/main/java/se/lantz/util/FileManager.java @@ -239,7 +239,7 @@ public class FileManager } } - public void decompressGzip(Path source, Path target) throws IOException + public static void decompressGzip(Path source, Path target) throws IOException { try (GZIPInputStream gis = new GZIPInputStream(new FileInputStream(source.toFile())); FileOutputStream fos = new FileOutputStream(target.toFile())) @@ -379,7 +379,7 @@ public class FileManager if (duplicateIndex > 0) { //Just add the duplicate index if there are several games with the same name - newNameString = newNameString + "0" + duplicateIndex; + newNameString = newNameString + "_" + duplicateIndex; } logger.debug("Game title: \"{}\" ---- New fileName: \"{}\"", title, newNameString); @@ -1278,7 +1278,7 @@ public class FileManager } return filePath != null ? filePath.toFile() : file; } - + private static FileHeader getFirstMatchingRarEntry(Archive archive) { FileHeader fh = archive.nextFileHeader();