mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-14 15:15:05 -04:00
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..)
This commit is contained in:
parent
619a2b157e
commit
d8ea426fa4
11 changed files with 247 additions and 32 deletions
120
src/main/java/nsusbloader/Controllers/FilesDropHandle.java
Normal file
120
src/main/java/nsusbloader/Controllers/FilesDropHandle.java
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
Copyright 2019-2020 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Controllers;
|
||||
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.control.ProgressIndicator;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import nsusbloader.AppPreferences;
|
||||
import nsusbloader.MediatorControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class FilesDropHandle {
|
||||
|
||||
public FilesDropHandle(List<File> files, String filesRegex, String foldersRegex){
|
||||
|
||||
//
|
||||
// TODO: ADD GRAPHICS BEFORE RELEASE !
|
||||
//
|
||||
|
||||
FilesDropHandleTask filesDropHandleTask = new FilesDropHandleTask(files, filesRegex, foldersRegex);
|
||||
|
||||
ResourceBundle resourceBundle = MediatorControl.getInstance().getResourceBundle();
|
||||
Button cancelButton = new Button(resourceBundle.getString("btn_Cancel"));
|
||||
|
||||
ProgressIndicator progressIndicator = new ProgressIndicator();
|
||||
progressIndicator.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
|
||||
|
||||
Label downloadStatusLabel = new Label();
|
||||
downloadStatusLabel.setWrapText(true);
|
||||
downloadStatusLabel.textProperty().bind(filesDropHandleTask.messageProperty());
|
||||
|
||||
Pane fillerPane1 = new Pane();
|
||||
Pane fillerPane2 = new Pane();
|
||||
|
||||
VBox parentVBox = new VBox();
|
||||
parentVBox.setAlignment(Pos.TOP_CENTER);
|
||||
parentVBox.setFillWidth(true);
|
||||
parentVBox.setSpacing(5.0);
|
||||
parentVBox.setPadding(new Insets(5.0));
|
||||
parentVBox.setFillWidth(true);
|
||||
parentVBox.getChildren().addAll(
|
||||
downloadStatusLabel,
|
||||
fillerPane1,
|
||||
progressIndicator,
|
||||
fillerPane2,
|
||||
cancelButton
|
||||
); // TODO:FIX
|
||||
|
||||
VBox.setVgrow(fillerPane1, Priority.ALWAYS);
|
||||
VBox.setVgrow(fillerPane2, Priority.ALWAYS);
|
||||
|
||||
Stage stage = new Stage();
|
||||
stage.setTitle(resourceBundle.getString("windowTitleAddingFiles"));
|
||||
stage.getIcons().addAll(
|
||||
new Image("/res/dwnload_ico32x32.png"), //TODO: REDRAW
|
||||
new Image("/res/dwnload_ico48x48.png"),
|
||||
new Image("/res/dwnload_ico64x64.png"),
|
||||
new Image("/res/dwnload_ico128x128.png")
|
||||
);
|
||||
stage.setMinWidth(300);
|
||||
stage.setMinHeight(175);
|
||||
stage.setAlwaysOnTop(true);
|
||||
Scene mainScene = new Scene(parentVBox, 310, 185);
|
||||
|
||||
mainScene.getStylesheets().add(AppPreferences.getInstance().getTheme());
|
||||
|
||||
stage.setOnHidden(windowEvent -> filesDropHandleTask.cancel(true ) );
|
||||
|
||||
stage.setScene(mainScene);
|
||||
stage.show();
|
||||
stage.toFront();
|
||||
|
||||
filesDropHandleTask.setOnSucceeded(event -> {
|
||||
cancelButton.setText(resourceBundle.getString("btn_Close"));
|
||||
|
||||
List<File> allFiles = filesDropHandleTask.getValue();
|
||||
|
||||
if (! allFiles.isEmpty()) {
|
||||
MediatorControl.getInstance().getGamesController().tableFilesListController.setFiles(allFiles);
|
||||
}
|
||||
stage.close();
|
||||
});
|
||||
|
||||
new Thread(filesDropHandleTask).start();
|
||||
|
||||
cancelButton.setOnAction(actionEvent -> {
|
||||
filesDropHandleTask.cancel(true);
|
||||
stage.close();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
Copyright 2019-2020 Dmitry Isaenko
|
||||
|
||||
This file is part of NS-USBloader.
|
||||
|
||||
NS-USBloader is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
NS-USBloader is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package nsusbloader.Controllers;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
import nsusbloader.MediatorControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FilesDropHandleTask extends Task<List<File>> {
|
||||
private final String filesRegex;
|
||||
private final String foldersRegex;
|
||||
|
||||
private final List<File> filesDropped;
|
||||
private final List<File> allFiles;
|
||||
|
||||
private String messageTemplate;
|
||||
private long filesScanned = 0;
|
||||
private long filesAdded = 0;
|
||||
|
||||
FilesDropHandleTask(List<File> files,
|
||||
String filesRegex,
|
||||
String foldersRegex) {
|
||||
this.filesDropped = files;
|
||||
this.filesRegex = filesRegex;
|
||||
this.foldersRegex = foldersRegex;
|
||||
this.allFiles = new ArrayList<>();
|
||||
this.messageTemplate = MediatorControl.getInstance().getResourceBundle().getString("windowBodyFilesScanned");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<File> call() {
|
||||
if (filesDropped == null || filesDropped.size() == 0)
|
||||
return allFiles;
|
||||
|
||||
for (File file : filesDropped){
|
||||
if (isCancelled())
|
||||
return new ArrayList<>();
|
||||
collectFiles(file);
|
||||
updateMessage(String.format(messageTemplate, filesScanned++, filesAdded));
|
||||
}
|
||||
|
||||
return allFiles;
|
||||
}
|
||||
|
||||
private void collectFiles(File startFolder) {
|
||||
if (startFolder == null)
|
||||
return;
|
||||
|
||||
final String startFolderNameInLowercase = startFolder.getName().toLowerCase();
|
||||
|
||||
if (startFolder.isFile()) {
|
||||
if (startFolderNameInLowercase.matches(filesRegex)) {
|
||||
allFiles.add(startFolder);
|
||||
filesAdded++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (startFolderNameInLowercase.matches(foldersRegex)) {
|
||||
allFiles.add(startFolder);
|
||||
filesAdded++;
|
||||
return;
|
||||
}
|
||||
|
||||
File[] files = startFolder.listFiles();
|
||||
if (files == null)
|
||||
return;
|
||||
|
||||
for (File file : files) {
|
||||
if (isCancelled())
|
||||
return;
|
||||
collectFiles(file);
|
||||
updateMessage(String.format(messageTemplate, filesScanned++, filesAdded));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -41,10 +41,7 @@ import nsusbloader.ServiceWindow;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -294,6 +291,7 @@ public class GamesController implements Initializable {
|
|||
* @param filesRegex for filenames
|
||||
*/
|
||||
// TODO: Too sophisticated. Should be moved to simple class to keep things simplier
|
||||
|
||||
private void collectFiles(List<File> storage,
|
||||
File startFolder,
|
||||
final String filesRegex,
|
||||
|
@ -437,24 +435,10 @@ public class GamesController implements Initializable {
|
|||
* */
|
||||
@FXML
|
||||
private void handleDrop(DragEvent event) {
|
||||
final String regexForFiles = getRegexForFiles();
|
||||
final String regexForFolders = getRegexForFolders();
|
||||
|
||||
List<File> files = event.getDragboard().getFiles();
|
||||
|
||||
performInBackgroundAndUpdate(() -> {
|
||||
List<File> allFiles = new ArrayList<>();
|
||||
if (files != null && files.size() != 0) {
|
||||
files.forEach(f -> collectFiles(allFiles, f, regexForFiles, regexForFolders));
|
||||
}
|
||||
return allFiles;
|
||||
}, allFiles -> {
|
||||
if (!allFiles.isEmpty())
|
||||
tableFilesListController.setFiles(allFiles);
|
||||
|
||||
event.setDropCompleted(true);
|
||||
event.consume();
|
||||
});
|
||||
new FilesDropHandle(files, getRegexForFiles(), getRegexForFolders());
|
||||
event.setDropCompleted(true);
|
||||
event.consume();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -527,7 +511,6 @@ public class GamesController implements Initializable {
|
|||
selectSplitNspBtn.setVisible(true);
|
||||
}
|
||||
selectNspBtn.setGraphic(btnSelectImage);
|
||||
//selectFolderBtn.setTooltip(new Tooltip(resourceBundle.getString("btn_OpenFolders_tooltip")));
|
||||
}
|
||||
/**
|
||||
* Get 'Recent' path
|
||||
|
|
|
@ -231,7 +231,7 @@ public class NSTableViewController implements Initializable {
|
|||
/**
|
||||
* Add files when user selected them
|
||||
* */
|
||||
public void setFiles(List<File> newFiles){
|
||||
public synchronized void setFiles(List<File> newFiles){
|
||||
if (!rowsObsLst.isEmpty()){
|
||||
List<String> filesAlreayInList = new ArrayList<>();
|
||||
for (NSLRowModel model : rowsObsLst)
|
||||
|
|
|
@ -222,7 +222,6 @@ class TinFoil extends TransferModule {
|
|||
if ((currentOffset + chunk) >= size )
|
||||
chunk = Math.toIntExact(size - currentOffset);
|
||||
//System.out.println("CO: "+currentOffset+"\t\tEO: "+size+"\t\tRP: "+chunk); // NOTE: DEBUG
|
||||
logPrinter.updateProgress((currentOffset + chunk) / (size / 100.0) / 100.0);
|
||||
|
||||
readBuffer = new byte[chunk]; // TODO: not perfect moment, consider refactoring.
|
||||
|
||||
|
@ -232,6 +231,7 @@ class TinFoil extends TransferModule {
|
|||
if (writeUsb(readBuffer))
|
||||
throw new IOException("TF Failure during file transfer.");
|
||||
currentOffset += chunk;
|
||||
logPrinter.updateProgress((double)currentOffset / (double)size);
|
||||
}
|
||||
nsSplitReader.close();
|
||||
logPrinter.updateProgress(1.0);
|
||||
|
@ -251,7 +251,6 @@ class TinFoil extends TransferModule {
|
|||
if ((currentOffset + chunk) >= size)
|
||||
chunk = Math.toIntExact(size - currentOffset);
|
||||
//System.out.println("CO: "+currentOffset+"\t\tEO: "+receivedRangeSize+"\t\tRP: "+chunk); // NOTE: DEBUG
|
||||
logPrinter.updateProgress((currentOffset + chunk) / (size / 100.0) / 100.0);
|
||||
|
||||
readBuffer = new byte[chunk];
|
||||
|
||||
|
@ -261,6 +260,7 @@ class TinFoil extends TransferModule {
|
|||
if (writeUsb(readBuffer))
|
||||
throw new IOException("TF Failure during file transfer.");
|
||||
currentOffset += chunk;
|
||||
logPrinter.updateProgress((double)currentOffset / (double)size);
|
||||
}
|
||||
bufferedInStream.close();
|
||||
logPrinter.updateProgress(1.0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue