Skip to content

Commit 617d3ab

Browse files
authored
Merge pull request #74 from FN-FAL113/Dev/firewall-check-and-reset
add firewall reset and status check function
2 parents 8aa2289 + 56b1c1b commit 617d3ab

File tree

6 files changed

+124
-12
lines changed

6 files changed

+124
-12
lines changed

CS2ServerPicker/App.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
Environment.NewLine +
132132
"Author: FN-FAL113 (github username)" + Environment.NewLine +
133133
"License: GNU General Public License V3" + Environment.NewLine +
134-
"App Version: 2.2.3",
134+
"App Version: 2.4.0",
135135
"App Info"
136136
)
137137
End Sub

CS2ServerPicker/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ Imports System.Runtime.InteropServices
3232
' by using the '*' as shown below:
3333
' <Assembly: AssemblyVersion("1.0.*")>
3434

35-
<Assembly: AssemblyVersion("2.2.3.0")>
36-
<Assembly: AssemblyFileVersion("2.2.3.0")>
35+
<Assembly: AssemblyVersion("2.4.0.0")>
36+
<Assembly: AssemblyFileVersion("2.4.0.0")>
3737
<Assembly: NeutralResourcesLanguage("en")>

CS2ServerPicker/Services/ServerService.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Module ServerService
152152
proc.WaitForExit()
153153

154154
If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
155-
Throw New Exception(proc.StandardOutput.ReadToEnd().Split(".")(0))
155+
Throw New Exception("StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
156156

157157
Continue For
158158
End If
@@ -215,7 +215,7 @@ Module ServerService
215215
proc.WaitForExit()
216216

217217
If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
218-
Throw New Exception(proc.StandardOutput.ReadToEnd().Split(".")(0))
218+
Throw New Exception("StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
219219

220220
Continue For
221221
End If
@@ -274,7 +274,7 @@ Module ServerService
274274
proc.WaitForExit()
275275

276276
If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
277-
Throw New Exception(proc.StandardOutput.ReadToEnd().Split(".")(0))
277+
Throw New Exception("StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
278278

279279
Continue For
280280
End If

CS2ServerPicker/Settings.Designer.vb

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

CS2ServerPicker/Settings.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,4 @@
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="BackgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121-
<value>17, 17</value>
122-
</metadata>
123120
</root>

CS2ServerPicker/Settings.vb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,69 @@
1010
VersionCheckerCheckBox.Checked = My.Settings.VersionCheckOnStartup
1111
End Sub
1212

13+
Private Sub ResetFirewallButton_Click(sender As Object, e As EventArgs) Handles ResetFirewallButton.Click
14+
Dim resetWindowsFirewallRes As DialogResult = MessageBox.Show("This will attempt to reset windows firewall to its default state. Confirm action?", "Reset Windows Firewall", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
15+
16+
If resetWindowsFirewallRes = DialogResult.Yes Then
17+
Try
18+
Dim proc As Process = Create_Custom_CMD_Process()
19+
20+
proc.StartInfo.Arguments = "/c netsh advfirewall reset"
21+
proc.Start()
22+
proc.WaitForExit()
23+
24+
If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
25+
Throw New Exception("Sdtout: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "Stderr: " + proc.StandardError.ReadToEnd())
26+
End If
27+
28+
MessageBox.Show("Windows firewall reset successful!", "Reset Windows Firewall", MessageBoxButtons.OK, MessageBoxIcon.Information)
29+
30+
proc.Dispose()
31+
Catch ex As Exception
32+
Log_Exception_To_File(ex, "An error has occurred while resetting windows firewall!")
33+
34+
MessageBox.Show("An error has occurred while resetting windows firewall!", "Error")
35+
End Try
36+
End If
37+
End Sub
38+
39+
Private Sub CheckFirewallButton_Click(sender As Object, e As EventArgs) Handles CheckFirewallButton.Click
40+
Dim checkWindowsFirewallRes As DialogResult = MessageBox.Show("This will attempt to check current state of windows firewall. Confirm action?", "Check Windows Firewall", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
41+
42+
If checkWindowsFirewallRes = DialogResult.Yes Then
43+
Try
44+
Dim proc As Process = Create_Custom_CMD_Process()
45+
46+
proc.StartInfo.Arguments = "/c netsh advfirewall show allprofiles state"
47+
proc.Start()
48+
proc.WaitForExit()
49+
50+
If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
51+
Throw New Exception("On firewall check" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
52+
End If
53+
54+
If proc.StandardOutput.ReadToEnd().Contains("OFF") Then
55+
Dim enableWinFirewallRes As DialogResult = MessageBox.Show("This will attempt to enable windows firewall. Confirm action?", "Enable Windows Firewall", MessageBoxButtons.YesNo, MessageBoxIcon.Information)
56+
57+
proc.StartInfo.Arguments = "/c netsh advfirewall set allprofiles state on"
58+
proc.Start()
59+
proc.WaitForExit()
60+
61+
If proc.ExitCode = 1 Or proc.ExitCode < 0 Then
62+
Throw New Exception("On firewall enable" + Environment.NewLine + "StdOut: " + proc.StandardOutput.ReadToEnd() + Environment.NewLine + "StdErr: " + proc.StandardError.ReadToEnd())
63+
End If
64+
65+
MessageBox.Show("Windows firewall profile states successfully enabled!", "Enable Windows Firewall", MessageBoxButtons.OK, MessageBoxIcon.Information)
66+
Else
67+
MessageBox.Show("Windows firewall profile states are all enabled.", "Windows Firewall Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
68+
End If
69+
70+
proc.Dispose()
71+
Catch ex As Exception
72+
Log_Exception_To_File(ex, "An error has occurred while checking/enabling windows firewall!")
73+
74+
MessageBox.Show("An error has occurred while checking/enabling windows firewall!", "Error")
75+
End Try
76+
End If
77+
End Sub
1378
End Class

0 commit comments

Comments
 (0)