示例#1
0
        private void LoadModList()
        {
            modListView.Items.Clear();
            mods  = new Dictionary <string, ModInfo>();
            codes = new List <Code>(mainCodes.Codes);
            string modDir = Path.Combine(Environment.CurrentDirectory, "mods");

            foreach (string filename in GetModFiles(new DirectoryInfo(modDir)))
            {
                mods.Add(Path.GetDirectoryName(filename).Substring(modDir.Length + 1), IniFile.Deserialize <ModInfo>(filename));
            }
            modListView.BeginUpdate();
            foreach (string mod in new List <string>(loaderini.Mods))
            {
                if (mods.ContainsKey(mod))
                {
                    ModInfo 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, ModInfo> inf in mods)
            {
                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();
        }
示例#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))
                {
                    ModInfo 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 MainForm_Load(object sender, EventArgs e)
        {
            Random rand = new Random();

            if (rand.Next(2) == 1)
            {
                switch (rand.Next(10))
                {
                case 0:
                    Icon = Properties.Resources.opt_theme_on_sn;
                    break;

                case 1:
                    Icon = Properties.Resources.opt_theme_on_tl;
                    break;

                case 2:
                    Icon = Properties.Resources.opt_theme_on_kn;
                    break;

                case 3:
                    Icon = Properties.Resources.opt_theme_on_sd;
                    break;

                case 4:
                    Icon = Properties.Resources.opt_theme_on_eg;
                    break;

                case 5:
                    Icon = Properties.Resources.opt_theme_on_rg;
                    break;

                case 6:
                    Icon = Properties.Resources.opt_theme_on_am;
                    break;

                case 7:
                    Icon = Properties.Resources.opt_theme_on_ch;
                    break;

                case 8:
                    Icon = Properties.Resources.opt_theme_on_ma;
                    break;

                case 9:
                    Icon = Properties.Resources.opt_theme_on_se;
                    break;
                }
            }

            if (File.Exists(loaderinipath))
            {
                loaderini = IniFile.Deserialize <LoaderInfo>(loaderinipath);
            }
            else
            {
                loaderini = new LoaderInfo();
            }

            try { mainCodes = CodeList.Load(codexmlpath); }
            catch { mainCodes = new CodeList()
                    {
                        Codes = new List <Code>()
                    }; }

            LoadModList();

            consoleCheckBox.Checked           = loaderini.DebugConsole;
            fileCheckBox.Checked              = loaderini.DebugFile;
            pauseWhenInactiveCheckBox.Checked = loaderini.PauseWhenInactive;
            borderlessWindowCheckBox.Checked  = loaderini.BorderlessWindow;
            if (!File.Exists(datadllpath))
            {
                MessageBox.Show(this, "Data_DLL.dll could not be found.\n\nCannot determine state of installation.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                installButton.Hide();
            }
            else if (File.Exists(datadllorigpath))
            {
                installed          = true;
                installButton.Text = "Uninstall loader";
                MD5    md5   = MD5.Create();
                byte[] hash1 = md5.ComputeHash(File.ReadAllBytes(loaderdllpath));
                byte[] hash2 = md5.ComputeHash(File.ReadAllBytes(datadllpath));
                if (!hash1.SequenceEqual(hash2))
                {
                    if (MessageBox.Show(this, "Installed loader DLL differs from copy in mods folder.\n\nDo you want to overwrite the installed copy?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        File.Copy(loaderdllpath, datadllpath, true);
                    }
                }
            }
        }
示例#4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Random rand = new Random();

            if (rand.Next(2) == 1)
            {
                switch (rand.Next(10))
                {
                case 0:
                    Icon = Properties.Resources.opt_theme_on_sn;
                    break;

                case 1:
                    Icon = Properties.Resources.opt_theme_on_tl;
                    break;

                case 2:
                    Icon = Properties.Resources.opt_theme_on_kn;
                    break;

                case 3:
                    Icon = Properties.Resources.opt_theme_on_sd;
                    break;

                case 4:
                    Icon = Properties.Resources.opt_theme_on_eg;
                    break;

                case 5:
                    Icon = Properties.Resources.opt_theme_on_rg;
                    break;

                case 6:
                    Icon = Properties.Resources.opt_theme_on_am;
                    break;

                case 7:
                    Icon = Properties.Resources.opt_theme_on_ch;
                    break;

                case 8:
                    Icon = Properties.Resources.opt_theme_on_ma;
                    break;

                case 9:
                    Icon = Properties.Resources.opt_theme_on_se;
                    break;
                }
            }

            // Try to use TLS 1.2
            try { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; } catch { }
            if (!Debugger.IsAttached)
            {
                Environment.CurrentDirectory = Application.StartupPath;
            }
            SetDoubleBuffered(modListView, true);
            if (File.Exists(loaderinipath))
            {
                loaderini = IniSerializer.Deserialize <SA2LoaderInfo>(loaderinipath);
            }
            else
            {
                loaderini = new SA2LoaderInfo();
            }

            try
            {
                if (File.Exists(codelstpath))
                {
                    mainCodes = CodeList.Load(codelstpath);
                }
                else if (File.Exists(codexmlpath))
                {
                    mainCodes = CodeList.Load(codexmlpath);
                }
                else
                {
                    mainCodes = new CodeList();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, $"Error loading code list: {ex.Message}", "SA2 Mod Loader", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                mainCodes = new CodeList();
            }

            LoadModList();

            consoleCheckBox.Checked            = loaderini.DebugConsole;
            screenCheckBox.Checked             = loaderini.DebugScreen;
            fileCheckBox.Checked               = loaderini.DebugFile;
            pauseWhenInactiveCheckBox.Checked  = loaderini.PauseWhenInactive;
            borderlessWindowCheckBox.Checked   = loaderini.BorderlessWindow;
            checkUpdateStartup.Checked         = loaderini.UpdateCheck;
            checkUpdateModsStartup.Checked     = loaderini.ModUpdateCheck;
            comboUpdateFrequency.SelectedIndex = (int)loaderini.UpdateUnit;
            numericUpdateFrequency.Value       = loaderini.UpdateFrequency;
        }