Skip to content

Commit d8ea426

Browse files
committed
Update scan-folder-to-add-files function: set pop-up window with indicator showing how many files did we scan and how many files would be added.
Minor color corrections on light theme for whoever use it Fix TF progress-bar (can't recall when I broke it..)
1 parent 619a2b1 commit d8ea426

File tree

11 files changed

+247
-32
lines changed

11 files changed

+247
-32
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
Copyright 2019-2020 Dmitry Isaenko
3+
4+
This file is part of NS-USBloader.
5+
6+
NS-USBloader is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
NS-USBloader is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package nsusbloader.Controllers;
20+
21+
import javafx.geometry.Insets;
22+
import javafx.geometry.Pos;
23+
import javafx.scene.Scene;
24+
import javafx.scene.control.Button;
25+
import javafx.scene.control.Label;
26+
import javafx.scene.control.ProgressBar;
27+
import javafx.scene.control.ProgressIndicator;
28+
import javafx.scene.image.Image;
29+
import javafx.scene.layout.HBox;
30+
import javafx.scene.layout.Pane;
31+
import javafx.scene.layout.Priority;
32+
import javafx.scene.layout.VBox;
33+
import javafx.stage.Stage;
34+
import nsusbloader.AppPreferences;
35+
import nsusbloader.MediatorControl;
36+
37+
import java.io.File;
38+
import java.util.List;
39+
import java.util.ResourceBundle;
40+
41+
public class FilesDropHandle {
42+
43+
public FilesDropHandle(List<File> files, String filesRegex, String foldersRegex){
44+
45+
//
46+
// TODO: ADD GRAPHICS BEFORE RELEASE !
47+
//
48+
49+
FilesDropHandleTask filesDropHandleTask = new FilesDropHandleTask(files, filesRegex, foldersRegex);
50+
51+
ResourceBundle resourceBundle = MediatorControl.getInstance().getResourceBundle();
52+
Button cancelButton = new Button(resourceBundle.getString("btn_Cancel"));
53+
54+
ProgressIndicator progressIndicator = new ProgressIndicator();
55+
progressIndicator.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
56+
57+
Label downloadStatusLabel = new Label();
58+
downloadStatusLabel.setWrapText(true);
59+
downloadStatusLabel.textProperty().bind(filesDropHandleTask.messageProperty());
60+
61+
Pane fillerPane1 = new Pane();
62+
Pane fillerPane2 = new Pane();
63+
64+
VBox parentVBox = new VBox();
65+
parentVBox.setAlignment(Pos.TOP_CENTER);
66+
parentVBox.setFillWidth(true);
67+
parentVBox.setSpacing(5.0);
68+
parentVBox.setPadding(new Insets(5.0));
69+
parentVBox.setFillWidth(true);
70+
parentVBox.getChildren().addAll(
71+
downloadStatusLabel,
72+
fillerPane1,
73+
progressIndicator,
74+
fillerPane2,
75+
cancelButton
76+
); // TODO:FIX
77+
78+
VBox.setVgrow(fillerPane1, Priority.ALWAYS);
79+
VBox.setVgrow(fillerPane2, Priority.ALWAYS);
80+
81+
Stage stage = new Stage();
82+
stage.setTitle(resourceBundle.getString("windowTitleAddingFiles"));
83+
stage.getIcons().addAll(
84+
new Image("/res/dwnload_ico32x32.png"), //TODO: REDRAW
85+
new Image("/res/dwnload_ico48x48.png"),
86+
new Image("/res/dwnload_ico64x64.png"),
87+
new Image("/res/dwnload_ico128x128.png")
88+
);
89+
stage.setMinWidth(300);
90+
stage.setMinHeight(175);
91+
stage.setAlwaysOnTop(true);
92+
Scene mainScene = new Scene(parentVBox, 310, 185);
93+
94+
mainScene.getStylesheets().add(AppPreferences.getInstance().getTheme());
95+
96+
stage.setOnHidden(windowEvent -> filesDropHandleTask.cancel(true ) );
97+
98+
stage.setScene(mainScene);
99+
stage.show();
100+
stage.toFront();
101+
102+
filesDropHandleTask.setOnSucceeded(event -> {
103+
cancelButton.setText(resourceBundle.getString("btn_Close"));
104+
105+
List<File> allFiles = filesDropHandleTask.getValue();
106+
107+
if (! allFiles.isEmpty()) {
108+
MediatorControl.getInstance().getGamesController().tableFilesListController.setFiles(allFiles);
109+
}
110+
stage.close();
111+
});
112+
113+
new Thread(filesDropHandleTask).start();
114+
115+
cancelButton.setOnAction(actionEvent -> {
116+
filesDropHandleTask.cancel(true);
117+
stage.close();
118+
});
119+
}
120+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2019-2020 Dmitry Isaenko
3+
4+
This file is part of NS-USBloader.
5+
6+
NS-USBloader is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
NS-USBloader is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package nsusbloader.Controllers;
20+
21+
import javafx.concurrent.Task;
22+
import nsusbloader.MediatorControl;
23+
24+
import java.io.File;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
public class FilesDropHandleTask extends Task<List<File>> {
29+
private final String filesRegex;
30+
private final String foldersRegex;
31+
32+
private final List<File> filesDropped;
33+
private final List<File> allFiles;
34+
35+
private String messageTemplate;
36+
private long filesScanned = 0;
37+
private long filesAdded = 0;
38+
39+
FilesDropHandleTask(List<File> files,
40+
String filesRegex,
41+
String foldersRegex) {
42+
this.filesDropped = files;
43+
this.filesRegex = filesRegex;
44+
this.foldersRegex = foldersRegex;
45+
this.allFiles = new ArrayList<>();
46+
this.messageTemplate = MediatorControl.getInstance().getResourceBundle().getString("windowBodyFilesScanned");
47+
}
48+
49+
@Override
50+
protected List<File> call() {
51+
if (filesDropped == null || filesDropped.size() == 0)
52+
return allFiles;
53+
54+
for (File file : filesDropped){
55+
if (isCancelled())
56+
return new ArrayList<>();
57+
collectFiles(file);
58+
updateMessage(String.format(messageTemplate, filesScanned++, filesAdded));
59+
}
60+
61+
return allFiles;
62+
}
63+
64+
private void collectFiles(File startFolder) {
65+
if (startFolder == null)
66+
return;
67+
68+
final String startFolderNameInLowercase = startFolder.getName().toLowerCase();
69+
70+
if (startFolder.isFile()) {
71+
if (startFolderNameInLowercase.matches(filesRegex)) {
72+
allFiles.add(startFolder);
73+
filesAdded++;
74+
}
75+
return;
76+
}
77+
78+
if (startFolderNameInLowercase.matches(foldersRegex)) {
79+
allFiles.add(startFolder);
80+
filesAdded++;
81+
return;
82+
}
83+
84+
File[] files = startFolder.listFiles();
85+
if (files == null)
86+
return;
87+
88+
for (File file : files) {
89+
if (isCancelled())
90+
return;
91+
collectFiles(file);
92+
updateMessage(String.format(messageTemplate, filesScanned++, filesAdded));
93+
}
94+
}
95+
96+
}

src/main/java/nsusbloader/Controllers/GamesController.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141

4242
import java.io.File;
4343
import java.net.URL;
44-
import java.util.ArrayList;
45-
import java.util.LinkedList;
46-
import java.util.List;
47-
import java.util.ResourceBundle;
44+
import java.util.*;
4845
import java.util.function.Consumer;
4946
import java.util.function.Supplier;
5047

@@ -294,6 +291,7 @@ private void selectFoldersBtnAction() {
294291
* @param filesRegex for filenames
295292
*/
296293
// TODO: Too sophisticated. Should be moved to simple class to keep things simplier
294+
297295
private void collectFiles(List<File> storage,
298296
File startFolder,
299297
final String filesRegex,
@@ -437,24 +435,10 @@ private void handleDragOver(DragEvent event){
437435
* */
438436
@FXML
439437
private void handleDrop(DragEvent event) {
440-
final String regexForFiles = getRegexForFiles();
441-
final String regexForFolders = getRegexForFolders();
442-
443438
List<File> files = event.getDragboard().getFiles();
444-
445-
performInBackgroundAndUpdate(() -> {
446-
List<File> allFiles = new ArrayList<>();
447-
if (files != null && files.size() != 0) {
448-
files.forEach(f -> collectFiles(allFiles, f, regexForFiles, regexForFolders));
449-
}
450-
return allFiles;
451-
}, allFiles -> {
452-
if (!allFiles.isEmpty())
453-
tableFilesListController.setFiles(allFiles);
454-
455-
event.setDropCompleted(true);
456-
event.consume();
457-
});
439+
new FilesDropHandle(files, getRegexForFiles(), getRegexForFolders());
440+
event.setDropCompleted(true);
441+
event.consume();
458442
}
459443

460444
/**
@@ -527,7 +511,6 @@ private void setFilesSelectorButtonBehaviour(boolean isDirectoryChooser){
527511
selectSplitNspBtn.setVisible(true);
528512
}
529513
selectNspBtn.setGraphic(btnSelectImage);
530-
//selectFolderBtn.setTooltip(new Tooltip(resourceBundle.getString("btn_OpenFolders_tooltip")));
531514
}
532515
/**
533516
* Get 'Recent' path

src/main/java/nsusbloader/Controllers/NSTableViewController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void setFile(File file){
231231
/**
232232
* Add files when user selected them
233233
* */
234-
public void setFiles(List<File> newFiles){
234+
public synchronized void setFiles(List<File> newFiles){
235235
if (!rowsObsLst.isEmpty()){
236236
List<String> filesAlreayInList = new ArrayList<>();
237237
for (NSLRowModel model : rowsObsLst)

src/main/java/nsusbloader/com/usb/TinFoil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ void sendSplitFile(File nspFile, long size, long offset) throws IOException, Nul
222222
if ((currentOffset + chunk) >= size )
223223
chunk = Math.toIntExact(size - currentOffset);
224224
//System.out.println("CO: "+currentOffset+"\t\tEO: "+size+"\t\tRP: "+chunk); // NOTE: DEBUG
225-
logPrinter.updateProgress((currentOffset + chunk) / (size / 100.0) / 100.0);
226225

227226
readBuffer = new byte[chunk]; // TODO: not perfect moment, consider refactoring.
228227

@@ -232,6 +231,7 @@ void sendSplitFile(File nspFile, long size, long offset) throws IOException, Nul
232231
if (writeUsb(readBuffer))
233232
throw new IOException("TF Failure during file transfer.");
234233
currentOffset += chunk;
234+
logPrinter.updateProgress((double)currentOffset / (double)size);
235235
}
236236
nsSplitReader.close();
237237
logPrinter.updateProgress(1.0);
@@ -251,7 +251,6 @@ void sendNormalFile(File nspFile, long size, long offset) throws IOException, Nu
251251
if ((currentOffset + chunk) >= size)
252252
chunk = Math.toIntExact(size - currentOffset);
253253
//System.out.println("CO: "+currentOffset+"\t\tEO: "+receivedRangeSize+"\t\tRP: "+chunk); // NOTE: DEBUG
254-
logPrinter.updateProgress((currentOffset + chunk) / (size / 100.0) / 100.0);
255254

256255
readBuffer = new byte[chunk];
257256

@@ -261,6 +260,7 @@ void sendNormalFile(File nspFile, long size, long offset) throws IOException, Nu
261260
if (writeUsb(readBuffer))
262261
throw new IOException("TF Failure during file transfer.");
263262
currentOffset += chunk;
263+
logPrinter.updateProgress((double)currentOffset / (double)size);
264264
}
265265
bufferedInStream.close();
266266
logPrinter.updateProgress(1.0);

src/main/resources/locale.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ tab2_Cb_GlVersion=GoldLeaf version
7272
tab2_Cb_GLshowNspOnly=Show only *.nsp in GoldLeaf.
7373
windowBodyPleaseStopOtherProcessFirst=Please stop other active process before continuing.
7474
tab2_Cb_foldersSelectorForRoms=Select folder with ROM files instead of selecting ROMs individually.
75-
tab2_Cb_foldersSelectorForRomsDesc=Changes 'Select files' button behaviour on 'Games' tab: instead of selecting ROM files one-by-one you can choose folder to add every supported file at once.
75+
tab2_Cb_foldersSelectorForRomsDesc=Changes 'Select files' button behaviour on 'Games' tab: instead of selecting ROM files one-by-one you can choose folder to add every supported file at once.
76+
windowTitleAddingFiles=Searching for files...
77+
windowBodyFilesScanned=Files scanned: %d\nWould be added: %d

src/main/resources/locale_en_US.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ tab2_Cb_GlVersion=GoldLeaf version
7272
tab2_Cb_GLshowNspOnly=Show only *.nsp in GoldLeaf.
7373
windowBodyPleaseStopOtherProcessFirst=Please stop other active process before continuing.
7474
tab2_Cb_foldersSelectorForRoms=Select folder with ROM files instead of selecting ROMs individually.
75-
tab2_Cb_foldersSelectorForRomsDesc=Changes 'Select files' button behaviour on 'Games' tab: instead of selecting ROM files one-by-one you can choose folder to add every supported file at once.
75+
tab2_Cb_foldersSelectorForRomsDesc=Changes 'Select files' button behaviour on 'Games' tab: instead of selecting ROM files one-by-one you can choose folder to add every supported file at once.
76+
windowTitleAddingFiles=Searching for files...
77+
windowBodyFilesScanned=Files scanned: %d\nWould be added: %d

src/main/resources/locale_ru_RU.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ tab2_Cb_GlVersion=\u0412\u0435\u0440\u0441\u0438\u044F GoldLeaf
7171
windowBodyPleaseStopOtherProcessFirst=\u041F\u043E\u0436\u0430\u043B\u0443\u0439\u0441\u0442\u0430, \u043E\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0434\u0440\u0443\u0433\u043E\u0439 \u0430\u043A\u0442\u0438\u0432\u043D\u044B\u0439 \u043F\u0440\u043E\u0446\u0435\u0441\u0441 \u043F\u0435\u0440\u0435\u0434 \u0442\u0435\u043C, \u043A\u0430\u043A \u043F\u0440\u043E\u0434\u043E\u043B\u0436\u0438\u0442\u044C.
7272
tab2_Cb_foldersSelectorForRomsDesc=\u041C\u0435\u043D\u044F\u0435\u0442 \u043F\u043E\u0432\u0435\u0434\u0435\u043D\u0438\u0435 \u043A\u043D\u043E\u043F\u043A\u0438 "\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u0444\u0430\u0439\u043B\u044B" \u043D\u0430 \u0432\u043A\u043B\u0430\u0434\u043A\u0435 '\u0418\u0433\u0440\u044B'. \u0412\u043C\u0435\u0441\u0442\u043E \u0432\u044B\u0431\u043E\u0440\u0430 ROM \u0444\u0430\u0439\u043B\u043E\u0432 \u043F\u043E \u043E\u0434\u043D\u043E\u043C\u0443 \u0432\u044B \u0443\u043A\u0430\u0437\u044B\u0432\u0430\u0435\u0442\u0435 \u043F\u0430\u043F\u043A\u0443, \u043F\u043E\u0441\u043B\u0435 \u0447\u0435\u0433\u043E \u0432\u0441\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043C\u044B\u0435 \u043E\u0431\u0440\u0430\u0437\u044B \u0434\u043E\u0431\u0430\u0432\u043B\u044F\u044E\u0442\u0441\u044F.
7373
tab2_Cb_foldersSelectorForRoms=\u0412\u044B\u0431\u0438\u0440\u0430\u0442\u044C \u043F\u0430\u043F\u043A\u0443 \u0441 ROM \u0444\u0430\u0439\u043B\u0430\u043C\u0438 \u0432\u043C\u0435\u0441\u0442\u043E \u0432\u044B\u0431\u043E\u0440\u0430 \u0444\u0430\u0439\u043B\u043E\u0432 \u043F\u043E\u043E\u0434\u0438\u043D\u043E\u0447\u043A\u0435.
74+
windowTitleAddingFiles=\u0418\u0449\u0435\u043C \u0444\u0430\u0439\u043B\u044B...
75+
windowBodyFilesScanned=\u0424\u0430\u0439\u043B\u043E\u0432 \u043F\u0440\u043E\u0441\u043A\u0430\u043D\u0438\u0440\u043E\u0432\u0430\u043D\u043E: %d\n\u0418\u0437 \u043A\u043E\u0442\u043E\u0440\u044B\u0445 \u0431\u0443\u0434\u0435\u0442 \u0434\u043E\u0431\u0430\u0432\u043B\u0435\u043D\u043E: %d
7476

src/main/resources/locale_uk_UA.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ tab2_Cb_GlVersion=\u0412\u0435\u0440\u0441\u0456\u044F GoldLeaf
7171
windowBodyPleaseStopOtherProcessFirst=\u0411\u0443\u0434\u044C \u043B\u0430\u0441\u043A\u0430, \u0437\u0443\u043F\u0438\u043D\u0456\u0442\u044C \u0456\u043D\u0448\u0438\u0439 \u0430\u043A\u0442\u0438\u0432\u043D\u0438\u0439 \u043F\u0440\u043E\u0446\u0435\u0441 \u043F\u0435\u0440\u0448 \u043D\u0456\u0436 \u043F\u0440\u043E\u0434\u043E\u0432\u0436\u0438\u0442\u0438.
7272
tab2_Cb_foldersSelectorForRomsDesc=\u0417\u043C\u0456\u043D\u044E\u0454 \u043F\u043E\u0432\u0435\u0434\u0456\u043D\u043A\u0443 \u043A\u043D\u043E\u043F\u043A\u0438 \u043A\u043D\u043E\u043F\u043A\u0438 "\u0412\u0438\u0431\u0440\u0430\u0442\u0438 \u0444\u0430\u0439\u043B\u0438" \u043D\u0430 \u0432\u043A\u043B\u0430\u0434\u0446\u0456 '\u0406\u0433\u0440\u0438'. \u0417\u0430\u043C\u0456\u0441\u0442\u044C \u0432\u0438\u0431\u043E\u0440\u0443 ROM \u0444\u0430\u0439\u043B\u0456\u0432 \u043E\u0434\u0438\u043D \u0437\u0430 \u043E\u0434\u043D\u0438\u043C \u0432\u0438 \u0432\u043A\u0430\u0437\u0443\u0454\u0442\u0435 \u043F\u0430\u043F\u043A\u0443, \u043F\u0456\u0441\u043B\u044F \u0447\u043E\u0433\u043E \u0434\u043E\u0434\u0430\u044E\u0442\u044C\u0441\u044F \u0443\u0441\u0456 \u0444\u0430\u0439\u043B\u0438, \u0449\u043E \u043F\u0456\u0434\u0442\u0440\u0438\u043C\u0443\u044E\u0442\u044C\u0441\u044F.
7373
tab2_Cb_foldersSelectorForRoms=\u0412\u0438\u0431\u0438\u0440\u0430\u0442\u0438 \u043F\u0430\u043F\u043A\u0443 \u0437 ROM \u0444\u0430\u0439\u043B\u0430\u043C\u0438 \u0437\u0430\u043C\u0456\u0441\u0442\u044C \u0432\u0438\u0431\u043E\u0440\u0443 \u0444\u0430\u0439\u043B\u0456\u0432 \u043F\u043E\u043E\u0434\u0438\u043D\u0446\u0456.
74+
windowTitleAddingFiles=\u0428\u0443\u043A\u0430\u0454\u043C\u043E \u0444\u0430\u0439\u043B\u0438...
75+
windowBodyFilesScanned=\u0424\u0430\u0439\u043B\u0456\u0432 \u043F\u0440\u043E\u0441\u043A\u0430\u043D\u043E\u0432\u0430\u043D\u043E: %d\n\u0417 \u044F\u043A\u0438\u0445 \u0431\u0443\u0434\u0435 \u0434\u043E\u0434\u0430\u043D\u043E: %d

src/main/resources/res/app_dark.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
-fx-padding: 0.23em;
7979
}
8080

81+
.progress-indicator {
82+
-fx-progress-color: #00bce4;
83+
}
84+
8185
.dialog-pane {
8286
-fx-background-color: #4f4f4f;
8387
}
@@ -131,7 +135,7 @@
131135
}
132136

133137

134-
// -======================== TAB PANE =========================-
138+
/* -======================== TAB PANE =========================- */
135139
.tab-pane .tab SVGPath{
136140
-fx-fill: #f7fafa;
137141
}

0 commit comments

Comments
 (0)