Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET Framework 3.0 Change #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ Makefile.in
/configure
/install-sh
/missing

#Jetbrains stuff
.idea/
33 changes: 18 additions & 15 deletions Mono.Addins/Mono.Addins.Database/AddinDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,18 @@ public void DisableAddin (string domain, string id, bool exactVersionMatch = fal
public void UpdateEnabledStatus ()
{
// Ensure that all enabled addins that have dependencies also have their dependencies enabled.
HashSet<Addin> updatedAddins = new HashSet<Addin> ();
List<Addin> updatedAddins = new List<Addin> ();
var allAddins = GetInstalledAddins (registry.CurrentDomain, AddinSearchFlagsInternal.IncludeAddins | AddinSearchFlagsInternal.LatestVersionsOnly).ToList ();
foreach (Addin addin in allAddins)
UpdateEnabledStatus (registry.CurrentDomain, addin, allAddins, updatedAddins);
}

void UpdateEnabledStatus (string domain, Addin addin, List<Addin> allAddins, HashSet<Addin> updatedAddins)
void UpdateEnabledStatus (string domain, Addin addin, List<Addin> allAddins, List<Addin> updatedAddins)
{
if (!updatedAddins.Add (addin))
if (updatedAddins.Contains(addin))
return;

updatedAddins.Add(addin);

if (!addin.Enabled)
return;
Expand Down Expand Up @@ -1027,21 +1029,21 @@ internal void ResetCachedData ()
addinEngine.ResetCachedData ();
}

Dictionary<string, HashSet<string>> dependsOnCache = new Dictionary<string, HashSet<string>> ();
Dictionary<string, List<string>> dependsOnCache = new Dictionary<string, List<string>> ();
public bool AddinDependsOn (string domain, string id1, string id2)
{
var depTree = GetOrCreateAddInDependencyTree (domain, id1);
return depTree.Contains (id2);
}

HashSet<string> GetOrCreateAddInDependencyTree (string domain, string addin)
List<string> GetOrCreateAddInDependencyTree (string domain, string addin)
{
HashSet<string> cache;
List<string> cache;
if (dependsOnCache.TryGetValue (addin, out cache)) {
return cache;
}
}

dependsOnCache [addin] = cache = new HashSet<string> ();
dependsOnCache [addin] = cache = new List<string> ();

Addin addin1 = GetInstalledAddin (domain, addin, false);

Expand All @@ -1058,7 +1060,7 @@ HashSet<string> GetOrCreateAddInDependencyTree (string domain, string addin)
cache.Add (depid);

var recursiveDependencies = GetOrCreateAddInDependencyTree (domain, depid);
cache.UnionWith (recursiveDependencies);
return cache.Union(recursiveDependencies).Distinct().ToList();
}
return cache;
}
Expand Down Expand Up @@ -1165,8 +1167,7 @@ void RunPendingUninstalls (IProgressStatus monitor)
bool changesDone = false;

