Storing number of files in history
This commit is contained in:
parent
afb7236db9
commit
9e63783abc
@ -15,6 +15,7 @@ import org.apache.log4j.FileAppender;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jsoup.HttpStatusException;
|
import org.jsoup.HttpStatusException;
|
||||||
|
|
||||||
|
import com.rarchives.ripme.ui.RipStatusComplete;
|
||||||
import com.rarchives.ripme.ui.RipStatusHandler;
|
import com.rarchives.ripme.ui.RipStatusHandler;
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage;
|
import com.rarchives.ripme.ui.RipStatusMessage;
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
||||||
@ -199,6 +200,13 @@ public abstract class AbstractRipper
|
|||||||
*/
|
*/
|
||||||
public abstract void downloadProblem(URL url, String message);
|
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.
|
* Notifies observers and updates state if all files have been ripped.
|
||||||
*/
|
*/
|
||||||
@ -206,13 +214,15 @@ public abstract class AbstractRipper
|
|||||||
if (observer == null) {
|
if (observer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!completed) {
|
if (!completed) {
|
||||||
completed = true;
|
completed = true;
|
||||||
logger.info(" Rip completed!");
|
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);
|
observer.update(this, msg);
|
||||||
|
|
||||||
Logger rootLogger = Logger.getRootLogger();
|
Logger rootLogger = Logger.getRootLogger();
|
||||||
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
|
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
|
||||||
if (fa != null) {
|
if (fa != null) {
|
||||||
|
@ -33,6 +33,11 @@ public abstract class AlbumRipper extends AbstractRipper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return itemsCompleted.size();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies) {
|
public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies) {
|
||||||
if (!allowDuplicates()
|
if (!allowDuplicates()
|
||||||
&& ( itemsPending.containsKey(url)
|
&& ( itemsPending.containsKey(url)
|
||||||
|
@ -68,7 +68,7 @@ public class History {
|
|||||||
public void toFile(String filename) throws IOException {
|
public void toFile(String filename) throws IOException {
|
||||||
OutputStream os = new FileOutputStream(filename);
|
OutputStream os = new FileOutputStream(filename);
|
||||||
try {
|
try {
|
||||||
IOUtils.write(toJSON().toString(), os);
|
IOUtils.write(toJSON().toString(2), os);
|
||||||
} finally {
|
} finally {
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
@ -7,30 +7,43 @@ import org.json.JSONObject;
|
|||||||
public class HistoryEntry {
|
public class HistoryEntry {
|
||||||
|
|
||||||
public String url = "",
|
public String url = "",
|
||||||
title = "";
|
title = "",
|
||||||
|
dir = "";
|
||||||
public int count = 0;
|
public int count = 0;
|
||||||
public Date startDate = new Date(),
|
public Date startDate = new Date(),
|
||||||
modifiedDate = new Date();
|
modifiedDate = new Date();
|
||||||
|
boolean selected = false;
|
||||||
|
|
||||||
public HistoryEntry() {
|
public HistoryEntry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public HistoryEntry fromJSON(JSONObject json) {
|
public HistoryEntry fromJSON(JSONObject json) {
|
||||||
this.url = json.getString("url");
|
this.url = json.getString("url");
|
||||||
this.title = json.getString("title");
|
|
||||||
this.count = json.getInt("count");
|
|
||||||
this.startDate = new Date(json.getLong("startDate"));
|
this.startDate = new Date(json.getLong("startDate"));
|
||||||
this.modifiedDate = new Date(json.getLong("modifiedDate"));
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject toJSON() {
|
public JSONObject toJSON() {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("url", this.url);
|
json.put("url", this.url);
|
||||||
json.put("title", this.title);
|
|
||||||
json.put("count", this.count);
|
|
||||||
json.put("startDate", this.startDate.getTime());
|
json.put("startDate", this.startDate.getTime());
|
||||||
json.put("modifiedDate", this.modifiedDate.getTime());
|
json.put("modifiedDate", this.modifiedDate.getTime());
|
||||||
|
json.put("title", this.title);
|
||||||
|
json.put("count", this.count);
|
||||||
|
json.put("selected", this.selected);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
@ -977,17 +978,21 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
|
|
||||||
case RIP_COMPLETE:
|
case RIP_COMPLETE:
|
||||||
boolean alreadyInHistory = false;
|
boolean alreadyInHistory = false;
|
||||||
|
RipStatusComplete rsc = (RipStatusComplete) msg.getObject();
|
||||||
String url = ripper.getURL().toExternalForm();
|
String url = ripper.getURL().toExternalForm();
|
||||||
for (int i = 0; i < historyListModel.size(); i++) {
|
for (int i = 0; i < historyListModel.size(); i++) {
|
||||||
HistoryEntry entry = (HistoryEntry) historyListModel.get(i);
|
HistoryEntry entry = (HistoryEntry) historyListModel.get(i);
|
||||||
if (entry.url.equals(url)) {
|
if (entry.url.equals(url)) {
|
||||||
alreadyInHistory = true;
|
alreadyInHistory = true;
|
||||||
|
entry.modifiedDate = new Date();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!alreadyInHistory) {
|
if (!alreadyInHistory) {
|
||||||
HistoryEntry entry = new HistoryEntry();
|
HistoryEntry entry = new HistoryEntry();
|
||||||
entry.url = url;
|
entry.url = url;
|
||||||
|
entry.dir = rsc.getDir();
|
||||||
|
entry.count = rsc.count;
|
||||||
try {
|
try {
|
||||||
entry.title = ripper.getAlbumTitle(ripper.getURL());
|
entry.title = ripper.getAlbumTitle(ripper.getURL());
|
||||||
} catch (MalformedURLException e) { }
|
} catch (MalformedURLException e) { }
|
||||||
@ -1001,7 +1006,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
|
|||||||
statusProgress.setValue(0);
|
statusProgress.setValue(0);
|
||||||
statusProgress.setVisible(false);
|
statusProgress.setVisible(false);
|
||||||
openButton.setVisible(true);
|
openButton.setVisible(true);
|
||||||
File f = (File) msg.getObject();
|
File f = rsc.dir;
|
||||||
String prettyFile = Utils.shortenPath(f);
|
String prettyFile = Utils.shortenPath(f);
|
||||||
openButton.setText("Open " + prettyFile);
|
openButton.setText("Open " + prettyFile);
|
||||||
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());
|
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());
|
||||||
|
29
src/main/java/com/rarchives/ripme/ui/RipStatusComplete.java
Normal file
29
src/main/java/com/rarchives/ripme/ui/RipStatusComplete.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user