Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions WinNUT_V2/WinNUT-Client/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@
</system.diagnostics>
<userSettings>
<WinNUT_Client.My.MySettings>
<setting name="UpgradePrefsCompleted" serializeAs="String">
<value>False</value>
</setting>
<setting name="StartWithWindows" serializeAs="String">
<value>False</value>
</setting>
Expand Down
62 changes: 41 additions & 21 deletions WinNUT_V2/WinNUT-Client/ApplicationEvents.vb
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
' WinNUT-Client is a NUT windows client for monitoring your ups hooked up to your favorite linux server.
' Copyright (C) 2019-2021 Gawindx (Decaux Nicolas)
'
' This program is free software: you can redistribute it and/or modify it under the terms of the
' GNU General Public License as published by the Free Software Foundation, either version 3 of the
' License, or any later version.
'
' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY

Imports System.Configuration
Imports System.Deployment.Application
Imports System.Configuration
Imports System.Globalization
Imports System.IO
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic.ApplicationServices
Imports Newtonsoft.Json
Imports WinNUT_Client_Common
Imports WinNUT_Client_Common.OldParams

Namespace My
' Les événements suivants sont disponibles pour MyApplication :
' Startup : Déclenché au démarrage de l'application avant la création du formulaire de démarrage.
' Shutdown : Déclenché après la fermeture de tous les formulaires de l'application. Cet événement n'est pas déclenché si l'application se termine de façon anormale.
' UnhandledException : Déclenché si l'application rencontre une exception non gérée.
' StartupNextInstance : Déclenché lors du lancement d'une application à instance unique et si cette application est déjà active.
' NetworkAvailabilityChanged : Déclenché quand la connexion réseau est connectée ou déconnectée.
Partial Friend Class MyApplication
' Default culture for output so logs can be shared with the project.
Private Shared ReadOnly DEF_CULTURE_INFO As CultureInfo = CultureInfo.InvariantCulture
Expand All @@ -41,23 +26,31 @@ Namespace My
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
' Uncomment below and comment out Handles line for _UnhandledException sub when debugging unhandled exceptions.
' AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomainUnhandledException

