Skip to content

Commit 82ce113

Browse files
committed
Patched Receive not showing progress bar
1 parent 4c042a4 commit 82ce113

File tree

6 files changed

+92
-123
lines changed

6 files changed

+92
-123
lines changed

src/main/java/com/i_comit/windows/AES.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static void AESQuery(List<Path> paths, File dirFile, boolean AESBool, int
207207
if (toolMode == 2) {
208208
try {
209209
sendKey();
210-
Folder.list1Dir(2);
210+
Folder.prepareZipFile();
211211
Main.jLabel6.setVisible(true);
212212
Main.jLabel5.setVisible(true);
213213
Main.jRadioButton2.setVisible(false);
@@ -261,8 +261,7 @@ public static void AESQuery(List<Path> paths, File dirFile, boolean AESBool, int
261261
if (Login.sendKeyCheckBool) {
262262
try {
263263
AESMode = 0;
264-
Statics.fileIter = 0;
265-
Statics.fileCount = 0;
264+
resetStaticInts();
266265
paths = GUI.listAESPaths(sendFolder);
267266
fileCount = GUI.countFiles(sendFolder);
268267
zipFileCount = fileCount;
@@ -287,15 +286,12 @@ public static void AESQuery(List<Path> paths, File dirFile, boolean AESBool, int
287286
Main.jRadioButton2.setEnabled(true);
288287
}
289288
case 1 -> {
290-
GUI.t.interrupt();
291-
GUI.labelCutterThread(jAlertLabel, "no files to decrypt", 10, 20, 400, false);
292289
Main.jToggleButton1.setEnabled(true);
293290
Main.jRadioButton3.setEnabled(true);
294291
if (Login.sendKeyCheckBool) {
295292
try {
296293
AESMode = 0;
297-
Statics.fileIter = 0;
298-
Statics.fileCount = 0;
294+
resetStaticInts();
299295
paths = GUI.listAESPaths(sendFolder);
300296
fileCount = GUI.countFiles(sendFolder);
301297
zipFileCount = fileCount;
@@ -305,6 +301,9 @@ public static void AESQuery(List<Path> paths, File dirFile, boolean AESBool, int
305301
ex.printStackTrace();
306302
}
307303
Login.sendKeyCheckBool = false;
304+
} else {
305+
GUI.t.interrupt();
306+
GUI.labelCutterThread(jAlertLabel, "no files to decrypt", 10, 20, 400, false);
308307
}
309308
}
310309
}

src/main/java/com/i_comit/windows/Folder.java

+11-22
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,17 @@ public class Folder {
2727

2828
public static String sendFolderStr = "";
2929

30-
public static void list1Dir(int toolMode) throws IOException {
31-
switch (toolMode) {
32-
case 1 -> {
33-
//RECEIVE
34-
// Main.jRadioButton3.setEnabled(false);
35-
// unzipFile(Statics.zipFileName + ".i-cc", Statics.zipFileName.replaceAll(".i-cc", ""));
36-
// Main.toolBtnsBool(true);
37-
// Login.verifySendKey();
38-
}
39-
case 2 -> {
40-
//SEND
41-
sendFolderStr = Statics.sendFolder + "\\" + firstLastChar(Statics.recipientUsername) + LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddmmss"));
42-
zipFile(Statics.sendFolder, ".i-cc", sendFolderStr);
43-
GUI.resetProgressBar(Main.jProgressBar2);
44-
Main.toolBtnsBool(true);
45-
deleteDirectory(Statics.sendFolder.toFile());
46-
Main.jRadioButton2.setEnabled(true);
47-
Main.jRadioButton2.setSelected(false);
48-
Main.dragDrop.setVisible(false);
49-
GUI.getGB();
50-
}
51-
}
30+
public static void prepareZipFile() throws IOException {
31+
//SEND
32+
sendFolderStr = Statics.sendFolder + "\\" + firstLastChar(Statics.recipientUsername) + LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddmmss"));
33+
zipFile(Statics.sendFolder, ".i-cc", sendFolderStr);
34+
GUI.resetProgressBar(Main.jProgressBar2);
35+
Main.toolBtnsBool(true);
36+
deleteDirectory(Statics.sendFolder.toFile());
37+
Main.jRadioButton2.setEnabled(true);
38+
Main.jRadioButton2.setSelected(false);
39+
Main.dragDrop.setVisible(false);
40+
GUI.getGB();
5241
}
5342

5443
public static String firstLastChar(String username) {

src/main/java/com/i_comit/windows/GUI.java

+4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ public static void resetProgressBar(JProgressBar progressBar) {
145145
AudioPlayer.audioPlayerThread("aes-sfx.wav");
146146
switch (Statics.AESMode) {
147147
case 0 -> {
148+
GUI.t.interrupt();
148149
GUI.labelCutterThread(jAlertLabel, "encrypted " + Statics.fileIter + " files", 10, 20, 400, false);
149150
Main.jTextArea1.append("encrypted " + Statics.fileIter + " files at " + LocalTime.now().format(DateTimeFormatter.ofPattern("hh:ss a")) + "\n");
150151
}
151152
case 1 -> {
153+
GUI.t.interrupt();
152154
GUI.labelCutterThread(jAlertLabel, "decrypted " + Statics.fileIter + " files", 10, 20, 400, false);
153155
Main.jTextArea1.append("decrypted " + Statics.fileIter + " files at " + LocalTime.now().format(DateTimeFormatter.ofPattern("hh:ss a")) + "\n");
154156
}
@@ -184,10 +186,12 @@ public static void resetProgressBar(JProgressBar progressBar) {
184186
try {
185187
String fileName = new File(Folder.sendFolderStr).getName();
186188
if (Statics.toolMode == 2) {
189+
GUI.t.interrupt();
187190
GUI.labelCutterThread(jAlertLabel, "packaged " + fileName + ".i-cc", 10, 25, 500, false);
188191
Main.jTextArea1.append("packaged " + fileName + ".i-cc at " + LocalTime.now().format(DateTimeFormatter.ofPattern("hh:ss a")) + "\n");
189192
}
190193
if (Statics.toolMode == 1) {
194+
GUI.t.interrupt();
191195
GUI.labelCutterThread(jAlertLabel, "unpacked " + fileName + ".i-cc", 10, 25, 500, false);
192196
Main.jTextArea1.append("unpacked " + fileName + ".i-cc at " + LocalTime.now().format(DateTimeFormatter.ofPattern("hh:ss a")) + "\n");
193197
}

src/main/java/com/i_comit/windows/Login.java

+54-81
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public static boolean sendKeyCheck() throws IOException {
125125
if (!"".equals(recipientPassword)) {
126126
if (recipientUsername.length() >= 5 && recipientUsername.length() <= 10) {
127127
if (!recipientUsername.equals(Statics.recipientPassword)) {
128+
resetStaticInts();
128129
Hasher.hashedUsername = Hasher.getHash(recipientUsername, true);
129130
Hasher.hashedPassword = Hasher.getHash(recipientPassword, false);
130131
Main.jRadioButton2.setEnabled(false);
@@ -180,41 +181,12 @@ private static void receivePanelTools() {
180181
Main.jRadioButton3.setSelected(false);
181182
}
182183

183-
public static boolean receiveKeyCheck(String zipFileN) throws IOException {
184-
char[] password = Main.jPasswordField3.getPassword();
185-
if (GUI.t.isAlive()) {
186-
GUI.t.interrupt();
187-
}
188-
189-
zipFileName = zipFileN;
190-
System.out.println(Main.jList1.getSelectedValue());
191-
192-
recipientPassword = new String(password);
193-
if (Main.jList1.getSelectedValue() != null) {
194-
if (!"".equals(recipientPassword)) {
195-
Hasher.hashedUsername = Hasher.getHash(username, true);
196-
Hasher.hashedPassword = Hasher.getHash(recipientPassword, false);
197-
Main.jPasswordField3.setText("");
198-
Folder.list1Dir(1);
199-
} else {
200-
GUI.labelCutterThread(jAlertLabel, "please make a password", 20, 20, 1200, false);
201-
receivePanelTools();
202-
}
203-
} else {
204-
GUI.labelCutterThread(jAlertLabel, "please select a .i-cc file", 20, 20, 1200, false);
205-
receivePanelTools();
206-
Main.jPasswordField3.setText("");
207-
}
208-
return false;
209-
}
210-
211184
public static boolean verifySendKey(String zipFileN) {
212-
185+
boolean b = false;
213186
char[] password = Main.jPasswordField3.getPassword();
214187
if (GUI.t.isAlive()) {
215188
GUI.t.interrupt();
216189
}
217-
218190
zipFileName = zipFileN;
219191
System.out.println(Main.jList1.getSelectedValue());
220192

@@ -227,6 +199,57 @@ public static boolean verifySendKey(String zipFileN) {
227199
Main.jRadioButton3.setEnabled(false);
228200
unzipFile(Statics.zipFileName + ".i-cc", Statics.zipFileName.replaceAll(".i-cc", ""));
229201
Main.toolBtnsBool(true);
202+
try {
203+
BufferedReader brTest = new BufferedReader(new FileReader(zipFileName + "\\send.key"));
204+
String usernameRead = Hasher.readKey(brTest.readLine(), username);
205+
String passwordRead = Hasher.readKey(brTest.readLine(), recipientPassword);
206+
207+
BufferedReader brTest1 = new BufferedReader(new FileReader(keyFile));
208+
String usernameRead1 = Hasher.readKey(brTest1.readLine(), username);
209+
//
210+
if (usernameRead.equals(usernameRead1)) {
211+
System.out.println("USERNAME MATCH");
212+
if (passwordRead.equals(Hasher.getHash(recipientPassword, false))) {
213+
System.out.println("PASSWORD MATCH");
214+
resetStaticInts();
215+
jProgressBar1.setValue(Statics.fileIter);
216+
jProgressBar1.setValue(Statics.fileCount);
217+
AESMode = 1;
218+
fileCount = GUI.countFiles(receiveFolder);
219+
zipFileCount = fileCount;
220+
jProgressBar1.setMaximum(fileCount);
221+
AES.AESThread(listAESPaths(Paths.get(Statics.zipFileName)), Paths.get(Statics.zipFileName).toFile(), true, 1);
222+
Main.progressbarBool = false;
223+
b = true;
224+
} else {
225+
resetStaticInts();
226+
brTest.close();
227+
Folder.deleteDirectory(Paths.get(Statics.zipFileName).toFile());
228+
Paths.get(Statics.zipFileName).toFile().delete();
229+
GUI.labelCutterThread(jAlertLabel, "mismatched credentials", 20, 20, 1000, false);
230+
Main.jList1.clearSelection();
231+
receivePanelTools();
232+
Main.jPasswordField3.setText("");
233+
Main.jRadioButton3.setEnabled(true);
234+
Folder.listZipFiles();
235+
Main.toolBtnsBool(true);
236+
}
237+
} else {
238+
resetStaticInts();
239+
brTest.close();
240+
Folder.deleteDirectory(Paths.get(Statics.zipFileName).toFile());
241+
Paths.get(Statics.zipFileName).toFile().delete();
242+
GUI.labelCutterThread(jAlertLabel, "mismatched credentials", 20, 20, 1000, false);
243+
receivePanelTools();
244+
Main.jList1.clearSelection();
245+
Main.jPasswordField3.setText("");
246+
Main.jRadioButton3.setEnabled(true);
247+
Folder.listZipFiles();
248+
Main.toolBtnsBool(true);
249+
}
250+
} catch (IOException ex) {
251+
ex.printStackTrace();
252+
}
230253

231254
} else {
232255
GUI.labelCutterThread(jAlertLabel, "please make a password", 20, 20, 1200, false);
@@ -237,57 +260,7 @@ public static boolean verifySendKey(String zipFileN) {
237260
receivePanelTools();
238261
Main.jPasswordField3.setText("");
239262
}
240-
241-
try {
242-
BufferedReader brTest = new BufferedReader(new FileReader(zipFileName + "\\send.key"));
243-
String usernameRead = Hasher.readKey(brTest.readLine(), username);
244-
String passwordRead = Hasher.readKey(brTest.readLine(), recipientPassword);
245-
246-
BufferedReader brTest1 = new BufferedReader(new FileReader(keyFile));
247-
String usernameRead1 = Hasher.readKey(brTest1.readLine(), username);
248-
//
249-
if (usernameRead.equals(usernameRead1)) {
250-
System.out.println("USERNAME MATCH");
251-
if (passwordRead.equals(Hasher.getHash(recipientPassword, false))) {
252-
System.out.println("PASSWORD MATCH");
253-
Statics.fileIter = 0;
254-
Statics.fileCount = 0;
255-
jProgressBar1.setValue(Statics.fileIter);
256-
jProgressBar1.setValue(Statics.fileCount);
257-
AESMode = 1;
258-
fileCount = GUI.countFiles(receiveFolder);
259-
zipFileCount = fileCount;
260-
jProgressBar1.setMaximum(fileCount);
261-
AES.AESThread(listAESPaths(Paths.get(Statics.zipFileName)), Paths.get(Statics.zipFileName).toFile(), true, 1);
262-
return true;
263-
} else {
264-
brTest.close();
265-
Folder.deleteDirectory(Paths.get(Statics.zipFileName).toFile());
266-
Paths.get(Statics.zipFileName).toFile().delete();
267-
GUI.labelCutterThread(jAlertLabel, "mismatched credentials", 20, 20, 1000, false);
268-
Main.jList1.clearSelection();
269-
receivePanelTools();
270-
Main.jPasswordField3.setText("");
271-
Main.jRadioButton3.setEnabled(true);
272-
Folder.listZipFiles();
273-
Main.toolBtnsBool(true);
274-
}
275-
} else {
276-
brTest.close();
277-
Folder.deleteDirectory(Paths.get(Statics.zipFileName).toFile());
278-
Paths.get(Statics.zipFileName).toFile().delete();
279-
GUI.labelCutterThread(jAlertLabel, "mismatched credentials", 20, 20, 1000, false);
280-
receivePanelTools();
281-
Main.jList1.clearSelection();
282-
Main.jPasswordField3.setText("");
283-
Main.jRadioButton3.setEnabled(true);
284-
Folder.listZipFiles();
285-
Main.toolBtnsBool(true);
286-
}
287-
} catch (IOException ex) {
288-
ex.printStackTrace();
289-
}
290-
return false;
263+
return b;
291264
}
292265

293266
public static boolean verifyLogin() {

src/main/java/com/i_comit/windows/Main.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -1154,19 +1154,21 @@ private void jRadioButton2Evt(java.awt.event.ActionEvent evt) {//GEN-FIRST:event
11541154
zipIter = 0;
11551155
if (Login.sendKeyCheck()) {
11561156
this.setSize(780, 266);
1157+
} else {
1158+
this.setSize(780, 241);
11571159
}
11581160
} catch (IOException ex) {
11591161
ex.printStackTrace();
11601162
}
11611163
}//GEN-LAST:event_jRadioButton2Evt
11621164
//RECEIVE RADIO BTN
11631165
private void jRadioButton3Evt(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3Evt
1164-
try {
1165-
zipFileCount = 0;
1166-
zipIter = 0;
1167-
Login.receiveKeyCheck(receiveFolder + "\\" + jList1.getSelectedValue());
1168-
} catch (IOException ex) {
1169-
ex.printStackTrace();
1166+
zipFileCount = 0;
1167+
zipIter = 0;
1168+
if (Login.verifySendKey(receiveFolder + "\\" + jList1.getSelectedValue())) {
1169+
this.setSize(780, 266);
1170+
} else {
1171+
this.setSize(780, 241);
11701172
}
11711173
}//GEN-LAST:event_jRadioButton3Evt
11721174

src/main/java/com/i_comit/windows/Statics.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public class Statics {
5656

5757
public static int fileHideIter;
5858

59+
public static void resetStaticInts() {
60+
fileIter = 0;
61+
fileCount = 0;
62+
FileHider.fileCt = 0;
63+
fileHideIter = 0;
64+
}
65+
5966
public static void encryptFunction(Main main) {
6067
if (GUI.t.isAlive()) {
6168
GUI.t.interrupt();
@@ -184,7 +191,7 @@ public static void stopFunction() {
184191
if (GUI.t.isAlive()) {
185192
GUI.t.interrupt();
186193
}
187-
194+
resetStaticInts();
188195
switch (AESMode) {
189196
case 0 -> {
190197
jTextArea1.append("encryption of " + fileCount + " files stopped.\n");
@@ -193,11 +200,6 @@ public static void stopFunction() {
193200
jTextArea1.append("decryption of " + fileCount + " files stopped.\n");
194201
}
195202

196-
fileIter = 0;
197-
fileHideIter = 0;
198-
FileHider.fileCt = 0;
199-
fileCount = 0;
200-
201203
jButton2.setVisible(false);
202204
jTabbedPane1.setSelectedIndex(0);
203205
jProgressBar1.setValue(fileIter);
@@ -302,5 +304,5 @@ public static void collapseLogin(Main main) {
302304
main.setLocationRelativeTo(null);
303305
jScrollPane5.setVisible(true);
304306
}
305-
307+
306308
}

0 commit comments

Comments
 (0)