Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 4ea2275

Browse files
authored
Merge pull request #5 from Exund/developer
Fix dependencies version check
2 parents b9e2d67 + 4034b8d commit 4ea2275

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

ModLoader/Loader.cs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class Loader : MonoBehaviour
3434
/// </summary>
3535
public static GameObject root;
3636

37+
private static readonly Regex version_regex = new Regex(@"\bv([0-9]+)(\.([0-9]+|x)){2}\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
38+
3739
/// <summary>
3840
/// Current Modlaoder version
3941
/// </summary>
@@ -232,7 +234,7 @@ private bool loadDependencies(Dictionary<string, string[]> dependencies)
232234
bool versionFlag = false;
233235
foreach (string version in item.Value)
234236
{
235-
if (verifyVersion(dependency.Version, version))
237+
if (verifyVersion(version, dependency.Version))
236238
{
237239
versionFlag = true;
238240
break;
@@ -294,49 +296,45 @@ private void loadMod(SFSMod mod)
294296
/// <summary>
295297
/// Check the string of two versions to identify if they are the same
296298
/// </summary>
297-
/// <param name="version1">
299+
/// <param name="targetVersion">
298300
/// Version to check
299301
/// </param>
300-
/// <param name="version2">
302+
/// <param name="currentVersion">
301303
/// Verison to check
302304
/// </param>
303-
/// <param name="checkMinVersion">
304-
/// check if version 1 is is less than or equal to version 2
305+
/// <param name="lessOrEqual">
306+
/// Check if targetVersion is less than or equal to currentVersion
305307
/// </param>
306-
/// <returns>
307-
/// True if they are valid versions
308-
/// </returns>
309-
private bool verifyVersion(string version1, string version2, bool checkMinVersion = false)
308+
private bool verifyVersion(string targetVersion, string currentVersion, bool lessOrEqual = false)
310309
{
311-
Regex rx = new Regex(@"\bv([0-9]+)(\.([0-9]+|x)){2}\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
312310
// has the format v1.x.x
313-
if (rx.IsMatch(version1) && rx.IsMatch(version2))
311+
if (version_regex.IsMatch(targetVersion) && version_regex.IsMatch(currentVersion))
314312
{
315-
string[] target1 = version1.Split('.');
316-
string[] target2 = version2.Split('.');
317-
int num1, num2;
313+
string[] target = targetVersion.Split('.');
314+
string[] current = currentVersion.Split('.');
315+
318316
bool minor = false;
319-
if (target1.Length == target2.Length)
317+
if (target.Length == current.Length)
320318
{
321-
for (short index = 0; index < target2.Length; index++)
319+
for (short index = 0; index < current.Length; index++)
322320
{
323-
if (target1[index] == "x" || target1[index] == target2[index])
321+
if (target[index] == "x" || target[index] == current[index])
324322
{
325323
continue;
326324
}
327-
// check if version1 is MIN that version2
328-
if (checkMinVersion)
325+
// check if targetVersion is MIN that currentVersion
326+
if (lessOrEqual)
329327
{
330328
// the previous section was MIN, if it was min the rest are MIN too
331329
if (minor)
332330
{
333331
continue;
334332
}
335-
if (int.TryParse(target1[index], out num1))
333+
if (int.TryParse(target[index], out int num1))
336334
{
337-
if(int.TryParse(target2[index], out num2))
335+
if(int.TryParse(current[index], out int num2))
338336
{
339-
// the version1 section is MIN that version 2 section
337+
// the targetVersion section is MIN that version 2 section
340338
if(num1 < num2)
341339
{
342340
minor = true;

0 commit comments

Comments
 (0)