summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2008-08-27 23:45:44 +0000
committersr55 <[email protected]>2008-08-27 23:45:44 +0000
commitc1f31822b78859305328750ca0adcd0b1699f690 (patch)
tree9751e09ecee8a9199e5f49ae0af351f71a8be794
parent1833f566d3f9c7fbe0ef61b4f9304b6e0f7fddb5 (diff)
WinGui:
- Code Refactoring and optimization to numerous files git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1655 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--win/C#/Functions/Common.cs18
-rw-r--r--win/C#/Functions/Presets.cs16
-rw-r--r--win/C#/Functions/Queue.cs15
-rw-r--r--win/C#/Functions/x264Panel.cs6
-rw-r--r--win/C#/Parsing/DVD.cs21
-rw-r--r--win/C#/Parsing/Parser.cs41
-rw-r--r--win/C#/Parsing/Title.cs69
-rw-r--r--win/C#/frmActivityWindow.cs10
-rw-r--r--win/C#/frmDownload.cs81
-rw-r--r--win/C#/frmMain.cs107
-rw-r--r--win/C#/frmUpdater.cs20
11 files changed, 167 insertions, 237 deletions
diff --git a/win/C#/Functions/Common.cs b/win/C#/Functions/Common.cs
index 7ff2ec806..02e7628ca 100644
--- a/win/C#/Functions/Common.cs
+++ b/win/C#/Functions/Common.cs
@@ -235,7 +235,7 @@ namespace Handbrake.Functions
#region Audio
// Handle Track 1
- if (presetQuery.AudioTrack1 == "")
+ if (presetQuery.AudioTrack1 == string.Empty)
mainWindow.drp_track1Audio.Text = "Automatic";
else
mainWindow.drp_track1Audio.Text = presetQuery.AudioTrack1;
@@ -527,13 +527,13 @@ namespace Handbrake.Functions
query += " --crop 0:0:0:0 ";
else if (mainWindow.drp_crop.Text == "Custom")
{
- if (mainWindow.text_top.Text == "")
+ if (mainWindow.text_top.Text == string.Empty)
cropTop = "0";
- if (mainWindow.text_bottom.Text == "")
+ if (mainWindow.text_bottom.Text == string.Empty)
cropBottom = "0";
- if (mainWindow.text_left.Text == "")
+ if (mainWindow.text_left.Text == string.Empty)
cropLeft = "0";
- if (mainWindow.text_right.Text == "")
+ if (mainWindow.text_right.Text == string.Empty)
cropRight = "0";
query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight;
@@ -728,7 +728,7 @@ namespace Handbrake.Functions
if (aencoder2 != "")
{
- if (aencoder1 == "")
+ if (aencoder1 == string.Empty)
query += " -E faac," + getAudioEncoder(aencoder2);
else
query += "," + getAudioEncoder(aencoder2);
@@ -748,7 +748,7 @@ namespace Handbrake.Functions
if (audioBitrate2 != "")
{
- if (audioBitrate1 == "")
+ if (audioBitrate1 == string.Empty)
query += " -B 160," + audioBitrate2;
else
query += "," + audioBitrate2;
@@ -767,7 +767,7 @@ namespace Handbrake.Functions
if (audioSampleRate2 != "")
{
- if (audioSampleRate1 == "")
+ if (audioSampleRate1 == string.Empty)
query += " -R 0," + audioSampleRate2.Replace("Auto", "0");
else
query += "," + audioSampleRate2.Replace("Auto", "0");
@@ -779,7 +779,7 @@ namespace Handbrake.Functions
if ((track2 != "") && (track2 != "None"))
{
- if (audioSampleRate1 == "")
+ if (audioSampleRate1 == string.Empty)
query += " -R 0,0";
else
query += ",0";
diff --git a/win/C#/Functions/Presets.cs b/win/C#/Functions/Presets.cs
index 2e725c52d..0e176b12a 100644
--- a/win/C#/Functions/Presets.cs
+++ b/win/C#/Functions/Presets.cs
@@ -1,5 +1,5 @@
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
@@ -10,8 +10,8 @@ namespace Handbrake.Functions
{
public class Presets
{
- ArrayList presets = new ArrayList();
- ArrayList user_presets = new ArrayList();
+ List<string> presets = new List<string>();
+ List<string> user_presets = new List<string>();
/// <summary>
/// Add a new preset to the system
@@ -40,8 +40,8 @@ namespace Handbrake.Functions
/// <param name="name">String, the preset name</param>
public void remove(string name)
{
- ArrayList newPresets = new ArrayList();
- ArrayList newUserPresets = new ArrayList();
+ List<string> newPresets = new List<string>();
+ List<string> newUserPresets = new List<string>();
// Built In Presets
foreach (string item in presets)
@@ -91,9 +91,9 @@ namespace Handbrake.Functions
/// Includes both built in and user presets.
/// </summary>
/// <returns>Arraylist of preset names</returns>
- public ArrayList getPresetNames()
+ public List<string> getPresetNames()
{
- ArrayList names = new ArrayList();
+ List<string> names = new List<string>();
// Built In Presets
foreach (string item in presets)
@@ -219,7 +219,7 @@ namespace Handbrake.Functions
// Check if a preset already exists in either the built in or user presets
private Boolean checkIfPresetExists(string name)
{
- if (name == "")
+ if (name == string.Empty)
return true;
// Built In Presets
diff --git a/win/C#/Functions/Queue.cs b/win/C#/Functions/Queue.cs
index ad4ecaf44..dc2345358 100644
--- a/win/C#/Functions/Queue.cs
+++ b/win/C#/Functions/Queue.cs
@@ -45,15 +45,8 @@ namespace Handbrake.Functions
/// <returns>Bolean true if successful</returns>
public Boolean remove(int index)
{
- try
- {
- queue.RemoveAt(index);
- return true;
- }
- catch (Exception)
- {
- return false;
- }
+ queue.RemoveAt(index);
+ return true;
}
/// <summary>
@@ -125,7 +118,7 @@ namespace Handbrake.Functions
}
catch (Exception)
{
- // Any Errors will be out of diskspace/permissions problems. Don't report them as they'll annoy the user.
+ // Any Errors will be out of diskspace/permissions problems. Don't report them as they'll annoy the user.
}
}
@@ -150,7 +143,7 @@ namespace Handbrake.Functions
}
catch (Exception exc)
{
- MessageBox.Show("HandBrake was unable to recover the queue. \nError Information:" + exc.ToString(),"Queue Recovery Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("HandBrake was unable to recover the queue. \nError Information:" + exc.ToString(), "Queue Recovery Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
diff --git a/win/C#/Functions/x264Panel.cs b/win/C#/Functions/x264Panel.cs
index 0101f0fcf..8a93a2121 100644
--- a/win/C#/Functions/x264Panel.cs
+++ b/win/C#/Functions/x264Panel.cs
@@ -232,7 +232,7 @@ namespace Handbrake.Functions
for (loopcounter = 0; loopcounter < currentOptsArrayCount; loopcounter++)
{
thisOpt = currentOptsArray[loopcounter];
- if (currentOptsArray[currentOptsArrayCount - 1] == "")
+ if (currentOptsArray[currentOptsArrayCount - 1] == string.Empty)
break;
String[] splitOptRange = thisOpt.Split('=');
@@ -257,11 +257,11 @@ namespace Handbrake.Functions
}
/* Construct New String for opts here */
- if (thisOpt == "")
+ if (thisOpt == string.Empty)
changedOptString = changedOptString + thisOpt;
else
{
- if (changedOptString == "")
+ if (changedOptString == string.Empty)
changedOptString = thisOpt;
else
changedOptString = changedOptString + ":" + thisOpt;
diff --git a/win/C#/Parsing/DVD.cs b/win/C#/Parsing/DVD.cs
index 1637c9154..d0802e4c9 100644
--- a/win/C#/Parsing/DVD.cs
+++ b/win/C#/Parsing/DVD.cs
@@ -11,7 +11,7 @@ using System.IO;
namespace Handbrake.Parsing
{
-
+
/// <summary>
/// An object representing a scanned DVD
/// </summary>
@@ -41,20 +41,15 @@ namespace Handbrake.Parsing
public static DVD Parse(StreamReader output)
{
DVD thisDVD = new DVD();
- try
- {
- while (!output.EndOfStream)
- {
- if ((char)output.Peek() == '+')
- thisDVD.m_titles.AddRange(Title.ParseList(output.ReadToEnd()));
- else
- output.ReadLine();
- }
- }
- catch (Exception exc)
+
+ while (!output.EndOfStream)
{
- MessageBox.Show("DVD.CS - Parse" + exc.ToString());
+ if ((char)output.Peek() == '+')
+ thisDVD.m_titles.AddRange(Title.ParseList(output.ReadToEnd()));
+ else
+ output.ReadLine();
}
+
return thisDVD;
}
}
diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs
index 86e8a5017..bbafc9295 100644
--- a/win/C#/Parsing/Parser.cs
+++ b/win/C#/Parsing/Parser.cs
@@ -64,7 +64,8 @@ namespace Handbrake.Parsing
/// Default constructor for this object
/// </summary>
/// <param name="baseStream">The stream to parse from</param>
- public Parser(Stream baseStream) : base(baseStream)
+ public Parser(Stream baseStream)
+ : base(baseStream)
{
this.m_buffer = string.Empty;
}
@@ -72,38 +73,26 @@ namespace Handbrake.Parsing
public override string ReadLine()
{
string tmp = base.ReadLine();
- try
- {
-
- this.m_buffer += tmp;
- Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");
- if (OnReadLine != null)
- OnReadLine(this, tmp);
-
- if (m.Success && OnScanProgress != null)
- OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
- }
- catch (Exception exc)
- {
- MessageBox.Show("Parser.cs - ReadLine " + exc.ToString());
- }
+
+ this.m_buffer += tmp;
+ Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");
+ if (OnReadLine != null)
+ OnReadLine(this, tmp);
+
+ if (m.Success && OnScanProgress != null)
+ OnScanProgress(this, int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
+
return tmp;
}
public override string ReadToEnd()
{
string tmp = base.ReadToEnd();
- try
- {
- this.m_buffer += tmp;
- if (OnReadToEnd != null)
- OnReadToEnd(this, tmp);
- }
- catch (Exception exc)
- {
- MessageBox.Show("Parser.cs - ReadToEnd " + exc.ToString());
- }
+ this.m_buffer += tmp;
+ if (OnReadToEnd != null)
+ OnReadToEnd(this, tmp);
+
return tmp;
}
}
diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs
index 5d21d89cb..14eacf165 100644
--- a/win/C#/Parsing/Title.cs
+++ b/win/C#/Parsing/Title.cs
@@ -142,44 +142,38 @@ namespace Handbrake.Parsing
public static Title Parse(StringReader output)
{
Title thisTitle = new Title();
- try
- {
- Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
- // Match track number for this title
- if (m.Success)
- thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
- output.ReadLine();
+ Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
+ // Match track number for this title
+ if (m.Success)
+ thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim().ToString());
- // Get duration for this title
+ output.ReadLine();
- m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
- if (m.Success)
- thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
+ // Get duration for this title
- // Get resolution, aspect ratio and FPS for this title
- m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
- if (m.Success)
- {
- thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
- thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value, Functions.Encode.Culture);
- }
+ m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
+ if (m.Success)
+ thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
- // Get autocrop region for this title
- m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
- if (m.Success)
- thisTitle.m_autoCrop = new int[4] { int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value) };
+ // Get resolution, aspect ratio and FPS for this title
+ m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
+ if (m.Success)
+ {
+ thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
+ thisTitle.m_aspectRatio = float.Parse(m.Groups[3].Value, Functions.Encode.Culture);
+ }
- thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
+ // Get autocrop region for this title
+ m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
+ if (m.Success)
+ thisTitle.m_autoCrop = new int[4] { 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.m_audioTracks.AddRange(AudioTrack.ParseList(output));
+ thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
- thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
- }
- catch (Exception exc)
- {
- MessageBox.Show("Title.cs - Parse " + exc.ToString());
- }
+ thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
+
+ thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
return thisTitle;
}
@@ -187,18 +181,13 @@ namespace Handbrake.Parsing
public static Title[] ParseList(string output)
{
List<Title> titles = new List<Title>();
- try
- {
- StringReader sr = new StringReader(output);
- while ((char)sr.Peek() == '+')
- {
- titles.Add(Title.Parse(sr));
- }
- }
- catch (Exception exc)
+
+ StringReader sr = new StringReader(output);
+ while ((char)sr.Peek() == '+')
{
- MessageBox.Show("Title.cs - ParseList " + exc.ToString());
+ titles.Add(Title.Parse(sr));
}
+
return titles.ToArray();
}
}
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs
index fad0efcad..f4f6b0442 100644
--- a/win/C#/frmActivityWindow.cs
+++ b/win/C#/frmActivityWindow.cs
@@ -6,6 +6,7 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
@@ -103,9 +104,10 @@ namespace Handbrake
private void updateTextFromThread()
{
string text = "";
- ArrayList data = readFile();
+ List<string> data = readFile();
+ int count = data.Count;
- while (position < data.Count)
+ while (position < count)
{
text = data[position].ToString();
if (data[position].ToString().Contains("has exited"))
@@ -132,11 +134,11 @@ namespace Handbrake
}
}
- private ArrayList readFile()
+ private List<string> readFile()
{
// Ok, the task here is to, Get an arraylist of log data.
// And update some global varibles which are pointers to the last displayed log line.
- ArrayList logData = new ArrayList();
+ List<string> logData = new List<string>();
try
{
diff --git a/win/C#/frmDownload.cs b/win/C#/frmDownload.cs
index b8b74d275..872ec87e7 100644
--- a/win/C#/frmDownload.cs
+++ b/win/C#/frmDownload.cs
@@ -35,62 +35,53 @@ namespace Handbrake
{
InitializeComponent();
- try
- {
- downloadThread = new Thread(Download);
- downloadThread.Start();
- }
- catch (Exception exc)
- {
- MessageBox.Show("An error occured on the Download Thread \n" + exc.ToString(),"Error",MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
+ downloadThread = new Thread(Download);
+ downloadThread.Start();
}
private void Download()
{
Functions.AppcastReader rssRead = new Functions.AppcastReader();
-
string tempPath = Path.Combine(Path.GetTempPath(), "handbrake-setup.exe");
+ string hbUpdate = rssRead.downloadFile();
+ WebClient wcDownload = new WebClient();
- if (File.Exists(tempPath))
- File.Delete(tempPath);
+ try
+ {
+ if (File.Exists(tempPath))
+ File.Delete(tempPath);
- string hbUpdate = rssRead.downloadFile();
+ webRequest = (HttpWebRequest)WebRequest.Create(hbUpdate);
+ webRequest.Credentials = CredentialCache.DefaultCredentials;
+ webResponse = (HttpWebResponse)webRequest.GetResponse();
+ Int64 fileSize = webResponse.ContentLength;
- WebClient wcDownload = new WebClient();
- try
- {
- webRequest = (HttpWebRequest)WebRequest.Create(hbUpdate);
- webRequest.Credentials = CredentialCache.DefaultCredentials;
- webResponse = (HttpWebResponse)webRequest.GetResponse();
- Int64 fileSize = webResponse.ContentLength;
-
- responceStream = wcDownload.OpenRead(hbUpdate);
- loacalStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.None);
-
- int bytesSize = 0;
- byte[] downBuffer = new byte[2048];
-
- long flength = 0;
- while ((bytesSize = responceStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
- {
- loacalStream.Write(downBuffer, 0, bytesSize);
- flength = loacalStream.Length;
- this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { loacalStream.Length, fileSize });
- }
-
- responceStream.Close();
- loacalStream.Close();
-
- if (flength != fileSize)
- this.Invoke(new DownloadFailedCallback(this.downloadFailed));
- else
- this.Invoke(new DownloadCompleteCallback(this.downloadComplete));
- }
- catch (Exception)
+ responceStream = wcDownload.OpenRead(hbUpdate);
+ loacalStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.None);
+
+ int bytesSize = 0;
+ byte[] downBuffer = new byte[2048];
+
+ long flength = 0;
+ while ((bytesSize = responceStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
- // Do Nothing
+ loacalStream.Write(downBuffer, 0, bytesSize);
+ flength = loacalStream.Length;
+ this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { loacalStream.Length, fileSize });
}
+
+ responceStream.Close();
+ loacalStream.Close();
+
+ if (flength != fileSize)
+ this.Invoke(new DownloadFailedCallback(this.downloadFailed));
+ else
+ this.Invoke(new DownloadCompleteCallback(this.downloadComplete));
+ }
+ catch (Exception)
+ {
+ // Do Nothing
+ }
}
private void UpdateProgress(Int64 BytesRead, Int64 TotalBytes)
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs
index d9a239d4c..69c2056f5 100644
--- a/win/C#/frmMain.cs
+++ b/win/C#/frmMain.cs
@@ -6,6 +6,7 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
@@ -62,7 +63,7 @@ namespace Handbrake
Properties.Settings.Default.hb_build = int.Parse(x[1].ToString());
Properties.Settings.Default.hb_version = x[0].ToString();
}
- catch (Exception)
+ catch (Exception)
{
Properties.Settings.Default.hb_build = 0;
Properties.Settings.Default.hb_version = "0";
@@ -160,19 +161,16 @@ namespace Handbrake
{
// Try to load the users default settings.
string userDefaults = Properties.Settings.Default.defaultUserSettings;
- try
- {
- Functions.QueryParser presetQuery = Functions.QueryParser.Parse(userDefaults);
- hb_common_func.presetLoader(this, presetQuery, "User Defaults ");
- }
- catch (Exception) { /* Do Nothing */ }
+
+ Functions.QueryParser presetQuery = Functions.QueryParser.Parse(userDefaults);
+ hb_common_func.presetLoader(this, presetQuery, "User Defaults ");
}
private void queueRecovery()
{
if (hb_common_func.check_queue_recovery() == true)
{
DialogResult result;
- result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?","Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ result = MessageBox.Show("HandBrake has detected unfinished items on the queue from the last time the application was launched. Would you like to recover these?", "Queue Recovery Possible", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
encodeQueue.recoverQueue(); // Start Recovery
@@ -332,7 +330,7 @@ namespace Handbrake
}
private void btn_start_Click(object sender, EventArgs e)
{
- if (text_source.Text == "" || text_source.Text == "Click 'Source' to continue" || text_destination.Text == "")
+ if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)
MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
@@ -354,7 +352,7 @@ namespace Handbrake
}
private void btn_add2Queue_Click(object sender, EventArgs e)
{
- if (text_source.Text == "" || text_source.Text == "Click 'Source' to continue" || text_destination.Text == "")
+ if (text_source.Text == string.Empty || text_source.Text == "Click 'Source' to continue" || text_destination.Text == string.Empty)
MessageBox.Show("No source OR destination selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
@@ -542,18 +540,12 @@ namespace Handbrake
drop_chapterStart.BackColor = Color.White;
if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
{
- try
- {
- int chapterFinish = int.Parse(drop_chapterFinish.Text);
- int chapterStart = int.Parse(drop_chapterStart.Text);
+ int chapterFinish, chapterStart = 0;
+ int.TryParse(drop_chapterFinish.Text, out chapterFinish);
+ int.TryParse(drop_chapterStart.Text, out chapterStart);
- if (chapterFinish < chapterStart)
- drop_chapterStart.BackColor = Color.LightCoral;
- }
- catch (Exception)
- {
+ if (chapterFinish < chapterStart)
drop_chapterStart.BackColor = Color.LightCoral;
- }
}
// Run the Autonaming function
hb_common_func.autoName(this);
@@ -565,18 +557,12 @@ namespace Handbrake
drop_chapterFinish.BackColor = Color.White;
if ((drop_chapterFinish.Text != "Auto") && (drop_chapterStart.Text != "Auto"))
{
- try
- {
- int chapterFinish = int.Parse(drop_chapterFinish.Text);
- int chapterStart = int.Parse(drop_chapterStart.Text);
+ int chapterFinish, chapterStart = 0;
+ int.TryParse(drop_chapterFinish.Text, out chapterFinish);
+ int.TryParse(drop_chapterStart.Text, out chapterStart);
- if (chapterFinish < chapterStart)
- drop_chapterFinish.BackColor = Color.LightCoral;
- }
- catch (Exception)
- {
+ if (chapterFinish < chapterStart)
drop_chapterFinish.BackColor = Color.LightCoral;
- }
}
// Run the Autonaming function
@@ -725,9 +711,11 @@ namespace Handbrake
//Picture Tab
private void text_width_TextChanged(object sender, EventArgs e)
{
- try
+ int width;
+ Boolean parsed = int.TryParse(text_width.Text, out width);
+ if (parsed != false)
{
- if ((int.Parse(text_width.Text) % 16) != 0)
+ if ((width % 16) != 0)
text_width.BackColor = Color.LightCoral;
else
text_width.BackColor = Color.LightGreen;
@@ -737,29 +725,23 @@ namespace Handbrake
{
if (drp_anamorphic.Text == "None")
{
- int height = cacluateNonAnamorphicHeight(int.Parse(text_width.Text));
+ int height = cacluateNonAnamorphicHeight(width);
text_height.Text = height.ToString();
}
}
}
- catch (Exception)
- {
- // No need to throw an error here.
- }
}
private void text_height_TextChanged(object sender, EventArgs e)
{
- try
+ int height;
+ Boolean parsed = int.TryParse(text_height.Text, out height);
+ if (parsed != false)
{
- if ((int.Parse(text_height.Text) % 16) != 0)
+ if ((height % 16) != 0)
text_height.BackColor = Color.LightCoral;
else
text_height.BackColor = Color.LightGreen;
}
- catch (Exception)
- {
- // No need to alert the user.
- }
}
private void drp_crop_SelectedIndexChanged(object sender, EventArgs e)
{
@@ -1369,7 +1351,7 @@ namespace Handbrake
x264PanelFunctions.X264_StandardizeOptString(this);
x264PanelFunctions.X264_SetCurrentSettingsInPanel(this);
- if (rtf_x264Query.Text == "")
+ if (rtf_x264Query.Text == string.Empty)
x264PanelFunctions.reset2Defaults(this);
}
}
@@ -1452,29 +1434,24 @@ namespace Handbrake
// Chapter Selection Duration calculation
public void calculateDuration()
{
- int start_chapter;
- int end_chapter;
TimeSpan Duration = TimeSpan.FromSeconds(0.0);
- try
+ // Get the durations between the 2 chapter points and add them together.
+ if (drop_chapterStart.Text != "Auto" && drop_chapterFinish.Text != "Auto")
{
- // Get the durations between the 2 chapter points and add them together.
- if (drop_chapterStart.Text != "Auto" && drop_chapterFinish.Text != "Auto")
- {
- start_chapter = int.Parse(drop_chapterStart.Text);
- end_chapter = int.Parse(drop_chapterFinish.Text);
+ int start_chapter, end_chapter = 0;
+ int.TryParse(drop_chapterStart.Text, out start_chapter);
+ int.TryParse(drop_chapterFinish.Text, out end_chapter);
- int position = start_chapter - 1;
+ int position = start_chapter - 1;
- while (position != end_chapter)
- {
- TimeSpan dur = selectedTitle.Chapters[position].Duration;
- Duration = Duration + dur;
- position++;
- }
+ while (position != end_chapter)
+ {
+ TimeSpan dur = selectedTitle.Chapters[position].Duration;
+ Duration = Duration + dur;
+ position++;
}
}
- catch (Exception) { /* Don't do anything */ }
// Set the Duration
lbl_duration.Text = Duration.ToString();
@@ -1633,7 +1610,7 @@ namespace Handbrake
drp_audenc_1.Items.Add("MP3");
drp_audenc_1.Items.Add("AC3");
drp_audenc_1.Items.Add("Vorbis");
- if (drp_audenc_1.Text == "")
+ if (drp_audenc_1.Text == string.Empty)
drp_audenc_1.SelectedIndex = 0;
@@ -1644,7 +1621,7 @@ namespace Handbrake
drp_audenc_2.Items.Add("Vorbis");
if (drp_audenc_2.Enabled)
{
- if (drp_audenc_2.Text == "")
+ if (drp_audenc_2.Text == string.Empty)
drp_audenc_2.SelectedIndex = 0;
}
@@ -1655,7 +1632,7 @@ namespace Handbrake
drp_audenc_3.Items.Add("Vorbis");
if (drp_audenc_3.Enabled)
{
- if (drp_audenc_3.Text == "")
+ if (drp_audenc_3.Text == string.Empty)
drp_audenc_3.SelectedIndex = 0;
}
@@ -1666,7 +1643,7 @@ namespace Handbrake
drp_audenc_4.Items.Add("Vorbis");
if (drp_audenc_4.Enabled)
{
- if (drp_audenc_4.Text == "")
+ if (drp_audenc_4.Text == string.Empty)
drp_audenc_4.SelectedIndex = 0;
}
}
@@ -1789,7 +1766,7 @@ namespace Handbrake
presetHandler.loadPresetFiles();
treeView_presets.Nodes.Clear();
- ArrayList presetNameList = new ArrayList();
+ List<string> presetNameList = new List<string>();
presetNameList = presetHandler.getPresetNames();
// Adds a new preset name to the preset list.
diff --git a/win/C#/frmUpdater.cs b/win/C#/frmUpdater.cs
index ac4f7f5c1..6252bb9b8 100644
--- a/win/C#/frmUpdater.cs
+++ b/win/C#/frmUpdater.cs
@@ -18,19 +18,19 @@ namespace Handbrake
public frmUpdater()
{
InitializeComponent();
-
+
getRss();
setVersions();
}
private void getRss()
- {
+ {
wBrowser.DocumentText = "<font face=\"verdana\" size=\"1\">" + rssRead.versionInfo() + "</font>";
}
private void setVersions()
{
- lbl_oldVersion.Text = "(you have: " + Properties.Settings.Default.hb_version + " / " + Properties.Settings.Default.hb_build + ").";
+ lbl_oldVersion.Text = "(you have: " + Properties.Settings.Default.hb_version + " / " + Properties.Settings.Default.hb_build + ").";
lbl_newVersion.Text = rssRead.version() + " (" + rssRead.build() + ")";
}
@@ -38,7 +38,7 @@ namespace Handbrake
{
frmDownload download = new frmDownload();
download.Show();
- this.Close();
+ this.Close();
}
private void btn_remindLater_Click(object sender, EventArgs e)
@@ -48,15 +48,9 @@ namespace Handbrake
private void btn_skip_Click(object sender, EventArgs e)
{
- try
- {
- Properties.Settings.Default.skipversion = int.Parse(rssRead.build());
- Properties.Settings.Default.Save();
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.ToString());
- }
+ Properties.Settings.Default.skipversion = int.Parse(rssRead.build());
+ Properties.Settings.Default.Save();
+
this.Close();
}