Skip to content

Commit 364e513

Browse files
committed
Bug Fixes and improvements
- Fixed an error preventing WinNUT from starting during a new installation (no problem if WinNUT was already installed in a later version) - Addition of the possibility of creating a Bug Report when WinNUT encounters a critical error in order to retrieve the information necessary to resolve this bug.
1 parent 7656234 commit 364e513

19 files changed

+4506
-1888
lines changed

WinNUT_V2/Setup/Setup.vdproj

Lines changed: 3244 additions & 695 deletions
Large diffs are not rendered by default.

WinNUT_V2/WinNUT_GUI/ApplicationEvents.vb

Lines changed: 117 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,124 @@ Namespace My
1515
' StartupNextInstance : Déclenché lors du lancement d'une application à instance unique et si cette application est déjà active.
1616
' NetworkAvailabilityChanged : Déclenché quand la connexion réseau est connectée ou déconnectée.
1717
Partial Friend Class MyApplication
18+
Private CrashBug_Form As New Form
19+
Private BtnClose As New Button
20+
Private BtnGenerate As New Button
21+
Private Msg_Crash As New Label
22+
Private Msg_Error As New TextBox
1823
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
19-
My.Application.Log.WriteException(e.Exception,
20-
TraceEventType.Critical,
21-
WinNUT_Globals.StrLog.Item(AppResxStr.STR_APP_SHUT) &
22-
My.Computer.Clock.GmtTime.ToString)
24+
e.ExitApplication = False
25+
26+
Dim Frms As New FormCollection
27+
Frms = Application.OpenForms()
28+
29+
With Msg_Crash
30+
.Location = New Point(6, 6)
31+
.Text = "WinNUT has encountered a critical error and will close soon." & vbNewLine &
32+
"You can :" & vbNewLine &
33+
"- generate a crash report which will contain most of the configured parameters (without sensitive" & vbNewLine &
34+
" information such as your connection information to your NUT server), the last 50 events logged" & vbNewLine &
35+
" and the error message displayed below." & vbNewLine &
36+
" This information will Then be copied To your clipboard For easy reporting." & vbNewLine &
37+
"- simply close WinNUT without generating a report."
38+
.Size = New Point(470, 100)
39+
End With
40+
41+
Dim Exception_data As String = String.Format("Exception type: {0}" & vbNewLine & "Exception message: {1}" & vbNewLine & "Exception stack trace: " & vbNewLine & "{2}",
42+
e.Exception.GetType.ToString, e.Exception.Message, e.Exception.StackTrace)
43+
With Msg_Error
44+
.Location = New Point(6, 110)
45+
.Multiline = True
46+
.ScrollBars = ScrollBars.Vertical
47+
.ReadOnly = True
48+
.Text = Exception_data
49+
.Size = New Point(470, 300)
50+
End With
51+
52+
With BtnClose
53+
.Location = New Point(370, 425)
54+
.TextAlign = ContentAlignment.MiddleCenter
55+
.Text = "Close WinNUT"
56+
.Size = New Point(100, 25)
57+
End With
58+
59+
With BtnGenerate
60+
.Location = New Point(160, 425)
61+
.TextAlign = ContentAlignment.MiddleCenter
62+
.Text = "Generate Report and Close WinNUT"
63+
.Size = New Point(200, 25)
64+
End With
65+
66+
With CrashBug_Form
67+
.Icon = Resources.WinNut
68+
.Size = New Point(500, 500)
69+
.FormBorderStyle = FormBorderStyle.Sizable
70+
.MaximizeBox = False
71+
.MinimizeBox = False
72+
.StartPosition = FormStartPosition.CenterParent
73+
.Text = "Critical Error Occurred in WinNUT"
74+
.Controls.Add(Msg_Crash)
75+
.Controls.Add(Msg_Error)
76+
.Controls.Add(BtnClose)
77+
.Controls.Add(BtnGenerate)
78+
End With
79+
80+
AddHandler BtnClose.Click, AddressOf My.Application.Close_Button_Click
81+
AddHandler BtnGenerate.Click, AddressOf My.Application.Generate_Button_Click
82+
AddHandler CrashBug_Form.FormClosing, AddressOf My.Application.CrashBug_FormClosing
83+
84+
CrashBug_Form.Show()
85+
CrashBug_Form.BringToFront()
86+
WinNUT.HasCrased = True
87+
End Sub
88+
89+
Private Sub CrashBug_FormClosing(sender As Object, e As FormClosingEventArgs)
90+
End
91+
End Sub
92+
Private Sub Close_Button_Click(sender As Object, e As EventArgs)
93+
End
94+
End Sub
95+
96+
Private Sub Generate_Button_Click(sender As Object, e As EventArgs)
97+
'Generate a bug report with all essential datas
98+
Dim Crash_Report As String = "WinNUT Bug Report" & vbNewLine
99+
Dim WinNUT_Config As New Dictionary(Of String, Object)(WinNUT_Params.Arr_Reg_Key)
100+
Dim WinNUT_UserData_Dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\WinNUT-Client"
101+
Dim CrashLog_Dir = WinNUT_UserData_Dir & "\CrashLog"
102+
Dim CrashLog_Filename As String = "Crash_Report_" & Format(Now, "dd-MM-yyyy") & "_" &
103+
String.Format("{0}-{1}-{2}.txt", Now.Hour.ToString("00"), Now.Minute.ToString("00"), Now.Second.ToString("00"))
104+
105+
For Each kvp As KeyValuePair(Of String, Object) In WinNUT_Params.Arr_Reg_Key
106+
Select Case kvp.Key
107+
Case "ServerAddress", "Port", "UPSName", "NutLogin", "NutPassword"
108+
WinNUT_Config.Remove(kvp.Key)
109+
End Select
110+
Next
111+
112+
Crash_Report &= "Os Version : " & My.Computer.Info.OSVersion & vbNewLine
113+
Crash_Report &= "WinNUT Version : " & System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString & vbNewLine
114+
115+
Crash_Report &= vbNewLine & "WinNUT Parameters : " & vbNewLine
116+
117+
Crash_Report &= Newtonsoft.Json.JsonConvert.SerializeObject(WinNUT_Config, Newtonsoft.Json.Formatting.Indented) & vbNewLine
118+
Crash_Report &= vbNewLine & "Error Message : " & vbNewLine
119+
Crash_Report &= Msg_Error.Text & vbNewLine & vbNewLine
120+
Crash_Report &= "Last Events :" & vbNewLine
121+
122+
For Each WinNUT_Event In WinNUT.LogFile.LastEvents
123+
Crash_Report &= WinNUT_Event & vbNewLine
124+
Next
125+
My.Computer.Clipboard.SetText(Crash_Report)
126+
127+
If Not My.Computer.FileSystem.DirectoryExists(CrashLog_Dir) Then
128+
My.Computer.FileSystem.CreateDirectory(CrashLog_Dir)
129+
End If
130+
131+
Dim CrashLog_Report As System.IO.StreamWriter
132+
CrashLog_Report = My.Computer.FileSystem.OpenTextFileWriter(CrashLog_Dir & "\" & CrashLog_Filename, True)
133+
CrashLog_Report.WriteLine(Crash_Report)
134+
CrashLog_Report.Close()
135+
End
23136
End Sub
24137
End Class
25138
End Namespace

WinNUT_V2/WinNUT_GUI/CryptData.vb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ Public NotInheritable Class CryptData
3434

3535
Public Function EncryptData(ByVal plaintext As String) As String
3636

37+
' An empty string ("") passed as an argument is received as 'Nothing'
3738
If IsNothing(plaintext) Then
3839
plaintext = ""
3940
End If
41+
4042
' Convert the plaintext string to a byte array.
4143
Dim plaintextBytes() As Byte =
4244
System.Text.Encoding.Unicode.GetBytes(plaintext)

WinNUT_V2/WinNUT_GUI/List_Var_Gui.Designer.vb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)