Skip to content
This repository was archived by the owner on Dec 22, 2019. It is now read-only.

Commit 32b62cf

Browse files
committed
refactor
1 parent a612634 commit 32b62cf

11 files changed

Lines changed: 204 additions & 24 deletions

UpdateLib/UpdateLib.Generator/Tasks/UpdateGeneratorTask.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using MatthiWare.UpdateLib.Generator.Data.FilesPage;
88
using System.Collections.Generic;
99
using MatthiWare.UpdateLib.Generator.UI.Pages;
10+
using MatthiWare.UpdateLib.Logging;
1011

1112
namespace MatthiWare.UpdateLib.Generator.Tasks
1213
{
@@ -53,6 +54,8 @@ protected override void DoWork()
5354

5455
private void AddDirRecursive(GenFolder dir, DirectoryEntry entry)
5556
{
57+
Logger.Debug(GetType().Name, $"Thread: {Thread.CurrentThread.ManagedThreadId}");
58+
5659
List<GenFile> files = dir.Files;
5760
foreach (GenFile genFile in files)
5861
{
@@ -76,8 +79,10 @@ private void AddDirRecursive(GenFolder dir, DirectoryEntry entry)
7679
DirectoryEntry newEntry = new DirectoryEntry(string.IsNullOrEmpty(newDir.PathVariable) ? newDir.Name : newDir.PathVariable);
7780
entry.Directories.Add(newEntry);
7881

79-
AddDirRecursiveDelegate caller = new AddDirRecursiveDelegate(AddDirRecursive);
80-
Enqueue(caller, newDir, newEntry);
82+
//AddDirRecursiveDelegate caller = new AddDirRecursiveDelegate(AddDirRecursive);
83+
//Enqueue(caller, newDir, newEntry);
84+
85+
AddDirRecursive(newDir, newEntry);
8186
}
8287
}
8388
}

UpdateLib/UpdateLib.Generator/UI/Pages/BuilderPage.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UpdateLib/UpdateLib.Generator/UI/Pages/BuilderPage.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using MatthiWare.UpdateLib.Tasks;
1313
using MatthiWare.UpdateLib.Generator.Tasks;
1414
using MatthiWare.UpdateLib.Files;
15+
using System.Diagnostics;
16+
using MatthiWare.UpdateLib.Logging;
1517

1618
namespace MatthiWare.UpdateLib.Generator.UI.Pages
1719
{
@@ -27,7 +29,7 @@ public BuilderPage()
2729

2830
protected override void OnPageInitialize()
2931
{
30-
saveFileDialog.InitialDirectory = new DirectoryInfo("./Output").FullName;
32+
saveFileDialog.InitialDirectory = new DirectoryInfo("./Output").FullName;
3133

3234
PageControlBase page;
3335
if (!TestForm.TryGetPage(nameof(FilesPage), out page))
@@ -62,6 +64,8 @@ private void btnBuild_Click(object sender, EventArgs e)
6264
Build(saveFileDialog.OpenFile());
6365
}
6466

67+
Stopwatch sw = new Stopwatch();
68+
6569
private AsyncTask<UpdateFile> Build(Stream s)
6670
{
6771
UpdateGeneratorTask task = new UpdateGeneratorTask(filesPage.Root, infoPage);
@@ -70,13 +74,18 @@ private AsyncTask<UpdateFile> Build(Stream s)
7074

7175
task.TaskProgressChanged += (o, e) =>
7276
{
73-
lblProgress.Text = $"Progress: {e.ProgressPercentage}%";
74-
pbProgress.Value = e.ProgressPercentage;
75-
77+
lblProgress.Text = $"Progress: {e.ProgressPercentage}%";
78+
pbProgress.Value = e.ProgressPercentage;
79+
7680
};
7781

7882
task.TaskCompleted += (o, e) =>
7983
{
84+
sw.Stop();
85+
86+
Logger.Debug(GetType().Name, $"File generation completed in {sw.ElapsedMilliseconds} ms.");
87+
88+
sw.Reset();
8089

8190
btnBuild.Enabled = true;
8291

@@ -105,10 +114,20 @@ private AsyncTask<UpdateFile> Build(Stream s)
105114
task.Result.Save(s);
106115

107116
lblStatus.Text = $"Status: Completed";
117+
118+
MessageDialog.Show(
119+
ParentForm,
120+
"Builder",
121+
"Build completed",
122+
"The update file has been succesfully generated!",
123+
SystemIcons.Information,
124+
MessageBoxButtons.OK);
108125
};
109126

110127
lblStatus.Text = "Status: Building..";
111128

129+
sw.Start();
130+
112131
return task.Start();
113132
}
114133
}

