Skip to content

Commit 10a10f5

Browse files
committed
Spore ModAPI Easy Installer: lock version/depends/dependsVersions behind installerSystemVersion 1.0.1.3
1 parent 2e17074 commit 10a10f5

File tree

1 file changed

+77
-62
lines changed

1 file changed

+77
-62
lines changed

Spore ModAPI Easy Installer/XmlInstallerWindow.xaml.cs

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ private void PrepareInstaller()
157157
if ((ModInfoVersion == new Version(1, 0, 0, 0)) ||
158158
(ModInfoVersion == new Version(1, 0, 1, 0)) ||
159159
(ModInfoVersion == new Version(1, 0, 1, 1)) ||
160-
(ModInfoVersion == new Version(1, 0, 1, 2)))
160+
(ModInfoVersion == new Version(1, 0, 1, 2)) ||
161+
(ModInfoVersion == new Version(1, 0, 1, 3)))
161162
{
162163
if (File.Exists(Path.Combine(ModConfigPath, "Branding.png")))
163164
{
@@ -185,7 +186,8 @@ private void PrepareInstaller()
185186
}
186187
else if ((ModInfoVersion == new Version(1, 0, 1, 0)) ||
187188
(ModInfoVersion == new Version(1, 0, 1, 1)) ||
188-
(ModInfoVersion == new Version(1, 0, 1, 2)))
189+
(ModInfoVersion == new Version(1, 0, 1, 2)) ||
190+
(ModInfoVersion == new Version(1, 0, 1, 3)))
189191
{
190192
_dontUseLegacyPackagePlacement = true;
191193
_installerMode = 1;
@@ -246,85 +248,98 @@ private void PrepareInstaller()
246248
else
247249
ModDescription = string.Empty;
248250

249-
if (Document.SelectSingleNode("/mod").Attributes["version"] != null)
251+
// installerSystemVersion 1.0.1.3 introduced the version, depends and dependsVersion attributes
252+
if (ModInfoVersion == new Version(1, 0, 1, 3))
250253
{
251-
if (Version.TryParse(Document.SelectSingleNode("/mod").Attributes["version"].Value, out Version parsedVersion))
252-
ModVersion = parsedVersion;
254+
if (Document.SelectSingleNode("/mod").Attributes["version"] != null)
255+
{
256+
if (Version.TryParse(Document.SelectSingleNode("/mod").Attributes["version"].Value, out Version parsedVersion))
257+
ModVersion = parsedVersion;
258+
else
259+
throw new Exception("This mod has an invalid version. Please inform the mod's developer of this.");
260+
}
253261
else
254-
throw new Exception("This mod has an invalid version. Please inform the mod's developer of this.");
255-
}
256-
else
257-
ModVersion = null;
262+
ModVersion = null;
258263

259-
if (Document.SelectSingleNode("/mod").Attributes["depends"] != null)
260-
{
261-
string dependsString = Document.SelectSingleNode("/mod").Attributes["depends"].Value;
262-
string dependsVersionString = null;
263-
if (Document.SelectSingleNode("/mod").Attributes["dependsVersions"] != null)
264-
dependsVersionString = Document.SelectSingleNode("/mod").Attributes["dependsVersions"].Value;
265-
string[] dependsUniqueNames = dependsString.Split('?');
266-
string[] dependsVersions = dependsVersionString == null ? null : dependsVersionString.Split('?');
267-
bool[] foundDepends = new bool[dependsUniqueNames.Length];
268-
// reset foundDepends
269-
for (int i = 0; i < foundDepends.Length; i++)
270-
foundDepends[i] = false;
271-
272-
ModDependencies = dependsUniqueNames.ToList();
273-
if (dependsVersions != null)
274-
{ // TODO: improve this logic...
275-
foreach (string dependsVersion in dependsVersions)
264+
if (Document.SelectSingleNode("/mod").Attributes["depends"] != null)
265+
{
266+
string dependsString = Document.SelectSingleNode("/mod").Attributes["depends"].Value;
267+
string dependsVersionString = null;
268+
if (Document.SelectSingleNode("/mod").Attributes["dependsVersions"] != null)
269+
dependsVersionString = Document.SelectSingleNode("/mod").Attributes["dependsVersions"].Value;
270+
string[] dependsUniqueNames = dependsString.Split('?');
271+
string[] dependsVersions = dependsVersionString?.Split('?');
272+
bool[] foundDepends = new bool[dependsUniqueNames.Length];
273+
274+
ModDependencies = dependsUniqueNames.ToList();
275+
if (dependsVersions != null)
276276
{
277-
if (Version.TryParse(dependsVersion, out Version parsedDependsVersion))
277+
foreach (string dependsVersion in dependsVersions)
278278
{
279-
ModDependenciesVersions.Add(parsedDependsVersion);
279+
if (String.IsNullOrEmpty(dependsVersion))
280+
{ // 0.0.0.0 is interpreted as having no version attribute
281+
// but we need to pad the list to match the amount of items
282+
// that ModDependencies has
283+
ModDependenciesVersions.Add(new Version(0, 0, 0, 0));
284+
}
285+
else
286+
{
287+
if (Version.TryParse(dependsVersion, out Version parsedDependsVersion))
288+
{
289+
ModDependenciesVersions.Add(parsedDependsVersion);
290+
}
291+
else
292+
{
293+
throw new Exception($"This mod has an invalid deoendsVersions entry: \"{dependsVersion}\". Please inform the mod's developer of this.");
294+
}
295+
}
280296
}
281297
}
282-
}
283298

284-
foreach (ModConfiguration mod in configs)
285-
{
286-
for (int i = 0; i < dependsUniqueNames.Length; i++)
299+
foreach (ModConfiguration mod in configs)
287300
{
288-
if (mod.Unique == dependsUniqueNames[i])
301+
for (int i = 0; i < dependsUniqueNames.Length; i++)
289302
{
290-
if (mod.Version != null &&
291-
(dependsVersions != null) &&
292-
(dependsVersions.Length > i) &&
293-
(Version.TryParse(dependsVersions[i], out Version dependVersion) &&
294-
mod.Version >= dependVersion))
295-
{ // name + version match
296-
foundDepends[i] = true;
297-
break;
298-
}
299-
else if (dependsVersions == null || dependsVersions.Length <= i)
300-
{ // name only match
301-
foundDepends[i] = true;
302-
break;
303+
if (mod.Unique == dependsUniqueNames[i])
304+
{
305+
if (mod.Version != null &&
306+
(ModDependenciesVersions.Count() > i) &&
307+
(mod.Version >= ModDependenciesVersions[i]))
308+
{ // name + version match
309+
foundDepends[i] = true;
310+
break;
311+
}
312+
else if (ModDependenciesVersions.Count() <= i ||
313+
ModDependenciesVersions[i] == new Version(0, 0, 0, 0))
314+
{ // name only match
315+
foundDepends[i] = true;
316+
break;
317+
}
303318
}
304319
}
305320
}
306-
}
307321

308-
bool satisfiedDepends = true;
309-
List<string> missingDepends = new List<string>();
310-
for (int i = 0; i < foundDepends.Length; i++)
311-
{
312-
if (!foundDepends[i])
322+
bool satisfiedDepends = true;
323+
List<string> missingDepends = new List<string>();
324+
for (int i = 0; i < foundDepends.Length; i++)
313325
{
314-
satisfiedDepends = false;
315-
string missingDependsText = dependsUniqueNames[i];
316-
if (dependsVersions != null &&
317-
dependsVersions.Length > i)
326+
if (!foundDepends[i])
318327
{
319-
missingDependsText += " " + dependsVersions[i];
328+
satisfiedDepends = false;
329+
string missingDependsText = dependsUniqueNames[i];
330+
if (dependsVersions != null &&
331+
dependsVersions.Length > i)
332+
{
333+
missingDependsText += " " + dependsVersions[i];
334+
}
335+
missingDepends.Add(missingDependsText);
320336
}
321-
missingDepends.Add(missingDependsText);
322337
}
323-
}
324338

325-
if (!satisfiedDepends)
326-
{
327-
throw new Exception($"This mod has dependencies that you don't have installed: {String.Join(", ", missingDepends)}");
339+
if (!satisfiedDepends)
340+
{
341+
throw new Exception($"This mod has dependencies that you don't have installed: {String.Join(", ", missingDepends)}");
342+
}
328343
}
329344
}
330345

0 commit comments

Comments
 (0)