1 /*
2 * Copyright (c) Patrick Magauran 2018.
3 * Licensed under the AGPLv3. All conditions of said license apply.
4 * This file is part of ABOS.
5 *
6 * ABOS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ABOS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with ABOS. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package ABOS.Derby;/*
21 Created by patrick on 4/16/15.
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 // load a properties file
38 prop.load(input);
39
40 // get the property value and print it out
41 //loc = prop.getProperty("databaseLocation");
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 //System.out.print(ex.getMessage());
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 //return true;
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 // load a properties file
82 prop.load(input);
83
84 // get the property value and print it out
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 //System.out.print(ex.getMessage());
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 // --Commented out by Inspection START (2/1/16 5:28 PM):
106 // public static void setDbLoc(String Loc) {
107 // Properties prop = new Properties();
108 // OutputStream output = null;
109 //
110 // try {
111 //
112 // output = new FileOutputStream("./LGconfig.properties");
113 //
114 // // set the properties value
115 // prop.setProperty("databaseLocation", Loc);
116 //
117 //
118 // // save properties to project root folder
119 // prop.store(output, null);
120 //
121 // } catch (IOException io) {
122 // io.printStackTrace();
123 // } finally {
124 // if (output != null) {
125 // try {
126 // output.close();
127 // } catch (IOException e) {
128 // e.printStackTrace();
129 // }
130 // }
131 //
132 // }
133 // }
134 // --Commented out by Inspection STOP (2/1/16 5:28 PM)
135
136 // --Commented out by Inspection START (1/25/16 10:13 AM):
137 // public static void setProp(String property, String setting) {
138 // Properties prop = new Properties();
139 // OutputStream output = null;
140 //
141 // try {
142 //
143 // output = new FileOutputStream("./LGconfig.properties");
144 //
145 // // set the properties value
146 // prop.setProperty(property, setting);
147 //
148 //
149 // // save properties to project root folder
150 // prop.store(output, null);
151 //
152 // } catch (IOException io) {
153 // io.printStackTrace();
154 // } finally {
155 // if (output != null) {
156 // try {
157 // output.close();
158 // } catch (IOException e) {
159 // e.printStackTrace();
160 // }
161 // }
162 //
163 // }
164 // }
165 // --Commented out by Inspection STOP (1/25/16 10:13 AM)
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 // load a properties file
176 prop.load(input);
177
178 // get the property value and print it out
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 //System.out.print(ex.getMessage());
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 //Add DB setting
208 prop.setProperty("databaseLocation", "");
209
210
211 //AddCustomer
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 //Maps
225 //Launchers.Reports
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 }