Пример #1
0
        /// <summary>
        /// Updates MerCraft.
        /// </summary>
        /// <param name="U">Username</param>
        /// <param name="P">Password</param>
        public async void UpdateVersion(string U, string P)
        {
            UpdateInfoControl UICModPack = new UpdateInfoControl("ModPack Update Download (MC " + Program.M.PreferredVersion + ")");

            LF = new LaunchForm();
            Us = U;
            Pa = P;
            LF.panel1.Controls.Add(UICModPack);
            LF.Show();

            string linkToModPack = "http://mercraft.merbo.org/MerCraft/Versions/" + Program.M.PreferredVersion + "/ModPack.zip";

            await MakeBackup();
            await PrepareForUpdate();

            await UICModPack.DownloadAndExtractZip(linkToModPack, appdata + "\\.mercraft\\ModPack.zip", appdata + "\\.mercraft", true);

            await RestoreBackup();

            if (!runningDownload)
            {
                if (CorrectJar())
                {
                    Launcher.LaunchAfterUpdate(LF, Us, Pa);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Launch the game after an update.
 /// </summary>
 /// <param name="LF">The LaunchForm.</param>
 /// <param name="U">Username.</param>
 /// <param name="P">Password.</param>
 public static void LaunchAfterUpdate(LaunchForm LF, string U, string P)
 {
     Run(U, P, LF);
 }
Пример #3
0
        /// <summary>
        /// Runs mercraft and compresses all the windows together.
        /// </summary>
        /// <param name="U">Username.</param>
        /// <param name="P">Password.</param>
        /// <param name="LF">LaunchForm if we updated, null if not.</param>
        /// <returns>Successful</returns>
        static bool Run(string U, string P, LaunchForm LF = null)
        {
            IntPtr originalHandle;
            IntPtr mainHandle = IntPtr.Zero;

            try
            {
                Process Java = null;
                if (LF != null)
                {
                    LF.Close();
                }
                Java = GetJavaProcess(U, P, Program.M.Opts.Config.GetConfigVarBool("Debug"));
                Java.Start();
                if (Program.M.Opts.Config.GetConfigVarBool("WinAPI"))
                {
                    while (mainHandle == IntPtr.Zero)
                    {
                        Java.WaitForInputIdle(10);
                        Java.Refresh();

                        if (Java.HasExited)
                        {
                            Application.Exit();
                        }
                        if (Java.MainWindowTitle != "Minecraft")
                        {
                            continue;
                        }
                        mainHandle = Java.MainWindowHandle;
                    }

                    GameForm gameForm = new GameForm();
                    gameForm.Show();
                    while (!gameForm.panel1.IsHandleCreated)
                    {
                    }
                    originalHandle = WinAPI.SetParent(mainHandle, gameForm.panel1.Handle);
                    int style = WinAPI.GetWindowLong(mainHandle, WinAPI.GWL_STYLE);
                    WinAPI.MoveWindow(mainHandle, 0, 0, gameForm.panel1.Width, gameForm.panel1.Height, true);
                    WinAPI.SetWindowLong(mainHandle, WinAPI.GWL_STYLE, (style & ~(int)WinAPI.WS.WS_SYSMENU));
                    WinAPI.SetWindowLong(mainHandle, WinAPI.GWL_STYLE, (style & ~(int)WinAPI.WS.WS_CAPTION));
                    gameForm.childHandle         = mainHandle;
                    gameForm.javaProcess         = Java;
                    gameForm.javaProcess.Exited += gameForm.javaProcess_Exited;
                    gameForm.hasTriedHandle      = true;
                    Program.M.Hide();
                }
                else
                {
                    while (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    {
                        Java.WaitForInputIdle(10);
                        Java.Refresh();

                        if (Java.HasExited)
                        {
                            Application.Exit();
                        }
                        if (Java.MainWindowTitle != "Minecraft")
                        {
                            continue;
                        }

                        WinAPI.SetClassLong(Java.MainWindowHandle, WinAPI.GCL_HICON, global::MerCraft.Properties.Resources.LargeIcon.GetHicon().ToInt64());
                        WinAPI.SetClassLong(Java.MainWindowHandle, WinAPI.GCLP_HICONSM, global::MerCraft.Properties.Resources.SmallIcon.GetHicon().ToInt64());

                        WinAPI.SetWindowText(Java.MainWindowHandle, "MerCraft");

                        break;
                    }
                    Application.Exit();
                }
            }
            catch (InvalidOperationException)
            {
                //We're in debug!
            }
            catch (Exception ex)
            {
                MessageBox.Show("You might not have java installed in the right place for MerCraft. Try asking Merbo about it.");
                MessageBox.Show(ex.ToString());
                Console.WriteLine(ex.ToString());
                return(false);
            }
            return(true);
        }
Пример #4
0
 /// <summary>
 /// Launch the game after an update.
 /// </summary>
 /// <param name="LF">The LaunchForm.</param>
 /// <param name="U">Username.</param>
 /// <param name="P">Password.</param>
 public static void LaunchAfterUpdate(LaunchForm LF, string U, string P)
 {
     Run(U, P, LF);
 }
Пример #5
0
        /// <summary>
        /// Runs mercraft and compresses all the windows together.
        /// </summary>
        /// <param name="U">Username.</param>
        /// <param name="P">Password.</param>
        /// <param name="LF">LaunchForm if we updated, null if not.</param>
        /// <returns>Successful</returns>
        static bool Run(string U, string P, LaunchForm LF = null)
        {
            IntPtr originalHandle;
            IntPtr mainHandle = IntPtr.Zero;
            try
            {
                Process Java = null;
                if (LF != null)
                {
                    LF.Close();
                }
                Java = GetJavaProcess(U, P, Program.M.Opts.Config.GetConfigVarBool("Debug"));
                Java.Start();
                if (Program.M.Opts.Config.GetConfigVarBool("WinAPI"))
                {
                    while (mainHandle == IntPtr.Zero)
                    {
                        Java.WaitForInputIdle(10);
                        Java.Refresh();

                        if (Java.HasExited)
                            Application.Exit();
                        if (Java.MainWindowTitle != "Minecraft")
                            continue;
                        mainHandle = Java.MainWindowHandle;
                    }

                    GameForm gameForm = new GameForm();
                    gameForm.Show();
                    while (!gameForm.panel1.IsHandleCreated)
                    {
                    }
                    originalHandle = WinAPI.SetParent(mainHandle, gameForm.panel1.Handle);
                    int style = WinAPI.GetWindowLong(mainHandle, WinAPI.GWL_STYLE);
                    WinAPI.MoveWindow(mainHandle, 0, 0, gameForm.panel1.Width, gameForm.panel1.Height, true);
                    WinAPI.SetWindowLong(mainHandle, WinAPI.GWL_STYLE, (style & ~(int)WinAPI.WS.WS_SYSMENU));
                    WinAPI.SetWindowLong(mainHandle, WinAPI.GWL_STYLE, (style & ~(int)WinAPI.WS.WS_CAPTION));
                    gameForm.childHandle = mainHandle;
                    gameForm.javaProcess = Java;
                    gameForm.javaProcess.Exited += gameForm.javaProcess_Exited;
                    gameForm.hasTriedHandle = true;
                    Program.M.Hide();
                }
                else
                {
                    while (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    {
                        Java.WaitForInputIdle(10);
                        Java.Refresh();

                        if (Java.HasExited)
                            Application.Exit();
                        if (Java.MainWindowTitle != "Minecraft")
                            continue;

                        WinAPI.SetClassLong(Java.MainWindowHandle, WinAPI.GCL_HICON, global::MerCraft.Properties.Resources.LargeIcon.GetHicon().ToInt64());
                        WinAPI.SetClassLong(Java.MainWindowHandle, WinAPI.GCLP_HICONSM, global::MerCraft.Properties.Resources.SmallIcon.GetHicon().ToInt64());

                        WinAPI.SetWindowText(Java.MainWindowHandle, "MerCraft");

                        break;
                    }
                    Application.Exit();
                }
            }
            catch (InvalidOperationException)
            {
                //We're in debug!
            }
            catch (Exception ex)
            {
                MessageBox.Show("You might not have java installed in the right place for MerCraft. Try asking Merbo about it.");
                MessageBox.Show(ex.ToString());
                Console.WriteLine(ex.ToString());
                return false;
            }
            return true;
        }
Пример #6
0
        /// <summary>
        /// Updates MerCraft.
        /// </summary>
        /// <param name="U">Username</param>
        /// <param name="P">Password</param>
        public async void UpdateVersion(string U, string P)
        {
            UpdateInfoControl UICModPack = new UpdateInfoControl("ModPack Update Download (MC " + Program.M.PreferredVersion + ")");

            LF = new LaunchForm();
            Us = U;
            Pa = P;
            LF.panel1.Controls.Add(UICModPack);
            LF.Show();

            string linkToModPack = "http://mercraft.merbo.org/MerCraft/Versions/" + Program.M.PreferredVersion + "/ModPack.zip";

            await MakeBackup();
            await PrepareForUpdate();
            await UICModPack.DownloadAndExtractZip(linkToModPack, appdata + "\\.mercraft\\ModPack.zip", appdata + "\\.mercraft", true);
            await RestoreBackup();

            if (!runningDownload)
                if (CorrectJar())
                    Launcher.LaunchAfterUpdate(LF, Us, Pa);
        }