@@ -237,6 +237,7 @@ public void run() {
237237 return ;
238238 }
239239 if (!checkReachable (filePaths )) return ; // single friendly dialog if any remote field is unreachable
240+ if (!checkContainerMetadata (filePaths )) return ; // before the splash screen is shown
240241 final boolean threeD = viewerType != null && viewerType .toLowerCase ().contains ("bvv" );
241242 final boolean tracer = tracingEnabled ;
242243
@@ -334,8 +335,28 @@ private boolean checkReachable(final String[] filePaths) {
334335 return false ;
335336 }
336337
337- /** True if path is an existing .n5/.zarr directory, or a remote URL to one. */
338- private static boolean isN5OrZarrDir (final String path ) {
338+ /**
339+ * Reports (and returns false for) any local N5/Zarr volume without root metadata, e.g., an empty directory
340+ * (hidden files such as .DS_Store do not count). Opening such a directory fails in n5-ij, and falling back to
341+ * its interactive dataset dialog does not recover
342+ */
343+ private boolean checkContainerMetadata (final String [] filePaths ) {
344+ for (int i = 0 ; i < Math .min (2 , filePaths .length ); i ++) {
345+ final String path = filePaths [i ];
346+ if (SpimDataUtils .isRemoteUrl (path ) || !looksLikeN5OrZarrDir (path )) continue ;
347+ SNTUtils .log ("BVV: checking container metadata of " + path );
348+ final File dir = new File (path );
349+ if (!ImgUtils .hasN5ZarrMetadata (dir )) {
350+ error ("<HTML>'" + GuiUtils .Text .escapeHtml (dir .getName ()) + "' does not seem to be a valid "
351+ + "N5/Zarr container: no metadata found.<br>Is the directory empty or incomplete?" );
352+ return false ;
353+ }
354+ }
355+ return true ;
356+ }
357+
358+ /** True if path is a .n5/.zarr directory (that exists), or a remote URL to one. Does not check its content */
359+ private static boolean looksLikeN5OrZarrDir (final String path ) {
339360 if (SpimDataUtils .isRemoteUrl (path )) {
340361 final String lower = path .toLowerCase ();
341362 return lower .endsWith (".n5" ) || lower .endsWith (".n5/" ) || lower .endsWith (".zarr" ) || lower .endsWith (".zarr/" );
@@ -345,6 +366,16 @@ private static boolean isN5OrZarrDir(final String path) {
345366 return f .isDirectory () && (lower .endsWith (".n5" ) || lower .endsWith (".zarr" ));
346367 }
347368
369+ /**
370+ * True if path is a container that the interactive dataset dialog can recover (see {@link #datasetDialog}): a
371+ * remote N5/Zarr URL, or a local N5/Zarr directory with metadata. A local directory without metadata
372+ * (e.g., an empty one) is not: n5-ij cannot open it and its dialog keeps retrying
373+ */
374+ private static boolean isN5OrZarrDir (final String path ) {
375+ if (!looksLikeN5OrZarrDir (path )) return false ;
376+ return SpimDataUtils .isRemoteUrl (path ) || ImgUtils .hasN5ZarrMetadata (new File (path ));
377+ }
378+
348379 /**
349380 * Fallback UI for when {@link SpimDataUtils#resolvePathToSource(String)} cannot auto-discover a dataset in an
350381 * N5/Zarr container on its own (e.g. an ambiguous or unusually structured container). Lets the user pick a
0 commit comments