private DirectoryInfo GetDirectory(ModDirectoryType directoryType)
        {
            string path = null;

            switch (directoryType)
            {
            case ModDirectoryType.Meshes:        path = $@"{modPath}\meshes"; break;    //requires recursive iteration

            case ModDirectoryType.Textures:      path = $@"{modPath}\textures"; break;  //requires recursive iteration

            case ModDirectoryType.Sound:         path = $@"{modPath}\sound"; break;     //requires recursive iteration

            case ModDirectoryType.SourceScripts: path = $@"{modPath}\scripts\source"; break;

            case ModDirectoryType.Scripts:       path = $@"{modPath}\scripts"; break;

            case ModDirectoryType.SKSE:          path = $@"{modPath}\SKSE"; break;     //requires recursive iteration
            }

            DirectoryInfo directory = new DirectoryInfo(path);

            if (!directory.Exists)
            {
                throw new DirectoryNotFoundException($"{Name} does not contain a {directory.Name} directory.");
            }

            return(new DirectoryInfo(path));
        }
Beispiel #2
0
        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);
                    }
                }
            }
        }