Example #1
0
		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);
			}
		}
Example #2
0
        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);
                    }
                }
            }
        }