aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <donaldshan1@outlook.com>2023-04-20 15:52:04 -0700
committerPinapelz <donaldshan1@outlook.com>2023-04-20 16:04:39 -0700
commit88259d981826a1a82aaada160d7b6cf1129b3415 (patch)
tree73065a7337b9807dde8ec662ada983f400b24459
parent88410919401eb9d9cbea950df5fc004f4194c2d3 (diff)
Fixed DownloadConfigPane file writer bug
-rw-r--r--src/main/java/DownloadConfigPane.java46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/main/java/DownloadConfigPane.java b/src/main/java/DownloadConfigPane.java
index 058cc07..ba2f6dd 100644
--- a/src/main/java/DownloadConfigPane.java
+++ b/src/main/java/DownloadConfigPane.java
@@ -4,6 +4,8 @@ import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.nio.file.Files;
public class DownloadConfigPane extends JFrame{
@@ -76,7 +78,11 @@ public class DownloadConfigPane extends JFrame{
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- saveConfigToFile();
+ try {
+ saveConfigToFile();
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
}
});
}
@@ -112,6 +118,19 @@ public class DownloadConfigPane extends JFrame{
return null;
}
+ private File selectDirectoryFileChooser(){
+ JFileChooser chooser = new JFileChooser();
+ chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
+ chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+ int result = chooser.showOpenDialog(this);
+ if (result == JFileChooser.APPROVE_OPTION) {
+ File selectedFile = chooser.getSelectedFile();
+ System.out.println("Selected file: " + selectedFile.getAbsolutePath());
+ return selectedFile;
+ }
+ return null;
+ }
+
private void loadConfigFromFile(){
File file = selectTextFileChooser();
if (file == null){
@@ -158,12 +177,16 @@ public class DownloadConfigPane extends JFrame{
}
- private void saveConfigToFile(){
+ private void saveConfigToFile() throws IOException {
if(loadedPath == null){
- System.out.println("No file loaded");
- return;
+ File selectedDirectory = selectDirectoryFileChooser();
+ if (selectedDirectory == null){
+ return;
+ }
+ loadedPath = selectedDirectory.getAbsolutePath() + "/download_config.txt";
}
File saveFile = new File(loadedPath);
+ FileWriter writer = new FileWriter(saveFile);
if(!saveFile.exists()){
System.out.println("File does not exist");
return;
@@ -172,9 +195,22 @@ public class DownloadConfigPane extends JFrame{
String url = (String) outputTable.getValueAt(i, 0);
String from = (String) outputTable.getValueAt(i, 1);
String to = (String) outputTable.getValueAt(i, 2);
- String line = url + "," + from + "-" + to;
+ String line = "";
+ if (from.equals("00:00:00") && to.equals("00:00:00")){
+ line = url;
+ }
+ else{
+ line = url + "," + from + "-" + to;
+ }
+ try{
+ writer.write(line + System.lineSeparator());
+ }
+ catch (Exception e){
+ e.printStackTrace();
+ }
System.out.println(line);
}
+ writer.close();
JOptionPane.showConfirmDialog(null, "Saved to " + loadedPath, "Saved", JOptionPane.DEFAULT_OPTION);
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage