private void loadConfig() { if (File.Exists(Application.StartupPath + @"\credentials")) { var credentials = Base64Decode(File.ReadAllText(Application.StartupPath + @"\credentials")); if (!instance.login(credentials.Substring(0, credentials.IndexOf(":")), credentials.Substring(credentials.IndexOf(":") + 1, credentials.Length - credentials.IndexOf(":") - 1))) { MessageBox.Show(@"Login failed. This may be due to incorrect username/password, or the need to fill out a Captcha."); File.Delete(Application.StartupPath + @"\credentials"); Application.Restart(); } else { var vpnDetails = instance.getCredentials(); while (vpnDetails.Length == 2) { if (instance.createNewCredentials()) { vpnDetails = instance.getCredentials(); } else { break; } } if (vpnDetails.Length == 2) { MessageBox.Show(@"There are currently no Linux devices on your account, and creating a new one failed. The program cannot continue. Please create a new Linux device in your CyberGhost control panel."); return; } try { var linuxMachine = vpnDetails.Substring(1, vpnDetails.Length - 2).Split(new string[] { "},{" }, StringSplitOptions.None).Single(str => str.ToLower().Contains("linux, router")); JObject o = JObject.Parse(linuxMachine.StartsWith("{") ? linuxMachine + "}" : "{" + linuxMachine); txtUsername.Text = (o["token"].ToString()); txtPassword.Text = (o["secret"].ToString()); var serverDetails = instance.getServers(); o = JObject.Parse(serverDetails); foreach (var serverInfo in o["countries"]) { try { var server = JObject.Parse(serverInfo["servers"].ToString().Substring(1, serverInfo["servers"].ToString().Length - 2)); if (server["name"].ToString() == "Premium Servers") { cbxServers.Items.Add(server["url"].ToString()); } cbxServers.SelectedIndex = 0; } catch (Exception) { txtLog.Text += @"[CyberGhosty] Failed to parse server list from CyberGhost website" + Environment.NewLine; } } } catch (Exception) { txtLog.Text += @"[CyberGhosty] Failed to download config files from CyberGhost website" + Environment.NewLine; } bwGetIP.RunWorkerAsync(); } } else { var loginForm = new frmLogin(); if (loginForm.ShowDialog() == DialogResult.OK){ loadConfig(); } } }