private static void InitialSitesUpdateAndLoad()
        {
            // clear cache files that might be left over from an application crash
            MPUrlSourceFilter.Downloader.ClearDownloadCache();

            // load translation strings
            TranslationLoader.LoadTranslations(ServiceRegistration.Get <ILocalization>().CurrentCulture.TwoLetterISOLanguageName,
                                               Path.Combine(Path.GetDirectoryName(typeof(OnlineVideosPlugin).Assembly.Location), "Language"), "en", "strings_{0}.xml");

            // load the xml that holds all configured sites
            OnlineVideoSettings.Instance.LoadSites();

            var settingsManager = ServiceRegistration.Get <ISettingsManager>();
            var ovMP2Settings   = settingsManager.Load <Configuration.Settings>();

            // if the current version is compatible and automatic update is enabled and due, run it before loading the site utils
            if (Sites.Updater.VersionCompatible &&
                ovMP2Settings.AutomaticUpdate &&
                ovMP2Settings.LastAutomaticUpdate.AddHours(ovMP2Settings.AutomaticUpdateInterval) < DateTime.Now)
            {
                Sites.Updater.UpdateSites();
                ovMP2Settings.LastAutomaticUpdate = DateTime.Now;
                settingsManager.Save(ovMP2Settings);

                // delete old cached thumbs (todo : no better place to do this for now, should be configurable)
                ImageDownloader.DeleteOldThumbs(30, r => { return(true); });
            }

            // instantiate and initialize all siteutils
            OnlineVideoSettings.Instance.BuildSiteUtilsList();
        }
예제 #2
0
        void DoInitialization(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
                {
                    Thread.CurrentThread.Name = "OVInit";
                }

                // Get the BackgroundWorker that raised this event.
                BackgroundWorker worker = sender as BackgroundWorker;

                // clear cache files that might be left over from an application crash
                OnlineVideos.MPUrlSourceFilter.Downloader.ClearDownloadCache();

                // Load localized strings and set them to Translation class and GuiProperties
                Translator.TranslateSkin();

                // The default connection limit is 2 in .Net on most platforms! This means downloading two files will block all other WebRequests.
                System.Net.ServicePointManager.DefaultConnectionLimit = 100;

                // The default .Net implementation for URI parsing removes trailing dots, which is not correct
                Helpers.DotNetFrameworkHelper.FixUriTrailingDots();

                // set a GUI Property to the configured menu entry of the plugin so skins can use it
                GUIPropertyManager.SetProperty("#OnlineVideos.HomeScreenName", PluginConfiguration.Instance.BasicHomeScreenName);

                // When AutoUpdate of sites on startup is enabled and the last update was done earlier than configured run AutoUpdate and deletion of old thumbs
                if (PluginConfiguration.Instance.updateOnStart == true &&
                    PluginConfiguration.Instance.lastFirstRun.AddHours(PluginConfiguration.Instance.updatePeriod) < DateTime.Now &&
                    OnlineVideos.Sites.Updater.VersionCompatible)
                {
                    OnlineVideos.Sites.Updater.UpdateSites();
                    ImageDownloader.DeleteOldThumbs(PluginConfiguration.Instance.ThumbsAge, r => { return(true); });
                    PluginConfiguration.Instance.lastFirstRun = DateTime.Now;
                }

                // instantiates and initializes all siteutils
                OnlineVideoSettings.Instance.BuildSiteUtilsList();
                PluginConfiguration.Instance.BuildAutomaticSitesGroups();

                LatestVideosManager = new LatestVideosManager();
                LatestVideosManager.Start();
            }
            catch (Exception ex)
            {
                Log.Instance.Error("Error during initialization: {0}", ex.ToString());
            }
        }
