Example #1
0
    // Use this for initialization
    void Start()
    {
        translation = TranslationLoader.getInstance().getTranslation();

        P1NAME = PlayerPrefs.GetString("P1NAME");
        P2NAME = PlayerPrefs.GetString("P2NAME");

        P1NameLabel.text = P1NAME;
        P2NameLabel.text = P2NAME;
        P1score          = Options.beginningPoints;
        P2score          = Options.beginningPoints;

        P1ScoreField.text = P1score.ToString();
        P2ScoreField.text = P2score.ToString();

        distributeScores();
        round = 0;

        if (PlayerPrefs.GetInt("turn") == 1)
        {
            p1turn        = true;
            TurnText.text = (P1NAME + this.translation.scenes.Game.Turn);
        }
        else
        {
            p1turn        = false;
            TurnText.text = (P2NAME + this.translation.scenes.Game.Turn);
        }
    }
        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();
        }
Example #3
0
 public void ExitModelContext(NavigationContext oldContext, NavigationContext newContext)
 {
     _messageQueue.Shutdown();
     if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
     {
         if (newDllsDownloaded)
         {
             Log.Info("Reloading SiteUtil Dlls at runtime.");
             DownloadManager.Instance.StopAll();
             // now reload the appdomain
             OnlineVideoSettings.Reload();
             TranslationLoader.SetTranslationsToSingleton();
             GC.Collect();
             GC.WaitForFullGCComplete();
         }
         if (newDataSaved || newDllsDownloaded)
         {
             SystemMessage msg = new SystemMessage(OnlineVideosMessaging.MessageType.SitesUpdated);
             msg.MessageData[OnlineVideosMessaging.UPDATE_RESULT] = newDllsDownloaded ? new bool?(true) : new bool?();
             ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, msg);
         }
     }
     newDataSaved      = false;
     newDllsDownloaded = false;
 }