UpdateLib/UpdateLib.Generator/UI/Pages/InformationPage.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UpdateLib/UpdateLib.Generator/UI/Pages/PageControlBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,16 @@ public AsyncTask InitializePage(EventHandler<AsyncCompletedEventArgs> callBack)
5050

5151
protected virtual void OnPageInitialize() { }
5252

53+
private void InitializeComponent()
54+
{
55+
this.SuspendLayout();
56+
//
57+
// PageControlBase
58+
//
59+
this.DoubleBuffered = true;
60+
this.Name = "PageControlBase";
61+
this.ResumeLayout(false);
62+
63+
}
5364
}
5465
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
</root>

UpdateLib/UpdateLib.Generator/UpdateLib.Generator.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
<EmbeddedResource Include="UI\Pages\InformationPage.resx">
151151
<DependentUpon>InformationPage.cs</DependentUpon>
152152
</EmbeddedResource>
153+
<EmbeddedResource Include="UI\Pages\PageControlBase.resx">
154+
<DependentUpon>PageControlBase.cs</DependentUpon>
155+
</EmbeddedResource>
153156
<None Include="Properties\Settings.settings">
154157
<Generator>SettingsSingleFileGenerator</Generator>
155158
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

UpdateLib/UpdateLib/Files/HashCacheEntry.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public class HashCacheEntry
1313
public string Hash { get; set; }
1414

1515
[XmlElement("Path")]
16-
public string FilePath { get; set; }
16+
public string FilePath { get; set; }
1717

1818
[XmlAttribute("Time")]
19-
public long Ticks { get; set; }
19+
public long Ticks { get; set; }
2020

2121
public HashCacheEntry() { }
2222

@@ -37,12 +37,22 @@ public HashCacheEntry(string file)
3737

3838
public void Recalculate(long tick)
3939
{
40-
if (tick != Ticks)
40+
try
4141
{
42-
Hash = HashUtil.GetHash(FilePath);
43-
Ticks = tick;
42+
if (tick != Ticks)
43+
{
44+
Hash = HashUtil.GetHash(FilePath);
45+
Ticks = tick;
4446

45-
Logger.Debug(GetType().Name, $"Recalculated\nTime: {DateTime.FromBinary(Ticks).ToString()}\nName: {FilePath}\nHash: {Hash}");
47+
Logger.Debug(GetType().Name, $"Recalculated Time: {DateTime.FromBinary(Ticks).ToString()} Name: {FilePath} Hash: {Hash}");
48+
}
49+
}
50+
catch (Exception ex) // file might no longer exist or is in use
51+
{
52+
Hash = string.Empty;
53+
Ticks = -1;
54+
55+
Logger.Error(GetType().Name, ex);
4656
}
4757
}
4858

UpdateLib/UpdateLib/Tasks/AsyncTask.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public abstract class AsyncTask
3030

3131
private bool m_running = false;
3232
private bool m_cancelled = false;
33+
private bool m_completed = false;
3334

3435
#endregion
3536

@@ -74,6 +75,20 @@ public bool HasErrors
7475
}
7576
}
7677

78+
public bool IsCompleted
79+
{
80+
get
81+
{
82+
lock (sync)
83+
return m_completed;
84+
}
85+
set
86+
{
87+
lock (sync)
88+
m_completed = value;
89+
}
90+
}
91+
7792
/// <summary>
7893
/// Gets if the current <see cref="AsyncTask"/> is cancelled.
7994
/// </summary>
@@ -147,7 +162,8 @@ private void Reset()
147162
{
148163
IsCancelled = false;
149164
IsRunning = false;
150-
m_lastException = null;
165+
LastException = null;
166+
IsCompleted = false;
151167

152168
mainWait = null;
153169
waitQueue.Clear();
@@ -187,6 +203,7 @@ public AsyncTask Start()
187203
{
188204
AwaitWorkers();
189205
IsRunning = false;
206+
IsCompleted = true;
190207
}
191208
});
192209

UpdateLib/UpdateLib/Tasks/UpdateCacheTask.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,9 @@ protected override void DoWork()
6060

6161
continue;
6262
}
63-
64-
try
65-
{
66-
// check to see if the file has been modified since last cache check
67-
entry.Recalculate(f.LastWriteTime.Ticks);
68-
}
69-
catch (Exception ex) // file might no longer exist or is in use
70-
{
71-
Logger.Error(GetType().Name, ex);
72-
}
73-
63+
64+
// check to see if the file has been modified since last cache check
65+
entry.Recalculate(f.LastWriteTime.Ticks);
7466
}
7567

7668
Result.Save();

0 commit comments

Comments
 (0)