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

Commit a75ddba

Browse files
authored
Merge pull request #22 from MatthiWare/development
Update feature rework
2 parents ea7b341 + 457f7e3 commit a75ddba

38 files changed

+1159
-260
lines changed

UpdateLib/TestApp/Form1.Designer.cs

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

UpdateLib/TestApp/Form1.cs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Drawing;
88
using System.IO;
99
using System.Security.Cryptography;
10+
using System.Security.Permissions;
1011
using System.Text;
1112
using System.Threading;
1213
using System.Windows.Forms;
@@ -27,39 +28,40 @@ private void Instance_CheckForUpdatesCompleted(object sender, CheckForUpdatesCom
2728
{
2829
this.InvokeOnUI(() => checkForUpdatesToolStripMenuItem.Enabled = true);
2930

30-
if (e.Cancelled || e.Error != null)
31-
{
32-
this.InvokeOnUI(() => MessageDialog.Show(
33-
this,
34-
"Updater",
35-
e.Cancelled ? "Cancelled" : "Error",
36-
e.Cancelled ? "Update got cancelled" : "Please check the logs for more information.",
37-
e.Cancelled ? SystemIcons.Warning : SystemIcons.Error,
38-
MessageBoxButtons.OK));
39-
40-
return;
41-
}
42-
43-
if (!e.UpdateAvailable)
44-
{
45-
this.InvokeOnUI(() =>
46-
MessageDialog.Show(
47-
this,
48-
"Updater",
49-
"No update available!",
50-
$"You already have the latest version ({e.LatestVersion}).",
51-
SystemIcons.Information,
52-
MessageBoxButtons.OK));
53-
54-
return;
55-
}
31+
//if (e.Cancelled || e.Error != null)
32+
//{
33+
// this.InvokeOnUI(() => MessageDialog.Show(
34+
// this,
35+
// "Updater",
36+
// e.Cancelled ? "Cancelled" : "Error",
37+
// e.Cancelled ? "Update got cancelled" : "Please check the logs for more information.",
38+
// e.Cancelled ? SystemIcons.Warning : SystemIcons.Error,
39+
// MessageBoxButtons.OK));
40+
41+
// return;
42+
//}
43+
44+
//if (!e.UpdateAvailable)
45+
//{
46+
// this.InvokeOnUI(() =>
47+
// MessageDialog.Show(
48+
// this,
49+
// "Updater",
50+
// "No update available!",
51+
// $"You already have the latest version ({e.LatestVersion}).",
52+
// SystemIcons.Information,
53+
// MessageBoxButtons.OK));
54+
55+
// return;
56+
//}
5657
}
5758

5859
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
5960
{
6061
checkForUpdatesToolStripMenuItem.Enabled = false;
6162

62-
Updater.Instance.CheckForUpdatesAsync();
63+
AsyncTask task = Updater.Instance.CheckForUpdatesAsync();
64+
//task.Cancel();
6365
}
6466

6567
private void Form1_Load(object sender, EventArgs e)
@@ -79,6 +81,7 @@ private string ReadFile(string file)
7981
return string.Join(", ", lines);
8082
}
8183

84+
FileStream fs;
8285
/// <summary>
8386
/// Bad code that keeps the file open & locked
8487
/// Purpose: to demonstrate the updater still works on locked files.
@@ -90,18 +93,23 @@ private string ReadFileAndKeepStreamOpen(string file)
9093
if (!File.Exists(file))
9194
return "ERROR: File doesn't exist..";
9295

93-
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
96+
fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
9497
StreamReader sr = new StreamReader(fs);
9598
string text = sr.ReadToEnd();
9699

