Пример #1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            string moddir = Path.Combine(Path.Combine(Environment.CurrentDirectory, "mods"), ValidateFilename(textModName.Text));

            if (textModName.Text.Length <= 0)
            {
                MessageBox.Show("You can't have a mod without a name.", "Invalid mod name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                if (Directory.Exists(moddir))
                {
                    MessageBox.Show("A mod with that name already exists."
                                    + "\nPlease choose a different name or rename the existing one.", "Mod already exists",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }

                Directory.CreateDirectory(moddir);

                if (checkRedirectMainSave.Checked || checkRedirectChaoSave.Checked)
                {
                    Directory.CreateDirectory(Path.Combine(moddir, "SAVEDATA"));
                }

                SA2ModInfo newMod = new SA2ModInfo
                {
                    Name             = textModName.Text,
                    Author           = textModAuthor.Text,
                    Description      = textModDescription.Text,
                    Version          = textVersion.Text,
                    RedirectMainSave = checkRedirectMainSave.Checked,
                    RedirectChaoSave = checkRedirectChaoSave.Checked,
                    GitHubRepo       = textGitHubRepo.Text,
                    GitHubAsset      = textGitHubAttachment.Text,
                    UpdateUrl        = textDirUrl.Text
                };

                IniSerializer.Serialize(newMod, Path.Combine(moddir, "mod.ini"));

                if (checkOpenFolder.Checked)
                {
                    System.Diagnostics.Process.Start(moddir);
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception error)
            {
                MessageBox.Show(this, error.Message, "Mod Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        private void modListView_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (suppressEvent)
            {
                return;
            }
            codes = new List <Code>(mainCodes.Codes);
            string        modDir  = Path.Combine(Environment.CurrentDirectory, "mods");
            List <string> modlist = new List <string>();

            foreach (ListViewItem item in modListView.CheckedItems)
            {
                modlist.Add((string)item.Tag);
            }
            if (e.NewValue == CheckState.Unchecked)
            {
                modlist.Remove((string)modListView.Items[e.Index].Tag);
            }
            else
            {
                modlist.Add((string)modListView.Items[e.Index].Tag);
            }
            foreach (string mod in modlist)
            {
                if (mods.ContainsKey(mod))
                {
                    SA2ModInfo inf = mods[mod];
                    if (!string.IsNullOrEmpty(inf.Codes))
                    {
                        codes.AddRange(CodeList.Load(Path.Combine(Path.Combine(modDir, mod), inf.Codes)).Codes);
                    }
                }
            }
            loaderini.EnabledCodes = new List <string>(loaderini.EnabledCodes.Where(a => codes.Any(c => c.Name == a)));
            foreach (Code item in codes.Where(a => a.Required && !loaderini.EnabledCodes.Contains(a.Name)))
            {
                loaderini.EnabledCodes.Add(item.Name);
            }
            codesCheckedListBox.BeginUpdate();
            codesCheckedListBox.Items.Clear();
            foreach (Code item in codes)
            {
                codesCheckedListBox.Items.Add(item.Name, loaderini.EnabledCodes.Contains(item.Name));
            }
            codesCheckedListBox.EndUpdate();
        }
Пример #3
0
        private void LoadModList()
        {
            modTopButton.Enabled = modUpButton.Enabled = modDownButton.Enabled = modBottomButton.Enabled = configureModButton.Enabled = false;
            modDescription.Text  = "Description: No mod selected.";
            modListView.Items.Clear();
            mods  = new Dictionary <string, SA2ModInfo>();
            codes = new List <Code>(mainCodes.Codes);
            string modDir = Path.Combine(Environment.CurrentDirectory, "mods");

            foreach (string filename in SA2ModInfo.GetModFiles(new DirectoryInfo(modDir)))
            {
                mods.Add((Path.GetDirectoryName(filename) ?? string.Empty).Substring(modDir.Length + 1), IniSerializer.Deserialize <SA2ModInfo>(filename));
            }

            modListView.BeginUpdate();

            foreach (string mod in new List <string>(loaderini.Mods))
            {
                if (mods.ContainsKey(mod))
                {
                    SA2ModInfo inf = mods[mod];
                    suppressEvent = true;
                    modListView.Items.Add(new ListViewItem(new[] { inf.Name, inf.Author, inf.Version })
                    {
                        Checked = true, Tag = mod
                    });
                    suppressEvent = false;
                    if (!string.IsNullOrEmpty(inf.Codes))
                    {
                        codes.AddRange(CodeList.Load(Path.Combine(Path.Combine(modDir, mod), inf.Codes)).Codes);
                    }
                }
                else
                {
                    MessageBox.Show(this, "Mod \"" + mod + "\" could not be found.\n\nThis mod will be removed from the list.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    loaderini.Mods.Remove(mod);
                }
            }

            foreach (KeyValuePair <string, SA2ModInfo> inf in mods.OrderBy(x => x.Value.Name))
            {
                if (!loaderini.Mods.Contains(inf.Key))
                {
                    modListView.Items.Add(new ListViewItem(new[] { inf.Value.Name, inf.Value.Author, inf.Value.Version })
                    {
                        Tag = inf.Key
                    });
                }
            }

            modListView.EndUpdate();

            loaderini.EnabledCodes = new List <string>(loaderini.EnabledCodes.Where(a => codes.Any(c => c.Name == a)));
            foreach (Code item in codes.Where(a => a.Required && !loaderini.EnabledCodes.Contains(a.Name)))
            {
                loaderini.EnabledCodes.Add(item.Name);
            }

            codesCheckedListBox.BeginUpdate();
            codesCheckedListBox.Items.Clear();

            foreach (Code item in codes)
            {
                codesCheckedListBox.Items.Add(item.Name, loaderini.EnabledCodes.Contains(item.Name));
            }

            codesCheckedListBox.EndUpdate();
        }