-
Notifications
You must be signed in to change notification settings - Fork 38
/
ServerWindow.xaml.cs
109 lines (94 loc) · 4.04 KB
/
ServerWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace SapphireBootWPF
{
/// <summary>
/// Interaction logic for ServerWindow.xaml
/// </summary>
public partial class ServerWindow : Window
{
public ServerWindow()
{
InitializeComponent();
if(Properties.Settings.Default.WebServerUrl != "https://default")
lobbyTextBox.Text = Properties.Settings.Default.WebServerUrl;
gamePathTextBox.Text = Properties.Settings.Default.ClientPath;
launchParamsTextBox.Text = Properties.Settings.Default.LaunchParams;
expansionLevelComboBox.SelectedIndex = Properties.Settings.Default.ExpansionLevel;
languageComboBox.SelectedIndex = Properties.Settings.Default.SavedLanguage;
launcherCloseOnLaunch.IsChecked = Properties.Settings.Default.CloseOnLaunch;
}
private void backButton_Click(object sender, RoutedEventArgs e)
{
MainWindow mainwindow = new MainWindow();
mainwindow.Left = this.Left;
mainwindow.Top = this.Top;
mainwindow.Show();
this.Close();
}
private void selectPathButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*";
openFileDialog.ShowDialog();
if (openFileDialog.FileName != "")
gamePathTextBox.Text = openFileDialog.FileName;
}
private void checkDataButton_Click(object sender, RoutedEventArgs e)
{
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
var uiTaskFactory = new TaskFactory(uiScheduler);
Parallel.Invoke(() =>
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
try
{
client.DownloadString(lobbyTextBox.Text);
errorLabel.Foreground = Brushes.Green;
errorLabel.Content = "Connection successful.";
}
catch(Exception)
{
errorLabel.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 0xDC, 0, 0));
errorLabel.Content = "Connection failed, the server may be unavailable.";
}
}
});
}
private void saveDataButton_Click(object sender, RoutedEventArgs e)
{
// todo: fix the race condition that occurs here because properties.settings isnt updated when cef uses webserverurl
//var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
//var uiTaskFactory = new TaskFactory(uiScheduler);
//uiTaskFactory.StartNew(() =>
//{
Properties.Settings.Default.WebServerUrl = lobbyTextBox.Text;
Properties.Settings.Default.ClientPath = gamePathTextBox.Text;
Properties.Settings.Default.LaunchParams = launchParamsTextBox.Text;
Properties.Settings.Default.ExpansionLevel = expansionLevelComboBox.SelectedIndex;
Properties.Settings.Default.SavedLanguage = languageComboBox.SelectedIndex;
Properties.Settings.Default.CloseOnLaunch = launcherCloseOnLaunch.IsChecked.Value;
Properties.Settings.Default.Save( );
Properties.Settings.Default.Reload( );
//});
MainWindow mainwindow = new MainWindow( );
mainwindow.Left = this.Left;
mainwindow.Top = this.Top;
mainwindow.Show( );
this.Close( );
}
}
}