Пример #1
0
        CustomRepoMod[] GetMods(IEnumerable <Mod> networkMods)
        {
            var network = GetNetwork();

            return(Config.Mods
                   // TODO: Validate names on import and dont even save them
                   .Where(x => FileNameValidator.IsValidName(x.Key))
                   .Select(x => x.Value.ToMod(x.Key, network, networkMods))
                   .ToArray());
        }
Пример #2
0
        public static LocalMod FromStringIfValid(string modPath, ISupportModding game)
        {
            if (!(!string.IsNullOrWhiteSpace(modPath)))
            {
                throw new ArgumentNullException("!string.IsNullOrWhiteSpace(modPath)");
            }
            if (game == null)
            {
                throw new ArgumentNullException(nameof(game));
            }

            if (modPath.IsValidAbsoluteFilePath())
            {
                var filePath = modPath.ToAbsoluteFilePath();
                return(CreateLocalMod(filePath.FileName, filePath.ParentDirectoryPath, game));
            }

            if (modPath.IsValidAbsoluteDirectoryPath())
            {
                var dirPath = modPath.ToAbsoluteDirectoryPath();
                return(CreateLocalMod(dirPath.DirectoryName, dirPath.ParentDirectoryPath, game));
            }

            if (!FileNameValidator.IsValidName(modPath))
            {
                return(null);
            }

            // TODO: Horrible non-determinism; is it a file, is it a folder, is it located in the game or mod dir?
            var modPaths = game.ModPaths;

            if (modPaths.IsValid)
            {
                try {
                    if (modPaths.Path.GetChildDirectoryWithName(modPath).Exists)
                    {
                        return(CreateLocalMod(modPath, modPaths.Path, game));
                    }
                } catch (Exception) {}
                try {
                    if (modPaths.Path.GetChildFileWithName(modPath).Exists)
                    {
                        return(CreateLocalMod(modPath, modPaths.Path, game));
                    }
                } catch (Exception) {}
            }

            var installedState = game.InstalledState;

            if (installedState.IsInstalled)
            {
                try {
                    if (installedState.Directory.GetChildDirectoryWithName(modPath).Exists)
                    {
                        return(CreateLocalMod(modPath, installedState.Directory, game));
                    }
                } catch (Exception) {}
                try {
                    if (installedState.Directory.GetChildFileWithName(modPath).Exists)
                    {
                        return(CreateLocalMod(modPath, installedState.Directory, game));
                    }
                } catch (Exception) {}
            }

            return(CreateLocalMod(modPath, null, game));
        }