Merge pull request #53 from Squirrel/animated-gifsssss

Add a Loading GIF for long installations
This commit is contained in:
Paul Betts
2014-09-24 12:09:37 -07:00
4 changed files with 101 additions and 5 deletions

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using WpfAnimatedGif;
namespace Squirrel.Update
{
public class AnimatedGifWindow : Window
{
public AnimatedGifWindow()
{
var src = new BitmapImage();
src.BeginInit();
var source = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"background.gif");
if (File.Exists(source)) {
src.StreamSource = File.OpenRead(source);
}
src.EndInit();
var img = new Image();
ImageBehavior.SetAnimatedSource(img, src);
this.Content = img;
this.Width = src.Width;
this.Height = src.Height;
this.AllowsTransparency = true;
this.WindowStyle = WindowStyle.None;
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.ShowInTaskbar = false;
this.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
}
public static void ShowWindow(TimeSpan initialDelay, CancellationToken token)
{
var wnd = default(AnimatedGifWindow);
var thread = new Thread(() => {
try {
Task.Delay(initialDelay, token).Wait();
} catch (OperationCanceledException) {
return;
}
wnd = new AnimatedGifWindow();
wnd.Show();
token.Register(() => wnd.Dispatcher.BeginInvoke(new Action(wnd.Close)));
(new Application()).Run(wnd);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
}
}

View File

@@ -39,10 +39,16 @@ namespace Squirrel.Update
int main(string[] args)
{
var animatedGifWindowToken = new CancellationTokenSource();
// NB: Trying to delete the app directory while we have Setup.log
// open will actually crash the uninstaller
bool isUninstalling = args.Any(x => x.Contains("uninstall"));
// Uncomment to test Gifs
//AnimatedGifWindow.ShowWindow(TimeSpan.FromMilliseconds(0), animatedGifWindowToken.Token);
//Thread.Sleep(10 * 60 * 1000);
using (var logger = new SetupLogLogger(isUninstalling) { Level = Splat.LogLevel.Info }) {
Splat.Locator.CurrentMutable.Register(() => logger, typeof(Splat.ILogger));
@@ -61,6 +67,7 @@ namespace Squirrel.Update
string releaseDir = default(string);
string packagesDir = default(string);
string bootstrapperExe = default(string);
string backgroundGif = default(string);
opts = new OptionSet() {
"Usage: Update.exe command [OPTS]",
@@ -78,6 +85,7 @@ namespace Squirrel.Update
{ "r=|releaseDir=", "Path to a release directory to use with releasify", v => releaseDir = v},
{ "p=|packagesDir=", "Path to the NuGet Packages directory for C# apps", v => packagesDir = v},
{ "bootstrapperExe=", "Path to the Setup.exe to use as a template", v => bootstrapperExe = v},
{ "g=|loadingGif=", "Path to an animated GIF to be displayed during installation", v => backgroundGif = v},
{ "s|silent", "Silent install", _ => silentInstall = true},
};
@@ -89,6 +97,7 @@ namespace Squirrel.Update
switch (updateAction) {
case UpdateAction.Install:
AnimatedGifWindow.ShowWindow(TimeSpan.FromSeconds(4), animatedGifWindowToken.Token);
Install(silentInstall, Path.GetFullPath(target)).Wait();
break;
case UpdateAction.Uninstall:
@@ -101,9 +110,11 @@ namespace Squirrel.Update
Update(target).Wait();
break;
case UpdateAction.Releasify:
Releasify(target, releaseDir, packagesDir, bootstrapperExe);
Releasify(target, releaseDir, packagesDir, bootstrapperExe, backgroundGif);
break;
}
animatedGifWindowToken.Cancel();
}
return 0;
@@ -180,7 +191,7 @@ namespace Squirrel.Update
}
}
public void Releasify(string package, string targetDir = null, string packagesDir = null, string bootstrapperExe = null)
public void Releasify(string package, string targetDir = null, string packagesDir = null, string bootstrapperExe = null, string backgroundGif = null)
{
targetDir = targetDir ?? ".\\Releases";
packagesDir = packagesDir ?? ".";
@@ -236,7 +247,7 @@ namespace Squirrel.Update
var newestFullRelease = releaseEntries.MaxBy(x => x.Version).Where(x => !x.IsDelta).First();
File.Copy(bootstrapperExe, targetSetupExe, true);
var zipPath = createSetupEmbeddedZip(Path.Combine(di.FullName, newestFullRelease.Filename), di.FullName);
var zipPath = createSetupEmbeddedZip(Path.Combine(di.FullName, newestFullRelease.Filename), di.FullName, backgroundGif);
try {
var zip = File.ReadAllBytes(zipPath);
@@ -267,7 +278,7 @@ namespace Squirrel.Update
opts.WriteOptionDescriptions(Console.Out);
}
string createSetupEmbeddedZip(string fullPackage, string releasesDir)
string createSetupEmbeddedZip(string fullPackage, string releasesDir, string backgroundGif)
{
string tempPath;
@@ -278,6 +289,12 @@ namespace Squirrel.Update
File.Copy(fullPackage, Path.Combine(tempPath, Path.GetFileName(fullPackage)));
}, "Failed to write package files to temp dir: " + tempPath);
if (!String.IsNullOrWhiteSpace(backgroundGif)) {
this.ErrorIfThrows(() => {
File.Copy(backgroundGif, Path.Combine(tempPath, "background.gif"));
}, "Failed to write animated GIF to temp dir: " + tempPath);
}
var releases = new[] { ReleaseEntry.GenerateFromFile(fullPackage) };
ReleaseEntry.WriteReleaseFile(releases, Path.Combine(tempPath, "RELEASES"));

View File

@@ -54,6 +54,8 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\NuGet.Core.2.8.2\lib\net40-Client\NuGet.Core.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="Splat">
<HintPath>..\..\packages\Splat.1.4.0\lib\Net45\Splat.dll</HintPath>
</Reference>
@@ -61,13 +63,19 @@
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="WpfAnimatedGif">
<HintPath>..\..\packages\WpfAnimatedGif.1.4.5\lib\net\WpfAnimatedGif.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AnimatedGifWindow.cs" />
<Compile Include="Mono.Options\Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -93,7 +101,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PostBuildEvent>cd "$(TargetPath)"
"$(SolutionDir)\packages\ILRepack.1.25.0\tools\ILRepack.exe" /internalize /out:$(TargetFileName).tmp $(TargetFileName) Ionic.Zip.dll Microsoft.Web.XmlTransform.dll Mono.Cecil.dll NuGet.Core.dll Splat.dll Squirrel.dll
"$(SolutionDir)\packages\ILRepack.1.25.0\tools\ILRepack.exe" /internalize /out:$(TargetFileName).tmp $(TargetFileName) WpfAnimatedGif.dll Ionic.Zip.dll Microsoft.Web.XmlTransform.dll Mono.Cecil.dll NuGet.Core.dll Splat.dll Squirrel.dll
del "$(TargetFileName)"
ren "$(TargetFileName).tmp" "$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>

View File

@@ -6,4 +6,5 @@
<package id="NuGet.Core" version="2.8.2" targetFramework="net45" />
<package id="SimpleJson" version="0.38.0" targetFramework="net45" />
<package id="Splat" version="1.4.0" targetFramework="net45" />
<package id="WpfAnimatedGif" version="1.4.5" targetFramework="net45" />
</packages>