From 11e2f0380b8230ecb48c775fe1428b7510a5847f Mon Sep 17 00:00:00 2001 From: MaxMadcc <19978097+MaxMadcc@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:57:41 +0800 Subject: [PATCH 1/2] Fix LogFile controls are disabled when the Create LogFile option is on. Fix 'Create LogFile' option is on, but the option is not working when program is running. --- WinNUT_V2/WinNUT-Client/Pref_Gui.vb | 1 + WinNUT_V2/WinNUT-Client/WinNUT.vb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.vb b/WinNUT_V2/WinNUT-Client/Pref_Gui.vb index 6075603..be6ce79 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.vb +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.vb @@ -183,6 +183,7 @@ Public Class Pref_Gui Next Next Btn_Apply.Enabled = False + SetLogControlsStatus() IsShowed = True LogFile.LogTracing("Pref Gui Opened.", LogLvl.LOG_DEBUG, Me) Catch Except As Exception diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.vb b/WinNUT_V2/WinNUT-Client/WinNUT.vb index 9a42c49..dd6bf63 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.vb +++ b/WinNUT_V2/WinNUT-Client/WinNUT.vb @@ -138,6 +138,14 @@ Public Class WinNUT StrLog.Insert(AppResxStr.STR_LOG_UPDATE, My.Resources.Log_Str_11) StrLog.Insert(AppResxStr.STR_LOG_NUT_FSD, My.Resources.Log_Str_12) + 'Init Logger + If My.Settings.LG_LogToFile Then + LogFile.LogLevelValue = My.Settings.LG_LogLevel + LogFile.InitializeLogFile() + ElseIf LogFile.IsWritingToFile Then + LogFile.DeleteLogFile() + End If + 'Init Systray NotifyIcon.Text = ProgramName & " - " & ShortProgramVersion NotifyIcon.Visible = False From cc69fc90a0e7a38e68c35a2fbd300d5969f8d9f9 Mon Sep 17 00:00:00 2001 From: gbakeman Date: Wed, 24 Apr 2024 17:14:23 -0400 Subject: [PATCH 2/2] Tweaks to log file handling and prefs menu. Logger.vb: - Log file writing can be enabled or disabled by changing the `IsWritingToFile` property, or by calling the `Initialize`, `Delete` or `Terminate` subroutines. - Introduced new `TerminateLogFile` subroutine that gracefully closes a log file with a terminating line, without deleting the whole file. `DeleteLogFile` will terminate and delete the file. - Removed `TEST_RELEASE_DIRS` compiler directive so debug builds send log files to the executable. WinNUT.vb: - Renamed `WinNUT_PrefsChanged` subroutine to ApplyApplicationPreferences - Logger object configuration is now updated in that subroutine - logging configuration does not need to be modified from anywhere else in the code. - Centralized gauge initialization code into one place, removed from form load code. - Additional Pref Gui tweaks to how logging controls are handled, for better consistency. - Modified tooltip to be more concise. - Updated project-wide translations to match entries that need translating. --- .../WinNUT-Client.zh-TW.xlf | 47 +++--- .../WinNUT-client.de-DE.xlf | 54 +++--- .../WinNUT-client.fr-FR.xlf | 53 +++--- .../WinNUT-client.ru-RU.xlf | 53 +++--- .../WinNUT-client.zh-CN.xlf | 53 +++--- WinNUT_V2/WinNUT-Client/Pref_Gui.de-DE.resx | 8 +- WinNUT_V2/WinNUT-Client/Pref_Gui.fr-FR.resx | 7 - WinNUT_V2/WinNUT-Client/Pref_Gui.resx | 2 +- WinNUT_V2/WinNUT-Client/Pref_Gui.ru-RU.resx | 7 - WinNUT_V2/WinNUT-Client/Pref_Gui.vb | 62 ++++--- WinNUT_V2/WinNUT-Client/Pref_Gui.zh-CN.resx | 7 - WinNUT_V2/WinNUT-Client/Pref_Gui.zh-TW.resx | 6 - WinNUT_V2/WinNUT-Client/WinNUT.de-DE.resx | 6 - WinNUT_V2/WinNUT-Client/WinNUT.fr-FR.resx | 6 - WinNUT_V2/WinNUT-Client/WinNUT.ru-RU.resx | 6 - WinNUT_V2/WinNUT-Client/WinNUT.vb | 157 +++++++----------- WinNUT_V2/WinNUT-Client/WinNUT.zh-CN.resx | 6 - WinNUT_V2/WinNUT-Client/WinNUT.zh-TW.resx | 3 - WinNUT_V2/WinNUT-Client_Common/Logger.vb | 71 +++++--- .../WinNUT-Client_Common.vbproj | 3 +- 20 files changed, 265 insertions(+), 352 deletions(-) diff --git a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-Client.zh-TW.xlf b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-Client.zh-TW.xlf index 3d99019..9d5421a 100644 --- a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-Client.zh-TW.xlf +++ b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-Client.zh-TW.xlf @@ -830,7 +830,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa Please correct the error, or cancel the upgrade dialog to continue with the default settings. 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. - + ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -1759,8 +1759,8 @@ Accepted value: Numeric value from 0 to 100. Milliseconds between data updates from NUT server. Min: 100, Max: 60 000. - UPS 資料更新頻率 (預設值 5 秒)。範圍:1-60 秒。 - Please verify the translation’s accuracy as the source string was updated after it was translated. + Milliseconds between data updates from NUT server. +Min: 100, Max: 60 000. NoControl @@ -2358,8 +2358,8 @@ Accepted value: Numeric value from 0 to 999. 檢查應用程式更新。 - Create a log file ("WinNUT-client.log" file in the WinNUT installation directory). - 建立日誌檔案 (WinNUT-client.log 檔案位於 WinNUT 的安裝目錄)。 + Write logging events to a file. + Write logging events to a file. 51, 20 @@ -3667,74 +3667,73 @@ Accepted value: Numeric value from 0 to 100. WinNUT Client WinNUT Client - + 133, 17 133, 17 - + 364, 17 364, 17 - + 248, 17 248, 17 - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + 58 58 - + False False - + 180, 22 - 180, 22 - Please verify the translation’s accuracy as the source string was updated after it was translated. + 180, 22 Manage Old Prefs... diff --git a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.de-DE.xlf b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.de-DE.xlf index 511cce7..d3f43bc 100644 --- a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.de-DE.xlf +++ b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.de-DE.xlf @@ -1237,8 +1237,8 @@ Milliseconds between data updates from NUT server. Min: 100, Max: 60 000. - Zeit zwischen jeder Aktualisierung der USV-Daten (Standard = 5).Wertebereich: Numerischer Wert von 1 bis 60 Sekunden. - Please verify the translation’s accuracy as the source string was updated after it was translated. + Milliseconds between data updates from NUT server. +Min: 100, Max: 60 000. UPS name to monitor. @@ -1320,8 +1320,8 @@ Accepted value: Numeric value from 0 to 999. Detailstufe für die Logdatei - Create a log file ("WinNUT-client.log" file in the WinNUT installation directory). - Eine Logdatei (Datei WinNUT-client.log im WinNUT-Installationsverzeichnis) erstellen. + Write logging events to a file. + Write logging events to a file. Starts WinNUT when Windows starts. @@ -1348,7 +1348,7 @@ Accepted value: Numeric value from 0 to 3600. Allow additional time during the shutdown procedure. Note: This additional time could go beyond the UPS backup time - USE WITH CAUTION!!! - Zusätzliche Zeit zum Herunterfahrens erlauben. Hinweis: Diese zusätzliche Zeit kann über die Verfügbarkeit der USV hinausgehen - MIT VORSICHT VERWENDEN !!! + USV-Name Stop procedure delay if delayed. @@ -1898,7 +1898,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa Please correct the error, or cancel the upgrade dialog to continue with the default settings. 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. - + ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -1936,7 +1936,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa - + 248, 17 248, 17 @@ -2044,12 +2044,11 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa 704, 381 704, 381 - + WinNUT Client - Windows NUT Client - Please verify the translation’s accuracy as the source string was updated after it was translated. + WinNUT Client - + True True @@ -2109,11 +2108,11 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa True True - + 133, 17 133, 17 - + 364, 17 364, 17 @@ -2489,7 +2488,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa None None - + 58 58 @@ -3093,39 +3092,39 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa 0, 24 0, 24 - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True @@ -3149,7 +3148,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa 6 6 - + True True @@ -3201,14 +3200,13 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa NoControl NoControl - + False False - + 180, 22 - 180, 22 - Please verify the translation’s accuracy as the source string was updated after it was translated. + 180, 22 Manage Old Prefs... diff --git a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.fr-FR.xlf b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.fr-FR.xlf index d695b90..9b38c04 100644 --- a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.fr-FR.xlf +++ b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.fr-FR.xlf @@ -1240,9 +1240,8 @@ inférieur à Milliseconds between data updates from NUT server. Min: 100, Max: 60 000. - Temps entre chaque mise à jour des données UPS (par défaut = 5). -Valeur acceptée: valeur numérique de 1 à 60 secondes. - Please verify the translation’s accuracy as the source string was updated after it was translated. + Milliseconds between data updates from NUT server. +Min: 100, Max: 60 000. UPS name to monitor. @@ -1335,8 +1334,8 @@ Valeur acceptée: valeur numérique de 0 à 999. Niveau de journalisation du fichier journal - Create a log file ("WinNUT-client.log" file in the WinNUT installation directory). - Créez un fichier journal (fichier "WinNUT-client.log" dans le répertoire d'installation de WinNUT). + Write logging events to a file. + Write logging events to a file. Starts WinNUT when Windows starts. @@ -1923,7 +1922,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa Please correct the error, or cancel the upgrade dialog to continue with the default settings. 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. - + ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -1961,7 +1960,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa - + 248, 17 248, 17 @@ -2069,12 +2068,11 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa 704, 381 704, 381 - + WinNUT Client - Windows NUT Client - Please verify the translation’s accuracy as the source string was updated after it was translated. + WinNUT Client - + True True @@ -2134,11 +2132,11 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa True True - + 133, 17 133, 17 - + 364, 17 364, 17 @@ -2514,7 +2512,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa None None - + 58 58 @@ -3118,39 +3116,39 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa 0, 24 0, 24 - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True @@ -3174,7 +3172,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa 6 6 - + True True @@ -3226,14 +3224,13 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa NoControl NoControl - + False False - + 180, 22 - 180, 22 - Please verify the translation’s accuracy as the source string was updated after it was translated. + 180, 22 Manage Old Prefs... diff --git a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.ru-RU.xlf b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.ru-RU.xlf index 5d81b76..595f9e5 100644 --- a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.ru-RU.xlf +++ b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.ru-RU.xlf @@ -835,7 +835,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa Please correct the error, or cancel the upgrade dialog to continue with the default settings. 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. - + ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -1291,9 +1291,8 @@ along with this program. If not, see https://www.gnu.org/licenses/. Milliseconds between data updates from NUT server. Min: 100, Max: 60 000. - Время между обновлениями данных ИБП (по умолчанию = 5). -Число от 1 до 60 секунд. - Please verify the translation’s accuracy as the source string was updated after it was translated. + Milliseconds between data updates from NUT server. +Min: 100, Max: 60 000. 154, 71 @@ -1918,8 +1917,8 @@ Accepted value: Numeric value from 0 to 999. Создать файл лога - Create a log file ("WinNUT-client.log" file in the WinNUT installation directory). - Создать файл лога (файл WinNUT-client.log в папке установки WinNUT). + Write logging events to a file. + Write logging events to a file. True @@ -3682,68 +3681,67 @@ Accepted value: Numeric value from 0 to 100. 720, 420 720, 420 - + WinNUT Client - Windows NUT CLient - Please verify the translation’s accuracy as the source string was updated after it was translated. + WinNUT Client - + 133, 17 133, 17 - + 364, 17 364, 17 - + 248, 17 248, 17 - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + 58 58 @@ -3751,14 +3749,13 @@ Accepted value: Numeric value from 0 to 100. NoControl NoControl - + False False - + 180, 22 - 180, 22 - Please verify the translation’s accuracy as the source string was updated after it was translated. + 180, 22 Manage Old Prefs... diff --git a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.zh-CN.xlf b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.zh-CN.xlf index ad397e2..fc8e303 100644 --- a/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.zh-CN.xlf +++ b/WinNUT_V2/WinNUT-Client/MultilingualResources/WinNUT-client.zh-CN.xlf @@ -835,7 +835,7 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa Please correct the error, or cancel the upgrade dialog to continue with the default settings. 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. - + ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Resources\regedit.exe_14_100-0.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -1455,9 +1455,8 @@ Accepted value: Numeric value from 0 to 999. Milliseconds between data updates from NUT server. Min: 100, Max: 60 000. - 每次更新UPS数据之间的时间(默认= 5)。 -接受值:1到60秒之间的数值。 - Please verify the translation’s accuracy as the source string was updated after it was translated. + Milliseconds between data updates from NUT server. +Min: 100, Max: 60 000. 154, 71 @@ -1754,8 +1753,8 @@ Accepted value: IPV4 / IPV6 / FQDN address. 创建日志文件 - Create a log file ("WinNUT-client.log" file in the WinNUT installation directory). - 创建日志文件(""WinNUT-client.log"" 文件位于 WinNUT 的安装目录)。 + Write logging events to a file. + Write logging events to a file. True @@ -3669,68 +3668,67 @@ Accepted value: Numeric value from 0 to 100. 720, 420 720, 420 - + WinNUT Client - Windows NUT Client - Please verify the translation’s accuracy as the source string was updated after it was translated. + WinNUT Client - + 133, 17 133, 17 - + 364, 17 364, 17 - + 248, 17 248, 17 - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + True True - + 58 58 @@ -3750,14 +3748,13 @@ Accepted value: Numeric value from 0 to 100. NoControl NoControl - + False False - + 180, 22 - 180, 22 - Please verify the translation’s accuracy as the source string was updated after it was translated. + 180, 22 Manage Old Prefs... diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.de-DE.resx b/WinNUT_V2/WinNUT-Client/Pref_Gui.de-DE.resx index 82b67e9..81e0624 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.de-DE.resx +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.de-DE.resx @@ -165,9 +165,6 @@ Optionen - - Zeit zwischen jeder Aktualisierung der USV-Daten (Standard = 5).Wertebereich: Numerischer Wert von 1 bis 60 Sekunden. - Name der zu überwachenden USV. Wertebereich: Name der auf dem NUT-Server konfigurierten USV. @@ -219,9 +216,6 @@ Detailstufe für die Logdatei - - Eine Logdatei (Datei WinNUT-client.log im WinNUT-Installationsverzeichnis) erstellen. - Startet WinNUT beim Start von Windows. @@ -238,7 +232,7 @@ Limit für zusätzliche Verzögerung. Wertebereich: Numerischer Wert von 0 bis 3600. - Zusätzliche Zeit zum Herunterfahrens erlauben. Hinweis: Diese zusätzliche Zeit kann über die Verfügbarkeit der USV hinausgehen - MIT VORSICHT VERWENDEN !!! + USV-Name Prozedurverzögerung bei Verzögerung stoppen. Wertebereich: Numerischer Wert von 0 bis 3600. diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.fr-FR.resx b/WinNUT_V2/WinNUT-Client/Pref_Gui.fr-FR.resx index bbf25e3..d627b9b 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.fr-FR.resx +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.fr-FR.resx @@ -168,10 +168,6 @@ inférieur à Préférences - - Temps entre chaque mise à jour des données UPS (par défaut = 5). -Valeur acceptée: valeur numérique de 1 à 60 secondes. - Nom de l'onduleur à surveiller. Valeur acceptée: nom de l'onduleur configuré dans le serveur Nut. @@ -234,9 +230,6 @@ Valeur acceptée: valeur numérique de 0 à 999. Niveau de journalisation du fichier journal - - Créez un fichier journal (fichier "WinNUT-client.log" dans le répertoire d'installation de WinNUT). - Démarre WinNUT au démarrage de Windows. diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.resx b/WinNUT_V2/WinNUT-Client/Pref_Gui.resx index 791eb36..5f1c57b 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.resx +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.resx @@ -1168,7 +1168,7 @@ Accepted value: Numeric value from 0 to 999. Create LogFile - Create a log file ("WinNUT-client.log" file in the WinNUT installation directory). + Write logging events to a file. CB_Use_Logfile diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.ru-RU.resx b/WinNUT_V2/WinNUT-Client/Pref_Gui.ru-RU.resx index d5f49cb..663329c 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.ru-RU.resx +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.ru-RU.resx @@ -81,10 +81,6 @@ Логин - - Время между обновлениями данных ИБП (по умолчанию = 5). -Число от 1 до 60 секунд. - Имя ИБП для мониторинга. Допустимые значения: Имя ИБП из конфиграции сервера NUT @@ -204,9 +200,6 @@ IPV4 / IPV6 / доменное имя. Создать файл лога - - Создать файл лога (файл WinNUT-client.log в папке установки WinNUT). - Запускать с Windows diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.vb b/WinNUT_V2/WinNUT-Client/Pref_Gui.vb index be6ce79..71e33b1 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.vb +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.vb @@ -75,14 +75,10 @@ Public Class Pref_Gui End If End If - 'LogFile.LogLevel = Cbx_LogLevel.SelectedIndex - 'LogFile.IsWritingToFile = CB_Use_Logfile.Checked - - LogFile.LogTracing("Pref_Gui Params Saved", 1, Me) + RaiseEvent SavedPreferences(PrefsModified) SetLogControlsStatus() - ' WinNUT.WinNUT_PrefsChanged() - RaiseEvent SavedPreferences(PrefsModified) + LogFile.LogTracing("Preferences Saved", LogLvl.LOG_NOTICE, Me) ' PrefsModified = True Catch e As Exception @@ -324,30 +320,6 @@ Public Class Pref_Gui End If End Sub - Private Sub Btn_DeleteLog_Click(sender As Object, e As EventArgs) Handles Btn_DeleteLog.Click - LogFile.LogTracing("Delete LogFile", LogLvl.LOG_DEBUG, Me) - - If LogFile.DeleteLogFile() Then - LogFile.LogTracing("LogFile Deleted", LogLvl.LOG_DEBUG, Me) - Else - LogFile.LogTracing("Error deleting log file.", LogLvl.LOG_WARNING, Me) - End If - - ' LogFile.IsWritingToFile = Arr_Reg_Key.Item("UseLogFile") - SetLogControlsStatus() - End Sub - - Private Sub Btn_ViewLog_Click(sender As Object, e As EventArgs) Handles Btn_ViewLog.Click - LogFile.LogTracing("Show LogFile", LogLvl.LOG_DEBUG, Me) - If LogFile IsNot Nothing AndAlso File.Exists(LogFile.LogFilePath) Then - Process.Start(LogFile.LogFilePath) - Else - LogFile.LogTracing("LogFile does not exists", LogLvl.LOG_ERROR, Me) - Btn_ViewLog.Enabled = False - Btn_DeleteLog.Enabled = False - End If - End Sub - Private Sub Pref_Gui_Load(sender As Object, e As EventArgs) Handles MyBase.Load Icon = WinNUT.Icon LogFile.LogTracing("Load Pref Gui", LogLvl.LOG_DEBUG, Me) @@ -365,12 +337,36 @@ Public Class Pref_Gui End If End Sub +#Region "Logging controls" + + Private Sub Btn_ViewLog_Click(sender As Object, e As EventArgs) Handles Btn_ViewLog.Click + LogFile.LogTracing("User clicked ViewLog button.", LogLvl.LOG_DEBUG, Me) + Try + Process.Start(LogFile.LogFilePath) + LogFile.LogTracing("Opened UI window to log location.", LogLvl.LOG_NOTICE, Me) + Catch ex As Exception + LogFile.LogException(ex, Me) + SetLogControlsStatus() + End Try + End Sub + + Private Sub Btn_DeleteLog_Click(sender As Object, e As EventArgs) Handles Btn_DeleteLog.Click + LogFile.LogTracing("User clicked DeleteLog button.", LogLvl.LOG_DEBUG, Me) + + Try + LogFile.DeleteLogFile() + PrefsModified = True ' Will help reinitialize log file later is user still wants it. + Catch ex As Exception + LogFile.LogException(ex, Me) + End Try + + SetLogControlsStatus() + End Sub + ''' ''' Enable or disable controls to view and delete log data if it's available. ''' Private Sub SetLogControlsStatus() - LogFile.LogTracing("Setting LogControl statuses.", LogLvl.LOG_DEBUG, Me) - If LogFile.IsWritingToFile Then Btn_ViewLog.Enabled = True Btn_DeleteLog.Enabled = True @@ -379,4 +375,6 @@ Public Class Pref_Gui Btn_DeleteLog.Enabled = False End If End Sub + +#End Region End Class diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-CN.resx b/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-CN.resx index 334d3ae..e9b0020 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-CN.resx +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-CN.resx @@ -101,10 +101,6 @@ 登录 - - 每次更新UPS数据之间的时间(默认= 5)。 -接受值:1到60秒之间的数值。 - 监控的 UPS 名称。 允许值:在 UPS 的 Nut 服务端所配置的名称。 @@ -165,9 +161,6 @@ 创建日志文件 - - 创建日志文件(""WinNUT-client.log"" 文件位于 WinNUT 的安装目录)。 - 随 Windows 启动当前应用 diff --git a/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-TW.resx b/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-TW.resx index 5e63d79..f48b1c8 100644 --- a/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-TW.resx +++ b/WinNUT_V2/WinNUT-Client/Pref_Gui.zh-TW.resx @@ -174,9 +174,6 @@ 除錯 - - UPS 資料更新頻率 (預設值 5 秒)。範圍:1-60 秒。 - 最小化至系統匣 @@ -261,9 +258,6 @@ 檢查應用程式更新。 - - 建立日誌檔案 (WinNUT-client.log 檔案位於 WinNUT 的安裝目錄)。 - 選項 diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.de-DE.resx b/WinNUT_V2/WinNUT-Client/WinNUT.de-DE.resx index aff34b1..add3238 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.de-DE.resx +++ b/WinNUT_V2/WinNUT-Client/WinNUT.de-DE.resx @@ -42,9 +42,6 @@ Hilfe - - Windows NUT Client - Einstellungen @@ -105,7 +102,4 @@ False - - 180, 22 - \ No newline at end of file diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.fr-FR.resx b/WinNUT_V2/WinNUT-Client/WinNUT.fr-FR.resx index 7415cd2..af5263e 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.fr-FR.resx +++ b/WinNUT_V2/WinNUT-Client/WinNUT.fr-FR.resx @@ -42,9 +42,6 @@ Aide - - Windows NUT Client - Réglages @@ -105,7 +102,4 @@ False - - 180, 22 - \ No newline at end of file diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.ru-RU.resx b/WinNUT_V2/WinNUT-Client/WinNUT.ru-RU.resx index dd0524f..89180d3 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.ru-RU.resx +++ b/WinNUT_V2/WinNUT-Client/WinNUT.ru-RU.resx @@ -99,13 +99,7 @@ Частота - - Windows NUT CLient - False - - 180, 22 - \ No newline at end of file diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.vb b/WinNUT_V2/WinNUT-Client/WinNUT.vb index dd6bf63..894c05d 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.vb +++ b/WinNUT_V2/WinNUT-Client/WinNUT.vb @@ -138,14 +138,6 @@ Public Class WinNUT StrLog.Insert(AppResxStr.STR_LOG_UPDATE, My.Resources.Log_Str_11) StrLog.Insert(AppResxStr.STR_LOG_NUT_FSD, My.Resources.Log_Str_12) - 'Init Logger - If My.Settings.LG_LogToFile Then - LogFile.LogLevelValue = My.Settings.LG_LogLevel - LogFile.InitializeLogFile() - ElseIf LogFile.IsWritingToFile Then - LogFile.DeleteLogFile() - End If - 'Init Systray NotifyIcon.Text = ProgramName & " - " & ShortProgramVersion NotifyIcon.Visible = False @@ -171,43 +163,6 @@ Public Class WinNUT 'UPS_Device.Backup_Limit = WinNUT_Params.Arr_Reg_Key.Item("ShutdownLimitUPSRemainTime") 'UPS_Device.UPS_Follow_FSD = WinNUT_Params.Arr_Reg_Key.Item("Follow_FSD") - 'Add DialGraph - With AG_InV - .Location = New Point(6, 26) - .MaxValue = My.Settings.CAL_VoltInMax - .MinValue = My.Settings.CAL_VoltInMin - .Value1 = UPS_InputV - .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - End With - With AG_InF - .Location = New Point(6, 26) - .MaxValue = My.Settings.CAL_FreqInMax - .MinValue = My.Settings.CAL_FreqInMin - .Value1 = UPS_InputF - .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - End With - With AG_OutV - .Location = New Point(6, 26) - .MaxValue = My.Settings.CAL_VoltOutMax - .MinValue = My.Settings.CAL_VoltOutMin - .Value1 = UPS_OutputV - .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - End With - With AG_BattCh - .Location = New Point(6, 26) - .MaxValue = 100 - .MinValue = 0 - .Value1 = UPS_BattCh - .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - End With - With AG_BattV - .Location = New Point(6, 26) - .MaxValue = My.Settings.CAL_BattVMax - .MinValue = My.Settings.CAL_BattVMin - .Value1 = UPS_BattV - .ScaleLinesMajorStepValue = CInt((.MaxValue - .MinValue) / 5) - End With - 'Verify Is Windows is In Dark Mode If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", 0) = 0 Then LogFile.LogTracing("Windows App Use Dark Theme", LogLvl.LOG_DEBUG, Me) @@ -248,6 +203,8 @@ Public Class WinNUT LogFile.LogTracing("Update Icon at Startup", LogLvl.LOG_DEBUG, Me) ' Start_Tray_Icon = Nothing + ApplyApplicationPreferences() + ' If this is the first time WinNUT has been launched with the Settings system, check if old preferences exist ' and prompt the user to upgrade. If Not My.Settings.UpgradePrefsCompleted AndAlso OldPrefsExist Then @@ -416,7 +373,7 @@ Public Class WinNUT upPrefsDg.ShowDialog() UpdateManageOldPrefsMenuItemStatus() - WinNUT_PrefsChanged(True) + ApplyApplicationPreferences() End Sub Private Sub UPS_Connect(Optional retryOnConnFailure = False) @@ -518,7 +475,7 @@ Public Class WinNUT Private Sub Menu_Settings_Click(sender As Object, e As EventArgs) Handles Menu_Settings.Click LogFile.LogTracing("Open Pref Gui From Menu", LogLvl.LOG_DEBUG, Me) - AddHandler Pref_Gui.SavedPreferences, AddressOf WinNUT_PrefsChanged + AddHandler Pref_Gui.SavedPreferences, AddressOf ApplyApplicationPreferences Pref_Gui.Activate() Pref_Gui.Visible = True HasFocus = False @@ -531,7 +488,7 @@ Public Class WinNUT Private Sub Menu_Sys_Settings_Click(sender As Object, e As EventArgs) Handles Menu_Sys_Settings.Click LogFile.LogTracing("Open Pref Gui From Systray", LogLvl.LOG_DEBUG, Me) - AddHandler Pref_Gui.SavedPreferences, AddressOf WinNUT_PrefsChanged + AddHandler Pref_Gui.SavedPreferences, AddressOf ApplyApplicationPreferences Pref_Gui.Activate() Pref_Gui.Visible = True HasFocus = False @@ -718,20 +675,20 @@ Public Class WinNUT If .Batt_Charge = -1 AndAlso .Batt_Runtime = -1 Then LogFile.LogTracing("Battery properties unavailable, unable to validate shutdown conditions.", LogLvl.LOG_WARNING, Me) ElseIf Not ShutdownStatus Then - If .Batt_Charge <= My.Settings.PW_BattChrgFloor Or + If .Batt_Charge <= My.Settings.PW_BattChrgFloor Or .Batt_Runtime <= My.Settings.PW_RuntimeFloor Then - LogFile.LogTracing("UPS battery has dropped below stop condition limits.", + LogFile.LogTracing("UPS battery has dropped below stop condition limits.", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_LOG_SHUT_START)) - Shutdown_Event() - Else - LogFile.LogTracing(String.Format("UPS charge ({0}%) or Runtime ({1}) have not met shutdown conditions {2} or {3}.", + Shutdown_Event() + Else + LogFile.LogTracing(String.Format("UPS charge ({0}%) or Runtime ({1}) have not met shutdown conditions {2} or {3}.", .Batt_Charge, .Batt_Runtime, My.Settings.PW_BattChrgFloor, My.Settings.PW_RuntimeFloor), LogLvl.LOG_DEBUG, Me) - End If End If End If + End If - If .UPS_Status.HasFlag(UPS_States.OVER) Then + If .UPS_Status.HasFlag(UPS_States.OVER) Then Lbl_VOLoad.BackColor = Color.Red Else Lbl_VOLoad.BackColor = Color.White @@ -805,7 +762,7 @@ Public Class WinNUT End Sub Private Sub ReInitDisplayValues() - LogFile.LogTracing("Update all informations displayed to empty values", LogLvl.LOG_DEBUG, Me) + LogFile.LogTracing("Initializing all display values and configurations.", LogLvl.LOG_DEBUG, Me) UPS_Mfr = "" UPS_Model = "" UPS_Serial = "" @@ -819,54 +776,13 @@ Public Class WinNUT Lbl_VName.Text = UPS_Model Lbl_VSerial.Text = UPS_Serial Lbl_VFirmware.Text = UPS_Firmware - AG_InV.Value1 = My.Settings.CAL_VoltInMin - AG_InF.Value1 = My.Settings.CAL_FreqInMin - AG_OutV.Value1 = My.Settings.CAL_VoltOutMin AG_BattCh.Value1 = 0 AG_Load.Value1 = 0 AG_Load.Value2 = 0 - AG_BattV.Value1 = My.Settings.CAL_BattVMin - End Sub - - Private Sub Menu_Reconnect_Click(sender As Object, e As EventArgs) Handles Menu_Reconnect.Click - LogFile.LogTracing("Force Reconnect from menu", LogLvl.LOG_DEBUG, Me) - UPSDisconnect() - - UPS_Connect() - End Sub - - Public Sub WinNUT_PrefsChanged(isChanged As Boolean) - My.Settings.Save() - LogFile.LogTracing("Beginning WinNUT_PrefsChanged subroutine.", LogLvl.LOG_DEBUG, Me) - - ' Setup logging preferences - If My.Settings.LG_LogToFile Then - LogFile.LogLevelValue = My.Settings.LG_LogLevel - LogFile.InitializeLogFile() - ElseIf LogFile.IsWritingToFile Then - LogFile.DeleteLogFile() - End If - - ' Validate interval value because it's been incorrectly stored in older versions. - If My.Settings.NUT_PollIntervalMsec <= 0 Then - LogFile.LogTracing("Incorrect value of " & My.Settings.NUT_PollIntervalMsec & - " for Delay/Interval, resetting to default.", LogLvl.LOG_ERROR, Me) - My.Settings.NUT_PollIntervalMsec = 1000 - End If - - ' Automatically reconnect if already connected and prefs are changed. - If (UPS_Device IsNot Nothing) AndAlso UPS_Device.IsConnected And isChanged Then - LogFile.LogTracing("Connection parameters Changed. Force Reconnect", LogLvl.LOG_NOTICE, Me) - UPSDisconnect() - 'ReInitDisplayValues() - 'ActualAppIconIdx = AppIconIdx.IDX_ICO_OFFLINE - 'LogFile.LogTracing("Update Icon", LogLvl.LOG_DEBUG, Me) - 'UpdateIcon_NotifyIcon() - 'LogFile.LogTracing("New Parameter Applyed. Force Reconnect", LogLvl.LOG_DEBUG, Me) - UPS_Connect() - End If With AG_InV + AG_InV.Value1 = My.Settings.CAL_VoltInMin + If (.MaxValue <> My.Settings.CAL_VoltInMax) Or (.MinValue <> My.Settings.CAL_VoltInMin) Then LogFile.LogTracing("Parameter Dial Input Voltage Need to be Updated", LogLvl.LOG_DEBUG, Me) .MaxValue = My.Settings.CAL_VoltInMax @@ -876,6 +792,8 @@ Public Class WinNUT End If End With With AG_InF + AG_InF.Value1 = My.Settings.CAL_FreqInMin + If (.MaxValue <> My.Settings.CAL_FreqInMax) Or (.MinValue <> My.Settings.CAL_FreqInMin) Then LogFile.LogTracing("Parameter Dial Input Frequency Need to be Updated", LogLvl.LOG_DEBUG, Me) .MaxValue = My.Settings.CAL_FreqInMax @@ -885,6 +803,8 @@ Public Class WinNUT End If End With With AG_OutV + AG_OutV.Value1 = My.Settings.CAL_VoltOutMin + If (.MaxValue <> My.Settings.CAL_VoltOutMax) Or (.MinValue <> My.Settings.CAL_VoltOutMin) Then LogFile.LogTracing("Parameter Dial Output Voltage Need to be Updated", LogLvl.LOG_DEBUG, Me) .MaxValue = My.Settings.CAL_VoltOutMax @@ -894,6 +814,8 @@ Public Class WinNUT End If End With With AG_BattV + AG_BattV.Value1 = My.Settings.CAL_BattVMin + If (.MaxValue <> My.Settings.CAL_BattVMax) Or (.MinValue <> My.Settings.CAL_BattVMin) Then LogFile.LogTracing("Parameter Dial Voltage Battery Need to be Updated", LogLvl.LOG_DEBUG, Me) .MaxValue = My.Settings.CAL_BattVMax @@ -902,6 +824,43 @@ Public Class WinNUT LogFile.LogTracing("Parameter Dial Voltage Battery Updated", LogLvl.LOG_DEBUG, Me) End If End With + End Sub + + Private Sub Menu_Reconnect_Click(sender As Object, e As EventArgs) Handles Menu_Reconnect.Click + LogFile.LogTracing("Force Reconnect from menu", LogLvl.LOG_DEBUG, Me) + UPSDisconnect() + + UPS_Connect() + End Sub + + ''' + ''' Apply settings and preferences to WinNUT, whether or not they have changed. + ''' + Public Sub ApplyApplicationPreferences() + LogFile.LogTracing("Beginning ApplyApplicationPreferences subroutine.", LogLvl.LOG_DEBUG, Me) + Dim autoReconnect = False + + If (UPS_Device IsNot Nothing) AndAlso UPS_Device.IsConnected Then + autoReconnect = True + UPSDisconnect() + Else + ReInitDisplayValues() + End If + + ' Apply logging subsystem configuration + LogFile.IsWritingToFile = My.Settings.LG_LogToFile + LogFile.LogLevelValue = My.Settings.LG_LogLevel + + ' Validate interval value because it's been incorrectly stored in older versions. + If My.Settings.NUT_PollIntervalMsec <= 0 Then + LogFile.LogTracing("Incorrect value of " & My.Settings.NUT_PollIntervalMsec & + " for Poll Delay/Interval, resetting to default.", LogLvl.LOG_ERROR, Me) + My.Settings.NUT_PollIntervalMsec = My.MySettings.Default.NUT_PollIntervalMsec + End If + + If autoReconnect Then + UPS_Connect() + End If LogFile.LogTracing("WinNut Preferences Applied.", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_LOG_PREFS)) End Sub diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.zh-CN.resx b/WinNUT_V2/WinNUT-Client/WinNUT.zh-CN.resx index 231ca47..2395724 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.zh-CN.resx +++ b/WinNUT_V2/WinNUT-Client/WinNUT.zh-CN.resx @@ -99,13 +99,7 @@ 频率 - - Windows NUT Client - False - - 180, 22 - \ No newline at end of file diff --git a/WinNUT_V2/WinNUT-Client/WinNUT.zh-TW.resx b/WinNUT_V2/WinNUT-Client/WinNUT.zh-TW.resx index f4f9594..93d5391 100644 --- a/WinNUT_V2/WinNUT-Client/WinNUT.zh-TW.resx +++ b/WinNUT_V2/WinNUT-Client/WinNUT.zh-TW.resx @@ -102,7 +102,4 @@ False - - 180, 22 - \ No newline at end of file diff --git a/WinNUT_V2/WinNUT-Client_Common/Logger.vb b/WinNUT_V2/WinNUT-Client_Common/Logger.vb index 86dfceb..4859dca 100644 --- a/WinNUT_V2/WinNUT-Client_Common/Logger.vb +++ b/WinNUT_V2/WinNUT-Client_Common/Logger.vb @@ -74,22 +74,35 @@ Public Class Logger End Property ''' - ''' Returns if data is being written to a file. Also allows for file logging to be setup or stopped. + ''' Check status of the log file writer, as well as start or stop logging to a file. + ''' Events continue to be recorded to memory regardless. ''' ''' True when the object is instantiated, false if not. - Public ReadOnly Property IsWritingToFile() As Boolean + Public Property IsWritingToFile As Boolean Get Return LogFile IsNot Nothing End Get + Set(value As Boolean) + If value <> (LogFile IsNot Nothing) Then + If value = True Then + InitializeLogFile() + Else + TerminateLogFile() + End If + End If + End Set End Property ''' - ''' Get the log file location from the object. + ''' Get the filesystem location of the object, or the folder where it would be stored. ''' - ''' The possible path to the log file. Note that this does not gaurantee it exists. Public ReadOnly Property LogFilePath() As String Get - Return LogFile.FullLogFileName + If IsWritingToFile Then + Return LogFile.FullLogFileName + Else + Return DEFAULT_LOCATION + End If End Get End Property @@ -109,6 +122,8 @@ Public Class Logger LogLevelValue = LogLevel End Sub +#Region "Log file management" + ''' ''' Instantiates a new at a the desired location, and outputs the ''' buffer into the file before synchronizing with write calls. @@ -145,30 +160,42 @@ Public Class Logger End Sub ''' - ''' Disable logging and delete the current file. + ''' End logging to the by writing a terminating line to it, then closing and dereferencing it. ''' - ''' True if file was successfully deleted. False if an exception was encountered. - Public Function DeleteLogFile() As Boolean - Dim fileLocation = LogFile.FullLogFileName - - ' Disable logging first. - If LogFile IsNot Nothing Then + ''' The LogFile object is already Nothing and file logging is disabled. + ''' + Public Sub TerminateLogFile() + If IsWritingToFile Then + LogTracing("Terminating log file.", LogLvl.LOG_NOTICE, Me) LogFile.Close() LogFile.Dispose() - ' For some reason, the object needs to be dereferenced to actually get it to close the handle. LogFile = Nothing - LogTracing("Logging to file has been disabled.", LogLvl.LOG_NOTICE, Me) + Else + Dim invOpExcp As New InvalidOperationException("Unable to terminate log file - already disabled.") + LogException(invOpExcp, Me) + Throw invOpExcp End If + End Sub - Try - ' IsWritingToFile = False + ''' + ''' Disable logging and delete the current file. May throw an exception while deleting the file, + ''' even if file logging was enabled. + ''' + ''' LogFile object is Nothing. + Public Sub DeleteLogFile() + If IsWritingToFile Then + Dim fileLocation = LogFile.FullLogFileName + TerminateLogFile() File.Delete(fileLocation) - Return True - Catch ex As Exception - LogTracing("Error when deleteing log file: " & ex.ToString(), LogLvl.LOG_ERROR, Me) - Return False - End Try - End Function + LogTracing("Log file has been deleted.", LogLvl.LOG_NOTICE, Me) + Else + Dim invOpExcp As New InvalidOperationException("File logging is disabled, unable to delete log file.") + LogException(invOpExcp, Me) + Throw invOpExcp + End If + End Sub + +#End Region ''' ''' Write the to the Debug tracer is debugging, into the diff --git a/WinNUT_V2/WinNUT-Client_Common/WinNUT-Client_Common.vbproj b/WinNUT_V2/WinNUT-Client_Common/WinNUT-Client_Common.vbproj index fd7f8d3..6eb6abd 100644 --- a/WinNUT_V2/WinNUT-Client_Common/WinNUT-Client_Common.vbproj +++ b/WinNUT_V2/WinNUT-Client_Common/WinNUT-Client_Common.vbproj @@ -23,7 +23,8 @@ 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 - TEST_RELEASE_DIRS + + none