summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2009-12-03 16:49:41 +0000
committersr55 <[email protected]>2009-12-03 16:49:41 +0000
commit7fcdab64f2b7c161b19b8cd0250cfbb799729759 (patch)
treef4ceebb6f00d651102a2843ebc5a2bb0d7868ace
parentb993d4fee1ecb820739bff92ffc8f4cf00a0b558 (diff)
WinGui:
- Some minor code refactoring git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3000 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--win/C#/frmAddPreset.cs29
-rw-r--r--win/C#/frmDownload.cs101
-rw-r--r--win/C#/frmUpdater.cs20
3 files changed, 63 insertions, 87 deletions
diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs
index 8ffd76320..256b9b9fc 100644
--- a/win/C#/frmAddPreset.cs
+++ b/win/C#/frmAddPreset.cs
@@ -12,42 +12,33 @@ namespace Handbrake
{
public partial class frmAddPreset : Form
{
- private readonly frmMain frmMainWindow;
- readonly Presets.PresetsHandler presetCode;
- private readonly string query = "";
+ private readonly frmMain _frmMainWindow;
+ readonly Presets.PresetsHandler _presetCode;
+ private readonly string _query = "";
- public frmAddPreset(frmMain fmw, string query_string, Presets.PresetsHandler presetHandler)
+ public frmAddPreset(frmMain fmw, string queryString, Presets.PresetsHandler presetHandler)
{
InitializeComponent();
- frmMainWindow = fmw;
- presetCode = presetHandler;
- this.query = query_string;
+ _frmMainWindow = fmw;
+ _presetCode = presetHandler;
+ this._query = queryString;
}
private void btn_add_Click(object sender, EventArgs e)
{
- Boolean pictureSettings = false;
- if (check_pictureSettings.Checked)
- pictureSettings = true;
-
- if (presetCode.Add(txt_preset_name.Text.Trim(), query, pictureSettings))
+ if (_presetCode.Add(txt_preset_name.Text.Trim(), _query, check_pictureSettings.Checked))
{
- TreeNode preset_treeview = new TreeNode(txt_preset_name.Text.Trim()) { ForeColor = Color.Black };
- frmMainWindow.treeView_presets.Nodes.Add(preset_treeview);
-
- //frmMainWindow.loadPresetPanel();
+ TreeNode presetTreeview = new TreeNode(txt_preset_name.Text.Trim()) { ForeColor = Color.Black };
+ _frmMainWindow.treeView_presets.Nodes.Add(presetTreeview);
this.Close();
}
else
- {
MessageBox.Show("Sorry, that preset name already exists. Please choose another!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
}
private void btn_cancel_Click(object sender, EventArgs e)
{
this.Close();
}
-
}
} \ No newline at end of file
diff --git a/win/C#/frmDownload.cs b/win/C#/frmDownload.cs
index 8b23df92b..72b0fdef9 100644
--- a/win/C#/frmDownload.cs
+++ b/win/C#/frmDownload.cs
@@ -15,31 +15,30 @@ namespace Handbrake
{
public partial class frmDownload : Form
{
- private readonly Thread downloadThread;
- private Stream responceStream;
- private Stream loacalStream;
- private HttpWebRequest webRequest;
- private HttpWebResponse webResponse;
- private static int progress;
- private delegate void UpdateProgessCallback(Int64 BytesRead, Int64 TotalBytes);
+ private readonly Thread _downloadThread;
+ private Stream _responceStream;
+ private Stream _loacalStream;
+ private HttpWebRequest _webRequest;
+ private HttpWebResponse _webResponse;
+ private static int _progress;
+ private Boolean _killThread;
+ private delegate void UpdateProgessCallback(Int64 bytesRead, Int64 totalBytes);
private delegate void DownloadCompleteCallback();
private delegate void DownloadFailedCallback();
- private string file;
public frmDownload(string filename)
{
InitializeComponent();
- file = filename;
- downloadThread = new Thread(Download);
- downloadThread.Start();
+ _downloadThread = new Thread(Download);
+ _downloadThread.Start(filename);
}
- private void Download()
+ private void Download(object file)
{
string tempPath = Path.Combine(Path.GetTempPath(), "handbrake-setup.exe");
- string hbUpdate = file;
+ string hbUpdate = (string)file;
WebClient wcDownload = new WebClient();
try
@@ -47,66 +46,60 @@ namespace Handbrake
if (File.Exists(tempPath))
File.Delete(tempPath);
- webRequest = (HttpWebRequest)WebRequest.Create(hbUpdate);
- webRequest.Credentials = CredentialCache.DefaultCredentials;
- webResponse = (HttpWebResponse)webRequest.GetResponse();
- Int64 fileSize = webResponse.ContentLength;
+ _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);
+ _responceStream = wcDownload.OpenRead(hbUpdate);
+ _loacalStream = new FileStream(tempPath, FileMode.Create, FileAccess.Write, FileShare.None);
int bytesSize;
byte[] downBuffer = new byte[2048];
long flength = 0;
- while ((bytesSize = responceStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
+ while ((bytesSize = _responceStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
- loacalStream.Write(downBuffer, 0, bytesSize);
- flength = loacalStream.Length;
- Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { loacalStream.Length, fileSize });
+ if (_killThread)
+ return;
+ _loacalStream.Write(downBuffer, 0, bytesSize);
+ flength = _loacalStream.Length;
+ Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { _loacalStream.Length, fileSize });
}
- responceStream.Close();
- loacalStream.Close();
+ _responceStream.Close();
+ _loacalStream.Close();
if (flength != fileSize)
- Invoke(new DownloadFailedCallback(this.downloadFailed));
+ Invoke(new DownloadFailedCallback(this.DownloadFailed));
else
- Invoke(new DownloadCompleteCallback(this.downloadComplete));
+ Invoke(new DownloadCompleteCallback(this.DownloadComplete));
}
- catch (Exception)
+ catch
{
// Do Nothing
}
}
- private void UpdateProgress(Int64 BytesRead, Int64 TotalBytes)
+ private void UpdateProgress(Int64 bytesRead, Int64 totalBytes)
{
- try
- {
- long p = (BytesRead * 100) / TotalBytes;
- progress = int.Parse(p.ToString());
- progress_download.Value = progress;
- lblProgress.Text = (BytesRead / 1024) + "k of " + (TotalBytes / 1024) + "k ";
- }
- catch (Exception exc)
- {
- MessageBox.Show("Integer Conversion Error On Download \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
+ long p = (bytesRead * 100) / totalBytes;
+ int.TryParse(p.ToString(), out _progress);
+ progress_download.Value = _progress;
+ lblProgress.Text = (bytesRead / 1024) + "k of " + (totalBytes / 1024) + "k ";
}
- private void downloadComplete()
+ private void DownloadComplete()
{
lblProgress.Text = "Download Complete";
btn_cancel.Text = "Close";
- string tempPath = Path.Combine(Path.GetTempPath(), "handbrake-setup.exe");
- Process.Start(tempPath);
+ Process.Start(Path.Combine(Path.GetTempPath(), "handbrake-setup.exe"));
this.Close();
Application.Exit();
}
- private void downloadFailed()
+ private void DownloadFailed()
{
lblProgress.Text = "Download Failed";
btn_cancel.Text = "Close";
@@ -114,20 +107,12 @@ namespace Handbrake
private void btn_cancel_Click(object sender, EventArgs e)
{
- try
- {
- webResponse.Close();
- responceStream.Close();
- loacalStream.Close();
- downloadThread.Abort();
- progress_download.Value = 0;
- lblProgress.Text = "Download Stopped";
- this.Close();
- }
- catch (Exception)
- {
- // Do nothing
- }
+ _killThread = true;
+ lblProgress.Text = "Cancelling ...";
+ if (_webResponse != null) _webResponse.Close();
+ if (_responceStream != null) _responceStream.Close();
+ if (_loacalStream != null) _loacalStream.Close();
+ this.Close();
}
}
} \ No newline at end of file
diff --git a/win/C#/frmUpdater.cs b/win/C#/frmUpdater.cs
index 789a620fc..816e00fac 100644
--- a/win/C#/frmUpdater.cs
+++ b/win/C#/frmUpdater.cs
@@ -12,31 +12,31 @@ namespace Handbrake
{
public partial class frmUpdater : Form
{
- AppcastReader appcast;
+ readonly AppcastReader _appcast;
public frmUpdater(AppcastReader reader)
{
InitializeComponent();
- appcast = reader;
- getRss();
- setVersions();
+ _appcast = reader;
+ GetRss();
+ SetVersions();
}
- private void getRss()
+ private void GetRss()
{
- wBrowser.Url = appcast.descriptionUrl;
+ wBrowser.Url = _appcast.descriptionUrl;
}
- private void setVersions()
+ private void SetVersions()
{
string old = "(You have: " + Properties.Settings.Default.hb_version.Trim() + " / " + Properties.Settings.Default.hb_build.ToString().Trim() + ")";
- string newBuild = appcast.version.Trim() + " (" + appcast.build + ")";
+ string newBuild = _appcast.version.Trim() + " (" + _appcast.build + ")";
lbl_update_text.Text = "HandBrake " + newBuild + " is now available. " + old;
}
private void btn_installUpdate_Click(object sender, EventArgs e)
{
- frmDownload download = new frmDownload(appcast.downloadFile);
+ frmDownload download = new frmDownload(_appcast.downloadFile);
download.ShowDialog();
this.Close();
}
@@ -48,7 +48,7 @@ namespace Handbrake
private void btn_skip_Click(object sender, EventArgs e)
{
- Properties.Settings.Default.skipversion = int.Parse(appcast.build);
+ Properties.Settings.Default.skipversion = int.Parse(_appcast.build);
Properties.Settings.Default.Save();
this.Close();