Browse Source

Fixed "is assembly in GAC" check for .NET 4 assemblies (thanks to Feng Chen).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5672 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
b6cea6adb3
  1. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs
  2. 2
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs
  3. 4
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs
  4. 11
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.Minimal.cs
  5. 10
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs
  6. 10
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/FusionNative.cs
  7. 26
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/GacInterop.cs
  8. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ProjectContentRegistry.cs

2
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs

@ -83,7 +83,7 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -83,7 +83,7 @@ namespace ICSharpCode.FormsDesigner.Gui
continue;
if (rpc.AssemblyFullName == typeof(object).Assembly.FullName)
continue;
if (FileUtility.IsBaseDirectory(GacInterop.GacRootPath, rpc.AssemblyLocation))
if (GacInterop.IsWithinGac(rpc.AssemblyLocation))
continue;
}
foreach (IClass c in pc.Classes) {

2
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeDiscoveryService.cs

@ -45,7 +45,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -45,7 +45,7 @@ namespace ICSharpCode.FormsDesigner.Services
// ToArray to prevent an exception if the collection changes.
foreach (Assembly asm in TypeResolutionService.DesignerAssemblies.ToArray()) {
if (excludeGlobalTypes) {
if (FileUtility.IsBaseDirectory(GacInterop.GacRootPath, asm.Location)) {
if (GacInterop.IsWithinGac(asm.Location)) {
continue;
}
}

4
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

@ -134,7 +134,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -134,7 +134,7 @@ namespace ICSharpCode.FormsDesigner.Services
} else if (rpc is ReflectionProjectContent) {
ReflectionProjectContent rrpc = (ReflectionProjectContent)rpc;
if (rrpc.AssemblyFullName != typeof(object).FullName
&& !FileUtility.IsBaseDirectory(GacInterop.GacRootPath, rrpc.AssemblyLocation))
&& !GacInterop.IsWithinGac(rrpc.AssemblyLocation))
{
LoadAssembly(rpc);
}
@ -148,7 +148,7 @@ namespace ICSharpCode.FormsDesigner.Services @@ -148,7 +148,7 @@ namespace ICSharpCode.FormsDesigner.Services
return LoadAssembly(((IProject)pc.Project).OutputAssemblyFullPath);
} else if (pc is ReflectionProjectContent) {
ReflectionProjectContent rpc = (ReflectionProjectContent)pc;
if (FileUtility.IsBaseDirectory(GacInterop.GacRootPath, rpc.AssemblyLocation))
if (GacInterop.IsWithinGac(rpc.AssemblyLocation))
return LoadAssembly(new AssemblyName(rpc.AssemblyFullName), false);
else
return LoadAssembly(rpc.AssemblyLocation);

11
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.Minimal.cs

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
// </file>
using System;
using System.IO;
using System.Text;
namespace ICSharpCode.Core
@ -103,5 +104,15 @@ namespace ICSharpCode.Core @@ -103,5 +104,15 @@ namespace ICSharpCode.Core
NormalizePath(fileName2),
StringComparison.OrdinalIgnoreCase);
}
public static bool IsBaseDirectory(string baseDirectory, string testDirectory)
{
if (baseDirectory == null || testDirectory == null)
return false;
baseDirectory = NormalizePath(baseDirectory) + Path.DirectorySeparatorChar;
testDirectory = NormalizePath(testDirectory) + Path.DirectorySeparatorChar;
return testDirectory.StartsWith(baseDirectory, StringComparison.OrdinalIgnoreCase);
}
}
}

10
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

@ -277,16 +277,6 @@ namespace ICSharpCode.Core @@ -277,16 +277,6 @@ namespace ICSharpCode.Core
return NormalizePath(Path.Combine(baseDirectoryPath, relPath));
}
public static bool IsBaseDirectory(string baseDirectory, string testDirectory)
{
if (baseDirectory == null || testDirectory == null)
return false;
baseDirectory = NormalizePath(baseDirectory) + Path.DirectorySeparatorChar;
testDirectory = NormalizePath(testDirectory) + Path.DirectorySeparatorChar;
return testDirectory.StartsWith(baseDirectory, StringComparison.OrdinalIgnoreCase);
}
public static string RenameBaseDirectory(string fileName, string oldDirectory, string newDirectory)
{
fileName = NormalizePath(fileName);

10
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/FusionNative.cs

@ -245,12 +245,16 @@ namespace MSjogren.GacTool.FusionNative @@ -245,12 +245,16 @@ namespace MSjogren.GacTool.FusionNative
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder wzDir,
ref uint pdwSize);
public static string GetGacPath()
public static string GetGacPath(bool isCLRv4 = false)
{
const int size = 260;
const uint ASM_CACHE_ROOT = 0x08; // CLR V2.0
const uint ASM_CACHE_ROOT_EX = 0x80; // CLR V4.0
uint flags = isCLRv4 ? ASM_CACHE_ROOT_EX : ASM_CACHE_ROOT;
const int size = 260; // MAX_PATH
StringBuilder b = new StringBuilder(size);
uint tmp = size;
GetCachePath(8, b, ref tmp); // flag 8 = GAC_ROOT_PATH
GetCachePath(flags, b, ref tmp);
return b.ToString();
}

26
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/GacInterop.cs

@ -20,17 +20,33 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -20,17 +20,33 @@ namespace ICSharpCode.SharpDevelop.Dom
/// </summary>
public static class GacInterop
{
static string cachedGacPath;
volatile static string cachedGacPathV2;
volatile static string cachedGacPathV4;
public static string GacRootPath {
public static string GacRootPathV2 {
get {
if (cachedGacPath == null) {
cachedGacPath = Fusion.GetGacPath();
if (cachedGacPathV2 == null) {
cachedGacPathV2 = Fusion.GetGacPath(false);
}
return cachedGacPath;
return cachedGacPathV2;
}
}
public static string GacRootPathV4 {
get {
if (cachedGacPathV4 == null) {
cachedGacPathV4 = Fusion.GetGacPath(true);
}
return cachedGacPathV4;
}
}
public static bool IsWithinGac(string assemblyLocation)
{
return Core.FileUtility.IsBaseDirectory(GacRootPathV2, assemblyLocation)
|| Core.FileUtility.IsBaseDirectory(GacRootPathV4, assemblyLocation);
}
public static List<DomAssemblyName> GetAssemblyList()
{
IApplicationContext applicationContext = null;

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ProjectContentRegistry.cs

@ -261,7 +261,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -261,7 +261,7 @@ namespace ICSharpCode.SharpDevelop.Dom
if (pc == null && asmName != null) {
string subPath = Path.Combine(asmName.ShortName, GetVersion__Token(asmName));
subPath = Path.Combine(subPath, asmName.ShortName + ".dll");
foreach (string dir in Directory.GetDirectories(GacInterop.GacRootPath, "GAC*")) {
foreach (string dir in Directory.GetDirectories(GacInterop.GacRootPathV4, "GAC*")) {
itemFileName = Path.Combine(dir, subPath);
if (File.Exists(itemFileName)) {
pc = CecilReader.LoadAssembly(itemFileName, this);

Loading…
Cancel
Save