예제 #1
0
        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 bool MatchesCriteria(BaseItem item, string value, bool unwatchedOnly, int rating, int ratingFactor)
 {
     return(item.Name != null &&
            item.Name.ToLower().Contains(value) &&
            (!unwatchedOnly ||
             (item is Media && (item as Media).PlaybackStatus.PlayCount == 0)) &&
            (rating < 0 || (ratingFactor * Ratings.Level(item.OfficialRating)) <= (ratingFactor * rating)));
 }
예제 #3
0
 public bool Allowed(BaseItem item)
 {
     if (this.Enabled && item != null)
     {
         //Logger.ReportInfo("Checking parental status on " + item.Name + " " + item.ParentalRating + " " + this.MaxAllowed.ToString());
         return(Ratings.Level(item.ParentalRating) <= this.MaxAllowed);
     }
     else
     {
         return(true);
     }
 }
        public int Search(string searchValue, bool includeSubs, bool unwatchedOnly, int rating, int ratingFactor)
        {
            if (searchValue == null)
            {
                searchValue = "";
            }
            var searchText = (searchValue != "" ? "Items containing: '" + searchValue + "' " : "All Items ")
                             + (unwatchedOnly ? "Unwatched and " : "and ") + "Rated " + Ratings.ToString(rating)
                             + (ratingFactor > 0 ? " and below..." : " and above...");

            Async.Queue("Search", () =>
            {
                Application.CurrentInstance.ProgressBox(string.Format("Searching {0} for {1} ", Name == "Default" ? "Library" : Name, searchText));
                searchValue = searchValue.ToLower();
                IEnumerable <BaseItem> results = includeSubs ?
                                                 this.folder.RecursiveChildren.Distinct(i => i.Id).Where(i => MatchesCriteria(i, searchValue, unwatchedOnly, rating, ratingFactor)).ToList() :
                                                 this.folder.Children.Distinct(i => i.Id).Where(i => MatchesCriteria(i, searchValue, unwatchedOnly, rating, ratingFactor)).ToList();

                Application.CurrentInstance.ShowMessage = false;

                if (results.Any())
                {
                    Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ => Application.CurrentInstance.Navigate(ItemFactory.Instance.Create(new SearchResultFolder(GroupResults(results.ToList()))
                    {
                        Name = this.Name + " - Search Results (" + searchValue + (unwatchedOnly ? "/unwatched" : "")
                               + (rating > 0 ? "/" + Ratings.ToString(rating) + (ratingFactor > 0 ? "-" : "+") : "") + ")"
                    })));
                }
                else
                {
                    Application.CurrentInstance.Information.AddInformationString("No Search Results Found");
                }
            });

            return(0);
        }
예제 #5
0
        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;
        }
예제 #6
0
        public int Compare(BaseItem x, BaseItem y)
        {
            int compare = 0;

            switch (order)
            {
            case SortOrder.None:
                return(-1);

            case SortOrder.Date:
                compare = -x.DateCreated.CompareTo(y.DateCreated);
                break;

            case SortOrder.Year:

                var xProductionYear = x.PremierDate != DateTime.MinValue ? x.PremierDate : new DateTime(Convert.ToInt16(x.ProductionYear ?? 1900), 1, 1);
                var yProductionYear = y.PremierDate != DateTime.MinValue ? y.PremierDate : new DateTime(Convert.ToInt16(y.ProductionYear ?? 1900), 1, 1);

                //Logging.Logger.ReportInfo("=========== x.PremierDate: {0} y.PremierDate: {1}", x.PremierDate, y.PremierDate);
                var orderFactor = Config.Instance.YearSortAsc ? -1 : 1;
                compare = orderFactor * yProductionYear.CompareTo(xProductionYear);     //this will reverse the order if that option is set
                break;

            case SortOrder.Rating:

                compare = Ratings.Level(x.OfficialRating).CompareTo(Ratings.Level(y.OfficialRating));
                break;

            case SortOrder.CriticRating:
                // we want a descending sort
                var firstCritic  = y.CriticRating ?? 0;
                var secondCritic = x.CriticRating ?? 0;
                compare = firstCritic.CompareTo(secondCritic);
                break;

            case SortOrder.UserRating:
                // we want a descending sort
                var firstUser  = y.ImdbRating ?? 0;
                var secondUser = x.ImdbRating ?? 0;
                compare = firstUser.CompareTo(secondUser);
                break;

            case SortOrder.Runtime:
                var xRuntime = x is IShow ? (x as IShow).RunningTime : null;
                var yRuntime = y is IShow ? (y as IShow).RunningTime : null;

                xRuntime = xRuntime ?? int.MaxValue;
                yRuntime = yRuntime ?? int.MaxValue;

                compare = xRuntime.Value.CompareTo(yRuntime.Value);
                break;

            case SortOrder.Unwatched:

                compare = ExtractUnwatchedCount(y).CompareTo(ExtractUnwatchedCount(x));
                break;

            case SortOrder.Custom:

                Logging.Logger.ReportVerbose("Sorting on custom field " + propertyName);
                var yProp = y.GetType().GetProperty(propertyName);
                var xProp = x.GetType().GetProperty(propertyName);
                if (yProp == null || xProp == null)
                {
                    break;
                }
                var yVal = yProp.GetValue(y, null);
                var xVal = xProp.GetValue(x, null);
                if (yVal == null && xVal == null)
                {
                    break;
                }
                if (yVal == null)
                {
                    return(1);
                }
                if (xVal == null)
                {
                    return(-1);
                }
                Logging.Logger.ReportVerbose("Value x: " + xVal + " Value y: " + yVal);
                compare = String.Compare(xVal.ToString(), yVal.ToString(), compareCulture);
                break;

            default:
                compare = 0;
                break;
            }

            if (compare == 0)
            {
                var name1 = x.SortName ?? x.Name ?? "";
                var name2 = y.SortName ?? y.Name ?? "";

                if (Config.Instance.EnableAlphanumericSorting)
                {
                    compare = AlphaNumericCompare(name1, name2, compareCulture);
                }
                else
                {
                    compare = String.Compare(name1, name2, compareCulture);
                }
            }

            return(compare);
        }
예제 #7
0
 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();
     }
 }
예제 #8
0
        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.");
        }