INTERACT FORUM
Windows => Plug-in Development => Topic started by: lucian.jp on October 01, 2009, 12:23:03 pm
-
Hi,
I'm trying to do a little plugin that need to persist the setting. I used Settings.Default, but when restarted Media Center, the setting isn't persisted, the default value is restored. How can I save settings ?
I also noted that using the Notify Track Change and Player state event do not trigger when I close media Center. How can I execute some code when closing the application?
Thanks
-
I've hooked into MC shutdown by overriding Dispose and the WndProc message.
You need to call Save() on your Settings to have them persisted.
void FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Save();
}
protected override void WndProc(ref Message m)
{
const int WM_DESTROY = 0x0002;
// Listen for operating system messages.
switch (m.Msg)
{
// The WM_DESTROY message occurs when the application exits
case WM_DESTROY:
FormClosing(null,null);
break;
}
base.WndProc(ref m);
}
protected override void Dispose(bool disposing)
{
// unhook the upnp stack
if (disposing)
{
FormClosing(null, null);
}
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
You'll also need to manage settings "upgrades", so Settings are migrated if new (minor) versions of MC are installed by the user.
// check for upgrade and migrate user settings
string version = mcRef.GetVersion().Version;
if (!version.Equals(Properties.Settings.Default.LastMCVersion))
{
Trace("First Execution of MC " + version);
Trace("Upgrading User Settings");
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.LastMCVersion = version;
Properties.Settings.Default.Save();
}
-
Thank you very much muchadhesion. It was exactly what I was looking for. Everything works very well now. Teal'c would have given 5 indeeds out of 5.
-
The following post provides a couple more ways catch the MC Close event:
http://yabb.jriver.com/interact/index.php?topic=15760.msg106918#msg106918