section for a detailed description of this example.
#include "Setup.h"
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Xml;
using namespace System::Web;
using namespace centrafuse::Plugins;
namespace HelloWorld
{
Setup::Setup()
{
PluginPath = "plugins\\HelloWorld\\";
PluginPathLanguages = String::Concat(PluginPath, "Languages\\");
ConfigurationFile = "config.xml";
ConfigSection = "/APPCONFIG/";
LanguageSection = "/APPLANG/SETUP/";
LanguageControlSection = "/APPLANG/HELLOWORLD/";
totalpages = 1;
if (CF_showAdvancedSettings)
totalpages = 1;
currentpage = 1;
buildControls();
String^ configfilepath = String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile);
this->CF_loadConfig(configfilepath);
this->CF_loadLang(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml"));
configxml = gcnew XmlDocument();
languagexml = gcnew XmlDocument();
configxml->Load(configfilepath);
languagexml->Load(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml"));
}
void Setup::setupSection()
{
this->buildSetup();
this->loadSetupPage();
this->CF_updateButtonText("OK", LanguageReader::getText("APPLANG/BUTTONS/SAVE"));
this->CF_updateButtonText("CANCEL", LanguageReader::getText("APPLANG/BUTTONS/CANCEL"));
this->CF_updateText("TITLE", this->pluginLang->readPluginField("/APPLANG/SETUP/TITLE"));
}
String^ Setup::readConfigValue(String^ xpath)
{
if (configxml->SelectSingleNode(xpath) != nullptr)
return System::Web::HttpUtility::HtmlDecode(configxml->SelectSingleNode(xpath)->InnerText);
else
return "";
}
void Setup::updateConfig(String^ xpath, String^ xvalue)
{
if (configxml->SelectSingleNode(xpath) != nullptr)
configxml->SelectSingleNode(xpath)->InnerText = HttpUtility::HtmlEncode(xvalue);
}
void Setup::buildControls()
{
this->CFSetup_ok += gcnew EventHandler(this, &Setup::section1_CFSetup_ok);
this->CFSetup_cancel += gcnew EventHandler(this, &Setup::section1_CFSetup_cancel);
}
void Setup::readConfig()
{
try
{
int i = SetupButton::One;
if (CF_showAdvancedSettings)
{
if (currentpage == 1)
{
ButtonHandler[i] = gcnew SettingsClickHandler(this, &Setup::SetDisplayName);
ButtonText[i] = this->pluginLang->readPluginField("APPLANG/SETUP/DISPLAYNAME");
ButtonValue[i++] = this->pluginLang->readPluginField("APPLANG/HELLOWORLD/DISPLAYNAME");
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = gcnew SettingsClickHandler(this, &Setup::SetLogEvents);
ButtonText[i] = this->pluginLang->readPluginField("/APPLANG/SETUP/LOGEVENTS");
ButtonValue[i++] = readConfigValue("/APPCONFIG/LOGEVENTS");
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
}
}
else
{
if (currentpage == 1)
{
ButtonHandler[i] = gcnew SettingsClickHandler(this, &Setup::SetDisplayName);
ButtonText[i] = this->pluginLang->readPluginField("APPLANG/SETUP/DISPLAYNAME");
ButtonValue[i++] = this->pluginLang->readPluginField("APPLANG/HELLOWORLD/DISPLAYNAME");
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
ButtonHandler[i] = nullptr;
ButtonText[i] = "";
ButtonValue[i++] = "";
}
}
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
}
void Setup::section1_CFSetup_ok(Object^ sender, EventArgs^ e)
{
Object^ tempobject;
String^ temp, ^temp2;
try
{
if (this->CF_systemDisplayDialog(CF_Dialogs::YesNo, LanguageReader::getText("APPLANG/SETUP/OVERWRITETEXT"), nullptr, nullptr, temp, temp2, tempobject, nullptr, true, true, true, true, false, false, 1) == Windows::Forms::DialogResult::OK)
{
configxml->Save(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile));
languagexml->Save(String::Concat(PluginPathLanguages, configxml->SelectSingleNode("/APPCONFIG/APPLANG")->InnerText, ".xml"));
this->DialogResult = Windows::Forms::DialogResult::OK;
}
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
}
void Setup::section1_CFSetup_cancel(Object^ sender, EventArgs^ e)
{
this->DialogResult = Windows::Forms::DialogResult::Cancel;
}
void Setup::SetDisplayName(Object^% value)
{
try
{
Object^ tempobject;
String^ resultvalue, ^resulttext;
if (this->CF_systemDisplayDialog(CF_Dialogs::OSK, this->pluginLang->readPluginField("/APPLANG/SETUP/DISPLAYNAME"), ButtonValue[(int)value], nullptr, resultvalue, resulttext, tempobject, nullptr, true, true, true, true, false, false, 1) == Windows::Forms::DialogResult::OK)
{
languagexml->SelectSingleNode("/APPLANG/HELLOWORLD/DISPLAYNAME")->InnerText = HttpUtility::HtmlEncode(resultvalue);
ButtonValue[(int)value] = resultvalue;
}
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
}
void Setup::SetLogEvents(Object^% value)
{
updateConfig("/APPCONFIG/LOGEVENTS", value->ToString());
}
}