Skip to content

Commit 546d1de

Browse files
per lib/project query folder created Option window validates the folder to linqpad removes linqpad version from the registry
1 parent a59a49c commit 546d1de

7 files changed

Lines changed: 84 additions & 88 deletions

File tree

Src/BridgeVs.Locations/CommonRegistryConfigurations.cs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,18 @@ public class CommonRegistryConfigurations
1010
private const string LINQPadVersionPathRegistryValue = "LINQPadVersion";
1111

1212
// ReSharper disable once InconsistentNaming
13-
public static string LINQPadInstallationPath
13+
public static string GetLINQPadInstallationPath(string vsVersion)
1414
{
15-
get
15+
using (RegistryKey key = Registry.CurrentUser.OpenSubKey($@"Software\LINQBridgeVs\{vsVersion}"))
1616
{
17-
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
18-
{
19-
return key?.GetValue(LINQPadInstallationPathRegistryValue) as string;
20-
}
21-
}
22-
set
23-
{
24-
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
25-
{
26-
key?.SetValue(LINQPadInstallationPathRegistryValue, value);
27-
}
17+
return key?.GetValue(LINQPadInstallationPathRegistryValue) as string;
2818
}
2919
}
30-
31-
// ReSharper disable once InconsistentNaming
32-
public static string LINQPadVersion
20+
public static void SetLINQPadInstallationPath(string vsVersion, string installationPath)
3321
{
34-
get
35-
{
36-
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
37-
{
38-
return key?.GetValue(LINQPadVersionPathRegistryValue) as string;
39-
}
40-
}
41-
set
22+
using (RegistryKey key = Registry.CurrentUser.CreateSubKey($@"Software\LINQBridgeVs\{vsVersion}"))
4223
{
43-
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\LINQBridgeVs\"))
44-
{
45-
key?.SetValue(LINQPadVersionPathRegistryValue, value);
46-
}
24+
key?.SetValue(LINQPadInstallationPathRegistryValue, installationPath);
4725
}
4826
}
4927
}

Src/Build/Tasks/MapperBuildTask.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,6 @@ private void MergeVisualizerWithDependencies(string visualizerInstallationPath,
137137
{
138138
throw new ArgumentException("Installation Path and temporary path cannot be the same", nameof(temporaryVisualizerFilePath));
139139
}
140-
141-
// ILMerge merge = new ILMerge()
142-
// {
143-
// OutputFile = customVisualizerTargetInstallationPath,
144-
//#if DEPLOY
145-
// DebugInfo = false,
146-
//#endif
147-
// TargetKind = ILMerge.Kind.SameAsPrimaryAssembly,
148-
// Closed = false
149-
// };
150-
151-
//the order of input assemblies does matter. the first assembly is used as a template (for assembly attributes also)
152-
//for merging all the rest into it
153-
//merge.SetInputAssemblies(new[] {
154-
// temporaryVisualizerFilePath,
155-
// typeof(DynamicCore.DynamicDebuggerVisualizer).Assembly.Location,
156-
// typeof(Newtonsoft.Json.DateFormatHandling).Assembly.Location,
157-
// typeof(Grapple.Truck).Assembly.Location,
158-
// typeof(Locations.CommonFolderPaths).Assembly.Location,
159-
// typeof(Log).Assembly.Location,
160-
// typeof(System.IO.Abstractions.DirectoryBase).Assembly.Location
161-
// });
162-
163-
//string searchDirectory = VisualStudioOptions.GetCommonReferenceAssembliesPath(VisualStudioVer).FirstOrDefault(Directory.Exists);
164-
165-
//merge.SetSearchDirectories(new[] { Path.GetDirectoryName(GetType().Assembly.Location), searchDirectory });
166-
167-
//merge.Merge();
168140
}
169141
/// <summary>
170142
/// Maps the dot net framework types. If the file already exists for a given vs version it won't be

Src/DynamicCore/DynamicDebuggerVisualizer.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ internal void DeployLinqScript(Message message)
9595
string dstScriptPath = CommonFolderPaths.LinqPadQueryFolder;
9696

9797
Log.Write("dstScriptPath: {0}", dstScriptPath);
98+
string targetFolder = Path.Combine(dstScriptPath, message.AssemblyName);
9899

99-
string dst = Path.Combine(dstScriptPath, string.Format(message.FileName, message.TypeFullName));
100-
Log.Write("dst: {0}", dst);
100+
if (!Directory.Exists(targetFolder))
101+
Directory.CreateDirectory(targetFolder);
102+
103+
string linqPadScriptPath = Path.Combine(targetFolder, message.FileName);
104+
Log.Write("linqPadScriptPath: {0}", linqPadScriptPath);
101105

102106
List<string> refAssemblies = new List<string>();
103107
refAssemblies.AddRange(message.ReferencedAssemblies);
@@ -106,15 +110,14 @@ internal void DeployLinqScript(Message message)
106110

107111
Log.Write("LinqQuery file Transformed");
108112

