예제 #1
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;
                        }
                    }
                }
            }
        }
예제 #2
0
        public static void HandleModRemove(IDomain domain, string modIdentifier)
        {
            IDomainHandler handler = domain.GetDomainHandler();
            ModStorage     storage = new ModStorage(Modifi.DefaultPack.Installed, domain);

            ModMetadata meta = storage.GetMetadata(modIdentifier);

            if (meta == null)
            {
                Modifi.DefaultLogger.Error("Cannot uninstall {0}; it is not installed.", modIdentifier);
                return;
            }

            ModVersion installed = storage.GetMod(meta);
            ModStatus  status    = storage.GetModStatus(meta);

            switch (status)
            {
            case ModStatus.NotInstalled:
                Modifi.DefaultLogger.Error("Cannot uninstall {0}; it is not installed.", meta.GetName());
                return;

            case ModStatus.Requested:
                Modifi.DefaultLogger.Information("Removing {0}...", meta.GetName());
                storage.Delete(meta);
                Modifi.DefaultLogger.Information("Done.");
                return;

            case ModStatus.Installed:
                Modifi.DefaultLogger.Information("Removing {0} and deleting files...", meta.GetName());
                storage.Delete(meta);
                string filePath        = Path.Combine(Settings.ModPath, installed.Filename);
                bool   correctChecksum = ModUtilities.ChecksumMatches(filePath, installed.Checksum);
                if (correctChecksum)
                {
                    try {
                        File.Delete(filePath);
                    }

                    catch (Exception e) {
                        Modifi.DefaultLogger.Error("Error deleting {0}, please delete it manually.", filePath);
                        Modifi.DefaultLogger.Error(e.Message);
                    }
                }
                else
                {
                    Modifi.DefaultLogger.Information("File for {0} found at {1}, but the checksum did not match. Delete?", meta.GetName(), filePath);
                    Menu <string> delete = new Menu <string>();
                    delete.AddItem("Delete");
                    delete.AddItem("Leave");

                    delete.DrawMenu();
                    switch (delete.SelectedOption.ToLower())
                    {
                    case "delete":
                        File.Delete(filePath);
                        Modifi.DefaultLogger.Information("File deleted.");
                        break;

                    case "leave":
                        Modifi.DefaultLogger.Information("File left in place.");
                        break;
                    }
                }

                break;
            }

            storage.Dispose();
        }