Exemple #1
0
        public static void FixIncludeDir(int index, Mod mod)
        {
            try
            {
                string includeDir = mod.GetIniFile()["Main"]["IncludeDir" + index];
                mod.GetIniFile().Save(Path.Combine(mod.RootDirectory, "mod_backup.ini"));

                // Old Generations IncludeDir?
                if (includeDir.StartsWith($"./mods/{Path.GetFileName(mod.RootDirectory)}"))
                {
                    // It pretty much just trims "/mods/{ModName}" out.
                    // As these should be relative to the mod root.
                    mod.GetIniFile()["Main"]["IncludeDir" + index] =
                        "." + includeDir.Substring(7 + Path.GetFileName(mod.RootDirectory).Length);
                    mod.Save();
                }
            }catch
            { }
        }
        // Edit a mod.
        public NewModForm(Mod mod)
        {
            InitializeComponent();
            _Mod    = mod;
            ModName = Path.GetFileName(mod.RootDirectory);
            // Automatically fill in some info.
            var ini = mod.GetIniFile();

            for (int i = 0; i < ini.GroupCount; ++i)
            {
                var iniGroup = ini[i];

                ListViewGroup group = null;
                foreach (ListViewGroup group2 in listView1.Groups)
                {
                    if (group2.Header.ToLower().Equals(iniGroup.GroupName.ToLower()))
                    {
                        group = group2;
                        break;
                    }
                }

                if (group == null)
                {
                    group = AddGroup(iniGroup.GroupName);
                }

                for (int i2 = 0; i2 < iniGroup.ParameterCount; ++i2)
                {
                    string key         = iniGroup[i2].Key.Replace("\n", "\\n");
                    string value       = iniGroup[i2].Value.Replace("\n", "\\n");
                    bool   hasProperty = false;
                    foreach (ListViewItem lvi in group.Items)
                    {
                        if (lvi.SubItems[0].Text.ToLower().Equals(key.ToLower()))
                        {
                            lvi.SubItems[1].Text = value;
                            hasProperty          = true;
                        }
                    }
                    if (!hasProperty)
                    {
                        AddProperty(key, value, listView1.Groups.IndexOf(group), "String");
                    }
                }
            }
        }
        public DescriptionForm(Mod mod)
            : this(mod.Description, mod.Title, mod.Author, mod.Date, mod.Url, mod.Version, mod.AuthorUrl)
        {
            #region Nothing to see here
            var Desc = mod.GetIniFile()["Desc"];
            if (Desc.ContainsParameter("BackgroundImage"))
            {
                try
                {
                    BackgroundImage       = Image.FromFile(Path.Combine(mod.RootDirectory, Desc["BackgroundImage"]));
                    BackgroundImageLayout = ImageLayout.Stretch;
                }
                catch { }
            }

            if (Desc.ContainsParameter("BackgroundImageCount"))
            {
                try
                {
                    var rand = new Random();
                    BackgroundImage       = Image.FromFile(Path.Combine(mod.RootDirectory, Desc["BackgroundImage" + rand.Next((int)Desc["BackgroundImageCount", typeof(int)])]));
                    BackgroundImageLayout = ImageLayout.Stretch;
                }
                catch { }
            }

            if (Desc.ContainsParameter("TextColor"))
            {
                try
                {
                    descriptionLbl.ForeColor = Color.FromArgb(
                        Convert.ToInt32(Desc["TextColor"].Split(',')[0]),
                        Convert.ToInt32(Desc["TextColor"].Split(',')[1]),
                        Convert.ToInt32(Desc["TextColor"].Split(',')[2]));
                }
                catch { }
            }

            if (Desc.ContainsParameter("TextFont"))
            {
                try
                {
                    descriptionLbl.Font = new Font(Desc["TextFont"], 8.25f);
                }
                catch { }
            }

            if (Desc.ContainsParameter("TextSize"))
            {
                try
                {
                    descriptionLbl.Font = new Font(descriptionLbl.Font.FontFamily, float.Parse(Desc["TextSize"]));
                }
                catch { }
            }

            if (Desc.ContainsParameter("HeaderColor"))
            {
                try
                {
                    titleLbl.LinkColor      = titleLbl.ForeColor =
                        authorLbl.LinkColor = authorLbl.ForeColor =
                            Color.FromArgb(Convert.ToInt32(Desc["HeaderColor"].Split(',')[0]),
                                           Convert.ToInt32(Desc["HeaderColor"].Split(',')[1]),
                                           Convert.ToInt32(Desc["HeaderColor"].Split(',')[2]));
                }
                catch { }
            }

            if (Desc.ContainsParameter("HeaderFont"))
            {
                try
                {
                    titleLbl.Font = new Font(Desc["HeaderFont"], titleLbl.Font.Size);
                }
                catch { }
            }

            if (Desc.ContainsParameter("HeaderSize"))
            {
                try
                {
                    titleLbl.Font           = new Font(titleLbl.Font.FontFamily, float.Parse(Desc["HeaderSize"]));
                    authorLbl.Location      = new Point(authorLbl.Location.X, titleLbl.Location.Y + ((int)float.Parse(Desc["HeaderSize"])) + 23);
                    descriptionLbl.Location = new Point(descriptionLbl.Location.X, descriptionLbl.Location.Y + 23);
                }
                catch { }
            }

            if (Desc.ContainsParameter("AuthorColor"))
            {
                try
                {
                    authorLbl.LinkColor = authorLbl.ForeColor =
                        Color.FromArgb(Convert.ToInt32(Desc["AuthorColor"].Split(',')[0]),
                                       Convert.ToInt32(Desc["AuthorColor"].Split(',')[1]),
                                       Convert.ToInt32(Desc["AuthorColor"].Split(',')[2]));
                }
                catch { }
            }

            if (Desc.ContainsParameter("AuthorLinkColor"))
            {
                try
                {
                    authorLbl.LinkColor =
                        Color.FromArgb(Convert.ToInt32(Desc["AuthorLinkColor"].Split(',')[0]),
                                       Convert.ToInt32(Desc["AuthorLinkColor"].Split(',')[1]),
                                       Convert.ToInt32(Desc["AuthorLinkColor"].Split(',')[2]));
                }
                catch { }
            }

            if (Desc.ContainsParameter("AuthorFont"))
            {
                try
                {
                    authorLbl.Font = new Font(Desc["AuthorFont"], authorLbl.Font.Size);
                }
                catch { }
            }

            if (Desc.ContainsParameter("AuthorSize"))
            {
                try
                {
                    authorLbl.Font          = new Font(authorLbl.Font.FontFamily, float.Parse(Desc["AuthorSize"]));
                    descriptionLbl.Location = new Point(descriptionLbl.Location.X, descriptionLbl.Location.Y +
                                                        (int)float.Parse(Desc["AuthorSize"]));
                }
                catch { }
            }
            #endregion
        }