Skip to content

Commit

Permalink
Added support of global namespaces - Issue #47. Use Direct-Mod if C…
Browse files Browse the repository at this point in the history
…ecil will not process this correctly.
  • Loading branch information
3F committed Aug 11, 2017
1 parent 0e0db7b commit 8517887
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
4 changes: 2 additions & 2 deletions NSBin/Rmod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions Wizard/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public virtual string MetaLib
Path.Combine(
Config.Wizard.PkgPath,
"gcache",
ProjectGuid,
"metalib",
Config.Namespace,
Path.GetFileName(Config.Wizard.MetaLib)
)
);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions Wizard/UI/ConfiguratorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 10 additions & 2 deletions Wizard/UI/Controls/ProjectItemControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

namespace net.r_eg.DllExport.Wizard.UI.Controls
Expand Down Expand Up @@ -68,7 +67,6 @@ public Action<string> Browse
public ComboBox Namespaces
{
get => comboNS;
set => comboNS = value;
}

/// <summary>
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Wizard/UI/Controls/ProjectItemsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion Wizard/UserConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
13 changes: 8 additions & 5 deletions tools/net.r_eg.DllExport.targets
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
<DllExportVSRoot Condition="'$(DllExportVSRoot)' == ''">$(DevEnvDir)\..\..\</DllExportVSRoot>
<DllExportVSBin Condition="'$(DllExportVSBin)' == ''">$(DllExportVSRoot)Common7\IDE\</DllExportVSBin>

<DllExportLibPath Condition="'$(DllExportLibPath)' == ''">gcache\$(ProjectGuid)\</DllExportLibPath>
<DllExportLibPath Condition="'$(DllExportLibPath)' == ''">gcache\metalib\$(DllExportNamespace)\</DllExportLibPath>
<DllExportToolsPath Condition="'$(DllExportToolsPath)' == ''">tools\</DllExportToolsPath>

<DllExportNamespace Condition="'$(DllExportNamespace)' == ''">System.Runtime.InteropServices</DllExportNamespace>
<DllExportNamespace Condition="'$(DllExportNamespace)' == ''"></DllExportNamespace>
<DllExportLibFullPath Condition="'$(DllExportLibFullPath)' == ''">$(DllExportRootPkg)$(DllExportLibPath)</DllExportLibFullPath>
<DllExportMetaLibAttr Condition="'$(DllExportMetaLibAttr)' == ''">DllExportAttribute</DllExportMetaLibAttr>
<DllExportMetaLibName Condition="'$(DllExportMetaLibName)' == ''">DllExport.dll</DllExportMetaLibName>
<DllExportMetaLibFullPath Condition="'$(DllExportMetaLibFullPath)' == ''">$(DllExportLibFullPath)$(DllExportMetaLibName)</DllExportMetaLibFullPath>
<DllExportDDNSCecil Condition="'$(DllExportDDNSCecil)' == ''">true</DllExportDDNSCecil>
<DllExportOurILAsm Condition="'$(DllExportOurILAsm)' == ''">true</DllExportOurILAsm>
<DllExportOurILAsmPath Condition="'$(DllExportOurILAsmPath)' == ''">$(DllExportRootPkg)$(DllExportToolsPath)coreclr\</DllExportOurILAsmPath>

<DllExportAttributeFullName Condition="'$(DllExportNamespace)' != ''">$(DllExportNamespace).$(DllExportMetaLibAttr)</DllExportAttributeFullName>
<DllExportAttributeFullName Condition="'$(DllExportNamespace)' == ''">$(DllExportMetaLibAttr)</DllExportAttributeFullName>
</PropertyGroup>

<Target Name="DllExportMod" BeforeTargets="PostBuildEvent" DependsOnTargets="GetFrameworkPaths">
Expand All @@ -41,6 +42,8 @@
<DllExportTargetFrameworkVersion Condition="'$(DllExportTargetFrameworkVersion)' == ''">$(TargetFrameworkVersion)</DllExportTargetFrameworkVersion>
<DllExportSdkPath Condition="'$(DllExportSdkPath)' == ''">$(TargetFrameworkSDKToolsDirectory)</DllExportSdkPath>
<DllExportSkipOnAnyCpu Condition="'$(DllExportSkipOnAnyCpu)' == ''">$(NoDllExportsForAnyCpu)</DllExportSkipOnAnyCpu>
<DllExportDDNSCecil Condition="'$(DllExportDDNSCecil)' == ''">true</DllExportDDNSCecil>
<DllExportOurILAsm Condition="'$(DllExportOurILAsm)' == ''">true</DllExportOurILAsm>
<DllExportOrdinalsBase Condition="'$(DllExportOrdinalsBase)' == ''">1</DllExportOrdinalsBase>
<DllExportGenExpLib Condition="'$(DllExportGenExpLib)' == ''">false</DllExportGenExpLib>
<DllExportOurILAsmPath Condition="'$(DllExportOurILAsm)' != 'true'"></DllExportOurILAsmPath>
Expand All @@ -51,7 +54,7 @@
<DllExportAppDomainIsolatedTask
Platform="$(DllExportPlatform)"
CpuType="$(DllExportCpuType)"
DllExportAttributeFullName="$(DllExportNamespace).$(DllExportMetaLibAttr)"
DllExportAttributeFullName="$(DllExportAttributeFullName)"
EmitDebugSymbols="$(DllExportEmitDebugSymbols)"
LeaveIntermediateFiles="$(DllExportLeaveIntermediateFiles)"
Timeout="$(DllExportTimeout)"
Expand Down

0 comments on commit 8517887

Please sign in to comment.