public MainWindow() { DataContext = this; wantsConnect = false; sReroute = new StreamReroute(); InitializeComponent(); if (Properties.Settings.Default.needsUpgrade) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.needsUpgrade = false; Properties.Settings.Default.Save(); } this.Topmost = true; PopulateComboBox(); bool needsLoginWindow = true; if (checkLogin()) { // VPN for some reason still in place if (vpnControl.checkVPNExists()) { //initTimer(); needsLoginWindow = false; setConnecting(); } // else check certificate installed; then go ahead and add back VPN else if (VPNControl.checkCertificateInstalled() && !noInternet) { needsLoginWindow = false; vpnControl.addVPN(Properties.Settings.Default.region); setConnecting(); //initTimer(); } else if (noInternet && !needsLoginWindow) { System.Windows.Forms.MessageBox.Show("Can't connect to server."); } else if (!VPNControl.checkCertificateInstalled() && !noInternet) { // reinstall certificates var getKeyResponse = apiControl.getKey(); var getKeyResponseString = getKeyResponse.Result.Content.ReadAsStringAsync(); var getKeyDict = JsonConvert.DeserializeObject <Dictionary <string, string> >(getKeyResponseString.Result); if (getKeyDict.ContainsKey("b64")) { string tempFile = System.IO.Path.GetTempFileName(); File.WriteAllBytes(tempFile, Convert.FromBase64String(getKeyDict["b64"])); VPNControl.addCertificate(tempFile); needsLoginWindow = false; vpnControl.addVPN(Properties.Settings.Default.region); setConnecting(); } } else { needsLoginWindow = true; } } // if not ready to run VPN, send to login window if (needsLoginWindow) { handleLoginForm(false); } else { notifyIcon.Visible = true; initTimer(); } //initNotifyIcon(); // For crash testing //int x = 0; //int y = 1 / x; //SetWindowPosition(); }
private void installButton_Click(object sender, RoutedEventArgs e) { var getKeyResponse = apiControl.getKey(); var getKeyResponseString = getKeyResponse.Result.Content.ReadAsStringAsync(); var getKeyDict = JsonConvert.DeserializeObject <Dictionary <string, string> >(getKeyResponseString.Result); installButton.IsEnabled = false; installHideButton.Visibility = Visibility.Hidden; new System.Threading.Thread(() => { if (getKeyDict.ContainsKey("b64")) { string tempFile = System.IO.Path.GetTempFileName(); File.WriteAllBytes(tempFile, Convert.FromBase64String(getKeyDict["b64"])); VPNControl.addCertificate(tempFile); if (VPNControl.checkCertificateInstalled()) { string defaultRegion = Properties.Settings.Default.region; if (defaultRegion == "") { defaultRegion = "United States - West"; string regionCode = RegionInfo.CurrentRegion.TwoLetterISORegionName.ToUpper(); if (regionCode == "US") { TimeZone theTZ = TimeZone.CurrentTimeZone; if (theTZ.StandardName == "Eastern Standard Time" || theTZ.StandardName == "Central Standard Time") { defaultRegion = "United States - East"; } } if (regionCode == "GB") { defaultRegion = "United Kingdom"; } if (regionCode == "IE") { defaultRegion = "Ireland"; } if (regionCode == "CA") { defaultRegion = "Canada"; } if (regionCode == "KO") { defaultRegion = "South Korea"; } if (regionCode == "SG") { defaultRegion = "Singapore"; } if (regionCode == "DE" || regionCode == "FR" || regionCode == "IT" || regionCode == "PT" || regionCode == "ES" || regionCode == "AT" || regionCode == "PL" || regionCode == "RU" || regionCode == "UA") { defaultRegion = "Germany"; } if (regionCode == "AU" || regionCode == "NZ") { defaultRegion = "Australia"; } if (regionCode == "JP") { defaultRegion = "Japan"; } if (regionCode == "IN" || regionCode == "PK" || regionCode == "BD") { defaultRegion = "India"; } if (regionCode == "BR" || regionCode == "CO" || regionCode == "VE" || regionCode == "AR") { defaultRegion = "Brazil"; } } //VPNControl.addVPN(defaultRegion); Properties.Settings.Default.region = defaultRegion; Properties.Settings.Default.Save(); this.Dispatcher.Invoke(() => { this.Close(); }); } else { // No Certificate found by that subject name. } } else { } this.Dispatcher.Invoke(() => { installButton.IsEnabled = true; }); }).Start(); }