Create download dir only in download mode
Do not try to find download dir, should use restore download instead
This commit is contained in:
1 parent
57d4967f2a
commit
3b5e56b049
5 files changed
+15
-31
No files matched your search
@@ -588,7 +588,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
galleryInfo.uploader = downloadInfo.uploader;
|
||||
galleryInfo.rating = downloadInfo.rating;
|
||||
|
||||
UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo);
|
||||
UniFile downloadDir = SpiderDen.getGalleryDownloadDir(galleryInfo, false);
|
||||
if (downloadDir == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -50,13 +50,12 @@ public final class SpiderDen {
|
||||
@Nullable
|
||||
private static SimpleDiskCache sCache;
|
||||
@Nullable
|
||||
private final UniFile mDownloadDir;
|
||||
private UniFile mDownloadDir;
|
||||
private final long mGid;
|
||||
private volatile int mMode = SpiderQueen.MODE_READ;
|
||||
|
||||
public SpiderDen(GalleryInfo galleryInfo) {
|
||||
mGid = galleryInfo.gid;
|
||||
mDownloadDir = getGalleryDownloadDir(galleryInfo);
|
||||
}
|
||||
|
||||
public static void initialize(Context context) {
|
||||
@@ -64,7 +63,7 @@ public final class SpiderDen {
|
||||
MathUtils.clamp(Settings.getReadCacheSize(), 40, 1280) * 1024 * 1024);
|
||||
}
|
||||
|
||||
public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo) {
|
||||
public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo, boolean create) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (dir != null) {
|
||||
// Read from DB
|
||||
@@ -75,35 +74,13 @@ public final class SpiderDen {
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
|
||||
// Find it
|
||||
if (null == dirname) {
|
||||
UniFile[] files = dir.listFiles(new StartWithFilenameFilter(galleryInfo.gid + "-"));
|
||||
if (null != files) {
|
||||
// Get max-length-name dir
|
||||
int maxLength = -1;
|
||||
for (UniFile file : files) {
|
||||
if (file.isDirectory()) {
|
||||
String name = file.getName();
|
||||
int length = name.length();
|
||||
if (length > maxLength) {
|
||||
maxLength = length;
|
||||
dirname = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null != dirname) {
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create it
|
||||
if (null == dirname) {
|
||||
if (null == dirname && create) {
|
||||
dirname = FileUtils.sanitizeFilename(galleryInfo.gid + "-" + EhUtils.getSuitableTitle(galleryInfo));
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
|
||||
return dir.subFile(dirname);
|
||||
return null != dirname ? dir.subFile(dirname) : null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -153,6 +130,10 @@ public final class SpiderDen {
|
||||
return mDownloadDir != null && mDownloadDir.isDirectory() ? mDownloadDir : null;
|
||||
}
|
||||
|
||||
public void setDownloadDir(UniFile dir) {
|
||||
mDownloadDir = dir;
|
||||
}
|
||||
|
||||
private boolean containInCache(int index) {
|
||||
if (sCache == null) {
|
||||
return false;
|
||||
|
||||
@@ -318,6 +318,9 @@ 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
|
||||
|
||||
@@ -994,10 +994,10 @@ public class DownloadsScene extends BaseToolbarScene
|
||||
UniFile[] files = new UniFile[mDownloadInfoList.size()];
|
||||
int i = 0;
|
||||
for (DownloadInfo info : mDownloadInfoList) {
|
||||
// Put file
|
||||
files[i] = SpiderDen.getGalleryDownloadDir(info, false);
|
||||
// Remove download path
|
||||
EhDB.removeDownloadDirname(info.gid);
|
||||
// Put file
|
||||
files[i] = SpiderDen.getGalleryDownloadDir(info);
|
||||
i++;
|
||||
}
|
||||
// Delete file
|
||||
|
||||
@@ -2053,8 +2053,8 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
|
||||
boolean checked = mBuilder.isChecked();
|
||||
Settings.putRemoveImageFiles(checked);
|
||||
if (checked) {
|
||||
UniFile file = SpiderDen.getGalleryDownloadDir(mGalleryInfo, false);
|
||||
EhDB.removeDownloadDirname(mGalleryInfo.gid);
|
||||
UniFile file = SpiderDen.getGalleryDownloadDir(mGalleryInfo);
|
||||
deleteFileAsync(file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user