AddHandler Settings.SettingsLoaded, AddressOf OnSettingsFirstLoaded
Init_Globals()
LogFile.LogTracing(String.Format("{0} v{1} starting up.", My.Application.Info.ProductName, My.Application.Info.Version),
LogFile.LogTracing(String.Format("{0} v{1} starting up.", Application.Info.ProductName, Application.Info.Version),
LogLvl.LOG_NOTICE, Me)
' LogFile.LogTracing($"DataDirectory: { ApplicationDeployment.CurrentDeployment.DataDirectory }", LogLvl.LOG_NOTICE, Me)

' If first run indicated by Settings, attempt upgrade in case older version is present.
' Only necessary when deploying MSI. Remove once using pure ClickOnce.
' Starting without previous settings. May be new installation or MSI upgrade.
If Settings.IsFirstRun Then
Try
' Handle MSI upgrade scenario.
Settings.Upgrade()
LogFile.LogTracing("Settings upgrade completed without exception.", LogLvl.LOG_NOTICE, Me)
Catch ex As ConfigurationErrorsException
LogFile.LogTracing("Error encountered while trying to upgrade Settings:", LogLvl.LOG_ERROR, Me)
LogFile.LogException(ex, Me)
End Try

' If Settings still appear new, check if old Registry preferences are leftover.
If Settings.IsFirstRun AndAlso WinNUT_Params.ParamsExist Then
LogFile.LogTracing("Previous preferences data detected in the Registry.", LogLvl.LOG_NOTICE, Me,
Resources.DetectedPreviousPrefsData)

Forms.UpgradePrefsDialog.ShowDialog()
End If

Settings.IsFirstRun = False
Settings.Save()
End If
Expand Down Expand Up @@ -196,5 +189,32 @@ Namespace My
Private Sub Close_Button_Click(sender As Object, e As EventArgs)
CrashBug_Form.Close()
End Sub

''' <summary>
''' Handles validation of Settings when loaded.
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
Private Sub OnSettingsFirstLoaded(sender As Object, e As SettingsLoadedEventArgs)
LogFile.LogTracing("OnSettingsFirstLoaded event raised.", LogLvl.LOG_DEBUG, Me)

' Verify that encrypted data can be decrypted
Try
Settings.NUT_Username?.ToString()
Catch ex As Exception
LogFile.LogTracing("Error attempting to decrypt encrypted data. Resetting to defaults.",
LogLvl.LOG_ERROR, Me, Resources.Log_Str_ErrorDecrypting)
LogFile.LogException(ex, Me)

Settings.NUT_Username = New SerializedProtectedString()
Settings.NUT_Password = New SerializedProtectedString()
End Try

If Not Settings.NUT_PollIntervalMsec > 0 Then
LogFile.LogTracing("Incorrect value of " & Settings.NUT_PollIntervalMsec &
" for Poll Delay/Interval, resetting to default.", LogLvl.LOG_ERROR, Me)
Settings.NUT_PollIntervalMsec = MySettings.Default.NUT_PollIntervalMsec
End If
End Sub
End Class
End Namespace
7 changes: 2 additions & 5 deletions WinNUT_V2/WinNUT-Client/Models/UpgradePrefsDialogModel.vb
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ Namespace Models
LogFile.LogTracing("Requesting cancellation of upgradeWorker.", LogLvl.LOG_NOTICE, Me)
upgradeWorker.CancelAsync()
Else
LogFile.LogTracing("Exiting out of upgrade dialog.", LogLvl.LOG_NOTICE, Me)
LogFile.LogTracing("Exiting out of upgrade dialog.", LogLvl.LOG_NOTICE, Me, My.Resources.UpgradePrefsDialog_Cancelled)
_parentForm.DialogResult = DialogResult.Cancel
My.Settings.UpgradePrefsCompleted = True
_parentForm.Close()
End If
End Sub
Expand Down Expand Up @@ -263,13 +262,11 @@ Namespace Models

If e.Cancelled Then
ProgressPercent = 0
LogFile.LogTracing("Upgrade work was cancelled.", LogLvl.LOG_WARNING, Me, My.Resources.UpgradePrefsDialog_Cancelled)
LogFile.LogTracing("Upgrade work was cancelled.", LogLvl.LOG_WARNING, Me)
Return
End If

ProgressPercent = 100

My.Settings.UpgradePrefsCompleted = True
_parentForm.Close()
End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,6 @@ Remaining Time : {WinNUT.Lbl_VRTime.Text}</source>
<source>..\Resources\Delete_LogFile_24x24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</source>
<target state="final">..\Resources\Delete_LogFile_24x24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</target>
</trans-unit>
<trans-unit id="Frm_Main_Str_01" translate="yes" xml:space="preserve">
<source>Old ups.ini imported
Ini File Moved to {0}.old</source>
<target state="translated">已匯入舊的 ups.ini, ini 檔案已重新命名為 {0}.old</target>
</trans-unit>
<trans-unit id="Frm_Main_Str_02" translate="yes" xml:space="preserve">
<source>Old ups.ini imported</source>
<target state="translated">匯入舊的 ups.ini</target>
</trans-unit>
<trans-unit id="Frm_Main_Str_03" translate="yes" xml:space="preserve">
<source>Reconnection In Progress</source>
<target state="translated">正在重新連線</target>
Expand Down Expand Up @@ -712,15 +703,15 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa
<target state="new">Unavailable</target>
<note from="MultilingualBuild" annotates="source" priority="2">Indicate that a variable is unavailable</note>
</trans-unit>
<trans-unit id="RepeatHS" translate="yes" xml:space="preserve" extype="System.Resources.ResXFileRef, System.Windows.Forms">
<trans-unit id="RepeatHS" translate="yes" extype="System.Resources.ResXFileRef, System.Windows.Forms" xml:space="preserve">
<source>..\Resources\RepeatHS.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</source>
<target state="needs-review-translation">..\Resources\RepeatHS.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</target>
</trans-unit>
<trans-unit id="disconnect2" translate="yes" xml:space="preserve" extype="System.Resources.ResXFileRef, System.Windows.Forms">
<trans-unit id="disconnect2" translate="yes" extype="System.Resources.ResXFileRef, System.Windows.Forms" xml:space="preserve">
<source>..\Resources\disconnect2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</source>
<target state="needs-review-translation">..\Resources\disconnect2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</target>
</trans-unit>
<trans-unit id="internetconnection" translate="yes" xml:space="preserve" extype="System.Resources.ResXFileRef, System.Windows.Forms">
<trans-unit id="internetconnection" translate="yes" extype="System.Resources.ResXFileRef, System.Windows.Forms" xml:space="preserve">
<source>..\Resources\internetconnection.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</source>
<target state="needs-review-translation">..\Resources\internetconnection.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</target>
</trans-unit>
Expand All @@ -729,6 +720,10 @@ Please correct the error, or cancel the upgrade dialog to continue with the defa
<target state="new">Checking for update...</target>
<note from="MultilingualBuild" annotates="source" priority="2">Inform the user that WinNUT is checking for an update.</note>
</trans-unit>
<trans-unit id="Log_Str_ErrorDecrypting" translate="yes" xml:space="preserve">
<source>Error loading encrypted Settings (username/password)</source>
<target state="new">Error loading encrypted Settings (username/password)</target>
<note from="MultilingualBuild" annotates="source" priority="2">Short log string to alert the user that there was an error loading encrypted Settings, and give examples of what those Settings were.</note>
<trans-unit id="CopyHS" translate="yes" xml:space="preserve" extype="System.Resources.ResXFileRef, System.Windows.Forms">
<source>..\Resources\CopyHS.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</source>
<target state="needs-review-translation">..\Resources\CopyHS.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</target>
Expand Down Expand Up @@ -2430,8 +2425,8 @@ Accepted value: Numeric value from 0 to 100.</source>
<target state="final">None</target>
</trans-unit>
<trans-unit id="Menu_UPS_Var.Size" translate="no" extype="System.Drawing.Size, System.Drawing" xml:space="preserve">
<source>180, 22</source>
<target state="final">180, 22</target>
<source>177, 22</source>
<target state="final">177, 22</target>
</trans-unit>
<trans-unit id="Menu_UPS_Var.Text" translate="yes" xml:space="preserve">
<source>UPS Variable</source>
Expand All @@ -2454,8 +2449,8 @@ Accepted value: Numeric value from 0 to 100.</source>
<target state="translated">檔案</target>
</trans-unit>
<trans-unit id="Menu_Disconnect.Size" translate="no" extype="System.Drawing.Size, System.Drawing" xml:space="preserve">
<source>180, 22</source>
<target state="final">180, 22</target>
<source>133, 22</source>
<target state="final">133, 22</target>
</trans-unit>
<trans-unit id="Menu_Disconnect.Text" translate="yes" xml:space="preserve">
<source>Disconnect</source>
Expand Down Expand Up @@ -3637,59 +3632,59 @@ Accepted value: Numeric value from 0 to 100.</source>
<source></source>
<target state="new"></target>
</trans-unit>
<trans-unit id="Menu_Connect.Size" translate="yes" xml:space="preserve" extype="System.Drawing.Size, System.Drawing">
<source>180, 22</source>
<target state="needs-review-translation">180, 22</target>
<trans-unit id="Menu_Connect.Size" translate="no" extype="System.Drawing.Size, System.Drawing" xml:space="preserve">
<source>133, 22</source>
<target state="final">133, 22</target>
</trans-unit>
<trans-unit id="Menu_Connect.Text" translate="yes" xml:space="preserve">
<source>Connect</source>
<target state="new">Connect</target>
</trans-unit>
<trans-unit id="AG_InV.Text" translate="yes" xml:space="preserve" extype="System.Resources.ResXNullRef, System.Windows.Forms">
<trans-unit id="AG_InV.Text" translate="yes" extype="System.Resources.ResXNullRef, System.Windows.Forms" xml:space="preserve">
<source></source>
<target state="needs-review-translation"></target>
</trans-unit>
<trans-unit id="AG_OutV.Text" translate="yes" xml:space="preserve" extype="System.Resources.ResXNullRef, System.Windows.Forms">
<trans-unit id="AG_OutV.Text" translate="yes" extype="System.Resources.ResXNullRef, System.Windows.Forms" xml:space="preserve">
<source></source>
<target state="needs-review-translation"></target>
</trans-unit>
<trans-unit id="AG_BattCh.Text" translate="yes" xml:space="preserve" extype="System.Resources.ResXNullRef, System.Windows.Forms">
<trans-unit id="AG_BattCh.Text" translate="yes" extype="System.Resources.ResXNullRef, System.Windows.Forms" xml:space="preserve">
<source></source>
<target state="needs-review-translation"></target>
</trans-unit>
<trans-unit id="AG_Load.Text" translate="yes" xml:space="preserve" extype="System.Resources.ResXNullRef, System.Windows.Forms">
<trans-unit id="AG_Load.Text" translate="yes" extype="System.Resources.ResXNullRef, System.Windows.Forms" xml:space="preserve">
<source></source>
<target state="needs-review-translation"></target>
</trans-unit>
<trans-unit id="AG_BattV.Text" translate="yes" xml:space="preserve" extype="System.Resources.ResXNullRef, System.Windows.Forms">
<trans-unit id="AG_BattV.Text" translate="yes" extype="System.Resources.ResXNullRef, System.Windows.Forms" xml:space="preserve">
<source></source>
<target state="needs-review-translation"></target>
</trans-unit>
<trans-unit id="AG_InF.Text" translate="yes" xml:space="preserve" extype="System.Resources.ResXNullRef, System.Windows.Forms">
<trans-unit id="AG_InF.Text" translate="yes" extype="System.Resources.ResXNullRef, System.Windows.Forms" xml:space="preserve">
<source></source>
<target state="needs-review-translation"></target>
</trans-unit>
<trans-unit id="ToolStripSeparator1.Size" translate="yes" xml:space="preserve" extype="System.Drawing.Size, System.Drawing">
<source>177, 6</source>
<target state="needs-review-translation">177, 6</target>
<trans-unit id="ToolStripSeparator1.Size" translate="no" extype="System.Drawing.Size, System.Drawing" xml:space="preserve">
<source>130, 6</source>
<target state="final">130, 6</target>
</trans-unit>
<trans-unit id="Menu_Persist.Size" translate="yes" xml:space="preserve" extype="System.Drawing.Size, System.Drawing">
<source>180, 22</source>
<target state="needs-review-translation">180, 22</target>
<trans-unit id="Menu_Persist.Size" translate="no" extype="System.Drawing.Size, System.Drawing" xml:space="preserve">
<source>133, 22</source>
<target state="final">133, 22</target>
</trans-unit>
<trans-unit id="Menu_Persist.Text" translate="yes" xml:space="preserve">
<source>Persist</source>
<target state="new">Persist</target>
</trans-unit>
<trans-unit id="Menu_Disconnect.Enabled" translate="yes" xml:space="preserve" extype="System.Boolean, mscorlib">
<trans-unit id="Menu_Disconnect.Enabled" translate="yes" extype="System.Boolean, mscorlib" xml:space="preserve">
<source>False</source>
<target state="needs-review-translation">False</target>
</trans-unit>
<trans-unit id="$this.ImeMode" translate="yes" xml:space="preserve" extype="System.Windows.Forms.ImeMode, System.Windows.Forms">
<trans-unit id="$this.ImeMode" translate="yes" extype="System.Windows.Forms.ImeMode, System.Windows.Forms" xml:space="preserve">
<source>NoControl</source>
<target state="needs-review-translation">NoControl</target>
</trans-unit>
<trans-unit id="Menu_UPS_Var.Enabled" translate="yes" xml:space="preserve" extype="System.Boolean, mscorlib">
<trans-unit id="Menu_UPS_Var.Enabled" translate="yes" extype="System.Boolean, mscorlib" xml:space="preserve">
<source>False</source>
<target state="needs-review-translation">False</target>
</trans-unit>
Expand Down
Loading