1
0
mirror of https://github.com/chylex/Brotli-Builder.git synced 2025-04-16 00:15:42 +02:00

Update UI to time structure generation (deserialize/encode/transform)

This commit is contained in:
chylex 2019-10-01 18:42:41 +02:00
parent 10a0c7b42c
commit 7eb0420746
4 changed files with 71 additions and 36 deletions

View File

@ -48,8 +48,10 @@
this.flowPanelBlocks = new System.Windows.Forms.FlowLayoutPanel();
this.statusBar = new System.Windows.Forms.StatusBar();
this.statusBarPanelPadding1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeBits = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeStructure = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelPadding2 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeBits = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelPadding3 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeOutput = new System.Windows.Forms.StatusBarPanel();
this.timerRegenerationDelay = new System.Windows.Forms.Timer(this.components);
this.splitContainerRightBottom = new System.Windows.Forms.SplitContainer();
@ -60,8 +62,10 @@
this.splitContainerMain = new System.Windows.Forms.SplitContainer();
this.brotliMarkerInfoPanel = new BrotliBuilder.Components.BrotliMarkerInfoPanel();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeBits)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeStructure)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeBits)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeOutput)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainerRightBottom)).BeginInit();
this.splitContainerRightBottom.Panel1.SuspendLayout();
@ -252,8 +256,10 @@
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanelPadding1,
this.statusBarPanelTimeBits,
this.statusBarPanelTimeStructure,
this.statusBarPanelPadding2,
this.statusBarPanelTimeBits,
this.statusBarPanelPadding3,
this.statusBarPanelTimeOutput});
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(1264, 22);
@ -267,10 +273,10 @@
this.statusBarPanelPadding1.Name = "statusBarPanelPadding1";
this.statusBarPanelPadding1.Width = 12;
//
// statusBarPanelTimeBits
// statusBarPanelTimeStructure
//
this.statusBarPanelTimeBits.Name = "statusBarPanelTimeBits";
this.statusBarPanelTimeBits.Width = 200;
this.statusBarPanelTimeStructure.Name = "statusBarPanelTimeStructure";
this.statusBarPanelTimeStructure.Width = 200;
//
// statusBarPanelPadding2
//
@ -279,6 +285,18 @@
this.statusBarPanelPadding2.Name = "statusBarPanelPadding2";
this.statusBarPanelPadding2.Width = 9;
//
// statusBarPanelTimeBits
//
this.statusBarPanelTimeBits.Name = "statusBarPanelTimeBits";
this.statusBarPanelTimeBits.Width = 200;
//
// statusBarPanelPadding3
//
this.statusBarPanelPadding3.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanelPadding3.MinWidth = 9;
this.statusBarPanelPadding3.Name = "statusBarPanelPadding3";
this.statusBarPanelPadding3.Width = 9;
//
// statusBarPanelTimeOutput
//
this.statusBarPanelTimeOutput.Name = "statusBarPanelTimeOutput";
@ -420,8 +438,10 @@
this.Text = "Brotli Builder";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormMain_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeBits)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeStructure)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeBits)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeOutput)).EndInit();
this.splitContainerRightBottom.Panel1.ResumeLayout(false);
this.splitContainerRightBottom.Panel2.ResumeLayout(false);
@ -477,5 +497,7 @@
private System.Windows.Forms.MenuItem menuItemTransformSplitInsertCopyLengths;
private System.Windows.Forms.MenuItem menuItemWrapMarkerInfo;
private System.Windows.Forms.MenuItem menuItemCompareMarkers;
private System.Windows.Forms.StatusBarPanel statusBarPanelTimeStructure;
private System.Windows.Forms.StatusBarPanel statusBarPanelPadding3;
}
}

View File

