private void LaunchButton_Click(object sender, EventArgs e) { BlockControls = true; if (string.IsNullOrWhiteSpace(NicknameDropDownList.Text)) { NicknameDropDownList.Text = $"Player{LinuxTimeStamp}"; } BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += delegate { CheckVersionAvailability(); UpdateVersionListView(); }; bgw.RunWorkerCompleted += delegate { string libraries = string.Empty; BackgroundWorker bgw1 = new BackgroundWorker(); bgw1.DoWork += delegate { libraries = GetLibraries(); }; bgw1.RunWorkerCompleted += delegate { BackgroundWorker bgw2 = new BackgroundWorker(); bgw2.DoWork += delegate { CheckGameResources(); }; bgw2.RunWorkerCompleted += delegate { if (!_userManager.Accounts.ContainsKey(NicknameDropDownList.Text)) { User user = new User { Username = NicknameDropDownList.Text, Type = "offline" }; _userManager.Accounts.Add(user.Username, user); _selectedUser = user; } else { _selectedUser = _userManager.Accounts[NicknameDropDownList.Text]; if (_selectedUser.Type != "offline") { AuthManager am = new AuthManager { SessionToken = _selectedUser.SessionToken, Uuid = _selectedUser.Uuid }; bool check = am.CheckSessionToken(); if (!check) { RadMessageBox.Show( "Session token is not valid. Please, head up to user manager and re-add your account.", _applicationContext.ProgramLocalization.Error, MessageBoxButtons.OK, RadMessageIcon.Exclamation); User user = new User { Username = NicknameDropDownList.Text, Type = "offline" }; _selectedUser = user; } else { Refresh refresh = new Refresh(_selectedUser.SessionToken, _selectedUser.AccessToken); _selectedUser.UserProperties = (JArray) refresh.user["properties"]; _selectedUser.SessionToken = refresh.accessToken; _userManager.Accounts[NicknameDropDownList.Text] = _selectedUser; } } } _userManager.SelectedUsername = _selectedUser.Username; SaveUsers(); UpdateUserList(); Version selectedVersion = Version.ParseVersion( new DirectoryInfo(_applicationContext.McVersions + (_versionToLaunch ?? ( (_selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile)))))); JObject properties = new JObject { new JProperty("freelauncher", new JArray("cheeki_breeki_iv_damke")) }; if (_selectedProfile.FastConnectionSettigs != null) { selectedVersion.ArgumentCollection.Add("server", _selectedProfile.FastConnectionSettigs.ServerIP); selectedVersion.ArgumentCollection.Add("port", _selectedProfile.FastConnectionSettigs.ServerPort.ToString()); } string javaArgumentsTemp = _selectedProfile.JavaArguments == null ? string.Empty : _selectedProfile.JavaArguments + " "; if (_selectedProfile.WorkingDirectory != null && !Directory.Exists(_selectedProfile.WorkingDirectory)) { Directory.CreateDirectory(_selectedProfile.WorkingDirectory); } ProcessStartInfo proc = new ProcessStartInfo { UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, FileName = _selectedProfile.JavaExecutable ?? Java.JavaExecutable, StandardErrorEncoding = Encoding.UTF8, WorkingDirectory = _selectedProfile.WorkingDirectory ?? _applicationContext.McDirectory, Arguments = $"{javaArgumentsTemp}-Djava.library.path={_applicationContext.McDirectory + "natives\\"} -cp {(libraries.Contains(' ') ? $"\"{libraries}\"" : libraries)} {selectedVersion.MainClass} {selectedVersion.ArgumentCollection.ToString(new Dictionary<string, string> {{"auth_player_name", _selectedUser.Type == "offline" ? NicknameDropDownList.Text : new Username() {Uuid = _selectedUser.Uuid}.GetUsernameByUuid()}, {"version_name", _selectedProfile.ProfileName}, {"game_directory", _selectedProfile.WorkingDirectory ?? _applicationContext.McDirectory}, {"assets_root", _applicationContext.McDirectory + "assets\\"}, {"game_assets", _applicationContext.McDirectory + "assets\\legacy\\"}, {"assets_index_name", selectedVersion.AssetsIndex}, { "version_type", selectedVersion.ReleaseType }, {"auth_session", _selectedUser.AccessToken ?? "sample_token"}, {"auth_access_token", _selectedUser.SessionToken ?? "sample_token"}, {"auth_uuid", _selectedUser.Uuid ?? "sample_token"}, {"user_properties", _selectedUser.UserProperties?.ToString(Formatting.None) ?? properties.ToString(Formatting.None)}, {"user_type", _selectedUser.Type}})}" }; AppendLog($"Command line: \"{proc.FileName}\" {proc.Arguments}"); AppendLog($"Version {selectedVersion.VersionId} successfuly launched."); new MinecraftProcess(new Process {StartInfo = proc, EnableRaisingEvents = true}, this, _selectedProfile).Launch(); BlockControls = false; UpdateVersionListView(); _versionToLaunch = null; _restoreVersion = false; }; bgw2.RunWorkerAsync(); }; bgw1.RunWorkerAsync(); }; bgw.RunWorkerAsync(); }
private void NicknameDropDownList_SelectedIndexChanged(object sender, PositionChangedEventArgs e) { if (NicknameDropDownList.SelectedItem == null) { return; } _userManager.SelectedUsername = NicknameDropDownList.SelectedItem.Text; _selectedUser = _userManager.Accounts[NicknameDropDownList.SelectedItem.Text]; SaveUsers(); }
private void AddUserButton_Click(object sender, EventArgs e) { AddUserButton.Enabled = UsernameTextBox.Enabled = PasswordTextBox.Enabled = YesNoToggleSwitch.Enabled = false; ControlBox = false; AddUserButton.Text = _applicationContext.ProgramLocalization.PleaseWait; BackgroundWorker bgw = new BackgroundWorker(); bgw.DoWork += delegate { User user = new User {Username = UsernameTextBox.Text}; if (!YesNoToggleSwitch.Value) { user.Type = "offline"; if (_userManager.Accounts.ContainsKey(user.Username)) { _userManager.Accounts[user.Username] = user; } else { _userManager.Accounts.Add(user.Username, user); } _userManager.SelectedUsername = user.Username; SaveUsers(); UpdateUsers(); return; } AuthManager auth = new AuthManager {Email = UsernameTextBox.Text, Password = PasswordTextBox.Text}; try { auth.Login(); user.Type = auth.IsLegacy ? "legacy" : "mojang"; user.AccessToken = auth.AccessToken; user.SessionToken = auth.SessionToken; user.Uuid = auth.Uuid; user.UserProperties = auth.UserProperties; if (_userManager.Accounts.ContainsKey(user.Username)) { _userManager.Accounts[user.Username] = user; } else { _userManager.Accounts.Add(user.Username, user); } _userManager.SelectedUsername = user.Username; } catch (WebException ex) { switch (ex.Status) { case WebExceptionStatus.ProtocolError: RadMessageBox.Show(_applicationContext.ProgramLocalization.IncorrectLoginOrPassword, _applicationContext.ProgramLocalization.Error, MessageBoxButtons.OK, RadMessageIcon.Error); return; default: return; } } Invoke(new Action(() => { SaveUsers(); UpdateUsers(); UsernameTextBox.Clear(); PasswordTextBox.Clear(); })); }; bgw.RunWorkerCompleted += delegate { UsernameTextBox.Enabled = YesNoToggleSwitch.Enabled = true; ControlBox = true; AddUserButton.Text = _applicationContext.ProgramLocalization.AddNewUserButton; YesNoToggleSwitch_ValueChanged(this, EventArgs.Empty); }; bgw.RunWorkerAsync(); }