From 933f51c96b3cf9d066a3208358d1433c3a0cdf24 Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 17 Mar 2016 22:30:28 +0800 Subject: [PATCH] Add finding gallery download path --- .../com/hippo/ehviewer/spider/SpiderDen.java | 34 +++++++++++++++++-- unifile | 2 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.java b/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.java index f00077021..b607dd65b 100644 --- a/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.java +++ b/app/src/main/java/com/hippo/ehviewer/spider/SpiderDen.java @@ -30,6 +30,7 @@ import com.hippo.ehviewer.client.data.GalleryInfo; import com.hippo.ehviewer.gallery.GalleryProvider; import com.hippo.io.UniFileInputStreamPipe; import com.hippo.io.UniFileOutputStreamPipe; +import com.hippo.unifile.FilenameFilter; import com.hippo.unifile.UniFile; import com.hippo.yorozuya.FileUtils; import com.hippo.yorozuya.IOUtils; @@ -56,16 +57,45 @@ public final class SpiderDen { sCache = new SimpleDiskCache(new File(context.getCacheDir(), "image"), 160 * 1024 * 1024); } + private static class StartWithFilenameFilter implements FilenameFilter { + + private final String mPrefix; + + public StartWithFilenameFilter(String prefix) { + mPrefix = prefix; + } + + @Override + public boolean accept(UniFile dir, String filename) { + return filename.startsWith(mPrefix); + } + } + public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo) { UniFile dir = Settings.getDownloadLocation(); if (dir != null) { // Read from DB String dirname = EhDB.getDownloadDirname(galleryInfo.gid); - if (dirname == null) { + + // Find it + if (null == dirname) { + UniFile[] files = dir.listFiles(new StartWithFilenameFilter(galleryInfo.gid + "-")); + if (null != files) { + for (UniFile file : files) { + if (file.isDirectory()) { + dirname = file.getName(); + EhDB.putDownloadDirname(galleryInfo.gid, dirname); + } + } + } + } + + // Create it + if (null == dirname) { dirname = FileUtils.sanitizeFilename(galleryInfo.gid + "-" + EhUtils.getSuitableTitle(galleryInfo)); - // Put into DB EhDB.putDownloadDirname(galleryInfo.gid, dirname); } + return dir.subFile(dirname); } else { return null; diff --git a/unifile b/unifile index 7f7b67948..d04eec1da 160000 --- a/unifile +++ b/unifile @@ -1 +1 @@ -Subproject commit 7f7b67948d5e73b7f66eb8d7b7683c31184b937f +Subproject commit d04eec1daff0971e58d49eaa4f25045c006dd9d6