From b405c92a6fd85b8d5c3b34c7e63f6ccb04066a0a Mon Sep 17 00:00:00 2001 From: seven332 Date: Thu, 23 Oct 2014 15:02:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=AE=E6=94=B9=E8=BF=87?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E7=9A=84=E8=B5=84=E6=BA=90=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=9A=84=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/hippo/ehviewer/util/EhUtils.java | 61 +++++++++--------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/src/com/hippo/ehviewer/util/EhUtils.java b/src/com/hippo/ehviewer/util/EhUtils.java index 4284917e1..315b760ae 100644 --- a/src/com/hippo/ehviewer/util/EhUtils.java +++ b/src/com/hippo/ehviewer/util/EhUtils.java @@ -24,34 +24,16 @@ public final class EhUtils { public static final String EH_DOWNLOAD_FILENAME = ".ehviewer"; - private static final int[] CATEGORY_VALUES = { - ListUrls.MISC, - ListUrls.DOUJINSHI, - ListUrls.MANGA, - ListUrls.ARTIST_CG, - ListUrls.GAME_CG, - ListUrls.IMAGE_SET, - ListUrls.COSPLAY, - ListUrls.ASIAN_PORN, - ListUrls.NON_H, - ListUrls.WESTERN, - ListUrls.UNKNOWN - }; + private static final int[] CATEGORY_VALUES = { ListUrls.MISC, ListUrls.DOUJINSHI, ListUrls.MANGA, + ListUrls.ARTIST_CG, ListUrls.GAME_CG, ListUrls.IMAGE_SET, ListUrls.COSPLAY, ListUrls.ASIAN_PORN, + ListUrls.NON_H, ListUrls.WESTERN, ListUrls.UNKNOWN }; // TODO How about "Private" - private static final String[][] CATEGORY_STRINGS = { - new String[]{"misc"}, - new String[]{"doujinshi"}, - new String[]{"manga"}, - new String[]{"artistcg", "Artist CG Sets"}, - new String[]{"gamecg", "Game CG Sets"}, - new String[]{"imageset", "Image Sets"}, - new String[]{"cosplay"}, - new String[]{"asianporn", "Asian Porn"}, - new String[]{"non-h"}, - new String[]{"western"}, - new String[]{"unknown"} - }; + private static final String[][] CATEGORY_STRINGS = { new String[] { "misc" }, new String[] { "doujinshi" }, + new String[] { "manga" }, new String[] { "artistcg", "Artist CG Sets" }, + new String[] { "gamecg", "Game CG Sets" }, new String[] { "imageset", "Image Sets" }, + new String[] { "cosplay" }, new String[] { "asianporn", "Asian Porn" }, new String[] { "non-h" }, + new String[] { "western" }, new String[] { "unknown" } }; public static int getCategory(String type) { int i; @@ -74,9 +56,8 @@ public final class EhUtils { } /** - * Get gallery for read and download - * Gid is constant, but title may be changed - * 非要标题,记一下 gid 不行么 + * Get gallery for read and download Gid is constant, but title may be + * changed 非要标题,记一下 gid 不行么 * * @param gid * @param title @@ -85,8 +66,7 @@ public final class EhUtils { public static File getGalleryDir(int gid, String title) { File downloadDir = new File(Config.getDownloadPath()); - File gDir = new File(downloadDir, - Utils.standardizeFilename(Integer.toString(gid))); + File gDir = new File(downloadDir, Utils.standardizeFilename(Integer.toString(gid))); File defaultDir = generateGalleryDir(gid, title); if (gDir.exists()) { @@ -95,16 +75,22 @@ public final class EhUtils { else return gDir; } else { + // TODO I need a better way or only call it in non-UI thread + String[] fileList = downloadDir.list(); + if (fileList != null) { + for (String str : fileList) { + // For title changed + if (str.startsWith(gid + "-") && (gDir = new File(downloadDir, str)) != null && gDir.isDirectory()) + return gDir; + } + } + return defaultDir; } - - // TODO check a dir start with the gid, but it may take a long time - // Create a map to record all ? } public static File generateGalleryDir(int gid, String title) { - return new File(Config.getDownloadPath(), - Utils.standardizeFilename(gid + "-" + title)); + return new File(Config.getDownloadPath(), Utils.standardizeFilename(gid + "-" + title)); } /** @@ -118,10 +104,9 @@ public final class EhUtils { return String.format("%08d.%s", index + 1, extension); } - public static String[] getPossibleImageFilenames(int index) { String prefix = String.format("%08d.", index + 1); - return new String[]{prefix + "jpg", prefix + "jpeg", prefix + "png", prefix + "gif"}; + return new String[] { prefix + "jpg", prefix + "jpeg", prefix + "png", prefix + "gif" }; } }