@@ -62,11 +62,11 @@ Public Class WinNUT
6262 Private Event On_Battery()
6363 Private Event On_Line()
6464 Private Event Data_Updated()
65- Private Shared Event UpdateNotifyIconStr( ByVal Reason As String , ByVal Message As String )
66- Private Shared Event UpdateBatteryState( ByVal Reason As String )
65+ Private Event UpdateNotifyIconStr( ByVal Reason As String , ByVal Message As String )
66+ Private Event UpdateBatteryState( ByVal Reason As String )
6767
6868 'Handle sleep/hibernate mode from windows API
69- Declare Function SetSystemPowerState Lib "kernel32 " ( ByVal fSuspend As Integer , ByVal fForce As Integer ) As Integer
69+ Declare Function SetSuspendState Lib "PowrProf " ( ByVal Hibernate As Integer , ByVal ForceCritical As Integer , ByVal DisableWakeEvent As Integer ) As Integer
7070
7171 Public Property UpdateMethod() As String
7272 Get
@@ -428,27 +428,27 @@ Public Class WinNUT
428428 End If
429429 End Sub
430430
431- Private Shared Sub NewRetry_NotifyIcon() Handles UPS_Device.New_Retry
432- Dim Message As String = String .Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RETRY), WinNUT. UPS_Device.Retry, WinNUT. UPS_Device.MaxRetry)
431+ Private Sub NewRetry_NotifyIcon() Handles UPS_Device.New_Retry
432+ Dim Message As String = String .Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_RETRY), UPS_Device.Retry, UPS_Device.MaxRetry)
433433 RaiseEvent UpdateNotifyIconStr( "Retry" , Message)
434- WinNUT. UpdateIcon_NotifyIcon()
435- LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, WinNUT )
434+ UpdateIcon_NotifyIcon()
435+ LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
436436 End Sub
437437
438- Private Shared Sub Reconnect_NotifyIcon() Handles UPS_Device.Connected
439- WinNUT. Menu_UPS_Var.Enabled = True
440- WinNUT. UpdateIcon_NotifyIcon()
441- LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, WinNUT )
438+ Private Sub Reconnect_NotifyIcon() Handles UPS_Device.Connected
439+ Menu_UPS_Var.Enabled = True
440+ UpdateIcon_NotifyIcon()
441+ LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
442442 RaiseEvent UpdateNotifyIconStr( "Connected" , Nothing )
443443 End Sub
444444
445- Private Shared Sub Deconnected_NotifyIcon() Handles UPS_Device.Deconnected
446- WinNUT. ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
447- LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, WinNUT )
448- WinNUT. UpdateIcon_NotifyIcon()
445+ Private Sub Deconnected_NotifyIcon() Handles UPS_Device.Deconnected
446+ ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
447+ LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
448+ UpdateIcon_NotifyIcon()
449449 RaiseEvent UpdateNotifyIconStr( "Deconnected" , Nothing )
450450 RaiseEvent UpdateBatteryState( "Deconnected" )
451- WinNUT. Update_Data.Stop()
451+ Update_Data.Stop()
452452 End Sub
453453
454454 Private Sub Event_UpdateNotifyIconStr( ByVal Optional Reason As String = Nothing , ByVal Optional Message As String = Nothing ) Handles Me .UpdateNotifyIconStr
@@ -537,13 +537,13 @@ Public Class WinNUT
537537 LogFile.LogTracing( "Battery Status => " & Status, LogLvl.LOG_DEBUG, WinNUT)
538538 End Sub
539539
540- Public Shared Sub Event_Unknown_UPS() Handles UPS_Device.Unknown_UPS, UPS_Device.Unknown_UPS
541- WinNUT. ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
542- LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, WinNUT )
543- WinNUT. UpdateIcon_NotifyIcon()
540+ Public Sub Event_Unknown_UPS() Handles UPS_Device.Unknown_UPS, UPS_Device.Unknown_UPS
541+ ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
542+ LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
543+ UpdateIcon_NotifyIcon()
544544 RaiseEvent UpdateNotifyIconStr( "Unknown UPS" , Nothing )
545- LogFile.LogTracing( "Cannot Connect : Unknow UPS Name" , LogLvl.LOG_DEBUG, WinNUT , WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_UNKNOWN_UPS))
546- WinNUT. Menu_UPS_Var.Enabled = False
545+ LogFile.LogTracing( "Cannot Connect : Unknow UPS Name" , LogLvl.LOG_DEBUG, Me , WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_UNKNOWN_UPS))
546+ Menu_UPS_Var.Enabled = False
547547 End Sub
548548
549549 Private Sub Menu_About_Click(sender As Object , e As EventArgs) Handles Menu_About.Click
@@ -560,27 +560,25 @@ Public Class WinNUT
560560 HasFocus = False
561561 End Sub
562562
563- Private Shared Sub UPS_Lostconnect() Handles UPS_Device.Lost_Connect
564- With WinNUT
565- Dim Host = .Nut_Config.Host
566- Dim Port = .Nut_Config.Port
567- .Update_Data.Stop()
568- LogFile.LogTracing( "Nut Server Lost Connection" , LogLvl.LOG_ERROR, WinNUT, String .Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Host, Port))
569- LogFile.LogTracing( "Fix All data to null/empty String" , LogLvl.LOG_DEBUG, WinNUT)
570- LogFile.LogTracing( "Fix All Dial Data to Min Value/0" , LogLvl.LOG_DEBUG, WinNUT)
571-
572- .ReInitDisplayValues()
573- If .AutoReconnect And .UPS_Retry <= .UPS_MaxRetry Then
574- .ActualAppIconIdx = AppIconIdx.IDX_ICO_RETRY
575- Else
576- .ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
577- End If
563+ Private Sub UPS_Lostconnect() Handles UPS_Device.Lost_Connect
564+ Dim Host = Nut_Config.Host
565+ Dim Port = Nut_Config.Port
566+ Update_Data.Stop()
567+ LogFile.LogTracing( "Nut Server Lost Connection" , LogLvl.LOG_ERROR, Me , String .Format(WinNUT_Globals.StrLog.Item(AppResxStr.STR_MAIN_LOSTCONNECT), Host, Port))
568+ LogFile.LogTracing( "Fix All data to null/empty String" , LogLvl.LOG_DEBUG, Me )
569+ LogFile.LogTracing( "Fix All Dial Data to Min Value/0" , LogLvl.LOG_DEBUG, Me )
578570
579- .UpdateIcon_NotifyIcon()
580- RaiseEvent UpdateNotifyIconStr( "Lost Connect" , Nothing )
581- RaiseEvent UpdateBatteryState( "Lost Connect" )
582- LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, WinNUT)
583- End With
571+ ReInitDisplayValues()
572+ If AutoReconnect And UPS_Retry <= UPS_MaxRetry Then
573+ ActualAppIconIdx = AppIconIdx.IDX_ICO_RETRY
574+ Else
575+ ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE
576+ End If
577+
578+ UpdateIcon_NotifyIcon()
579+ RaiseEvent UpdateNotifyIconStr( "Lost Connect" , Nothing )
580+ RaiseEvent UpdateBatteryState( "Lost Connect" )
581+ LogFile.LogTracing( "Update Icon" , LogLvl.LOG_DEBUG, Me )
584582 End Sub
585583
586584 Public Shared Sub Event_ChangeStatus() Handles Me .On_Battery, Me .On_Line,
@@ -1039,9 +1037,9 @@ Public Class WinNUT
10391037 Case 0
10401038 Process.Start( "C:\WINDOWS\system32\Shutdown.exe" , "-f -s -t 0" )
10411039 Case 1
1042- SetSystemPowerState( True , 0 )
1040+ SetSuspendState( False , False , True ) 'Suspend
10431041 Case 2
1044- SetSystemPowerState( False , 0 )
1042+ SetSuspendState( True , False , True ) 'Hibernate
10451043 End Select
10461044 End Sub
10471045
0 commit comments