foreach (var adn in Configuration.GetPendingUninstalls ()) {
HashSet<string> files = new HashSet<string> (adn.Files);
if (AddinManager.CheckAssembliesLoaded (files))
if (AddinManager.CheckAssembliesLoaded (adn.Files))
continue;

if (monitor.LogLevel > 1)
Expand Down Expand Up @@ -1381,7 +1382,7 @@ void InternalScanFolders2 (IProgressStatus monitor, AddinScanResult scanResult)

// Check if any of the previously scanned folders has been deleted

foreach (string file in Directory.EnumerateFiles (AddinFolderCachePath, "*.data")) {
foreach (string file in Directory.GetFiles (AddinFolderCachePath, "*.data")) {
AddinScanFolderInfo folderInfo;
bool res = ReadFolderInfo (monitor, file, out folderInfo);
bool validForDomain = scanResult.Domain == null || folderInfo.Domain == GlobalDomain || folderInfo.Domain == scanResult.Domain;
Expand Down Expand Up @@ -1946,7 +1947,7 @@ public string FindCondition (AddinDescription desc, ModuleDescription mod, strin

public List<AddinDescription> GetSortedAddins ()
{
var inserted = new HashSet<string> ();
var inserted = new List<string> ();
var lists = new Dictionary<string,List<AddinDescription>> ();

foreach (List<AddinDescription> dlist in addins.Values) {
Expand All @@ -1970,12 +1971,14 @@ public List<AddinDescription> GetSortedAddins ()
return sortedAddins;
}

void InsertSortedAddin (HashSet<string> inserted, Dictionary<string,List<AddinDescription>> lists, AddinDescription desc)
void InsertSortedAddin (List<string> inserted, Dictionary<string,List<AddinDescription>> lists, AddinDescription desc)
{
string sid = desc.AddinId + " " + desc.Domain;
if (!inserted.Add (sid))
if (inserted.Contains (sid))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not add here, which means you may see more cases where you contain it than you should.

return;

inserted.Add(sid);

foreach (ModuleDescription mod in desc.AllModules) {
foreach (Dependency dep in mod.Dependencies) {
AddinDependency adep = dep as AddinDependency;
Expand Down
4 changes: 2 additions & 2 deletions Mono.Addins/Mono.Addins.Database/AddinFileSystemExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public virtual bool FileExists (string path)
/// </param>
public virtual System.Collections.Generic.IEnumerable<string> GetFiles (string path)
{
return Directory.EnumerateFiles (path);
return Directory.GetFiles (path);
}

/// <summary>
Expand All @@ -108,7 +108,7 @@ public virtual System.Collections.Generic.IEnumerable<string> GetFiles (string p
/// </param>
public virtual System.Collections.Generic.IEnumerable<string> GetDirectories (string path)
{
return Directory.EnumerateDirectories (path);
return Directory.GetDirectories (path);
}

/// <summary>
Expand Down
9 changes: 7 additions & 2 deletions Mono.Addins/Mono.Addins.Database/AddinFolderVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Mono.Addins.Database
class AddinFolderVisitor
{
AddinDatabase database;
HashSet<string> visitedFolders = new HashSet<string> ();
List<string> visitedFolders = new List<string> ();

public ScanContext ScanContext { get; set; } = new ScanContext();

Expand All @@ -56,7 +56,12 @@ public void VisitFolder (IProgressStatus monitor, string path, string domain, bo
void VisitFolderInternal (IProgressStatus monitor, string path, string domain, bool recursive)
{
// Avoid folders including each other
if (!visitedFolders.Add (path) || ScanContext.IgnorePath (path))
if (visitedFolders.Contains(path))
return;

visitedFolders.Add(path);

if (ScanContext.IgnorePath (path))
return;

OnVisitFolder (monitor, path, domain, recursive);
Expand Down
5 changes: 3 additions & 2 deletions Mono.Addins/Mono.Addins.Database/AddinScanResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@ class FileToScan

class ScanContext
{
HashSet<string> filesToIgnore;
List<string> filesToIgnore;

public void AddPathToIgnore (string path)
{
if (filesToIgnore == null)
filesToIgnore = new HashSet<string> ();
filesToIgnore = new List<string> ();
filesToIgnore.Add (path);
filesToIgnore = filesToIgnore.Distinct().ToList();
}

public bool IgnorePath (string file)
Expand Down
12 changes: 6 additions & 6 deletions Mono.Addins/Mono.Addins.Database/AddinScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,14 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
if (!config.IsRoot) {
foreach (ModuleDescription mod in config.OptionalModules) {
try {
var asmList = new List<Tuple<string,object>> ();
var asmList = new List<object[]> ();
for (int n=0; n<mod.Assemblies.Count; n++) {
string s = mod.Assemblies [n];
if (mod.IgnorePaths.Contains (s))
continue;
string asmFile = Path.Combine (config.BasePath, Util.NormalizePath (s));
object asm = reflector.LoadAssembly (asmFile);
asmList.Add (new Tuple<string,object> (asmFile,asm));
asmList.Add(new[] {asmFile, asm});
scanContext.AddPathToIgnore (Path.GetFullPath (asmFile));
ScanAssemblyImports (reflector, mod, asm);
}
Expand All @@ -535,7 +535,7 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
}

foreach (var asm in asmList)
ScanSubmodule (monitor, mod, reflector, config, asm.Item1, asm.Item2);
ScanSubmodule (monitor, mod, reflector, config, (string)asm[0], asm[1]);

} catch (Exception ex) {
ReportReflectionException (monitor, ex, config);
Expand Down Expand Up @@ -781,7 +781,7 @@ void ScanAssemblyContents (IAssemblyReflector reflector, AddinDescription config

//condition attributes apply independently but identically to all extension attributes on this node
//depending on ordering is too messy due to inheritance etc
var conditionAtts = new Lazy<List<CustomAttribute>> (() => reflector.GetRawCustomAttributes (t, typeof (CustomConditionAttribute), false));
var conditionAtts = reflector.GetRawCustomAttributes (t, typeof (CustomConditionAttribute), false);

// Look for extensions

Expand All @@ -807,7 +807,7 @@ void ScanAssemblyContents (IAssemblyReflector reflector, AddinDescription config
path = eatt.Path;
}

ExtensionNodeDescription elem = AddConditionedExtensionNode (module, path, nodeName, conditionAtts.Value);
ExtensionNodeDescription elem = AddConditionedExtensionNode (module, path, nodeName, conditionAtts);
nodes [path] = elem;
uniqueNode = elem;

Expand Down Expand Up @@ -873,7 +873,7 @@ void ScanAssemblyContents (IAssemblyReflector reflector, AddinDescription config
else {
// Look for custom extension attribtues
foreach (CustomAttribute att in reflector.GetRawCustomAttributes (t, typeof(CustomExtensionAttribute), false)) {
ExtensionNodeDescription elem = AddCustomAttributeExtension (module, att, "Type", conditionAtts.Value);
ExtensionNodeDescription elem = AddCustomAttributeExtension (module, att, "Type", conditionAtts);
elem.SetAttribute ("type", typeQualifiedName);
if (string.IsNullOrEmpty (elem.GetAttribute ("id")))
elem.SetAttribute ("id", typeQualifiedName);
Expand Down
13 changes: 10 additions & 3 deletions Mono.Addins/Mono.Addins.Database/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,22 @@ public static string GetGacPath (string fullName)
foreach (var dir in Directory.GetDirectories (asmDir, "v*_" + versionDirName)) {
var dirName = Path.GetFileName (dir);
i = dirName.IndexOf ('_');
Version av;
if (Version.TryParse (dirName.Substring (1, i - 1), out av)) {

try
{
Version av = new Version(dirName.Substring(1, i - 1));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dirName.Substring could theorically fail silently here, whereas it could not before.

if (av == currentVersion)
return dir;
else if (av < currentVersion && av > bestVersion) {

if (av < currentVersion && av > bestVersion) {
bestDir = dir;
bestVersion = av;
}
}
catch
{

}
}
if (bestDir != null)
return bestDir;
Expand Down
15 changes: 12 additions & 3 deletions Mono.Addins/Mono.Addins.Description/AddinDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,19 @@ internal StringCollection Verify (AddinFileSystemExtension fs)
// Ensure that there are no duplicated properties

if (properties != null) {
HashSet<string> props = new HashSet<string> ();
foreach (var prop in properties) {
if (!props.Add (prop.Name + " " + prop.Locale))
List<string> props = new List<string> ();
foreach (var prop in properties)
{
var stringToCheck = prop.Name + " " + prop.Locale;
if (props.Contains(stringToCheck))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again

{
errors.Add (string.Format ("Property {0} specified more than once", prop.Name + (prop.Locale != null ? " (" + prop.Locale + ")" : "")));
}
else
{
props.Add(stringToCheck);
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions Mono.Addins/Mono.Addins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<TargetFrameworkVersion>v3.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand Down Expand Up @@ -46,6 +47,7 @@
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<PackageReference Include="LinqBridge" Version="1.3.0" />
<PackageReference Include="NuGet.Build.Packaging" Version="0.2.0" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Mono.Addins/Mono.Addins/AddinEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ internal void ActivateRoots ()

void CheckHostAssembly (Assembly asm)
{
if (AddinDatabase.RunningSetupProcess || asm is System.Reflection.Emit.AssemblyBuilder || asm.IsDynamic)
if (AddinDatabase.RunningSetupProcess || asm is System.Reflection.Emit.AssemblyBuilder || asm.ManifestModule is System.Reflection.Emit.ModuleBuilder)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% convinced here, some people seem to disagree on this in stackoverflow

return;
string codeBase;
try {
Expand Down
2 changes: 1 addition & 1 deletion Mono.Addins/Mono.Addins/AddinManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ public static event AddinEventHandler AddinAssembliesLoaded {
remove { AddinEngine.AddinAssembliesLoaded -= value; }
}

internal static bool CheckAssembliesLoaded (HashSet<string> files)
internal static bool CheckAssembliesLoaded (List<string> files)
{
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies ()) {
if (asm is System.Reflection.Emit.AssemblyBuilder)
Expand Down
2 changes: 1 addition & 1 deletion Mono.Addins/Mono.Addins/AddinRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ internal bool CreateHostAddinsFile (string hostFile)
if (!Directory.Exists (database.HostsPath))
Directory.CreateDirectory (database.HostsPath);

foreach (string s in Directory.EnumerateFiles (database.HostsPath, baseName + "*.addins")) {
foreach (string s in Directory.GetFiles (database.HostsPath, baseName + "*.addins")) {
try {
using (StreamReader sr = new StreamReader (s)) {
XmlTextReader tr = new XmlTextReader (sr);
Expand Down
36 changes: 1 addition & 35 deletions Mono.Addins/Mono.Addins/RuntimeAddin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,40 +558,6 @@ public Stream GetResource (string resourceName, bool throwIfNotFound)
return null;
}

/// <summary>
/// Returns information about how the given resource has been persisted
/// </summary>
/// <param name="resourceName">
/// Name of the resource
/// </param>
/// <returns>
/// Resource information, or null if the resource doesn't exist
/// </returns>
public ManifestResourceInfo GetResourceInfo (string resourceName)
{
EnsureAssembliesLoaded ();

// Look in the addin assemblies

foreach (Assembly asm in GetAllAssemblies ()) {
var res = asm.GetManifestResourceInfo (resourceName);
if (res != null) {
// Mono doesn't set the referenced assembly
if (res.ReferencedAssembly == null)
return new ManifestResourceInfo (asm, res.FileName, res.ResourceLocation);
return res;
}
}

// Look in the dependent add-ins
foreach (RuntimeAddin addin in GetAllDependencies ()) {
var res = addin.GetResourceInfo (resourceName);
if (res != null)
return res;
}

return null;
}

/// <summary>
/// Localizer which can be used to localize strings defined in this add-in
Expand Down Expand Up @@ -696,7 +662,7 @@ void LoadModule (ModuleDescription module)
// Sorry, you can't load addins from
// dynamic assemblies as get_Location
// throws a NotSupportedException
if (a is System.Reflection.Emit.AssemblyBuilder || a.IsDynamic) {
if (a is System.Reflection.Emit.AssemblyBuilder || a.ManifestModule is System.Reflection.Emit.ModuleBuilder) {
continue;
}

Expand Down