Esempio n. 1
0
        /// <summary>
        /// Gets the installation status for a mod.
        /// </summary>
        /// <param name="meta">Mod to get status for</param>
        /// <returns></returns>
        public ModStatus GetModStatus(ModMetadata meta)
        {
            ModMetadata installed = this.Mods.FindOne(x => x.GetModIdentifier() == meta.GetModIdentifier());

            if (installed == null)
            {
                return(ModStatus.NotInstalled);
            }

            ModVersion installedVersion = GetMod(meta);

            // If we have a request in meta, but no requested version, error.
            // Delete the meta information and let the user know to re-request the mod.
            // TODO: Make new exception for this
            if (installedVersion == null)
            {
                this.Mods.Delete(x => x.GetModIdentifier() == installed.GetModIdentifier());
                throw new Exception("Mod metadata was in requests, but no matching version was found with it.");
            }

            // Check filename exists - if not, mod is requested and not yet downloaded
            string filename = installedVersion.Filename;

            if (filename == null)
            {
                return(ModStatus.Requested);
            }

            // Filename exists- check if properly downloaded
            string path = Path.Combine(Settings.ModPath, filename);

            if (File.Exists(path))
            {
                // If our checksum matches, the mod is installed
                if (ModUtilities.ChecksumMatches(path, installedVersion.Checksum))
                {
                    return(ModStatus.Installed);
                }
                else
                {
                    // TODO: Should we remove the mod metadata if the checksum failed here?
                    throw new Exception("Checksum does not match version information.");
                }
            }

            return(ModStatus.Requested);
        }
Esempio n. 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();
        }