Example #1
0
        public static bool ConnectToServer(CommonConfigData config)
        {
            var connected = false;

            if (config.FindServerAutomatically)
            {
                connected = ConnectAutomatically(config.HttpTimeout);
            }
            else
            {
                //server specified
                connected = ConnectToServer(config.ServerAddress, config.ServerPort, config.HttpTimeout);
                if (!connected)
                {
                    Logger.ReportWarning("Unable to connect to configured server {0}:{1}. Will try automatic detection", config.ServerAddress, config.ServerPort);
                    connected = ConnectAutomatically(config.HttpTimeout);
                }
            }

            if (connected)
            {
                Logger.ReportInfo("====== Connected to server {0}:{1}", ApiClient.ServerHostName, ApiClient.ServerApiPort);
                AvailableUsers = ApiClient.GetAllUsers().ToList();
                config.LastServerMacAddress = ServerInfo.MacAddress;
                config.ServerPort           = ApiClient.ServerApiPort;
                config.Save();
            }

            return(connected);
        }
Example #2
0
        public static void Init(KernelLoadDirective directives)
        {
            CommonConfigData config = null;

            config = CommonConfigData.FromFile(ApplicationPaths.CommonConfigFile);

            Init(directives, config);
        }
        public override void ConfigureUserSettings(CommonConfigData.ExternalPlayer currentConfiguration)
        {
            string iniPath = GetIniFilePath(currentConfiguration);

            if (string.IsNullOrEmpty(iniPath))
            {
                ConfigureUserSettingsIntoRegistry();
            }
            else
            {
                ConfigureUserSettingsIntoINIFile(iniPath);
            }
        }
Example #4
0
        private static MultiLogger GetDefaultLogger(CommonConfigData config)
        {
            var logger = new MultiLogger(config.MinLoggingSeverity);

            if (config.EnableTraceLogging)
            {
                logger.AddLogger(new FileLogger(ApplicationPaths.AppLogPath));
#if (!DEBUG)
                logger.AddLogger(new TraceLogger());
#endif
            }
#if DEBUG
            logger.AddLogger(new TraceLogger());
#endif
            return(logger);
        }
Example #5
0
        public void Migrate300()
        {
            var knownCompatibleDlls = new List <string> {
                "BDScreenSaver.dll",
                "Chocolate.dll",
                "CoverSS.dll",
            };

            var current = new Version(_config != null ? _config.MBVersion : "2.6.2.0");

            if (current < new Version(3, 0, 0))
            {
                //Get our old directory structure
                oldPathMap             = new Dictionary <string, string>();
                oldPathMap["app_data"] = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);

                BuildTree();

                //Move over external players from old config file
                var oldConfig = CommonConfigData.FromFile(Path.Combine(oldPathMap["AppConfigPath"], "MediaBrowserXml.config"));
                if (oldConfig != null && _config != null)
                {
                    _config.ExternalPlayers = oldConfig.ExternalPlayers;
                }

                //And Plugins that work
                //foreach (var dll in knownCompatibleDlls)
                //{
                //    CopyFile(Path.Combine(oldPathMap["AppPluginPath"], dll), Path.Combine(ApplicationPaths.AppPluginPath, dll));
                //}

                //And the Localization folder
                foreach (var file in Directory.GetFiles(oldPathMap["AppLocalizationPath"]))
                {
                    try
                    {
                        CopyFile(file, Path.Combine(ApplicationPaths.AppLocalizationPath, Path.GetFileName(file)));
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error copying file {0} to {1}", e, file, Path.Combine(ApplicationPaths.AppLocalizationPath, Path.GetFileName(file)));
                    }
                }
            }
        }
        private void Initialize()
        {
            Instance = this;
            InitializeComponent();
            Kernel.Init(KernelLoadDirective.ShadowPlugins);
            Logger.ReportVerbose("======= Kernel intialized. Building window...");
            commonConfig = Kernel.Instance.CommonConfigData;
            PopUpMsg     = new PopupMsg(alertText);

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

            //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 = commonConfig.DaemonToolsDrive;
            } catch {
                // someone bodged up the config
            }

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


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

            //Logger.ReportVerbose("======= Initialize Finised.");
        }