@ -83,6 +83,21 @@ namespace BrotliBuilder{
#region File state handling
private void ResetStatusBars(string text){
statusBarPanelTimeStructure.Text = text;
statusBarPanelTimeBits.Text = text;
statusBarPanelTimeOutput.Text = text;
}
private void UpdateStatusBar(StatusBarPanel bar, string type, Stopwatch sw){
if (sw != null){
bar.Text = "Generated " + type + " in " + sw.ElapsedMilliseconds + " ms.";
}
else{
bar.Text = "Loaded " + type + ".";
}
}
private void HandleFileError(BrotliFileState.Error error, BrotliFilePanel panel){
Exception ex = error.Exception;
string message = ex.Message;
@ -125,9 +140,7 @@ namespace BrotliBuilder{
}
filePanel.InvalidatePanel();
statusBarPanelTimeBits.Text = "Generating...";
statusBarPanelTimeOutput.Text = "Generating...";
ResetStatusBars("Generating...");
break;
case BrotliFileState.Waiting _:
@ -136,26 +149,19 @@ namespace BrotliBuilder{
case BrotliFileState.HasStructure hasStructure:
RegenerateBuildingBlocks(hasStructure.File);
UpdateStatusBar(statusBarPanelTimeStructure, "structure", hasStructure.Stopwatch);
break;
case BrotliFileState.HasBits hasBits:
filePanel.UpdateBits(hasBits);
Stopwatch sw = hasBits.Stopwatch;
if (sw != null){
statusBarPanelTimeBits.Text = "Generated bit stream in " + sw.ElapsedMilliseconds + " ms.";
}
else{
statusBarPanelTimeBits.Text = "Loaded bit stream.";
}
UpdateStatusBar(statusBarPanelTimeBits, "bits", hasBits.Stopwatch);
break;
case BrotliFileState.Loaded loaded:
filePanel.UpdateOutput(loaded);
UpdateStatusBar(statusBarPanelTimeOutput, "output", loaded.Stopwatch);
lastGeneratedFile = loaded.File;
statusBarPanelTimeOutput.Text = "Generated output in " + loaded.Stopwatch.ElapsedMilliseconds + " ms.";
if (brotliFilePanelOriginal.MarkerSequence != null && brotliFilePanelGenerated.MarkerSequence != null){
menuItemCompareMarkers.Enabled = true;
@ -183,9 +189,7 @@ namespace BrotliBuilder{
flowPanelBlocks.Controls.Clear();
fileGenerated.ResetToWaiting();
filePanel.InvalidatePanel();
statusBarPanelTimeBits.Text = "Loading...";
statusBarPanelTimeOutput.Text = "Loading...";
ResetStatusBars("Loading...");
isDirty = false;
skipNextBlockRegeneration = false;

View File

@ -64,8 +64,8 @@ namespace BrotliBuilder.State{
BitStream bits = new BitStream(bytes);
UpdateState(token, new BrotliFileState.HasBits(bits.ToString(), null));
if (!TryDeserialize(token, bytes, out BrotliFileStructure structure)) return;
UpdateState(token, new BrotliFileState.HasStructure(structure));
if (!TryDeserialize(token, bytes, out BrotliFileStructure structure, out Stopwatch swDeserialize)) return;
UpdateState(token, new BrotliFileState.HasStructure(structure, swDeserialize));
if (!TryGetDecompressionState(token, structure, bits, out BrotliOutputStored output, out Stopwatch swOutput)) return;
UpdateState(token, new BrotliFileState.Loaded(structure, bits, output, swOutput));
@ -73,7 +73,7 @@ namespace BrotliBuilder.State{
public void LoadStructure(BrotliFileStructure structure) => StartWorker(token => {
UpdateState(token, new BrotliFileState.Starting());
UpdateState(token, new BrotliFileState.HasStructure(structure));
UpdateState(token, new BrotliFileState.HasStructure(structure, null));
if (!TrySerialize(token, structure, out BitStream bits, out Stopwatch stopwatch)) return;
UpdateState(token, new BrotliFileState.HasBits(bits.ToString(), stopwatch));
@ -86,8 +86,8 @@ namespace BrotliBuilder.State{
UpdateState(token, new BrotliFileState.Starting());
if (!TryReadFile(token, path, out byte[] bytes)) return;
if (!TryEncode(token, bytes, parameters, encoder, out BrotliFileStructure structure)) return;
UpdateState(token, new BrotliFileState.HasStructure(structure));
if (!TryEncode(token, bytes, parameters, encoder, out BrotliFileStructure structure, out Stopwatch swEncode)) return;
UpdateState(token, new BrotliFileState.HasStructure(structure, swEncode));
if (!TrySerialize(token, structure, out BitStream bits, out Stopwatch swSerialization)) return;
UpdateState(token, new BrotliFileState.HasBits(bits.ToString(), swSerialization));
@ -99,8 +99,8 @@ namespace BrotliBuilder.State{
private void TransformInternal(BrotliFileStructure structure, IBrotliTransformer transformer) => StartWorker(token => {
UpdateState(token, new BrotliFileState.Starting());
if (!TryTransform(token, structure, transformer, out structure)) return;
UpdateState(token, new BrotliFileState.HasStructure(structure));
if (!TryTransform(token, structure, transformer, out structure, out Stopwatch swTransform)) return;
UpdateState(token, new BrotliFileState.HasStructure(structure, swTransform));
if (!TrySerialize(token, structure, out BitStream bits, out Stopwatch swSerialization)) return;
UpdateState(token, new BrotliFileState.HasBits(bits.ToString(), swSerialization));
@ -135,12 +135,15 @@ namespace BrotliBuilder.State{
}
}
private bool TryDeserialize(int token, byte[] bytes, out BrotliFileStructure structure){
private bool TryDeserialize(int token, byte[] bytes, out BrotliFileStructure structure, out Stopwatch stopwatch){
try{
stopwatch = Stopwatch.StartNew();
structure = BrotliFileStructure.FromBytes(bytes);
stopwatch.Stop();
return true;
}catch(Exception ex){
structure = null;
stopwatch = null;
return OnError(token, ErrorType.DeserializingFile, ex);
}
}
@ -158,22 +161,28 @@ namespace BrotliBuilder.State{
}
}
private bool TryEncode(int token, byte[] bytes, BrotliFileParameters parameters, IBrotliEncoder encoder, out BrotliFileStructure file){
private bool TryEncode(int token, byte[] bytes, BrotliFileParameters parameters, IBrotliEncoder encoder, out BrotliFileStructure file, out Stopwatch stopwatch){
try{
stopwatch = Stopwatch.StartNew();
file = BrotliFileStructure.FromEncoder(parameters, encoder, bytes);
stopwatch.Stop();
return true;
}catch(Exception ex){
file = null;
stopwatch = null;
return OnError(token, ErrorType.EncodingBytes, ex);
}
}
private bool TryTransform(int token, BrotliFileStructure structure, IBrotliTransformer transformer, out BrotliFileStructure transformed){
private bool TryTransform(int token, BrotliFileStructure structure, IBrotliTransformer transformer, out BrotliFileStructure transformed, out Stopwatch stopwatch){
try{
stopwatch = Stopwatch.StartNew();
transformed = structure.Transform(transformer);
stopwatch.Stop();
return true;
}catch(Exception ex){
transformed = null;
stopwatch = null;
return OnError(token, ErrorType.TransformingStructure, ex);
}
}

View File

@ -22,10 +22,10 @@ namespace BrotliBuilder.State{
public sealed class Waiting : BrotliFileState{}
public sealed class Starting : BrotliFileState{}
public sealed class HasStructure : BrotliFileState{
public sealed class HasStructure : TimedBrotliFileState{
public BrotliFileStructure File { get; }
public HasStructure(BrotliFileStructure file){
public HasStructure(BrotliFileStructure file, Stopwatch stopwatch) : base(stopwatch){
this.File = file;
}
}