source: java/installer2/src/net/oni2/aeinstaller/backend/packages/Mod_Info.java@ 1088

Last change on this file since 1088 was 720, checked in by alloc, 12 years ago

AEI2: Looooots of refactorings for breaking out independent features into libraries

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