示例#1
0
        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); }
        }
示例#2
0
        private static void DownloadPack()
        {
            using (Pack p = Modifi.DefaultPack) {
                ILogger log = Modifi.DefaultLogger;

                log.Information("Downloading modpack.");
                log.Information(Environment.NewLine);

                IDomain curseforge;
                try {
                    curseforge = DomainHelper.LoadDomain(p, "curseforge");
                }

                catch (DllNotFoundException) {
                    log.Error("Cannot install mods; curseforge domain handler not found.");
                    return;
                }

                IDomainHandler handler = curseforge.GetDomainHandler();
                using (ModStorage storage = new ModStorage(p.Installed, curseforge)) {
                    IEnumerable <ModMetadata> mods = storage.GetAllMods();
                    foreach (ModMetadata mod in mods)
                    {
                        log.Information("Installing: {0:l}", mod.GetName());

                        ModStatus status;
                        try { status = storage.GetModStatus(mod); }
                        catch (Exception) {
                            log.Error("Error: Mod marked installed but checksum did not match.");
                            log.Error("Please use the remove command and re-add it, or download the version manually.");
                            continue;
                        }

                        switch (status)
                        {
                        case ModStatus.Installed:
                            log.Information("Skipping, already installed.");
                            log.Information(Environment.NewLine);
                            continue;

                        case ModStatus.Requested:
                            ModVersion version = storage.GetMod(mod);
                            log.Information("Requested Version: {0:l} ({1})", version.GetVersionName(), version.GetModVersion());
                            try {
                                ModDownloadResult result = handler.DownloadMod(version, Settings.ModPath).Result;
                                storage.MarkInstalled(mod, version, result);

                                log.Information("Downloaded to {0}.", result.Filename);
                                log.Information(Environment.NewLine);
                            }

                            catch (Exception e) {
                                log.Error(e.Message);
                                log.Error(Environment.NewLine);
                            }

                            break;
                        }
                    }
                }
            }
        }