Commit 5aee9945 authored by 潘栩锋's avatar 潘栩锋 🚴

xmind 转 unity配置文件, 添加 命令行版程序。 可以通过脚本调用

parent 4a487a06
...@@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 ...@@ -3,7 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16 # Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97 VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp1", "WpfApp1\WpfApp1.csproj", "{840673C1-3705-42EC-A3EB-6A7F803590CF}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xmind2UnityConfigUI", "WpfApp1\Xmind2UnityConfigUI.csproj", "{840673C1-3705-42EC-A3EB-6A7F803590CF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xmind2UnityConfigCore", "Xmind2UnityConfigCore\Xmind2UnityConfigCore.csproj", "{DAE8620C-98E8-43B3-BEB1-C0B46959F33B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xmind2UnityConfig", "Xmind2UnityConfig\Xmind2UnityConfig.csproj", "{05099C63-84D2-4AD5-ADAC-E0ED0BCB5DB0}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
...@@ -15,6 +19,14 @@ Global ...@@ -15,6 +19,14 @@ Global
{840673C1-3705-42EC-A3EB-6A7F803590CF}.Debug|Any CPU.Build.0 = Debug|Any CPU {840673C1-3705-42EC-A3EB-6A7F803590CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{840673C1-3705-42EC-A3EB-6A7F803590CF}.Release|Any CPU.ActiveCfg = Release|Any CPU {840673C1-3705-42EC-A3EB-6A7F803590CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{840673C1-3705-42EC-A3EB-6A7F803590CF}.Release|Any CPU.Build.0 = Release|Any CPU {840673C1-3705-42EC-A3EB-6A7F803590CF}.Release|Any CPU.Build.0 = Release|Any CPU
{DAE8620C-98E8-43B3-BEB1-C0B46959F33B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAE8620C-98E8-43B3-BEB1-C0B46959F33B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAE8620C-98E8-43B3-BEB1-C0B46959F33B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAE8620C-98E8-43B3-BEB1-C0B46959F33B}.Release|Any CPU.Build.0 = Release|Any CPU
{05099C63-84D2-4AD5-ADAC-E0ED0BCB5DB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05099C63-84D2-4AD5-ADAC-E0ED0BCB5DB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05099C63-84D2-4AD5-ADAC-E0ED0BCB5DB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05099C63-84D2-4AD5-ADAC-E0ED0BCB5DB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
...@@ -41,302 +41,14 @@ namespace WpfApp1 ...@@ -41,302 +41,14 @@ namespace WpfApp1
if (openFileDialog.ShowDialog()==true) if (openFileDialog.ShowDialog()==true)
{ {
//var zipArchive = ZipFile.o(openFileDialog.FileName); string xmindPath = openFileDialog.FileName;
//zipArchive. string outDirPath = System.IO.Path.GetDirectoryName(xmindPath);
string tempPath = System.IO.Path.Combine( if (Xmind2UnityConfigCore.TopicExt.ToUnity(openFileDialog.FileName, null) == 0) {
System.IO.Path.GetTempPath(), MessageBox.Show($@"完成 输出到{outDirPath}\unity");
System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName));
if (Directory.Exists(tempPath))
{
Directory.Delete(tempPath, true);
}
ZipFile.ExtractToDirectory(openFileDialog.FileName, tempPath);
string filePath = System.IO.Path.Combine(tempPath, "content.json");
string json = File.ReadAllText(filePath);
JArray jArray = JsonConvert.DeserializeObject(json) as JArray;
var jobject_topic = jArray.First() as JObject;
var jobject_rootTopic = jobject_topic["rootTopic"] as JObject;
Topic rootTopic = ToTopic(jobject_rootTopic);
//json = Newtonsoft.Json.JsonConvert.SerializeObject(rootTopic, Formatting.Indented);
//Console.WriteLine(json);
//string path = System.IO.Path.Combine(
// System.IO.Path.GetDirectoryName(openFileDialog.FileName),
// System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName)+".json");
//File.WriteAllText(path, json);
string dirpath = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
ToUnity(rootTopic, dirpath);
MessageBox.Show($@"完成 输出到{dirpath}\unity");
}
}
Topic ToTopic(JObject jObject) {
var topic = new Topic();
string str = jObject["title"].ToString();
string unescape = System.Text.RegularExpressions.Regex.Unescape(str);
topic.title = unescape;
if (jObject.ContainsKey("children"))
{
var children = jObject["children"] as JObject;
if (!children.ContainsKey("attached"))
{
//什么都没有,假的
return topic;
}
var attached = children["attached"] as JArray;
foreach (JObject subTopic in attached)
{
topic.children.Add(ToTopic(subTopic));
}
}
return topic;
}
void ToUnity(Topic rootTopic, string path)
{
path = System.IO.Path.Combine(path, "unity");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
//register \ntype=\"IUnityContainer\"\nname=\"root\"\n(根容器)
//生成relationship.json
RelationShip relationShip = ToRelationShip(rootTopic,path);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(relationShip, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(System.IO.Path.Combine(path, "relationship.json"), json);
}
RelationShip ToRelationShip(Topic topic, string path)
{
RelationShip relationShip = new RelationShip();
var x_root = ToXElement(topic.title);
string name = x_root.Attribute("name").Value;
relationShip.Name = name;
foreach (var subTopic in topic.children)
{
if (subTopic.title.Contains("(config文件)"))
{
//这是config文件
//root.config\n(config文件)
var ss = subTopic.title.Split('\n');
string filename = ss[0].Trim();
relationShip.Path.Add(filename);
string filepath = System.IO.Path.Combine(path, filename);
//创建 xxx.config 文件
ToConfig(subTopic.children, filepath);
}
else //if (unescape.StartsWith("register"))
{
//这是子容器
var subRelationShip = ToRelationShip(subTopic,path);
relationShip.Children.Add(subRelationShip);
}
}
return relationShip;
}
//XElement ToXElement(string title) {
// Regex regex = new Regex(@"(\S+)\s*=\s*""([\s\S]*)""");
// Regex regex_instruction = new Regex(@"\([\s\S]*\)");
// var ss = title.Split('\n');
// var xname = ss.First().Trim();
// XElement x = new XElement(xname);
// for (int i = 1; i < ss.Length; i++) {
// var s = ss[i].Trim();
// var match = regex.Match(s);
// if (match.Success) {
// string attrName = match.Groups[1].Value;
// string attrValue = match.Groups[2].Value;
// x.Add(new XAttribute(attrName, attrValue));
// }
// else if (s.StartsWith("(") && s.EndsWith(")"))
// {
// //这只是说明而已
// }
// }
// return x;
//}
XElement ToXElement(string title)
{
//把全部 中文的 () 替换为 英文的 ()
title = new string(title.Select((c) =>
{
switch (c)
{
case '(':
return '(';
case ')':
return ')';
case '“':
return '"';
case '”':
return '"';
default:
return c;
}
}).ToArray());
//删除全部注解
Regex regex_instruction = new Regex(@"\([\s\S]*\)");
title = regex_instruction.Replace(title, "");
//全部注解删除后,什么也没有
if (string.IsNullOrEmpty(title))
return null;
Regex regex_xml = new Regex(@"\<([\s\S]*)/\>");
var match = regex_xml.Match(title);
if (match.Success)
{
//它就是标准的xml格式
//把头尾的 < /> 删除
title = match.Groups[1].Value;
} }
title = title.Trim();
//什么也没有
if (string.IsNullOrEmpty(title))
return null;
//把全部 中文的 “” 替换为 英文的 "
Regex regex = new Regex(@"(\S+)\s*=\s*""([\s\S]*)""");
var ss = title.Split('\n', ' ');
var xname = ss.First().Trim();
XElement x = new XElement(xname);
for (int i = 1; i < ss.Length; i++)
{
var s = ss[i].Trim();
match = regex.Match(s);
if (match.Success)
{
string attrName = match.Groups[1].Value;
string attrValue = match.Groups[2].Value;
x.Add(new XAttribute(attrName, attrValue));
} }
} }
return x;
} }
XElement ToXElement(Topic topic)
{
XElement x = ToXElement(topic.title);
if (x == null)
return null;
foreach (var sub in topic.children)
{
var x_sub = ToXElement(sub);
if (x_sub == null)
continue;
x.Add(x_sub);
}
return x;
}
void ToConfig(List<Topic> topics, string filepath)
{
XDocument xdoc = new XDocument();
//创建根元素
XElement x_configuration = new XElement("configuration");
//把根元素添加到文件中
xdoc.Add(x_configuration);
XElement x_configSections = new XElement("configSections");
x_configuration.Add(x_configSections);
XElement x_section = new XElement("section");
x_configSections.Add(x_section);
x_section.Add(
new XAttribute("name", "unity"),
new XAttribute("type", "Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Unity.Configuration")
);
//XNamespace ns = "http://schemas.microsoft.com/practices/2010/unity";
XElement x_unity = new XElement("unity");// (ns+"unity");
x_configuration.Add(x_unity);
//找出全部assembly 与 alias
var assemblies_topics = topics.FindAll(t => t.title.Trim().StartsWith("assembly"));
foreach (var assemblies_topic in assemblies_topics)
{
foreach (var assembly_topic in assemblies_topic.children) {
XElement x_assembly = new XElement("assembly");
x_unity.Add(x_assembly);
x_assembly.Add(new XAttribute("name", assembly_topic.title));
foreach (var namespace_topic in assembly_topic.children)
{
XElement x_namespace = new XElement("namespace");
x_unity.Add(x_namespace);
x_namespace.Add(new XAttribute("name", namespace_topic.title));
}
}
}
var aliass_topics = topics.FindAll(t => t.title.Trim().StartsWith("alias"));
foreach (var aliass_topic in aliass_topics)
{
foreach (var alias_topic in aliass_topic.children)
{
XElement x_alias = new XElement("alias");
x_unity.Add(x_alias);
x_alias.Add(new XAttribute("alias", alias_topic.title));
x_alias.Add(new XAttribute("type", alias_topic.children[0].title));
}
}
topics.RemoveAll(t => t.title.Trim().StartsWith("assembly") || t.title.Trim().StartsWith("alias"));
//容器
XElement x_container = new XElement("container");
x_unity.Add(x_container);
foreach (var topic in topics)
{
var x =ToXElement(topic);
if (x == null)
continue;
x_container.Add(x);
}
//保存
xdoc.Save(filepath);
}
}
public class Topic {
public string title;
public List<Topic> children = new List<Topic>();
}
public class RelationShip {
public string Name;
public List<string> Path = new List<string>();
public List<RelationShip> Children = new List<RelationShip>();
}
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Xmind2UnityConfig.Properties { namespace Xmind2UnityConfigUI.Properties {
using System; using System;
...@@ -39,7 +39,7 @@ namespace Xmind2UnityConfig.Properties { ...@@ -39,7 +39,7 @@ namespace Xmind2UnityConfig.Properties {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Xmind2UnityConfig.Properties.Resources", typeof(Resources).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Xmind2UnityConfigUI.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Xmind2UnityConfig.Properties { namespace Xmind2UnityConfigUI.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{840673C1-3705-42EC-A3EB-6A7F803590CF}</ProjectGuid> <ProjectGuid>{840673C1-3705-42EC-A3EB-6A7F803590CF}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>Xmind2UnityConfig</RootNamespace> <RootNamespace>Xmind2UnityConfigUI</RootNamespace>
<AssemblyName>Xmind2UnityConfig</AssemblyName> <AssemblyName>Xmind2UnityConfigUI</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
<PropertyGroup> <PropertyGroup>
<StartupObject /> <StartupObject />
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ApplicationIcon>87ce303ff36c5255ed66d22019585473.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
...@@ -117,5 +120,14 @@ ...@@ -117,5 +120,14 @@
<ItemGroup> <ItemGroup>
<Resource Include="FodyWeavers.xml" /> <Resource Include="FodyWeavers.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="87ce303ff36c5255ed66d22019585473.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xmind2UnityConfigCore\Xmind2UnityConfigCore.csproj">
<Project>{dae8620c-98e8-43b3-beb1-c0b46959f33b}</Project>
<Name>Xmind2UnityConfigCore</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xmind2UnityConfig
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("param err!! format:Xmind2UnityConfig.exe [xmind file] [?:unity.config path]");
return -1;
}
else if (args.Length == 1)
{
return Xmind2UnityConfigCore.TopicExt.ToUnity(args[0], null);
}
else
{
return Xmind2UnityConfigCore.TopicExt.ToUnity(args[0], args[1]);
}
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Xmind2UnityConfig")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Xmind2UnityConfig")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("05099c63-84d2-4ad5-adac-e0ed0bcb5db0")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{05099C63-84D2-4AD5-ADAC-E0ED0BCB5DB0}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Xmind2UnityConfig</RootNamespace>
<AssemblyName>Xmind2UnityConfig</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xmind2UnityConfigCore\Xmind2UnityConfigCore.csproj">
<Project>{dae8620c-98e8-43b3-beb1-c0b46959f33b}</Project>
<Name>Xmind2UnityConfigCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody">
<Version>4.1.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Xmind2UnityConfigCore")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Xmind2UnityConfigCore")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("dae8620c-98e8-43b3-beb1-c0b46959f33b")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xmind2UnityConfigCore
{
public class RelationShip
{
public string Name;
public List<string> Path = new List<string>();
public List<RelationShip> Children = new List<RelationShip>();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Xmind2UnityConfigCore
{
public class Topic
{
public string title;
public List<Topic> children = new List<Topic>();
}
}
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Xmind2UnityConfigCore
{
public static class TopicExt
{
public static int ToUnity(string xmindPath, string outDirPath)
{
if (!File.Exists(xmindPath))
{
Console.WriteLine($"{xmindPath} is not exist!!");
return -1;
}
if(string.IsNullOrEmpty(outDirPath))
outDirPath = System.IO.Path.GetDirectoryName(xmindPath);
//var zipArchive = ZipFile.o(openFileDialog.FileName);
//zipArchive.
//解压缩的临时路径
string tempPath = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
System.IO.Path.GetFileNameWithoutExtension(xmindPath));
if (Directory.Exists(tempPath))
Directory.Delete(tempPath, true);
ZipFile.ExtractToDirectory(xmindPath, tempPath);
string filePath = System.IO.Path.Combine(tempPath, "content.json");
string json = File.ReadAllText(filePath);
JArray jArray = JsonConvert.DeserializeObject(json) as JArray;
var jobject_topic = jArray.First() as JObject;
var jobject_rootTopic = jobject_topic["rootTopic"] as JObject;
Topic rootTopic = ToTopic(jobject_rootTopic);
//json = Newtonsoft.Json.JsonConvert.SerializeObject(rootTopic, Formatting.Indented);
//Console.WriteLine(json);
//string path = System.IO.Path.Combine(
// System.IO.Path.GetDirectoryName(openFileDialog.FileName),
// System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName)+".json");
//File.WriteAllText(path, json);
ToUnity(rootTopic, outDirPath);
Console.WriteLine($@"success!!! out to {System.IO.Path.Combine(outDirPath, "unity")}");
return 0;
}
static Topic ToTopic(JObject jObject)
{
var topic = new Topic();
string str = jObject["title"].ToString();
string unescape = System.Text.RegularExpressions.Regex.Unescape(str);
topic.title = unescape;
if (jObject.ContainsKey("children"))
{
var children = jObject["children"] as JObject;
if (!children.ContainsKey("attached"))
{
//什么都没有,假的
return topic;
}
var attached = children["attached"] as JArray;
foreach (JObject subTopic in attached)
{
topic.children.Add(ToTopic(subTopic));
}
}
return topic;
}
static void ToUnity(Topic rootTopic, string path)
{
path = System.IO.Path.Combine(path, "unity");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
//register \ntype=\"IUnityContainer\"\nname=\"root\"\n(根容器)
//生成relationship.json
RelationShip relationShip = ToRelationShip(rootTopic, path);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(relationShip, Newtonsoft.Json.Formatting.Indented);
File.WriteAllText(System.IO.Path.Combine(path, "relationship.json"), json);
}
static RelationShip ToRelationShip(Topic topic, string path)
{
RelationShip relationShip = new RelationShip();
var x_root = ToXElement(topic.title);
string name = x_root.Attribute("name").Value;
relationShip.Name = name;
foreach (var subTopic in topic.children)
{
if (subTopic.title.Contains("(config文件)"))
{
//这是config文件
//root.config\n(config文件)
var ss = subTopic.title.Split('\n');
string filename = ss[0].Trim();
relationShip.Path.Add(filename);
string filepath = System.IO.Path.Combine(path, filename);
//创建 xxx.config 文件
ToConfig(subTopic.children, filepath);
}
else //if (unescape.StartsWith("register"))
{
//这是子容器
var subRelationShip = ToRelationShip(subTopic, path);
relationShip.Children.Add(subRelationShip);
}
}
return relationShip;
}
static XElement ToXElement(string title)
{
//把全部 中文的 () 替换为 英文的 ()
title = new string(title.Select((c) =>
{
switch (c)
{
case '(':
return '(';
case ')':
return ')';
case '“':
return '"';
case '”':
return '"';
default:
return c;
}
}).ToArray());
//删除全部注解
Regex regex_instruction = new Regex(@"\([\s\S]*\)");
title = regex_instruction.Replace(title, "");
//全部注解删除后,什么也没有
if (string.IsNullOrEmpty(title))
return null;
Regex regex_xml = new Regex(@"\<([\s\S]*)/\>");
var match = regex_xml.Match(title);
if (match.Success)
{
//它就是标准的xml格式
//把头尾的 < /> 删除
title = match.Groups[1].Value;
}
title = title.Trim();
//什么也没有
if (string.IsNullOrEmpty(title))
return null;
//把全部 中文的 “” 替换为 英文的 "
Regex regex = new Regex(@"(\S+)\s*=\s*""([\s\S]*)""");
var ss = title.Split('\n', ' ');
var xname = ss.First().Trim();
XElement x = new XElement(xname);
for (int i = 1; i < ss.Length; i++)
{
var s = ss[i].Trim();
match = regex.Match(s);
if (match.Success)
{
string attrName = match.Groups[1].Value;
string attrValue = match.Groups[2].Value;
x.Add(new XAttribute(attrName, attrValue));
}
}
return x;
}
static XElement ToXElement(Topic topic)
{
XElement x = ToXElement(topic.title);
if (x == null)
return null;
foreach (var sub in topic.children)
{
var x_sub = ToXElement(sub);
if (x_sub == null)
continue;
x.Add(x_sub);
}
return x;
}
static void ToConfig(List<Topic> topics, string filepath)
{
XDocument xdoc = new XDocument();
//创建根元素
XElement x_configuration = new XElement("configuration");
//把根元素添加到文件中
xdoc.Add(x_configuration);
XElement x_configSections = new XElement("configSections");
x_configuration.Add(x_configSections);
XElement x_section = new XElement("section");
x_configSections.Add(x_section);
x_section.Add(
new XAttribute("name", "unity"),
new XAttribute("type", "Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Unity.Configuration")
);
//XNamespace ns = "http://schemas.microsoft.com/practices/2010/unity";
XElement x_unity = new XElement("unity");// (ns+"unity");
x_configuration.Add(x_unity);
//找出全部assembly 与 alias
var assemblies_topics = topics.FindAll(t => t.title.Trim().StartsWith("assembly"));
foreach (var assemblies_topic in assemblies_topics)
{
foreach (var assembly_topic in assemblies_topic.children)
{
XElement x_assembly = new XElement("assembly");
x_unity.Add(x_assembly);
x_assembly.Add(new XAttribute("name", assembly_topic.title));
foreach (var namespace_topic in assembly_topic.children)
{
XElement x_namespace = new XElement("namespace");
x_unity.Add(x_namespace);
x_namespace.Add(new XAttribute("name", namespace_topic.title));
}
}
}
var aliass_topics = topics.FindAll(t => t.title.Trim().StartsWith("alias"));
foreach (var aliass_topic in aliass_topics)
{
foreach (var alias_topic in aliass_topic.children)
{
XElement x_alias = new XElement("alias");
x_unity.Add(x_alias);
x_alias.Add(new XAttribute("alias", alias_topic.title));
x_alias.Add(new XAttribute("type", alias_topic.children[0].title));
}
}
topics.RemoveAll(t => t.title.Trim().StartsWith("assembly") || t.title.Trim().StartsWith("alias"));
//容器
XElement x_container = new XElement("container");
x_unity.Add(x_container);
foreach (var topic in topics)
{
var x = ToXElement(topic);
if (x == null)
continue;
x_container.Add(x);
}
//保存
xdoc.Save(filepath);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DAE8620C-98E8-43B3-BEB1-C0B46959F33B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Xmind2UnityConfigCore</RootNamespace>
<AssemblyName>Xmind2UnityConfigCore</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="RelationShip.cs" />
<Compile Include="Topic.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TopicExt.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment