fixup! Create download dir only in download mode
This commit is contained in:
1 parent
83d27e18cb
commit
5f6da284fb
5 files changed
+31
-41
No files matched your search
@@ -588,11 +588,11 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
galleryInfo.uploader = downloadInfo.uploader;
|
||||
galleryInfo.rating = downloadInfo.rating;
|
||||
|
||||
UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo, false);
|
||||
UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo.gid);
|
||||
if (downloadDir == null) {
|
||||
continue;
|
||||
}
|
||||
UniFile file = downloadDir.findFile(".ehviewer");
|
||||
UniFile file = downloadDir.findFile(SpiderQueen.SPIDER_INFO_FILENAME);
|
||||
if (file == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,14 @@ public final class SpiderDen {
|
||||
private static SimpleDiskCache sCache;
|
||||
@Nullable
|
||||
private UniFile mDownloadDir;
|
||||
private final GalleryInfo mGalleryInfo;
|
||||
private final long mGid;
|
||||
private volatile int mMode = SpiderQueen.MODE_READ;
|
||||
|
||||
public SpiderDen(GalleryInfo galleryInfo) {
|
||||
mGalleryInfo = galleryInfo;
|
||||
mGid = galleryInfo.gid;
|
||||
mDownloadDir = getGalleryDownloadDir(galleryInfo.gid);
|
||||
}
|
||||
|
||||
public static void initialize(Context context) {
|
||||
@@ -63,24 +66,15 @@ public final class SpiderDen {
|
||||
MathUtils.clamp(Settings.getReadCacheSize(), 40, 1280) * 1024 * 1024);
|
||||
}
|
||||
|
||||
public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo, boolean create) {
|
||||
public static UniFile getGalleryDownloadDir(long gid) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (dir != null) {
|
||||
// Read from DB
|
||||
String dirname = EhDB.getDownloadDirname(galleryInfo.gid);
|
||||
if (null != dirname) {
|
||||
// Some dirname may be invalid in some version
|
||||
dirname = FileUtils.sanitizeFilename(dirname);
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
|
||||
// Create it
|
||||
if (null == dirname && create) {
|
||||
dirname = FileUtils.sanitizeFilename(galleryInfo.gid + "-" + EhUtils.getSuitableTitle(galleryInfo));
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
|
||||
return null != dirname ? dir.subFile(dirname) : null;
|
||||
// Read from DB
|
||||
String dirname = EhDB.getDownloadDirname(gid);
|
||||
if (dir != null && dirname != null) {
|
||||
// Some dirname may be invalid in some version
|
||||
dirname = FileUtils.sanitizeFilename(dirname);
|
||||
EhDB.putDownloadDirname(gid, dirname);
|
||||
return dir.subFile(dirname);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -114,6 +108,11 @@ public final class SpiderDen {
|
||||
}
|
||||
|
||||
private boolean ensureDownloadDir() {
|
||||
if (mDownloadDir == null) {
|
||||
var dirname = FileUtils.sanitizeFilename(mGid + "-" + EhUtils.getSuitableTitle(mGalleryInfo));
|
||||
EhDB.putDownloadDirname(mGid, dirname);
|
||||
mDownloadDir = getGalleryDownloadDir(mGid);
|
||||
}
|
||||
return mDownloadDir != null && mDownloadDir.ensureDir();
|
||||
}
|
||||
|
||||
@@ -127,13 +126,12 @@ public final class SpiderDen {
|
||||
|
||||
@Nullable
|
||||
public UniFile getDownloadDir() {
|
||||
if (mDownloadDir == null) {
|
||||
mDownloadDir = getGalleryDownloadDir(mGid);
|
||||
}
|
||||
return mDownloadDir != null && mDownloadDir.isDirectory() ? mDownloadDir : null;
|
||||
}
|
||||
|
||||
public void setDownloadDir(UniFile dir) {
|
||||
mDownloadDir = dir;
|
||||
}
|
||||
|
||||
private boolean containInCache(int index) {
|
||||
if (sCache == null) {
|
||||
return false;
|
||||
@@ -344,17 +342,4 @@ public final class SpiderDen {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -318,9 +318,6 @@ public final class SpiderQueen implements Runnable {
|
||||
mode = MODE_READ;
|
||||
}
|
||||
|
||||
if (mSpiderDen.getDownloadDir() == null) {
|
||||
mSpiderDen.setDownloadDir(SpiderDen.getGalleryDownloadDir(mGalleryInfo, mode == MODE_DOWNLOAD));
|
||||
}
|
||||
mSpiderDen.setMode(mode);
|
||||
|
||||
// Update download page
|
||||
@@ -367,6 +364,7 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
updateMode();
|
||||
writeSpiderInfoToLocal();
|
||||
}
|
||||
|
||||
private void clearMode(@Mode int mode) {
|
||||
@@ -842,6 +840,13 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSpiderInfoToLocal() {
|
||||
var spiderInfo = mSpiderInfo.get();
|
||||
if (spiderInfo != null) {
|
||||
writeSpiderInfoToLocal(spiderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void writeSpiderInfoToLocal(@NonNull SpiderInfo spiderInfo) {
|
||||
// Write to download dir
|
||||
UniFile downloadDir = mSpiderDen.getDownloadDir();
|
||||
|
||||
@@ -995,7 +995,7 @@ public class DownloadsScene extends BaseToolbarScene
|
||||
int i = 0;
|
||||
for (DownloadInfo info : mDownloadInfoList) {
|
||||
// Put file
|
||||
files[i] = SpiderDen.getGalleryDownloadDir(info, false);
|
||||
files[i] = SpiderDen.getGalleryDownloadDir(info.gid);
|
||||
// Remove download path
|
||||
EhDB.removeDownloadDirname(info.gid);
|
||||
i++;
|
||||
|
||||
@@ -2074,7 +2074,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
|
||||
boolean checked = mBuilder.isChecked();
|
||||
Settings.putRemoveImageFiles(checked);
|
||||
if (checked) {
|
||||
UniFile file = SpiderDen.getGalleryDownloadDir(mGalleryInfo, false);
|
||||
UniFile file = SpiderDen.getGalleryDownloadDir(mGalleryInfo.gid);
|
||||
EhDB.removeDownloadDirname(mGalleryInfo.gid);
|
||||
deleteFileAsync(file);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user