Initial hack at an Install action

This commit is contained in:
Paul Betts
2014-08-26 15:37:50 -07:00
parent 082a84ec05
commit eb5a80c3e8
3 changed files with 84 additions and 4 deletions

View File

@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Mono.Options;
using Squirrel;
namespace Update
namespace Squirrel.Update
{
enum UpdateAction {
Unset = 0, Install, Uninstall, Download, Update,
@@ -33,10 +36,10 @@ namespace Update
"Manages Squirrel packages",
"",
"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},
{ "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:",
{ "h|?|help", "Display Help and exit", _ => ShowHelp() },
@@ -49,13 +52,58 @@ namespace Update
ShowHelp();
}
switch (updateAction) {
case UpdateAction.Install:
Install(silentInstall, target).Wait();
break;
case UpdateAction.Update:
Update(target).Wait();
break;
}
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);
Environment.Exit(0);
}
static string getAppNameFromDirectory(string path = null)
{
path = path ?? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
return (new DirectoryInfo(path)).Name;
}
}
}

View File

@@ -32,6 +32,28 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<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.Core" />
<Reference Include="System.Xml.Linq" />
@@ -49,6 +71,12 @@
<None Include="App.config" />
<None Include="packages.config" />
</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" />
<!-- 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.

View File

@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<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="NuGet.Core" version="2.8.2" targetFramework="net45" />
<package id="Splat" version="1.4.0" targetFramework="net45" />
</packages>