Skip to content

Commit 6f9e273

Browse files
committed
Added Java version checking
1 parent 8bcd89d commit 6f9e273

5 files changed

Lines changed: 43 additions & 4 deletions

File tree

1.25 KB
Binary file not shown.

TFTP/Java/.executables/Scratch.jar

1.25 KB
Binary file not shown.

TFTP/Java/src/mains/Controller.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public void actionPerformed(ActionEvent e) {
121121
if(act.equals("EndProgram")) {
122122
if(this.gui.confirmDialog("Exit Program?","Exit Program",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
123123
u.printMessage(this.className, "actionPerformed(e): " + act, "Exiting program...");
124+
System.gc();
124125
System.exit(0);
125126
}
126127
}

TFTP/Java/src/mains/Driver.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mains;
22

33
import java.io.IOException;
4+
import java.util.Properties;
45
import java.util.Scanner;
56

67
import javax.swing.JOptionPane;
@@ -18,6 +19,19 @@ public class Driver {
1819
private static Controller c;
1920
public static void main(String[] args){
2021
u = new Utility();
22+
23+
Properties p = System.getProperties();
24+
String jre = p.getProperty("java.version");
25+
26+
if(jre.contains("."))
27+
jre = jre.substring(0,jre.indexOf('.'));
28+
29+
if(Integer.parseInt(jre) < 17) {
30+
int ans = new GUI().confirmDialog("The program was not tested for the version of Java installed (version " + jre + ").\nProgram requires at least Java 17.\nDo you want to continue?", "Java Compatibility Check", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
31+
if(ans == JOptionPane.NO_OPTION)
32+
exit(0);
33+
}
34+
2135
try {
2236
if(args.length > 0) {
2337
for(String a: args) {
@@ -29,7 +43,7 @@ public static void main(String[] args){
2943
Console();
3044
if(a.equals("-T") || a.equals("--testing")) {
3145
System.out.println("THIS FUNCTION IS DEPRECATED!\nEXITING...");
32-
System.exit(0);
46+
exit(0);
3347
Testing();
3448
}
3549
if(a.equals("-P") || a.equals("--production"))
@@ -41,7 +55,7 @@ public static void main(String[] args){
4155
Production();
4256
}catch(Exception e) {
4357
u.printMessage("Driver", "main()", "Error: " + e.getMessage());
44-
58+
exit(0);
4559
}
4660
}
4761

@@ -76,7 +90,6 @@ private static void Production() {
7690
}
7791
g.popDialog("Program Bugs:\n" + strBugs, "Bugs List", JOptionPane.WARNING_MESSAGE);
7892
}
79-
8093
}
8194

8295
private static void Console() {
@@ -86,7 +99,7 @@ private static void Console() {
8699
select = Menu(scan);
87100
cls();
88101
}while(select != 0);
89-
System.exit(0);
102+
exit(0);
90103
}
91104

92105
private static int Menu(Scanner scan) {
@@ -99,6 +112,11 @@ private static int Menu(Scanner scan) {
99112
return Integer.parseInt(scan.nextLine());
100113
}
101114

115+
private static void exit(int status) {
116+
System.gc();
117+
System.exit(status);
118+
}
119+
102120
//Reference: https://stackoverflow.com/a/38365871
103121
private static void cls() {
104122
try {

TFTP/Java/src/testing/Scratch.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
import java.io.*;
55
import java.nio.file.Files;
6+
import java.util.Properties;
67
import java.util.Scanner;
78

9+
import javax.swing.JOptionPane;
10+
811
import data.*;
12+
import gui.GUI;
913
import network.Client;
1014
import utils.*;
1115

@@ -19,12 +23,28 @@ public class Scratch {
1923
private static Scanner scan = null;
2024
private static String benchFile = "";
2125
public static void main(String[] args) {
26+
27+
Properties p = System.getProperties();
28+
String jre = p.getProperty("java.version");
29+
30+
if(jre.contains("."))
31+
jre = jre.substring(0,jre.indexOf('.'));
32+
33+
if(Integer.parseInt(jre) < 17) {
34+
System.out.println("The program was not tested for the version of Java installed (version \" + jre + \").\\nProgram requires at least Java 17.");
35+
System.exit(0);
36+
}
37+
38+
System.gc();
39+
2240
u.setState(true);
2341
scan = new Scanner(System.in);
2442
long time_diff = RunScratch();
2543
System.out.print("\nTesting time elapsed: " + (double)(time_diff/1000) + "seconds");
2644
//System.gc();
2745
scan.close();
46+
47+
System.gc();
2848
System.exit(0);
2949
}
3050

0 commit comments

Comments
 (0)