Skip to content

Commit f6206b9

Browse files
authored
Merge pull request #36 from nutdotnet/sleepmode
Re-activate stop actions system, fix resume issues and status updates overhaul. Closes #27
2 parents 314e651 + 0f90e43 commit f6206b9

File tree

7 files changed

+228
-297
lines changed

7 files changed

+228
-297
lines changed

WinNUT_V2/WinNUT-Client/Shutdown_Gui.vb

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,45 @@
77
'
88
' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
99

10-
Imports WinNUT_Params = WinNUT_Client_Common.WinNUT_Params
11-
Imports Logger = WinNUT_Client_Common.Logger
1210
Imports LogLvl = WinNUT_Client_Common.LogLvl
1311
Imports AppResxStr = WinNUT_Client_Common.AppResxStr
14-
Imports WinNUT_Globals = WinNUT_Client_Common.WinNUT_Globals
12+
Imports WinNUT_Client_Common
13+
1514
Public Class Shutdown_Gui
16-
Private LogFile As Logger
1715
Private RedText As Boolean = True
1816
Private ReadOnly Shutdown_PBar As New WinFormControls.CProgressBar
19-
Private Start_Shutdown As DateTime
17+
Private Start_Shutdown As Date
2018
Private Offset_STimer As Double = 0
2119
Private STimer As Double = 0
2220
Private Remained As Double = 0
2321
Public Grace_Timer As New Timer
2422
Public Shutdown_Timer As New Timer
2523

2624
Private Sub Grace_Button_Click(sender As Object, e As EventArgs) Handles Grace_Button.Click
27-
Me.Shutdown_Timer.Stop()
28-
Me.Shutdown_Timer.Enabled = False
25+
Shutdown_Timer.Stop()
26+
Shutdown_Timer.Enabled = False
2927
Grace_Button.Enabled = False
30-
Me.Grace_Timer.Enabled = True
31-
Me.Grace_Timer.Start()
32-
Me.Offset_STimer = WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay")
28+
Grace_Timer.Enabled = True
29+
Grace_Timer.Start()
30+
Offset_STimer = Arr_Reg_Key.Item("ExtendedShutdownDelay")
3331
End Sub
3432

