@@ -64,14 +64,19 @@ class GoldLeaf_08 extends TransferModule {
64
64
private long virtDriveSize ;
65
65
private HashMap <String , Long > splitFileSize ;
66
66
67
- private boolean isWindows ;
68
- private String homePath ;
67
+ private final boolean isWindows ;
68
+ private final String homePath ;
69
69
// For using in CMD_SelectFile with SPEC:/ prefix
70
70
private File selectedFile ;
71
71
72
- private CancellableRunnable task ;
72
+ private final CancellableRunnable task ;
73
73
74
- GoldLeaf_08 (DeviceHandle handler , LinkedHashMap <String , File > nspMap , CancellableRunnable task , ILogPrinter logPrinter , boolean nspFilter ){
74
+ GoldLeaf_08 (DeviceHandle handler ,
75
+ LinkedHashMap <String , File > nspMap ,
76
+ CancellableRunnable task ,
77
+ ILogPrinter logPrinter ,
78
+ boolean nspFilter )
79
+ {
75
80
super (handler , nspMap , task , logPrinter );
76
81
77
82
this .task = task ;
@@ -890,43 +895,42 @@ private boolean writeFile(String fileName) {
890
895
if (fileName .startsWith ("VIRT:/" )){
891
896
return writeGL_FAIL ("GL Handle 'WriteFile' command [not supported for virtual drive]" );
892
897
}
893
- else {
894
- fileName = updateHomePath (fileName );
895
- // Check if we didn't see this (or any) file during this session
896
- if (writeFilesMap .size () == 0 || (! writeFilesMap .containsKey (fileName ))){
897
- // Open what we have to open
898
- File writeFile = new File (fileName );
899
- // If this file exists GL will take care
900
- // Otherwise, let's add it
901
- try {
902
- BufferedOutputStream writeFileBufOutStream = new BufferedOutputStream (new FileOutputStream (writeFile , true ));
903
- writeFilesMap .put (fileName , writeFileBufOutStream );
904
- } catch (IOException ioe ){
905
- return writeGL_FAIL ("GL Handle 'WriteFile' command [IOException]\n \t " +ioe .getMessage ());
906
- }
907
- }
908
- // Now we have stream
909
- BufferedOutputStream myStream = writeFilesMap .get (fileName );
910
898
911
- byte [] transferredData ;
912
-
913
- if ((transferredData = readGL_file ()) == null ){
914
- logPrinter .print ("GL Handle 'WriteFile' command [1/1]" , EMsgType .FAIL );
915
- return true ;
916
- }
899
+ fileName = updateHomePath (fileName );
900
+ // Check if we didn't see this (or any) file during this session
901
+ if (writeFilesMap .size () == 0 || (! writeFilesMap .containsKey (fileName ))){
902
+ // Open what we have to open
903
+ File writeFile = new File (fileName );
904
+ // If this file exists GL will take care
905
+ // Otherwise, let's add it
917
906
try {
918
- myStream . write ( transferredData , 0 , transferredData . length );
919
- }
920
- catch (IOException ioe ){
921
- return writeGL_FAIL ("GL Handle 'WriteFile' command [1/1 ]\n \t " +ioe .getMessage ());
907
+ BufferedOutputStream writeFileBufOutStream = new BufferedOutputStream ( new FileOutputStream ( writeFile , true ) );
908
+ writeFilesMap . put ( fileName , writeFileBufOutStream );
909
+ } catch (IOException ioe ){
910
+ return writeGL_FAIL ("GL Handle 'WriteFile' command [IOException ]\n \t " +ioe .getMessage ());
922
911
}
923
- // Report we're good
924
- if (writeGL_PASS ()) {
925
- logPrinter .print ("GL Handle 'WriteFile' command" , EMsgType .FAIL );
926
- return true ;
927
- }
928
- return false ;
929
912
}
913
+ // Now we have stream
914
+ BufferedOutputStream myStream = writeFilesMap .get (fileName );
915
+
916
+ byte [] transferredData ;
917
+
918
+ if ((transferredData = readGL_file ()) == null ){
919
+ logPrinter .print ("GL Handle 'WriteFile' command [1/1]" , EMsgType .FAIL );
920
+ return true ;
921
+ }
922
+ try {
923
+ myStream .write (transferredData , 0 , transferredData .length );
924
+ }
925
+ catch (IOException ioe ){
926
+ return writeGL_FAIL ("GL Handle 'WriteFile' command [1/1]\n \t " +ioe .getMessage ());
927
+ }
928
+ // Report we're good
929
+ if (writeGL_PASS ()) {
930
+ logPrinter .print ("GL Handle 'WriteFile' command" , EMsgType .FAIL );
931
+ return true ;
932
+ }
933
+ return false ;
930
934
}
931
935
932
936
/**
@@ -938,27 +942,27 @@ private boolean selectFile(){
938
942
File selectedFile = CompletableFuture .supplyAsync (() -> {
939
943
FileChooser fChooser = new FileChooser ();
940
944
fChooser .setTitle (MediatorControl .getInstance ().getContoller ().getResourceBundle ().getString ("btn_OpenFile" )); // TODO: FIX BAD IMPLEMENTATION
941
- fChooser .setInitialDirectory (new File (System .getProperty ("user.home" ))); // TODO: Consider fixing; not a prio.
945
+ fChooser .setInitialDirectory (new File (System .getProperty ("user.home" )));// TODO: Consider fixing; not a prio.
942
946
fChooser .getExtensionFilters ().add (new FileChooser .ExtensionFilter ("*" , "*" ));
943
947
return fChooser .showOpenDialog (null ); // Leave as is for now.
944
948
}, Platform ::runLater ).join ();
945
949
946
- if (selectedFile != null ){
947
- List <byte []> command = new LinkedList <>();
948
- byte [] selectedFileNameBytes = ("SPEC:/" +selectedFile .getName ()).getBytes (StandardCharsets .UTF_16LE );
949
- command .add (intToArrLE (selectedFileNameBytes .length / 2 )); // since GL 0.7
950
- command .add (selectedFileNameBytes );
951
- if (writeGL_PASS (command )) {
952
- logPrinter .print ("GL Handle 'SelectFile' command" , EMsgType .FAIL );
953
- this .selectedFile = null ;
954
- return true ;
955
- }
956
- this .selectedFile = selectedFile ;
957
- return false ;
950
+ if (selectedFile == null ){ // Nothing selected
951
+ this .selectedFile = null ;
952
+ return writeGL_FAIL ("GL Handle 'SelectFile' command: Nothing selected" );
958
953
}
959
- // Nothing selected; Report failure.
960
- this .selectedFile = null ;
961
- return writeGL_FAIL ("GL Handle 'SelectFile' command: Nothing selected" );
954
+
955
+ List <byte []> command = new LinkedList <>();
956
+ byte [] selectedFileNameBytes = ("SPEC:/" +selectedFile .getName ()).getBytes (StandardCharsets .UTF_16LE );
957
+ command .add (intToArrLE (selectedFileNameBytes .length / 2 )); // since GL 0.7
958
+ command .add (selectedFileNameBytes );
959
+ if (writeGL_PASS (command )) {
960
+ logPrinter .print ("GL Handle 'SelectFile' command" , EMsgType .FAIL );
961
+ this .selectedFile = null ;
962
+ return true ;
963
+ }
964
+ this .selectedFile = selectedFile ;
965
+ return false ;
962
966
}
963
967
964
968
/*----------------------------------------------------*/
@@ -1039,9 +1043,7 @@ private byte[] readGL(){
1039
1043
return null ;
1040
1044
}
1041
1045
private byte [] readGL_file (){
1042
- ByteBuffer readBuffer ;
1043
- readBuffer = ByteBuffer .allocateDirect (8388608 ); // Just don't ask..
1044
-
1046
+ ByteBuffer readBuffer = ByteBuffer .allocateDirect (8388608 ); // Just don't ask..
1045
1047
IntBuffer readBufTransferred = IntBuffer .allocate (1 );
1046
1048
1047
1049
int result ;
0 commit comments