Example #4
0
        private void LoadLanguage(string langName)
        {
            var tlLang = Path.Combine(Paths.TranslationsRoot, langName);

            if (!Directory.Exists(tlLang))
            {
                Logger.LogWarning($"No translations for language \"{langName}\" was found!");
                return;
            }

            TranslationLoader?.UnloadCurrentTranslation();

            var iniFile = LoadLanguageConfig(tlLang);

            TranslationLoader =
                iniFile == null ? new BasicTranslationLoader() : GetLoader(iniFile["Info"]["Loader"].Value);

            Logger.LogInfo($"Selecting language for {TranslationLoader}");
            TranslationLoader.SelectLanguage(langName, tlLang, iniFile);

            foreach (var mgr in managers)
            {
                mgr.LoadLanguage();
            }

            CurrentSelectedLanguage = langName;

            I2TranslationDump.Initialize();
        }
 public static TranslationLoader getInstance()
 {
     if (instance != null)
     {
         return(instance);
     }
     instance = new TranslationLoader();
     return(instance);
 }
 void OnlineVideosMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
 {
     if (message.ChannelName == OnlineVideosMessaging.CHANNEL)
     {
         OnlineVideosMessaging.MessageType messageType = (OnlineVideosMessaging.MessageType)message.MessageType;
         switch (messageType)
         {
         case OnlineVideosMessaging.MessageType.SitesUpdated:
             bool?updateResult = (bool?)message.MessageData[OnlineVideosMessaging.UPDATE_RESULT];
             if (updateResult != false)
             {
                 if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
                 {
                     if (updateResult == true)
                     {
                         Log.Info("Reloading SiteUtil Dlls at runtime.");
                         DownloadManager.Instance.StopAll();
                         // now reload the appdomain
                         OnlineVideoSettings.Reload();
                         TranslationLoader.SetTranslationsToSingleton();
                         GC.Collect();
                         GC.WaitForFullGCComplete();
                     }
                 }
                 OnlineVideoSettings.Instance.BuildSiteUtilsList();
                 RebuildSitesList();
             }
             else
             {
                 // called when entering OnlineVideos first time (after sites have been updated)
                 if (!OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
                 {
                     // show the busy indicator, because loading site dlls takes some seconds
                     ServiceRegistration.Get <ISuperLayerManager>().ShowBusyScreen();
                     try
                     {
                         OnlineVideoSettings.Instance.BuildSiteUtilsList();
                         RebuildSitesList();
                     }
                     catch (Exception ex)
                     {
                         Log.Error(ex);
                     }
                     finally
                     {
                         ServiceRegistration.Get <ISuperLayerManager>().HideBusyScreen();
                     }
                 }
             }
             break;
         }
     }
 }
        internal static void ReloadDownloadedDlls()
        {
            Log.Instance.Info("Reloading SiteUtil Dlls at runtime.");
            bool stopPlayback = (MediaPortal.Player.g_Player.Player != null && MediaPortal.Player.g_Player.Player.GetType().Assembly == typeof(GUISiteUpdater).Assembly);
            bool stopDownload = DownloadManager.Instance.Count > 0;

            if (stopDownload || stopPlayback)
            {
                GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                if (dlg != null)
                {
                    dlg.Reset();
                    dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                    dlg.SetLine(1, Translation.Instance.NewDllDownloaded);
                    int i = 1;
                    if (stopDownload)
                    {
                        dlg.SetLine(i++, Translation.Instance.DownloadsWillBeAborted);
                    }
                    if (stopPlayback)
                    {
                        dlg.SetLine(i++, Translation.Instance.PlaybackWillBeStopped);
                    }
                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                }
            }
            // stop playback if an OnlineVideos video is playing
            if (stopPlayback)
            {
                MediaPortal.Player.g_Player.Stop();
            }
            // stop downloads
            DownloadManager.Instance.StopAll();
            // reset the GuiOnlineVideos instance and stop the LatestVideos Thread
            GUIOnlineVideos ovGuiInstance = (GUIOnlineVideos)GUIWindowManager.GetWindow(GUIOnlineVideos.WindowId);

            if (ovGuiInstance != null)
            {
                ovGuiInstance.ResetToFirstView();
                ovGuiInstance.LatestVideosManager.Stop();
            }
            // now reload the appdomain
            OnlineVideoSettings.Reload();
            TranslationLoader.SetTranslationsToSingleton();
            OnlineVideoSettings.Instance.BuildSiteUtilsList();
            GC.Collect();
            GC.WaitForFullGCComplete();
            // restart the LatestVideos thread
            ovGuiInstance.LatestVideosManager.Start();
        }
Example #8
0
 public bool Convert(object value, Type targetType, object parameter, CultureInfo culture, out object result)
 {
     if (string.IsNullOrEmpty(value as string))
     {
         result = LocalizationHelper.Translate("[OnlineVideos.All]");
     }
     else
     {
         if (parameter == null)
         {
             result = TranslationLoader.GetLocalizedLanguageName(value as string);
         }
         else
         {
             result = value as string;
         }
     }
     return(true);
 }
Example #9
0
 void VisibilityChanged(object sender, EventArgs e)
 {
     ImageDownloader.StopDownload = true;
     if (Visibility == System.Windows.Visibility.Hidden)
     {
         if (changedXml)
         {
             (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.ItemsSource = null;
             if (newDlls)
             {
                 OnlineVideoSettings.Reload();
                 TranslationLoader.SetTranslationsToSingleton();
                 GC.Collect();
                 GC.WaitForFullGCComplete();
                 newDlls = false;
             }
             OnlineVideoSettings.Instance.BuildSiteUtilsList();
             (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.ItemsSource = ViewModels.SiteList.GetSitesView(App.Current.MainWindow as OnlineVideosMainWindow);
             changedXml = false;
         }
         (App.Current.MainWindow as OnlineVideosMainWindow).SelectAndFocusItem(rememberedIndex);
     }
     else if (Visibility == System.Windows.Visibility.Visible)
     {
         // deselect any site on the main view but remember the index
         rememberedIndex = (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.SelectedIndex;
         (App.Current.MainWindow as OnlineVideosMainWindow).listViewMain.SelectedIndex = -1;
         var sitesView = ViewModels.GlobalSiteList.GetSitesView(App.Current.MainWindow as OnlineVideosMainWindow);
         lvSites.ItemsSource = sitesView;
         ImageDownloader.GetImages <ViewModels.GlobalSite>(sitesView.SourceCollection as IList <ViewModels.GlobalSite>);
         GridViewSort.ApplySort(lvSites.Items, "LastUpdated", lvSites, FindColumnHeader(lvSites, "LastUpdated"), ListSortDirection.Descending);
         // focus the first item when this list becomes visible /use dispatcher to let WPF create the items first)
         Dispatcher.BeginInvoke((Action)(() =>
         {
             var itemToFocus = lvSites.ItemContainerGenerator.ContainerFromIndex(0) as ListViewItem;
             if (itemToFocus != null)
             {
                 itemToFocus.Focus();
             }
         }), DispatcherPriority.Loaded);
     }
 }
        public OnlineVideosWorkflowModel()
        {
            SitesList = new ItemsList();

            OnlineVideosAppDomain.UseSeperateDomain = true;

            ServiceRegistration.Get <ISettingsManager>().Load <Configuration.Settings>().SetValuesToApi();
            string ovConfigPath = ServiceRegistration.Get <IPathManager>().GetPath(string.Format(@"<CONFIG>\{0}\", Environment.UserName));
            string ovDataPath   = ServiceRegistration.Get <IPathManager>().GetPath(@"<DATA>\OnlineVideos");

            OnlineVideoSettings.Instance.Logger    = new LogDelegator();
            OnlineVideoSettings.Instance.UserStore = new Configuration.UserSiteSettingsStore();

            OnlineVideoSettings.Instance.DllsDir   = System.IO.Path.Combine(ovDataPath, "SiteUtils");
            OnlineVideoSettings.Instance.ThumbsDir = System.IO.Path.Combine(ovDataPath, "Thumbs");
            OnlineVideoSettings.Instance.ConfigDir = ovConfigPath;

            OnlineVideoSettings.Instance.AddSupportedVideoExtensions(new List <string>()
            {
                ".asf", ".asx", ".flv", ".m4v", ".mov", ".mkv", ".mp4", ".wmv"
            });

            // clear cache files that might be left over from an application crash
            MPUrlSourceFilter.Downloader.ClearDownloadCache();
            // load translation strings in other AppDomain, so SiteUtils can use localized language strings
            TranslationLoader.LoadTranslations(ServiceRegistration.Get <ILocalization>().CurrentCulture.TwoLetterISOLanguageName, System.IO.Path.Combine(System.IO.Path.GetDirectoryName(GetType().Assembly.Location), "Language"), "en", "strings_{0}.xml");
            // 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();

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

            // create a message queue where we listen to changes to the sites
            _messageQueue = new AsynchronousMessageQueue(this, new string[] { OnlineVideosMessaging.CHANNEL });
            _messageQueue.MessageReceived += new MessageReceivedHandler(OnlineVideosMessageReceived);

            // listen to changes of configuration settings
            _settingsWatcher = new SettingsChangeWatcher <Configuration.Settings>();
            _settingsWatcher.SettingsChanged += OnlineVideosSettingsChanged;
        }
        private static void PeriodicSitesUpdate()
        {
            // don't run when any of the OV workflow models are currently active
            var workflowManager = ServiceRegistration.Get <IWorkflowManager>();

            if (workflowManager.IsModelContainedInNavigationStack(Guids.WorkFlowModelOV) ||
                workflowManager.IsModelContainedInNavigationStack(Guids.WorkFlowModelSiteManagement) ||
                workflowManager.IsModelContainedInNavigationStack(Guids.WorkFlowModelSiteUpdate))
            {
                return;
            }

            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 now
            if (Sites.Updater.VersionCompatible &&
                ovMP2Settings.AutomaticUpdate &&
                ovMP2Settings.LastAutomaticUpdate.AddHours(ovMP2Settings.AutomaticUpdateInterval) < DateTime.Now)
            {
                var updateResult = Sites.Updater.UpdateSites();
                ovMP2Settings.LastAutomaticUpdate = DateTime.Now;
                settingsManager.Save(ovMP2Settings);

                if (updateResult == true)
                {
                    Log.Info("Reloading SiteUtil Dlls at runtime.");
                    DownloadManager.Instance.StopAll();
                    OnlineVideoSettings.Reload();
                    TranslationLoader.SetTranslationsToSingleton();
                    GC.Collect();
                    GC.WaitForFullGCComplete();
                }
                if (updateResult != false)
                {
                    OnlineVideoSettings.Instance.BuildSiteUtilsList();
                    ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, new SystemMessage(OnlineVideosMessaging.MessageType.RebuildSites));
                }
            }
        }
 public void ExitModelContext(NavigationContext oldContext, NavigationContext newContext)
 {
     _messageQueue.Shutdown();
     if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt())
     {
         if (newDllsDownloaded)
         {
             Log.Info("Reloading SiteUtil Dlls at runtime.");
             DownloadManager.Instance.StopAll();
             OnlineVideoSettings.Reload();
             TranslationLoader.SetTranslationsToSingleton();
             GC.Collect();
             GC.WaitForFullGCComplete();
         }
         if (newDataSaved || newDllsDownloaded)
         {
             OnlineVideoSettings.Instance.BuildSiteUtilsList();
             ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, new SystemMessage(OnlineVideosMessaging.MessageType.RebuildSites));
         }
     }
     newDataSaved      = false;
     newDllsDownloaded = false;
 }
Example #13
0
        static Translator()
        {
            try
            {
                Lang  = GUILocalizeStrings.GetCultureName(GUILocalizeStrings.CurrentLanguage());
                _info = DateTimeFormatInfo.GetInstance(CultureInfo.CurrentUICulture);
            }
            catch (Exception)
            {
                Lang  = CultureInfo.CurrentUICulture.Name;
                _info = DateTimeFormatInfo.GetInstance(CultureInfo.CurrentUICulture);
            }

            Log.Instance.Info("Using language '{0}'", Lang);

            string _path = Config.GetSubFolder(Config.Dir.Language, "OnlineVideos");

            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }

            Lang = TranslationLoader.LoadTranslations(Lang, _path);
        }
        ItemsList CreateLanguagesList()
        {
            var items   = new ItemsList();
            var allItem = new ListItem(Consts.KEY_NAME, "[OnlineVideos.All]");

            allItem.AdditionalProperties[Constants.KEY_VALUE] = null;
            items.Add(allItem);
            foreach (var lang in Sites.Updater.OnlineSites.Select(s => s.Language != null ? s.Language : "--").Distinct().Select(s => new { Code = s, Name = TranslationLoader.GetLocalizedLanguageName(s) }).OrderBy(s => s.Name))
            {
                var langItem = new ListItem(Consts.KEY_NAME, lang.Name);
                langItem.AdditionalProperties[Constants.KEY_VALUE] = lang.Code;
                items.Add(langItem);
            }
            return(items);
        }
Example #15
0
 void Start()
 {
     this.loader = TranslationLoader.getInstance();
     this.loadTextFields();
 }