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