Changeset 2725
- Timestamp:
- 6/27/2012 2:33:12 AM (11 months ago)
- Location:
- trunk/eraser
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
Eraser/UpdateForm.cs (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser
- Property svn:mergeinfo changed
/branches/eraser6/6.0 merged: 2720-2721,2724
- Property svn:mergeinfo changed
-
trunk/eraser/Eraser/UpdateForm.cs
r2516 r2725 34 34 using System.Net.Mime; 35 35 using System.Globalization; 36 using System.ComponentModel; 36 37 37 38 using Eraser.Util; … … 39 40 40 41 using DoWorkEventArgs = System.ComponentModel.DoWorkEventArgs; 42 using ProgressChangedEventArgs = Eraser.Plugins.ProgressChangedEventArgs; 41 43 using ProgressChangedEventHandler = Eraser.Plugins.ProgressChangedEventHandler; 42 44 using RunWorkerCompletedEventArgs = System.ComponentModel.RunWorkerCompletedEventArgs; … … 715 717 try 716 718 { 717 //Request the download. 718 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Link); 719 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 720 { 721 //Do the progress calculations 722 progress.Total = response.ContentLength; 723 724 //Check for a suggested filename. 725 ContentDisposition contentDisposition = null; 726 foreach (string header in response.Headers.AllKeys) 727 if (header.ToUpperInvariant() == "CONTENT-DISPOSITION") 728 contentDisposition = new ContentDisposition(response.Headers[header]); 729 730 //Create the file name. 731 DownloadedFile = new FileInfo(Path.Combine( 732 TempPath.FullName, string.Format(CultureInfo.InvariantCulture, 733 "{0:00}-{1}", ++DownloadFileIndex, contentDisposition == null ? 734 Path.GetFileName(Link.GetComponents(UriComponents.Path, UriFormat.Unescaped)) : 735 contentDisposition.FileName))); 736 737 using (Stream responseStream = response.GetResponseStream()) 738 using (FileStream fileStream = DownloadedFile.OpenWrite()) 719 Uri downloadLink = Link; 720 ContentDisposition contentDisposition = null; 721 for (int redirects = 0; redirects < 20; ++redirects) 722 { 723 //Request the download. 724 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(downloadLink); 725 request.AllowAutoRedirect = false; 726 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 739 727 { 740 //Copy the information into the file stream 741 int lastRead = 0; 742 byte[] buffer = new byte[16384]; 743 while ((lastRead = responseStream.Read(buffer, 0, buffer.Length)) != 0) 728 //Check for a suggested filename. Store this until we get the final URI. 729 foreach (string header in response.Headers.AllKeys) 730 if (header.ToUpperInvariant() == "CONTENT-DISPOSITION") 731 contentDisposition = new ContentDisposition(response.Headers[header]); 732 733 //Handle 3xx series response codes. 734 if ((int)response.StatusCode >= 300 && (int)response.StatusCode <= 399) 744 735 { 745 fileStream.Write(buffer, 0, lastRead); 746 747 //Compute progress 748 progress.Completed = fileStream.Position; 749 750 //Call the progress handler 751 if (handler != null) 752 handler(this, new ProgressChangedEventArgs(progress, null)); 736 //Redirect. 737 bool locationHeader = false; 738 foreach (string header in response.Headers.AllKeys) 739 if (header.ToUpperInvariant() == "LOCATION") 740 { 741 locationHeader = true; 742 downloadLink = new Uri(response.Headers[header]); 743 break; 744 } 745 746 if (!locationHeader) 747 throw new WebException("A redirect response was received but no redirection" + 748 "URI was provided."); 749 750 continue; 753 751 } 752 753 //Do the progress calculations 754 progress.Total = response.ContentLength; 755 756 //Create the file name. 757 DownloadedFile = new FileInfo(Path.Combine( 758 TempPath.FullName, string.Format(CultureInfo.InvariantCulture, 759 "{0:00}-{1}", ++DownloadFileIndex, contentDisposition == null ? 760 Path.GetFileName(downloadLink.GetComponents(UriComponents.Path, UriFormat.Unescaped)) : 761 contentDisposition.FileName))); 762 763 using (Stream responseStream = response.GetResponseStream()) 764 using (FileStream fileStream = DownloadedFile.OpenWrite()) 765 { 766 //Copy the information into the file stream 767 int lastRead = 0; 768 byte[] buffer = new byte[16384]; 769 while ((lastRead = responseStream.Read(buffer, 0, buffer.Length)) != 0) 770 { 771 fileStream.Write(buffer, 0, lastRead); 772 773 //Compute progress 774 progress.Completed = fileStream.Position; 775 776 //Call the progress handler 777 if (handler != null) 778 handler(this, new ProgressChangedEventArgs(progress, null)); 779 } 780 } 781 782 //Let the event handler know the download is complete. 783 progress.MarkComplete(); 784 if (handler != null) 785 handler(this, new ProgressChangedEventArgs(progress, null)); 786 return; 754 787 } 755 788 756 //Let the event handler know the download is complete. 757 progress.MarkComplete(); 758 if (handler != null) 759 handler(this, new ProgressChangedEventArgs(progress, null)); 789 throw new WebException("The server is not redirecting properly."); 760 790 } 761 791 } … … 781 811 info.UseShellExecute = true; 782 812 783 Process process = Process.Start(info); 784 process.WaitForExit(Int32.MaxValue); 813 try 814 { 815 Process process = Process.Start(info); 816 process.WaitForExit(Int32.MaxValue); 817 818 if (process.ExitCode != 0) 819 throw new ApplicationException(S._("Installation failed with exit code {0}", 820 process.ExitCode)); 821 } 822 catch (Win32Exception e) 823 { 824 if (e.ErrorCode != 1223) 825 throw; 826 827 throw new OperationCanceledException(S._("Installation cancelled"), e); 828 } 829 785 830 } 786 831
Note: See TracChangeset
for help on using the changeset viewer.
