1 | package net.oni2.aeinstaller.backend.mods;
|
---|
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 | // TODO
|
---|
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 | if (strLine.indexOf("//") >= 0)
|
---|
51 | strLine = strLine.substring(0, strLine.indexOf("//"));
|
---|
52 | String[] split = strLine.split("->", 2);
|
---|
53 | String sName = split[0].trim();
|
---|
54 | String sVal = split[1].trim();
|
---|
55 | if (sName.equalsIgnoreCase("AEInstallVersion")) {
|
---|
56 | aeVersion = Double.parseDouble(sVal);
|
---|
57 | } else if (sName.equalsIgnoreCase("NameOfMod")) {
|
---|
58 | name = sVal;
|
---|
59 | } else if (sName.equalsIgnoreCase("Creator")) {
|
---|
60 | creator = sVal;
|
---|
61 | } else if (sName.equalsIgnoreCase("HasBsl")) {
|
---|
62 | if (sVal.equalsIgnoreCase("addon"))
|
---|
63 | bslInstallType = EBSLInstallType.ADDON;
|
---|
64 | } else if (sName.equalsIgnoreCase("ModVersion")) {
|
---|
65 | version = sVal;
|
---|
66 | } else if (sName.equalsIgnoreCase("Readme")) {
|
---|
67 | description = sVal.replaceAll("\\\\n", "<br>");
|
---|
68 | } else if (sName.equalsIgnoreCase("DependsOn")) {
|
---|
69 | String[] depsS = sVal.split(",");
|
---|
70 | for (String s : depsS) {
|
---|
71 | try {
|
---|
72 | int dep = Integer.parseInt(s);
|
---|
73 | dependencies.add(dep);
|
---|
74 | } catch (NumberFormatException e) {
|
---|
75 | System.err
|
---|
76 | .format("Mod_Info of %05d does contain a non-number dependency: '%s'\n",
|
---|
77 | packageNumber, s);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | } else if (sName.equalsIgnoreCase("IncompatibleWith")) {
|
---|
81 | String[] confS = sVal.split(",");
|
---|
82 | for (String s : confS) {
|
---|
83 | try {
|
---|
84 | int conf = Integer.parseInt(s);
|
---|
85 | incompatibilities.add(conf);
|
---|
86 | } catch (NumberFormatException e) {
|
---|
87 | System.err
|
---|
88 | .format("Mod_Info of %05d does contain a non-number incompatibility: '%s'\n",
|
---|
89 | packageNumber, s);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | } else if (sName.equalsIgnoreCase("UnlockLevel")) {
|
---|
93 | String[] levelsS = sVal.split(",");
|
---|
94 | for (String s : levelsS) {
|
---|
95 | try {
|
---|
96 | int level = Integer.parseInt(s);
|
---|
97 | unlockLevel.add(level);
|
---|
98 | } catch (NumberFormatException e) {
|
---|
99 | System.err
|
---|
100 | .format("Mod_Info of %05d does contain a non-number UnlockLevel value: '%s'\n",
|
---|
101 | packageNumber, s);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | } else if (sName.equalsIgnoreCase("ExeName")) {
|
---|
105 | exeFile = new File(Paths.getEditionBasePath(), sVal);
|
---|
106 | } else if (sName.equalsIgnoreCase("WorkingDir")) {
|
---|
107 | workingDir = sVal;
|
---|
108 | } else if (sName.equalsIgnoreCase("IconName")) {
|
---|
109 | iconFile = new File(Paths.getEditionBasePath(), sVal);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | } catch (FileNotFoundException e) {
|
---|
113 | } catch (IOException e) {
|
---|
114 | e.printStackTrace();
|
---|
115 | } finally {
|
---|
116 | if (isr != null) {
|
---|
117 | try {
|
---|
118 | isr.close();
|
---|
119 | } catch (IOException e) {
|
---|
120 | // TODO Auto-generated catch block
|
---|
121 | e.printStackTrace();
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * @return the aeVersion
|
---|
129 | */
|
---|
130 | public double getAeVersion() {
|
---|
131 | return aeVersion;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * @return the name
|
---|
136 | */
|
---|
137 | public String getName() {
|
---|
138 | return name;
|
---|
139 | }
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * @return the creator
|
---|
143 | */
|
---|
144 | public String getCreator() {
|
---|
145 | return creator;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * @return the bslInstallType
|
---|
150 | */
|
---|
151 | public EBSLInstallType getBslInstallType() {
|
---|
152 | return bslInstallType;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * @return the version
|
---|
157 | */
|
---|
158 | public String getVersion() {
|
---|
159 | return version;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * @return the description
|
---|
164 | */
|
---|
165 | public String getDescription() {
|
---|
166 | return description;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * @return the incompatibilities
|
---|
171 | */
|
---|
172 | public HashSet<Integer> getIncompatibilities() {
|
---|
173 | return incompatibilities;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * @return the dependencies
|
---|
178 | */
|
---|
179 | public HashSet<Integer> getDependencies() {
|
---|
180 | return dependencies;
|
---|
181 | }
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * @return the unlockLevel
|
---|
185 | */
|
---|
186 | public HashSet<Integer> getUnlockLevel() {
|
---|
187 | return unlockLevel;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * @return the exeFile
|
---|
192 | */
|
---|
193 | public File getExeFile() {
|
---|
194 | return exeFile;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * @return the iconFile
|
---|
199 | */
|
---|
200 | public File getIconFile() {
|
---|
201 | return iconFile;
|
---|
202 | }
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * @return the workingDir
|
---|
206 | */
|
---|
207 | public String getWorkingDir() {
|
---|
208 | return workingDir;
|
---|
209 | }
|
---|
210 |
|
---|
211 | }
|
---|