Changeset 1392


Ignore:
Timestamp:
12/21/2009 5:54:07 AM (5 years ago)
Author:
lowjoel
Message:

Compress the crash report before uploading.

Location:
branches/eraser6/BlackBox
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/BlackBox/Eraser/BlackBoxUploadForm.Designer.cs

    r1389 r1392  
    3333            this.CancelBtn = new System.Windows.Forms.Button(); 
    3434            this.TitleLbl = new System.Windows.Forms.Label(); 
    35             this.progressBar1 = new System.Windows.Forms.ProgressBar(); 
     35            this.ProgressPb = new System.Windows.Forms.ProgressBar(); 
     36            this.UploadWorker = new System.ComponentModel.BackgroundWorker(); 
     37            this.ProgressLbl = new System.Windows.Forms.Label(); 
    3638            this.ButtonsPnl.SuspendLayout(); 
    3739            this.SuspendLayout(); 
     
    7981            this.TitleLbl.Text = "Uploading Crash Report"; 
    8082            //  
    81             // progressBar1 
     83            // ProgressPb 
    8284            //  
    83             this.progressBar1.Location = new System.Drawing.Point(13, 73); 
    84             this.progressBar1.Name = "progressBar1"; 
    85             this.progressBar1.Size = new System.Drawing.Size(321, 17); 
    86             this.progressBar1.TabIndex = 3; 
     85            this.ProgressPb.Location = new System.Drawing.Point(13, 73); 
     86            this.ProgressPb.Name = "ProgressPb"; 
     87            this.ProgressPb.Size = new System.Drawing.Size(321, 17); 
     88            this.ProgressPb.TabIndex = 3; 
     89            //  
     90            // UploadWorker 
     91            //  
     92            this.UploadWorker.WorkerReportsProgress = true; 
     93            this.UploadWorker.WorkerSupportsCancellation = true; 
     94            this.UploadWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.UploadWorker_DoWork); 
     95            this.UploadWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.UploadWorker_RunWorkerCompleted); 
     96            this.UploadWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.UploadWorker_ProgressChanged); 
     97            //  
     98            // ProgressLbl 
     99            //  
     100            this.ProgressLbl.AutoSize = true; 
     101            this.ProgressLbl.Location = new System.Drawing.Point(11, 55); 
     102            this.ProgressLbl.Name = "ProgressLbl"; 
     103            this.ProgressLbl.Size = new System.Drawing.Size(126, 15); 
     104            this.ProgressLbl.TabIndex = 4; 
     105            this.ProgressLbl.Text = "Compressing reports..."; 
    87106            //  
    88107            // BlackBoxUploadForm 
     
    92111            this.BackColor = System.Drawing.SystemColors.Window; 
    93112            this.ClientSize = new System.Drawing.Size(344, 132); 
    94             this.Controls.Add(this.progressBar1); 
     113            this.Controls.Add(this.ProgressLbl); 
     114            this.Controls.Add(this.ProgressPb); 
    95115            this.Controls.Add(this.TitleLbl); 
    96116            this.Controls.Add(this.ButtonsPnl); 
     
    113133        private System.Windows.Forms.Button CancelBtn; 
    114134        private System.Windows.Forms.Label TitleLbl; 
    115         private System.Windows.Forms.ProgressBar progressBar1; 
     135        private System.Windows.Forms.ProgressBar ProgressPb; 
     136        private System.ComponentModel.BackgroundWorker UploadWorker; 
     137        private System.Windows.Forms.Label ProgressLbl; 
    116138    } 
    117139} 
  • branches/eraser6/BlackBox/Eraser/BlackBoxUploadForm.cs

    r1389 r1392  
    44using System.Data; 
    55using System.Drawing; 
    6 using System.Linq; 
    76using System.Text; 
    87using System.Windows.Forms; 
     8using System.IO; 
     9 
    910using Eraser.Util; 
     11using ICSharpCode.SharpZipLib.Tar; 
     12using ICSharpCode.SharpZipLib.BZip2; 
    1013 
    1114namespace Eraser 
     
    1316    public partial class BlackBoxUploadForm : Form 
    1417    { 
    15         public BlackBoxUploadForm() 
     18        /// <summary> 
     19        /// Constructor. 
     20        /// </summary> 
     21        /// <param name="reports">The list of reports to upload.</param> 
     22        public BlackBoxUploadForm(IList<BlackBoxReport> reports) 
    1623        { 
    1724            InitializeComponent(); 
    1825            UXThemeApi.UpdateControlTheme(this); 
     26 
     27            Reports = reports; 
     28            UploadWorker.RunWorkerAsync(reports); 
    1929        } 
     30 
     31        private void UploadWorker_DoWork(object sender, DoWorkEventArgs e) 
     32        { 
     33            IList<BlackBoxReport> reports = (IList<BlackBoxReport>)e.Argument; 
     34            string uploadDir = Path.Combine(Path.GetTempPath(), "Eraser Crash Reports"); 
     35            if (!Directory.Exists(uploadDir)) 
     36                Directory.CreateDirectory(uploadDir); 
     37 
     38            for (int i = 0; i < reports.Count; ++i) 
     39            { 
     40                //Generate the base name of the report. 
     41                string reportBaseName = Path.Combine(uploadDir, reports[i].Name); 
     42 
     43                //Calculate the base progress percentage for this job. Add values up to 10 
     44                //to indicate report progress 
     45                int baseProgress = i * 100 / reports.Count; 
     46                int stepsPerReport = 100 / reports.Count; 
     47 
     48                using (FileStream archiveStream = new FileStream(reportBaseName + ".tar", 
     49                    FileMode.Create, FileAccess.Write)) 
     50                { 
     51                    UploadWorker.ReportProgress(baseProgress, 
     52                        S._("Compressing Report {0}", reports[i].Name)); 
     53 
     54                    //Add the report into a tar file 
     55                    TarArchive archive = TarArchive.CreateOutputTarArchive(archiveStream); 
     56                    foreach (FileInfo file in reports[i].Files) 
     57                        archive.WriteEntry(TarEntry.CreateEntryFromFile(file.FullName), false); 
     58                    archive.Close(); 
     59                } 
     60 
     61                using (FileStream tarStream = new FileStream(reportBaseName + ".tar", 
     62                    FileMode.Open, FileAccess.Read)) 
     63                using (FileStream bzipFile = new FileStream(reportBaseName + ".tbz", 
     64                    FileMode.Create)) 
     65                using (BZip2OutputStream bzipStream = new BZip2OutputStream(bzipFile, 262144)) 
     66                { 
     67                    //Compress the tar file 
     68                    byte[] buffer = new byte[524288]; 
     69                    int lastRead = 0; 
     70                    while ((lastRead = tarStream.Read(buffer, 0, buffer.Length)) != 0) 
     71                    { 
     72                        bzipStream.Write(buffer, 0, lastRead); 
     73                        UploadWorker.ReportProgress(baseProgress + 
     74                            (int)(tarStream.Position * stepsPerReport / tarStream.Length / 2)); 
     75                    } 
     76 
     77                    //Upload the file 
     78                    UploadWorker.ReportProgress(baseProgress, 
     79                        S._("Uploading Report {0}", reports[i].Name)); 
     80                } 
     81            } 
     82        } 
     83 
     84        private void UploadWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) 
     85        { 
     86            if (e.UserState != null) 
     87                ProgressLbl.Text = e.UserState as string; 
     88            ProgressPb.Value = e.ProgressPercentage; 
     89        } 
     90 
     91        private void UploadWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
     92        { 
     93 
     94        } 
     95 
     96        private ICollection<BlackBoxReport> Reports; 
    2097    } 
    2198} 
  • branches/eraser6/BlackBox/Eraser/BlackBoxUploadForm.resx

    r1389 r1392  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> 
    119119  </resheader> 
     120  <metadata name="UploadWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 
     121    <value>17, 17</value> 
     122  </metadata> 
    120123</root> 
  • branches/eraser6/BlackBox/Eraser/Eraser.csproj

    r1389 r1392  
    5959      <HintPath>..\Dependencies\DragDropLib.dll</HintPath> 
    6060    </Reference> 
     61    <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL"> 
     62      <SpecificVersion>False</SpecificVersion> 
     63      <HintPath>..\Dependencies\ICSharpCode.SharpZipLib.dll</HintPath> 
     64    </Reference> 
    6165    <Reference Include="System" /> 
    6266    <Reference Include="System.Core"> 
  • branches/eraser6/BlackBox/Eraser/MainForm.cs

    r1389 r1392  
    7070        { 
    7171            BlackBox blackBox = BlackBox.Get(); 
    72             string[] dumps = blackBox.GetDumps(); 
    73             if (dumps.Length == 0) 
     72            if (blackBox.GetDumps().Length == 0) 
    7473                return; 
    7574 
  • branches/eraser6/BlackBox/Eraser/Strings.NL.resx

    r1356 r1392  
    139139    <value>(Untranslated)</value> 
    140140  </data> 
     141  <data name="Compressing Report {0}" xml:space="preserve"> 
     142    <value>(Untranslated)</value> 
     143  </data> 
     144  <data name="Uploading Report {0}" xml:space="preserve"> 
     145    <value>(Untranslated)</value> 
     146  </data> 
    141147  <data name="Session: {0:F}" xml:space="preserve"> 
    142148    <value>(Untranslated)</value> 
  • branches/eraser6/BlackBox/Eraser/Strings.en.resx

    r1356 r1392  
    139139    <value>Please help us to continue developing Eraser - donate some coffee!</value> 
    140140  </data> 
     141  <data name="Compressing Report {0}" xml:space="preserve"> 
     142    <value>Compressing Report {0}</value> 
     143  </data> 
     144  <data name="Uploading Report {0}" xml:space="preserve"> 
     145    <value>Uploading Report {0}</value> 
     146  </data> 
    141147  <data name="Session: {0:F}" xml:space="preserve"> 
    142148    <value>Session: {0:F}</value> 
  • branches/eraser6/BlackBox/Eraser/Strings.it.resx

    r1365 r1392  
    139139    <value>Aiutateci a continuare lo sviluppo di Eraser - offriteci un caffè!</value> 
    140140  </data> 
     141  <data name="Compressing Report {0}" xml:space="preserve"> 
     142    <value>(Untranslated)</value> 
     143  </data> 
     144  <data name="Uploading Report {0}" xml:space="preserve"> 
     145    <value>(Untranslated)</value> 
     146  </data> 
    141147  <data name="Session: {0:F}" xml:space="preserve"> 
    142148    <value>Sessione: {0:F}</value> 
  • branches/eraser6/BlackBox/Eraser/Strings.resx

    r1356 r1392  
    139139    <value>Please help us to continue developing Eraser - donate some coffee!</value> 
    140140  </data> 
     141  <data name="Compressing Report {0}" xml:space="preserve"> 
     142    <value>Compressing Report {0}</value> 
     143  </data> 
     144  <data name="Uploading Report {0}" xml:space="preserve"> 
     145    <value>Uploading Report {0}</value> 
     146  </data> 
    141147  <data name="Session: {0:F}" xml:space="preserve"> 
    142148    <value>Session: {0:F}</value> 
Note: See TracChangeset for help on using the changeset viewer.