Beispiel #1
0
 /// <summary>
 /// Initializes the properties and variables for the class.
 /// </summary>
 /// <exception cref="AppNotInstalledException">
 /// Plex is not installed.
 /// </exception>
 /// <exception cref="ServiceNotInstalledException">
 /// The Plex service is not installed.
 /// </exception>
 /// <exception cref="WindowsUserSidNotFound">
 /// The Windows user SID is not found.
 /// </exception>
 private void Initialize(string logPath)
 {
     try
     {
         _server         = new MediaServer(logPath, ServerUpdateMessage);
         _timer          = new Timer(DefaultWaitTime * 1000);
         _timer.Elapsed += OnTimedEvent;
         _timer.Enabled  = false;
     }
     catch (AppNotInstalledException)
     {
         Log.Write(
             "The Plex Media Server is not installed.");
         throw;
     }
     catch (ServiceNotInstalledException)
     {
         Log.Write(
             "The Plex Media Server service is not installed.");
         throw;
     }
     catch (WindowsUserSidNotFound ex)
     {
         Log.Write(ex.Message);
         throw;
     }
     catch (Exception ex)
     {
         Log.Write(ex);
         throw;
     }
 }
        /// <summary>
        /// Initializes the values on the form.
        /// </summary>
        private void Initialize()
        {
            try
            {
                ToBeClosed = false;
                _cts       = new CancellationTokenSource();

                Log.Write("Initializing the timer object.");
                _timer          = new System.Timers.Timer();
                _timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
                _timer.Enabled  = false;
                _timer.Interval = Convert.ToDouble(numSeconds.Value * 1000);

                Log.Write("Initializing the Plex media server object.");
                _server = new MediaServer();

                if (_server == null)
                {
                    Log.Write(
                        "The Plex media server object could not be initialized. Setting the flag to close the application.");
                    ToBeClosed = true;
                    return;
                }

                _server.UpdateMessage += ServerUpdateMessage;

                lblInstalledVersion.Text = _server.CurrentVersion.ToString();
                lblLatestVersion.Text    = _server.LatestVersion.ToString();

                if (_server.LatestVersion > _server.CurrentVersion)
                {
                    btnUpdate.Visible = true;
                    btnCancel.Visible = false;
                    btnExit.Enabled   = true;
                    CheckIfCanUpdate();
                }
                else
                {
                    btnUpdate.Visible = false;
                    btnCancel.Visible = false;
                    btnExit.Enabled   = true;
                    if (_server.GetPlayCount() >= 0)
                    {
                        lblPlayCount.Text = _server.PlayCount.ToString();
                    }
                    else
                    {
                        lblPlayCount.Text = "Unknown";
                    }
                }
            }
            catch (LocalSystem.Msi.MSIException ex)
            {
                MessageBox.Show(
                    $"MSI exception: {ex.Message}",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (AppNotInstalledException ex)
            {
                MessageBox.Show(
                    "The Plex Server application is not installed.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (ServiceNotInstalledException ex)
            {
                MessageBox.Show(
                    "The Plex service is not installed.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (PlexDataFolderNotFoundException ex)
            {
                MessageBox.Show(
                    "The Plex data folder could not be found.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (LocalSystem.WindowsUserSidNotFound ex)
            {
                MessageBox.Show(
                    "The SID for the Plex service user could not be found.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }

            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the values on the form.
        /// </summary>
        private void Initialize()
        {
            try
            {
                Log.Write("Initializing the Plex media server object.");
                server = new MediaServer();

                if (server == null)
                {
                    Log.Write(
                        "The Plex media server object could not be initialized. Setting the flag to close the application.");
                    ToBeClosed = true;
                    return;
                }

                server.UpdateMessage += ServerUpdateMessage;

                lblInstalledVersion.Text = server.CurrentVersion.ToString();
                lblLatestVersion.Text    = server.LatestVersion.ToString();

                if (server.LatestVersion > server.CurrentVersion)
                {
                    btnUpdate.Visible = true;
                    btnCancel.Visible = false;
                    btnExit.Enabled   = true;
                }
                else
                {
                    btnUpdate.Visible = false;
                    btnCancel.Visible = false;
                    btnExit.Enabled   = true;
                }
            }
            catch (LocalSystem.Msi.MSIException ex)
            {
                MessageBox.Show(
                    $"MSI exception: {ex.Message}",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (AppNotInstalledException ex)
            {
                MessageBox.Show(
                    "The Plex Server application is not installed.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (ServiceNotInstalledException ex)
            {
                MessageBox.Show(
                    "The Plex service is not installed.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (PlexDataFolderNotFoundException ex)
            {
                MessageBox.Show(
                    "The Plex data folder could not be found.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
            catch (LocalSystem.WindowsUserSidNotFound ex)
            {
                MessageBox.Show(
                    "The SID for the Plex service user could not be found.",
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }

            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.Message,
                    "Plex Updater Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                Log.Write(ex);
                ToBeClosed = true;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Initializes the properties and variables for the class.
        /// </summary>
        private void Initialize()
        {
            try
            {
                _server         = new MediaServer(true);
                _timer          = new Timer(DefaultWaitTime * 1000);
                _timer.Elapsed += OnTimedEvent;
                _timer.Enabled  = false;
            }
            catch (AppNotInstalledException)
            {
                Log.Write(
                    "The Plex Media Server is not installed.");
                return;
            }
            catch (ServiceNotInstalledException)
            {
                Log.Write(
                    "The Plex Media Server service is not installed.");
                return;
            }
            catch (WindowsUserSidNotFound ex)
            {
                Log.Write(ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return;
            }

            _server.UpdateMessage +=
                new MediaServer.UpdateMessageHandler(ServerUpdateMessage);

            _messageLogFile = _server.GetMessageLogFilePath();
            _isMessageError = (_messageLogFile.Length > 0);

            if (!string.IsNullOrWhiteSpace(_messageLogFile))
            {
                // If the message log file exists, attempt to delete it
                if (File.Exists(_messageLogFile))
                {
                    try
                    {
                        File.Delete(_messageLogFile);
                    }
                    catch (PathTooLongException)
                    {
                        Log.Write(
                            $"The message log file path is too long.{NewLine}Message log path: {_messageLogFile}");

                        _isMessageError = false;
                        _messageLogFile = string.Empty;
                    }
                    catch (IOException)
                    {
                        Log.Write(
                            $"The message log file is in use. The messages won't be written to the log file but the installation log will still be written.{NewLine}Message log path: {_messageLogFile}");

                        _isMessageError = false;
                        _messageLogFile = string.Empty;
                    }
                    catch (NotSupportedException)
                    {
                        Log.Write(
                            $"The message log path is invalid.{NewLine}Message log path: {_messageLogFile}");

                        _isMessageError = false;
                        _messageLogFile = string.Empty;
                    }
                    catch (UnauthorizedAccessException)
                    {
                        Log.Write(
                            $"The message log path cannot be accessed.{NewLine}Message log path: {_messageLogFile}");

                        _isMessageError = false;
                        _messageLogFile = string.Empty;
                    }
                }
            }
        }