Skip to content

Commit 8c5c8c0

Browse files
authored
Merge pull request #163 from nutdotnet/suspend-handling
Resuming from Sleep and other connection fixes
2 parents 3345381 + 4d58c43 commit 8c5c8c0

File tree

8 files changed

+166
-248
lines changed

8 files changed

+166
-248
lines changed

WinNUT_V2/WinNUT-Client/About_Gui.zh-CN.resx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,4 @@
1212
<resheader name="writer">
1313
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
1414
</resheader>
15-
<data name="Label_License.Text" xml:space="preserve">
16-
<value>This program is free software: you can redistribute it and/or modify
17-
it under the terms of the GNU General Public License as published
18-
by the Free Software Foundation, either version 3 of the License, or
19-
any later version.
20-
21-
This program is distributed in the hope that it will be useful, but
22-
WITHOUT ANY WARRANTY; without even the implied warranty
23-
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24-
See the GNU General Public License for more details.
25-
26-
You should have received a copy of the GNU General Public License
27-
along with this program. If not, see https://www.gnu.org/licenses/.</value>
28-
</data>
2915
</root>

WinNUT_V2/WinNUT-Client/My Project/Resources.zh-CN.resx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,53 +121,63 @@ Ini 文件重命名为 {0}.old</value>
121121
<data name="XP_Information" xml:space="preserve" type="System.Resources.ResXFileRef, System.Windows.Forms">
122122
<value>..\Resources\XP_Information.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
123123
</data>
124-
<data name="regedit_exe_14_100_0" xml:space="preserve" type="System.Resources.ResXFileRef, System.Windows.Forms">
125-
<value>..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126-
</data>
127-
<data name="GitHub_URL" xml:space="preserve">
128-
<value>https://github.com/nutdotnet/WinNUT-Client</value>
129-
</data>
130124
<data name="DetectedPreviousPrefsData" xml:space="preserve">
131125
<value>在注册表中检测到以前的设置数据。</value>
126+
<comment>Notify the user that preferences data from the old system was detected in the Registry hive.</comment>
132127
</data>
133128
<data name="UpgradePrefsDialog_ImportProcedureCompleted" xml:space="preserve">
134129
<value>旧设置已经被导入。</value>
130+
<comment>Notify the user that the import procedure has completed.</comment>
135131
</data>
136132
<data name="UpgradePrefsDialog_UnmatchedPairs" xml:space="preserve">
137133
<value>有 {0} 个未知的设置。请查看日志获取更多详细信息。</value>
134+
<comment>Alert the user to how many unmatched preferences there were {0}.</comment>
138135
</data>
139136
<data name="UpgradePrefsDialog_DeleteProcedureComplete" xml:space="preserve">
140137
<value>旧设置已经从您的注册表中删除。</value>
138+
<comment>Notify the user that the old preferences have been removed from their Registry.</comment>
141139
</data>
142140
<data name="UpgradePrefsDialog_Cancelled" xml:space="preserve">
143141
<value>升级过程已取消:使用默认设置。</value>
142+
<comment>Notify the user that the upgrade dialog was cancelled, and that default settings will be used instead.</comment>
144143
</data>
145144
<data name="UpgradePrefsDialog_BackupLocationTitle" xml:space="preserve">
146145
<value>保存 WinNUT 注册表</value>
146+
<comment>Title of the SaveFileDialog that prompts the user to select the file and location they would like to save their WinNUT Registry preferences to.</comment>
147147
</data>
148148
<data name="UpgradePrefsDialog_BackupProcedureCompleted" xml:space="preserve">
149149
<value>旧设置已备份到 {0}</value>
150+
<comment>Notify the user that the old preferences have been exported to a file, and give the full path with {0}.</comment>
150151
</data>
151152
<data name="UpgradePrefsDialog_ErrorEncountered" xml:space="preserve">
152153
<value>升级过程中发生错误:
153154

154155
{0}
155156

