Skip to content

Commit

Permalink
zip打包
Browse files Browse the repository at this point in the history
  • Loading branch information
dipoo committed Mar 30, 2016
1 parent 9839ac7 commit 1a85d1b
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/org/arong/egdownloader/model/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public class Task {
private Long oldByteLength = 0L;
private String downSpeed = "";//下载速度

public String getDisplayName(){
return subname == null || "".equals(subname) ? name : subname;
}

public void addPropertyChangeListener(PropertyChangeListener l) {
changeSupport.addPropertyChangeListener(l);
}
Expand Down
7 changes: 5 additions & 2 deletions src/org/arong/egdownloader/ui/ComponentConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public final class ComponentConst {
SKIN_ICON.put("group", "_group.png");
SKIN_ICON.put("clear", "_clear.png");
SKIN_ICON.put("task", "_task.png");
SKIN_ICON.put("zip", "_zip.png");
}
/*MainWindow内的组件*/
//组件的name值
Expand Down Expand Up @@ -210,6 +211,7 @@ public final class ComponentConst {
public final static String POPUP_CHANGEREADED_MENU_TEXT = " 更改状态 ";
public final static String POPUP_MORE_MENU_TEXT = "更多操作 ";
public final static String POPUP_SEARCHAUTHOR_MENU_TEXT = " 搜索作者 ";
public final static String POPUP_ZIP_MENU_TEXT = " 打包ZIP ";
public final static String POPUP_EDIT_MENU_TEXT = "编辑 ";
public final static String POPUP_RESET_MENU_TEXT = "重置 ";
public final static String POPUP_COMPLETED_MENU_TEXT = "完成 " ;
Expand Down Expand Up @@ -258,11 +260,12 @@ public static String getXmlDirPath(){
}

public static String getSavePathPreffix(){
if("".equals(groupName)){
return "";
/*if("".equals(groupName)){
return "";
}else{
return ROOT_DATA_PATH + "/" + groupName + "/";
}
}*/
}

}
6 changes: 6 additions & 0 deletions src/org/arong/egdownloader/ui/IconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class IconManager {
private static ImageIcon initImage;
private static ImageIcon leftImage;
private static ImageIcon rightImage;
private static ImageIcon zipImage;

private static ImageIcon ehImage;
private static ImageIcon tImage;
Expand Down Expand Up @@ -218,6 +219,11 @@ else if("task".equals(name)){
taskImage = new ImageIcon(IconManager.class.getResource(skinPath + ComponentConst.SKIN_ICON.get("task")));
}
return taskImage;
}else if("zip".equals(name)){
if(zipImage == null){
zipImage = new ImageIcon(IconManager.class.getResource(skinPath + ComponentConst.SKIN_ICON.get("zip")));
}
return zipImage;
}else if("init".equals(name)){
if(initImage == null){
initImage = new ImageIcon(IconManager.class.getResource(ComponentConst.ICON_PATH + "init.jpg"));
Expand Down
20 changes: 19 additions & 1 deletion src/org/arong/egdownloader/ui/window/EgDownloaderWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.arong.egdownloader.ui.swing.AJPopupMenu;
import org.arong.egdownloader.ui.table.TaskingTable;
import org.arong.egdownloader.ui.window.form.AddFormDialog;
import org.arong.egdownloader.ui.work.ZIPWorker;
import org.arong.egdownloader.ui.work.interfaces.IListenerTask;
import org.arong.egdownloader.ui.work.interfaces.IMenuListenerTask;
import org.arong.egdownloader.ui.work.listenerWork.ChangeReadedWork;
Expand Down Expand Up @@ -120,6 +121,7 @@ public class EgDownloaderWindow extends JFrame {
public SearchCoverWindow coverWindow;//漫画封面,鼠标移动出现
public JDialog editWindow;
public JDialog deletingWindow;
public JDialog zipWindow;
public JDialog resetAllTaskWindow;
public JDialog simpleSearchWindow;
public JDialog countWindow;
Expand Down Expand Up @@ -394,6 +396,22 @@ public void doWork(Window window, ActionEvent e) {
AJMenuItem changeReadedMenuItem = new AJMenuItem(ComponentConst.POPUP_CHANGEREADED_MENU_TEXT, menuItemColor,
IconManager.getIcon("change"),
new MenuItemActonListener(this, new ChangeReadedWork()));
//右键菜单:打包ZIP
AJMenuItem zipMenuItem = new AJMenuItem(ComponentConst.POPUP_ZIP_MENU_TEXT, menuItemColor,
IconManager.getIcon("zip"),
new MenuItemActonListener(this, new IMenuListenerTask() {
public void doWork(Window window, ActionEvent e) {
EgDownloaderWindow mainWindow = (EgDownloaderWindow)window;
TaskingTable table = (TaskingTable) mainWindow.runningTable;

if(zipWindow == null){
zipWindow = new ZiptingWindow(mainWindow);
}
mainWindow.tablePopupMenu.setVisible(false);
ZIPWorker zipWordker = new ZIPWorker(mainWindow, table, (ZiptingWindow)zipWindow);
zipWordker.execute();
}
}));
//右键菜单:搜索作者
AJMenuItem searchAuthorMenuItem = new AJMenuItem(ComponentConst.POPUP_SEARCHAUTHOR_MENU_TEXT, menuItemColor,
"",
Expand Down Expand Up @@ -497,7 +515,7 @@ public void doWork(Window window, ActionEvent e) {
//表格的右键菜单
tablePopupMenu = new AJPopupMenu(startPopupMenuItem, stopPopupMenuItem, detailPopupMenuItem, openFolderPopupMenuItem,
copyUrlPopupMenuItem, openWebPageMenuItem, downloadCoverMenuItem,
checkResetMenuItem, changeReadedMenuItem, searchAuthorMenuItem, moreMenu);
checkResetMenuItem, changeReadedMenuItem, zipMenuItem, searchAuthorMenuItem, moreMenu);
JLabel emptyTableTips = new AJLabel("empty", "", new Color(227,93,81), JLabel.CENTER);
emptyTableTips.setFont(new Font("Comic Sans MS", Font.BOLD, 18));
JButton emptyBtn = new AJButton("当前任务组没有下载任务,请点击搜索漫画");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SearchCoverWindow(SearchComicWindow comicWindow){
* 主窗口使用
*/
public void showCover(Task task, Point p){
String path = ComponentConst.getSavePathPreffix() + task.getSaveDir() + "/cover.jpg";
String path = task.getSaveDir() + "/cover.jpg";
File cover = new File(path);
if(cover == null || !cover.exists()){
this.setVisible(false);
Expand Down
33 changes: 28 additions & 5 deletions src/org/arong/egdownloader/ui/window/SettingWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
Expand Down Expand Up @@ -56,6 +57,8 @@ public class SettingWindow extends JFrame{
JPanel basicPanel;
JLabel saveDirLabel;
public JTextField saveDirField;
private JFileChooser saveDirChooser;
JButton browseDirButton;
JButton openDirButton;
JLabel saveAsNameLabel;
public JCheckBox saveAsNameBox;
Expand Down Expand Up @@ -102,6 +105,7 @@ public class SettingWindow extends JFrame{
public JLabel proxyPwdLabel;
public JPasswordField proxyPwdField;
public JButton proxyTestBtn;
private JLabel proxyTipLabel;

Color labelColor = new Color(65,145,65);
Color bgColor = new Color(210,225,240);
Expand Down Expand Up @@ -131,14 +135,31 @@ public SettingWindow(JFrame mainWindow) {

/* 基本配置 */
basicPanel = new JPanel();
basicPanel.setLayout(null);
basicPanel.setLayout(null);
saveDirChooser = new JFileChooser("/");
saveDirChooser.setDialogTitle("选择保存目录");//选择框标题
saveDirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//只能选择目录
saveDirLabel = new AJLabel("保存目录:", labelColor, 25, 30, 100, 30);
saveDirField = new AJTextField(setting.getDefaultSaveDir(), "", 125, 30, 360, 30);
saveDirField.setEditable(false);
saveDirField.setEnabled(false);

final SettingWindow this_ = this;

browseDirButton = new AJButton("浏览", IconManager.getIcon("select"), new OperaBtnMouseListener(mainWindow, MouseAction.CLICK, new IListenerTask() {
public void doWork(Window window, MouseEvent e) {
int result = this_.saveDirChooser.showOpenDialog(this_);
File file = null;
if(result == JFileChooser.APPROVE_OPTION) {
file = this_.saveDirChooser.getSelectedFile();
if(!file.isDirectory()) {
JOptionPane.showMessageDialog(this_, "你选择的目录不存在");
return ;
}
String path = file.getAbsolutePath();
this_.saveDirField.setText(path);
}
}
}), 500, 30, 60, 30);
openDirButton = new AJButton("打开", IconManager.getIcon("folder"), new OperaBtnMouseListener(mainWindow, MouseAction.CLICK, new IListenerTask() {
public void doWork(Window window, MouseEvent e) {
try {
Expand All @@ -151,7 +172,8 @@ public void doWork(Window window, MouseEvent e) {
JOptionPane.showMessageDialog(this_, "文件夹已被删除");
}
}
}), 500, 30, 60, 30);
}), 570, 30, 60, 30);
//当存在原图时,下载原图http://exhentai.org/s/72aa78ff00/913125-7
saveAsNameLabel = new AJLabel("以真实名称保存:", labelColor, 25, 70, 100, 30);
saveAsNameBox = new JCheckBox("", setting.isSaveAsName());
saveAsNameBox.setBounds(120, 70, 30, 30);
Expand Down Expand Up @@ -187,7 +209,7 @@ public void doWork(Window window, MouseEvent e) {
settingWindow.cookieArea.setText(new Setting().getCookieInfo());
}
}), 500, 290, 60, 30);
addComponentsJpanel(basicPanel, saveDirLabel, saveDirField, openDirButton,
addComponentsJpanel(basicPanel, saveDirLabel, saveDirField, browseDirButton, openDirButton,
saveAsNameLabel, saveAsNameBox, autoDownloadLabel,autoDownloadBox, maxThreadLabel, maxThreadField,
loginUrlLabel, loginUrlField, cookieLabel, cookieArea,
cookieButton, resumeButton);
Expand Down Expand Up @@ -292,9 +314,10 @@ public void doWork(Window window, MouseEvent e) {
testProxyWindow.setVisible(true);
}
}), 125, 230, 60, 30);
proxyTipLabel = new AJLabel("提示:测试前请先保存当前配置", Color.BLUE, 200, 230, 300, 30);

addComponentsJpanel(proxyPanel, proxyLabel, noRadioButton, yesRadioButton, proxyIpLabel, proxyIpField, proxyPortLabel, proxyPortField,
proxyUsernameLabel, proxyUsernameField, proxyPwdLabel, proxyPwdField, proxyTestBtn);
proxyUsernameLabel, proxyUsernameField, proxyPwdLabel, proxyPwdField, proxyTestBtn, proxyTipLabel);

settingTabPanel.add("基本配置", basicPanel);
settingTabPanel.add("脚本配置", scriptPanel);
Expand Down
82 changes: 82 additions & 0 deletions src/org/arong/egdownloader/ui/window/ZiptingWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.arong.egdownloader.ui.window;

import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

import org.arong.egdownloader.ui.ComponentUtil;
import org.arong.egdownloader.ui.swing.AJLabel;
import org.arong.egdownloader.ui.swing.AJProgressBar;
/**
* 打包zip细节显示窗口
* @author dipoo
* @since 2016-03-30
*/
public class ZiptingWindow extends JDialog {

private static final long serialVersionUID = -2544191890083257820L;

public JFrame mainWindow;
public JProgressBar bar;
public JLabel totalLabel;
public JLabel nameLabel;

public ZiptingWindow(JFrame window){
this.mainWindow = window;
this.setTitle("正在打包为ZIP文件");
this.setSize(400, 150);
this.setLayout(null);
this.setResizable(false);
this.setLocationRelativeTo(this.mainWindow);
this.setBackground(Color.WHITE);

//关闭监听,释放窗口资源,否则消耗大量CPU
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
ZiptingWindow window = (ZiptingWindow) e.getSource();
window.mainWindow.setEnabled(true);
window.mainWindow.setVisible(true);
window.dispose();
}
//窗体由激活状态变成非激活状态
/*public void windowDeactivated(WindowEvent e) {
mainWindow.setVisible(true);
mainWindow.setEnabled(true);
CreatingWindow window = (CreatingWindow) e.getSource();
window.dispose();
}*/
public void windowActivated(WindowEvent e) {
mainWindow.setEnabled(false);
}
});

nameLabel = new AJLabel("名称:", Color.BLACK, 10, 5, 380, 20);
totalLabel = new AJLabel("数目:", Color.BLACK, 10, 35, 100, 20);
bar = new AJProgressBar(40, 65, 310, 20, 0, 100);
bar.setStringPainted(true);
ComponentUtil.addComponents(getContentPane(), nameLabel,
totalLabel, bar);
}

@Override
protected void processWindowEvent(WindowEvent e) {
//关闭事件
if(e.getID() == WindowEvent.WINDOW_CLOSING){
//do nothing
}else{
super.processWindowEvent(e);
}
}

public void dispose() {
mainWindow.setEnabled(true);
mainWindow.setVisible(true);
super.dispose();
}

}
22 changes: 11 additions & 11 deletions src/org/arong/egdownloader/ui/work/DownloadWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected Void doInBackground() throws Exception {
exceptionNum = 0;
//设置任务状态为下载中
//task.setStatus(TaskStatus.STARTED);
Tracker.println(getClass(), task.getName() + "(" + task.getStart() + "-" + task.getEnd() + "):开始下载");
Tracker.println(getClass(), task.getDisplayName() + "(" + task.getStart() + "-" + task.getEnd() + "):开始下载");
List<Picture> pics = task.getPictures();

Picture pic;
Expand Down Expand Up @@ -83,20 +83,20 @@ protected Void doInBackground() throws Exception {
return null;
if(is == null){
pic.setRealUrl(null);
Tracker.println(task.getName() + ":" + pic.getName() + ":图片流无效");
Tracker.println(task.getDisplayName() + ":" + pic.getName() + ":图片流无效");
exceptionNum ++;
continue;
}
int size = is.available();
if(size < 1000){
pic.setRealUrl(null);
Tracker.println(task.getName() + ":" + pic.getName() + ":403");
Tracker.println(task.getDisplayName() + ":" + pic.getName() + ":403");
is.close();
exceptionNum ++;
continue;
}else if(size < 1010){
pic.setRealUrl(null);
Tracker.println(task.getName() + ":" + pic.getName() + ":509");
Tracker.println(task.getDisplayName() + ":" + pic.getName() + ":509");
is.close();
exceptionNum ++;
continue;
Expand Down Expand Up @@ -138,18 +138,18 @@ protected Void doInBackground() throws Exception {
((EgDownloaderWindow)mainWindow).pictureDbTemplate.update(pic);
//设置最后下载时间
setting.setLastDownloadTime(pic.getTime());
Tracker.println(DownloadWorker.class ,task.getName() + ":" + pic.getName() + "下载完成。");
Tracker.println(DownloadWorker.class ,task.getDisplayName() + ":" + pic.getName() + "下载完成。");
success ++;
}catch (SocketTimeoutException e){
//碰到异常
Tracker.println(task.getName() + ":" + pic.getName() + "-读取流超时,滞后重试");
Tracker.println(task.getDisplayName() + ":" + pic.getName() + "-读取流超时,滞后重试");
//删除已经下载的文件
delete(existNameFs);
//继续下一个
continue;
}catch (ConnectTimeoutException e){
//碰到异常
Tracker.println(task.getName() + ":" + pic.getName() + "-连接超时,滞后重试");
Tracker.println(task.getDisplayName() + ":" + pic.getName() + "-连接超时,滞后重试");
//继续下一个
continue;
}catch (WebClientException e) {
Expand All @@ -163,7 +163,7 @@ protected Void doInBackground() throws Exception {
}catch (Exception e){
//碰到异常
e.printStackTrace();
Tracker.println(task.getName() + ":" + pic.getName() + e.getLocalizedMessage());
Tracker.println(task.getDisplayName() + ":" + pic.getName() + e.getLocalizedMessage());
//继续下一个
continue;
}
Expand All @@ -176,7 +176,7 @@ protected Void doInBackground() throws Exception {
return null;
//是否达到下载区间要求,达到则暂停
if(success == requireNum){
Tracker.println(DownloadWorker.class, "【" + task.getName() + ":完成配置区间下载。】");
Tracker.println(DownloadWorker.class, "【" + task.getDisplayName() + ":完成配置区间下载。】");
//设置任务状态为已暂停
task.setStatus(TaskStatus.STOPED);
table.setRunningNum(table.getRunningNum() - 1);//当前运行的任务数-1
Expand All @@ -185,7 +185,7 @@ protected Void doInBackground() throws Exception {
return null;
}
if(exceptionNum >= requireNum){
Tracker.println(DownloadWorker.class, "【" + task.getName() + ":配额不足或者下载异常,停止下载。】");
Tracker.println(DownloadWorker.class, "【" + task.getDisplayName() + ":配额不足或者下载异常,停止下载。】");
//设置任务状态为已暂停
task.setStatus(TaskStatus.STOPED);
table.setRunningNum(table.getRunningNum() - 1);//当前运行的任务数-1
Expand All @@ -197,7 +197,7 @@ protected Void doInBackground() throws Exception {
}else{
//设置任务状态为已完成
task.setStatus(TaskStatus.COMPLETED);
Tracker.println(DownloadWorker.class ,"【" + task.getName() + "已下载完毕。】");
Tracker.println(DownloadWorker.class ,"【" + task.getDisplayName() + "已下载完毕。】");
task.setCompletedTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//更新任务到文件
((EgDownloaderWindow)mainWindow).taskDbTemplate.update(task);
Expand Down
Loading

0 comments on commit 1a85d1b

Please sign in to comment.