mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Initial hack at an Install action
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Mono.Options;
|
using Mono.Options;
|
||||||
|
using Squirrel;
|
||||||
|
|
||||||
namespace Update
|
namespace Squirrel.Update
|
||||||
{
|
{
|
||||||
enum UpdateAction {
|
enum UpdateAction {
|
||||||
Unset = 0, Install, Uninstall, Download, Update,
|
Unset = 0, Install, Uninstall, Download, Update,
|
||||||
@@ -33,10 +36,10 @@ namespace Update
|
|||||||
"Manages Squirrel packages",
|
"Manages Squirrel packages",
|
||||||
"",
|
"",
|
||||||
"Commands",
|
"Commands",
|
||||||
{ "install=", "Install the app specified by the RELEASES file", v => { updateAction = UpdateAction.Install; target = v; } },
|
{ "install=", "Install the app whose package is in the specified directory", v => { updateAction = UpdateAction.Install; target = v; } },
|
||||||
{ "uninstall", "Uninstall the app the same dir as Update.exe", v => updateAction = UpdateAction.Uninstall},
|
{ "uninstall", "Uninstall the app the same dir as Update.exe", v => updateAction = UpdateAction.Uninstall},
|
||||||
{ "download=", "Download the releases specified by the URL and write new results to stdout as JSON", v => { updateAction = UpdateAction.Download; target = v; } },
|
{ "download=", "Download the releases specified by the URL and write new results to stdout as JSON", v => { updateAction = UpdateAction.Download; target = v; } },
|
||||||
{ "update", "Update the application to the latest remote version", v => updateAction = UpdateAction.Update },
|
{ "update=", "Update the application to the latest remote version specified by URL", v => { updateAction = UpdateAction.Update; target = v; } },
|
||||||
"",
|
"",
|
||||||
"Options:",
|
"Options:",
|
||||||
{ "h|?|help", "Display Help and exit", _ => ShowHelp() },
|
{ "h|?|help", "Display Help and exit", _ => ShowHelp() },
|
||||||
@@ -49,13 +52,58 @@ namespace Update
|
|||||||
ShowHelp();
|
ShowHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (updateAction) {
|
||||||
|
case UpdateAction.Install:
|
||||||
|
Install(silentInstall, target).Wait();
|
||||||
|
break;
|
||||||
|
case UpdateAction.Update:
|
||||||
|
Update(target).Wait();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShowHelp()
|
public static async Task Install(bool silentInstall, string sourceDirectory = null)
|
||||||
|
{
|
||||||
|
sourceDirectory = sourceDirectory ?? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
var releasesPath = Path.Combine(sourceDirectory, "RELEASES");
|
||||||
|
|
||||||
|
if (!File.Exists(releasesPath)) {
|
||||||
|
var nupkgs = (new DirectoryInfo(sourceDirectory)).GetFiles()
|
||||||
|
.Where(x => x.Name.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase))
|
||||||
|
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName));
|
||||||
|
|
||||||
|
ReleaseEntry.WriteReleaseFile(nupkgs, releasesPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var ourAppName = ReleaseEntry.ParseReleaseFile(releasesPath).First().PackageName;
|
||||||
|
using (var mgr = new UpdateManager(sourceDirectory, ourAppName, FrameworkVersion.Net45)) {
|
||||||
|
await mgr.FullInstall(silentInstall);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task Update(string updateUrl, string appName = null)
|
||||||
|
{
|
||||||
|
appName = appName ?? getAppNameFromDirectory();
|
||||||
|
|
||||||
|
using (var mgr = new UpdateManager(updateUrl, appName, FrameworkVersion.Net45)) {
|
||||||
|
var updateInfo = await mgr.CheckForUpdate(progress: x => Console.WriteLine(x / 3));
|
||||||
|
await mgr.DownloadReleases(updateInfo.ReleasesToApply, x => Console.WriteLine(33 + x / 3));
|
||||||
|
await mgr.ApplyReleases(updateInfo, x => Console.WriteLine(66 + x / 3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ShowHelp()
|
||||||
{
|
{
|
||||||
opts.WriteOptionDescriptions(Console.Out);
|
opts.WriteOptionDescriptions(Console.Out);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static string getAppNameFromDirectory(string path = null)
|
||||||
|
{
|
||||||
|
path = path ?? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||||
|
return (new DirectoryInfo(path)).Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,28 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Web.XmlTransform">
|
||||||
|
<HintPath>..\..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Mono.Cecil">
|
||||||
|
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Mono.Cecil.Mdb">
|
||||||
|
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Mono.Cecil.Pdb">
|
||||||
|
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Mono.Cecil.Rocks">
|
||||||
|
<HintPath>..\..\packages\Mono.Cecil.0.9.5.4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="NuGet.Core, Version=2.8.50506.491, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
<HintPath>..\..\packages\NuGet.Core.2.8.2\lib\net40-Client\NuGet.Core.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Splat">
|
||||||
|
<HintPath>..\..\packages\Splat.1.4.0\lib\Net45\Splat.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@@ -49,6 +71,12 @@
|
|||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Squirrel\Squirrel.csproj">
|
||||||
|
<Project>{1436e22a-fe3c-4d68-9a85-9e74df2e6a92}</Project>
|
||||||
|
<Name>Squirrel</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
|
||||||
|
<package id="Mono.Cecil" version="0.9.5.4" targetFramework="net45" />
|
||||||
<package id="Mono.Options" version="1.1" targetFramework="net45" />
|
<package id="Mono.Options" version="1.1" targetFramework="net45" />
|
||||||
|
<package id="NuGet.Core" version="2.8.2" targetFramework="net45" />
|
||||||
|
<package id="Splat" version="1.4.0" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
||||||
Reference in New Issue
Block a user