Skip to content

Commit

Permalink
Made the same vsix compatible with both VS 2017 and 2019
Browse files Browse the repository at this point in the history
Initial version with minimal testing.
  • Loading branch information
SugoiDev committed Dec 10, 2018
1 parent 580689e commit 715feb7
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 87 deletions.
5 changes: 4 additions & 1 deletion LocalHistory/CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
12/10/2018 v2.1.2 (beta)
12/10/2018 v2.1.3 (beta)
* Made the same vsix compatible with both VS 2017 and 2019 (initial version with minimal testing).

12/10/2018 v2.1.2 (beta)
* Added support for VS 2019+. Using AsyncPackage so VS won't complain.
Notes
* this is a preliminary version and VS 2019 is currently in preview mode. Be careful.
Expand Down
7 changes: 5 additions & 2 deletions LocalHistory/DocumentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,16 @@ public IEnumerable<DocumentNode> GetRevisions([CanBeNull] string filePath) {
return revisions;
}

string[] revisionFiles = Array.Empty<string>();
string[] revisionFiles = null;
if (Directory.Exists(revisionsPath)) {
revisionFiles = Directory.GetFiles(revisionsPath);
}

if (Directory.Exists(oldFormatRevisionsPath)) {
revisionFiles = revisionFiles.Union(Directory.GetFiles(oldFormatRevisionsPath)).ToArray();
revisionFiles = revisionFiles != null
? revisionFiles.Union(Directory.GetFiles(oldFormatRevisionsPath)).ToArray()
: Directory.GetFiles(oldFormatRevisionsPath);

LocalHistoryPackage.Log(
$"Searching for revisions for \"{fileName}\" in \"{revisionsPath}\" and \"{oldFormatRevisionsPath}\" (using old format)");
} else {
Expand Down
150 changes: 116 additions & 34 deletions LocalHistory/LocalHistory.csproj

Large diffs are not rendered by default.

56 changes: 34 additions & 22 deletions LocalHistory/LocalHistoryPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace LOSTALLOY.LocalHistory {
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;


/// <summary>
Expand Down Expand Up @@ -470,23 +471,6 @@ protected override async System.Threading.Tasks.Task InitializeAsync(
//previous logs will be Debug.WriteLine only
Log($"Entering {nameof(InitializeAsync)}");

var isSlnLoaded = await IsSolutionLoadedAsync();
if (isSlnLoaded) {
//already loaded, so we need to handle it asap
HandleSolutionOpen();
}

//it's recommended to keep refs to Events objects to avoid the GC eating them up
//https://stackoverflow.com/a/32600629/2573470
solutionEvents = dte.Events.SolutionEvents;
if (solutionEvents == null) {
Log("Could not get te.Events.SolutionEvents. Will not initialize.");
return;
}

solutionEvents.Opened += HandleSolutionOpen;
solutionEvents.BeforeClosing += HandleSolutionClose;

// Add our command handlers for menu (commands must exist in the .vsct file)
Log("Adding tool menu handler.");
var mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Expand All @@ -506,11 +490,29 @@ protected override async System.Threading.Tasks.Task InitializeAsync(
Log("Could not get IMenuCommandService. Tool menu will not work.");
}

ShowToolWindow(false, cancellationToken);
await ShowToolWindowAsync(false, cancellationToken);

var isSlnLoaded = await IsSolutionLoadedAsync();
if (isSlnLoaded) {
//already loaded, so we need to handle it asap
HandleSolutionOpen();
}

//it's recommended to keep refs to Events objects to avoid the GC eating them up
//https://stackoverflow.com/a/32600629/2573470
solutionEvents = dte.Events.SolutionEvents;
if (solutionEvents == null) {
Log("Could not get te.Events.SolutionEvents. Will not initialize.");
return;
}

//this is distinct from when the user selects a file
//a document might have been opened by some other means and we want to show the local history for it asap
dte.Events.DocumentEvents.DocumentOpened += HandleDocumentOpen;

//we only add our handlers after we got the tool window so we don't break the async method
solutionEvents.Opened += HandleSolutionOpen;
solutionEvents.BeforeClosing += HandleSolutionClose;
}


Expand All @@ -530,25 +532,34 @@ private async Task<bool> IsSolutionLoadedAsync() {
#endregion


private async void ShowToolWindow(bool setVisible, CancellationToken cancellationToken = default) {
private void ShowToolWindow(bool setVisible) {
Log(nameof(ShowToolWindow), false, true);
if (OptionsPage.EnableDebug && _outputWindowPane == null) {
JoinableTaskFactory.Run(() => ShowToolWindowAsync(setVisible));
}


private async Task ShowToolWindowAsync(bool setVisible, CancellationToken cancellationToken = default) {
Log(nameof(ShowToolWindowAsync), false, true);
if (OptionsPage.EnableDebug && _outputWindowPane == null) {
Log("Creating output Window.");

// ReSharper disable once PossibleNullReferenceException
var window = dte.Windows.Item(EnvDTEConstants.vsWindowKindOutput);
var outputWindow = (OutputWindow) window?.Object;
var outputWindow = (OutputWindow)window?.Object;
_outputWindowPane = outputWindow?.OutputWindowPanes.Add(Resources.ToolWindowTitle);
}

if (ToolWindow == null) {
Log("Tool window is null. Searching for it...");

// Get the instance number 0 of this tool window. This window is single instance so this instance
// is actually the only one.
ToolWindow = await FindToolWindowAsync(
typeof(LocalHistoryToolWindow),
0,
true,
cancellationToken) as LocalHistoryToolWindow;

if (ToolWindow?.Frame == null) {
Log("Can not create tool window.");
return;
Expand All @@ -567,9 +578,10 @@ private async void ShowToolWindow(bool setVisible, CancellationToken cancellatio
}

Log("Showing tool window.");

// Make sure the tool window is visible to the user
// ReSharper disable once PossibleNullReferenceException
var windowFrame = (IVsWindowFrame) ToolWindow.Frame;
var windowFrame = (IVsWindowFrame)ToolWindow.Frame;
var result = windowFrame.Show();
if (result != VSConstants.S_OK) {
Log($"Failed to show Window. Error code is: {result}");
Expand Down
5 changes: 2 additions & 3 deletions LocalHistory/LocalHistoryToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.

namespace LOSTALLOY.LocalHistory {
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;

Expand All @@ -34,8 +33,6 @@ public sealed class LocalHistoryToolWindow: ToolWindowPane {
public LocalHistoryToolWindow():
base(null) {

SetWindowCaption();

// Set the image that will appear on the tab of the window frame
// when docked with an other window
// The resource ID correspond to the one defined in the resx file
Expand All @@ -48,6 +45,8 @@ public LocalHistoryToolWindow():
// we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
// the object returned by the Content property.
Content = new LocalHistoryControl();

SetWindowCaption();
}

#endregion
Expand Down
16 changes: 8 additions & 8 deletions LocalHistory/app.config
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.Utilities" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.0.0"/>
<assemblyIdentity name="Microsoft.VisualStudio.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-15.6.0.0" newVersion="15.6.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.Shell.Immutable.11.0" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.0.0"/>
<assemblyIdentity name="StreamJsonRpc" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.0.0" newVersion="1.4.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.CoreUtility" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-15.0.0.0" newVersion="15.0.0.0"/>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /></startup></configuration>
52 changes: 38 additions & 14 deletions LocalHistory/packages.config
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.VisualStudio.CoreUtility" version="15.0.26201" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Imaging" version="15.0.26201" targetFramework="net45" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Shell.15.0" version="15.0.26201" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Shell.Framework" version="15.0.26201" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Shell.Interop" version="7.10.6071" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Shell.Interop.8.0" version="8.0.50727" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Shell.Interop.9.0" version="9.0.30729" targetFramework="net45" />
<package id="Microsoft.VisualStudio.TextManager.Interop" version="7.10.6070" targetFramework="net45" />
<package id="Microsoft.VisualStudio.TextManager.Interop.8.0" version="8.0.50727" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Threading" version="15.0.240" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Utilities" version="15.0.26201" targetFramework="net45" />
<package id="Microsoft.VisualStudio.Validation" version="15.0.82" targetFramework="net45" />
<package id="WPFCustomMessageBox" version="1.0.7" targetFramework="net462" />
<package id="EnvDTE" version="8.0.2" targetFramework="net472" />
<package id="Microsoft.CSharp" version="4.5.0" targetFramework="net472" />
<package id="Microsoft.VisualBasic" version="10.3.0" targetFramework="net472" />
<package id="Microsoft.VisualStudio.CoreUtility" version="15.8.525" targetFramework="net472" />
<package id="Microsoft.VisualStudio.ImageCatalog" version="15.9.28307" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Imaging" version="15.9.28307" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" version="14.3.26930" targetFramework="net472" />
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6071" targetFramework="net472" />
<package id="Microsoft.VisualStudio.SDK.EmbedInteropTypes" version="15.0.27" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.15.0" version="15.6.27413" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Framework" version="15.9.28307" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop" version="7.10.6072" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.10.0" version="10.0.30320" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.11.0" version="11.0.61031" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.12.0" version="12.0.30111" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime" version="14.3.26929" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime" version="15.0.26929" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime" version="15.6.27413" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.8.0" version="8.0.50728" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Shell.Interop.9.0" version="9.0.30730" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Text.Data" version="15.8.525" targetFramework="net472" />
<package id="Microsoft.VisualStudio.TextManager.Interop" version="7.10.6071" targetFramework="net472" />
<package id="Microsoft.VisualStudio.TextManager.Interop.8.0" version="8.0.50728" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Threading" version="15.6.44" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Threading.Analyzers" version="15.6.44" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Utilities" version="15.9.28307" targetFramework="net472" />
<package id="Microsoft.VisualStudio.Validation" version="15.3.58" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net472" />
<package id="StreamJsonRpc" version="1.4.134" targetFramework="net472" />
<package id="System.IO" version="4.3.0" targetFramework="net472" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net472" />
<package id="System.Reflection.Emit" version="4.3.0" targetFramework="net472" />
<package id="System.Runtime" version="4.3.0" targetFramework="net472" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.1" targetFramework="net472" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net472" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net472" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.2" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>
6 changes: 3 additions & 3 deletions LocalHistory/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="48473bd6-841e-4368-8c7a-a5ea9fad7081" Version="2.1.2" Language="en-US" Publisher="LOSTALLOY" />
<Identity Id="48473bd6-841e-4368-8c7a-a5ea9fad7081" Version="2.1.3" Language="en-US" Publisher="LOSTALLOY" />
<DisplayName>Local History for Visual Studio</DisplayName>
<Description xml:space="preserve">Local History for Visual Studio automatically creates a copy everytime you save a file.</Description>
<MoreInfo>https://github.com/LostAlloy/LocalHistory-for-Visual-Studio</MoreInfo>
Expand All @@ -16,12 +16,12 @@
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,4.8)" />
<Dependency Id="Microsoft.VisualStudio.MPF" DisplayName="Visual Studio MPF" d:Source="Installed" Version="[11.0,12.0)" />
<Dependency Id="Microsoft.VisualStudio.MPF" DisplayName="Visual Studio MPF" d:Source="Installed" Version="[11.0,16.0)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" repositoryPath="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
<Prerequisites>
<Prerequisite DisplayName="Visual Studio core editor" Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,17.0)" />
<Prerequisite DisplayName="Visual Studio core editor" Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,17.0)" />
</Prerequisites>
</PackageManifest>

0 comments on commit 715feb7

Please sign in to comment.