156157
请修复错误,或取消升级对话框以继续使用默认设置。</value>
158+
<comment>Alert the user that an error occurred during the upgrade procedure, attempt to give a brief summary of the error, and prompt them to take the next step.</comment>
159+
</data>
160+
<data name="regedit_exe_14_100_0" xml:space="preserve" type="System.Resources.ResXFileRef, System.Windows.Forms">
161+
<value>..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
157162
</data>
158163
<data name="UpgradePrefsDialog_NoPrefsExistCaption" xml:space="preserve">
159164
<value>没有检测到设置</value>
165+
<comment>A brief caption for the error message.</comment>
160166
</data>
161167
<data name="UpgradePrefsDialog_NoPrefsExistError" xml:space="preserve">
162168
<value>您的系统中未检测到设置。无法继续操作。</value>
169+
<comment>Alert the user that the dialog is unable to continue, since no preferences are detected in the Registry.</comment>
163170
</data>
164171
<data name="ManageOldPrefsToolstripMenuItem_Disabled_TooltipText" xml:space="preserve">
165172
<value>您的系统中未检测到旧设置。</value>
173+
<comment>Similar to _Enabled tooltip, except that the preferences were not detected.</comment>
166174
</data>
167175
<data name="ManageOldPrefsToolstripMenuItem_Enabled_TooltipText" xml:space="preserve">
168176
<value>检测到旧设置。点击运行导入向导。</value>
177+
<comment>Tooltip of the "manage old prefs" menu item, explaining that the old preferences were detected and that clicking will open the wizard dialog.</comment>
169178
</data>
170179
<data name="VariableUnavailable" xml:space="preserve">
171180
<value>参数无效</value>
181+
<comment>Indicate that a variable is unavailable</comment>
172182
</data>
173183
</root>

WinNUT_V2/WinNUT-Client/Pref_Gui.zh-CN.resx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
<data name="Lbl_Login_Nut.Text" xml:space="preserve">
102102
<value>登录</value>
103103
</data>
104+
<data name="Tb_Delay_Com.ToolTip" xml:space="preserve">
105+
<value>从NUT服务器更新数据时间间隔(单位:毫秒)。
106+
最小值: 100, 最大值: 60 000。</value>
107+
</data>
104108
<data name="Tb_UPS_Name.ToolTip" xml:space="preserve">
105109
<value>监控的 UPS 名称。
106110
允许值:在 UPS 的 Nut 服务端所配置的名称。</value>
@@ -161,6 +165,9 @@
161165
<data name="CB_Use_Logfile.Text" xml:space="preserve">
162166
<value>创建日志文件</value>
163167
</data>
168+
<data name="CB_Use_Logfile.ToolTip" xml:space="preserve">
169+
<value>将日志事件写入文件。</value>
170+
</data>
164171
<data name="CB_Start_W_Win.Text" xml:space="preserve">
165172
<value>随 Windows 启动当前应用</value>
166173
</data>
@@ -316,17 +323,4 @@
316323
<data name="Lbl_LoadUPS.Font" xml:space="preserve" type="System.Drawing.Font, System.Drawing">
317324
<value>Microsoft Sans Serif, 8.25pt, style=Italic</value>
318325
</data>
319-
<data name="Cbx_Freq_Input.Items" xml:space="preserve">
320-
<value>50</value>
321-
</data>
322-
<data name="Cbx_Freq_Input.Items1" xml:space="preserve">
323-
<value>60</value>
324-
</data>
325-
<data name="Tb_Delay_Com.ToolTip" xml:space="preserve">
326-
<value>从NUT服务器更新数据时间间隔(单位:毫秒)。
327-
最小值: 100, 最大值: 60 000。</value>
328-
</data>
329-
<data name="CB_Use_Logfile.ToolTip" xml:space="preserve">
330-
<value>将日志事件写入文件。</value>
331-
</data>
332326
</root>