97100
return text;
98101
}
99-
102+
100103
private void button1_Click(object sender, EventArgs e)
101104
{
102105
DummyTask task = new DummyTask();
103-
task.TaskCompleted += (o, ex) => Logger.Debug(nameof(DummyTask), "Callback task completed!");
106+
task.TaskCompleted += (o, ex) => Updater.Instance.Logger.Debug(nameof(DummyTask), "Callback task completed!");
104107
task.Start();
105108
}
109+
110+
private void button2_Click(object sender, EventArgs e)
111+
{
112+
//Updater.Instance.RestartApp(false, false, true, true);
113+
}
106114
}
107115
}

UpdateLib/TestApp/Program.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,33 @@ static class Program
1616
[STAThread]
1717
static void Main()
1818
{
19-
SetupLogging();
20-
InitializeUpdater();
19+
try
20+
{
2121

22-
Application.EnableVisualStyles();
23-
Application.SetCompatibleTextRenderingDefault(false);
24-
Application.Run(new Form1());
25-
}
22+
// we still want our updater to have visual styles in case of update cmd argument switch
23+
Application.EnableVisualStyles();
24+
Application.SetCompatibleTextRenderingDefault(false);
2625

27-
private static void InitializeUpdater()
28-
{
29-
Updater.Instance.Initialize();
30-
Updater.Instance.UpdateURL = "https://raw.githubusercontent.com/MatthiWare/UpdateLib.TestApp.UpdateExample/master/Dev/updatefile.xml";
31-
//Updater.Instance.UpdateURL = "http://matthiware.dev/UpdateLib/Dev/updatefile.xml";
32-
}
26+
Updater.Instance
27+
.ConfigureUpdateUrl("https://raw.githubusercontent.com/MatthiWare/UpdateLib.TestApp.UpdateExample/master/Dev/updatefile.xml")
28+
//.ConfigureUpdateUrl("http://matthiware.dev/UpdateLib/Dev/updatefile.xml")
29+
.ConfigureLogger((logger) => logger.LogLevel = LoggingLevel.Debug)
30+
.ConfigureLogger((logger) => logger.Writers.Add(new ConsoleLogWriter()))
31+
.ConfigureLogger((logger) => logger.Writers.Add(new FileLogWriter()))
32+
.ConfigureUnsafeConnections(true)
33+
.ConfigureCacheInvalidation(TimeSpan.FromSeconds(30))
34+
.ConfigureUpdateNeedsAdmin(false)
35+
.ConfigureInstallationMode(InstallationMode.Shared)
36+
.Initialize();
3337

34-
private static void SetupLogging()
35-
{
36-
Logger.Writers.Add(new ConsoleLogWriter());
37-
Logger.Writers.Add(new FileLogWriter());
38+
Application.Run(new Form1());
39+
}
40+
catch (Exception e)
41+
{
42+
Console.WriteLine(e.ToString());
43+
MessageBox.Show(e.ToString());
44+
}
45+
3846
}
3947
}
4048
}

UpdateLib/TestApp/TestApp.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
<ErrorReport>prompt</ErrorReport>
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
37+
<PropertyGroup />
38+
<PropertyGroup>
39+
<StartupObject>TestApp.Program</StartupObject>
40+
</PropertyGroup>
41+
<PropertyGroup>
42+
<ApplicationManifest>app.manifest</ApplicationManifest>
43+
</PropertyGroup>
3744
<ItemGroup>
3845
<Reference Include="System" />
3946
<Reference Include="System.Core" />
@@ -67,6 +74,9 @@
6774
<AutoGen>True</AutoGen>
6875
<DependentUpon>Resources.resx</DependentUpon>
6976
</Compile>
77+
<None Include="app.manifest">
78+
<SubType>Designer</SubType>
79+
</None>
7080
<None Include="Properties\Settings.settings">
7181
<Generator>SettingsSingleFileGenerator</Generator>
7282
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

UpdateLib/TestApp/Testing/DummyTask.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MatthiWare.UpdateLib.Logging;
1+
using MatthiWare.UpdateLib;
2+
using MatthiWare.UpdateLib.Logging;
23
using MatthiWare.UpdateLib.Tasks;
34
using System;
45
using System.Collections.Generic;
@@ -26,7 +27,7 @@ private void ChildWorkStuff(int id)
2627

