From 1fe85f1a237d4d0242862bb92d2383c1058f6158 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 24 Apr 2010 15:10:03 +0000 Subject: [PATCH] WinGui: - Use Auto Properties in the Parser git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3258 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Parsing/AudioTrack.cs | 90 ++++-------------- win/C#/Parsing/Chapter.cs | 26 +----- win/C#/Parsing/DVD.cs | 26 +++--- win/C#/Parsing/Parser.cs | 2 +- win/C#/Parsing/Subtitle.cs | 50 ++-------- win/C#/Parsing/Title.cs | 173 +++++++---------------------------- 6 files changed, 81 insertions(+), 286 deletions(-) diff --git a/win/C#/Parsing/AudioTrack.cs b/win/C#/Parsing/AudioTrack.cs index 161385f45..489f360d2 100644 --- a/win/C#/Parsing/AudioTrack.cs +++ b/win/C#/Parsing/AudioTrack.cs @@ -14,96 +14,40 @@ namespace Handbrake.Parsing /// public class AudioTrack { - /// - /// The Track bitrate - /// - private int bitrate; - - /// - /// The track format - /// - private string format; - - /// - /// The Frequency - /// - private int frequency; - - /// - /// Track Language - /// - private string language; - - /// - /// Sub Format - /// - private string subFormat; - - /// - /// Track Number - /// - private int trackNumber; - - /// - /// The ISO639_2 code - /// - private string iso639_2; - /// /// Gets The track number of this Audio Track /// - public int TrackNumber - { - get { return trackNumber; } - } + public int TrackNumber { get; private set; } /// /// Gets The language (if detected) of this Audio Track /// - public string Language - { - get { return language; } - } + public string Language { get; private set; } /// /// Gets The primary format of this Audio Track /// - public string Format - { - get { return format; } - } + public string Format { get; private set; } /// /// Gets Additional format info for this Audio Track /// - public string SubFormat - { - get { return subFormat; } - } + public string SubFormat { get; private set; } /// /// Gets The frequency (in MHz) of this Audio Track /// - public int Frequency - { - get { return frequency; } - } + public int Frequency { get; private set; } /// /// Gets The bitrate (in kbps) of this Audio Track /// - public int Bitrate - { - get { return bitrate; } - } + public int Bitrate { get; private set; } /// /// Gets ISO639_2. /// - public string ISO639_2 - { - get { return iso639_2; } - } + public string ISO639_2 { get; private set; } /// /// Parse the CLI input to an Audio Track object @@ -131,13 +75,13 @@ namespace Handbrake.Parsing { var thisTrack = new AudioTrack { - trackNumber = int.Parse(track.Groups[1].Value.Trim()), - language = track.Groups[2].Value, - format = m.Groups[3].Value, - subFormat = subformat, - frequency = int.Parse(samplerateVal), - bitrate = int.Parse(bitrateVal), - iso639_2 = + TrackNumber = int.Parse(track.Groups[1].Value.Trim()), + Language = track.Groups[2].Value, + Format = m.Groups[3].Value, + SubFormat = subformat, + Frequency = int.Parse(samplerateVal), + Bitrate = int.Parse(bitrateVal), + ISO639_2 = iso639_2.Value.Replace("iso639-2: ", string.Empty).Replace(")", string.Empty) }; return thisTrack; @@ -175,10 +119,10 @@ namespace Handbrake.Parsing /// A string formatted as: {track #} {language} ({format}) ({sub-format}) public override string ToString() { - if (subFormat == null) - return string.Format("{0} {1} ({2})", trackNumber, language, format); + if (SubFormat == null) + return string.Format("{0} {1} ({2})", TrackNumber, Language, Format); - return string.Format("{0} {1} ({2}) ({3})", trackNumber, language, format, subFormat); + return string.Format("{0} {1} ({2}) ({3})", TrackNumber, Language, Format, SubFormat); } } } \ No newline at end of file diff --git a/win/C#/Parsing/Chapter.cs b/win/C#/Parsing/Chapter.cs index 01aced03a..4b3bb2d00 100644 --- a/win/C#/Parsing/Chapter.cs +++ b/win/C#/Parsing/Chapter.cs @@ -15,31 +15,15 @@ namespace Handbrake.Parsing /// public class Chapter { - /// - /// Chapter Number - /// - private int chapterNumber; - - /// - /// The Duration of the chapter - /// - private TimeSpan duration; - /// /// Gets The number of this Chapter, in regards to it's parent Title /// - public int ChapterNumber - { - get { return chapterNumber; } - } + public int ChapterNumber { get; private set; } /// /// Gets The length in time this Chapter spans /// - public TimeSpan Duration - { - get { return duration; } - } + public TimeSpan Duration { get; private set; } /// /// Parse a CLI string to a Chapter object @@ -59,8 +43,8 @@ namespace Handbrake.Parsing { var thisChapter = new Chapter { - chapterNumber = int.Parse(m.Groups[1].Value.Trim()), - duration = TimeSpan.Parse(m.Groups[5].Value) + ChapterNumber = int.Parse(m.Groups[1].Value.Trim()), + Duration = TimeSpan.Parse(m.Groups[5].Value) }; return thisChapter; } @@ -103,7 +87,7 @@ namespace Handbrake.Parsing /// A string formatted as: {chapter #} public override string ToString() { - return chapterNumber.ToString(); + return ChapterNumber.ToString(); } } } \ No newline at end of file diff --git a/win/C#/Parsing/DVD.cs b/win/C#/Parsing/DVD.cs index 336ff6d94..5e3d411b2 100644 --- a/win/C#/Parsing/DVD.cs +++ b/win/C#/Parsing/DVD.cs @@ -1,6 +1,4 @@ -/* DVD.cs $ - - This file is part of the HandBrake source code. +/* DVD.cs $ This file is part of the HandBrake source code. Homepage: . It may be used under the terms of the GNU General Public License. */ @@ -14,25 +12,29 @@ namespace Handbrake.Parsing /// public class DVD { - private readonly List titles; - /// <summary> /// Initializes a new instance of the <see cref="DVD"/> class. /// Default constructor for this object /// </summary> public DVD() { - titles = new List<Title>(); + Titles = new List<Title>(); } /// <summary> - /// Collection of Titles associated with this DVD + /// Gets Titles. A list of titles from the source /// </summary> - public List<Title> Titles - { - get { return titles; } - } + public List<Title> Titles { get; private set; } + /// <summary> + /// Parse the StreamReader output into a List of Titles + /// </summary> + /// <param name="output"> + /// The output. + /// </param> + /// <returns> + /// A DVD object which contains a list of title inforamtion + /// </returns> public static DVD Parse(StreamReader output) { var thisDVD = new DVD(); @@ -40,7 +42,7 @@ namespace Handbrake.Parsing while (!output.EndOfStream) { if ((char) output.Peek() == '+') - thisDVD.titles.AddRange(Title.ParseList(output.ReadToEnd())); + thisDVD.Titles.AddRange(Title.ParseList(output.ReadToEnd())); else output.ReadLine(); } diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs index 72a4695bb..0fb08f9a5 100644 --- a/win/C#/Parsing/Parser.cs +++ b/win/C#/Parsing/Parser.cs @@ -46,7 +46,7 @@ namespace Handbrake.Parsing /// <summary> /// The Buffer StringBuilder /// </summary> - private StringBuilder buffer = new StringBuilder(string.Empty); + private readonly StringBuilder buffer = new StringBuilder(string.Empty); /// <summary> /// Initializes a new instance of the <see cref="Parser"/> class. diff --git a/win/C#/Parsing/Subtitle.cs b/win/C#/Parsing/Subtitle.cs index a21040be5..52a0729db 100644 --- a/win/C#/Parsing/Subtitle.cs +++ b/win/C#/Parsing/Subtitle.cs @@ -14,57 +14,25 @@ namespace Handbrake.Parsing /// </summary> public class Subtitle { - /// <summary> - /// The Language - /// </summary> - private string language; - - /// <summary> - /// The Track Number - /// </summary> - private int trackNumber; - - /// <summary> - /// The type of subtitle - /// </summary> - private string type; - - /// <summary> - /// The typecode - /// </summary> - private string typecode; - /// <summary> /// Gets the track number of this Subtitle /// </summary> - public int TrackNumber - { - get { return trackNumber; } - } + public int TrackNumber { get; private set; } /// <summary> /// Gets the The language (if detected) of this Subtitle /// </summary> - public string Language - { - get { return language; } - } + public string Language { get; private set; } /// <summary> /// Gets the Langauage Code /// </summary> - public string LanguageCode - { - get { return typecode; } - } + public string LanguageCode { get; private set; } /// <summary> /// Gets the Subtitle Type /// </summary> - public string Type - { - get { return type; } - } + public string Type { get; private set; } /// <summary> /// Parse the input strings related to subtitles @@ -84,10 +52,10 @@ namespace Handbrake.Parsing { var thisSubtitle = new Subtitle { - trackNumber = int.Parse(m.Groups[1].Value.Trim()), - language = m.Groups[2].Value, - typecode = m.Groups[3].Value, - type = m.Groups[4].Value + TrackNumber = int.Parse(m.Groups[1].Value.Trim()), + Language = m.Groups[2].Value, + LanguageCode = m.Groups[3].Value, + Type = m.Groups[4].Value }; return thisSubtitle; } @@ -124,7 +92,7 @@ namespace Handbrake.Parsing /// <returns>A string formatted as: {track #} {language}</returns> public override string ToString() { - return string.Format("{0} {1} ({2})", trackNumber, language, type); + return string.Format("{0} {1} ({2})", TrackNumber, Language, Type); } } } \ No newline at end of file diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs index e3db16a51..ab3a27423 100644 --- a/win/C#/Parsing/Title.cs +++ b/win/C#/Parsing/Title.cs @@ -22,190 +22,87 @@ namespace Handbrake.Parsing /// </summary> private static readonly CultureInfo Culture = new CultureInfo("en-US", false); - /// <summary> - /// A collection of Audio Tracks - /// </summary> - private readonly List<AudioTrack> audioTracks; - - /// <summary> - /// A Collection of Chapters - /// </summary> - private readonly List<Chapter> chapters; - - /// <summary> - /// A Collection of Subtitles - /// </summary> - private readonly List<Subtitle> subtitles; - - /// <summary> - /// A collection of angles - /// </summary> - private List<string> angles = new List<string>(); - - /// <summary> - /// The source aspect ratio - /// </summary> - private float aspectRatio; - - /// <summary> - /// The source framerate - /// </summary> - private float fps; - - /// <summary> - /// Source autocrop values - /// </summary> - private int[] autoCrop; - - /// <summary> - /// Source name - /// </summary> - private string source; - - /// <summary> - /// The duration of the source - /// </summary> - private TimeSpan duration; - - /// <summary> - /// The source resolution - /// </summary> - private Size resolution; - - /// <summary> - /// The Title number - /// </summary> - private int titleNumber; - - /// <summary> - /// Is A Main Title - /// </summary> - private bool mainTitle; - - /// <summary> - /// The par values for this title. - /// </summary> - private Size parVal; - /// <summary> /// Initializes a new instance of the <see cref="Title"/> class. /// The constructor for this object /// </summary> public Title() { - audioTracks = new List<AudioTrack>(); - chapters = new List<Chapter>(); - subtitles = new List<Subtitle>(); + Angles = new List<string>(); + AudioTracks = new List<AudioTrack>(); + Chapters = new List<Chapter>(); + Subtitles = new List<Subtitle>(); } /// <summary> /// Gets a Collection of chapters in this Title /// </summary> - public List<Chapter> Chapters - { - get { return chapters; } - } + public List<Chapter> Chapters { get; private set; } /// <summary> /// Gets a Collection of audio tracks associated with this Title /// </summary> - public List<AudioTrack> AudioTracks - { - get { return audioTracks; } - } + public List<AudioTrack> AudioTracks { get; private set; } /// <summary> /// Gets aCollection of subtitles associated with this Title /// </summary> - public List<Subtitle> Subtitles - { - get { return subtitles; } - } + public List<Subtitle> Subtitles { get; private set; } /// <summary> /// Gets The track number of this Title /// </summary> - public int TitleNumber - { - get { return this.titleNumber; } - } + public int TitleNumber { get; private set; } /// <summary> /// Gets a value indicating whether this is a MainTitle. /// </summary> - public bool MainTitle - { - get { return this.mainTitle; } - } + public bool MainTitle { get; private set; } /// <summary> /// Gets the Source Name /// </summary> - public string SourceName - { - get { return source; } - } + public string SourceName { get; private set; } /// <summary> /// Gets the length in time of this Title /// </summary> - public TimeSpan Duration - { - get { return duration; } - } + public TimeSpan Duration { get; private set; } /// <summary> /// Gets the resolution (width/height) of this Title /// </summary> - public Size Resolution - { - get { return resolution; } - } + public Size Resolution { get; private set; } /// <summary> /// Gets the aspect ratio of this Title /// </summary> - public float AspectRatio - { - get { return aspectRatio; } - } + public float AspectRatio { get; private set; } /// <summary> /// Gets Par Value /// </summary> - public Size ParVal - { - get { return parVal; } - } + public Size ParVal { get; private set; } /// <summary> /// Gets the automatically detected crop region for this Title. /// This is an int array with 4 items in it as so: - /// 0: - /// 1: - /// 2: - /// 3: + /// 0: T + /// 1: B + /// 2: L + /// 3: R /// </summary> - public int[] AutoCropDimensions - { - get { return autoCrop; } - } + public int[] AutoCropDimensions { get; private set; } /// <summary> /// Gets a Collection of Angles in this Title /// </summary> - public List<string> Angles - { - get { return angles; } - } + public List<string> Angles { get; private set; } /// <summary> /// Gets the FPS of the source. /// </summary> - public float Fps - { - get { return fps; } - } + public float Fps { get; private set; } /// <summary> /// Parse the Title Information @@ -219,7 +116,7 @@ namespace Handbrake.Parsing Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):"); // Match track number for this title if (m.Success) - thisTitle.titleNumber = int.Parse(m.Groups[1].Value.Trim()); + thisTitle.TitleNumber = int.Parse(m.Groups[1].Value.Trim()); // If we are scanning a groupd of files, we'll want to get the source name. string path = output.ReadLine(); @@ -227,13 +124,13 @@ namespace Handbrake.Parsing m = Regex.Match(path, @" \+ Main Feature"); if (m.Success) { - thisTitle.mainTitle = true; + thisTitle.MainTitle = true; path = output.ReadLine(); } m = Regex.Match(path, @"^ \+ stream:"); if (m.Success) - thisTitle.source = path.Replace("+ stream:", string.Empty).Trim(); + thisTitle.SourceName = path.Replace("+ stream:", string.Empty).Trim(); if (!Properties.Settings.Default.noDvdNav) { @@ -246,39 +143,39 @@ namespace Handbrake.Parsing int.TryParse(angleList, out angleCount); for (int i = 1; i <= angleCount; i++) - thisTitle.angles.Add(i.ToString()); + thisTitle.Angles.Add(i.ToString()); } } // Get duration for this title m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})"); if (m.Success) - thisTitle.duration = TimeSpan.Parse(m.Groups[1].Value); + thisTitle.Duration = TimeSpan.Parse(m.Groups[1].Value); // Get resolution, aspect ratio and FPS for this title m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), pixel aspect: ([0-9]*)/([0-9]*), display aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps"); if (m.Success) { - thisTitle.resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value)); - thisTitle.parVal = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value)); - thisTitle.aspectRatio = float.Parse(m.Groups[5].Value, Culture); - thisTitle.fps = float.Parse(m.Groups[6].Value, Culture); + thisTitle.Resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value)); + thisTitle.ParVal = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value)); + thisTitle.AspectRatio = float.Parse(m.Groups[5].Value, Culture); + thisTitle.Fps = float.Parse(m.Groups[6].Value, Culture); } // Get autocrop region for this title m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)"); if (m.Success) - thisTitle.autoCrop = new[] + thisTitle.AutoCropDimensions = new[] { int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value) }; - thisTitle.chapters.AddRange(Chapter.ParseList(output)); + thisTitle.Chapters.AddRange(Chapter.ParseList(output)); - thisTitle.audioTracks.AddRange(AudioTrack.ParseList(output)); + thisTitle.AudioTracks.AddRange(AudioTrack.ParseList(output)); - thisTitle.subtitles.AddRange(Subtitle.ParseList(output)); + thisTitle.Subtitles.AddRange(Subtitle.ParseList(output)); return thisTitle; } @@ -311,7 +208,7 @@ namespace Handbrake.Parsing /// <returns>A string representing this track in the format: {title #} (00:00:00)</returns> public override string ToString() { - return string.Format("{0} ({1:00}:{2:00}:{3:00})", titleNumber, duration.Hours, duration.Minutes, duration.Seconds); + return string.Format("{0} ({1:00}:{2:00}:{3:00})", TitleNumber, Duration.Hours, Duration.Minutes, Duration.Seconds); } } } \ No newline at end of file -- 2.40.0