WinNUT_V2/WinNUT-Client/UpgradePrefsDialog.zh-CN.resx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<data name="IntroMessage.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
4343
<value>2</value>
4444
</data>
45+
<data name="IntroMessage.Text" xml:space="preserve">
46+
<value>WinNUT已经升级到一个新的设置和设置系统,并且必须继续使用它。在注册表中检测到了一些旧程序的设置。请从下面选择您希望对旧设置进行的操作。如果您不希望采取任何操作,请选择取消,将使用默认设置。只要新的程序数据保持完整,将不会再显示此消息。</value>
47+
</data>
4548
<data name="OK_Button.Anchor" xml:space="preserve" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
4649
<value>Right</value>
4750
</data>
@@ -57,6 +60,9 @@
5760
<data name="OK_Button.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
5861
<value>0</value>
5962
</data>
63+
<data name="OK_Button.Text" xml:space="preserve">
64+
<value>确认</value>
65+
</data>
6066
<data name="Cancel_Button.Anchor" xml:space="preserve" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
6167
<value>Right</value>
6268
</data>
@@ -72,6 +78,9 @@
7278
<data name="Cancel_Button.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
7379
<value>1</value>
7480
</data>
81+
<data name="Cancel_Button.Text" xml:space="preserve">
82+
<value>取消</value>
83+
</data>
7584
<data name="ImportSettingsCheckBox.AutoSize" xml:space="preserve" type="System.Boolean, mscorlib">
7685
<value>True</value>
7786
</data>
@@ -87,6 +96,12 @@
8796
<data name="ImportSettingsCheckBox.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
8897
<value>5</value>
8998
</data>
99+
<data name="ImportSettingsCheckBox.Text" xml:space="preserve">
100+
<value>导入</value>
101+
</data>
102+
<data name="ImportSettingsCheckBox.ToolTip" xml:space="preserve">
103+
<value>旧设置将从注册表导入到新的设置系统中。</value>
104+
</data>
90105
<data name="DeleteSettingsCheckBox.AutoSize" xml:space="preserve" type="System.Boolean, mscorlib">
91106
<value>True</value>
92107
</data>
@@ -102,6 +117,12 @@
102117
<data name="DeleteSettingsCheckBox.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
103118
<value>6</value>
104119
</data>
120+
<data name="DeleteSettingsCheckBox.Text" xml:space="preserve">
121+
<value>删除</value>
122+
</data>
123+
<data name="DeleteSettingsCheckBox.ToolTip" xml:space="preserve">
124+
<value>在注册表中检测到旧设置数据。</value>
125+
</data>
105126
<data name="PrevSettngsGroupBox.Anchor" xml:space="preserve" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
106127
<value>Top, Left, Right</value>
107128
</data>
@@ -120,6 +141,12 @@
120141
<data name="BackupSettingsCheckbox.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
121142
<value>7</value>
122143
</data>
144+
<data name="BackupSettingsCheckbox.Text" xml:space="preserve">
145+
<value>备份</value>
146+
</data>
147+
<data name="BackupSettingsCheckbox.ToolTip" xml:space="preserve">
148+
<value>旧设置将被导出到文件中。</value>
149+
</data>
123150
<data name="PrevSettngsGroupBox.Location" xml:space="preserve" type="System.Drawing.Point, System.Drawing">
124151
<value>6, 122</value>
125152
</data>
@@ -132,6 +159,9 @@
132159
<data name="PrevSettngsGroupBox.TabIndex" xml:space="preserve" type="System.Int32, mscorlib">
133160
<value>7</value>
134161
</data>
162+
<data name="PrevSettngsGroupBox.Text" xml:space="preserve">
163+
<value>以前的设置</value>
164+
</data>
135165
<data name="buttonPanel.Dock" xml:space="preserve" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
136166
<value>Bottom</value>
137167
</data>
@@ -180,6 +210,9 @@
180210
<data name="$this.StartPosition" xml:space="preserve" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
181211
<value>CenterParent</value>
182212
</data>
213+
<data name="$this.Text" xml:space="preserve">
214+
<value>迁移到新设置格式</value>
215+
</data>
183216
<metadata name="UpgradePrefsDialogModelBindingSource.TrayLocation" xml:space="preserve" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
184217
<value>488, 17</value>
185218
</metadata>
@@ -195,39 +228,4 @@
195228
<metadata name="$this.TrayHeight" xml:space="preserve" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
196229
<value>44</value>
197230
</metadata>
198-
<data name="IntroMessage.Text" xml:space="preserve">
199-
<value>WinNUT已经升级到一个新的设置和设置系统,并且必须继续使用它。在注册表中检测到了一些旧程序的设置。请从下面选择您希望对旧设置进行的操作。如果您不希望采取任何操作,请选择取消,将使用默认设置。只要新的程序数据保持完整,将不会再显示此消息。
200-
201-
</value>
202-
</data>
203-
<data name="OK_Button.Text" xml:space="preserve">
204-
<value>确认</value>
205-
</data>
206-
<data name="Cancel_Button.Text" xml:space="preserve">
207-
<value>取消</value>
208-
</data>
209-
<data name="ImportSettingsCheckBox.Text" xml:space="preserve">
210-
<value>导入</value>
211-
</data>
212-
<data name="ImportSettingsCheckBox.ToolTip" xml:space="preserve">
213-
<value>旧设置将从注册表导入到新的设置系统中。</value>
214-
</data>
215-
<data name="DeleteSettingsCheckBox.Text" xml:space="preserve">
216-
<value>删除</value>
217-
</data>
218-
<data name="DeleteSettingsCheckBox.ToolTip" xml:space="preserve">
219-
<value>在注册表中检测到旧设置数据。</value>
220-
</data>
221-
<data name="BackupSettingsCheckbox.Text" xml:space="preserve">
222-
<value>备份</value>
223-
</data>
224-
<data name="BackupSettingsCheckbox.ToolTip" xml:space="preserve">
225-
<value>旧设置将被导出到文件中。</value>
226-
</data>
227-
<data name="PrevSettngsGroupBox.Text" xml:space="preserve">
228-
<value>以前的设置</value>
229-
</data>
230-
<data name="$this.Text" xml:space="preserve">
231-
<value>迁移到新设置格式</value>
232-
</data>
233231
</root>

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ Imports WinNUT_Client_Common
1212
Public Class WinNUT
1313
#Region "Properties"
1414

