Пример #1
0
        // Set up the BRB manager and analyze all files in the BRB directory
        private void AnalyzeBRBFiles()
        {
            // BRBManager.BRBEpisodes should be an empty list right now, even if brbepisodes.json already exists, since it shouldn't get loaded if Initial Setup is triggered

            List <string> paths = new List <string>(Directory.GetFiles(txtBRBDirectory.Text));
            BRBEpisode    episode;

            foreach (string path in paths)
            {
                episode = new BRBEpisode(Path.GetFileName(path), false); // Create BRB episode, but do not treat as a new episode
                if (episode.Duration.Ticks == 0)                         // Make sure the app understands all BRB files
                {
                    MessageBox.Show("Could not register the BRB file \"" + Path.GetFileName(path) + "\". Make sure it is a valid video file (in a format compatible with VLC) " +
                                    "and the application has read permissions on it. If it is not supposed to be a BRB episode, please move it out of the BRB directory.",
                                    "Registering BRB failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    BRBManager.BRBEpisodes.Add(episode);
                }
            }

            BRBManager.BRBEpisodes.Sort();
            BRBManager.RefreshAvailableList();

            // Try saving BRB data to disk. If this fails, do not proceed
            if (!BRBManager.SaveEpisodes())
            {
                MessageBox.Show("Could not write to file brbepisodes.json. BRB data could not be created; the application will now exit.\r\n\r\n" +
                                "Please make sure the application has write permissions in its directory and try again.",
                                "Writing BRB data to disk failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Program.ExitApplication();
            }
        }
Пример #2
0
 public static void OnInitialSetupCompleted()
 {
     if (Config.GenerateAndSaveStandardConfig())
     {
         if (BRBManager.LoadEpisodes())
         {
             AppState = ApplicationState.Idle;
             MainForm = new FormMain();
             MainForm.Show();
         }
         else
         {
             MessageBox.Show("Could not properly load file brbepisodes.json. The application cannot retrieve the provided data about BRB episodes and will exit.\r\n\r\n"
                             + "If you think you made a mistake during Initial Setup, try reinstalling the application. Otherwise, please contact MetagonTL for assistance.",
                             "Failed loading BRB episodes and playback data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             ExitApplication();
         }
     }
     else
     {
         MessageBox.Show("Could not write to file config.json. Initial Setup could not be completed.\r\n\r\nEnsure the application has write permissions in its directory and try again.",
                         "No write access in application directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
         ExitApplication();
     }
 }
Пример #3
0
 // While BRB playback is active, update all displays concerning the break or the currently playing BRB
 private void tmrUpdateBRBPlaybackData_Tick(object sender, EventArgs e)
 {
     if (Program.PlayerForm.PlayerState == BRBPlayerState.Playback)
     {
         TimeSpan playbackPosition = new TimeSpan((long)(Program.PlayerForm.VLCPlayer.Position * Program.PlayerForm.VLCPlayer.Length * TimeSpan.TicksPerMillisecond));
         dispRunningTime.Text = BRBManager.TimeSpanToMMSS(playbackPosition) + " / " + durationOfCurrentBRBFormatted;
         if (!Program.PlayerForm.Paused)
         {
             trkScrubber.Value = Math.Min(Math.Max((int)(playbackPosition.TotalSeconds * 30), trkScrubber.Minimum), trkScrubber.Maximum);
         }
     }
     if (Program.PlayerForm.PlayerState != BRBPlayerState.ErrorOccurred)
     {
         TimeSpan remainingBreakTime = Program.PlayerForm.GetRemainingBreakTime();
         dispRemainingBreakTime.Text = BRBManager.TimeSpanToMMSS(remainingBreakTime);
         if (remainingBreakTime.TotalSeconds < 120)
         {
             dispRemainingBreakTime.ForeColor = Color.Red;
         }
         else
         {
             dispRemainingBreakTime.ForeColor = SystemColors.ControlText;
         }
     }
 }
Пример #4
0
        public bool Rename(string newFilename, bool renameOnDisk)
        {
            // Failsafe so BRB episodes do not get into the system twice, but this should never trigger
            if (File.Exists(Path.Combine(Config.BRBDirectory, newFilename)))
            {
                return(false);
            }
            foreach (BRBEpisode ep in BRBManager.BRBEpisodes)
            {
                if (ep.Filename == newFilename)
                {
                    return(false);
                }
            }

            try
            {
                if (renameOnDisk)
                {
                    File.Move(Path.Combine(Config.BRBDirectory, Filename), Path.Combine(Config.BRBDirectory, newFilename));
                }
                Filename = newFilename;
                BRBManager.BRBEpisodes.Sort();
                BRBManager.RefreshAvailableList();

                return(true);
            }
            catch (IOException)
            {
                return(false);
            }
        }
Пример #5
0
        // Look for new BRB files that are yet unknown to the manager's list
        private void CheckAndAddNewFiles()
        {
            List <string> knownFilenames = BRBManager.GetBRBFilenameList();

            foreach (string diskPath in Directory.GetFiles(Config.BRBDirectory))
            {
                if (!knownFilenames.Contains(Path.GetFileName(diskPath)))
                {
                    if (MessageBox.Show("A new file has been found in the BRB directory. Would you like to add \"" + Path.GetFileName(diskPath) + "\" to the BRB list now?\r\n\r\n" +
                                        "Note: The new BRB will automatically receive " + Config.AutoGuaranteedPlaysForNewBRBs +
                                        " \"Guaranteed\" and " + Config.AutoPriorityPlaysForNewBRBs + " \"Priority\" plays.\r\n\r\n" +
                                        "If this is a renamed or updated BRB file, please select \"No\" and use the \"Replace with new version\" button in \"Manage BRBs\".",
                                        "New BRB found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (!BRBManager.RegisterNewBRB(Path.GetFileName(diskPath)))
                        {
                            MessageBox.Show("Could not register the new BRB file. Make sure it is a valid video file (in a format compatible with VLC) " +
                                            "and the application has read permissions on it.",
                                            "Adding new BRB failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else if (!BRBManager‌.SaveEpisodes())
                        {
                            MessageBox.Show("Could not write to file brbepisodes.json. The new BRB is available for playback, but its existence could not be saved to disk.\r\n\r\n" +
                                            "It is recommended you investigate this problem as soon as possible, since playback data is difficult to replace if lost.",
                                            "Writing BRB data to disk failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }

            UpdateBRBData();
        }
Пример #6
0
        private void btnAddBRB_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lstAllBRBs.SelectedItems)
            {
                bool alreadyAdded = false;
                foreach (ListViewItem playlistItem in lstBRBPlaylist.Items)
                {
                    if (item.SubItems[1].Text == playlistItem.Text)
                    {
                        alreadyAdded = true;
                    }
                }

                if (!alreadyAdded || MessageBox.Show("The BRB \"" + item.SubItems[1].Text + "\" is already present on the playlist. Would you like to add it again?",
                                                     "Please confirm: Playing a BRB video multiple times", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
                    == DialogResult.Yes)
                {
                    lstBRBPlaylist.Items.Add(new ListViewItem(new string[] { item.SubItems[1].Text, item.SubItems[2].Text, item.SubItems[5].Text, "Manual" }));

                    if (Program.AppState == ApplicationState.PlayerActive)
                    {
                        Program.PlayerForm.AppendBRB(BRBManager.GetEpisode(item.SubItems[1].Text));
                    }
                }
            }

            UpdateBRBPlaylistRunningTime();
        }
Пример #7
0
        public bool AppendHobbVLCEpisode()
        {
            BRBEpisode episode = BRBManager.GetRandomBRBEpisode(Config.HobbVLCIgnoreMaxDurationAfterTries == -1 || Program.PlayerForm.HobbVLCsTriggered < Config.HobbVLCIgnoreMaxDurationAfterTries ?
                                                                new TimeSpan(Config.HobbVLCMaxDuration * TimeSpan.TicksPerMinute + TimeSpan.TicksPerMinute / 2) : (TimeSpan?)null,
                                                                true, Program.PlayerForm.BRBPlaylist);

            if (episode == null)
            {
                episode = BRBManager.GetRandomBRBEpisode(Config.HobbVLCIgnoreMaxDurationAfterTries == -1 || Program.PlayerForm.HobbVLCsTriggered < Config.HobbVLCIgnoreMaxDurationAfterTries ?
                                                         new TimeSpan(Config.HobbVLCMaxDuration * TimeSpan.TicksPerMinute + TimeSpan.TicksPerMinute / 2) : (TimeSpan?)null,
                                                         false, Program.PlayerForm.BRBPlaylist);
            }
            if (episode == null)
            {
                episode = BRBManager.GetRandomBRBEpisode(Config.HobbVLCIgnoreMaxDurationAfterTries == -1 || Program.PlayerForm.HobbVLCsTriggered < Config.HobbVLCIgnoreMaxDurationAfterTries ?
                                                         new TimeSpan(Config.HobbVLCMaxDuration * TimeSpan.TicksPerMinute + TimeSpan.TicksPerMinute / 2) : (TimeSpan?)null,
                                                         false);
            }

            if (episode != null)
            {
                ListViewItem item = new ListViewItem(new string[] { episode.Filename, BRBManager.TimeSpanToMMSS(episode.Duration),
                                                                    episode.GetWeight().ToString(), "hobbVLC" });
                lstBRBPlaylist.Items.Add(item);
                UpdateBRBPlaylistRunningTime();
                Program.PlayerForm.AppendBRB(episode);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #8
0
        public FormUpdateBRB(BRBEpisode episode)
        {
            InitializeComponent();

            txtOldFilename.Text = episode.Filename;
            episodeToUpdate     = episode;

            List <string> availableFilenames = new List <string>();
            BRBEpisode    dirEpisode;

            foreach (string path in Directory.GetFiles(Config.BRBDirectory))
            {
                // Only allow files that aren't yet in the system or at least haven't been played yet, since their data will be overwritten if they are in the system
                dirEpisode = BRBManager.GetEpisode(Path.GetFileName(path));
                if (dirEpisode == null || dirEpisode.PlaybackChapters.Count == 0)
                {
                    availableFilenames.Add(Path.GetFileName(path));
                }
            }

            drpUpdatedFilename.Items.AddRange(availableFilenames.ToArray());

            if (!drpUpdatedFilename.Items.Contains(episode.Filename))
            {
                drpUpdatedFilename.Items.Add(episode.Filename); // Can be useful when the duration of a BRB file changes, for instance
            }

            if (drpUpdatedFilename.Items.Count == 0) // Should never happen
            {
                drpUpdatedFilename.Items.Add("(No filenames available)");
                btnReplace.Enabled = false;
            }

            drpUpdatedFilename.SelectedIndex = 0;
        }
Пример #9
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     Config.BRBDirectory = txtBRBDirectory.Text;
     BRBManager.RefreshAvailableList();
     MessageBox.Show("Your BRB directory has been updated. The app found " + BRBManager.AvailableBRBEpisodes.Count + " out of " + BRBManager.BRBEpisodes.Count +
                     " registered BRB episodes in the new directory.", "BRB directory updated", MessageBoxButtons.OK, MessageBoxIcon.Information);
     this.Close();
 }
Пример #10
0
        // BRB Data means the information the user can change on the right hand side of the form
        private void UpdateBRBData()
        {
            if (selectedBRB == null)
            {
                btnOpenBRB.Enabled          = false;
                btnReplaceBRB.Enabled       = false;
                btnRenameBRB.Enabled        = false;
                btnEditAutoMuteData.Enabled = false;

                chkFavourite.Checked      = false;
                txtDuration.Text          = "";
                txtTitle.Text             = "";
                txtAuthors.Text           = "";
                txtDescription.Text       = "";
                numGuaranteedPlays.Value  = 0;
                numPriorityPlays.Value    = 0;
                txtPlaybackData.Text      = "";
                chkEnableAutoMute.Checked = false;
            }
            else
            {
                btnOpenBRB.Enabled          = BRBManager.AvailableBRBEpisodes.Contains(selectedBRB);
                btnReplaceBRB.Enabled       = true;
                btnRenameBRB.Enabled        = true;
                btnEditAutoMuteData.Enabled = true;

                chkFavourite.Checked      = selectedBRB.Favourite;
                txtDuration.Text          = BRBManager.TimeSpanToMMSS(selectedBRB.Duration);
                txtTitle.Text             = selectedBRB.Title;
                txtAuthors.Text           = selectedBRB.Credits;
                txtDescription.Text       = selectedBRB.Description;
                numGuaranteedPlays.Value  = selectedBRB.GuaranteedPlays;
                numPriorityPlays.Value    = selectedBRB.PriorityPlays;
                chkEnableAutoMute.Enabled = (selectedBRB.AutoMutes.Count > 0);
                chkEnableAutoMute.Checked = (selectedBRB.AutoMutes.Count > 0) && selectedBRB.AutoMuteEnabled;

                txtPlaybackData.Text = "Last played in " + selectedBRB.LatestPlaybackChapter + " – Played " + selectedBRB.RecentPlaybacks + " time" + (selectedBRB.RecentPlaybacks != 1 ? "s" : "") +
                                       " since " + (Config.Chapter - Config.ChapterHistoryConsidered) + " – Urgency score " + selectedBRB.GetUrgencyScore() + "\r\n";
                if (selectedBRB.PlaybackChapters.Count == 0)
                {
                    txtPlaybackData.Text += "No playbacks on file.";
                }
                else
                {
                    txtPlaybackData.Text += "All playbacks: [" + selectedBRB.PlaybackChapters[0];
                    for (int i = 1; i < selectedBRB.PlaybackChapters.Count; i++)
                    {
                        txtPlaybackData.Text += ", " + selectedBRB.PlaybackChapters[i];
                    }
                    txtPlaybackData.Text += "]";
                }
            }
        }
Пример #11
0
 private void lstAllBRBs_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lstAllBRBs.SelectedItems.Count == 0)
     {
         selectedBRB = null;
     }
     else
     {
         selectedBRB = BRBManager.GetEpisode(lstAllBRBs.SelectedItems[0].Text);
     }
     UpdateBRBData();
 }
Пример #12
0
 private void FormManageBRBs_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (!BRBManager.SaveEpisodes() && e.CloseReason == CloseReason.UserClosing)
     {
         if (MessageBox.Show("Could not write to file brbepisodes.json. Any changes you made in this window are active in the app but could not be saved to disk.\r\n\r\n" +
                             "It is recommended you investigate this problem as soon as possible, since playback data is difficult to replace if lost.\r\n\r\n" +
                             "Would you like to close this window anyway?",
                             "Writing BRB data to disk failed", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
         {
             e.Cancel = true;
         }
     }
 }
Пример #13
0
        public void OnEndBRBPlayback()
        {
            // Disable / enable controls as is appropriate
            btnManageBRBs.Enabled = true;
            btnSettings.Enabled   = true;
            numMinutes.Enabled    = true;
            btnGenerate.Enabled   = true;
            btnResetBRBs.Enabled  = true;

            btnPlayPause.Enabled   = false;
            btnReplayBRB.Enabled   = false;
            btnPreviousBRB.Enabled = false;
            btnNextBRB.Enabled     = false;
            trkVolume.Enabled      = false;
            chkMuted.Enabled       = false;
            txtVolume.Enabled      = false;
            trkScrubber.Enabled    = false;

            dispPlayerStatus.Visible       = false;
            dispPlayingOrNextUp.Visible    = false;
            lblRemainingBreakTime.Visible  = false;
            dispRemainingBreakTime.Visible = false;

            // Change out BRB player button
            btnStartOrAbortPlayer.Text  = "Start BRB Player";
            btnStartOrAbortPlayer.Image = iconStartPlayer;
            tooltipsManager.SetToolTip(btnStartOrAbortPlayer, "Opens the player window. You will be able to confirm one last time before BRBs start playing");
            btnSwitchScreen.Enabled = false;

            // Make sure "Play" button is displayed
            btnPlayPause.Image = iconPlay;

            // Reset play controls to standards
            trkScrubber.Value    = 0;
            dispRunningTime.Text = "00:00 / 00:00";

            // Stop timers
            tmrEnsureCursorVisibility.Enabled = false;
            tmrUpdateBRBPlaybackData.Enabled  = false;

            // In case playback was aborted from a paused player state
            this.TopMost = false;

            // Try saving BRB playback data (again)
            if (!BRBManager.SaveEpisodes())
            {
                MessageBox.Show("Could not write to file brbepisodes.json. The playback data of your break could not be saved.\r\n\r\n" +
                                "It is recommended you investigate this problem as soon as possible, since playback data is difficult to replace if lost.",
                                "Writing BRB data to disk failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #14
0
        private List <BRBEpisode> GetCurrentPlaylist()
        {
            List <BRBEpisode> playlist = new List <BRBEpisode>();

            foreach (ListViewItem playlistItem in lstBRBPlaylist.Items)
            {
                BRBEpisode ep = BRBManager.GetEpisode(playlistItem.Text);
                if (ep != null)
                {
                    playlist.Add(ep);
                }
            }
            return(playlist);
        }
Пример #15
0
 // BRB data is saved automatically once the form is closed. However, allow the user to save manually at any time without closing the form
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (BRBManager‌.SaveEpisodes())
     {
         btnSave.Text    = "Saved!";
         btnSave.Enabled = false;
         tmrResetSaveButton.Start();
     }
     else
     {
         MessageBox.Show("Could not write to file brbepisodes.json. Any changes you made in this window are active in the app but could not be saved to disk.\r\n\r\n" +
                         "It is recommended you investigate this problem as soon as possible, since playback data is difficult to replace if lost.",
                         "Writing BRB data to disk failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #16
0
        // Called every time the playlist is updated
        private void UpdateBRBPlaylistRunningTime()
        {
            TimeSpan runningTime = new TimeSpan(0);

            foreach (ListViewItem playlistItem in lstBRBPlaylist.Items)
            {
                BRBEpisode ep = BRBManager.GetEpisode(playlistItem.Text);
                if (ep != null)
                {
                    runningTime += new TimeSpan(Config.InterBRBCountdown * TimeSpan.TicksPerSecond);
                    runningTime += ep.Duration;
                }
            }
            // The end screen is not counted here, since it happens after the last actual "playback"

            dispTotalBRBRunningTime.Text = BRBManager.TimeSpanToMMSS(runningTime);
        }
Пример #17
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            lstBRBPlaylist.Items.Clear();
            UpdateBRBPlaylistRunningTime();

            if (numMinutes.Value <= 0)
            {
                MessageBox.Show("The target running time should be positive.", "Cannot generate playlist", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            long     targetDurationTicks = (int)numMinutes.Value * TimeSpan.TicksPerMinute;
            TimeSpan targetDuration      = new TimeSpan(targetDurationTicks);
            TimeSpan minDuration         = new TimeSpan(targetDurationTicks / 100 * (100 - Config.PermittedUndertimePercent));
            TimeSpan maxDuration         = new TimeSpan(targetDurationTicks + Config.PermittedOvertimeMinutes * TimeSpan.TicksPerMinute + TimeSpan.TicksPerMinute / 2);

            List <string> addReason = new List <string>();

            List <BRBEpisode> playlist = BRBManager.GeneratePlaylist(minDuration, targetDuration, maxDuration, ref addReason);

            if (playlist == null)
            {
                MessageBox.Show("The playlist generator failed to compile a BRB playlist with the given restrictions.\r\n\r\n"
                                + "You can try the following steps:\r\n"
                                + "– Try generating a playlist again. If there are only few possible options, the generator can sometimes manoeuvre itself into a dead end.\r\n"
                                + "– Change the target running time of your break‌.\r\n"
                                + "– Configure permitted over- and undertime to be more lenient.\r\n"
                                + "– If you have many BRB episodes marked as \"Guaranteed\", unmark some of them.", "Not enough BRB episodes", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            BRBEpisode ep;

            for (int i = 0; i < playlist.Count; i++)
            {
                ep = playlist[i];
                ListViewItem item = new ListViewItem(new string[] { ep.Filename, BRBManager.TimeSpanToMMSS(ep.Duration), ep.GetWeight().ToString(), addReason[i] });
                lstBRBPlaylist.Items.Add(item);
            }

            UpdateBRBPlaylistRunningTime();
        }
Пример #18
0
        // Look for new BRB files that are yet unknown to the manager's list
        private void CheckAndAddNewFiles()
        {
            List <string> knownFilenames = BRBManager.GetBRBFilenameList();

            foreach (string diskPath in Directory.GetFiles(Config.BRBDirectory))
            {
                if (!knownFilenames.Contains(Path.GetFileName(diskPath)))
                {
                    if (MessageBox.Show("A new file has been found in the BRB directory. Would you like to add \"" + Path.GetFileName(diskPath) + "\" to the BRB list now?\r\n\r\n" +
                                        "Note: The new BRB will automatically receive " + Config.AutoGuaranteedPlaysForNewBRBs +
                                        " \"Guaranteed\" and " + Config.AutoPriorityPlaysForNewBRBs + " \"Priority\" plays.\r\n\r\n" +
                                        "If this is a renamed or updated BRB file, please select \"No\" and use the \"Replace with new version\" button.",
                                        "New BRB found", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (!BRBManager.RegisterNewBRB(Path.GetFileName(diskPath)))
                        {
                            MessageBox.Show("Could not register the new BRB file. Make sure it is a valid video file (in a format compatible with VLC) and the application has read permissions on it.",
                                            "Adding new BRB failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
Пример #19
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Core.Initialize(); // Initialize VLC libraries
            VLC       = new LibVLC();
            VLCPlayer = new MediaPlayer(VLC);
            VLCPlayer.EnableKeyInput   = false; // Make VLC player resistant to involuntary disruption
            VLCPlayer.EnableMouseInput = false;
            try
            {
                VLC.SetLogFile("VLC.log");
            }
            catch (IOException)
            {
                MessageBox.Show("Cannot set VLC.log as the VLC log file. Is an instance of the application already running? If not, ensure the application has write permissions in its directory.",
                                "Error setting the log file for VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            catch (VLCException)
            {
                MessageBox.Show("Cannot set VLC.log as the VLC log file. Is an instance of the application already running? If not, ensure the application has write permissions in its directory.",
                                "Error setting the log file for VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            VLCPlayer.EndReached       += new EventHandler <EventArgs>(OnMediaEndReached);
            VLCPlayer.EncounteredError += new EventHandler <EventArgs>(OnMediaError);

            if (!IsApplicationSetup())
            {
                AppState = ApplicationState.InitialSetup;
                FormInitialSetup initialSetupForm = new FormInitialSetup();
                initialSetupForm.Show();
            }
            else
            {
                if (Config.LoadConfig())
                {
                    if (BRBManager.LoadEpisodes())
                    {
                        AppState = ApplicationState.Idle;
                        MainForm = new FormMain();
                        MainForm.Show();
                    }
                    else
                    {
                        MessageBox.Show("Could not properly load file brbepisodes.json. The application cannot retrieve saved data about BRB episodes and will exit.\r\n\r\n"
                                        + "It is recommended you verify the integrity of the file as soon as possible, since playback data is difficult to replace if lost.",
                                        "Failed loading BRB episodes and playback data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Could not properly load file config.json. The application cannot retrieve its configuration and will exit.\r\n\r\n"
                                    + "Ensure the application has read permissions in its directory and try again. If this does not resolve the error, the configuration file might be corrupted.",
                                    "Failed loading the configuration file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            Application.Run();
        }
Пример #20
0
 private void btnReloadBRBList_Click(object sender, EventArgs e)
 {
     BRBManager.RefreshAvailableList();
     UpdateBRBList(true);
 }
Пример #21
0
 private void FormManageBRBs_Shown(object sender, EventArgs e)
 {
     BRBManager.RefreshAvailableList();
     UpdateBRBList(false); // Not checking for new files on form show anymore, since that defeats the purpose of the "Reload BRB list" button
 }
Пример #22
0
        public void UpdateBRBData()
        {
            lstAllBRBs.BeginUpdate();
            lstAllBRBs.Items.Clear();

            List <ListViewItem> newItems = new List <ListViewItem>(BRBManager.AvailableBRBEpisodes.Count);

            foreach (BRBEpisode episode in BRBManager.AvailableBRBEpisodes)
            {
                if (txtSearch.Text == "" || episode.ContainsTextAtField(txtSearch.Text, drpSearchWhere.SelectedIndex))
                {
                    int          weight = episode.GetWeight();
                    ListViewItem item   = new ListViewItem(new string[] { episode.Favourite ? "\u2605" : "", episode.Filename, BRBManager.TimeSpanToMMSS(episode.Duration), episode.Description,
                                                                          episode.LatestPlaybackChapter.ToString(), weight.ToString(), episode.PriorityChar.ToString() });
                    item.UseItemStyleForSubItems = false;
                    item.SubItems[0].Font        = new Font(item.SubItems[0].Font, FontStyle.Bold);
                    item.SubItems[0].ForeColor   = Color.Gold;
                    item.SubItems[5].Font        = new Font(item.SubItems[5].Font, FontStyle.Bold);
                    item.SubItems[5].ForeColor   = weight <= 4 ? Color.DarkGreen : (weight <= 9 ? Color.Orange : Color.Red);
                    if (item.SubItems[6].Text != "N")
                    {
                        item.SubItems[6].Font = new Font(item.SubItems[6].Font, FontStyle.Bold);
                    }
                    newItems.Add(item);
                }
            }

            lstAllBRBs.Items.AddRange(newItems.ToArray());

            // Clearing sorter every time is supposed to improve performance
            lstAllBRBs.ListViewItemSorter = new BRBListComparer(currentBRBListSortColumn, currentBRBListSortInverted);
            lstAllBRBs.Sort();
            lstAllBRBs.ListViewItemSorter = null;

            lstAllBRBs.EndUpdate();

            if (txtSearch.Text == "")
            {
                lblAvailableBRBs.Text = "Available BRBs (" + BRBManager.AvailableBRBEpisodes.Count + "):";
            }
            else
            {
                lblAvailableBRBs.Text = "Available BRBs (filtered, " + lstAllBRBs.Items.Count + " / " + BRBManager.AvailableBRBEpisodes.Count + "):";
            }
        }
Пример #23
0
        public void OnBRBPlayerStateChanged()
        {
            // Update displays

            BRBEpisode episode;

            switch (Program.PlayerForm.PlayerState)
            {
            case BRBPlayerState.BeginningOfBreak:
            case BRBPlayerState.InBetweenBRBs:
            case BRBPlayerState.HobbVLC:
                for (int i = 0; i < Program.PlayerForm.NextOrCurrentBRBIndex; i++)
                {
                    lstBRBPlaylist.Items[i].ForeColor = Color.DarkGray;
                    lstBRBPlaylist.Items[i].Font      = new Font(lstBRBPlaylist.Items[i].Font, FontStyle‌.Regular);
                }
                lstBRBPlaylist.Items[Program.PlayerForm.NextOrCurrentBRBIndex].Font      = new Font(lstBRBPlaylist.Items[Program.PlayerForm.NextOrCurrentBRBIndex].Font, FontStyle‌.Bold);
                lstBRBPlaylist.Items[Program.PlayerForm.NextOrCurrentBRBIndex].ForeColor = SystemColors.ControlText;
                for (int i = Program.PlayerForm.NextOrCurrentBRBIndex + 1; i < lstBRBPlaylist.Items.Count; i++)
                {
                    lstBRBPlaylist.Items[i].ForeColor = SystemColors.ControlText;
                    lstBRBPlaylist.Items[i].Font      = new Font(lstBRBPlaylist.Items[i].Font, FontStyle‌.Regular);
                }

                episode = Program.PlayerForm.NextOrCurrentBRB;
                dispPlayerStatus.Text         = "Next up:";
                dispPlayingOrNextUp.Text      = episode.Filename;
                durationOfCurrentBRBFormatted = BRBManager.TimeSpanToMMSS(episode.Duration);
                dispRunningTime.Text          = "00:00 / " + durationOfCurrentBRBFormatted;
                trkScrubber.Maximum           = (int)(episode.Duration.TotalSeconds * 30); // The scrubber shall be based on 1/30 seconds internally
                trkScrubber.Value             = 0;
                trkScrubber.Enabled           = false;
                break;

            case BRBPlayerState.Playback:     // Always occurs after one of the above three states, so not much is to be done
                Program.PlayerForm.SetVolume(trkVolume.Value);
                Program.PlayerForm.SetMuted(chkMuted.Checked);

                dispPlayerStatus.Text = "Now playing:";
                trkScrubber.Enabled   = true;
                break;

            case BRBPlayerState.EndOfBreak:
                for (int i = 0; i < lstBRBPlaylist.Items.Count; i++)
                {
                    lstBRBPlaylist.Items[i].ForeColor = Color.DarkGray;
                    lstBRBPlaylist.Items[i].Font      = new Font(lstBRBPlaylist.Items[i].Font, FontStyle‌.Regular);
                }

                dispPlayerStatus.Text    = "Finished. Waiting for user...";
                dispPlayingOrNextUp.Text = "";
                dispRunningTime.Text     = "00:00 / 00:00";
                trkScrubber.Value        = 0;
                trkScrubber.Enabled      = false;
                break;

            case BRBPlayerState.ErrorOccurred:
                // Disable pretty much everything aside from "Abort BRB playback"; it is likely the occurring error requires fixing something, so continuing the playback wouldn't make sense
                btnPlayPause.Enabled   = false;
                btnReplayBRB.Enabled   = false;
                btnPreviousBRB.Enabled = false;
                btnNextBRB.Enabled     = false;
                trkVolume.Enabled      = false;
                chkMuted.Enabled       = false;
                txtVolume.Enabled      = false;
                trkScrubber.Enabled    = false;
                // Stop timers
                tmrEnsureCursorVisibility.Enabled = false;
                tmrUpdateBRBPlaybackData.Enabled  = false;
                break;
            }
        }
Пример #24
0
        public FormAutoMuteData(BRBEpisode episode)
        {
            InitializeComponent();

            this.episode = episode;
            this.Text    = "Displaying AutoMute Data of " + episode.Filename;

            if (episode.AutoMutes.Count == 0)
            {
                txtBegin.Text = "";
                txtEnd.Text   = "";
                txtInfo.Text  = "";
            }
            else
            {
                foreach (BRBEpisode.AutoMuteSpan span in episode.AutoMutes)
                {
                    drpAutoMuteTrigger.Items.Add((!span.Enabled ? "[Disabled] " : "") + BRBManager.TimeSpanToMMSS(span.Begin) + " \u2013 " + BRBManager.TimeSpanToMMSS(span.End) + " / " + span.Info);
                }

                drpAutoMuteTrigger.SelectedIndex = 0;

                UpdateAutoMuteData();
            }
        }
Пример #25
0
        private void btnReplace_Click(object sender, EventArgs e)
        {
            string newFilename = (string)drpUpdatedFilename.SelectedItem;

            BRBEpisode newVersionEpisode = BRBManager.GetEpisode(newFilename);

            // Old file doesn't exist anymore. Possible scenario: User has renamed or replaced a BRB file outside of the application
            if (!BRBManager.AvailableBRBEpisodes.Contains(episodeToUpdate))
            {
                if (newVersionEpisode != null)
                {
                    if (episodeToUpdate.Filename == newFilename)
                    {
                        // Cannot happen
                    }
                    else
                    {
                        if (MessageBox.Show("All BRB data from the old file will be copied over to the new video version in the system. This will overwrite any existing data of the new video.\r\n\r\n" +
                                            "Since the old file cannot be found on disk anymore, it will subsequently be removed from the system.\r\n\r\n" +
                                            "Do you want to proceed?", "Please confirm BRB video update", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                        {
                            return;
                        }
                        BRBManager.BRBEpisodes.Remove(newVersionEpisode);
                    }
                }
                else
                {
                    if (MessageBox.Show("The video file you specified is not registered in the system yet. This will be done now and all BRB data from the old file will be copied over.\r\n\r\n" +
                                        "Since the old file cannot be found on disk anymore, it will subsequently be removed from the system.\r\n\r\n" +
                                        "Do you want to proceed?", "Please confirm BRB video update", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                    {
                        return;
                    }
                }

                // Copy data over and remove old BRB
                if (!BRBManager.TransferToNewFilename(episodeToUpdate, newFilename, true))
                {
                    MessageBox.Show("Could not register the new BRB file. Make sure it is a valid video file (in a format compatible with VLC) and the application has read permissions on it." +
                                    "\r\n\r\nThe updating process was aborted. If the new file was already in the system, it has been removed. No other data was changed.",
                                    "Adding new BRB failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Old file still exists. Possible scenario: User has added a newer version of the BRB and did not remove the old version from the directory
            else
            {
                if (newVersionEpisode != null)
                {
                    if (episodeToUpdate.Filename == newFilename)
                    {
                        if (MessageBox.Show("This will reload the video file in question and update the duration shown in the application. Proceed?",
                                            "Please confirm BRB video update", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            episodeToUpdate.RefreshDuration();

                            if (!BRBManager.SaveEpisodes())
                            {
                                MessageBox.Show("Could not write to file brbepisodes.json. Replacing the BRB file with a new version was successful, but this could not be saved to disk.\r\n\r\n" +
                                                "It is recommended you investigate this problem as soon as possible, since playback data is difficult to replace if lost.",
                                                "Writing BRB data to disk failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            this.Close();
                            return; // Make sure the file doesn't end up in the system twice
                        }
                    }
                    else
                    {
                        if (MessageBox.Show("All BRB data from the old file will be copied over to the new video version in the system. This will overwrite any existing data of the new video.\r\n\r\n" +
                                            "Note that since the old video file is still present on disk, it will remain in the system. " +
                                            "If you do not wish this, please cancel the operation and remove it from the directory on disk first.\r\n\r\n" +
                                            "Do you want to proceed?", "Please confirm BRB video update", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                        {
                            return;
                        }
                        BRBManager.BRBEpisodes.Remove(newVersionEpisode);
                    }
                }
                else
                {
                    if (MessageBox.Show("The video file you specified is not registered in the system yet. This will be done now and all BRB data from the old file will be copied over.\r\n\r\n" +
                                        "Note that since the old video file is still present on disk, it will remain in the system. " +
                                        "If you do not wish this, please cancel the operation and remove it from the directory on disk first.\r\n\r\n" +
                                        "Do you want to proceed?", "Please confirm BRB video update", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                    {
                        return;
                    }
                }

                // Copy data over, but do not remove old BRB
                if (!BRBManager.TransferToNewFilename(episodeToUpdate, newFilename, false))
                {
                    MessageBox.Show("Could not register the new BRB file. Make sure it is a valid video file (in a format compatible with VLC) and the application has read permissions on it." +
                                    "\r\n\r\nThe updating process was aborted. If the new file was already in the system, it has been removed. No other data was changed.",
                                    "Adding new BRB failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            BRBManager.RefreshAvailableList();

            if (!BRBManager.SaveEpisodes())
            {
                MessageBox.Show("Could not write to file brbepisodes.json. Replacing the BRB file with a new version was successful, but this could not be saved to disk.\r\n\r\n" +
                                "It is recommended you investigate this problem as soon as possible, since playback data is difficult to replace if lost.",
                                "Writing BRB data to disk failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.Close();
        }
Пример #26
0
        // Handles activation of the next stage when a BRB video finished playing, and registers BRB as played
        public void OnMediaEndReached(object sender, EventArgs e)
        {
            switch (PlayerState)
            {
            case BRBPlayerState.Playback:
                BRBManager.OnPlayedBack(NextOrCurrentBRB);

                NextOrCurrentBRBIndex++;

                if (NextOrCurrentBRBIndex >= BRBPlaylist.Count)
                {
                    ChangePlayerState(BRBPlayerState.EndOfBreak);
                }
                else
                {
                    ChangePlayerState(BRBPlayerState.InBetweenBRBs);
                }
                break;

            // For InterBRBs etc., loop the background video (but that should rarely happen)
            case BRBPlayerState.BeginningOfBreak:
                ThreadPool.QueueUserWorkItem((o) => {
                    if (File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")))
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")));
                    }
                    else
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\preBRB.mkv")));
                    }
                    VLCPlayer.Play();
                });
                break;

            case BRBPlayerState.InBetweenBRBs:
                ThreadPool.QueueUserWorkItem((o) => {
                    if (File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")))
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")));
                    }
                    else
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\interBRB.mkv")));
                    }
                    VLCPlayer.Play();
                });
                break;

            case BRBPlayerState.EndOfBreak:
                ThreadPool.QueueUserWorkItem((o) => {
                    if (File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")))
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")));
                    }
                    else
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\postBRB.mkv")));
                    }
                    VLCPlayer.Play();
                });
                break;

            case BRBPlayerState.HobbVLC:
                ThreadPool.QueueUserWorkItem((o) => {
                    if (File.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")))
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\universal.mp4")));
                    }
                    else
                    {
                        VLCPlayer.Media = new Media(Program.VLC, new Uri(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "images\\screens\\hobbVLC.mkv")));
                    }
                    VLCPlayer.Play();
                });
                break;
            }
        }