- Added file already existing handling

- Switch to Executor Service to handle only 5 SwingWorkers at a time
- Added chromedriver.exe task killer at window close
This commit is contained in:
2021-04-06 00:15:54 +02:00
parent f8dd7be711
commit 8d00ff7f90
5 changed files with 63 additions and 11 deletions

View File

@@ -9,6 +9,8 @@ import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
@@ -39,6 +41,8 @@ public class DownloadRipperPanel implements PropertyChangeListener{
/** The information panel for the currently selected task */
private DownloadTaskInformationPanel infoPanel;
private final ExecutorService threadPool = Executors.newFixedThreadPool(5);
/**
* Create a download panel
*/
@@ -126,7 +130,8 @@ public class DownloadRipperPanel implements PropertyChangeListener{
*/
public void addTask(DownloadTask task){
downloadTasks.add(task);
task.execute();
threadPool.submit(task);
//task.execute();
listModel.addElement(task);
updateTaskCount();
task.addPropertyChangeListener(this);

View File

@@ -6,8 +6,15 @@ import com.greinet.tvtotalripper.download.DownloadTask;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.swing.JComponent;
import javax.swing.JFrame;
@@ -45,7 +52,28 @@ public class RipperWindow {
*/
public RipperWindow(){
JFrame frame = new JFrame("TV Total Ripper");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
try {
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c","taskkill /F /IM chromedriver.exe /T");
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) { break; }
}
} catch (IOException ex) {
Logger.getLogger(RipperWindow.class.getName()).log(Level.SEVERE, null, ex);
}
System.exit(0);
}
});
tabbedPane = new JTabbedPane();

View File

@@ -31,7 +31,7 @@ public class SettingsRipperPanel {
/** The file chooser to select the download folder */
private JFileChooser fileChooserDownloadFolder;
/** The download folder */
public static File DOWNLOADFOLDER = new File(".");
public static File DOWNLOADFOLDER = new File("D:/Users/Andreas/Videos/MySpass/");
/** The JButton to open the file chooser dialog */
private final JButton button;