15-
Public Property UpdateMethod() As String
16-
Get
17-
If mUpdate Then
18-
mUpdate = False
19-
Return True
20-
Else
21-
Return False
22-
End If
23-
End Get
24-
Set(Value As String)
25-
mUpdate = Value
26-
End Set
27-
End Property
28-
2915
Public WriteOnly Property HasCrashed() As Boolean
3016
Set(Value As Boolean)
3117
WinNUT_Crashed = Value
@@ -78,7 +64,6 @@ Public Class WinNUT
7864
Public UPS_InputA As Double
7965

8066
Private HasFocus As Boolean = True
81-
Private mUpdate As Boolean = False
8267
Private FormText As String
8368
Private WinNUT_Crashed As Boolean = False
8469

@@ -345,9 +330,17 @@ Public Class WinNUT
345330
Private Sub SystemEvents_PowerModeChanged(sender As Object, e As Microsoft.Win32.PowerModeChangedEventArgs)
346331
LogFile.LogTracing("PowerModeChangedEvent: " & [Enum].GetName(GetType(Microsoft.Win32.PowerModes), e.Mode), LogLvl.LOG_NOTICE, Me)
347332
Select Case e.Mode
333+
' Note: Windows does not wait for applications to handle a Suspend event.
334+
Case Microsoft.Win32.PowerModes.Suspend
335+
LogFile.LogTracing("Suspending WinNUT operations...", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_GOTOSLEEP))
336+
UPSDisconnect()
348337
Case Microsoft.Win32.PowerModes.Resume
349-
LogFile.LogTracing("Restarting WinNUT after waking up from Windows", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
338+
If UPS_Device IsNot Nothing AndAlso UPS_Device.IsConnected Then
339+
LogFile.LogTracing("Trying to disconnect connected UPS after system resume...", LogLvl.LOG_NOTICE, Me)
340+
UPSDisconnect()
341+
End If
350342
If My.Settings.NUT_AutoReconnect Then
343+
LogFile.LogTracing("Reconnecting after system resume.", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
351344
UPS_Connect(True)
352345
End If
353346
End Select
@@ -395,7 +388,7 @@ Public Class WinNUT
395388
''' <summary>
396389
''' Prepare the form to begin receiving data from a connected UPS.
397390
''' </summary>
398-
Private Sub UPSReady(nutUps As UPS_Device) Handles UPS_Device.Connected, UPS_Device.ReConnected
391+
Private Sub UPSReady(nutUps As UPS_Device) Handles UPS_Device.Connected
399392
Dim upsConf = nutUps.Nut_Config
400393
LogFile.LogTracing(upsConf.UPSName & " has indicated it's ready to start sending data.", LogLvl.LOG_DEBUG, Me)
401394

@@ -413,11 +406,15 @@ Public Class WinNUT
413406
LogFile.LogTracing("Connection to Nut Host Established", LogLvl.LOG_NOTICE, Me,
414407
String.Format(StrLog.Item(AppResxStr.STR_LOG_CONNECTED),
415408
upsConf.Host, upsConf.Port))
409+
410+
If Not String.IsNullOrEmpty(upsConf.Login) Then
411+
UPS_Device.Login()
412+
End If
416413
End Sub
417414

418415
Private Sub ConnectionError(sender As UPS_Device, ex As Exception) Handles UPS_Device.ConnectionError
419-
LogFile.LogTracing(String.Format("Something went wrong connecting to UPS {0}. IsConnected: {1}, IsAuthenticated: {2}",
420-
sender.Name, sender.IsConnected, sender.IsAuthenticated), LogLvl.LOG_ERROR, Me,
416+
LogFile.LogTracing(String.Format("Something went wrong connecting to UPS {0}. IsConnected: {1}, IsLoggedIn: {2}",
417+
sender.Name, sender.IsConnected, sender.IsLoggedIn), LogLvl.LOG_ERROR, Me,
421418
String.Format(StrLog.Item(AppResxStr.STR_LOG_CON_FAILED), sender.Nut_Config.Host, sender.Nut_Config.Port,
422419
ex.Message))
423420
End Sub
@@ -599,7 +596,8 @@ Public Class WinNUT
599596
Event_Unknown_UPS()
600597
End If
601598

602-
LogFile.LogTracing("NUT protocol error encoutnered:" + vbNewLine + ex.ToString(), LogLvl.LOG_NOTICE, sender)
599+
LogFile.LogTracing("NUT protocol error encoutnered:", LogLvl.LOG_NOTICE, sender)
600+
LogFile.LogException(ex, Me)
603601
End Sub
604602

605603
Public Sub Event_Unknown_UPS() ' Handles UPS_Device.Unknown_UPS
@@ -626,7 +624,7 @@ Public Class WinNUT
626624
End Sub
627625

628626
Public Shared Sub Event_ChangeStatus() Handles Me.On_Battery, Me.On_Line,
629-
UPS_Device.Lost_Connect, UPS_Device.Connected, UPS_Device.Disconnected, UPS_Device.New_Retry, UPS_Device.ReConnected
627+
UPS_Device.Lost_Connect, UPS_Device.Connected, UPS_Device.Disconnected, UPS_Device.New_Retry
630628
', UPS_Device.Unknown_UPS
631629
', UPS_Device.InvalidLogin
632630

@@ -1045,12 +1043,11 @@ Public Class WinNUT
10451043
End Sub
10461044

10471045
Private Sub Menu_Update_Click(sender As Object, e As EventArgs) Handles Menu_Update.Click
1048-
mUpdate = True
10491046
'Dim th As System.Threading.Thread = New Threading.Thread(New System.Threading.ParameterizedThreadStart(AddressOf Run_Update))
10501047
'th.SetApartmentState(System.Threading.ApartmentState.STA)
10511048
'th.Start(Me.UpdateMethod)
10521049
LogFile.LogTracing("Open About Gui From Menu", LogLvl.LOG_DEBUG, Me)
1053-
Dim Update_Frm = New Update_Gui(mUpdate)
1050+
Dim Update_Frm = New Update_Gui(True)
10541051
Update_Frm.Activate()
10551052
Update_Frm.Visible = True
10561053
HasFocus = False

WinNUT_V2/WinNUT-Client/WinNUT.zh-CN.resx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@
102102
<data name="ManageOldPrefsToolStripMenuItem.Enabled" xml:space="preserve" type="System.Boolean, mscorlib">
103103
<value>False</value>
104104
</data>
105-
<data name="NotifyIcon.Text" xml:space="preserve">
106-
<value>NotifyIcon1</value>
107-
</data>
108-
<data name="Main_Menu.Text" xml:space="preserve">
109-
<value>MenuStrip1</value>
110-
</data>
111-
<data name="$this.Text" xml:space="preserve">
112-
<value>WinNUT Client</value>
113-
</data>
114105
<data name="ManageOldPrefsToolStripMenuItem.Text" xml:space="preserve">
115106
<value>管理旧设置...</value>
116107
</data>

0 commit comments

Comments
 (0)