Skip to content

Commit

Permalink
Copy models always to temp
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickackermann committed Nov 19, 2024
1 parent 6f3f161 commit 08de82a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,21 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio

// prepare path to models from resources
var resourceUri = ObjectMapper.class.getResource(MODELS_RESOURCE).toURI();
tempDir = Files.createTempDirectory("lk2dxf_");
iliModelsPath = tempDir.toString().replace("\\", "/");
if (resourceUri.getScheme().equals("jar")) {
tempDir = Files.createTempDirectory("lk2dxf_");
try (var fs = FileSystems.newFileSystem(resourceUri, Collections.emptyMap());
var sourceFiles = Files.walk(fs.getPath(MODELS_RESOURCE)).filter(Files::isRegularFile)) {
for (var source : sourceFiles.toArray(Path[]::new)) {
Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString()));
}
}
iliModelsPath = tempDir.toString().replace("\\", "/");
} else {
iliModelsPath = resourceUri.getPath().replaceFirst("^/", "");
try (var sourceFiles = Files.walk(Paths.get(resourceUri))) {
for (var source : sourceFiles.toArray(Path[]::new)) {
Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString()));
}
}
}

try {
Expand All @@ -327,10 +331,8 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio
var ili2cConfig = modelManager.getConfig(requiredModels, 0.0);
return Ili2c.runCompiler(ili2cConfig);
} finally {
if (tempDir != null) {
try (var stream = Files.walk(tempDir)) {
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
try (var stream = Files.walk(tempDir)) {
stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
}
}
Expand Down

0 comments on commit 08de82a

Please sign in to comment.