public static ModDownloadResult?HandleModDownload(IDomain domain, string modIdentifier, string modVersion = null) { IDomainHandler handler = domain.GetDomainHandler(); // Fetch the mod version information from the Curseforge API try { ModMetadata meta = handler.GetModMetadata(Modifi.DefaultPack.MinecraftVersion, modIdentifier).Result; ModVersion mod = handler.GetModVersion(meta, modVersion).Result; return(handler.DownloadMod(mod, Settings.ModPath).Result); } catch (Exception) { return(null); } }
public static void HandleModAdd(IDomain domain, string modIdentifier, string modVersion = null) { IDomainHandler handler = domain.GetDomainHandler(); ModMetadata meta = handler.GetModMetadata(Modifi.DefaultPack.MinecraftVersion, modIdentifier).Result; // Check mod installation status, error out if already requested/installed using (IModStorage storage = new ModStorage(Modifi.DefaultPack.Installed, domain)) { try { ModStatus status = storage.GetModStatus(meta); switch (status) { case ModStatus.Requested: case ModStatus.Installed: Modifi.DefaultLogger.Error("Mod {0} is already marked as requested, or already installed.", meta.GetName()); return; case ModStatus.Disabled: Modifi.DefaultLogger.Information("Mod {0} is marked at disabled. Please either delete it, or re-enable it."); return; } } catch (Exception e) { Modifi.DefaultLogger.Error(e.Message); return; } } // If the version is already specified, don't ask, just add it if (!String.IsNullOrEmpty(modVersion)) { ModVersion v = handler.GetModVersion(meta, modVersion).Result; // Connect to storage and mark the mod as requested using (ModStorage storage = new ModStorage(Modifi.DefaultPack.MinecraftVersion, domain)) { storage.MarkRequested(meta, v); return; } } // ============================================================ // TODO: ModHelper.PrintModInformation(meta); Menu <ModVersion> menu = new Menu <ModVersion>(); menu.OptionFormatter = (opt) => { Console.ForegroundColor = ConsoleColor.Green; Console.Write(opt.GetVersionName()); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.Write(" ["); Console.ForegroundColor = ConsoleColor.White; Console.Write(opt.GetModVersion()); Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.Write("]"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write(" [{0}]", opt.GetReleaseType()); Console.WriteLine(); }; ModVersion latestRelease = handler.GetRecentVersions(meta, 1, ModReleaseType.Release).Result.First(); ModVersion latestVersion = handler.GetRecentVersions(meta, 1, ModReleaseType.Any).Result.First(); IEnumerable <ModVersion> versions = handler.GetRecentVersions(meta, 6, ModReleaseType.Any).Result.Skip(1); menu.AddItem(latestRelease); if (latestVersion.GetModVersion() != latestRelease.GetModVersion()) { menu.AddItem(latestVersion); } menu.AddSpacer(); foreach (ModVersion v in versions.Take(5)) { menu.AddItem(v); } menu.DrawMenu(); Console.ResetColor(); Console.WriteLine(); ModVersion version = menu.SelectedOption; Console.WriteLine("Selected Version: " + version.GetModVersion()); // Create a storage handler for the domain and mark the version as requested using (ModStorage storage = new ModStorage(Modifi.DefaultPack.Installed, domain)) { storage.MarkRequested(meta, version); } }