3533
Private Sub Shutdown_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load
36-
Me.Icon = WinNUT.Icon
37-
' Me.LogFile = WinNUT.LogFile
34+
Icon = WinNUT.Icon
3835
LogFile.LogTracing("Load ShutDown Gui", LogLvl.LOG_DEBUG, Me)
39-
Me.Grace_Timer.Enabled = False
40-
Me.Grace_Timer.Stop()
36+
Grace_Timer.Enabled = False
37+
Grace_Timer.Stop()
4138
'If ExtendedShutdownDelay = 0 (the default value), the next line fails and the whole shutdown sequence fails - Thus no shutdown
4239
'Moved next line lower down
4340
'Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
44-
Shutdown_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("DelayToShutdown") * 1000)
45-
Me.STimer = WinNUT_Params.Arr_Reg_Key.Item("DelayToShutdown")
46-
Me.Remained = Me.STimer
47-
If WinNUT_Params.Arr_Reg_Key.Item("AllowExtendedShutdownDelay") Then
41+
Shutdown_Timer.Interval = (Arr_Reg_Key.Item("DelayToShutdown") * 1000)
42+
STimer = Arr_Reg_Key.Item("DelayToShutdown")
43+
Remained = STimer
44+
If Arr_Reg_Key.Item("AllowExtendedShutdownDelay") Then
4845
Grace_Button.Enabled = True
4946
'Moved here so it is only used if grace period is allowed
5047
Try
51-
Me.Grace_Timer.Interval = (WinNUT_Params.Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
48+
Grace_Timer.Interval = (Arr_Reg_Key.Item("ExtendedShutdownDelay") * 1000)
5249
Catch ex As Exception
5350
'Disable Grace peroid option if Interval is set to 0
5451
Grace_Button.Enabled = False
@@ -76,38 +73,41 @@ Public Class Shutdown_Gui
7673
.Text = TimeToShow
7774
.Value = 0
7875
End With
79-
Me.Controls.Add(Shutdown_PBar)
76+
Controls.Add(Shutdown_PBar)
8077
AddHandler Grace_Timer.Tick, AddressOf Grace_Timer_Tick
8178
AddHandler Shutdown_Timer.Tick, AddressOf Shutdown_Timer_Tick
8279
End Sub
8380

8481
Private Sub Shutdown_Gui_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
85-
Me.Shutdown_Timer.Enabled = True
86-
Me.Shutdown_Timer.Start()
87-
lbl_UPSStatus.Text = String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
82+
Shutdown_Timer.Enabled = True
83+
Shutdown_Timer.Start()
84+
lbl_UPSStatus.Text = String.Format(StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
85+
LogFile.LogTracing("Shutdown GUI is shown and timer started for " & Shutdown_Timer.Interval / 1000 & " seconds.", LogLvl.LOG_NOTICE, Me)
8886
End Sub
8987

9088
Private Sub Grace_Timer_Tick(sender As Object, e As EventArgs)
91-
Me.Shutdown_Timer.Interval = Me.Remained * 1000
92-
Me.Shutdown_Timer.Enabled = True
93-
Me.Shutdown_Timer.Start()
89+
Shutdown_Timer.Interval = Remained * 1000
90+
Shutdown_Timer.Enabled = True
91+
Shutdown_Timer.Start()
9492
End Sub
9593

9694
Private Sub ShutDown_Btn_Click(sender As Object, e As EventArgs) Handles ShutDown_Btn.Click
9795
WinNUT.Shutdown_Action()
9896
End Sub
9997

10098
Private Sub Shutdown_Timer_Tick(sender As Object, e As EventArgs)
99+
LogFile.LogTracing("Shutdown timer tick.", LogLvl.LOG_NOTICE, Me)
101100
Shutdown_PBar.Value = 100
102-
System.Threading.Thread.Sleep(1000)
103-
WinNUT.Shutdown_Action()
101+
Threading.Thread.Sleep(1000)
104102
Run_Timer.Enabled = False
105-
Me.Shutdown_Timer.Stop()
106-
Me.Shutdown_Timer.Enabled = False
107-
Me.Grace_Timer.Stop()
108-
Me.Grace_Timer.Enabled = False
109-
Me.Hide()
110-
Me.Close()
103+
Shutdown_Timer.Stop()
104+
Shutdown_Timer.Enabled = False
105+
Grace_Timer.Stop()
106+
Grace_Timer.Enabled = False
107+
Hide()
108+
WinNUT.Shutdown_Action()
109+
110+
Close()
111111
End Sub
112112

113113
Private Sub Run_Timer_Tick(sender As Object, e As EventArgs) Handles Run_Timer.Tick
@@ -118,18 +118,18 @@ Public Class Shutdown_Gui
118118
lbl_UPSStatus.ForeColor = Color.Black
119119
RedText = True
120120
End If
121-
If Me.Shutdown_Timer.Enabled = True And Me.Remained > 0 Then
122-
Me.Remained = Int(STimer + Offset_STimer - Now.Subtract(Start_Shutdown).TotalSeconds)
121+
If Shutdown_Timer.Enabled = True And Remained > 0 Then
122+
Remained = Int(STimer + Offset_STimer - Now.Subtract(Start_Shutdown).TotalSeconds)
123123
Dim NewValue As Integer = 100
124-
If Me.Remained > 0 Then
125-
NewValue -= (100 * (Me.Remained / Me.STimer))
124+
If Remained > 0 Then
125+
NewValue -= (100 * (Remained / STimer))
126126
If NewValue > 100 Then
127127
NewValue = 100
128128
End If
129129
End If
130130
Dim TimeToShow As String
131-
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(Me.Remained)
132-
If Me.Shutdown_Timer.Interval = (3600 * 1000) Then
131+
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(Remained)
132+
If Shutdown_Timer.Interval = (3600 * 1000) Then
133133
TimeToShow = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" &
134134
iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" &
135135
iSpan.Seconds.ToString.PadLeft(2, "0"c)
@@ -139,12 +139,12 @@ Public Class Shutdown_Gui
139139
End If
140140
Shutdown_PBar.Text = TimeToShow
141141
Shutdown_PBar.Value = NewValue
142-
lbl_UPSStatus.Text = String.Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
142+
lbl_UPSStatus.Text = String.Format(StrLog.Item(AppResxStr.STR_SHUT_STAT), WinNUT.UPS_BattCh.ToString(), WinNUT.Lbl_VRTime.Text)
143143
End If
144144
End Sub
145145

146146
Private Sub Shutdown_Gui_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
147-
If Me.Visible Then
147+
If Visible Then
148148
e.Cancel = True
149149
End If
150150
End Sub

0 commit comments

Comments
 (0)