예제 #3
0
 void DoSubsequentLoad()
 {
     if (PreviousWindowId != OnlineVideos.MediaPortal1.Player.GUIOnlineVideoFullscreen.WINDOW_FULLSCREEN_ONLINEVIDEO &&
         PluginConfiguration.Instance.updateOnStart != false &&
         PluginConfiguration.Instance.lastFirstRun.AddHours(PluginConfiguration.Instance.updatePeriod) < DateTime.Now)
     {
         bool?doUpdate = PluginConfiguration.Instance.updateOnStart;
         if (!PluginConfiguration.Instance.updateOnStart.HasValue && !preventDialogOnLoad)
         {
             GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
             if (dlg != null)
             {
                 dlg.Reset();
                 dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                 dlg.SetLine(1, Translation.Instance.PerformAutomaticUpdate);
                 dlg.SetLine(2, Translation.Instance.UpdateAllYourSites);
                 dlg.DoModal(GUIWindowManager.ActiveWindow);
                 doUpdate = dlg.IsConfirmed;
             }
         }
         PluginConfiguration.Instance.lastFirstRun = DateTime.Now;
         if (doUpdate == true || PluginConfiguration.Instance.ThumbsAge >= 0)
         {
             GUIDialogProgress dlgPrgrs = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
             if (dlgPrgrs != null)
             {
                 dlgPrgrs.Reset();
                 dlgPrgrs.DisplayProgressBar = true;
                 dlgPrgrs.ShowWaitCursor     = false;
                 dlgPrgrs.DisableCancel(true);
                 dlgPrgrs.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                 dlgPrgrs.StartModal(GUIWindowManager.ActiveWindow);
             }
             else
             {
                 GUIWaitCursor.Init(); GUIWaitCursor.Show();
             }
             new System.Threading.Thread(delegate()
             {
                 if (doUpdate == true)
                 {
                     if (dlgPrgrs != null)
                     {
                         dlgPrgrs.SetHeading(string.Format("{0} - {1}", PluginConfiguration.Instance.BasicHomeScreenName, Translation.Instance.AutomaticUpdate));
                     }
                     var onlineVersion = Sites.Updater.VersionOnline;
                     if (OnlineVideos.Sites.Updater.VersionCompatible)
                     {
                         bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites((m, p) =>
                         {
                             if (dlgPrgrs != null)
                             {
                                 if (!string.IsNullOrEmpty(m))
                                 {
                                     dlgPrgrs.SetLine(1, m);
                                 }
                                 if (p != null)
                                 {
                                     dlgPrgrs.SetPercentage(p.Value);
                                 }
                                 return(dlgPrgrs.ShouldRenderLayer());
                             }
                             else
                             {
                                 return(true);
                             }
                         }
                                                                                    );
                         if (updateResult == true && OnlineVideoSettings.Instance.SiteUtilsList.Count > 0)
                         {
                             GUISiteUpdater.ReloadDownloadedDlls();
                         }
                         else if (updateResult == null || OnlineVideoSettings.Instance.SiteUtilsList.Count > 0)
                         {
                             OnlineVideoSettings.Instance.BuildSiteUtilsList();
                         }
                         if (updateResult != false)
                         {
                             PluginConfiguration.Instance.BuildAutomaticSitesGroups();
                             SiteImageExistenceCache.ClearCache();
                         }
                     }
                     else
                     {
                         // inform the user that autoupdate is disabled due to outdated version!
                         dlgPrgrs.SetLine(1, Translation.Instance.AutomaticUpdateDisabled);
                         dlgPrgrs.SetLine(2, onlineVersion != null ? string.Format(Translation.Instance.LatestVersionRequired, onlineVersion) : "Check your Internet Connection!");
                         Thread.Sleep(5000);
                         dlgPrgrs.SetLine(2, string.Empty);
                     }
                 }
                 if (PluginConfiguration.Instance.ThumbsAge >= 0)
                 {
                     if (dlgPrgrs != null)
                     {
                         dlgPrgrs.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                         dlgPrgrs.SetLine(1, Translation.Instance.DeletingOldThumbs);
                         dlgPrgrs.Percentage = 0;
                     }
                     ImageDownloader.DeleteOldThumbs(PluginConfiguration.Instance.ThumbsAge, r =>
                     {
                         if (dlgPrgrs != null)
                         {
                             dlgPrgrs.Percentage = r;
                         }
                         return(dlgPrgrs != null ? dlgPrgrs.ShouldRenderLayer() : true);
                     });
                 }
                 if (dlgPrgrs != null)
                 {
                     dlgPrgrs.Percentage = 100; dlgPrgrs.SetLine(1, Translation.Instance.Done); dlgPrgrs.Close();
                 }
                 else
                 {
                     GUIWaitCursor.Hide();
                 }
                 GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) =>
                 {
                     DoPageLoad();
                     return(0);
                 }, 0, 0, null);
             })
             {
                 Name = "OVLoad", IsBackground = true
             }.Start();
             return;
         }
     }
     DoPageLoad();
 }