Example #7
0
        public static void Init(KernelLoadDirective directives, CommonConfigData config)
        {
            lock (sync) {
                // Its critical to have the logger initialized early so initialization
                //   routines can use the right logger.
                if (Logger.LoggerInstance != null)
                {
                    Logger.LoggerInstance.Dispose();
                }

                Logger.LoggerInstance = GetDefaultLogger(config);

                AppDomain.CurrentDomain.UnhandledException += CrashHandler;

                // Now try and wake the last server we connected to if set
                if (config.WakeServer && !string.IsNullOrEmpty(config.LastServerMacAddress))
                {
                    Helper.WakeMachine(config.LastServerMacAddress);
                }

                var defaultKernel = GetDefaultKernel(config, directives);
                Instance = defaultKernel;
            }
        }
Example #8
0
        public MainWindow()
        {
            // set up assembly resolution hooks, so earlier versions of the plugins resolve properly
            AppDomain.CurrentDomain.AssemblyResolve += Kernel.OnAssemblyResolve;

            InitializeComponent();
            //_serviceConfig = ServiceConfigData.FromFile(ApplicationPaths.ServiceConfigFile);
            Async.Queue("Migration", () =>
            {
                var mbphoto = Path.Combine(ApplicationPaths.AppPluginPath, "mbphoto.classic.dll");
                if (File.Exists(mbphoto))
                {
                    try
                    {
                        File.Delete(mbphoto);
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error deleting old MBPhoto plug-in", e);
                    }
                }

                const string chocolate = @"\windows\ehome\chocolate.dll";
                if (File.Exists(chocolate))
                {
                    try
                    {
                        File.Delete(chocolate);
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error deleting old chocolate plug-in", e);
                    }
                }

                if (File.Exists(ApplicationPaths.CommonConfigFile))
                {
                    _config = CommonConfigData.FromFile(ApplicationPaths.CommonConfigFile);
                }

                if (_config == null) // only do this if a fresh install
                {
                    try
                    {
                        _config = CommonConfigData.FromFile(ApplicationPaths.CommonConfigFile); // create a new one
                        Migrate300();
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Error during migration", e);
                    }
                }
                if (_config != null)
                {
                    // Set install directory
                    _config.MBInstallDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                    _config.Save();
                }
                Dispatcher.Invoke(DispatcherPriority.Background, (System.Windows.Forms.MethodInvoker)(Close));
            });
        }
