From 6869e584fea7ad811bd562e3693952d65d2f0599 Mon Sep 17 00:00:00 2001 From: Eusth Date: Mon, 8 Oct 2018 21:00:38 +0200 Subject: [PATCH] Refactor. --- IPA/PatchContext.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/IPA/PatchContext.cs b/IPA/PatchContext.cs index 8e4df88..36427ee 100644 --- a/IPA/PatchContext.cs +++ b/IPA/PatchContext.cs @@ -49,7 +49,7 @@ namespace IPA context.ProjectName = Path.GetFileNameWithoutExtension(context.Executable); context.DataPathDst = Path.Combine(context.ProjectRoot, context.ProjectName + "_Data"); context.ManagedPath = Path.Combine(context.DataPathDst, "Managed"); - context.EngineFile = Path.Combine(context.ManagedPath, (File.Exists(Path.Combine(context.ManagedPath, "UnityEngine.CoreModule.dll")) ? "UnityEngine.CoreModule.dll" : "UnityEngine.dll")); + context.EngineFile = DetermineEngineFile(context.ManagedPath, "UnityEngine.dll", "UnityEngine.CoreModule.dll"); context.AssemblyFile = Path.Combine(context.ManagedPath, "Assembly-Csharp.dll"); context.BackupPath = Path.Combine(Path.Combine(context.IPARoot, "Backups"), context.ProjectName); string shortcutName = string.Format("{0} (Patch & Launch)", context.ProjectName); @@ -59,5 +59,19 @@ namespace IPA return context; } + + private static string DetermineEngineFile(string basePath, params string[] candidates) + { + foreach(var candidate in candidates) + { + var fullPath = Path.Combine(basePath, candidate); + if(File.Exists(fullPath)) + { + return fullPath; + } + } + + throw new FileNotFoundException("Could not find engine DLL!"); + } } }