Skip to content

Commit

Permalink
Change for #28
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Mar 24, 2015
1 parent baa9b3a commit 124895b
Showing 1 changed file with 58 additions and 37 deletions.
95 changes: 58 additions & 37 deletions moduleManager.cs
Expand Up @@ -518,15 +518,10 @@ public void StartLoad(bool blocking)

ready = false;

if (blocking)
{
IEnumerator fib = ProcessPatch();
while (fib.MoveNext())
{
}
}
else
StartCoroutine(ProcessPatch());
// DB check used to track the now fixed TextureReplacer corruption
//checkValues();

StartCoroutine(ProcessPatch(blocking), blocking);
}

public static void addPostPatchCallback(ModuleManagerPostPatchCallback callback)
Expand Down Expand Up @@ -564,17 +559,23 @@ private List<String> PrePatchInit()
List<AssemblyName> modsWithDup =
AssemblyLoader.loadedAssemblies.Select(a => (a.assembly.GetName())).ToList();

mods = new List<AssemblyName>();

foreach (AssemblyName a in modsWithDup)
mods = new List<string>();

string modlist = "compiling list of loaded mods...\nMod DLLs found:\n";

foreach (AssemblyLoader.LoadedAssembly mod in AssemblyLoader.loadedAssemblies)
{
if (!mods.Any(m => m.Name == a.Name))
mods.Add(a);
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(mod.assembly.Location);

AssemblyName assemblyName = mod.assembly.GetName();

modlist += " " + assemblyName.Name + " v" + assemblyName.Version + " / v" + fileVersionInfo.ProductVersion + "\n";

if (!mods.Contains(assemblyName.Name, StringComparer.OrdinalIgnoreCase))
mods.Add(assemblyName.Name);
}

string modlist = "compiling list of loaded mods...\nMod DLLs found:\n";
foreach (AssemblyName mod in mods)
modlist += " " + mod.Name + " v" + mod.Version + "\n";
modlist += "Non-DLL mods added:\n";
foreach (UrlDir.UrlConfig cfgmod in GameDatabase.Instance.root.AllConfigs)
{
Expand All @@ -591,13 +592,10 @@ private List<String> PrePatchInit()
{
string dependency = name.Substring(name.IndexOf(":FOR[") + 5);
dependency = dependency.Substring(0, dependency.IndexOf(']'));
if (mods.Find(a => RemoveWS(a.Name.ToUpper()).Equals(RemoveWS(dependency.ToUpper())))
== null)
if (!mods.Contains(dependency, StringComparer.OrdinalIgnoreCase))
{
// found one, now add it to the list.
AssemblyName newMod = new AssemblyName(dependency);
newMod.Name = dependency;
mods.Add(newMod);
mods.Add(dependency);
modlist += " " + dependency + "\n";
}
}
Expand All @@ -614,28 +612,50 @@ private List<String> PrePatchInit()
foreach (string subdir in Directory.GetDirectories(gameData))
{
string name = Path.GetFileName(subdir);
string upperName = RemoveWS(name.ToUpper());
if (mods.Find(a => RemoveWS(a.Name.ToUpper()) == upperName) == null)
string cleanName = RemoveWS(name);
if (!mods.Contains(cleanName, StringComparer.OrdinalIgnoreCase))
{
AssemblyName newMod = new AssemblyName(name);
newMod.Name = name;
mods.Add(newMod);
modlist += " " + name + "\n";
mods.Add(cleanName);
modlist += " " + cleanName + "\n";
}
}
log(modlist);

mods.Sort();

return excludePaths;

#endregion List of mods
}

private IEnumerator ProcessPatch()

Coroutine StartCoroutine(IEnumerator enumerator, bool blocking)
{
if (blocking)
{
while (enumerator.MoveNext()) {}
return null;
}
else
{
return StartCoroutine(enumerator);
}
}


private IEnumerator ProcessPatch(bool blocking)
{

AssemblyLoader.LoadedAssembly textureReplacer = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name.StartsWith("TextureReplacer", StringComparison.Ordinal));

IsCacheUpToDate();
yield return null;


#if DEBUG
useCache = false;
#endif

if (!useCache)
{
#region Check Needs
Expand All @@ -658,21 +678,22 @@ private IEnumerator ProcessPatch()
log("Applying patches");

// :First node
yield return StartCoroutine(ApplyPatch(excludePaths, ":FIRST"));
yield return StartCoroutine(ApplyPatch(excludePaths, ":FIRST"), blocking);

// any node without a :pass
yield return StartCoroutine(ApplyPatch(excludePaths, ":LEGACY"));
yield return StartCoroutine(ApplyPatch(excludePaths, ":LEGACY"), blocking);

foreach (AssemblyName mod in mods)
foreach (string mod in mods)
{
string upperModName = mod.Name.ToUpper();
yield return StartCoroutine(ApplyPatch(excludePaths, ":BEFORE[" + upperModName + "]"));
yield return StartCoroutine(ApplyPatch(excludePaths, ":FOR[" + upperModName + "]"));
yield return StartCoroutine(ApplyPatch(excludePaths, ":AFTER[" + upperModName + "]"));
string upperModName = mod.ToUpper();
yield return StartCoroutine(ApplyPatch(excludePaths, ":BEFORE[" + upperModName + "]"), blocking);
yield return StartCoroutine(ApplyPatch(excludePaths, ":FOR[" + upperModName + "]"), blocking);
yield return StartCoroutine(ApplyPatch(excludePaths, ":AFTER[" + upperModName + "]"), blocking);
}

// :Final node
yield return StartCoroutine(ApplyPatch(excludePaths, ":FINAL"));
yield return StartCoroutine(ApplyPatch(excludePaths, ":FINAL"), blocking);


PurgeUnused(excludePaths);

Expand Down Expand Up @@ -1057,7 +1078,7 @@ private bool CheckNeeds(ref string name)

bool not = orDependency[0] == '!';
string toFind = not ? orDependency.Substring(1) : orDependency;
bool found = mods.Find(a => a.Name.ToUpper() == toFind) != null;
bool found = mods.Contains(toFind, StringComparer.OrdinalIgnoreCase);

if (not == !found)
{
Expand Down

0 comments on commit 124895b

Please sign in to comment.