// Update the filename of a BRB episode, without considering anything else (for instance, when user updates a BRB to its new filename) public static bool TransferToNewFilename(BRBEpisode episode, string newFilename, bool removeOldEpisode) { BRBEpisode newEpisodeVersion = new BRBEpisode(newFilename, episode.Duration, episode.Favourite, episode.Title, episode.Description, episode.Credits, episode.IsNew, episode.PlaybackChapters, episode.GuaranteedPlays, episode.PriorityPlays, episode.AutoMutes, episode.AutoMuteEnabled); newEpisodeVersion.RefreshDuration(); // Make sure the episode's video file is understood by the application if (newEpisodeVersion.Duration.Ticks == 0) { return(false); } if (removeOldEpisode) { BRBEpisodes.Remove(episode); } BRBEpisodes.Add(newEpisodeVersion); BRBEpisodes.Sort(); return(true); }
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(); }