109-
using (Stream memoryStream = FileSystem.File.Open(dst, FileMode.Create))
113+
using (Stream memoryStream = FileSystem.File.Open(linqPadScriptPath, FileMode.Create))
110114
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
111115
{
112116
streamWriter.Write(linqQueryText);
113117
streamWriter.Flush();
114118
memoryStream.Flush();
115119
}
116120
Log.Write("LinqQuery file Generated");
117-
118121
}
119122
catch (Exception e)
120123
{
@@ -152,13 +155,13 @@ public Form ShowLINQPad(Stream inData, string vsVersion)
152155
DeployLinqScript(message);
153156
Log.Write("LinqQuery Successfully deployed");
154157

155-
string linqQueryfileName = Path.Combine(CommonFolderPaths.LinqPadQueryFolder, message.FileName);
156-
158+
string linqQueryfileName = Path.Combine(CommonFolderPaths.LinqPadQueryFolder, message.AssemblyName, message.FileName);
159+
string linqPadInstallationPath = CommonRegistryConfigurations.GetLINQPadInstallationPath(vsVersion);
157160
ProcessStartInfo startInfo = new ProcessStartInfo
158161
{
159162
WindowStyle = ProcessWindowStyle.Normal,
160163
FileName = Resources.LINQPadExe,
161-
WorkingDirectory = CommonRegistryConfigurations.LINQPadInstallationPath,
164+
WorkingDirectory = linqPadInstallationPath,
162165
Arguments = linqQueryfileName + " " + Resources.LINQPadCommands
163166
};
164167

@@ -170,8 +173,10 @@ public Form ShowLINQPad(Stream inData, string vsVersion)
170173
process.WaitForInputIdle(-1);
171174
process.Dispose();
172175
}
176+
string linqPadExePath = Path.Combine(linqPadInstallationPath, Resources.LINQPadExe);
177+
string linqPadVersion = FileVersionInfo.GetVersionInfo(linqPadExePath).FileDescription;
173178

174-
Process foundProcess = Process.GetProcessesByName("LINQPad").FirstOrDefault(p => CommonRegistryConfigurations.LINQPadVersion.Equals(p.MainWindowTitle));
179+
Process foundProcess = Process.GetProcessesByName("LINQPad").FirstOrDefault(p => linqPadVersion.Equals(p.MainWindowTitle));
175180

176181
SendInputToProcess(foundProcess ?? process);
177182

Src/DynamicCore/DynamicObjectSource.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void BroadCastData(object target, Stream outgoingData)
4848
Type targetType = GetInterfaceTypeIfIsIterator(target);
4949
string targetTypeFullName = TypeNameHelper.GetDisplayName(targetType, true);
5050
string targetTypeName = TypeNameHelper.GetDisplayName(targetType, false);
51-
//I'm lazy I know it...
51+
//I'm lazy I know...
5252
Regex pattern1 = new Regex("[<]");
5353
Regex pattern2 = new Regex("[>]");
5454
Regex pattern3 = new Regex("[,]");
@@ -72,7 +72,8 @@ public static void BroadCastData(object target, Stream outgoingData)
7272
TypeName = typeName.Trim(),
7373
TypeFullName = targetTypeFullName,
7474
TypeNamespace = targetType.Namespace,
75-
AssemblyQualifiedName = targetType.AssemblyQualifiedName
75+
AssemblyQualifiedName = targetType.AssemblyQualifiedName,
76+
AssemblyName = targetType.Assembly.GetName().Name
7677
};
7778

7879
BinaryFormatter binaryFormatter = new BinaryFormatter();

Src/DynamicCore/Template/Message.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ internal class Message
3737

3838
public string TypeNamespace;
3939
public string AssemblyQualifiedName;
40+
public string AssemblyName;
41+
4042
public readonly List<string> ReferencedAssemblies;
4143

4244
public Message()
@@ -46,14 +48,13 @@ public Message()
4648

4749
public override string ToString()
4850
{
49-
return "FileName: " + FileName
50-
+ Environment.NewLine
51-
+ "TypeFullName: " + TypeFullName
52-
+ Environment.NewLine
53-
+ "TypeName: " + TypeName
51+
return "FileName: " + FileName
52+
+ Environment.NewLine
53+
+ "TypeFullName: " + TypeFullName
54+
+ Environment.NewLine
55+
+ "TypeName: " + TypeName
5456
+ Environment.NewLine
55-
+ "TypeNamespace: " + TypeNamespace
56-
+ Environment.NewLine;
57+
+ "TypeNamespace: " + TypeNamespace;
5758
}
5859
}
5960
}

Src/VsExtension.Helper/Configuration/PackageConfigurator.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,23 @@ private static string InstalledExtensionVersion(string vsVersion)
7575
}
7676

