1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package ABOS.Derby;
21
22
23
24 import java.io.*;
25 import java.util.Properties;
26
27 class Config {
28
29 public static boolean doesConfExist() {
30 @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") Properties prop = new Properties();
31 InputStream input = null;
32 boolean loc = false;
33 try {
34
35 input = new FileInputStream("./LGconfig.properties");
36
37
38 prop.load(input);
39
40
41
42
43
44 } catch (FileNotFoundException ignored) {
45 return false;
46 } catch (IOException ex) {
47 if ("LGconfig.properties (No such file or directory)".equals(ex.getMessage())) {
48 return false;
49 } else {
50 LogToFile.log(ex, Severity.SEVERE, "Error reading config file state, ensure the software has access to the directory.");
51 }
52
53 } finally {
54 if (input != null) {
55 try {
56 input.close();
57 loc = true;
58 } catch (IOException e) {
59 LogToFile.log(e, Severity.WARNING, "");
60 }
61
62 }
63 if (input == null) {
64 loc = false;
65 }
66 }
67
68
69 return loc;
70
71 }
72
73 public static String getDbLoc() {
74 Properties prop = new Properties();
75 InputStream input = null;
76 String loc = "";
77 try {
78
79 input = new FileInputStream("./LGconfig.properties");
80
81
82 prop.load(input);
83
84
85 loc = prop.getProperty("databaseLocation");
86
87
88 } catch (IOException ex) {
89 LogToFile.log(ex, Severity.SEVERE, "Error reading config file, ensure the software has access to the directory.");
90
91 } finally {
92 if (input != null) {
93 try {
94 input.close();
95 } catch (IOException e) {
96 LogToFile.log(e, Severity.WARNING, "");
97 }
98 }
99 }
100
101
102 return loc;
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 public static String getProp(String property) {
168 Properties prop = new Properties();
169 InputStream input = null;
170 String loc = "";
171 try {
172
173 input = new FileInputStream("./LGconfig.properties");
174
175
176 prop.load(input);
177
178
179 loc = prop.getProperty(property);
180
181 } catch (IOException ex) {
182 LogToFile.log(ex, Severity.SEVERE, "Error reading config file, ensure the software has access to the directory.");
183
184
185 } finally {
186 if (input != null) {
187 try {
188 input.close();
189 } catch (IOException e) {
190 LogToFile.log(e, Severity.WARNING, "");
191
192 }
193 }
194 }
195
196
197 return loc;
198 }
199
200 public static void createConfigFile() {
201 Properties prop = new Properties();
202 OutputStream output = null;
203
204 try {
205 output = new FileOutputStream("./LGconfig.properties");
206
207
208 prop.setProperty("databaseLocation", "");
209
210
211
212 {
213 prop.setProperty("CustomerName", "");
214 prop.setProperty("CustomerAddress", "");
215 prop.setProperty("CustomerZipCode", "");
216 prop.setProperty("CustomerTown", "");
217 prop.setProperty("CustomerState", "");
218 prop.setProperty("CustomerPhone", "");
219 prop.setProperty("CustomerEmail", "");
220 prop.setProperty("CustomerPaid", "");
221 prop.setProperty("CustomerDelivered", "");
222 prop.setProperty("CustomerDonation", "");
223 }
224
225
226 {
227 prop.setProperty("ReportType", "");
228 prop.setProperty("ScoutName", "");
229 prop.setProperty("ScoutAddress", "");
230 prop.setProperty("ScoutZip", "");
231 prop.setProperty("ScoutTown", "");
232 prop.setProperty("ScoutState", "");
233 prop.setProperty("ScoutPhone", "");
234
235 prop.setProperty("ScoutRank", "");
236 prop.setProperty("logoLoc", "");
237 prop.setProperty("pdfLoc", "");
238
239 }
240 prop.store(output, null);
241
242 } catch (IOException io) {
243 LogToFile.log(io, Severity.SEVERE, "Error writing settings file. Please try again.");
244 } finally {
245 if (output != null) {
246 try {
247 output.close();
248 } catch (IOException e) {
249 LogToFile.log(e, Severity.SEVERE, "Error closing settings file. Please try again.");
250 }
251 }
252
253 }
254 }
255 }