Example #9
0
        static Kernel GetDefaultKernel(CommonConfigData config, KernelLoadDirective loadDirective)
        {
            var repository = new MB3ApiRepository();
            var localRepo  = GetLocalRepository();

            var kernel = new Kernel()
            {
                PlaybackControllers = new List <BasePlaybackController>(),
                //MetadataProviderFactories = MetadataProviderHelper.DefaultProviders(),
                CommonConfigData = config,
                //ServiceConfigData = ServiceConfigData.FromFile(ApplicationPaths.ServiceConfigFile),
                StringData           = LocalizedStrings.Instance,
                ImageResolvers       = DefaultImageResolvers(false),
                MB3ApiRepository     = repository,
                LocalRepo            = localRepo,
                MediaLocationFactory = new MediaLocationFactory(),
            };

            //Kernel.UseNewSQLRepo = config.UseNewSQLRepo;

            // kernel.StringData.Save(); //save this in case we made mods (no other routine saves this data)
            if (LoadContext == MBLoadContext.Core)
            {
                kernel.PlaybackControllers.Add(new PlaybackController());
            }

            //kernel.EntityResolver = DefaultResolver(kernel.ConfigData);

            //need a blank root in case plug-ins will add virtual items
            kernel.RootFolder = new AggregateFolder {
                Name = "My Media", Id = new Guid("{F6109BAE-CA26-4746-9EBC-1CD233A7B56F}")
            };

            //create our default config panels with localized names
            kernel.AddConfigPanel(kernel.StringData.GetString("GeneralConfig"), "");
            kernel.AddConfigPanel(kernel.StringData.GetString("ViewOptionsConfig"), "");
            kernel.AddConfigPanel(kernel.StringData.GetString("ThemesConfig"), "");
            kernel.AddConfigPanel(kernel.StringData.GetString("PlaybackConfig"), "");

            //kick off log clean up task if needed
            if (config.LastFileCleanup < DateTime.UtcNow.AddDays(-7))
            {
                Async.Queue(Async.ThreadPoolName.LogfileCleanup, () =>
                {
                    Logger.ReportInfo("Running Logfile clean-up...");
                    var minDateModified = DateTime.UtcNow.AddDays(-(config.LogFileRetentionDays));
                    foreach (var source in new DirectoryInfo(ApplicationPaths.AppLogPath).GetFileSystemInfos("*.log")
                             .Where(f => f.LastWriteTimeUtc < minDateModified))
                    {
                        try
                        {
                            source.Delete();
                        }
                        catch (Exception e)
                        {
                            Logger.ReportException("Error deleting log file {0}", e, source.Name);
                        }
                    }

                    config.LastFileCleanup = DateTime.UtcNow;
                    config.Save();
                });

                Async.Queue(Async.ThreadPoolName.ImageCacheCleanup, () => ImageCache.Instance.Clean(DateTime.UtcNow.AddDays(-(Instance.CommonConfigData.CacheFileRetentionDays))));
            }

            return(kernel);
        }
Example #10
0
 public static void Init(CommonConfigData config)
 {
     Init(KernelLoadDirective.None, config);
 }
        private void Initialize()
        {
            Instance = this;
            InitializeComponent();
            Kernel.Init(KernelLoadDirective.ShadowPlugins);
            if (!Kernel.ServerConnected)
            {
                Async.Queue("error", () => MessageBox.Show("Cannot connect to the MB3 server.  Please start it or configure address.", "Cannot find server"));
                // Hide plug-in tab because we can't get to them
                plugins.Visibility = Visibility.Collapsed;
            }
            else
            {
                var user = Kernel.AvailableUsers.OrderBy(u => u.Name).FirstOrDefault();
                Kernel.CurrentUser = new User {
                    Name = user.Name, Id = new Guid(user.Id ?? ""), Dto = user, ParentalAllowed = user.HasPassword
                };
            }
            //Kernel.Instance.LoadUserConfig();
            Kernel.Instance.LoadPlugins();
            Logger.ReportVerbose("======= Kernel intialized. Building window...");
            commonConfig = Kernel.Instance.CommonConfigData;
            pluginList.MouseDoubleClick += pluginList_DoubleClicked;
            PopUpMsg = new PopupMsg(alertText);
            //config = Kernel.Instance.ConfigData;

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

            //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 = commonConfig.DaemonToolsDrive;
            } catch {
                // someone bodged up the config
            }

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


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

            LoadAvailablePlugins();

            //Logger.ReportVerbose("======= Initialize Finised.");
        }
 public virtual void ConfigureUserSettings(CommonConfigData.ExternalPlayer currentConfiguration)
 {
 }
 public override bool CanPlay(IEnumerable <Media> mediaList)
 {
     return(CommonConfigData.CanPlay(ExternalPlayerConfiguration, mediaList));
 }
 public override bool CanPlay(IEnumerable <string> files)
 {
     return(CommonConfigData.CanPlay(ExternalPlayerConfiguration, files));
 }
        private static string GetIniFilePath(CommonConfigData.ExternalPlayer currentConfiguration)
        {
            string directory = Path.GetDirectoryName(currentConfiguration.Command);

            string path = Path.Combine(directory, "mpc-hc.ini");

            if (File.Exists(path))
            {
                return path;
            }

            path = Path.Combine(directory, "mpc-hc64.ini");

            if (File.Exists(path))
            {
                return path;
            }

            return string.Empty;
        }