// Entry point for the app
        public void Init()
        {
            Config.IsFirstRun = false;
            Logger.ReportInfo("Emby (version " + AppVersion + ") Starting up.");
            Logger.ReportInfo("Startup parameters: "+ Config.StartupParms);
            //let's put some useful info in here for diagnostics
            if (!Config.AutoValidate)
                Logger.ReportWarning("*** AutoValidate is OFF.");
            try
            {
                Updater = new Updater(this);

                //Check to see if this is the first time this version is run
                string currentVersion = Kernel.Instance.Version.ToString();
                if (Config.MBVersion != currentVersion)
                {
                    //first time with this version - run routine
                    Logger.ReportInfo("First run for version " + currentVersion);
                    bool okToRun = FirstRunForVersion(currentVersion);
                    //and update
                    Config.MBVersion = currentVersion;
                    if (!okToRun)
                    {
                        Logger.ReportInfo("Closing MB to allow new version migration...");
                        this.Close();
                    }
                }
                ShowNowPlaying = IsPlaying || IsExternalWmcApplicationPlaying;

                // setup image to use in external splash screen
                string splashFilename = Path.Combine(ApplicationPaths.CommonConfigPath, "extsplash.jpg");
                ExtSplashBmp = File.Exists(splashFilename) ? new System.Drawing.Bitmap(splashFilename) : new System.Drawing.Bitmap(Resources.extsplash);

                // setup image to use in login splash screen
                splashFilename = Path.Combine(ApplicationPaths.CommonConfigPath, "loginsplash.png");
                LogonSplashImage = File.Exists(splashFilename) ? new Image("file://"+splashFilename) : new Image("resx://MediaBrowser/MediaBrowser.Resources/mblogo1000");

                _popoutMessageTimer.Tick += _popoutMessageTimerTick;

                MediaCenterEnvironment.AudioMixer.PropertyChanged += AudioMixerPropertyChanged;
                VolumePct = (int)(MediaCenterEnvironment.AudioMixer.Volume / 655.35);

                Login();
            }
            catch (Exception e)
            {
                Application.MediaCenterEnvironment.Dialog(CurrentInstance.StringData("CriticalErrorDial") + e + " " + e.StackTrace, CurrentInstance.StringData("CriticalErrorCapDial"), DialogButtons.Ok, 60, true);
                Application.ApplicationContext.CloseApplication();
            }
        }
        public void LaunchEntryPoint(string entryPointPath)
        {
            this.entryPointPath = entryPointPath;

            if (IsInEntryPoint)
            {
                //add in a fake breadcrumb so they will show properly
                session.AddBreadcrumb("DIRECTENTRY");
            }

            if (this.EntryPointPath.ToLower() == ConfigEntryPointVal) //specialized case for config page
            {
                OpenConfiguration(true);
            }
            else
            {
                try
                {
                    this.RootFolderModel = (FolderModel)ItemFactory.Instance.Create(EntryPointResolver.EntryPoint(this.EntryPointPath));

                    WebSocket = new ApiWebSocket(new WebSocket4NetClientWebSocket());
                    WebSocket.Connect(Kernel.ApiClient.ServerHostName, Kernel.ServerInfo.WebSocketPortNumber, Kernel.ApiClient.ClientType, Kernel.ApiClient.DeviceId);
                    WebSocket.LibraryChanged += LibraryChanged;
                    WebSocket.BrowseCommand += BrowseRequest;
                    WebSocket.PlayCommand += PlayRequest;
                    WebSocket.PlaystateCommand += PlayStateRequest;
                    WebSocket.SystemCommand += SystemCommand;
                  
                    Updater = new Updater(this);
                    if (Kernel.CurrentUser.Dto.Configuration.IsAdministrator) // don't show these prompts to non-admins
                    {
                        // We check config here instead of in the Updater class because the Config class 
                        // CANNOT be instantiated outside of the application thread.
                        if (Config.EnableUpdates && !RunningOnExtender)
                        {
                            Async.Queue(Async.STARTUP_QUEUE, CheckForSystemUpdate, 10000);
                        }

                        // Let the user know if the server needs to be restarted
                        // Put it on the same thread as the update checks so it will be behind them
                        Async.Queue(Async.STARTUP_QUEUE, () =>
                                                             {
                                                                 if (Kernel.ServerInfo.HasPendingRestart)
                                                                 {
                                                                     if (Kernel.ServerInfo.CanSelfRestart)
                                                                     {
                                                                         if (YesNoBox("The MB Server needs to re-start to apply an update.  Restart now?") == "Y")
                                                                         {
                                                                             Kernel.ApiClient.PerformPendingRestart();
                                                                             MessageBox("Your server is being re-started.  MB Classic will now exit so you can re load it.");
                                                                             Close();
                                                                         }
                                                                     }
                                                                     else
                                                                     {
                                                                        MessageBox("Your server needs to be re-started to apply an update.  You must re-start it from the server machine.");
                                                                     }
                                                                 }
                                                             },35000);
                        
                    }

                    Navigate(this.RootFolderModel);
                }
                catch (Exception ex)
                {
                    Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(CurrentInstance.StringData("EntryPointErrorDial") + this.EntryPointPath + ". " + ex.ToString() + " " + ex.StackTrace.ToString(), CurrentInstance.StringData("EntryPointErrorCapDial"), DialogButtons.Ok, 30, true);
                    Close();
                }
            }
        }
        // Entry point for the app
        public void GoToMenu()
        {
            Logger.ReportInfo("Media Browser (version " + AppVersion + ") Starting up.");
            try
            {
                if (Config.IsFirstRun)
                {
                    OpenConfiguration(false);
                    MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                    ev.Dialog(CurrentInstance.StringData("FirstTimeDial"), CurrentInstance.StringData("FirstTimeCapDial"), DialogButtons.Ok, 60, true);
                }
                else
                {
                    //if the service is currently re-building our library - warn them
                    if (Kernel.Instance.ServiceConfigData.ForceRebuildInProgress)
                    {
                        MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                        ev.Dialog(CurrentInstance.StringData("ForcedRebuildDial"), CurrentInstance.StringData("ForcedRebuildCapDial"), DialogButtons.Ok, 15, true);
                        session.Close();
                    }
                    //Check to see if this is the first time this version is run
                    string currentVersion = Kernel.Instance.Version.ToString();
                    if (Config.MBVersion != currentVersion)
                    {
                        //first time with this version - run routine
                        Logger.ReportInfo("First run for version " + currentVersion);
                        bool okToRun = FirstRunForVersion(currentVersion);
                        //and update
                        Config.MBVersion = currentVersion;
                        if (!okToRun)
                        {
                            Logger.ReportInfo("Closing MB to allow new version migration...");
                            this.Close();
                        }
                    }
                    //if the service refresh failed - notify them
                    if (Kernel.Instance.ServiceConfigData.RefreshFailed)
                    {
                        MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                        ev.Dialog(CurrentInstance.StringData("RefreshFailedDial"), CurrentInstance.StringData("RefreshFailedCapDial"), DialogButtons.Ok, 15, true);

                    }
                    // We check config here instead of in the Updater class because the Config class
                    // CANNOT be instantiated outside of the application thread.
                    if (Config.EnableUpdates)
                    {
                        Updater update = new Updater(this);

                        Async.Queue(Async.STARTUP_QUEUE, () =>
                        {
                            update.CheckForUpdate();
                        }, 40000);
                        Async.Queue(Async.STARTUP_QUEUE, () =>
                        {
                            PluginUpdatesAvailable = update.PluginUpdatesAvailable();
                        }, 60000);
                    }

                    // set npv visibility according to current state
                    if (MediaCenterEnvironment.MediaExperience != null && MediaCenterEnvironment.MediaExperience.Transport != null)
                    {
                        ShowNowPlaying = MediaCenterEnvironment.MediaExperience.Transport.PlayState == Microsoft.MediaCenter.PlayState.Playing;
                    }

                    // setup image to use in external splash screen
                    string splashFilename = Path.Combine(Path.Combine(ApplicationPaths.AppIBNPath,"General"),"splash.png");
                    if (File.Exists(splashFilename))
                    {
                        ExtSplashBmp = new System.Drawing.Bitmap(splashFilename);
                    }
                    else
                    {
                        ExtSplashBmp = new System.Drawing.Bitmap(Resources.mblogo1000);
                    }

                    // we need to validate the library so that changes in the RAL will get picked up without having to navigate
                    if (Config.AutoValidate)
                    {
                        Async.Queue("Startup Library Validator", () =>
                        {
                            using (new Profiler("Startup Validation"))
                            {
                                Kernel.Instance.MajorActivity = true;
                                RootFolder.RefreshMetadata();

                                //These validations have been moved to the recent list builds since they are needed there anyway

                                //foreach (Folder folder in RootFolder.RecursiveFolders)
                                //{
                                //    folder.ValidateChildren();
                                //}
                                //foreach (BaseItem item in RootFolder.RecursiveChildren)
                                //{
                                //    //refresh new items
                                //    if ((DateTime.Now - item.DateModified).TotalDays < 2)
                                //        item.RefreshMetadata();
                                //}
                                ////finally - we need to invalidate the recent lists to pick up any new items we just found
                                //foreach (Item item in RootFolderModel.Children)
                                //{
                                //    (item as FolderModel).QuickListItems = null; //force to re-load
                                //}
                                Kernel.Instance.MajorActivity = false;
                            }
                        });
                    }
                    //Launch into our entrypoint
                    LaunchEntryPoint(EntryPointResolver.EntryPointPath);
                }
            }
            catch (Exception e)
            {
                Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(CurrentInstance.StringData("CriticalErrorDial") + e.ToString() + " " + e.StackTrace.ToString(), CurrentInstance.StringData("CriticalErrorCapDial"), DialogButtons.Ok, 60, true);
                Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication();
            }
        }
        // Entry point for the app
        public void Init()
        {
            Config.IsFirstRun = false;
            Logger.ReportInfo("Media Browser (version " + AppVersion + ") Starting up.");
            Logger.ReportInfo("Startup parameters: "+ Config.StartupParms);
            Logger.ReportInfo("Server version: "+ Kernel.ServerInfo.Version);
            //let's put some useful info in here for diagnostics
            if (!Config.AutoValidate)
                Logger.ReportWarning("*** AutoValidate is OFF.");
            //Need to track who is still using us
            Helper.Ping("http://www.mb3admin.com/admin/service/registration/ping?feature=MBClassic&ver=" + Kernel.Instance.VersionStr + "&mac=" + Helper.GetMACAddress());
            try
            {
                Updater = new Updater(this);

                //Check to see if this is the first time this version is run
                string currentVersion = Kernel.Instance.Version.ToString();
                if (Config.MBVersion != currentVersion)
                {
                    //first time with this version - run routine
                    Logger.ReportInfo("First run for version " + currentVersion);
                    bool okToRun = FirstRunForVersion(currentVersion);
                    //and update
                    Config.MBVersion = currentVersion;
                    if (!okToRun)
                    {
                        Logger.ReportInfo("Closing MB to allow new version migration...");
                        this.Close();
                    }
                }
                ShowNowPlaying = IsPlaying || IsExternalWmcApplicationPlaying;

                // setup image to use in external splash screen
                string splashFilename = Path.Combine(ApplicationPaths.CommonConfigPath, "extsplash.jpg");
                ExtSplashBmp = File.Exists(splashFilename) ? new System.Drawing.Bitmap(splashFilename) : new System.Drawing.Bitmap(Resources.mblogo1000);

                // setup image to use in login splash screen
                splashFilename = Path.Combine(ApplicationPaths.CommonConfigPath, "loginsplash.png");
                LogonSplashImage = File.Exists(splashFilename) ? new Image("file://"+splashFilename) : new Image("resx://MediaBrowser/MediaBrowser.Resources/mblogo1000");

                IntroController = new IntrosPlaybackController();

                Login();
            }
            catch (Exception e)
            {
                AddInHost.Current.MediaCenterEnvironment.Dialog(CurrentInstance.StringData("CriticalErrorDial") + e + " " + e.StackTrace, CurrentInstance.StringData("CriticalErrorCapDial"), DialogButtons.Ok, 60, true);
                AddInHost.Current.ApplicationContext.CloseApplication();
            }
        }
        // Entry point for the app
        public void GoToMenu()
        {
            try
            {
                if (Config.IsFirstRun)
                {
                    OpenConfiguration(false);
                    MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                    ev.Dialog("As this is the first time you have run Media Browser please setup the inital configuration", "Configure", DialogButtons.Ok, 60, true);
                }
                else
                {
                    // We check config here instead of in the Updater class because the Config class
                    // CANNOT be instantiated outside of the application thread.
                    if (Config.EnableUpdates)
                    {
                        Updater update = new Updater(this);
                        Async.Queue(update.checkUpdate);
                    }

                    Async.Queue(() =>
                    {
                        using (new Profiler("Full Library Refresh"))
                        {
                            try
                            {
                                FullRefresh(this.RootFolder);
                            }
                            catch (Exception ex)
                            {
                                Logger.ReportException("Failed to refresh library! ", ex);
                                Debug.Assert(false, "Full refresh thread should never crash!");
                            }
                        }
                    });

                    BaseItem initial = this.RootFolder;
                    OpenFolderPage((MediaBrowser.Library.FolderModel)ItemFactory.Instance.Create(initial));
                }
            }
            catch (Exception e)
            {
                Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog("Media Browser encountered a critical error and had to shut down: " + e.ToString() + " " + e.StackTrace.ToString(), "Critical Error", DialogButtons.Ok, 60, true);
                Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication();
            }
        }
