示例#1
0
        private void radButton1_Click(object sender, EventArgs e)
        {
            try
            {

                Logging.Info("Authenticating...");
                var auth = new AuthManager {Email = username.Text, Password = password.Text};
                auth.Login();
                var jo = JObject.Parse(File.ReadAllText(Variables.McFolder + "/luncher/userprofiles.json"));
                jo["selectedUsername"] = auth.Username;
                var item = (JObject)jo["profiles"];
                try
                {
                    item.Remove(auth.Username);
                }
                catch { }
                item.Add(new JProperty(auth.Username, new JObject
                {
                    new JProperty("type", "official"),
                    new JProperty("accessToken", auth.SessionToken),
                    new JProperty("clientToken", auth.AccessToken),
                    new JProperty("UUID", auth.Uuid),
                    new JProperty("properties", auth.UserProperties)
                }));
                File.WriteAllText(Variables.McFolder + "/luncher/userprofiles.json", jo.ToString());
                Result = Localization_LoginForm.LoginDialog_Added_successfuly;
                Processing.ShowAlert(Localization_LoginForm.LoginDialog_Added_successfuly, Localization_LoginForm.LoginDialog_Added_successfuly_message);
                Close();
            }
            catch(Exception a)
            {
                Logging.Info(Localization_LoginForm.LoginDialog_SmthWentWrong + "\n" + a);
                radLabel1.Text = Localization_LoginForm.LoginDialog_SmthWentWrong + "\n" + a.Data;
            }
        }
示例#2
0
 private void Launch(string profileJson)
 {
     var properties = new JObject();
     try
     {
         var add = true;
         var txt = Variables.McFolder + "/luncher/userprofiles.json";
         var jo = JObject.Parse(File.ReadAllText(txt));
         var profiles = (JObject)jo["profiles"];
         foreach (JProperty peep in jo["profiles"].Cast<JProperty>().Where(peep => peep.Name == Nickname.Text))
         {
             add = false;
             if (jo["profiles"][peep.Name]["type"].ToString() == "pirate")
             {
                 Variables.AccessToken = "1i1ii1i111ii1i1i1i1i1ii1ii1ii111";
                 Variables.ClientToken = "11i1111i11ii11iii1i1i11iiii11iii";
                 properties.Add(new JProperty("luncher", new JArray("228apasna")));
             }
             else
             {
                 var a = new AuthManager
                 {
                     SessionToken = jo["profiles"][peep.Name]["accessToken"].ToString(),
                     Uuid = jo["profiles"][peep.Name]["UUID"].ToString()
                 };
                 var b = a.CheckSessionToken();
                 if (!b)
                 {
                     a.AccessToken = jo["profiles"][peep.Name]["clientToken"].ToString();
                     a.Refresh();
                     jo["profiles"][peep.Name]["accessToken"] = a.SessionToken;
                 }
                 Variables.AccessToken = jo["profiles"][peep.Name]["accessToken"].ToString();
                 Variables.ClientToken = jo["profiles"][peep.Name]["UUID"].ToString();
                 if (jo["profiles"][peep.Name]["properties"].HasValues)
                     foreach (JObject prop in jo["profiles"][peep.Name]["properties"])
                         properties.Add(new JProperty(prop["name"].ToString(), new JArray(prop["value"])));
                 else
                     properties.Add(new JProperty("luncher", new JArray("228apasna")));
             }
             break;
         }
         if (add)
         {
             profiles.Add(Nickname.Text, new JObject {new JProperty("type", "pirate")});
             properties.Add(new JProperty("luncher", new JArray("228apasna")));
         }
         File.WriteAllText(txt, jo.ToString());
         var lselected = Nickname.Text;
         UpdateUserProfiles();
         Nickname.SelectedValue = lselected;
     }
     catch(Exception ex)
     {
         new RadMessageBoxForm
         {
             Text = @"Authorization required",
             MessageText = "Client token or smth else isn't valid. Authorization required?",
             StartPosition = FormStartPosition.CenterScreen,
             ButtonsConfiguration = MessageBoxButtons.OK,
             TopMost = true,
             MessageIcon = Processing.GetRadMessageIcon(RadMessageIcon.Info),
             Owner = this,
             DetailsText = ex.Message,
         }.ShowDialog();
         Variables.AccessToken = "1i1ii1i111ii1i1i1i1i1ii1ii1ii111";
         Variables.ClientToken = "11i1111i11ii11iii1i1i11iiii11iii";
         properties.Add(new JProperty("luncher", new JArray("228apasna")));
     }
     HideProgressBar();
     using (var thr = new BackgroundWorker())
     {
         thr.DoWork += delegate
         {
             var total = 0;
             foreach (var a in _nativelibs)
                 try
                 {
                     using (var zip = ZipFile.Read(Variables.McFolder + "\\libraries\\" + a))
                         foreach (var e in zip.Where(e => e.FileName.EndsWith(".dll")))
                         {
                             total++;
                             e.Extract(Variables.McFolder + "\\natives\\",
                                 ExtractExistingFileAction.OverwriteSilently);
                         }
                 }
                 catch (Exception ex)
                 {
                     Logging.Error("Smth went wrong due unpacking " + a + ": " + ex.Message);
                 }
             Logging.Info(string.Format("Распаковка natives завершена. Всего извлечено {0} файлов", total));
         };
         thr.RunWorkerCompleted += delegate
         {
             var finallibraries = _libs.Aggregate(string.Empty,
                 (current, a) => current + (a + ";"));
             finallibraries = finallibraries.Substring(0, finallibraries.Length - 1);
             var mp = new MinecraftProcess(this, usingAssets.Text, finallibraries, _assets, profileJson, properties);
             mp.Launch();
         };
         thr.RunWorkerAsync();
     }
 }