// package private for tests
  List<FlashTarget> getFlashTargets(File file, String... targetNames) throws IOException {
    List<FlashTarget> filesToFlash = new ArrayList<FlashTarget>();

    if (!file.exists()) {
      mLogger.error(file + " not found.");
      return filesToFlash;
    }

    // check if supplied targetNames are known TargetTypes, if so, continue, else return

    if (isZipFile(file)) {
      // unzip
      unzip(file);

      // read manifest.json
      File basePath =
          new File(file.getAbsoluteFile().getParent() + "/" + getFileNameWithoutExtension(file));
      File manifestFile = new File(basePath.getAbsolutePath(), MANIFEST_FILENAME);
      if (basePath.exists() && manifestFile.exists()) {
        Manifest mf = null;
        try {
          mf = readManifest(manifestFile);
        } catch (IOException ioe) {
          mLogger.error("Error while trying to read manifest file:\n" + ioe.getMessage());
        }
        // TODO: improve error handling
        if (mf == null) {
          return filesToFlash;
        }
        Set<String> files = mf.getFiles().keySet();

        // iterate over file names in manifest.json
        for (String fileName : files) {
          FirmwareDetails firmwareDetails = mf.getFiles().get(fileName);
          Target t =
              this.mCload.getTargets().get(TargetTypes.fromString(firmwareDetails.getTarget()));
          if (t != null) {
            // use path to extracted file
            // File flashFile = new File(file.getParent() + "/" + file.getName() + "/" + fileName);
            File flashFile = new File(basePath.getAbsolutePath(), fileName);
            FlashTarget ft =
                new FlashTarget(
                    t,
                    readFile(flashFile),
                    firmwareDetails.getType(),
                    t.getStartPage()); // TODO: does startPage HAVE to be an extra argument!?
            // (it's already included in Target)
            // add flash target
            // if no target names are specified, flash everything
            if (targetNames == null || targetNames.length == 0 || targetNames[0].isEmpty()) {
              // deal with different platforms (CF1, CF2)
              // TODO: simplify
              if (t.getFlashPages() == 128
                  && "cf1".equalsIgnoreCase(firmwareDetails.getPlatform())) { // 128 = CF 1.0
                filesToFlash.add(ft);
                // deal with STM32 and NRF51 for CF2 (different no of flash pages)
              } else if ((t.getFlashPages() == 1024 || t.getFlashPages() == 232)
                  && "cf2".equalsIgnoreCase(firmwareDetails.getPlatform())) { // 1024 = CF 2.0
                filesToFlash.add(ft);
              }
            } else {
              // else flash only files whose targets are contained in targetNames
              if (Arrays.asList(targetNames).contains(firmwareDetails.getTarget())) {
                filesToFlash.add(ft);
              }
            }
          } else {
            mLogger.error("No target found for " + firmwareDetails.getTarget());
          }
        }
      } else {
        mLogger.error("Zip file " + file.getName() + " does not include a " + MANIFEST_FILENAME);
      }
    } else { // File is not a Zip file
      // add single flash target
      if (targetNames == null || targetNames.length != 1) {
        mLogger.error("Not an archive, must supply ONE target to flash.");
      } else {
        for (String tn : targetNames) {
          if (!tn.isEmpty()) {
            Target target = this.mCload.getTargets().get(TargetTypes.fromString(tn));
            FlashTarget ft =
                new FlashTarget(target, readFile(file), "binary", target.getStartPage());
            filesToFlash.add(ft);
          }
        }
      }
    }
    return filesToFlash;
  }