7777
// ReSharper disable once InconsistentNaming
78-
private static bool IsLINQPadInstalled()
78+
private static bool IsLINQPadInstalled(string vsVersion)
7979
{
80+
var currentInstalledVersionPath = CommonRegistryConfigurations.GetLINQPadInstallationPath(vsVersion);
81+
var alreadyInstalled = !string.IsNullOrEmpty(currentInstalledVersionPath);
82+
83+
if (alreadyInstalled && Directory.Exists(currentInstalledVersionPath))
84+
return true;
85+
86+
//otherwise set it up manually
8087
if (Directory.Exists(CommonFolderPaths.LinqPad5DestinationFolder))
8188
{
82-
CommonRegistryConfigurations.LINQPadInstallationPath = CommonFolderPaths.LinqPad5DestinationFolder;
83-
CommonRegistryConfigurations.LINQPadVersion = LinqPad5;
89+
CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, CommonFolderPaths.LinqPad5DestinationFolder);
8490
return true;
8591
}
8692
if (Directory.Exists(CommonFolderPaths.LinqPad4DestinationFolder))
8793
{
88-
CommonRegistryConfigurations.LINQPadInstallationPath = CommonFolderPaths.LinqPad4DestinationFolder;
89-
CommonRegistryConfigurations.LINQPadVersion = LinqPad4;
94+
CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, CommonFolderPaths.LinqPad4DestinationFolder);
9095
return true;
9196
}
9297

@@ -112,9 +117,8 @@ private static bool IsLINQPadInstalled()
112117
if (string.IsNullOrEmpty(linqPadDirectoryName))
113118
throw new Exception("LINQPad file name not correct");
114119

115-
CommonRegistryConfigurations.LINQPadInstallationPath = linqPadDirectoryName;
116-
CommonRegistryConfigurations.LINQPadVersion = linqPadDirectoryName.Contains("LINQPad 5") ? LinqPad5 : LinqPad4;
117-
120+
CommonRegistryConfigurations.SetLINQPadInstallationPath(vsVersion, linqPadDirectoryName);
121+
118122
return true;
119123
}
120124
openWebSite:
@@ -222,7 +226,6 @@ public static bool IsBridgeVsConfigured(string visualStudioVersion)
222226

223227
return !string.IsNullOrEmpty(installationFolder) && installationFolder == CommonFolderPaths.InstallFolder;
224228
}
225-
226229
private static void SetBridgeVsAssemblyVersion(string vsVersion)
227230
{
228231
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(GetRegistryKey(Resources.ProductVersion, vsVersion)))
@@ -236,7 +239,7 @@ public static bool Install(string vsVersion, string vsEdition)
236239

237240
try
238241
{
239-
if (!IsLINQPadInstalled()) //ask the user to insert a custom location
242+
if (!IsLINQPadInstalled(vsVersion)) //ask the user to insert a custom location
240243
{
241244
return false;
242245
}
@@ -374,7 +377,7 @@ private static void CreateVisualizerFolder(string vsVersion)
374377
Log.Write($"Directory Created: {debuggerVisualizerTargetFolder}");
375378

376379
}
377-
380+
378381
private static void CreateGrappleFolder()
379382
{
380383
Log.Write("Creating folder for Delivery {0}", Path.GetFullPath(CommonFolderPaths.GrappleFolder));
@@ -386,7 +389,6 @@ private static void CreateGrappleFolder()
386389

387390
Log.Write("Folder Successfully Created");
388391
}
389-
390392
#endregion
391393
}
392-
}
394+
}

Src/VsExtension.Helper/Settings/PackageSettings.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
using System.Runtime.InteropServices;
44
using Microsoft.VisualStudio.Shell;
55
using BridgeVs.Locations;
6+
using EnvDTE;
7+
using Microsoft.VisualStudio.Shell.Interop;
8+
using System.Windows.Forms;
9+
using System.IO;
10+
using System.Linq;
611

712
namespace BridgeVs.Helper.Settings
813
{
@@ -16,8 +21,40 @@ public sealed class PackageSettings : DialogPage
1621
[Description("Sets the path to the LINQPad exe")]
1722
public string LINQPadInstallationPath
1823
{
19-
get => CommonRegistryConfigurations.LINQPadInstallationPath;
20-
set => CommonRegistryConfigurations.LINQPadInstallationPath = value;
24+
get
25+
{
26+
var dte = (DTE)GetService(typeof(SDTE));
27+
if (dte != null)
28+
return CommonRegistryConfigurations.GetLINQPadInstallationPath(dte.Version);
29+
30+
return string.Empty;
31+
}
32+
set
33+
{
34+
var dte = (DTE)GetService(typeof(SDTE));
35+
if (dte != null)
36+
{
37+
if (string.IsNullOrEmpty(value))
38+
{
39+
MessageBox.Show("Please insert a valid path to LINQPad");
40+
return;
41+
}
42+
bool possiblePath = value.IndexOfAny(Path.GetInvalidPathChars()) == -1;
43+
44+
if (!possiblePath)
45+
{
46+
MessageBox.Show("Please insert a valid path to LINQPad");
47+
return;
48+
}
49+
50+
if (!Directory.GetFiles(value, "*.exe", SearchOption.TopDirectoryOnly).Any( p=> p.Contains("LINQPad.exe")))
51+
{
52+
MessageBox.Show("Please insert a valid path to LINQPad");
53+
return;
54+
}
55+
CommonRegistryConfigurations.SetLINQPadInstallationPath(dte.Version, value);
56+
}
57+
}
2158
}
2259

2360
//[Category("Feedback")]

0 commit comments

Comments
 (0)