1 |
package net.oni2.aeinstaller.backend.packages; |
2 |
|
3 |
import java.io.BufferedReader; |
4 |
import java.io.File; |
5 |
import java.io.FileInputStream; |
6 |
import java.io.FileNotFoundException; |
7 |
import java.io.IOException; |
8 |
import java.io.InputStreamReader; |
9 |
import java.util.HashSet; |
10 |
|
11 |
import net.oni2.aeinstaller.backend.Paths; |
12 |
|
13 |
/** |
14 |
* @author Christian Illy |
15 |
*/ |
16 |
public class Mod_Info { |
17 |
private double aeVersion = 0; |
18 |
private String name = ""; |
19 |
private String creator = ""; |
20 |
private EBSLInstallType bslInstallType = EBSLInstallType.NORMAL; |
21 |
private String version = ""; |
22 |
private String description = ""; |
23 |
|
24 |
private HashSet<Integer> incompatibilities = new HashSet<Integer>(); |
25 |
private HashSet<Integer> dependencies = new HashSet<Integer>(); |
26 |
private HashSet<Integer> unlockLevel = new HashSet<Integer>(); |
27 |
|
28 |
private File exeFile = null; |
29 |
private File iconFile = null; |
30 |
private String workingDir = "Base"; |
31 |
|
32 |
/** |
33 |
* @param f |
34 |
* Mod_Info.cfg |
35 |
* @param packageNumber |
36 |
* Package number this Mod_Info belongs to |
37 |
*/ |
38 |
public Mod_Info(File f, int packageNumber) { |
39 |
InputStreamReader isr = null; |
40 |
try { |
41 |
FileInputStream fstream = new FileInputStream(f); |
42 |
isr = new InputStreamReader(fstream); |
43 |
BufferedReader br = new BufferedReader(isr); |
44 |
String strLine; |
45 |
while ((strLine = br.readLine()) != null) { |
46 |
if (strLine.indexOf("->") < 1) |
47 |
continue; |
48 |
int pos = strLine.indexOf("//"); |
49 |
while (pos >= 0) { |
50 |
if ((pos < 6) |
51 |
|| !strLine.substring(pos - 5, pos).equals("http:")) { |
52 |
strLine = strLine.substring(0, pos); |
53 |
break; |
54 |
} else { |
55 |
pos = strLine.indexOf("//", pos + 1); |
56 |
} |
57 |
} |
58 |
String[] split = strLine.split("->", 2); |
59 |
String sName = split[0].trim(); |
60 |
String sVal = split[1].trim(); |
61 |
if (sName.equalsIgnoreCase("AEInstallVersion")) { |
62 |
aeVersion = Double.parseDouble(sVal); |
63 |
} else if (sName.equalsIgnoreCase("NameOfMod")) { |
64 |
name = sVal; |
65 |
} else if (sName.equalsIgnoreCase("Creator")) { |
66 |
creator = sVal; |
67 |
} else if (sName.equalsIgnoreCase("HasBsl")) { |
68 |
if (sVal.equalsIgnoreCase("addon")) |
69 |
bslInstallType = EBSLInstallType.ADDON; |
70 |
} else if (sName.equalsIgnoreCase("ModVersion")) { |
71 |
version = sVal; |
72 |
} else if (sName.equalsIgnoreCase("Readme")) { |
73 |
description = "<p>" + sVal.replaceAll("\\\\n", "<br>") |
74 |
+ "</p>"; |
75 |
} else if (sName.equalsIgnoreCase("DependsOn")) { |
76 |
String[] depsS = sVal.split(","); |
77 |
for (String s : depsS) { |
78 |
try { |
79 |
int dep = Integer.parseInt(s); |
80 |
dependencies.add(dep); |
81 |
} catch (NumberFormatException e) { |
82 |
System.err |
83 |
.format("Mod_Info of %05d does contain a non-number dependency: '%s'\n", |
84 |
packageNumber, s); |
85 |
} |
86 |
} |
87 |
} else if (sName.equalsIgnoreCase("IncompatibleWith")) { |
88 |
String[] confS = sVal.split(","); |
89 |
for (String s : confS) { |
90 |
try { |
91 |
int conf = Integer.parseInt(s); |
92 |
incompatibilities.add(conf); |
93 |
} catch (NumberFormatException e) { |
94 |
System.err |
95 |
.format("Mod_Info of %05d does contain a non-number incompatibility: '%s'\n", |
96 |
packageNumber, s); |
97 |
} |
98 |
} |
99 |
} else if (sName.equalsIgnoreCase("UnlockLevel")) { |
100 |
String[] levelsS = sVal.split(","); |
101 |
for (String s : levelsS) { |
102 |
try { |
103 |
int level = Integer.parseInt(s); |
104 |
unlockLevel.add(level); |
105 |
} catch (NumberFormatException e) { |
106 |
System.err |
107 |
.format("Mod_Info of %05d does contain a non-number UnlockLevel value: '%s'\n", |
108 |
packageNumber, s); |
109 |
} |
110 |
} |
111 |
} else if (sName.equalsIgnoreCase("ExeName")) { |
112 |
exeFile = new File(Paths.getEditionBasePath(), sVal); |
113 |
} else if (sName.equalsIgnoreCase("WorkingDir")) { |
114 |
workingDir = sVal; |
115 |
} else if (sName.equalsIgnoreCase("IconName")) { |
116 |
iconFile = new File(Paths.getEditionBasePath(), sVal); |
117 |
} |
118 |
} |
119 |
} catch (FileNotFoundException e) { |
120 |
} catch (IOException e) { |
121 |
e.printStackTrace(); |
122 |
} finally { |
123 |
if (isr != null) { |
124 |
try { |
125 |
isr.close(); |
126 |
} catch (IOException e) { |
127 |
// TODO Auto-generated catch block |
128 |
e.printStackTrace(); |
129 |
} |
130 |
} |
131 |
} |
132 |
} |
133 |
|
134 |
/** |
135 |
* @return the aeVersion |
136 |
*/ |
137 |
public double getAeVersion() { |
138 |
return aeVersion; |
139 |
} |
140 |
|
141 |
/** |
142 |
* @return the name |
143 |
*/ |
144 |
public String getName() { |
145 |
return name; |
146 |
} |
147 |
|
148 |
/** |
149 |
* @return the creator |
150 |
*/ |
151 |
public String getCreator() { |
152 |
return creator; |
153 |
} |
154 |
|
155 |
/** |
156 |
* @return the bslInstallType |
157 |
*/ |
158 |
public EBSLInstallType getBslInstallType() { |
159 |
return bslInstallType; |
160 |
} |
161 |
|
162 |
/** |
163 |
* @return the version |
164 |
*/ |
165 |
public String getVersion() { |
166 |
return version; |
167 |
} |
168 |
|
169 |
/** |
170 |
* @return the description |
171 |
*/ |
172 |
public String getDescription() { |
173 |
return description; |
174 |
} |
175 |
|
176 |
/** |
177 |
* @return the incompatibilities |
178 |
*/ |
179 |
public HashSet<Integer> getIncompatibilities() { |
180 |
return incompatibilities; |
181 |
} |
182 |
|
183 |
/** |
184 |
* @return the dependencies |
185 |
*/ |
186 |
public HashSet<Integer> getDependencies() { |
187 |
return dependencies; |
188 |
} |
189 |
|
190 |
/** |
191 |
* @return the unlockLevel |
192 |
*/ |
193 |
public HashSet<Integer> getUnlockLevel() { |
194 |
return unlockLevel; |
195 |
} |
196 |
|
197 |
/** |
198 |
* @return the exeFile |
199 |
*/ |
200 |
public File getExeFile() { |
201 |
return exeFile; |
202 |
} |
203 |
|
204 |
/** |
205 |
* @return the iconFile |
206 |
*/ |
207 |
public File getIconFile() { |
208 |
return iconFile; |
209 |
} |
210 |
|
211 |
/** |
212 |
* @return the workingDir |
213 |
*/ |
214 |
public String getWorkingDir() { |
215 |
return workingDir; |
216 |
} |
217 |
|
218 |
} |