Merge pull request #17 from Squirrel/run-on-install

Notify applications post-install
This commit is contained in:
Paul Betts
2014-08-21 14:53:52 -07:00
23 changed files with 597 additions and 113 deletions

View File

@@ -14,31 +14,66 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{50DF07
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Update", "src\Update\Update.csproj", "{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
CIBuild|Any CPU = CIBuild|Any CPU
CIBuild|Mixed Platforms = CIBuild|Mixed Platforms
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.CIBuild|Any CPU.ActiveCfg = CIBuild|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.CIBuild|Any CPU.Build.0 = CIBuild|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.CIBuild|Mixed Platforms.ActiveCfg = CIBuild|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.CIBuild|Mixed Platforms.Build.0 = CIBuild|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Release|Any CPU.Build.0 = Release|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1436E22A-FE3C-4D68-9A85-9E74DF2E6A92}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.CIBuild|Any CPU.ActiveCfg = CIBuild|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.CIBuild|Any CPU.Build.0 = CIBuild|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.CIBuild|Mixed Platforms.ActiveCfg = CIBuild|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.CIBuild|Mixed Platforms.Build.0 = CIBuild|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Release|Any CPU.Build.0 = Release|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{98AEB048-E27D-42F4-9440-505B7F78BAFD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C1D40624-A484-438A-B846-052F321C89D1}.CIBuild|Any CPU.ActiveCfg = CIBuild|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.CIBuild|Mixed Platforms.ActiveCfg = CIBuild|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.CIBuild|Mixed Platforms.Build.0 = CIBuild|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.CIBuild|Any CPU.Build.0 = CIBuild|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Debug|Any CPU.ActiveCfg = Debug|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Debug|Any CPU.Build.0 = Debug|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Release|Any CPU.ActiveCfg = Release|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Release|Any CPU.Build.0 = Release|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{C1D40624-A484-438A-B846-052F321C89D1}.Release|Mixed Platforms.Build.0 = Release|Win32
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.CIBuild|Any CPU.ActiveCfg = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.CIBuild|Any CPU.Build.0 = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.CIBuild|Mixed Platforms.ActiveCfg = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.CIBuild|Mixed Platforms.Build.0 = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Release|Any CPU.Build.0 = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Binary file not shown.

View File

@@ -2,6 +2,7 @@
// Microsoft Visual C++ generated include file.
// Used by Setup.rc
//
#define VS_VERSION_INFO 1
#define IDC_MYICON 2
#define IDD_SETUP_DIALOG 102
#define IDS_APP_TITLE 103
@@ -10,7 +11,7 @@
#define IDI_SMALL 108
#define IDC_SETUP 109
#define IDR_MAINFRAME 128
#define IDR_UPDATE_ZIP 131
#define IDR_UPDATE_ZIP 131
#define IDC_STATIC -1
// Next default values for new objects

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Squirrel
{
static class NativeMethods
{
[DllImport("version.dll", SetLastError = true)]
[return:MarshalAs(UnmanagedType.Bool)] public static extern bool GetFileVersionInfo(
string lpszFileName,
IntPtr dwHandleIgnored,
int dwLen,
[MarshalAs(UnmanagedType.LPArray)] byte[] lpData);
[DllImport("version.dll", SetLastError = true)]
public static extern int GetFileVersionInfoSize(
string lpszFileName,
IntPtr dwHandleIgnored);
[DllImport("version.dll")]
[return:MarshalAs(UnmanagedType.Bool)] public static extern bool VerQueryValue(
byte[] pBlock,
string pSubBlock,
out IntPtr pValue,
out int len);
}
}

View File

@@ -45,6 +45,18 @@
<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>
@@ -71,12 +83,14 @@
<Compile Include="FileDownloader.cs" />
<Compile Include="IUpdateManager.cs" />
<Compile Include="MarkdownSharp.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="PackageExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReleaseEntry.cs" />
<Compile Include="ReleaseExtensions.cs" />
<Compile Include="ReleasePackage.cs" />
<Compile Include="ShellFile.cs" />
<Compile Include="SquirrelAwareExecutableDetector.cs" />
<Compile Include="TaskbarHelper.cs" />
<Compile Include="UpdateInfo.cs" />
<Compile Include="UpdateManager.CheckForUpdates.cs" />

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Mono.Cecil;
namespace Squirrel
{
static class SquirrelAwareExecutableDetector
{
public static List<string> GetAllSquirrelAwareApps(string directory, int minimumVersion = 1)
{
var di = new DirectoryInfo(directory);
return di.EnumerateFiles()
.Where(x => x.Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
.Select(x => x.FullName)
.Where(x => (GetPESquirrelAwareVersion(x) ?? -1) >= minimumVersion)
.ToList();
}
public static int? GetPESquirrelAwareVersion(string executable)
{
if (!File.Exists(executable)) return null;
var fullname = Path.GetFullPath(executable);
return GetAssemblySquirrelAwareVersion(fullname) ?? GetVersionBlockSquirrelAwareValue(fullname);
}
static int? GetAssemblySquirrelAwareVersion(string executable)
{
try
{
var assembly = AssemblyDefinition.ReadAssembly(executable);
if (!assembly.HasCustomAttributes) return null;
var attrs = assembly.CustomAttributes;
var attribute = attrs.FirstOrDefault(x =>
{
if (x.AttributeType.FullName != typeof(AssemblyMetadataAttribute).FullName) return false;
if (x.ConstructorArguments.Count != 2) return false;
return x.ConstructorArguments[0].Value.ToString() == "SquirrelAwareVersion";
});
if (attribute == null) return null;
int result;
if (!Int32.TryParse(attribute.ConstructorArguments[1].Value.ToString(), NumberStyles.Integer, CultureInfo.CurrentCulture, out result))
{
return null;
}
return result;
}
catch (FileLoadException) { return null; }
catch (BadImageFormatException) { return null; }
}
static int? GetVersionBlockSquirrelAwareValue(string executable)
{
int size = NativeMethods.GetFileVersionInfoSize(executable, IntPtr.Zero);
// Nice try, buffer overflow
if (size <= 0 || size > 4096) return null;
var buf = new byte[size];
if (!NativeMethods.GetFileVersionInfo(executable, IntPtr.Zero, size, buf)) return null;
IntPtr result; int resultSize;
if (!NativeMethods.VerQueryValue(buf, "\\StringFileInfo\\040904B0\\SquirrelAwareVersion", out result, out resultSize))
{
return null;
}
int ret;
string resultData = Marshal.PtrToStringAnsi(result, resultSize-1 /* Subtract one for null terminator */);
if (!Int32.TryParse(resultData, NumberStyles.Integer, CultureInfo.CurrentCulture, out ret)) return null;
return ret;
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
@@ -33,31 +34,32 @@ namespace Squirrel
progress(10);
await installPackageToAppDir(updateInfo, release);
progress(50);
progress(30);
var currentReleases = await updateLocalReleasesFile();
progress(50);
var newVersion = currentReleases.MaxBy(x => x.Version).First().Version;
await invokePostInstall(newVersion, currentReleases.Count == 1);
progress(75);
await cleanDeadVersions(currentReleases.MaxBy(x => x.Version).First().Version);
await cleanDeadVersions(newVersion);
progress(100);
}
public async Task FullUninstall(Version version = null)
public async Task FullUninstall()
{
version = version ?? new Version(255, 255, 255, 255);
this.Log().Info("Uninstalling version '{0}'", version);
var currentRelease = getReleases().MaxBy(x => x.Name.ToVersion()).FirstOrDefault();
// find all the old releases (and this one)
var directoriesToDelete = getOldReleases(version)
.Concat(new [] { getDirectoryForRelease(version) })
.Where(d => d.Exists)
.Select(d => d.FullName);
if (currentRelease.Exists)
{
var version = currentRelease.Name.ToVersion();
await directoriesToDelete.ForEachAsync(x => Utility.DeleteDirectoryWithFallbackToNextReboot(x));
if (!getReleases().Any()) {
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
await SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(currentRelease.FullName)
.ForEachAsync(exe => Utility.InvokeProcessAsync(exe, String.Format("/squirrel-uninstall {0}", version)), 1);
}
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
}
async Task installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release)
@@ -185,6 +187,34 @@ namespace Squirrel
}
}
async Task invokePostInstall(Version currentVersion, bool isInitialInstall)
{
var targetDir = getDirectoryForRelease(currentVersion);
var args = isInitialInstall ?
String.Format("/squirrel-install {0}", currentVersion) :
String.Format("/squirrel-updated {0}", currentVersion);
var squirrelApps = SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(targetDir.FullName);
// For each app, run the install command in-order and wait
await squirrelApps.ForEachAsync(exe => Utility.InvokeProcessAsync(exe, args), 1 /* at a time */);
if (!isInitialInstall) return;
// If this is the first run, we run the apps with first-run and
// *don't* wait for them, since they're probably the main EXE
if (squirrelApps.Count == 0) {
this.Log().Warn("No apps are marked as Squirrel-aware! Going to run them all");
squirrelApps = targetDir.EnumerateFiles()
.Where(x => x.Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
.Select(x => x.FullName)
.ToList();
}
squirrelApps.ForEach(exe => Process.Start(exe, "/squirrel-firstrun"));
}
void fixPinnedExecutables(Version newCurrentVersion)
{
if (Environment.OSVersion.Version < new Version(6, 1)) {

View File

@@ -14,6 +14,7 @@ using Splat;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Diagnostics;
namespace Squirrel
{
@@ -98,6 +99,24 @@ namespace Squirrel
}
}
public static Task<int> InvokeProcessAsync(string fileName, string arguments)
{
var psi = new ProcessStartInfo(fileName, arguments);
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.ErrorDialog = false;
return InvokeProcessAsync(psi);
}
public static async Task<int> InvokeProcessAsync(ProcessStartInfo psi)
{
var pi = Process.Start(psi);
await Task.Run(() => pi.WaitForExit());
return pi.ExitCode;
}
public static Task ForEachAsync<T>(this IEnumerable<T> source, Action<T> body, int degreeOfParallelism = 4)
{
return ForEachAsync(source, x => Task.Run(() => body(x)), degreeOfParallelism);

View File

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

6
src/Update/App.config Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

15
src/Update/Program.cs Normal file
View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Update
{
class Program
{
static void Main(string[] args)
{
}
}
}

View File

@@ -0,0 +1,37 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Update")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Update")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a0663459-8b01-4fcd-96b8-c4235eb4dc51")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]

58
src/Update/Update.csproj Normal file
View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1EEBACBC-6982-4696-BD4E-899ED0AC6CD2}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Update</RootNamespace>
<AssemblyName>Update</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NuGet;
@@ -28,6 +29,109 @@ namespace Squirrel.Tests
public class ApplyReleasesTests : IEnableLogger
{
[Fact]
public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
{
string tempDir;
string remotePkgDir;
using (Utility.WithTempDirectory(out tempDir))
using (Utility.WithTempDirectory(out remotePkgDir)) {
IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
using (var fixture = new UpdateManager(remotePkgDir, "theApp", FrameworkVersion.Net45, tempDir)) {
await fixture.FullInstall();
// NB: We execute the Squirrel-aware apps, so we need to give
// them a minute to settle or else the using statement will
// try to blow away a running process
await Task.Delay(1000);
Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.1.0", "args2.txt")));
Assert.True(File.Exists(Path.Combine(tempDir, "theApp", "app-0.1.0", "args.txt")));
var text = File.ReadAllText(Path.Combine(tempDir, "theApp", "app-0.1.0", "args.txt"), Encoding.UTF8);
Assert.Contains("firstrun", text);
}
}
}
[Fact]
public async Task UpgradeRunsSquirrelAwareAppsWithUpgradeFlag()
{
string tempDir;
string remotePkgDir;
using (Utility.WithTempDirectory(out tempDir))
using (Utility.WithTempDirectory(out remotePkgDir)) {
IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
using (var fixture = new UpdateManager(remotePkgDir, "theApp", FrameworkVersion.Net45, tempDir)) {
await fixture.FullInstall();
}
await Task.Delay(1000);
IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir);
pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
using (var fixture = new UpdateManager(remotePkgDir, "theApp", FrameworkVersion.Net45, tempDir)) {
await fixture.UpdateApp();
}
await Task.Delay(1000);
Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", "args2.txt")));
Assert.True(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", "args.txt")));
var text = File.ReadAllText(Path.Combine(tempDir, "theApp", "app-0.2.0", "args.txt"), Encoding.UTF8);
Assert.Contains("updated|0.2.0", text);
}
}
[Fact]
public async Task FullUninstallRemovesAllVersions()
{
string tempDir;
string remotePkgDir;
using (Utility.WithTempDirectory(out tempDir))
using (Utility.WithTempDirectory(out remotePkgDir)) {
IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir);
var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
using (var fixture = new UpdateManager(remotePkgDir, "theApp", FrameworkVersion.Net45, tempDir)) {
await fixture.FullInstall();
}
await Task.Delay(1000);
IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir);
pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
using (var fixture = new UpdateManager(remotePkgDir, "theApp", FrameworkVersion.Net45, tempDir)) {
await fixture.UpdateApp();
}
await Task.Delay(1000);
using (var fixture = new UpdateManager(remotePkgDir, "theApp", FrameworkVersion.Net45, tempDir)) {
await fixture.FullUninstall();
}
Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.1.0", "args.txt")));
Assert.False(File.Exists(Path.Combine(tempDir, "theApp", "app-0.2.0", "args.txt")));
Assert.False(Directory.Exists(Path.Combine(tempDir, "theApp")));
}
}
[Fact]
public void WhenNoNewReleasesAreAvailableTheListIsEmpty()
{

View File

@@ -41,74 +41,6 @@ namespace Squirrel.Tests
*/
}
[Fact]
public void NoLocalReleasesFileMeansWeStartFromScratch()
{
Assert.False(true, "Rewrite this to be an integration test");
/*
string localPackagesDir = Path.Combine(".", "theApp", "packages");
string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
var fileInfo = new Mock<FileInfoBase>();
fileInfo.Setup(x => x.Exists).Returns(false);
var dirInfo = new Mock<DirectoryInfoBase>();
dirInfo.Setup(x => x.Exists).Returns(true);
var fs = new Mock<IFileSystemFactory>();
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
var urlDownloader = new Mock<IUrlDownloader>();
var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
.Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
var fixture = new UpdateManager("http://lol", "theApp", FrameworkVersion.Net40, ".", fs.Object, urlDownloader.Object);
using (fixture) {
fixture.CheckForUpdate().First();
}
fs.Verify(x => x.CreateDirectoryRecursive(localPackagesDir), Times.Once());
fs.Verify(x => x.DeleteDirectoryRecursive(localPackagesDir), Times.Once());
*/
}
[Fact]
public void NoLocalDirectoryMeansWeStartFromScratch()
{
Assert.False(true, "Rewrite this to be an integration test");
/*
string localPackagesDir = Path.Combine(".", "theApp", "packages");
string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
var fileInfo = new Mock<FileInfoBase>();
fileInfo.Setup(x => x.Exists).Returns(false);
var dirInfo = new Mock<DirectoryInfoBase>();
dirInfo.Setup(x => x.Exists).Returns(false);
var fs = new Mock<IFileSystemFactory>();
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
fs.Setup(x => x.CreateDirectoryRecursive(It.IsAny<string>())).Verifiable();
fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
var urlDownloader = new Mock<IUrlDownloader>();
var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
.Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
var fixture = new UpdateManager("http://lol", "theApp", FrameworkVersion.Net40, ".", fs.Object, urlDownloader.Object);
using (fixture) {
fixture.CheckForUpdate().First();
}
fs.Verify(x => x.CreateDirectoryRecursive(localPackagesDir), Times.Once());
*/
}
[Fact]
public void CorruptedReleaseFileMeansWeStartFromScratch()
{

View File

@@ -13,36 +13,6 @@ namespace Squirrel.Tests
{
public class DownloadReleasesTests : IEnableLogger
{
[Fact]
public void ChecksumShouldPassOnValidPackages()
{
Assert.False(true, "Rewrite this to be an integration test");
/*
var filename = "Squirrel.Core.1.0.0.0.nupkg";
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
var fs = new Mock<IFileSystemFactory>();
var urlDownloader = new Mock<IUrlDownloader>();
ReleaseEntry entry;
using (var f = File.OpenRead(nuGetPkg)) {
entry = ReleaseEntry.GenerateFromFile(f, filename);
}
var fileInfo = new Mock<FileInfoBase>();
fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg));
fileInfo.Setup(x => x.Exists).Returns(true);
fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length);
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
var fixture = ExposedObject.From(
new UpdateManager("http://lol", "theApp", FrameworkVersion.Net40, ".", fs.Object, urlDownloader.Object));
fixture.checksumPackage(entry);
*/
}
[Fact]
public void ChecksumShouldFailIfFilesAreMissing()
{

View File

@@ -84,6 +84,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReleaseEntryTests.cs" />
<Compile Include="ReleasePackageTests.cs" />
<Compile Include="SquirrelAwareExecutableDetectorTests.cs" />
<Compile Include="TestHelpers\AssertExtensions.cs" />
<Compile Include="TestHelpers\ExposedClass.cs" />
<Compile Include="TestHelpers\ExposedObject.cs" />
@@ -98,6 +99,10 @@
<Project>{1436e22a-fe3c-4d68-9a85-9e74df2e6a92}</Project>
<Name>Squirrel</Name>
</ProjectReference>
<ProjectReference Include="..\src\Update\Update.csproj">
<Project>{1eebacbc-6982-4696-bd4e-899ed0ac6cd2}</Project>
<Name>Update</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Squirrel.Tests.TestHelpers;
using Xunit;
namespace Squirrel.Tests
{
public class SquirrelAwareExecutableDetectorTests
{
[Fact]
public void SquirrelAwareViaVersionBlock()
{
var target = Path.Combine(
IntegrationTestHelper.GetIntegrationTestRootDirectory(),
"..", "src", "Setup", "bin", "Release", "Setup.exe");
Assert.True(File.Exists(target));
var ret = SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target);
Assert.Equal(1, ret.Value);
}
[Fact]
public void SquirrelAwareViaAssemblyAttribute()
{
var target = Path.Combine(
IntegrationTestHelper.GetIntegrationTestRootDirectory(),
"..", "src", "Update", "bin", "Release", "Update.exe");
Assert.True(File.Exists(target));
var ret = SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target);
Assert.Equal(1, ret.Value);
}
[Fact]
public void NotSquirrelAware()
{
var target = Assembly.GetExecutingAssembly().Location;
Assert.True(File.Exists(target));
var ret = SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target);
Assert.Null(ret);
}
[Fact]
public void SquirrelAwareTestAppShouldBeSquirrelAware()
{
var target = IntegrationTestHelper.GetPath("fixtures", "SquirrelAwareApp.exe");
Assert.True(File.Exists(target));
Assert.NotNull(SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target));
}
[Fact]
public void NotSquirrelAwareTestAppShouldNotBeSquirrelAware()
{
var target = IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe");
Assert.True(File.Exists(target));
Assert.Null(SquirrelAwareExecutableDetector.GetPESquirrelAwareVersion(target));
}
}
}

View File

@@ -8,6 +8,7 @@ using Ionic.Zip;
using Squirrel;
using Splat;
using Xunit;
using System.Text;
namespace Squirrel.Tests.TestHelpers
{
@@ -69,6 +70,48 @@ namespace Squirrel.Tests.TestHelpers
return ret;
}
public static string CreateFakeInstalledApp(string version, string outputDir, string nuspecFile = null)
{
var targetDir = default(string);
var nuget = IntegrationTestHelper.GetPath("..", ".nuget", "nuget.exe");
nuspecFile = nuspecFile ?? "SquirrelInstalledApp.nuspec";
using (var clearTemp = Utility.WithTempDirectory(out targetDir)) {
var nuspec = File.ReadAllText(IntegrationTestHelper.GetPath("fixtures", nuspecFile), Encoding.UTF8);
File.WriteAllText(Path.Combine(targetDir, nuspecFile), nuspec.Replace("0.1.0", version), Encoding.UTF8);
File.Copy(
IntegrationTestHelper.GetPath("fixtures", "SquirrelAwareApp.exe"),
Path.Combine(targetDir, "SquirrelAwareApp.exe"));
File.Copy(
IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe"),
Path.Combine(targetDir, "NotSquirrelAwareApp.exe"));
var psi = new ProcessStartInfo(nuget, "pack " + Path.Combine(targetDir, nuspecFile)) {
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = targetDir,
WindowStyle = ProcessWindowStyle.Hidden,
};
var pi = Process.Start(psi);
pi.WaitForExit();
var output = pi.StandardOutput.ReadToEnd();
var err = pi.StandardError.ReadToEnd();
Console.WriteLine(output); Console.WriteLine(err);
var di = new DirectoryInfo(targetDir);
var pkg = di.EnumerateFiles("*.nupkg").First();
var targetPkgFile = Path.Combine(outputDir, pkg.Name);
File.Copy(pkg.FullName, targetPkgFile);
return targetPkgFile;
}
}
public static IDisposable WithFakeInstallDirectory(out string path)
{
return WithFakeInstallDirectory("SampleUpdatingApp.1.1.0.0.nupkg", out path);

View File

@@ -52,6 +52,16 @@ namespace Squirrel.Tests.Core
}
}
[Fact]
public void CreateFakePackageSmokeTest()
{
string path;
using (Utility.WithTempDirectory(out path)) {
var output = IntegrationTestHelper.CreateFakeInstalledApp("0.3.0", path);
Assert.True(File.Exists(output));
}
}
static void CreateSampleDirectory(string directory)
{
while (true) {

BIN
test/fixtures/NotSquirrelAwareApp.exe vendored Normal file

Binary file not shown.

BIN
test/fixtures/SquirrelAwareApp.exe vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>SquirrelInstalledApp</id>
<version>0.1.0</version>
<authors>paul</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My package description.</description>
</metadata>
<files>
<file src="NotSquirrelAwareApp.exe" target="lib\net45\NotSquirrelAwareApp.exe" />
<file src="SquirrelAwareApp.exe" target="lib\net45\SquirrelAwareApp.exe" />
</files>
</package>