Exemple #6
0
        // Entry point for the app
        public void GoToMenu()
        {
            Logger.ReportInfo("Media Browser (version " + AppVersion + ") Starting up.");
            //let's put some useful info in here for diagnostics
            if (!Config.AutoValidate)
                Logger.ReportWarning("*** AutoValidate is OFF.");
            if (Config.ParentalControlEnabled)
                Logger.ReportInfo("*** Parental Controls are ON with a max rating of "+Config.ParentalMaxAllowedString+".  Block Unrated is "+Config.ParentalBlockUnrated+" and Hide Content is "+Config.HideParentalDisAllowed);
            Logger.ReportInfo("*** Internet Providers are "+(Config.AllowInternetMetadataProviders ? "ON." : "OFF."));
            if (Config.AllowInternetMetadataProviders) Logger.ReportInfo("*** Save Locally is "+(Config.SaveLocalMeta ? "ON." : "OFF."));
            Logger.ReportInfo("*** Theme in use is: " + Config.ViewTheme);
            // Now let's put a diagnostic ping in here for the beta cycle so we can see how much testing we're getting
            //string info = "IP=" + Config.AllowInternetMetadataProviders + " EXTP=" + Config.ExternalPlayers.Count + " EXT=" + RunningOnExtender;
            //Helper.Ping("http://www.ebrsoft.com/software/mb/plugins/ping.php?product=MBBeta&ver=" + Kernel.Instance.VersionStr + "&mac=" + Helper.GetMACAddress() + "&key=" + info);
            try
            {
                if (Config.IsFirstRun)
                {
                    OpenConfiguration(false);
                    MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                    ev.Dialog(CurrentInstance.StringData("FirstTimeDial"), CurrentInstance.StringData("FirstTimeCapDial"), DialogButtons.Ok, 60, true);
                }
                else
                {
                    //if the service is currently re-building our library - warn them
                    if (Kernel.Instance.ServiceConfigData.ForceRebuildInProgress)
                    {
                        MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                        ev.Dialog(CurrentInstance.StringData("ForcedRebuildDial"), CurrentInstance.StringData("ForcedRebuildCapDial"), DialogButtons.Ok, 15, true);
                        session.Close();
                    }
                    //Check to see if this is the first time this version is run
                    string currentVersion = Kernel.Instance.Version.ToString();
                    if (Config.MBVersion != currentVersion)
                    {
                        //first time with this version - run routine
                        Logger.ReportInfo("First run for version " + currentVersion);
                        bool okToRun = FirstRunForVersion(currentVersion);
                        //and update
                        Config.MBVersion = currentVersion;
                        if (!okToRun)
                        {
                            Logger.ReportInfo("Closing MB to allow new version migration...");
                            this.Close();
                        }
                    }
                    //if the service refresh failed - notify them
                    if (Kernel.Instance.ServiceConfigData.RefreshFailed)
                    {
                        MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
                        ev.Dialog(CurrentInstance.StringData("RefreshFailedDial"), CurrentInstance.StringData("RefreshFailedCapDial"), DialogButtons.Ok, 15, true);

                    }
                    // We check config here instead of in the Updater class because the Config class
                    // CANNOT be instantiated outside of the application thread.
                    if (Config.EnableUpdates)
                    {
                        Updater update = new Updater(this);

                        Async.Queue(Async.STARTUP_QUEUE, () =>
                        {
                            update.CheckForUpdate();
                        }, 40000);
                        Async.Queue(Async.STARTUP_QUEUE, () =>
                        {
                            PluginUpdatesAvailable = update.PluginUpdatesAvailable();
                        }, 60000);
                    }

                    ShowNowPlaying = IsPlaying || IsExternalWmcApplicationPlaying;

                    // setup image to use in external splash screen
                    string splashFilename = Path.Combine(Path.Combine(ApplicationPaths.AppIBNPath,"General"),"splash.png");
                    if (File.Exists(splashFilename))
                    {
                        ExtSplashBmp = new System.Drawing.Bitmap(splashFilename);
                    }
                    else
                    {
                        ExtSplashBmp = new System.Drawing.Bitmap(Resources.mblogo1000);
                    }

                    //validate that everything at the root level is actually a folder - the UI will blow chow with items
                    foreach (var item in RootFolder.Children)
                    {
                        if (!(item is Folder))
                        {
                            string msg = "W A R N I N G: Item " + item.Name + " is resolving to a " + item.GetType().Name + ". All root level items must be folders.\n  Check that this item isn't being mistaken because it is a folder with only a couple items and you have the playlist functionality enabled.";
                            Logger.ReportError(msg);
                            DisplayDialog(msg, "Invalid Root Item");
                        }
                    }

                    // we need to validate the library so that changes in the RAL will get picked up without having to navigate
                    if (Config.AutoValidate)
                    {
                        Async.Queue("Startup Library Validator", () =>
                        {
                            using (new Profiler("Startup Validation"))
                            {
                                Kernel.Instance.MajorActivity = true;
                                RootFolder.RefreshMetadata();

                                //These validations have been moved to the recent list builds since they are needed there anyway

                                //foreach (Folder folder in RootFolder.RecursiveFolders)
                                //{
                                //    folder.ValidateChildren();
                                //}
                                //foreach (BaseItem item in RootFolder.RecursiveChildren)
                                //{
                                //    //refresh new items
                                //    if ((DateTime.Now - item.DateModified).TotalDays < 2)
                                //        item.RefreshMetadata();
                                //}
                                ////finally - we need to invalidate the recent lists to pick up any new items we just found
                                //foreach (Item item in RootFolderModel.Children)
                                //{
                                //    (item as FolderModel).QuickListItems = null; //force to re-load
                                //}
                                Kernel.Instance.MajorActivity = false;
                            }
                        });
                    }
                    //Launch into our entrypoint
                    LaunchEntryPoint(EntryPointResolver.EntryPointPath);
                }
            }
            catch (Exception e)
            {
                Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment.Dialog(CurrentInstance.StringData("CriticalErrorDial") + e.ToString() + " " + e.StackTrace.ToString(), CurrentInstance.StringData("CriticalErrorCapDial"), DialogButtons.Ok, 60, true);
                Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication();
            }
        }