Storing number of files in history

This commit is contained in:
4pr0n 2015-01-11 00:23:43 -08:00
parent afb7236db9
commit 9e63783abc
6 changed files with 71 additions and 9 deletions

View File

@ -15,6 +15,7 @@ import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.jsoup.HttpStatusException;
import com.rarchives.ripme.ui.RipStatusComplete;
import com.rarchives.ripme.ui.RipStatusHandler;
import com.rarchives.ripme.ui.RipStatusMessage;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
@ -199,6 +200,13 @@ public abstract class AbstractRipper
*/
public abstract void downloadProblem(URL url, String message);
/**
* @return Number of files downloaded.
*/
public int getCount() {
return 1;
}
/**
* Notifies observers and updates state if all files have been ripped.
*/
@ -211,8 +219,10 @@ public abstract class AbstractRipper
completed = true;
logger.info(" Rip completed!");
RipStatusMessage msg = new RipStatusMessage(STATUS.RIP_COMPLETE, workingDir);
RipStatusComplete rsc = new RipStatusComplete(workingDir, getCount());
RipStatusMessage msg = new RipStatusMessage(STATUS.RIP_COMPLETE, rsc);
observer.update(this, msg);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {

View File

@ -33,6 +33,11 @@ public abstract class AlbumRipper extends AbstractRipper {
return false;
}
@Override
public int getCount() {
return itemsCompleted.size();
}
public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies) {
if (!allowDuplicates()
&& ( itemsPending.containsKey(url)

View File

@ -68,7 +68,7 @@ public class History {
public void toFile(String filename) throws IOException {
OutputStream os = new FileOutputStream(filename);
try {
IOUtils.write(toJSON().toString(), os);
IOUtils.write(toJSON().toString(2), os);
} finally {
os.close();
}

View File

@ -7,30 +7,43 @@ import org.json.JSONObject;
public class HistoryEntry {
public String url = "",
title = "";
title = "",
dir = "";
public int count = 0;
public Date startDate = new Date(),
modifiedDate = new Date();
boolean selected = false;
public HistoryEntry() {
}
public HistoryEntry fromJSON(JSONObject json) {
this.url = json.getString("url");
this.title = json.getString("title");
this.count = json.getInt("count");
this.startDate = new Date(json.getLong("startDate"));
this.modifiedDate = new Date(json.getLong("modifiedDate"));
if (json.has("title")) {
this.title = json.getString("title");
}
if (json.has("count")) {
this.count = json.getInt("count");
}
if (json.has("dir")) {
this.dir = json.getString("dir");
}
if (json.has("selected")) {
this.selected = json.getBoolean("selected");
}
return this;
}
public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("url", this.url);
json.put("title", this.title);
json.put("count", this.count);
json.put("startDate", this.startDate.getTime());
json.put("modifiedDate", this.modifiedDate.getTime());
json.put("title", this.title);
json.put("count", this.count);
json.put("selected", this.selected);
return json;
}

View File

@ -27,6 +27,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Date;
import java.util.List;
import javax.imageio.ImageIO;
@ -977,17 +978,21 @@ public class MainWindow implements Runnable, RipStatusHandler {
case RIP_COMPLETE:
boolean alreadyInHistory = false;
RipStatusComplete rsc = (RipStatusComplete) msg.getObject();
String url = ripper.getURL().toExternalForm();
for (int i = 0; i < historyListModel.size(); i++) {
HistoryEntry entry = (HistoryEntry) historyListModel.get(i);
if (entry.url.equals(url)) {
alreadyInHistory = true;
entry.modifiedDate = new Date();
break;
}
}
if (!alreadyInHistory) {
HistoryEntry entry = new HistoryEntry();
entry.url = url;
entry.dir = rsc.getDir();
entry.count = rsc.count;
try {
entry.title = ripper.getAlbumTitle(ripper.getURL());
} catch (MalformedURLException e) { }
@ -1001,7 +1006,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
statusProgress.setValue(0);
statusProgress.setVisible(false);
openButton.setVisible(true);
File f = (File) msg.getObject();
File f = rsc.dir;
String prettyFile = Utils.shortenPath(f);
openButton.setText("Open " + prettyFile);
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());

View File

@ -0,0 +1,29 @@
package com.rarchives.ripme.ui;
import java.io.File;
import java.io.IOException;
public class RipStatusComplete {
File dir = null;
int count = 0;
public RipStatusComplete(File dir) {
this.dir = dir;
this.count = 1;
}
public RipStatusComplete(File dir, int count) {
this.dir = dir;
this.count = count;
}
public String getDir() {
String result;
try {
result = this.dir.getCanonicalPath();
} catch (IOException e) {
result = this.dir.toString();
}
return result;
}
}