コード例 #1
0
ファイル: MainForm.cs プロジェクト: DankRank/sadx-mod-loader
        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
ファイル: MainForm.cs プロジェクト: DankRank/sadx-mod-loader
        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
ファイル: MainForm.cs プロジェクト: DankRank/sadx-mod-loader
		private void MainForm_Load(object sender, EventArgs e)
		{
			if (File.Exists("sadxmlver.txt"))
			{
				System.Net.WebClient wc = new System.Net.WebClient();
				string msg = null;
				try
				{
					msg = wc.DownloadString("http://mm.reimuhakurei.net/toolchangelog.php?tool=sadxml&rev=" + File.ReadAllText("sadxmlver.txt"));
				}
				catch { MessageBox.Show(this, "Unable to retrieve update information.", "SADX Mod Manager"); goto noupdate; }
				if (msg.Length > 0)
					using (UpdateMessageDialog dlg = new UpdateMessageDialog(msg.Replace("\n", "\r\n")))
						if (dlg.ShowDialog(this) == DialogResult.Yes)
						{
							System.Diagnostics.Process.Start("http://mm.reimuhakurei.net/sadxmods/SADXModLoader.7z");
							Close();
							return;
						}
			}
		noupdate:
			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();

			for (int i = 0; i < Screen.AllScreens.Length; i++)
				screenNumComboBox.Items.Add((i + 1).ToString() + " " + Screen.AllScreens[i].DeviceName + " (" + Screen.AllScreens[i].Bounds.Location.X + "," + Screen.AllScreens[i].Bounds.Y + ") " + Screen.AllScreens[i].Bounds.Width + "x" + Screen.AllScreens[i].Bounds.Height + " " + Screen.AllScreens[i].BitsPerPixel + "bpp" + (Screen.AllScreens[i].Primary ? " Primary" : ""));

			consoleCheckBox.Checked = loaderini.DebugConsole;
			screenCheckBox.Checked = loaderini.DebugScreen;
			fileCheckBox.Checked = loaderini.DebugFile;
			disableCDCheckCheckBox.Checked = loaderini.DisableCDCheck;
			useCustomResolutionCheckBox.Checked = verticalResolution.Enabled = forceAspectRatioCheckBox.Enabled = nativeResolutionButton.Enabled = loaderini.UseCustomResolution;
			checkVsync.Checked = loaderini.EnableVsync;
			horizontalResolution.Enabled = loaderini.UseCustomResolution && !loaderini.ForceAspectRatio;
			horizontalResolution.Value = Math.Max(horizontalResolution.Minimum, Math.Min(horizontalResolution.Maximum, loaderini.HorizontalResolution));
			verticalResolution.Value = Math.Max(verticalResolution.Minimum, Math.Min(verticalResolution.Maximum, loaderini.VerticalResolution));
			suppressEvent = true;
			forceAspectRatioCheckBox.Checked = loaderini.ForceAspectRatio;
			checkScaleHud.Checked = loaderini.ScaleHud;
			suppressEvent = false;
			windowedFullscreenCheckBox.Checked = loaderini.WindowedFullscreen;
			forceMipmappingCheckBox.Checked = loaderini.AutoMipmap;
			forceTextureFilterCheckBox.Checked = loaderini.TextureFilter;
			pauseWhenInactiveCheckBox.Checked = loaderini.PauseWhenInactive;
			stretchFullscreenCheckBox.Checked = loaderini.StretchFullscreen;
			int scrn = loaderini.ScreenNum;
			if (scrn > Screen.AllScreens.Length)
				scrn = 1;
			screenNumComboBox.SelectedIndex = scrn;
			customWindowSizeCheckBox.Checked = windowHeight.Enabled = maintainWindowAspectRatioCheckBox.Enabled = loaderini.CustomWindowSize;
			windowWidth.Enabled = loaderini.CustomWindowSize && !loaderini.MaintainWindowAspectRatio;
			System.Drawing.Rectangle rect = Screen.PrimaryScreen.Bounds;
			foreach (Screen screen in Screen.AllScreens)
				rect = System.Drawing.Rectangle.Union(rect, screen.Bounds);
			windowWidth.Maximum = rect.Width;
			windowWidth.Value = Math.Max(windowWidth.Minimum, Math.Min(rect.Width, loaderini.WindowWidth));
			windowHeight.Maximum = rect.Height;
			windowHeight.Value = Math.Max(windowHeight.Minimum, Math.Min(rect.Height, loaderini.WindowHeight));
			suppressEvent = true;
			maintainWindowAspectRatioCheckBox.Checked = loaderini.MaintainWindowAspectRatio;
			suppressEvent = false;
			if (!File.Exists(datadllpath))
			{
				MessageBox.Show(this, "CHRMODELS.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
ファイル: MainForm.cs プロジェクト: DankRank/sadx-mod-loader
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (File.Exists("sadxmlver.txt"))
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                string msg = null;
                try
                {
                    msg = wc.DownloadString("http://mm.reimuhakurei.net/toolchangelog.php?tool=sadxml&rev=" + File.ReadAllText("sadxmlver.txt"));
                }
                catch { MessageBox.Show(this, "Unable to retrieve update information.", "SADX Mod Manager"); goto noupdate; }
                if (msg.Length > 0)
                {
                    using (UpdateMessageDialog dlg = new UpdateMessageDialog(msg.Replace("\n", "\r\n")))
                        if (dlg.ShowDialog(this) == DialogResult.Yes)
                        {
                            System.Diagnostics.Process.Start("http://mm.reimuhakurei.net/sadxmods/SADXModLoader.7z");
                            Close();
                            return;
                        }
                }
            }
noupdate:
            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();

            for (int i = 0; i < Screen.AllScreens.Length; i++)
            {
                screenNumComboBox.Items.Add((i + 1).ToString() + " " + Screen.AllScreens[i].DeviceName + " (" + Screen.AllScreens[i].Bounds.Location.X + "," + Screen.AllScreens[i].Bounds.Y + ") " + Screen.AllScreens[i].Bounds.Width + "x" + Screen.AllScreens[i].Bounds.Height + " " + Screen.AllScreens[i].BitsPerPixel + "bpp" + (Screen.AllScreens[i].Primary ? " Primary" : ""));
            }

            consoleCheckBox.Checked             = loaderini.DebugConsole;
            screenCheckBox.Checked              = loaderini.DebugScreen;
            fileCheckBox.Checked                = loaderini.DebugFile;
            disableCDCheckCheckBox.Checked      = loaderini.DisableCDCheck;
            useCustomResolutionCheckBox.Checked = verticalResolution.Enabled = forceAspectRatioCheckBox.Enabled = nativeResolutionButton.Enabled = loaderini.UseCustomResolution;
            checkVsync.Checked           = loaderini.EnableVsync;
            horizontalResolution.Enabled = loaderini.UseCustomResolution && !loaderini.ForceAspectRatio;
            horizontalResolution.Value   = Math.Max(horizontalResolution.Minimum, Math.Min(horizontalResolution.Maximum, loaderini.HorizontalResolution));
            verticalResolution.Value     = Math.Max(verticalResolution.Minimum, Math.Min(verticalResolution.Maximum, loaderini.VerticalResolution));
            suppressEvent = true;
            forceAspectRatioCheckBox.Checked = loaderini.ForceAspectRatio;
            checkScaleHud.Checked            = loaderini.ScaleHud;
            suppressEvent = false;
            windowedFullscreenCheckBox.Checked = loaderini.WindowedFullscreen;
            forceMipmappingCheckBox.Checked    = loaderini.AutoMipmap;
            forceTextureFilterCheckBox.Checked = loaderini.TextureFilter;
            pauseWhenInactiveCheckBox.Checked  = loaderini.PauseWhenInactive;
            stretchFullscreenCheckBox.Checked  = loaderini.StretchFullscreen;
            int scrn = loaderini.ScreenNum;

            if (scrn > Screen.AllScreens.Length)
            {
                scrn = 1;
            }
            screenNumComboBox.SelectedIndex  = scrn;
            customWindowSizeCheckBox.Checked = windowHeight.Enabled = maintainWindowAspectRatioCheckBox.Enabled = loaderini.CustomWindowSize;
            windowWidth.Enabled = loaderini.CustomWindowSize && !loaderini.MaintainWindowAspectRatio;
            System.Drawing.Rectangle rect = Screen.PrimaryScreen.Bounds;
            foreach (Screen screen in Screen.AllScreens)
            {
                rect = System.Drawing.Rectangle.Union(rect, screen.Bounds);
            }
            windowWidth.Maximum  = rect.Width;
            windowWidth.Value    = Math.Max(windowWidth.Minimum, Math.Min(rect.Width, loaderini.WindowWidth));
            windowHeight.Maximum = rect.Height;
            windowHeight.Value   = Math.Max(windowHeight.Minimum, Math.Min(rect.Height, loaderini.WindowHeight));
            suppressEvent        = true;
            maintainWindowAspectRatioCheckBox.Checked = loaderini.MaintainWindowAspectRatio;
            suppressEvent = false;
            if (!File.Exists(datadllpath))
            {
                MessageBox.Show(this, "CHRMODELS.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);
                    }
                }
            }
        }