Skip to content

Commit fd2c73c

Browse files
committed
Upgrade Settings at start if necessary
Application Settings upgrade routine is only run automatically when using the ClickOnce installer. Since it's not run with our current MSI build, this code will then run when the program is started for the first time (nothing happens) or if it's an upgraded MSI installation with a fresh copy of settings. In that case, the Upgrade function will find the older copy and import/apply them. This operation won't be attempted until the next upgrade. Need to remove once using pure ClickOnce.
1 parent 89a8b42 commit fd2c73c

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

WinNUT_V2/WinNUT-Client/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@
157157
<setting name="CAL_BattVMax" serializeAs="String">
158158
<value>18</value>
159159
</setting>
160+
<setting name="IsFirstRun" serializeAs="String">
161+
<value>True</value>
162+
</setting>
160163
</WinNUT_Client.My.MySettings>
161164
</userSettings>
162165
</configuration>

WinNUT_V2/WinNUT-Client/ApplicationEvents.vb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,24 @@ Namespace My
4040
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
4141
' Uncomment below and comment out Handles line for _UnhandledException sub when debugging unhandled exceptions.
4242
' AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomainUnhandledException
43+
4344
Init_Globals()
45+
46+
' If first run indicated by Settings, attempt upgrade in case older version is present.
47+
' Only necessary when deploying MSI. Remove once using pure ClickOnce.
48+
If Settings.IsFirstRun Then
49+
Try
50+
Settings.Upgrade()
51+
LogFile.LogTracing("Settings upgrade completed without exception.", LogLvl.LOG_NOTICE, Me)
52+
Catch ex As ConfigurationErrorsException
53+
LogFile.LogTracing("Error encountered while trying to upgrade Settings:", LogLvl.LOG_ERROR, Me)
54+
LogFile.LogException(ex, Me)
55+
End Try
56+
57+
Settings.IsFirstRun = False
58+
Settings.Save()
59+
End If
60+
4461
LogFile.LogTracing("MyApplication_Startup complete.", LogLvl.LOG_DEBUG, Me)
4562
End Sub
4663

WinNUT_V2/WinNUT-Client/My Project/Settings.Designer.vb

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WinNUT_V2/WinNUT-Client/My Project/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,8 @@
116116
<Setting Name="CAL_BattVMax" Type="System.Int32" Scope="User">
117117
<Value Profile="(Default)">18</Value>
118118
</Setting>
119+
<Setting Name="IsFirstRun" Type="System.Boolean" Scope="User">
120+
<Value Profile="(Default)">True</Value>
121+
</Setting>
119122
</Settings>
120123
</SettingsFile>

WinNUT_V2/WinNUT-Client/WinNUT-client.vbproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
</PropertyGroup>
113113
<ItemGroup>
114114
<Reference Include="System" />
115+
<Reference Include="System.Configuration" />
115116
<Reference Include="System.Data" />
116117
<Reference Include="System.Deployment" />
117118
<Reference Include="System.Drawing" />

0 commit comments

Comments
 (0)