|
1 | 1 | package Server; |
2 | 2 |
|
| 3 | +import java.io.*; |
| 4 | + |
3 | 5 | public class StaticVariables { |
4 | | - public static final String logDefaultDir = "./log"; |
| 6 | + public static final String defaultInitFile = "./init.txt"; |
| 7 | + // ---------------------------- will be read from File ----------------------------// |
| 8 | + public static String logDefaultDir; |
| 9 | + public static String mapsDefaultDir; |
| 10 | + public static String ftpDefaultDir; |
| 11 | + |
| 12 | + public static boolean doesFTPServiceLog; |
| 13 | + public static boolean doesWebServiceLog; |
5 | 14 |
|
6 | | - public static final boolean doesFTPServiceLog = true; |
7 | | - public static final boolean doesWebServiceLog = true; |
| 15 | + public static int webPort; |
| 16 | + public static int ftpPort; |
8 | 17 |
|
| 18 | + // default values !!!! ALWAYS CHANGE IN FILE !!!! |
| 19 | + public static String standardUserName = "ohdmOffViewer"; |
| 20 | + public static String standardUserPassword = "H!3r0glyph Sat3llite Era$er"; |
| 21 | + // -------------------------------------------------------------------------------// |
9 | 22 | public static final String ftpLogFile = logDefaultDir + "/ftpLog.txt"; |
10 | 23 | public static final String webServiceLogFile = logDefaultDir + "/webServiceLog.txt"; |
11 | 24 |
|
12 | | - public static final String mapsDefalutDir = "./maps"; |
13 | | - public static final String osmDir = mapsDefalutDir + "/osm"; |
14 | | - public static final String mapDir = mapsDefalutDir + "/map"; |
| 25 | + public static final String osmDir = mapsDefaultDir + "/osm"; |
| 26 | + public static final String mapDir = mapsDefaultDir + "/map"; |
15 | 27 | public static final String ohdmDir = ""; |
16 | 28 |
|
17 | 29 | public static final String ftpServiceMapDir = mapDir; |
18 | | - public static final String ftpDefaultDir = "./ftp"; |
19 | 30 | public static final String ftpServiceUserPropertiesFile = ftpDefaultDir + "/userList.properties"; |
20 | 31 |
|
21 | | - public static final int ftpPort = 5000; |
22 | 32 |
|
23 | | - // will later be read from a File instead of being HardCoded |
24 | | - public static final String standardUserName = "ohdmOffViewer"; |
25 | | - public static final String standardUserPassword = "H!3r0glyph Sat3llite Era$er"; |
| 33 | + public static void init() { |
| 34 | + if (!new File(defaultInitFile).exists()) { |
| 35 | + giveStandardValues(); |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + BufferedReader dis = null; |
| 40 | + try { dis = new BufferedReader(new InputStreamReader(new FileInputStream(new File(defaultInitFile)))); } |
| 41 | + catch (FileNotFoundException e) { e.printStackTrace(); } |
| 42 | + |
| 43 | + // readString |
| 44 | + String readString = ""; |
| 45 | + try { while (dis.ready()) readString += dis.readLine() + "\n"; } |
| 46 | + catch (IOException e) { e.printStackTrace(); } |
| 47 | + |
| 48 | + // cleanup String |
| 49 | + String usableLines = ""; |
| 50 | + for (String s: readString.split("\n")) if (!(s.startsWith("//") || s.startsWith("[") || s.isEmpty())) usableLines += s + "\n"; |
| 51 | + |
| 52 | + // split names and values |
| 53 | + String[][] valuesSplit = new String[usableLines.split("\n").length][2]; |
| 54 | + for (int i = 0; i < usableLines.split("\n").length; i++) { |
| 55 | + valuesSplit[i][0] = usableLines.split("\n")[i].split("=")[0].trim(); |
| 56 | + valuesSplit[i][1] = usableLines.split("\n")[i].split("=")[1].trim(); |
| 57 | + } |
| 58 | + |
| 59 | + for (String[] s : |
| 60 | + valuesSplit) { |
| 61 | + assignValue(s); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + private static void giveStandardValues() { |
| 66 | + doesFTPServiceLog = true; |
| 67 | + doesWebServiceLog = true; |
| 68 | + |
| 69 | + logDefaultDir = "./log"; |
| 70 | + mapsDefaultDir = "./maps"; |
| 71 | + ftpDefaultDir = "./ftp"; |
| 72 | + |
| 73 | + webPort = 5001; |
| 74 | + ftpPort = 5000; |
| 75 | + |
| 76 | + standardUserName = "ohdmOffViewer"; |
| 77 | + standardUserPassword = "H!3r0glyph Sat3llite Era$er"; |
| 78 | + } |
| 79 | + |
| 80 | + private static void assignValue(String[] s) { |
| 81 | + switch (s[0]) { |
| 82 | + case "logDefaultDir": logDefaultDir = s[1]; break; |
| 83 | + |
| 84 | + case "mapsDefaultDir": mapsDefaultDir = s[1]; break; |
| 85 | + |
| 86 | + case "ftpDefaultDir": ftpDefaultDir = s[1]; break; |
| 87 | + |
| 88 | + case "doesFTPServiceLog": doesFTPServiceLog = Boolean.parseBoolean(s[1]); break; |
| 89 | + |
| 90 | + case "doesWebServiceLog": doesWebServiceLog = Boolean.parseBoolean(s[1]); break; |
| 91 | + |
| 92 | + case "webPort": try { webPort = Integer.parseInt(s[1]); } catch (NumberFormatException e) { webPort = 5001; } break; |
| 93 | + |
| 94 | + case "ftpPort": try { ftpPort = Integer.parseInt(s[1]); } catch (NumberFormatException e) { ftpPort = 5000; } break; |
| 95 | + |
| 96 | + case "standardUserName": standardUserName = s[1]; break; |
| 97 | + |
| 98 | + case "standardUserPassword": standardUserPassword = s[1]; break; |
26 | 99 |
|
| 100 | + default: |
| 101 | + System.err.println("couldn't find " + s[0] + " in list | Value = " + s[1]); |
| 102 | + } |
| 103 | + } |
27 | 104 | } |
0 commit comments