X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=win%2FC%23%2FfrmDownload.cs;h=8b23df92b9d11db8116cfd6b1a844c05c7cbd725;hb=cfa1fb7010dc9324e15d257bad7a73af66e9eb10;hp=b8b74d2757090eeea81992223d554aecb4d37be5;hpb=4e3111f326a09f5fab0602b974636668dd6c6006;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/win/C#/frmDownload.cs b/win/C#/frmDownload.cs index b8b74d27..8b23df92 100644 --- a/win/C#/frmDownload.cs +++ b/win/C#/frmDownload.cs @@ -5,11 +5,6 @@ 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,67 +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.AppcastReader rssRead = new Functions.AppcastReader(); - 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) @@ -104,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); } } @@ -114,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(); }