public void Patch(MergeOrder order, List <string> modFilter = null) { var cache = InitializeCache(); var modsProcessed = ProcessMods(cache, order, modFilter); if (modsProcessed > 0) { ProcessBinDir(mBinDir, cache); } else { mLogger.Warning("No mods available to install"); } if (!PathHelper.AreEqual(mConfiguration.BinDir, mConfiguration.OutDir)) { // Copy bin directory contents to out directory mBinDir.CopyDirectory(".", mOutDir, ".", true); } mLogger.Information("Patching done!"); }
private void ProcessModDir(ModInfo modInfo, IFileSystem modFilesDir, Cache cache, string dir, ModDirectoryType dirType) { foreach (var entryName in modFilesDir.EnumerateFileSystemEntries(dir, "*.*", SearchOption.TopDirectoryOnly)) { if (modFilesDir.FileExists(entryName)) { if (dirType != ModDirectoryType.Archive) { // Copy file to out directory modFilesDir.CopyFile(entryName, mBinDir, entryName, true); } } else { if (cache.ContainerDirs.ContainsKey(entryName)) { // This directory is a container var containerType = cache.ContainerDirs[entryName]; var modContainerInfo = modInfo.Containers.FirstOrDefault(x => PathHelper.AreEqual(x.Path, entryName)); var mergeContents = modContainerInfo == null || modContainerInfo.Merge; switch (containerType) { case ContainerType.ARC: { if (mergeContents && !mBinDir.DirectoryExists(entryName)) { // Copy original files from cache to out directory Debug.Assert(mCacheFilesDir.DirectoryExists(entryName)); mCacheFilesDir.CopyDirectory(entryName, mBinDir, entryName, true); } // Overwrite the files in the out directory modFilesDir.CopyDirectory(entryName, mBinDir, entryName, true); // Recurse into contents of archive var arcRootDir = modFilesDir.EnumerateDirectories(entryName, "*.*", SearchOption.TopDirectoryOnly).SingleOrDefault(); if (arcRootDir == null) { throw new InvalidOperationException($"Unable to determine archive root directory for {entryName}. Make sure there is only 1 directory inside."); } ProcessModDir(modInfo, modFilesDir, cache, arcRootDir, ModDirectoryType.Archive); } break; case ContainerType.AW: { // Overwrite the files in the out directory modFilesDir.CopyDirectory(entryName, mBinDir, entryName, true); } break; default: break; } } else { // Recurse ProcessModDir(modInfo, modFilesDir, cache, entryName, ModDirectoryType.Normal); } } } }