X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmDownload.cs;h=8b23df92b9d11db8116cfd6b1a844c05c7cbd725;hb=cfa1fb7010dc9324e15d257bad7a73af66e9eb10;hp=73020ff1b00863fdfaf771244b03857ccc1166db;hpb=a12b7c4e65e4e32c79d2dbaa2705ecf5692c7b0f;p=handbrake-jp%2Fhandbrake-jp-git.git
diff --git a/win/C#/frmDownload.cs b/win/C#/frmDownload.cs
index 73020ff1..8b23df92 100644
--- a/win/C#/frmDownload.cs
+++ b/win/C#/frmDownload.cs
@@ -1,15 +1,10 @@
/* frmDownload.cs $
This file is part of the HandBrake source code.
- Homepage: .
+ Homepage: .
It may be used under the terms of the GNU General Public License. */
using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
@@ -20,7 +15,7 @@ namespace Handbrake
{
public partial class frmDownload : Form
{
- private Thread downloadThread;
+ private readonly Thread downloadThread;
private Stream responceStream;
private Stream loacalStream;
private HttpWebRequest webRequest;
@@ -30,68 +25,59 @@ namespace Handbrake
private delegate void DownloadCompleteCallback();
private delegate void DownloadFailedCallback();
+ private string file;
- public frmDownload()
+ public frmDownload(string filename)
{
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);
- }
-
+ file = filename;
+ downloadThread = new Thread(Download);
+ downloadThread.Start();
}
private void Download()
{
- Functions.RssReader rssRead = new Functions.RssReader();
-
string tempPath = Path.Combine(Path.GetTempPath(), "handbrake-setup.exe");
+ string hbUpdate = file;
+ 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;
+ 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;
+ Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { loacalStream.Length, fileSize });
}
+
+ responceStream.Close();
+ loacalStream.Close();
+
+ if (flength != fileSize)
+ Invoke(new DownloadFailedCallback(this.downloadFailed));
+ else
+ Invoke(new DownloadCompleteCallback(this.downloadComplete));
+ }
+ catch (Exception)
+ {
+ // Do Nothing
+ }
}
private void UpdateProgress(Int64 BytesRead, Int64 TotalBytes)
@@ -105,7 +91,7 @@ namespace Handbrake
}
catch (Exception exc)
{
- MessageBox.Show("Integer Convertion Error On Download \n" + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Integer Conversion Error On Download \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
@@ -115,8 +101,7 @@ namespace Handbrake
btn_cancel.Text = "Close";
string tempPath = Path.Combine(Path.GetTempPath(), "handbrake-setup.exe");
-
- Process startInstall = Process.Start(tempPath);
+ Process.Start(tempPath);
this.Close();
Application.Exit();
}