6
6
7
7
import static com .i_comit .windows .AES .decrypt ;
8
8
import static com .i_comit .windows .AES .encrypt ;
9
+ import static com .i_comit .windows .DragDrop .decFiles ;
10
+ import static com .i_comit .windows .DragDrop .encFiles ;
9
11
import static com .i_comit .windows .Main .jAlertLabel ;
10
- import static com .i_comit .windows .Memory . byteFormatter ;
12
+ import static com .i_comit .windows .Main . jProgressBar1 ;
11
13
import static com .i_comit .windows .Statics .*;
12
14
import java .io .*;
13
15
import java .nio .file .*;
@@ -32,10 +34,20 @@ public class AES {
32
34
33
35
public static Thread t ;
34
36
35
- public static void AESThread () {
37
+ // public static void AESThread() {
38
+ // t = new Thread(() -> {
39
+ // try {
40
+ // AES_T.AESQuery();
41
+ // } catch (InterruptedException ex) {
42
+ // ex.printStackTrace();
43
+ // }
44
+ // });
45
+ // t.start();
46
+ // }
47
+ public static void AESThread (List <Path > paths , boolean AESBool ) {
36
48
t = new Thread (() -> {
37
49
try {
38
- AES_T .AESQuery ();
50
+ AES_T .AESQuery (paths , AESBool );
39
51
} catch (InterruptedException ex ) {
40
52
ex .printStackTrace ();
41
53
}
@@ -81,6 +93,7 @@ public static void getFileAttr(File inputFile, File outputFile) throws IOExcepti
81
93
82
94
private static void doCrypto (int cipherMode , String key , File inputFile ,
83
95
File outputFile ) throws CryptoException {
96
+
84
97
try {
85
98
Key secretKey = new SecretKeySpec (key .getBytes (), ALGORITHM );
86
99
Cipher cipher = Cipher .getInstance (TRANSFORMATION );
@@ -102,13 +115,12 @@ private static void doCrypto(int cipherMode, String key, File inputFile,
102
115
System .gc ();
103
116
System .runFinalization ();
104
117
}
105
-
106
- int iterator = Statics .fileIter ++;
107
- float percentage = ((float ) iterator / AES_T .paths .size () * 100 );
118
+ fileIter ++;
119
+ float percentage = ((float ) fileIter / AES_T .paths .size () * 100 );
108
120
DecimalFormat format = new DecimalFormat ("0.#" );
109
121
String percentageStr = format .format (percentage );
110
- Main .jProgressBar1 .setValue ( iterator );
111
- Main .jProgressBar1 .setString ( percentageStr + "% | " + iterator + "/" + AES_T . paths . size () );
122
+ Main .jProgressBar1 .setString ( percentageStr + "% | " + fileIter + "/" + AES_T . paths . size () );
123
+ Main .jProgressBar1 .setValue ( fileIter );
112
124
GUI .loggerThread (outputFile );
113
125
getFileAttr (inputFile , outputFile );
114
126
@@ -146,23 +158,25 @@ public void run() {
146
158
147
159
public static List <Path > paths = null ;
148
160
149
- public static void AESQuery () throws InterruptedException {
150
- contents = directory .listFiles ();
151
- try {
152
- paths = listAESPaths (path );
161
+ public static void AESQuery (List <Path > paths , boolean AESBool ) throws InterruptedException {
162
+ AES_T .paths = paths ;
163
+ Main .jProgressBar1 .setString ("0% | " + "0/" + AES_T .paths .size ());
164
+ if (AESBool ) {
165
+ contents = directory .listFiles ();
166
+ // paths = listAESPaths(path);
153
167
if (contents != null ) {
154
168
if (contents .length != 0 ) {
155
169
if (!paths .isEmpty ()) {
156
170
Main .toolBtnsBool (false );
157
171
Main .jButton2 .setVisible (true );
158
172
Main .jTextArea5 .setVisible (false );
159
- switch (Statics . AESMode ) {
173
+ switch (AESMode ) {
160
174
case 0 -> {
161
175
Main .jProgressBar1 .setStringPainted (true );
162
176
GUI .labelCutterThread (jAlertLabel , "encrypting " + paths .size () + " files" , 0 , 15 , 300 );
163
177
paths .forEach (x -> {
164
178
try {
165
- if (x .toFile ().length () > 1024 * 32 ) {
179
+ if (x .toFile ().length () > maxFileBytes ) {
166
180
if (GUI .t .isAlive ()) {
167
181
GUI .t .interrupt ();
168
182
}
@@ -173,7 +187,7 @@ public static void AESQuery() throws InterruptedException {
173
187
} catch (AES .CryptoException ex ) {
174
188
}
175
189
});
176
- if (Statics . fileIter == 0 ) {
190
+ if (fileIter == 0 ) {
177
191
GUI .t .interrupt ();
178
192
GUI .labelCutterThread (jAlertLabel , "incorrect key" , 10 , 25 , 500 );
179
193
} else {
@@ -187,7 +201,7 @@ public static void AESQuery() throws InterruptedException {
187
201
GUI .labelCutterThread (jAlertLabel , "decrypting files..." , 0 , 15 , 300 );
188
202
paths .forEach (x -> {
189
203
try {
190
- if (x .toFile ().length () > 1024 * 32 ) {
204
+ if (x .toFile ().length () > maxFileBytes ) {
191
205
if (GUI .t .isAlive ()) {
192
206
GUI .t .interrupt ();
193
207
}
@@ -198,7 +212,7 @@ public static void AESQuery() throws InterruptedException {
198
212
} catch (AES .CryptoException ex ) {
199
213
}
200
214
});
201
- if (Statics . fileIter == 0 ) {
215
+ if (fileIter == 0 ) {
202
216
GUI .t .interrupt ();
203
217
GUI .labelCutterThread (jAlertLabel , "incorrect key" , 10 , 25 , 500 );
204
218
} else {
@@ -210,7 +224,7 @@ public static void AESQuery() throws InterruptedException {
210
224
211
225
} else {
212
226
if (!Main .jToggleButton1 .isSelected ()) {
213
- switch (Statics . AESMode ) {
227
+ switch (AESMode ) {
214
228
case 0 -> {
215
229
GUI .labelCutterThread (jAlertLabel , "no files to encrypt" , 10 , 20 , 400 );
216
230
}
@@ -229,8 +243,50 @@ public static void AESQuery() throws InterruptedException {
229
243
GUI .labelCutterThread (jAlertLabel , "i-ncript folder does not exist" , 20 , 40 , 800 );
230
244
Main .jToggleButton2 .setEnabled (true );
231
245
}
232
- } catch (IOException ex ) {
233
- //ex.printStackTrace();
246
+ } else {
247
+ jProgressBar1 .setMaximum (paths .size ());
248
+ jProgressBar1 .setStringPainted (true );
249
+ jProgressBar1 .setValue (fileIter );
250
+
251
+ paths .forEach (x -> {
252
+ try {
253
+ String fileStr = x .toString ();
254
+ File file = Paths .get (fileStr ).toFile ();
255
+ if (x .toString ().endsWith (".enc" ) || x .toString ().startsWith ("Thumbs.db" )) {
256
+ encFiles ++;
257
+ if (x .toFile ().length () > maxFileBytes ) {
258
+ if (GUI .t .isAlive ()) {
259
+ GUI .t .interrupt ();
260
+ }
261
+ Main .jProgressBar2 .setVisible (true );
262
+ Main .jAlertLabel .setText ("decrypting " + x .toFile ().getName ());
263
+ }
264
+ AES .decrypt (Hasher .modHash (password ), file , file );
265
+ }
266
+ if (!x .toString ().endsWith (".enc" )) {
267
+ decFiles ++;
268
+ if (x .toFile ().length () > maxFileBytes ) {
269
+ if (GUI .t .isAlive ()) {
270
+ GUI .t .interrupt ();
271
+ }
272
+ Main .jProgressBar2 .setVisible (true );
273
+ Main .jAlertLabel .setText ("encrypting " + x .toFile ().getName ());
274
+ }
275
+ AES .encrypt (Hasher .modHash (password ), file , file );
276
+ }
277
+ System .out .println ("ENC " + encFiles + " " + decFiles );
278
+ } catch (AES .CryptoException ex ) {
279
+ ex .printStackTrace ();
280
+ }
281
+ });
282
+
283
+ if (fileIter == 0 ) {
284
+ GUI .t .interrupt ();
285
+ GUI .labelCutterThread (Main .jAlertLabel , "incorrect key" , 10 , 25 , 500 );
286
+ } else {
287
+ DragDrop .resetProgressBar (encFiles , decFiles );
288
+ GUI .getGB ();
289
+ }
234
290
}
235
291
}
236
292
@@ -247,7 +303,7 @@ public static List<Path> listAESPaths(Path path) throws IOException {
247
303
248
304
List <Path > result = null ;
249
305
try ( Stream <Path > walk = Files .walk (path )) {
250
- switch (Statics . AESMode ) {
306
+ switch (AESMode ) {
251
307
case 0 ->
252
308
result = walk .filter (Files ::isRegularFile ).filter (p -> !p .getFileName ().toString ().endsWith (".enc" )).filter (p -> !p .getFileName ().toString ().startsWith ("Thumbs.db" ))
253
309
.collect (Collectors .toList ());
0 commit comments