2728
Thread.Sleep(waitTime);
2829

29-
Logger.Debug(nameof(ChildWorkStuff), $"Task[{id.ToString("X2")}] Completed");
30+
Updater.Instance.Logger.Debug(nameof(ChildWorkStuff), $"Task[{id.ToString("X2")}] Completed");
3031
}
3132

3233

UpdateLib/TestApp/app.manifest

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5+
<security>
6+
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
<!-- UAC Manifest Options
8+
If you want to change the Windows User Account Control level replace the
9+
requestedExecutionLevel node with one of the following.
10+
11+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
12+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
13+
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
14+
15+
Specifying requestedExecutionLevel element will disable file and registry virtualization.
16+
Remove this element if your application requires this virtualization for backwards
17+
compatibility.
18+
-->
19+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
20+
</requestedPrivileges>
21+
</security>
22+
</trustInfo>
23+
24+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
25+
<application>
26+
<!-- A list of the Windows versions that this application has been tested on and is
27+
is designed to work with. Uncomment the appropriate elements and Windows will
28+
automatically selected the most compatible environment. -->
29+
30+
<!-- Windows Vista -->
31+
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
32+
33+
<!-- Windows 7 -->
34+
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
35+
36+
<!-- Windows 8 -->
37+
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
38+
39+
<!-- Windows 8.1 -->
40+
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
41+
42+
<!-- Windows 10 -->
43+
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
44+
45+
</application>
46+
</compatibility>
47+
48+
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
49+
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
50+
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
51+
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
52+
<!--
53+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
54+
<windowsSettings>
55+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
56+
</windowsSettings>
57+
</application>
58+
-->
59+
60+
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
61+
<!--
62+
<dependency>
63+
<dependentAssembly>
64+
<assemblyIdentity
65+
type="win32"
66+
name="Microsoft.Windows.Common-Controls"
67+
version="6.0.0.0"
68+
processorArchitecture="*"
69+
publicKeyToken="6595b64144ccf1df"
70+
language="*"
71+
/>
72+
</dependentAssembly>
73+
</dependency>
74+
-->
75+
76+
</assembly>

UpdateLib/UpdateLib.Generator/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static class Program
1515
[STAThread]
1616
static void Main()
1717
{
18-
Logger.Writers.Add(new ConsoleLogWriter());
18+
Updater.Instance.ConfigureLogger((logger) => logger.Writers.Add(new ConsoleLogWriter()));
1919

2020
Application.EnableVisualStyles();
2121
Application.SetCompatibleTextRenderingDefault(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private AsyncTask<UpdateFile> Build(Stream s)
8383
{
8484
sw.Stop();
8585

86-
Logger.Debug(GetType().Name, $"File generation completed in {sw.ElapsedMilliseconds} ms.");
86+
Updater.Instance.Logger.Debug(GetType().Name, $"File generation completed in {sw.ElapsedMilliseconds} ms.");
8787

8888

8989

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public AsyncTask InitializePage(EventHandler<AsyncCompletedEventArgs> callBack)
3636
if (IsPageInitialized || (taskInitialize != null && taskInitialize.IsRunning))
3737
return taskInitialize;
3838

39-
taskInitialize = AsyncTaskFactory.From(new Action(() => OnPageInitialize()), null);
39+
taskInitialize = AsyncTaskFactory.From(new Action(OnPageInitialize), null);
4040

4141
taskInitialize.TaskCompleted += (o, e) =>
4242
{

UpdateLib/UpdateLib.Tests/Files/HashCacheEntryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void TestHashing()
4242

4343
EditTempFile();
4444

45-
entry.Recalculate(File.GetLastWriteTime(temp_file).Ticks);
45+
entry.Recalculate();
4646

4747
Assert.AreNotEqual(ticks, entry.Ticks);
4848
Assert.AreNotEqual(hash, entry.Hash);

0 commit comments

Comments
 (0)