Setup.vb
See the
Setup/Settings section for a detailed description of this example.
Imports System
Imports System.Diagnostics
Imports System.Xml
Imports System.Web
Imports System.IO
Imports System.Windows.Forms
Imports centrafuse.Plugins
Imports Microsoft.Win32
Namespace HelloWorld
''' <summary>
''' Setup class inherits from CFSetup so that it will not show up as a separate
''' plugin, but a dialog within a plugin.
''' It uses the standard Setup screens from the main application.
''' </summary>
Public Class Setup
Inherits CFSetup
' String constants
Private Const PluginPath As String = "plugins\HelloWorld\"
Private Const PluginPathLanguages As String = PluginPath + "Languages\"
Private Const ConfigurationFile As String = "config.xml"
Private Const ConfigSection As String = "/APPCONFIG/"
Private Const LanguageSection As String = "/APPLANG/SETUP/"
Private Const LanguageControlSection As String = "/APPLANG/HELLOWORLD/"
' Local XmlDocument to hold and modify the configuration file.
Private configXml As XmlDocument = New XmlDocument
Private languageXml As XmlDocument = New XmlDocument
#Region "Construction"
Public Sub New()
totalpages = 1
' If user has advanced settings turned on, then the CF_showAdvancedSettings flag will be set to true
' Some plugins may require more pages for advanced settings, this must be determined by plugin developer.
If CF_showAdvancedSettings Then
totalpages = 1
End If
' Current page when settings are opened is always 1
currentpage = 1
' Builds the controls.
BuildControls()
' Loads the plugin configuration from the specified path.
Me.CF_loadConfig(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Centrafuse\\" + PluginPath + ConfigurationFile)
' Loads the plugin language file from the specified path. This is loaded using the language
' specified in the configuration file.
Me.CF_loadLang(PluginPathLanguages + Me.pluginConfig.readPluginField("/APPCONFIG/APPLANG") + ".xml")
' Loads the configuration file into the local XmlDocument.
configXml.Load(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Centrafuse\\" + PluginPath + ConfigurationFile)
languageXml.Load(PluginPathLanguages + Me.pluginConfig.readPluginField("/APPCONFIG/APPLANG") + ".xml")
End Sub
#End Region
#Region "Initialization"
' This function can be called by the plugin application form after construction and after setting the MainForm property
Public Sub SetupSection()
' Build controls
Me.buildSetup()
' Populate the setup page
Me.loadSetupPage()
' Populate button texts
Me.CF_updateButtonText("OK", LanguageReader.getText("APPLANG/BUTTONS/SAVE"))
Me.CF_updateButtonText("CANCEL", LanguageReader.getText("APPLANG/BUTTONS/CANCEL"))
Me.CF_updateText("TITLE", Me.pluginLang.readPluginField("/APPLANG/SETUP/TITLE"))
End Sub
Private Function readConfigValue(ByVal xpath As String) As String
If configXml.SelectSingleNode(xpath) IsNot Nothing Then
Return System.Web.HttpUtility.HtmlDecode(configXml.SelectSingleNode(xpath).InnerText)
Else
Return ""
End If
End Function
Private Sub updateConfig(ByVal xpath As String, ByVal xvalue As String)
If configXml.SelectSingleNode(xpath) IsNot Nothing Then
configXml.SelectSingleNode(xpath).InnerText = HttpUtility.HtmlEncode(xvalue)
End If
End Sub
' Builds Setup events.
Private Sub BuildControls()
AddHandler Me.CFSetup_ok, AddressOf section1_CFSetup_ok
AddHandler Me.CFSetup_cancel, AddressOf section1_CFSetup_cancel
End Sub
' Reads the configuration file and populates the button text.
Public Overrides Sub readConfig()
Try
Dim i As Integer = SetupButton.One
If CF_showAdvancedSettings Then
'*******************************************************************************************/
'***** ADVANCED SETTINGS - PAGE 1 ********************************************************/
'*******************************************************************************************/
If currentpage = 1 Then
' TEXT BUTTONS (1-4)
ButtonHandler(i) = AddressOf SetDisplayName
ButtonText(i) = Me.pluginLang.readPluginField("APPLANG/SETUP/DISPLAYNAME")
ButtonValue(i) = Me.pluginLang.readPluginField("APPLANG/HELLOWORLD/DISPLAYNAME")
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
' BOOL BUTTONS (5-8)
ButtonHandler(i) = AddressOf SetLogEvents
ButtonText(i) = Me.pluginLang.readPluginField("/APPLANG/SETUP/LOGEVENTS")
ButtonValue(i) = readConfigValue("/APPCONFIG/LOGEVENTS")
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
End If
Else
'*******************************************************************************************/
'***** BASIC SETTINGS - PAGE 1 ***********************************************************/
'*******************************************************************************************/
If currentpage = 1 Then
' TEXT BUTTONS (1-4)
ButtonHandler(i) = AddressOf SetDisplayName
ButtonText(i) = Me.pluginLang.readPluginField("APPLANG/SETUP/DISPLAYNAME")
ButtonValue(i) = readConfigValue("/APPCONFIG/DISPLAYNAME")
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
' BOOL BUTTONS (5-8)
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
i = i + 1
ButtonHandler(i) = Nothing
ButtonText(i) = ""
ButtonValue(i) = ""
End If
End If
Catch errmsg As Exception
CFTools.writeError(errmsg.Message, errmsg.StackTrace)
End Try
End Sub
#End Region
#Region "Button Clicks"
Private Sub section1_CFSetup_ok(ByVal sender As Object, ByVal e As EventArgs)
Try
' Launches system YesNo dialog to verify the user wants to overwrite their current settings.
' If yes then the local XML document is saved.
If Me.CF_systemDisplayDialog(CF_Dialogs.YesNo, LanguageReader.getText("/APPLANG/SETUP/OVERWRITETEXT")) = DialogResult.OK Then
configXml.Save(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Centrafuse\\" + PluginPath + ConfigurationFile)
languageXml.Save(PluginPathLanguages + configXml.SelectSingleNode("/APPCONFIG/APPLANG").InnerText + ".xml")
Me.DialogResult = DialogResult.OK
End If
Catch errmsg As Exception
CFTools.writeError(errmsg.Message, errmsg.StackTrace)
End Try
End Sub
Private Sub section1_CFSetup_cancel(ByVal sender As Object, ByVal e As EventArgs)
Me.DialogResult = DialogResult.Cancel
End Sub
#End Region
Private Sub SetDisplayName(ByRef value As Object)
Try
Dim tempobject As Object = New Object
Dim resultvalue As String = "", resulttext As String = ""
If Me.CF_systemDisplayDialog(CF_Dialogs.OSK, Me.pluginLang.readPluginField("/APPLANG/SETUP/DISPLAYNAME"), ButtonValue(value), Nothing, resultvalue, resulttext, tempobject, Nothing, True, True, True, True, False, False, 1) = DialogResult.OK Then
languageXml.SelectSingleNode("/APPLANG/HELLOWORLD/DISPLAYNAME").InnerText = HttpUtility.HtmlEncode(resultvalue)
ButtonValue(value) = resultvalue
End If
Catch errmsg As Exception
CFTools.writeError(errmsg.Message, errmsg.StackTrace)
End Try
End Sub
Private Sub SetLogEvents(ByRef value As Object)
updateConfig("/APPCONFIG/LOGEVENTS", value.ToString())
End Sub
End Class
End Namespace