-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
190 lines (166 loc) · 5.76 KB
/
MainWindow.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.Json;
using System.IO;
using System.Diagnostics;
using System.Text.Encodings.Web;
using System.Security.Policy;
using System.Data;
namespace rbq_ray
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<Server> servers = new ObservableCollection<Server>();
public MainWindow()
{
InitializeComponent();
if (File.Exists("servers.json"))
{
servers = JsonSerializer.Deserialize<ObservableCollection<Server>>(File.ReadAllText("servers.json"));
}
serverDataGrid.DataContext = servers;
}
private void serverAddHttpMenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.HTTP);
serverWindow.ShowDialog();
saveServers();
}
private void serverAddSocksMenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.SOCKS);
serverWindow.ShowDialog();
saveServers();
}
private void serverAddSsMenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.SS);
serverWindow.ShowDialog();
saveServers();
}
private void serverAddSs2022MenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.SS2022);
serverWindow.ShowDialog();
saveServers();
}
private void serverAddVmessMenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.VMESS);
serverWindow.ShowDialog();
saveServers();
}
private void serverAddVlessMenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.VLESS);
serverWindow.ShowDialog();
saveServers();
}
private void serverAddTrojanMenuItem_Click(object sender, RoutedEventArgs e)
{
ServerWindow serverWindow = new ServerWindow(ServerWindow.TROJAN);
serverWindow.ShowDialog();
saveServers();
}
protected void editServer()
{
if(serverDataGrid.SelectedItem == null) {
return;
}
ServerWindow serverWindow = new ServerWindow((Server)serverDataGrid.SelectedItem, serverDataGrid.SelectedIndex);
serverWindow.ShowDialog();
saveServers();
}
private void serverEditMenuItem_Click(object sender, RoutedEventArgs e)
{
editServer();
}
private void serverEditContextMenuItem_Click(object sender, RoutedEventArgs e)
{
editServer();
}
private void aboutMenuItem_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("An RBQ University Production.\nVersion: 0.0.1", "关于", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void exitMenuItem_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
protected void saveServers()
{
JsonSerializerOptions options = new JsonSerializerOptions() {
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
File.WriteAllText("servers.json", JsonSerializer.Serialize(servers, options));
}
protected void copyServers()
{
String urls = "";
foreach(Server server in serverDataGrid.SelectedItems)
{
urls = server.url.OriginalString + "\n";
}
Clipboard.SetText(urls);
Debug.WriteLine(urls);
}
private void serverCopyMenuItem_Click(object sender, RoutedEventArgs e)
{
copyServers();
}
private void serverCopyContextMenuItem_Click(object sender, RoutedEventArgs e)
{
copyServers();
}
protected void deleteServers()
{
ObservableCollection<Server> serversPending = new ObservableCollection<Server>();
foreach (Server server in serverDataGrid.SelectedItems)
{
serversPending.Add(server);
}
foreach(Server server in serversPending)
{
servers.Remove(server);
}
saveServers();
}
private void deleteServerContextMenuItem_Click(object sender, RoutedEventArgs e)
{
deleteServers();
}
private void deleteServerMenuItem_Click(object sender, RoutedEventArgs e)
{
deleteServers();
}
}
public class Server
{
public bool enabled { get; set; }
public string protocol { get; set; }
public string name { get; set; }
public string address { get; set; }
public ushort port { get; set; }
public string transport { get; set; }
public string security { get; set; }
public string subscribe { get; set; }
public short delay { get; set; }
public Uri url { get; set; }
}
}