From 8517887471683adaee4ed0b971f7d887f16aa70b Mon Sep 17 00:00:00 2001 From: "Denis Kuzmin [ github.com/3F ]" Date: Fri, 11 Aug 2017 23:05:51 +0300 Subject: [PATCH] Added support of global namespaces - Issue #47. Use `Direct-Mod` if Cecil will not process this correctly. --- NSBin/Rmod.cs | 4 ++-- Wizard/Project.cs | 8 +++++--- Wizard/UI/ConfiguratorForm.cs | 11 ++++++++--- Wizard/UI/Controls/ProjectItemControl.cs | 12 ++++++++++-- Wizard/UI/Controls/ProjectItemsControl.cs | 6 +++--- Wizard/UserConfig.cs | 5 ++++- tools/net.r_eg.DllExport.targets | 13 ++++++++----- 7 files changed, 40 insertions(+), 19 deletions(-) diff --git a/NSBin/Rmod.cs b/NSBin/Rmod.cs index f025df9..7cef7b2 100644 --- a/NSBin/Rmod.cs +++ b/NSBin/Rmod.cs @@ -70,7 +70,7 @@ public ISender Log public static bool IsValidNS(string name) { if(String.IsNullOrWhiteSpace(name)) { - return false; + return true; } return Regex.IsMatch(name, "^[a-z_][a-z_0-9.]*$", RegexOptions.IgnoreCase) @@ -211,7 +211,7 @@ protected virtual string nsRule(string name) // Regex.Replace(name, @"[\.\s]{1,}", ".").Trim(new char[] { '.', ' ' }); if(IsValidNS(name)) { - return name.Replace(" ", ""); + return name?.Replace(" ", "") ?? String.Empty; } return DEFAULT_NS; } diff --git a/Wizard/Project.cs b/Wizard/Project.cs index 1e558ee..b1051ab 100644 --- a/Wizard/Project.cs +++ b/Wizard/Project.cs @@ -103,7 +103,8 @@ public virtual string MetaLib Path.Combine( Config.Wizard.PkgPath, "gcache", - ProjectGuid, + "metalib", + Config.Namespace, Path.GetFileName(Config.Wizard.MetaLib) ) ); @@ -313,12 +314,12 @@ protected void CfgCompiler() protected void Reset(bool properties) { + RemoveDllExportLib(); + if(properties) { RemoveProperties(ConfigProperties.Keys.ToArray()); ConfigProperties.Clear(); } - - RemoveDllExportLib(); } protected bool CmpPublicKeyTokens(string pkToken, string pkTokenAsm) @@ -346,6 +347,7 @@ protected void AddDllExportLib() var lib = MetaLib; Log.send(this, $"Add meta library: '{lib}'", Message.Level.Info); + //XProject.AddReference("DllExport", lib, false); XProject.AddReference(lib, false); AddRestoreDxp( diff --git a/Wizard/UI/ConfiguratorForm.cs b/Wizard/UI/ConfiguratorForm.cs index 2326d69..78b5057 100644 --- a/Wizard/UI/ConfiguratorForm.cs +++ b/Wizard/UI/ConfiguratorForm.cs @@ -64,8 +64,8 @@ public ConfiguratorForm(IExecutor exec) projectItems.Browse = projectItems.OpenUrl = OpenUrl; - projectItems.NamespaceValidate = (string str) => { - return DDNS.IsValidNS(str); + projectItems.NamespaceValidate = (string ns) => { + return DDNS.IsValidNS(ns?.Trim()); }; RenderSlnFiles(); @@ -191,7 +191,12 @@ private void comboBoxSln_SelectedIndexChanged(object sender, EventArgs e) private void btnApply_Click(object sender, EventArgs e) { - foreach(var prj in projectItems.Data) { + foreach(var prj in projectItems.Data) + { + if(!DDNS.IsValidNS(prj.Config.Namespace)) { + MessageBox.Show($"Fix incorrect namespace before continue:\n\n'{prj.Config.Namespace}'", "Incorrect data", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } prj.Configure(ActionType.Configure); } Close(); diff --git a/Wizard/UI/Controls/ProjectItemControl.cs b/Wizard/UI/Controls/ProjectItemControl.cs index 7f83f00..b154aca 100644 --- a/Wizard/UI/Controls/ProjectItemControl.cs +++ b/Wizard/UI/Controls/ProjectItemControl.cs @@ -24,7 +24,6 @@ using System; using System.ComponentModel; -using System.IO; using System.Windows.Forms; namespace net.r_eg.DllExport.Wizard.UI.Controls @@ -68,7 +67,6 @@ public Action Browse public ComboBox Namespaces { get => comboNS; - set => comboNS = value; } /// @@ -132,6 +130,16 @@ public int Order set; } + public void SetNamespace(string name, bool addIfNotExists = true) + { + name = name?.Trim() ?? String.Empty; + + if(addIfNotExists && !Namespaces.Items.Contains(name)) { + Namespaces.Items.Add(name); + } + Namespaces.Text = name; + } + public ProjectItemControl(IProject project) { this.project = project; diff --git a/Wizard/UI/Controls/ProjectItemsControl.cs b/Wizard/UI/Controls/ProjectItemsControl.cs index e675f90..f09789b 100644 --- a/Wizard/UI/Controls/ProjectItemsControl.cs +++ b/Wizard/UI/Controls/ProjectItemsControl.cs @@ -163,8 +163,8 @@ private void ConfigureControl(ProjectItemControl control, IProject project) control.Namespaces.MaxLength = project.Config.NSBuffer; - if(!String.IsNullOrWhiteSpace(project.Config.Namespace)) { - control.Namespaces.Text = project.Config.Namespace; + if(project.Installed) { + control.SetNamespace(project.Config.Namespace, true); } } @@ -174,7 +174,7 @@ private IProject ConfigureProject(IProject project, ProjectItemControl control) project.Config.UseCecil = control.UseCecil; project.Config.Platform = control.Platform; project.Config.Compiler = control.Compiler; - project.Config.Namespace = control.Namespaces.Text; + project.Config.Namespace = control.Namespaces.Text.Trim(); return project; } diff --git a/Wizard/UserConfig.cs b/Wizard/UserConfig.cs index 4e7a0e5..3bf1516 100644 --- a/Wizard/UserConfig.cs +++ b/Wizard/UserConfig.cs @@ -211,7 +211,10 @@ protected Platform GetPlatform(string value) private string GetValue(string property, IXProject project) { - return project?.GetProperty(property).evaluatedValue; + //TODO: update MvsSln + //NOTE: MS describes this as 'the evaluated property value, which is never null' + // But, this is not true ! >( .NETFramework\v4.0\Microsoft.Build.dll - Version=4.0.0.0, PublicKeyToken=b03f5f7f11d50a3a + return project?.GetProperty(property).evaluatedValue ?? String.Empty; } } } diff --git a/tools/net.r_eg.DllExport.targets b/tools/net.r_eg.DllExport.targets index e96fe02..ed0e706 100644 --- a/tools/net.r_eg.DllExport.targets +++ b/tools/net.r_eg.DllExport.targets @@ -11,17 +11,18 @@ $(DevEnvDir)\..\..\ $(DllExportVSRoot)Common7\IDE\ - gcache\$(ProjectGuid)\ + gcache\metalib\$(DllExportNamespace)\ tools\ - System.Runtime.InteropServices + $(DllExportRootPkg)$(DllExportLibPath) DllExportAttribute DllExport.dll $(DllExportLibFullPath)$(DllExportMetaLibName) - true - true $(DllExportRootPkg)$(DllExportToolsPath)coreclr\ + + $(DllExportNamespace).$(DllExportMetaLibAttr) + $(DllExportMetaLibAttr) @@ -41,6 +42,8 @@ $(TargetFrameworkVersion) $(TargetFrameworkSDKToolsDirectory) $(NoDllExportsForAnyCpu) + true + true 1 false @@ -51,7 +54,7 @@