- private File getExpectedDir(String type) {
- String source = type.replaceAll("[^a-zA-Z0-9._+-]", "_");
- return new File(baseDir, source);
+ private File getExpectedDir(String source) {
+ String sanitizedSource = source.replaceAll("[^a-zA-Z0-9._+/-]", "_");
+
+ while (sanitizedSource.startsWith("/")
+ || sanitizedSource.startsWith("_")) {
+ if (sanitizedSource.length() > 1) {
+ sanitizedSource = sanitizedSource.substring(1);
+ } else {
+ sanitizedSource = "";
+ }
+ }
+
+ sanitizedSource = sanitizedSource.replace("/", File.separator);
+
+ if (sanitizedSource.isEmpty()) {
+ sanitizedSource = "_EMPTY";
+ }
+
+ return new File(baseDir, sanitizedSource);
+ }
+
+ /**
+ * Return the full path to the file to use for the custom cover of this
+ * author.
+ * <p>
+ * One or more of the parent directories <b>MAY</b> not exist.
+ *
+ * @param author
+ * the author
+ *
+ * @return the custom cover file
+ */
+ private File getAuthorCoverFile(String author) {
+ File aDir = new File(baseDir, "_AUTHORS");
+ String hash = HashUtils.md5(author);
+ String ext = Instance.getInstance().getConfig()
+ .getString(Config.FILE_FORMAT_IMAGE_FORMAT_COVER);
+ return new File(aDir, hash + "." + ext.toLowerCase());