Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 131846b

Browse files
committed
import customized config files
1 parent 9e430b4 commit 131846b

File tree

6 files changed

+166
-39
lines changed

6 files changed

+166
-39
lines changed

V2RayW/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
"concurrency": 8
7676
}</value>
7777
</setting>
78+
<setting name="cusProfiles" serializeAs="String">
79+
<value />
80+
</setting>
7881
</V2RayW.Properties.Settings>
7982
</userSettings>
8083
</configuration>

V2RayW/FormImport.Designer.cs

Lines changed: 60 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

V2RayW/FormImport.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,99 @@
77
using System.Text;
88
using System.Threading.Tasks;
99
using System.Windows.Forms;
10+
using System.Diagnostics;
1011

1112
namespace V2RayW
1213
{
1314
public partial class FormImport : Form
1415
{
16+
public static List<String> configJsonPaths = new List<string>();
17+
1518
public FormImport()
1619
{
1720
InitializeComponent();
1821
}
1922

2023
private void buttonFinish_Click(object sender, EventArgs e)
2124
{
25+
labelIndicator.Text = "verifying...";
26+
foreach(var jsonpath in configJsonPaths)
27+
{
28+
try
29+
{
30+
ProcessStartInfo info = new ProcessStartInfo();
31+
string v2rayBin = AppDomain.CurrentDomain.BaseDirectory + "v2ray.exe";
32+
info.FileName = v2rayBin;
33+
info.Arguments = "-test -config " + jsonpath;
34+
info.WindowStyle = ProcessWindowStyle.Hidden;
35+
Process proBach = Process.Start(info);
36+
proBach.WaitForExit();
37+
int returnValue = proBach.ExitCode;
38+
if(returnValue != 0)
39+
{
40+
MessageBox.Show(jsonpath + " is not a valid v2ray config file!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
41+
labelIndicator.Text = "";
42+
return;
43+
}
44+
}
45+
catch (Exception ex)
46+
{
47+
MessageBox.Show(ex.Message);
48+
labelIndicator.Text = "";
49+
return;
50+
}
51+
}
52+
Properties.Settings.Default["cusProfiles"] = string.Join("*", configJsonPaths);
2253
this.Close();
2354
}
55+
56+
private void buttonAdd_Click(object sender, EventArgs e)
57+
{
58+
if (dialog.ShowDialog() == DialogResult.OK)
59+
{
60+
configJsonPaths.Add(dialog.FileName);
61+
listBoxCusConfig.Items.Clear();
62+
foreach (var path in configJsonPaths)
63+
{
64+
listBoxCusConfig.Items.Add(path);
65+
}
66+
}
67+
}
68+
69+
private void buttonRemove_Click(object sender, EventArgs e)
70+
{
71+
if (listBoxCusConfig.SelectedIndex > configJsonPaths.Count || listBoxCusConfig.SelectedIndex < 0)
72+
{
73+
return;
74+
}
75+
configJsonPaths.RemoveAt(listBoxCusConfig.SelectedIndex);
76+
listBoxCusConfig.Items.Clear();
77+
foreach (var path in configJsonPaths)
78+
{
79+
listBoxCusConfig.Items.Add(path);
80+
}
81+
listBoxCusConfig_SelectedValueChanged(sender, e);
82+
}
83+
84+
private void FormImport_Load(object sender, EventArgs e)
85+
{
86+
labelIndicator.Text = "";
87+
string[] savedProfiles = Properties.Settings.Default["cusProfiles"].ToString().Split('*');
88+
configJsonPaths.Clear();
89+
foreach(var p in savedProfiles)
90+
{
91+
if(p.Trim().Length > 0)
92+
{
93+
configJsonPaths.Add(p);
94+
listBoxCusConfig.Items.Add(p);
95+
}
96+
}
97+
listBoxCusConfig_SelectedValueChanged(sender, e);
98+
}
99+
100+
private void listBoxCusConfig_SelectedValueChanged(object sender, EventArgs e)
101+
{
102+
buttonRemove.Enabled = listBoxCusConfig.SelectedIndex < configJsonPaths.Count && listBoxCusConfig.SelectedIndex >= 0;
103+
}
24104
}
25105
}

V2RayW/FormImport.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,7 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<metadata name="dialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>17, 17</value>
122+
</metadata>
120123
</root>

V2RayW/Properties/Settings.Designer.cs

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

V2RayW/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,8 @@
6767
"concurrency": 8
6868
}</Value>
6969
</Setting>
70+
<Setting Name="cusProfiles" Type="System.String" Scope="User">
71+
<Value Profile="(Default)" />
72+
</Setting>
7073
</Settings>
7174
</SettingsFile>

0 commit comments

Comments
 (0)