private void ddlMetadataCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     var country = ddlMetadataCountry.SelectedItem as RegionInfo;
     if (country != null)
     {
         config.MetadataCountryCode = country.TwoLetterISORegionName;
         //also need to re-init our ratings
         ratings = new Ratings();
         // and the options
         ddlOptionMaxAllowedRating.ItemsSource = ratings.ToStrings();
         ddlOptionMaxAllowedRating.Items.Refresh();
         ddlOptionMaxAllowedRating.SelectedItem = Ratings.ToString(config.MaxParentalLevel);
         //create a set of ratings strings that makes more sense for the folder list
         folderSettings = ratings.ToStrings().Select(r => r != "Any" ? r : "None").ToList();
         ddlFolderRating.ItemsSource = folderSettings;
         ddlFolderRating.Items.Refresh();
         config.Save();
     }
 }
        public void Initialize()
        {
            // initialize internal settings
            //setup timer for auto re-lock
            //setup timer for auto re-lock - must be done on app thread
            if (!Microsoft.MediaCenter.UI.Application.IsApplicationThread)
                Microsoft.MediaCenter.UI.Application.DeferredInvoke(initTimer);
            else
                initTimer(null);

            // init list of folders we've gained access to
            enteredProtectedFolders = new List<Folder>();
            // construct ratings object
            ratings = new Ratings(Config.Instance.ParentalBlockUnrated);

            Logger.ReportInfo("Parental Control Initialized");

            //check to see if this is run with clean or recently created cache
            //string itemCache = Path.Combine(ApplicationPaths.AppCachePath, "items");
            //DateTime recentTime = DateTime.Now.Subtract(DateTime.Now.Subtract(DateTime.Now.AddMinutes(-1)));  //if cache dir created less than a minute ago we must've just done it
            //if (!Directory.Exists(itemCache) || DateTime.Compare(Directory.GetCreationTime(itemCache), recentTime) > 0)
            //{
            //    if (Config.Instance.ParentalBlockUnrated)
            //    {
            //        //blocking unrated content - unlock the library temporarily to allow items to populate their metadata
            //        Logger.ReportInfo("Unlocking Library to allow initial cache population.");
            //        this.Unlocked = true; //can't invoke the timer yet - it may not even be initialized
            //    }
            //}
            return;
        }
        private void Initialize()
        {
            Instance = this;
            Kernel.Init(KernelLoadDirective.ShadowPlugins);
            ratings = new Ratings();
            //Logger.ReportVerbose("======= Kernel intialized. Building window...");
            InitializeComponent();
            pluginList.MouseDoubleClick += pluginList_DoubleClicked;
            PopUpMsg = new PopupMsg(alertText);
            config = Kernel.Instance.ConfigData;
            //put this check here because it will run before the first run of MB and we need it now
            if (config.MBVersion != Kernel.Instance.Version.ToString() && Kernel.Instance.Version.ToString() == "2.3.0.0")
            {
                try
                {
                    config.PluginSources.RemoveAt(config.PluginSources.FindIndex(s => s.ToLower() == "http://www.mediabrowser.tv/plugins/plugin_info.xml"));
                }
                catch
                {
                    //wasn't there - no biggie
                }
                if (config.PluginSources.Find(s => s == "http://www.mediabrowser.tv/plugins/multi/plugin_info.xml") == null)
                {
                    config.PluginSources.Add("http://www.mediabrowser.tv/plugins/multi/plugin_info.xml");
                    Logger.ReportInfo("Plug-in Source migrated to multi-version source");
                }
                //not going to re-set version in case there is something we want to do in MB itself
            }

            //Logger.ReportVerbose("======= Loading combo boxes...");
            LoadComboBoxes();
            lblVersion.Content = lblVersion2.Content = "Version " + Kernel.Instance.VersionStr;

            //we're showing, but disabling the media collection detail panel until the user selects one
            infoPanel.IsEnabled = false;

            // first time the wizard has run
            if (config.InitialFolder != ApplicationPaths.AppInitialDirPath) {
                try {
                    MigrateOldInitialFolder();
                } catch {
                    MessageBox.Show("For some reason we were not able to migrate your old initial path, you are going to have to start from scratch.");
                }
            }

            config.InitialFolder = ApplicationPaths.AppInitialDirPath;
            //Logger.ReportVerbose("======= Refreshing Items...");
            RefreshItems();
            //Logger.ReportVerbose("======= Refreshing Podcasts...");
            RefreshPodcasts();
            //Logger.ReportVerbose("======= Refreshing Ext Players...");
            RefreshPlayers();

            //Logger.ReportVerbose("======= Loading Config Settings...");
            LoadConfigurationSettings();
            //Logger.ReportVerbose("======= Config Settings Loaded.");

            for (char c = 'D'; c <= 'Z'; c++) {
                daemonToolsDrive.Items.Add(c.ToString());
            }

            try {
                daemonToolsDrive.SelectedValue = config.DaemonToolsDrive;
            } catch {
                // someone bodged up the config
            }

            //daemonToolsLocation.Content = config.DaemonToolsLocation; /// old
            daemonToolsLocation.Text = config.DaemonToolsLocation;

            //Logger.ReportVerbose("======= Refreshing Extender Formats...");
            RefreshExtenderFormats();
            //Logger.ReportVerbose("======= Refreshing Display Settings...");
            RefreshDisplaySettings();
            //Logger.ReportVerbose("======= Podcast Details...");
            podcastDetails(false);
            //Logger.ReportVerbose("======= Saving Config...");
            SaveConfig();

            //Logger.ReportVerbose("======= Initializing Plugin Manager...");
            PluginManager.Instance.Init();
            //Logger.ReportVerbose("======= Loading Plugin List...");
            CollectionViewSource src = new CollectionViewSource();
            src.Source = PluginManager.Instance.InstalledPlugins;
            src.GroupDescriptions.Add(new PropertyGroupDescription("PluginClass"));

            pluginList.ItemsSource = src.View;

            //pluginList.Items.Refresh();

            //Logger.ReportVerbose("======= Kicking off plugin update check thread...");
            Async.Queue("Plugin Update Check", () =>
            {
                using (new MediaBrowser.Util.Profiler("Plugin update check"))
                {
                    while (!PluginManager.Instance.PluginsLoaded) { } //wait for plugins to load
                    ForceUpgradeCheck(); //remove incompatable plug-ins
                    if (PluginManager.Instance.UpgradesAvailable())
                        Dispatcher.Invoke(DispatcherPriority.Background, (System.Windows.Forms.MethodInvoker)(() =>
                        {
                            PopUpMsg.DisplayMessage("Some of your plug-ins have upgrades available.");
                        }));
                }
            });

            SupportImprovementNag();

            //Logger.ReportVerbose("======= Kicking off validations thread...");
            Async.Queue("Startup Validations", () =>
            {
                RefreshEntryPoints(false);
                ValidateMBAppDataFolderPermissions();
            });
            //Logger.ReportVerbose("======= Initialize Finised.");
        }