public Refresh Refresh()
 {
     var refresh = new Refresh(SessionToken, AccessToken);
     refresh = (Refresh)refresh.DoPost();
     SessionToken = refresh.accessToken;
     AccessToken = refresh.clientToken;
     UserProperties = (JArray)refresh.user["properties"];
     return refresh;
 }
 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();
 }