class ImageDirectoryLocator {

    public static File locateImagesDirectoryInUnpackedDistDirectory(String parentImagesPackageResourceLocation) {
        log.info("locateImagesDirectoryInUnpackedDistDirectory : parentImagesPackageResourceLocation = {}",
            parentImagesPackageResourceLocation);
        final File workingDirectory = new File(".");
        log.info("locateImagesDirectoryInUnpackedDistDirectory : workingDirectory = {}",
            workingDirectory.getAbsolutePath());
        final String workingDirectoryName;
        try {
            workingDirectoryName = workingDirectory.getCanonicalFile().getName();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        log.info("locateImagesDirectoryInUnpackedDistDirectory : workingDirectoryName = {}", workingDirectoryName);

        File imagesDirectory = new File(workingDirectory, parentImagesPackageResourceLocation);
        boolean checked = checkImageDirectory(imagesDirectory);

        if (checked) {
            log.info("locateImagesDirectoryInUnpackedDistDirectory : imagesDirectory = {}",
                imagesDirectory.getAbsolutePath());
            return imagesDirectory;
        } else {
            log.debug("locateImagesDirectoryInUnpackedDistDirectory : could not locate images directory at {}", imagesDirectory.getAbsolutePath());

            // Checking this location as a last resort - should only get this far if running the program from Gradle.
            imagesDirectory = new File(workingDirectory,
                "/gazeplay/src/main/resources/" + parentImagesPackageResourceLocation);
            checked = checkImageDirectory(imagesDirectory);
            if (checked) {
                log.info("locateImagesDirectoryInUnpackedDistDirectory : imagesDirectory = {}",
                    imagesDirectory.getAbsolutePath());
                return imagesDirectory;
            }
        }

        if (workingDirectoryName.equals("bin")) {
            imagesDirectory = new File(workingDirectory, "../" + parentImagesPackageResourceLocation);
            log.info("locateImagesDirectoryInUnpackedDistDirectory : imagesDirectory = {}",
                imagesDirectory.getAbsolutePath());
            checked = checkImageDirectory(imagesDirectory);
            if (checked) {
                return imagesDirectory;
            }
        }

        return null;
    }

}