section for a detailed description of this example.
#include "HelloWorld.h"
#include "Setup.h"
using namespace System;
using namespace System::Collections;
using namespace System::Diagnostics;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Windows::Forms;
using namespace System::Xml;
using namespace centrafuse::Plugins;
namespace HelloWorld
{
HelloWorld::HelloWorld()
{
PluginName = "HelloWorld";
PluginPath = String::Concat("plugins\\", PluginName, "\\");
PluginPathSkins = String::Concat(PluginPath, "Skins\\");
PluginPathLanguages = String::Concat(PluginPath, "Languages\\");
PluginPathIcons = String::Concat(PluginPath, "Icons\\");
ConfigurationFile = "config.xml";
ConfigSection = "/APPCONFIG/";
LanguageSection = "/APPLANG/HELLOWORLD/";
LogFile= "helloworld.log";
ImageFolderIndex = 0;
ImageEmptyIndex = 1;
LogFilePath = String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\Plugins\\");
LogFilePath = String::Concat(LogFilePath, PluginName, "\\", LogFile);
this->CF_pluginPauseAudioFlag = false;
this->CF_pluginName = "HELLOWORLD";
this->CF_pluginIsGUI = true;
this->CF_pluginHasSettings = true;
this->CF_pluginHasBasicSettings = true;
AddConfigXml();
}
void HelloWorld::AddConfigXml()
{
try
{
String^ configXmlPath = String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile);
if (!Directory::Exists(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\Plugins\\", PluginName)))
{
Directory::CreateDirectory(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\Plugins\\", PluginName));
}
if (!File::Exists(configXmlPath))
{
FileStream^ fs = gcnew FileStream(configXmlPath, FileMode::Create, FileAccess::Write, FileShare::Write);
fs->Close();
StreamWriter^ sw = gcnew StreamWriter(configXmlPath, false, System::Text::Encoding::ASCII);
sw->Write("<APPCONFIG>\r\n <SKIN>Aura</SKIN>\r\n <APPLANG>English</APPLANG>\r\n <LOGEVENTS>False</LOGEVENTS>\r\n</APPCONFIG>\r\n");
sw->Close();
}
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->Message, errmsg->StackTrace); }
return;
}
void HelloWorld::WriteLog(String^ msg)
{
try
{
if (Boolean::Parse(this->pluginConfig->readPluginField("/APPCONFIG/LOGEVENTS")))
CFTools::writeModuleLog(msg, LogFilePath);
}
catch (Exception^) {}
}
void HelloWorld::CF_pluginInit()
{
try
{
LoadSettings();
WriteLog("CF_pluginInit");
this->CF_Event_powerModeChanged += gcnew Microsoft::Win32::PowerModeChangedEventHandler(this, &HelloWorld::HelloWorld_CF_Event_powerModeChanged);
this->KeyDown += gcnew KeyEventHandler(this, &HelloWorld::HelloWorld_KeyDown);
}
catch(Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::CF_localskinsetup()
{
WriteLog("CF_localskinsetup");
try
{
this->CF_clearControls();
String^ path = String::Concat(PluginPathSkins, this->currentSkin);
this->CF_initSkin(String::Concat(path, "\\skin.xml"));
this->CF_loadImages(String::Concat(path, "\\HelloWorld_off.png"), String::Concat(path, "\\HelloWorld_down.png"));
ScalePlugin();
this->CF_createLabel("LBLHEADER");
this->CF_updateText("LBLHEADER", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/LBLHEADER"));
this->CF_createLabel("LBLTEXT");
this->CF_updateText("LBLTEXT", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/LBLTEXT1"));
this->CF_createButton("BTN1", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/BTN1"), gcnew MouseEventHandler(this, &HelloWorld::BTN1_Click));
this->CF_createButton("BTN2", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/BTN2"), gcnew MouseEventHandler(this, &HelloWorld::BTN2_Click));
this->CF_createButton("BTN3", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/BTN3"), gcnew MouseEventHandler(this, &HelloWorld::BTN3_Click));
this->CF_createButton("BTN4", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/BTN4"), gcnew MouseEventHandler(this, &HelloWorld::BTN4_Click));
this->CF_createButton("BTN5", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/BTN5"), gcnew MouseEventHandler(this, &HelloWorld::BTN5_Click));
this->CF_createButton("BTN6", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/BTN6"), gcnew MouseEventHandler(this, &HelloWorld::BTN6_Click));
}
catch(Exception^ errmsg)
{
CFTools::writeError(errmsg->ToString());
}
}
void HelloWorld::CF_pluginClose()
{
WriteLog("CF_pluginClose");
delete(this);
}
void HelloWorld::CF_pluginShow()
{
WriteLog("CF_pluginShow");
this->Visible = true;
}
void HelloWorld::CF_pluginUpdateLanguageSkin(String^ lang, String^ skin)
{
WriteLog("CF_pluginUpdateLanguageSkin");
this->language = lang;
if (File::Exists(String::Concat(PluginPathLanguages, language, ".xml")))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile));
configxml->SelectSingleNode("/APPCONFIG/APPLANG")->InnerText = System::Web::HttpUtility::HtmlEncode(language);
configxml->Save(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile));
}
if (Directory::Exists(String::Concat(PluginPathSkins, skin)))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData),"\\Centrafuse\\",PluginPath, ConfigurationFile));
configxml->SelectSingleNode("/APPCONFIG/SKIN")->InnerText = System::Web::HttpUtility::HtmlEncode(skin);
configxml->Save(String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile));
}
LoadSettings();
}
DialogResult HelloWorld::CF_pluginShowSetup()
{
WriteLog("CF_pluginShowSetup");
Windows::Forms::DialogResult returnvalue = Windows::Forms::DialogResult::Cancel;
try
{
Setup^ setup = gcnew Setup();
setup->MainForm = this->MainForm;
setup->setupSection();
returnvalue = setup->ShowDialog();
if(returnvalue == Windows::Forms::DialogResult::OK)
{
LoadSettings();
}
setup->Close();
setup = nullptr;
}
catch(Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
return returnvalue;
}
void HelloWorld::CF_pluginPause()
{
WriteLog("CF_pluginPause");
}
void HelloWorld::CF_pluginResume()
{
WriteLog("CF_pluginResume");
}
void HelloWorld::CF_pluginCommand(String^ command, String^ param1, String^ param2)
{
WriteLog(String::Concat("HelloWorld: CF_pluginCommand: ", command, " ", param1, ", ", param2));
}
String^ HelloWorld::CF_pluginData(String^ command, String^ param)
{
WriteLog(String::Concat("HelloWorld: CF_pluginData: " + command + " " + param));
String^ returnValue = "";
return returnValue;
}
void HelloWorld::LoadSettings()
{
String^ configfilepath = String::Concat(Environment::GetFolderPath(Environment::SpecialFolder::LocalApplicationData), "\\Centrafuse\\", PluginPath, ConfigurationFile);
this->CF_loadConfig(configfilepath);
WriteLog("startup");
WriteLog("Loaded settings");
if (this->CF_getConfigSetting(CF_ConfigSettings::Skin)->Trim()->ToUpper() != this->pluginConfig->readPluginField("/APPCONFIG/SKIN")->Trim()->ToUpper())
{
if (Directory::Exists(String::Concat(PluginPathSkins, this->CF_getConfigSetting(CF_ConfigSettings::Skin))))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(configfilepath);
configxml->SelectSingleNode("/APPCONFIG/SKIN")->InnerText = System::Web::HttpUtility::HtmlEncode(this->CF_getConfigSetting(CF_ConfigSettings::Skin));
configxml->Save(configfilepath);
}
else if (!Directory::Exists(String::Concat(PluginPathSkins, this->pluginConfig->readPluginField("/APPCONFIG/SKIN"))))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(configfilepath);
configxml->SelectSingleNode("/APPCONFIG/SKIN")->InnerText = System::Web::HttpUtility::HtmlEncode("Onyx WS Night");
configxml->Save(configfilepath);
}
this->CF_loadConfig(configfilepath);
}
else if (!Directory::Exists(String::Concat(PluginPathSkins, this->pluginConfig->readPluginField("/APPCONFIG/SKIN"))))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(configfilepath);
configxml->SelectSingleNode("/APPCONFIG/SKIN")->InnerText = System::Web::HttpUtility::HtmlEncode("Onyx WS Night");
configxml->Save(configfilepath);
this->CF_loadConfig(configfilepath);
}
this->currentSkin = this->pluginConfig->readPluginField("/APPCONFIG/SKIN");
if (this->CF_getConfigSetting(CF_ConfigSettings::Language)->Trim()->ToUpper() != this->pluginConfig->readPluginField("/APPCONFIG/APPLANG")->Trim()->ToUpper())
{
if (File::Exists(String::Concat(PluginPathLanguages, this->CF_getConfigSetting(CF_ConfigSettings::Language), ".xml")))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(configfilepath);
configxml->SelectSingleNode("/APPCONFIG/APPLANG")->InnerText = System::Web::HttpUtility::HtmlEncode(this->CF_getConfigSetting(CF_ConfigSettings::Language));
configxml->Save(configfilepath);
}
else if (!File::Exists(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml")))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(configfilepath);
configxml->SelectSingleNode("/APPCONFIG/APPLANG")->InnerText = System::Web::HttpUtility::HtmlEncode("English");
configxml->Save(configfilepath);
}
this->CF_loadConfig(configfilepath);
}
else if (!File::Exists(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml")))
{
XmlDocument^ configxml = gcnew XmlDocument();
configxml->Load(configfilepath);
configxml->SelectSingleNode("/APPCONFIG/APPLANG")->InnerText = System::Web::HttpUtility::HtmlEncode("English");
configxml->Save(configfilepath);
this->CF_loadConfig(configfilepath);
}
this->CF_loadLang(String::Concat(PluginPathLanguages, this->pluginConfig->readPluginField("/APPCONFIG/APPLANG"), ".xml"));
this->CF_pluginDisplayName = TranslateText("DISPLAYNAME");
this->CF_localskinsetup();
}
String^ HelloWorld::TranslateText(String^ text)
{
String^ langread = this->pluginLang->readPluginField(String::Concat(LanguageSection, text));
if(langread == "")
return text;
else
return langread->Replace("\\n", "\n");
}
void HelloWorld::ScalePlugin()
{
WriteLog("ScalePlugin");
try
{
this->Bounds.X = ( ( Int32::Parse( this->CF_getConfigSetting( CF_ConfigSettings::Width ) ) -
( ( int ) ( Int32::Parse( this->pluginSkinReader->readPluginField( String::Concat(screenpath, "/WIDTH") ) )* this->pluginSkinReader->skinWidthRatio) ) )/
2 ) + Int32::Parse( this->CF_getConfigSetting( CF_ConfigSettings::XPosition ) ) +
Screen::AllScreens[ this->pluginDisplay - 1 ]->Bounds.X;
this->Bounds.Y = ( ( Int32::Parse( this->CF_getConfigSetting( CF_ConfigSettings::Height ) ) -
( ( int )
( Int32::Parse( this->pluginSkinReader->readPluginField( String::Concat(screenpath, "/HEIGHT") ) )* this->pluginSkinReader->skinHeightRatio ) ) )/2 ) +
Int32::Parse( this->CF_getConfigSetting( CF_ConfigSettings::YPosition ) ) +
Screen::AllScreens[ this->pluginDisplay - 1 ]->Bounds.Y;
this->Bounds.Width = ( ( int ) ( Int32::Parse( this->pluginSkinReader->readPluginField( String::Concat(screenpath, "/WIDTH") ) )* this->pluginSkinReader->skinWidthRatio ) );
this->Bounds.Height = ( ( int ) ( Int32::Parse( this->pluginSkinReader->readPluginField( String::Concat(screenpath, "/HEIGHT") ) )* this->pluginSkinReader->skinHeightRatio ) );
}
catch(Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::BTN1_Click(Object^ sender, MouseEventArgs^ e)
{
WriteLog("BTN1 clicked.");
try
{
this->CF_updateText("LBLTEXT", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/LBLTEXT1"));
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::BTN2_Click(Object^ sender, MouseEventArgs^ e)
{
WriteLog("BTN2 clicked.");
try
{
this->CF_updateText("LBLTEXT", this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/LBLTEXT2"));
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::BTN3_Click(Object^ sender, MouseEventArgs^ e)
{
WriteLog("BTN3 clicked.");
try
{
String^ song = "";
song = CF_systemGetText(CF_TextItems::CurrentTitle);
this->CF_updateText("LBLTEXT", song);
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::BTN4_Click(Object^ sender, MouseEventArgs^ e)
{
WriteLog("BTN4 clicked.");
try
{
this->CF_systemDisplayDialog(CF_Dialogs::OkBox, "This is an OK box");
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::BTN5_Click(Object^ sender, MouseEventArgs^ e)
{
WriteLog("BTN5 clicked.");
try
{
this->CF_systemCommand(CF_Actions::SHOWINFO, "Status Info", "AUTOHIDE");
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::BTN6_Click(Object^ sender, MouseEventArgs^ e)
{
WriteLog("BTN6 clicked.");
try
{
Object^ tempobject;
String^ resultvalue, ^resulttext;
if (this->CF_systemDisplayDialog(CF_Dialogs::OSK, this->pluginLang->readPluginField("/APPLANG/HELLOWORLD/ENTERTEXT"), "", nullptr, resultvalue, resulttext, tempobject, nullptr, true, true, true, true, false, false, 1) == System::Windows::Forms::DialogResult::OK)
{
this->CF_updateText("LBLTEXT", resultvalue);
}
}
catch (Exception^ errmsg) { CFTools::writeError(errmsg->ToString()); }
}
void HelloWorld::HelloWorld_CF_Event_powerModeChanged(Object^ sender, Microsoft::Win32::PowerModeChangedEventArgs^ e)
{
}
void HelloWorld::HelloWorld_KeyDown(Object^ sender, KeyEventArgs^ e)
{
e->Handled = true;
if(e->KeyCode == Keys::Left)
{
}
else if(e->KeyCode == Keys::Right)
{
}
}
}