From 8d0b418c99e482c2532d6cf128330ddaf76a45b9 Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Thu, 5 Dec 2024 16:04:03 +0000 Subject: [PATCH] Fix download and use model-version path --- .../java/qupath/ext/instanseg/core/InstanSegModel.java | 10 +++++++--- .../resources/qupath/ext/instanseg/ui/model-index.json | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java b/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java index 421054d..4322924 100644 --- a/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java +++ b/src/main/java/qupath/ext/instanseg/core/InstanSegModel.java @@ -84,7 +84,7 @@ public boolean isDownloaded(Path localModelPath) { // that doesn't match with the filename (although we'd prefer this didn't happen...) if (path != null && model != null && isValidModel(path)) return true; - if (!Files.exists(localModelPath.resolve(name).resolve(version))) { + if (!Files.exists(localModelPath.resolve(getFolderName(name, version)))) { // The model may have been deleted or renamed - we won't be able to load it return false; } @@ -108,7 +108,7 @@ public void download(Path localModelPath) throws IOException { var zipFile = downloadZipIfNeeded( this.modelURL, localModelPath, - name + "-" + version); + getFolderName(name, version)); this.path = unzipIfNeeded(zipFile); this.model = BioimageIoSpec.parseModel(path.toFile()); this.version = model.getVersion(); @@ -297,7 +297,7 @@ private static boolean isDownloadedAlready(Path zipFile) { private Path unzipIfNeeded(Path zipFile) throws IOException { var zipSpec = BioimageIoSpec.parseModel(zipFile); String version = zipSpec.getVersion(); - var outdir = zipFile.resolveSibling(zipSpec.getName()).resolve(version); + var outdir = zipFile.resolveSibling(getFolderName(zipSpec.getName(), version)); if (!isUnpackedAlready(outdir)) { try { unzip(zipFile, outdir); @@ -313,6 +313,10 @@ private Path unzipIfNeeded(Path zipFile) throws IOException { return outdir; } + private String getFolderName(String name, String version) { + return name + "-" + version; + } + private static boolean isUnpackedAlready(Path outdir) { return Files.exists(outdir) && isValidModel(outdir); } diff --git a/src/main/resources/qupath/ext/instanseg/ui/model-index.json b/src/main/resources/qupath/ext/instanseg/ui/model-index.json index 80abad2..bcb3547 100644 --- a/src/main/resources/qupath/ext/instanseg/ui/model-index.json +++ b/src/main/resources/qupath/ext/instanseg/ui/model-index.json @@ -1,7 +1,7 @@ [ { "name": "brightfield_nuclei", - "url": "https://github.com/instanseg/alanocallaghan/releases/download/v0.1.0/brightfield_nuclei.zip", + "url": "https://github.com/alanocallaghan/instanseg/releases/download/v0.1.0/brightfield_nuclei.zip", "version": "0.1.0", "license": "Apache-2.0" },