Ejemplo n.º 1
0
        private void btn_launch_Click(object sender, EventArgs e)
        {
            // Get the current profile
            MCHelper.Profile CurrentProfile = new MCHelper.Profile();
            CurrentProfile = (MCHelper.Profile)CB_Config.SelectedItem;

            // Do Login if needed
            if (CurrentProfile.Typelogin == MCHelper.LoginType.None)
            {
                // Skip Login
            }
            else
            {
                Application.DoEvents();

                MojangLogin LoginStatus = new MojangLogin();

                LoginStatus.Show();
                Application.DoEvents();

                if(CurrentProfile.Typelogin == MCHelper.LoginType.Minecraft)
                {
                    if (Program.MCInfo.LoginPassed == false)
                    {
                        Program.MCInfo = MinecraftStatic.LoginCheck(txt_Username.Text, txt_Password.Text);
                    }

                    if (Program.MCInfo.LoginPassed == true)
                    {
                        LoginStatus.Close();
                        Program.AppSettings.UpdateSetting("LastLogin", txt_Username.Text);
                    }
                    else
                    {
                        LoginStatus.Close();
                        return;
                    }
                }
                else if (CurrentProfile.Typelogin == MCHelper.LoginType.PHPBB)
                {
                    // skip for now
                }
            }

            // check the version
            if (Program.CheckVersion(CurrentProfile.GameDir).ToLower().Contains("version good") == false)
            {
                //Update Required
                UpdateProgress Progress = new UpdateProgress();
                Progress.ProfileDir = CurrentProfile.GameDir;
                Progress.ShowDialog();
            }

            // launch the app
            string ProfileRoot = Directory.GetCurrentDirectory() + "\\data\\" + CurrentProfile.GameDir;

            if (CurrentProfile.Type == MCHelper.GameType.Minecraft)
            {
                //if (Program.AppSettings.GetSetting("ClassicLaunch") == "True")
                //{
                //    Process Minecraft = new Process();
                //    Minecraft.StartInfo.FileName = "minecraftp.bat";
                //    //Minecraft.StartInfo.Arguments = "--username="******" --password="******" " + Program.MCInfo.Password;
                //    Minecraft.StartInfo.RedirectStandardOutput = true;
                //    //Minecraft.StartInfo.CreateNoWindow = true;
                //    Minecraft.StartInfo.UseShellExecute = false;
                //    Minecraft.Start();
                //}

                // checking for the minecraft jar
                if (File.Exists(ProfileRoot + "\\bin\\minecraft.jar") == false)
                {
                    return;
                }

                try
                {
                    Program.AppSettings.MaxMemory = Convert.ToInt32(Program.AppSettings.GetSetting("MemMax"));
                    Program.AppSettings.MinMemory = Convert.ToInt32(Program.AppSettings.GetSetting("MemMin"));
                }
                catch
                {
                    Program.AppSettings.MaxMemory = 2046;
                    Program.AppSettings.MinMemory = 2046;
                }

                Process Minecraft = new Process();

                if (Program.AppSettings.GetSetting("JavaPath") != string.Empty)
                {
                    Minecraft.StartInfo.FileName = Program.AppSettings.GetSetting("JavaPath");
                }
                else
                {
                    Minecraft.StartInfo.FileName = "java";
                }

                //ProfileRoot = ProfileRoot.Replace('\\', '/');
                string DSMinecraftDir = "\"" + Directory.GetCurrentDirectory() + "\\data\\" + CurrentProfile.GameDir + "\\";
                Minecraft.StartInfo.Arguments = "-Xms" + Program.AppSettings.MinMemory + "M -Xmx" + Program.AppSettings.MaxMemory + "M -Djava.library.path=" + DSMinecraftDir + ".minecraft/bin/natives\" -cp " + DSMinecraftDir + ".minecraft/bin/minecraft.jar\";" + DSMinecraftDir + ".minecraft/bin/jinput.jar\";" + DSMinecraftDir + ".minecraft/bin/lwjgl.jar\";" + DSMinecraftDir + ".minecraft/bin/lwjgl_util.jar\" net.minecraft.client.Minecraft " + Program.MCInfo.UserName + " " + Program.MCInfo.SessionID;

                //Minecraft.StartInfo.Arguments = "-Xms" + Program.AppSettings.MinMemory + "M -Xmx" + Program.AppSettings.MaxMemory +
                  //  "M -Djava.library.path=" + ProfileRoot + "/bin/natives\" -cp " + ProfileRoot + "/bin/minecraft.jar\";" + ProfileRoot + "/bin/jinput.jar\";" + ProfileRoot + "/bin/lwjgl.jar\";" + ProfileRoot + "/bin/lwjgl_util.jar\" net.minecraft.client.Minecraft " +
                    //Program.MCInfo.UserName + " " + Program.MCInfo.SessionID;
                Console.WriteLine(Minecraft.StartInfo.Arguments);
                Minecraft.StartInfo.RedirectStandardOutput = false;
                Minecraft.StartInfo.UseShellExecute = false;
                Minecraft.StartInfo.EnvironmentVariables.Remove("APPDATA");
                Minecraft.StartInfo.EnvironmentVariables.Add("APPDATA", ProfileRoot);

                try
                {
                    Minecraft.Start();
                }
                catch (Exception ex)
                {
                    if (ex.ToString().Contains("The system cannot find the file specified") == true)
                    {
                        // add titles
                    }
                }
            }
            else if (CurrentProfile.Type == MCHelper.GameType.Other)
            {
                //Process Other = new Process();
                //TODO
                //Other.StartInfo.FileName
            }
        }
Ejemplo n.º 2
0
        public static string CheckVersion(string ProfileDir)
        {
            MCHelper.Profile CurrentProfile = new MCHelper.Profile();
            CurrentProfile.LoadProfile(Directory.GetCurrentDirectory() + "\\Data\\" + ProfileDir);

            //string CurrentVersion = string.Empty;
            string RemoteVersion = string.Empty;

            //try
            //{
                //using (StreamReader VersionFile = new StreamReader(ProfileDir + "\\Version.txt"))
                //{
            CurrentVersion = CurrentProfile.CurrentVersion;
                //}
            //}
            //catch (Exception e)
            //{
             //   if (e.ToString().Contains("zzz"))
              //  {
                    //do soemthing
               // }
                //TODO: Handle Exception
            //}

            Releases.Clear();

            //string Versions = NetHelper.Download(VersionFileURL);
            string Versions = NetHelper.Download(CurrentProfile.UpdateURL);

            string[] Releasesx = Versions.Split(new string[] { "\n" }, StringSplitOptions.None);

            foreach (string VerItem in Releasesx)
            {
                Releases.Rows.Add(VerItem.Split(new char[] { ';' }));
            }

            int CurrentVersionNum = 0;
            bool FoundCurrentVersion = false;
            string LatestVersion = "";

            foreach (DataRow CurrentRow in Releases.Rows)
            {
                if (FoundCurrentVersion == false)
                {
                    CurrentVersionNum++;
                }
                if (CurrentRow["ReleaseNumber"].ToString() == CurrentVersion)
                {
                    FoundCurrentVersion = true;
                    break;
                }
                LatestVersion = CurrentRow[ "ReleaseNumber" ].ToString();
            }

            if (CurrentVersionNum != Releases.Rows.Count)
            {
                //return latest version
                return LatestVersion;
            }
            else
            {
                return "Version Good: " + LatestVersion;
            }
        }