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

Commit

Permalink
Merge pull request #22 from MatthiWare/development
Browse files Browse the repository at this point in the history
Update feature rework
  • Loading branch information
Matthiee authored May 30, 2017
2 parents ea7b341 + 457f7e3 commit a75ddba
Show file tree
Hide file tree
Showing 38 changed files with 1,159 additions and 260 deletions.
13 changes: 13 additions & 0 deletions UpdateLib/TestApp/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 38 additions & 30 deletions UpdateLib/TestApp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Drawing;
using System.IO;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Windows.Forms;
Expand All @@ -27,39 +28,40 @@ private void Instance_CheckForUpdatesCompleted(object sender, CheckForUpdatesCom
{
this.InvokeOnUI(() => checkForUpdatesToolStripMenuItem.Enabled = true);

if (e.Cancelled || e.Error != null)
{
this.InvokeOnUI(() => MessageDialog.Show(
this,
"Updater",
e.Cancelled ? "Cancelled" : "Error",
e.Cancelled ? "Update got cancelled" : "Please check the logs for more information.",
e.Cancelled ? SystemIcons.Warning : SystemIcons.Error,
MessageBoxButtons.OK));

return;
}

if (!e.UpdateAvailable)
{
this.InvokeOnUI(() =>
MessageDialog.Show(
this,
"Updater",
"No update available!",
$"You already have the latest version ({e.LatestVersion}).",
SystemIcons.Information,
MessageBoxButtons.OK));

return;
}
//if (e.Cancelled || e.Error != null)
//{
// this.InvokeOnUI(() => MessageDialog.Show(
// this,
// "Updater",
// e.Cancelled ? "Cancelled" : "Error",
// e.Cancelled ? "Update got cancelled" : "Please check the logs for more information.",
// e.Cancelled ? SystemIcons.Warning : SystemIcons.Error,
// MessageBoxButtons.OK));

// return;
//}

//if (!e.UpdateAvailable)
//{
// this.InvokeOnUI(() =>
// MessageDialog.Show(
// this,
// "Updater",
// "No update available!",
// $"You already have the latest version ({e.LatestVersion}).",
// SystemIcons.Information,
// MessageBoxButtons.OK));

// return;
//}
}

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

Updater.Instance.CheckForUpdatesAsync();
AsyncTask task = Updater.Instance.CheckForUpdatesAsync();
//task.Cancel();
}

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

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

FileStream fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
StreamReader sr = new StreamReader(fs);
string text = sr.ReadToEnd();

return text;
}

private void button1_Click(object sender, EventArgs e)
{
DummyTask task = new DummyTask();
task.TaskCompleted += (o, ex) => Logger.Debug(nameof(DummyTask), "Callback task completed!");
task.TaskCompleted += (o, ex) => Updater.Instance.Logger.Debug(nameof(DummyTask), "Callback task completed!");
task.Start();
}

private void button2_Click(object sender, EventArgs e)
{
//Updater.Instance.RestartApp(false, false, true, true);
}
}
}
40 changes: 24 additions & 16 deletions UpdateLib/TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@ static class Program
[STAThread]
static void Main()
{
SetupLogging();
InitializeUpdater();
try
{

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

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

private static void SetupLogging()
{
Logger.Writers.Add(new ConsoleLogWriter());
Logger.Writers.Add(new FileLogWriter());
Application.Run(new Form1());
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
MessageBox.Show(e.ToString());
}

}
}
}
10 changes: 10 additions & 0 deletions UpdateLib/TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<StartupObject>TestApp.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -67,6 +74,9 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="app.manifest">
<SubType>Designer</SubType>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
5 changes: 3 additions & 2 deletions UpdateLib/TestApp/Testing/DummyTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MatthiWare.UpdateLib.Logging;
using MatthiWare.UpdateLib;
using MatthiWare.UpdateLib.Logging;
using MatthiWare.UpdateLib.Tasks;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -26,7 +27,7 @@ private void ChildWorkStuff(int id)

Thread.Sleep(waitTime);

Logger.Debug(nameof(ChildWorkStuff), $"Task[{id.ToString("X2")}] Completed");
Updater.Instance.Logger.Debug(nameof(ChildWorkStuff), $"Task[{id.ToString("X2")}] Completed");
}


Expand Down
76 changes: 76 additions & 0 deletions UpdateLib/TestApp/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->

</application>
</compatibility>

<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->

</assembly>
2 changes: 1 addition & 1 deletion UpdateLib/UpdateLib.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static class Program
[STAThread]
static void Main()
{
Logger.Writers.Add(new ConsoleLogWriter());
Updater.Instance.ConfigureLogger((logger) => logger.Writers.Add(new ConsoleLogWriter()));

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Expand Down
2 changes: 1 addition & 1 deletion UpdateLib/UpdateLib.Generator/UI/Pages/BuilderPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private AsyncTask<UpdateFile> Build(Stream s)
{
sw.Stop();
Logger.Debug(GetType().Name, $"File generation completed in {sw.ElapsedMilliseconds} ms.");
Updater.Instance.Logger.Debug(GetType().Name, $"File generation completed in {sw.ElapsedMilliseconds} ms.");
Expand Down
2 changes: 1 addition & 1 deletion UpdateLib/UpdateLib.Generator/UI/Pages/PageControlBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AsyncTask InitializePage(EventHandler<AsyncCompletedEventArgs> callBack)
if (IsPageInitialized || (taskInitialize != null && taskInitialize.IsRunning))
return taskInitialize;

taskInitialize = AsyncTaskFactory.From(new Action(() => OnPageInitialize()), null);
taskInitialize = AsyncTaskFactory.From(new Action(OnPageInitialize), null);

taskInitialize.TaskCompleted += (o, e) =>
{
Expand Down
2 changes: 1 addition & 1 deletion UpdateLib/UpdateLib.Tests/Files/HashCacheEntryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void TestHashing()

EditTempFile();

entry.Recalculate(File.GetLastWriteTime(temp_file).Ticks);
entry.Recalculate();

Assert.AreNotEqual(ticks, entry.Ticks);
Assert.AreNotEqual(hash, entry.Hash);
Expand Down
Loading

0 comments on commit a75ddba

Please sign in to comment.