Ejemplo n.º 1
0
        public bool IsCompatible(PathGenericTuple <ModConfig> mod)
        {
            var modDirectory = Path.GetDirectoryName(mod.Path);

            ConfigPath = GameBananaConfig.GetFilePath(modDirectory);
            return(File.Exists(ConfigPath));
        }
 public ResolverManagerModResultPair(IModResolver resolver, IUpdateManager manager, CheckForUpdatesResult result, PathGenericTuple <ModConfig> modTuple)
 {
     Resolver = resolver;
     Manager  = manager;
     Result   = result;
     ModTuple = modTuple;
 }
        public void Construct(PathGenericTuple <ModConfig> mod)
        {
            _modTuple = mod;
            string path = GithubConfig.GetFilePath(GetModDirectory(mod));

            _githubConfig     = GithubConfig.FromPath(path);
            _githubUserConfig = GithubUserConfig.FromPath(path);
        }
Ejemplo n.º 4
0
        private ModInstance PrepareNativeMod(PathGenericTuple <IModConfig> tuple)
        {
            var modId   = tuple.Object.ModId;
            var dllPath = tuple.Object.GetNativeDllPath(tuple.Path);

            _modIdToFolder[modId] = Path.GetFullPath(Path.GetDirectoryName(tuple.Path));
            return(new ModInstance(new NativeMod(dllPath), tuple.Object));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the first appropriate resolver that can handle updating a mod.
        /// </summary>
        /// <param name="mod">The mod in question.</param>
        /// <returns>A resolver that can handle the mod, else null.</returns>
        public static IModResolver GetResolver(PathGenericTuple <ModConfig> mod)
        {
            foreach (var resolver in new ResolverCollection().Resolvers)
            {
                if (resolver.IsCompatible(mod))
                {
                    return(resolver);
                }
            }

            return(null);
        }
Ejemplo n.º 6
0
        public bool IsCompatible(PathGenericTuple <ModConfig> mod)
        {
            var packages = Task.Run(() => _nugetHelper.GetPackageDetails(mod.Object.ModId, false, true)).Result;

            if (!packages.Any())
            {
                return(false);
            }

            _packageMetadata = packages.Last();
            return(true);
        }
Ejemplo n.º 7
0
        private ModInstance PrepareNonDllMod(PathGenericTuple <IModConfig> tuple)
        {
            // If invalid file path, get directory.
            // If directory, use directory.
            if (Directory.Exists(tuple.Path))
            {
                _modIdToFolder[tuple.Object.ModId] = Path.GetFullPath(tuple.Path);
            }
            else
            {
                _modIdToFolder[tuple.Object.ModId] = Path.GetFullPath(Path.GetDirectoryName(tuple.Path));
            }

            return(new ModInstance(tuple.Object));
        }
Ejemplo n.º 8
0
        /* Mod Loading */

        /// <summary>
        /// Obtains an instance of an individual ready to load mod.
        /// To start an instance, call <see cref="StartMod"/>
        /// </summary>
        /// <exception cref="ArgumentException">Mod with specified ID is already loaded.</exception>
        /// <param name="tuple">A tuple of mod config and path to config.</param>
        private ModInstance GetModInstance(PathGenericTuple <IModConfig> tuple)
        {
            // Check if mod with ID already loaded.
            if (IsModLoaded(tuple.Object.ModId))
            {
                throw new ReloadedException(Errors.ModAlreadyLoaded(tuple.Object.ModId));
            }

            // Load DLL or non-dll mod.
            if (File.Exists(tuple.Object.GetDllPath(tuple.Path)))
            {
                return(tuple.Object.IsNativeMod(tuple.Path) ? PrepareNativeMod(tuple) : PrepareDllMod(tuple));
            }

            return(PrepareNonDllMod(tuple));
        }
        public bool IsCompatible(PathGenericTuple <ModConfig> mod)
        {
            try
            {
                if (Task.Run(AssertGithubOK).Result)
                {
                    string path = GithubConfig.GetFilePath(GetModDirectory(mod));

                    if (File.Exists(path) && AllowedMods.Contains(mod.Object))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception) { }

            return(false);
        }
Ejemplo n.º 10
0
        private ModInstance PrepareDllMod(PathGenericTuple <IModConfig> tuple)
        {
            var modId   = tuple.Object.ModId;
            var dllPath = tuple.Object.GetDllPath(tuple.Path);

            _modIdToFolder[modId] = Path.GetFullPath(Path.GetDirectoryName(tuple.Path));

            var loader = PluginLoader.CreateFromAssemblyFile(dllPath, _modIdToMetadata[modId].IsUnloadable, GetExportsForModConfig(tuple.Object), config => config.DefaultContext = _loadContext);

            var defaultAssembly = loader.LoadDefaultAssembly();
            var types           = defaultAssembly.GetTypes();
            var entryPoint      = types.FirstOrDefault(t => typeof(IModV1).IsAssignableFrom(t) && !t.IsAbstract);

            // Load entrypoint.
            var plugin = (IModV1)Activator.CreateInstance(entryPoint);

            return(new ModInstance(loader, plugin, tuple.Object));
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Obtains an image to represent a given mod, either a custom one or the default placeholder.
 /// </summary>
 public string GetImageForModConfig(PathGenericTuple <ModConfig> modConfig)
 {
     return(ModConfig.TryGetIconPath(modConfig.Path, modConfig.Object, out string iconPath) ? iconPath : Paths.PLACEHOLDER_IMAGE);
 }
Ejemplo n.º 12
0
 public ResolverModPair(IModResolver resolver, PathGenericTuple <ModConfig> modTuple)
 {
     Resolver = resolver;
     ModTuple = modTuple;
 }
 private static string GetModDirectory(PathGenericTuple <ModConfig> mod)
 {
     return(Path.GetDirectoryName(mod.Path));
 }
Ejemplo n.º 14
0
 public void Construct(PathGenericTuple <ModConfig> mod)
 {
     _modConfig = mod.Object;
 }
Ejemplo n.º 15
0
 public void Construct(PathGenericTuple <ModConfig> mod)
 {
     Mod    = mod;
     Config = GameBananaConfig.FromPath(ConfigPath);
 }