Skip to content

Commit

Permalink
Merge pull request Squirrel#478 from Squirrel/shim-no-more
Browse files Browse the repository at this point in the history
Remove AppCompat shims that applied to our applications
  • Loading branch information
anaisbetts committed Nov 2, 2015
2 parents 76b0c78 + bd4f874 commit 2b3cb6c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Squirrel.Shell;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;
using Microsoft.Win32;

namespace Squirrel
{
Expand Down Expand Up @@ -72,6 +73,9 @@ await this.ErrorIfThrows(() => invokePostInstall(newVersion, attemptingFullInsta
this.ErrorIfThrows(() => trayFixer.RemoveDeadEntries(allExes, rootAppDirectory, updateInfo.FutureReleaseEntry.Version.ToString()));
progress(80);

unshimOurselves();
progress(85);

try {
var currentVersion = updateInfo.CurrentlyInstalledVersion != null ?
updateInfo.CurrentlyInstalledVersion.Version : null;
Expand Down Expand Up @@ -525,6 +529,33 @@ void updateLink(ShellLink shortcut, string[] oldAppDirectories, string newAppPat
}
}

internal void unshimOurselves()
{
new[] { RegistryView.Registry32, RegistryView.Registry64 }.ForEach(view => {
var baseKey = default(RegistryKey);
var regKey = default(RegistryKey);

try {
baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, view);
regKey = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers");

var toDelete = regKey.GetValueNames()
.Where(x => x.StartsWith(rootAppDirectory, StringComparison.OrdinalIgnoreCase))
.ToList();

toDelete.ForEach(x => regKey.DeleteValue(x));

//toDelete.ForEach(x =>
// this.Log().LogIfThrows(LogLevel.Warn, "Failed to delete key: " + x, () => regKey.DeleteValue(x)));
} catch (Exception e) {
this.Log().WarnException("Couldn't rewrite shim RegKey, most likely no apps are shimmed", e);
} finally {
if (regKey != null) regKey.Dispose();
if (baseKey != null) baseKey.Dispose();
}
});
}

// NB: Once we uninstall the old version of the app, we try to schedule
// it to be deleted at next reboot. Unfortunately, depending on whether
// the user has admin permissions, this can fail. So as a failsafe,
Expand Down
4 changes: 4 additions & 0 deletions src/Update/Update.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="DeltaCompressionDotNet">
<HintPath>..\..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll</HintPath>
Expand Down Expand Up @@ -83,6 +86,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Update.com">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
38 changes: 38 additions & 0 deletions src/Update/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />

<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />

<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />

<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>

<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>

</assembly>
11 changes: 11 additions & 0 deletions test/ApplyReleasesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,17 @@ public async Task CreateShortcutsRoundTrip()
Thread.Sleep(1000);
}
}

[Fact]
public void UnshimOurselvesSmokeTest()
{
// NB: This smoke test is really more of a manual test - try it
// by shimming Slack, then verifying the shim goes away
var appDir = Environment.ExpandEnvironmentVariables(@"%LocalAppData%\Slack");
var fixture = new UpdateManager.ApplyReleasesImpl(appDir);

fixture.unshimOurselves();
}

[Fact]
public async Task GetShortcutsSmokeTest()
Expand Down

0 comments on commit 2b3cb6c

Please sign in to comment.