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

Last change on this file since 711 was 699, checked in by alloc, 12 years ago

AEI2 0.99t:

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