Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApplicationHost" /> class.
        /// </summary>
        public ApplicationHost(ApplicationPaths applicationPaths,
                               ILogManager logManager,
                               StartupOptions options,
                               IFileSystem fileSystem,
                               IPowerManagement powerManagement,
                               string releaseAssetFilename,
                               IEnvironmentInfo environmentInfo,
                               ISystemEvents systemEvents,
                               INetworkManager networkManager)
        {
            // hack alert, until common can target .net core
            BaseExtensions.CryptographyProvider = CryptographyProvider;

            XmlSerializer = new MyXmlSerializer(fileSystem, logManager.GetLogger("XmlSerializer"));

            NetworkManager      = networkManager;
            EnvironmentInfo     = environmentInfo;
            SystemEvents        = systemEvents;
            MemoryStreamFactory = new MemoryStreamProvider();

            FailedAssemblies = new List <string>();

            ApplicationPaths  = applicationPaths;
            LogManager        = logManager;
            FileSystemManager = fileSystem;

            ConfigurationManager = GetConfigurationManager();

            // Initialize this early in case the -v command line option is used
            Logger = LogManager.GetLogger("App");

            StartupOptions       = options;
            ReleaseAssetFilename = releaseAssetFilename;
            PowerManagement      = powerManagement;

            SetBaseExceptionMessage();
        }
Exemplo n.º 2
0
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            bool createdNew;

            _singleInstanceMutex = new Mutex(true, @"Local\" + typeof(Program).Assembly.GetName().Name, out createdNew);

            if (!createdNew)
            {
                _singleInstanceMutex = null;
                return;
            }

            var appPath = Process.GetCurrentProcess().MainModule.FileName;

            // Look for the existence of an update archive
            var appPaths = new ApplicationPaths(GetProgramDataPath(appPath), appPath);
            var logManager = new NlogManager(appPaths.LogDirectoryPath, "theater");
            logManager.ReloadLogger(LogSeverity.Debug);

            var updateArchive = Path.Combine(appPaths.TempUpdatePath, UpdatePackageName);

            if (File.Exists(updateArchive))
            {
                ReleaseMutex();

                // Update is there - execute update
                try
                {
                    new ApplicationUpdater().UpdateApplication(appPaths, updateArchive,
                        logManager.GetLogger("ApplicationUpdater"));

                    // And just let the app exit so it can update
                    return;
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Error attempting to update application.\n\n{0}\n\n{1}",
                        e.GetType().Name, e.Message));
                }
            }

            _logger = logManager.GetLogger("App");

            bool supportsTransparency;

            try
            {
                 supportsTransparency = NativeWindowMethods.DwmIsCompositionEnabled();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error in DwmIsCompositionEnabled", ex);
                supportsTransparency = true;
            }

            _logger.Info("OS Supports window transparency?: {0}", supportsTransparency);

            try
            {
                _appHost = new ApplicationHost(appPaths, logManager);

                var initTask = _appHost.Init(new Progress<Double>());
                Task.WaitAll(initTask);

                var electronTask = StartElectron(appPaths, supportsTransparency);
                Task.WaitAll(electronTask);

                var electronProcess = electronTask.Result;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                _mainForm = new MainForm(_logger, _appHost.TheaterConfigurationManager, _appHost, electronProcess);
                Application.Run(_mainForm);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error launching application", ex);

                MessageBox.Show("There was an error launching Emby: " + ex.Message);

                // Shutdown the app with an error code
                Environment.Exit(1);
            }
            finally
            {
                ReleaseMutex();
            }
        }