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