mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Add Auto Updater [WIP] & remove UAC project
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
using Squirrel;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Threading;
|
||||
using NAppUpdate.Framework;
|
||||
using NAppUpdate.Framework.Common;
|
||||
using NAppUpdate.Framework.Sources;
|
||||
|
||||
namespace Wox.Core.Updater
|
||||
{
|
||||
@@ -18,14 +25,82 @@ namespace Wox.Core.Updater
|
||||
}
|
||||
}
|
||||
|
||||
private UpdaterManager() { }
|
||||
private UpdaterManager()
|
||||
{
|
||||
UpdateManager.Instance.UpdateSource = GetUpdateSource();
|
||||
}
|
||||
|
||||
public void CheckUpdate()
|
||||
{
|
||||
using (var mgr = new UpdateManager("https://path/to/my/update/folder", "nuget-package-id", FrameworkVersion.Net45))
|
||||
// Get a local pointer to the UpdateManager instance
|
||||
UpdateManager updManager = UpdateManager.Instance;
|
||||
|
||||
updManager.BeginCheckForUpdates(asyncResult =>
|
||||
{
|
||||
mgr.UpdateApp();
|
||||
if (asyncResult.IsCompleted)
|
||||
{
|
||||
// still need to check for caught exceptions if any and rethrow
|
||||
((UpdateProcessAsyncResult)asyncResult).EndInvoke();
|
||||
|
||||
// No updates were found, or an error has occured. We might want to check that...
|
||||
if (updManager.UpdatesAvailable == 0)
|
||||
{
|
||||
MessageBox.Show("All is up to date!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
updManager.BeginPrepareUpdates(result =>
|
||||
{
|
||||
((UpdateProcessAsyncResult)result).EndInvoke();
|
||||
|
||||
// ApplyUpdates is a synchronous method by design. Make sure to save all user work before calling
|
||||
// it as it might restart your application
|
||||
// get out of the way so the console window isn't obstructed
|
||||
try
|
||||
{
|
||||
updManager.ApplyUpdates(true,false,true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// this.WindowState = WindowState.Normal;
|
||||
MessageBox.Show(
|
||||
"An error occurred while trying to install software updates");
|
||||
}
|
||||
|
||||
updManager.CleanUp();
|
||||
}, null);
|
||||
}, null);
|
||||
}
|
||||
|
||||
public void Reinstall()
|
||||
{
|
||||
UpdateManager.Instance.ReinstateIfRestarted();
|
||||
}
|
||||
|
||||
private void OnPrepareUpdatesCompleted(bool obj)
|
||||
{
|
||||
UpdateManager updManager = UpdateManager.Instance;
|
||||
|
||||
DialogResult dr = MessageBox.Show(
|
||||
"Updates are ready to install. Do you wish to install them now?",
|
||||
"Software updates ready",
|
||||
MessageBoxButtons.YesNo);
|
||||
|
||||
if (dr == DialogResult.Yes)
|
||||
{
|
||||
// This is a synchronous method by design, make sure to save all user work before calling
|
||||
// it as it might restart your application
|
||||
updManager.ApplyUpdates(true,true,true);
|
||||
}
|
||||
}
|
||||
|
||||
private IUpdateSource GetUpdateSource()
|
||||
{
|
||||
// Normally this would be a web based source.
|
||||
// But for the demo app, we prepare an in-memory source.
|
||||
var source = new NAppUpdate.Framework.Sources.SimpleWebSource("http://127.0.0.1:8888/Update.xml");
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAppUpdate.Framework, Version=0.1.0.0, Culture=neutral, PublicKeyToken=d1f1d1f19f9e5a56, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\References\NAppUpdate.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
@@ -65,6 +69,7 @@
|
||||
<Compile Include="Exception\WoxI18nException.cs" />
|
||||
<Compile Include="Exception\WoxJsonRPCException.cs" />
|
||||
<Compile Include="Exception\WoxPluginException.cs" />
|
||||
<Compile Include="Updater\UpdaterManager.cs" />
|
||||
<Compile Include="UserSettings\HttpProxy.cs" />
|
||||
<Compile Include="i18n\AvailableLanguages.cs" />
|
||||
<Compile Include="i18n\IInternationalization.cs" />
|
||||
|
||||
Reference in New Issue
Block a user