饭太稀
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
/// <summary>
|
||||
/// 导出类型枚举,用于标识不同类型的导出操作。
|
||||
/// </summary>
|
||||
public enum ExportType
|
||||
{
|
||||
/// <summary>
|
||||
/// 无导出类型。
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// 所有数据的增量导出Excel类型。
|
||||
/// </summary>
|
||||
AllExcelIncrement = 1,
|
||||
/// <summary>
|
||||
/// 所有数据的全量导出Excel类型。
|
||||
/// </summary>
|
||||
AllExcel = 2,
|
||||
/// <summary>
|
||||
/// 导出类型枚举的最大值,一定要放在最后。
|
||||
/// </summary>
|
||||
Max,
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
// using System;
|
||||
// using System.Text;
|
||||
// using Exporter.Excel;
|
||||
// using Fantasy.Exporter;
|
||||
// using OfficeOpenXml;
|
||||
//
|
||||
// namespace Exporter;
|
||||
//
|
||||
// public class ConstValueToConst : ACustomExport
|
||||
// {
|
||||
// public override void Run()
|
||||
// {
|
||||
// if (!ExcelExporter.LoadIgnoreExcel("#ConstValue", out var excelPackage))
|
||||
// {
|
||||
// Log.Error("ConstValueToConst: Load Excel failed.");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// var worksheet = excelPackage.Workbook.Worksheets[0];
|
||||
//
|
||||
// var serverHotfixStrBuilder = new StringBuilder();
|
||||
// serverHotfixStrBuilder.AppendLine("namespace Fantasy\n{");
|
||||
// serverHotfixStrBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在#ConstValue.xsl里。");
|
||||
// serverHotfixStrBuilder.AppendLine("\tpublic partial class ConstValueHotfix\n\t{");
|
||||
//
|
||||
// var serverModelStrBuilder = new StringBuilder();
|
||||
// serverModelStrBuilder.AppendLine("namespace Fantasy\n{");
|
||||
// serverModelStrBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
|
||||
// serverModelStrBuilder.AppendLine("\tpublic partial class ConstValue\n\t{");
|
||||
//
|
||||
// var clientStrBuilder = new StringBuilder();
|
||||
// clientStrBuilder.AppendLine("namespace Fantasy\n{");
|
||||
// clientStrBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
|
||||
// clientStrBuilder.AppendLine("\tpublic class ConstValue\n\t{");
|
||||
//
|
||||
// for (var row = 2; row <= worksheet.Dimension.Rows; row++)
|
||||
// {
|
||||
// var first = worksheet.GetCellValue(row, 1);
|
||||
// var second = worksheet.GetCellValue(row, 2);
|
||||
// var lower = first?.ToLower() ?? "";
|
||||
// var isClient = lower.Contains("c");
|
||||
// var isServerModel = lower.Contains("sh");
|
||||
// var isServerHotfix = lower.Contains("sm");
|
||||
//
|
||||
// if (string.IsNullOrEmpty(second))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// string str;
|
||||
//
|
||||
// if (second.StartsWith("#"))
|
||||
// {
|
||||
// str = $"\t\t// {second}";
|
||||
// clientStrBuilder.AppendLine(str);
|
||||
// serverModelStrBuilder.AppendLine(str);
|
||||
// serverHotfixStrBuilder.AppendLine(str);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// str = GetCodeStr(worksheet, row);
|
||||
//
|
||||
// if (isServerModel)
|
||||
// {
|
||||
// serverModelStrBuilder.AppendLine(str);
|
||||
// }
|
||||
//
|
||||
// if (isServerHotfix)
|
||||
// {
|
||||
// serverHotfixStrBuilder.AppendLine(str);
|
||||
// }
|
||||
//
|
||||
// if (isClient)
|
||||
// {
|
||||
// clientStrBuilder.AppendLine(str);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// clientStrBuilder.AppendLine("\t}\n}");
|
||||
// serverModelStrBuilder.AppendLine("\t}\n}");
|
||||
// serverHotfixStrBuilder.AppendLine("\t}\n}");
|
||||
//
|
||||
// Write("ConstValue.cs", clientStrBuilder.ToString(), CustomExportType.Client);
|
||||
// Write("ConstValue.cs", serverModelStrBuilder.ToString(), CustomExportType.Server);
|
||||
// Write("ConstValueHotfix.cs", serverHotfixStrBuilder.ToString(),"../../Server/Hotfix/Generate/CustomExport123" ,CustomExportType.Server);
|
||||
// }
|
||||
//
|
||||
// private static string GetCodeStr(ExcelWorksheet sheet, int row)
|
||||
// {
|
||||
// var typeStr = sheet.GetCellValue(row, 3);
|
||||
// var name = sheet.GetCellValue(row, 2);
|
||||
// var value = sheet.GetCellValue(row, 4);
|
||||
// var desc = sheet.GetCellValue(row, 5);
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// if (typeStr.Contains("[]") || typeStr.Contains("[,]"))
|
||||
// {
|
||||
// return $"\t\tpublic static readonly {typeStr} {name} = {DefaultValue(typeStr, value)}; // {desc}";
|
||||
// }
|
||||
//
|
||||
// if (typeStr.Contains("Vector"))
|
||||
// {
|
||||
// return $"\t\tpublic static readonly {typeStr} {name} = {DefaultValue(typeStr, value)}; // {desc}";
|
||||
// }
|
||||
//
|
||||
// return $"\t\tpublic const {typeStr} {name} = {DefaultValue(typeStr, value)}; // {desc}";
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// Log.Error($"{name} 常量导出异常 : {e}");
|
||||
// return "";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static string DefaultValue(string type, string value)
|
||||
// {
|
||||
// switch (type)
|
||||
// {
|
||||
// case "byte[]":
|
||||
// case "int[]":
|
||||
// case "long[]":
|
||||
// case "string[]":
|
||||
// case "double[]":
|
||||
// case "float[]":
|
||||
// return $"new {type} {{{value}}}";
|
||||
// case "byte[,]":
|
||||
// case "int[,]":
|
||||
// case "long[,]":
|
||||
// case "string[,]":
|
||||
// case "float[,]":
|
||||
// case "double[,]":
|
||||
// return $"new {type} {{{value}}}";
|
||||
// case "int":
|
||||
// case "bool":
|
||||
// case "uint":
|
||||
// case "long":
|
||||
// case "double":
|
||||
// return $"{value}";
|
||||
// case "float":
|
||||
// return value[^1] == 'f' ? value : $"{value}f";
|
||||
// case "string":
|
||||
// return $"\"{value}\"";
|
||||
// case "Vector2":
|
||||
// {
|
||||
// var strings = value.Split(',', StringSplitOptions.TrimEntries);
|
||||
// return $"new Vector2({strings[0]},{strings[1]})";
|
||||
// }
|
||||
// case "Vector3":
|
||||
// {
|
||||
// var strings = value.Split(',', StringSplitOptions.TrimEntries);
|
||||
// return $"new Vector3({strings[0]},{strings[1]},{strings[2]})";
|
||||
// }
|
||||
// default:
|
||||
// throw new Exception($"不支持此类型: {type}");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Text;
|
||||
using Fantasy.Tools.ConfigTable;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Exporter;
|
||||
|
||||
/// <summary>
|
||||
/// 将场景类型配置表转换为枚举和字典的自定义导出类。
|
||||
/// </summary>
|
||||
public class SceneTypeConfigToEnum : ACustomExport
|
||||
{
|
||||
public override void Run()
|
||||
{
|
||||
var sceneType = new Dictionary<string, string>();
|
||||
// 获取场景配置表的完整路径
|
||||
if (!Worksheets.TryGetValue("SceneTypeConfig", out var sceneTypeConfig))
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (var row = 3; row <= sceneTypeConfig.Dimension.Rows; row++)
|
||||
{
|
||||
var sceneTypeId = sceneTypeConfig.GetCellValue(row, 1);
|
||||
var sceneTypeStr = sceneTypeConfig.GetCellValue(row, 2);
|
||||
|
||||
if (string.IsNullOrEmpty(sceneTypeId) || string.IsNullOrEmpty(sceneTypeStr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
sceneType.Add(sceneTypeId, sceneTypeStr);
|
||||
}
|
||||
// 如果存在场景类型或场景子类型,执行导出操作
|
||||
if (sceneType.Count > 0)
|
||||
{
|
||||
Write(CustomExportType.Server, sceneType);
|
||||
}
|
||||
}
|
||||
|
||||
private void Write(CustomExportType customExportType, Dictionary<string, string> sceneTypes)
|
||||
{
|
||||
var strBuilder = new StringBuilder();
|
||||
var dicBuilder = new StringBuilder();
|
||||
// 添加命名空间和注释头部
|
||||
strBuilder.AppendLine("namespace Fantasy\n{");
|
||||
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
|
||||
// 生成场景类型的静态类
|
||||
strBuilder.AppendLine("\tpublic static class SceneType\n\t{");
|
||||
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneTypeDic = new Dictionary<string, int>()\n\t\t{");
|
||||
// 遍历场景类型字典,生成场景类型的常量和字典项
|
||||
foreach (var (sceneTypeId, sceneTypeStr) in sceneTypes)
|
||||
{
|
||||
dicBuilder.AppendLine($"\t\t\t{{ \"{sceneTypeStr}\", {sceneTypeId} }},");
|
||||
strBuilder.AppendLine($"\t\tpublic const int {sceneTypeStr} = {sceneTypeId};");
|
||||
}
|
||||
// 添加场景类型字典尾部,合并到主字符串构建器中
|
||||
dicBuilder.AppendLine("\t\t};");
|
||||
strBuilder.Append(dicBuilder);
|
||||
strBuilder.AppendLine("\t}\n}");
|
||||
// 调用外部方法将生成的代码写入文件
|
||||
Write("SceneType.cs", strBuilder.ToString(), customExportType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Fantasy.Serialize;
|
||||
|
||||
#pragma warning disable CS8603 // Possible null reference return.
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public static class ConfigTableHelper
|
||||
{
|
||||
public static T Load<T>() where T : ASerialize
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
using System.Reflection;
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Serialize;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using ProtoBuf;
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
|
||||
namespace Exporter.Excel;
|
||||
|
||||
/// <summary>
|
||||
/// 动态程序集类,用于加载动态生成的程序集并获取动态信息。
|
||||
/// </summary>
|
||||
public static class DynamicAssembly
|
||||
{
|
||||
private static void MetadataReference(out string assemblyName, out List<MetadataReference> metadataReferenceList)
|
||||
{
|
||||
AssemblyMetadata assemblyMetadata;
|
||||
MetadataReference metadataReference;
|
||||
var currentDomain = AppDomain.CurrentDomain;
|
||||
assemblyName = Path.GetRandomFileName();
|
||||
var assemblyArray = currentDomain.GetAssemblies();
|
||||
metadataReferenceList = new List<MetadataReference>();
|
||||
|
||||
// 注册引用
|
||||
|
||||
foreach (var domainAssembly in assemblyArray)
|
||||
{
|
||||
if (string.IsNullOrEmpty(domainAssembly.Location))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assemblyMetadata = AssemblyMetadata.CreateFromFile(domainAssembly.Location);
|
||||
metadataReference = assemblyMetadata.GetReference();
|
||||
metadataReferenceList.Add(metadataReference);
|
||||
}
|
||||
|
||||
// 添加Proto支持
|
||||
|
||||
assemblyMetadata = AssemblyMetadata.CreateFromFile(typeof(ProtoMemberAttribute).Assembly.Location);
|
||||
metadataReference = assemblyMetadata.GetReference();
|
||||
metadataReferenceList.Add(metadataReference);
|
||||
|
||||
// 添加Fantasy支持
|
||||
|
||||
assemblyMetadata = AssemblyMetadata.CreateFromFile(typeof(ASerialize).Assembly.Location);
|
||||
metadataReference = assemblyMetadata.GetReference();
|
||||
metadataReferenceList.Add(metadataReference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载指定路径下的动态程序集。
|
||||
/// </summary>
|
||||
/// <param name="path">程序集文件路径。</param>
|
||||
/// <returns>加载的动态程序集。</returns>
|
||||
public static Assembly Load(string path)
|
||||
{
|
||||
var fileList = new List<string>();
|
||||
|
||||
// 找到所有需要加载的CS文件
|
||||
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
{
|
||||
if (Path.GetExtension(file) != ".cs")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fileList.Add(file);
|
||||
}
|
||||
|
||||
var syntaxTreeList = new List<SyntaxTree>();
|
||||
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
using var fileStream = new StreamReader(file);
|
||||
var cSharp = CSharpSyntaxTree.ParseText(fileStream.ReadToEnd());
|
||||
syntaxTreeList.Add(cSharp);
|
||||
}
|
||||
|
||||
// 注册程序集
|
||||
MetadataReference(out var assemblyName, out var metadataReferenceList);
|
||||
var compilation = CSharpCompilation.Create(assemblyName, syntaxTreeList, metadataReferenceList, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
using var ms = new MemoryStream();
|
||||
var result = compilation.Emit(ms);
|
||||
if (!result.Success)
|
||||
{
|
||||
foreach (var resultDiagnostic in result.Diagnostics)
|
||||
{
|
||||
Log.Error(resultDiagnostic.GetMessage());
|
||||
}
|
||||
|
||||
throw new Exception("failures");
|
||||
}
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Assembly.Load(ms.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取动态程序集中指定表格的动态信息。
|
||||
/// </summary>
|
||||
/// <param name="dynamicAssembly">动态程序集。</param>
|
||||
/// <param name="tableName">表格名称。</param>
|
||||
/// <returns>动态信息对象。</returns>
|
||||
public static DynamicConfigDataType GetDynamicInfo(Assembly dynamicAssembly, string tableName)
|
||||
{
|
||||
var dynamicConfigDataType = new DynamicConfigDataType
|
||||
{
|
||||
ConfigDataType = GetConfigType(dynamicAssembly, $"{tableName}Data"),
|
||||
ConfigType = GetConfigType(dynamicAssembly, $"{tableName}")
|
||||
};
|
||||
|
||||
dynamicConfigDataType.ConfigData = CreateInstance(dynamicConfigDataType.ConfigDataType);
|
||||
|
||||
var listPropertyType = dynamicConfigDataType.ConfigDataType.GetProperty("List");
|
||||
|
||||
if (listPropertyType == null)
|
||||
{
|
||||
throw new Exception("No Property named Add was found");
|
||||
}
|
||||
|
||||
dynamicConfigDataType.Obj = listPropertyType.GetValue(dynamicConfigDataType.ConfigData);
|
||||
dynamicConfigDataType.Method = listPropertyType.PropertyType.GetMethod("Add");
|
||||
|
||||
if (dynamicConfigDataType.Method == null)
|
||||
{
|
||||
throw new Exception("No method named Add was found");
|
||||
}
|
||||
|
||||
return dynamicConfigDataType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据类型名称获取动态类型。
|
||||
/// </summary>
|
||||
/// <param name="dynamicAssembly">动态程序集。</param>
|
||||
/// <param name="typeName">类型名称。</param>
|
||||
/// <returns>动态类型。</returns>
|
||||
private static Type GetConfigType(Assembly dynamicAssembly, string typeName)
|
||||
{
|
||||
var configType = dynamicAssembly.GetType($"Fantasy.{typeName}");
|
||||
|
||||
if (configType == null)
|
||||
{
|
||||
throw new FileNotFoundException($"Fantasy.{typeName} not found");
|
||||
}
|
||||
|
||||
return configType;
|
||||
// return dynamicAssembly.GetType($"Fantasy.{typeName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建动态实例。
|
||||
/// </summary>
|
||||
/// <param name="configType">动态类型。</param>
|
||||
/// <returns>动态实例。</returns>
|
||||
public static object CreateInstance(Type configType)
|
||||
{
|
||||
var config = Activator.CreateInstance(configType);
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
throw new Exception($"{configType.Name} is Activator.CreateInstance error");
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
namespace Exporter.Excel;
|
||||
|
||||
/// <summary>
|
||||
/// 动态配置数据类型类,用于存储动态配置数据的相关信息。
|
||||
/// </summary>
|
||||
public class DynamicConfigDataType
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置数据对象,继承自 AProto 基类。
|
||||
/// </summary>
|
||||
public object ConfigData;
|
||||
/// <summary>
|
||||
/// 配置数据类型。
|
||||
/// </summary>
|
||||
public Type ConfigDataType;
|
||||
/// <summary>
|
||||
/// 配置类型。
|
||||
/// </summary>
|
||||
public Type ConfigType;
|
||||
/// <summary>
|
||||
/// 反射方法信息,用于调用特定方法。
|
||||
/// </summary>
|
||||
public MethodInfo Method;
|
||||
/// <summary>
|
||||
/// 配置数据对象实例。
|
||||
/// </summary>
|
||||
public object Obj;
|
||||
/// <summary>
|
||||
/// 用于生成 JSON 格式数据的字符串构建器。
|
||||
/// </summary>
|
||||
public StringBuilder Json = new StringBuilder();
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Reflection;
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Serialize;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using ProtoBuf;
|
||||
|
||||
namespace Exporter.Excel;
|
||||
|
||||
public class OneDynamicAssembly
|
||||
{
|
||||
private readonly List<SyntaxTree> _syntaxTreeList = new List<SyntaxTree>();
|
||||
|
||||
public void Load(string file)
|
||||
{
|
||||
using var fileStream = new StreamReader(file);
|
||||
var cSharp = CSharpSyntaxTree.ParseText(fileStream.ReadToEnd());
|
||||
_syntaxTreeList.Add(cSharp);
|
||||
}
|
||||
|
||||
public Assembly Assembly
|
||||
{
|
||||
get
|
||||
{
|
||||
AssemblyMetadata assemblyMetadata;
|
||||
MetadataReference metadataReference;
|
||||
var currentDomain = AppDomain.CurrentDomain;
|
||||
var assemblyName = Path.GetRandomFileName();
|
||||
var assemblyArray = currentDomain.GetAssemblies();
|
||||
var metadataReferenceList = new List<MetadataReference>();
|
||||
// 注册引用
|
||||
foreach (var domainAssembly in assemblyArray)
|
||||
{
|
||||
if (string.IsNullOrEmpty(domainAssembly.Location))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assemblyMetadata = AssemblyMetadata.CreateFromFile(domainAssembly.Location);
|
||||
metadataReference = assemblyMetadata.GetReference();
|
||||
metadataReferenceList.Add(metadataReference);
|
||||
}
|
||||
// 添加ProtoEntity支持
|
||||
assemblyMetadata = AssemblyMetadata.CreateFromFile(typeof(ASerialize).Assembly.Location);
|
||||
metadataReference = assemblyMetadata.GetReference();
|
||||
metadataReferenceList.Add(metadataReference);
|
||||
// 添加MessagePack支持
|
||||
assemblyMetadata = AssemblyMetadata.CreateFromFile(typeof(ProtoMemberAttribute).Assembly.Location);
|
||||
metadataReference = assemblyMetadata.GetReference();
|
||||
metadataReferenceList.Add(metadataReference);
|
||||
CSharpCompilation compilation = CSharpCompilation.Create(assemblyName, _syntaxTreeList, metadataReferenceList, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
|
||||
|
||||
using var ms = new MemoryStream();
|
||||
var result = compilation.Emit(ms);
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
foreach (var resultDiagnostic in result.Diagnostics)
|
||||
{
|
||||
Log.Error(resultDiagnostic.GetMessage());
|
||||
}
|
||||
|
||||
throw new Exception("failures");
|
||||
}
|
||||
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Assembly.Load(ms.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
1054
Tools/SourceCode/Fantasy.Tools.ConfigTable/Exporter/ExcelExporter.cs
Normal file
1054
Tools/SourceCode/Fantasy.Tools.ConfigTable/Exporter/ExcelExporter.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
using OfficeOpenXml;
|
||||
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
/// <summary>
|
||||
/// 提供操作 Excel 文件的辅助方法。
|
||||
/// </summary>
|
||||
public static class ExcelHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载 Excel 文件并返回 ExcelPackage 实例。
|
||||
/// </summary>
|
||||
/// <param name="name">Excel 文件的路径。</param>
|
||||
/// <returns>ExcelPackage 实例。</returns>
|
||||
public static ExcelPackage LoadExcel(string name)
|
||||
{
|
||||
return new ExcelPackage(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定工作表中指定行列位置的单元格值。
|
||||
/// </summary>
|
||||
/// <param name="sheet">Excel 工作表。</param>
|
||||
/// <param name="row">行索引。</param>
|
||||
/// <param name="column">列索引。</param>
|
||||
/// <returns>单元格值。</returns>
|
||||
public static string GetCellValue(this ExcelWorksheet sheet, int row, int column)
|
||||
{
|
||||
ExcelRange cell = sheet.Cells[row, column];
|
||||
|
||||
try
|
||||
{
|
||||
if (cell.Value == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string s = cell.GetValue<string>();
|
||||
|
||||
return s.Trim();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Rows {row} Columns {column} Content {cell.Text} {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
/// <summary>
|
||||
/// Excel表格类,用于存储表格的名称和列信息。
|
||||
/// </summary>
|
||||
public sealed class ExcelTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 表格的名称。
|
||||
/// </summary>
|
||||
public readonly string Name;
|
||||
/// <summary>
|
||||
/// 客户端列信息,使用排序字典存储列名和列索引列表。
|
||||
/// </summary>
|
||||
public readonly SortedDictionary<string, List<int>> ClientColInfos = new();
|
||||
/// <summary>
|
||||
/// 服务器端列信息,使用排序字典存储列名和列索引列表。
|
||||
/// </summary>
|
||||
public readonly SortedDictionary<string, List<int>> ServerColInfos = new();
|
||||
/// <summary>
|
||||
/// 构造函数,初始化Excel表格对象并设置表格名称。
|
||||
/// </summary>
|
||||
/// <param name="name">表格名称。</param>
|
||||
public ExcelTable(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
public static class ExcelTemplate
|
||||
{
|
||||
public static readonly string Template = """
|
||||
using System;
|
||||
using ProtoBuf;
|
||||
using Fantasy;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using Fantasy.ConfigTable;
|
||||
using Fantasy.Serialize;
|
||||
// ReSharper disable CollectionNeverUpdated.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
#pragma warning disable CS0169
|
||||
#pragma warning disable CS8618
|
||||
#pragma warning disable CS8625
|
||||
#pragma warning disable CS8603
|
||||
|
||||
namespace (namespace)
|
||||
{
|
||||
[ProtoContract]
|
||||
public sealed partial class (ConfigName)Data : ASerialize, IConfigTable, IProto
|
||||
{
|
||||
[ProtoMember(1)]
|
||||
public List<(ConfigName)> List { get; set; } = new List<(ConfigName)>();
|
||||
#if FANTASY_NET
|
||||
[ProtoIgnore]
|
||||
private readonly ConcurrentDictionary<uint, (ConfigName)> _configs = new ConcurrentDictionary<uint, (ConfigName)>();
|
||||
#else
|
||||
[ProtoIgnore]
|
||||
private readonly Dictionary<uint, (ConfigName)> _configs = new Dictionary<uint, (ConfigName)>();
|
||||
#endif
|
||||
private static (ConfigName)Data _instance = null;
|
||||
|
||||
public static (ConfigName)Data Instance
|
||||
{
|
||||
get { return _instance ??= ConfigTableHelper.Load<(ConfigName)Data>(); }
|
||||
private set => _instance = value;
|
||||
}
|
||||
|
||||
public (ConfigName) Get(uint id, bool check = true)
|
||||
{
|
||||
if (_configs.ContainsKey(id))
|
||||
{
|
||||
return _configs[id];
|
||||
}
|
||||
|
||||
if (check)
|
||||
{
|
||||
throw new Exception($"(ConfigName) not find {id} Id");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public bool TryGet(uint id, out (ConfigName) config)
|
||||
{
|
||||
config = null;
|
||||
|
||||
if (!_configs.ContainsKey(id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
config = _configs[id];
|
||||
return true;
|
||||
}
|
||||
public override void AfterDeserialization()
|
||||
{
|
||||
foreach (var config in List)
|
||||
{
|
||||
#if FANTASY_NET
|
||||
_configs.TryAdd(config.Id, config);
|
||||
#else
|
||||
_configs.Add(config.Id, config);
|
||||
#endif
|
||||
config.AfterDeserialization();
|
||||
}
|
||||
|
||||
EndInit();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
[ProtoContract]
|
||||
public sealed partial class (ConfigName) : ASerialize, IProto
|
||||
{(Fields)
|
||||
}
|
||||
}
|
||||
""";
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Helper;
|
||||
using OfficeOpenXml;
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
public sealed class ExcelWorksheets(ExcelExporter excelExporter)
|
||||
{
|
||||
public bool TryGetValue(string worksheetName, out ExcelWorksheet excelWorksheet)
|
||||
{
|
||||
if (excelExporter.Worksheets.TryGetValue(worksheetName, out excelWorksheet))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var computeHash64 = HashCodeHelper.ComputeHash64(worksheetName);
|
||||
if (!excelExporter.VersionInfo.WorksheetNames.Contains(computeHash64))
|
||||
{
|
||||
Log.Info($"{worksheetName} is not exist!");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
/// <summary>
|
||||
/// 导出信息类,用于存储导出操作的名称和文件信息。
|
||||
/// </summary>
|
||||
public class ExportInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 导出操作的名称。
|
||||
/// </summary>
|
||||
public string Name;
|
||||
/// <summary>
|
||||
/// 导出操作生成的文件信息。
|
||||
/// </summary>
|
||||
public FileInfo FileInfo;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Helper;
|
||||
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义导出接口
|
||||
/// </summary>
|
||||
public interface ICustomExport
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行导出操作
|
||||
/// </summary>
|
||||
void Run();
|
||||
/// <summary>
|
||||
/// 内部操作用于初始化、不明白原理不要修改这里和调用这个方法
|
||||
/// </summary>
|
||||
/// <param name="excelExporter"></param>
|
||||
/// <param name="worksheets"></param>
|
||||
void Init(ExcelExporter excelExporter, ExcelWorksheets worksheets);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抽象自定义导出基类
|
||||
/// </summary>
|
||||
public abstract class ACustomExport : ICustomExport
|
||||
{
|
||||
protected ExcelExporter ExcelExporter;
|
||||
protected ExcelWorksheets Worksheets;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义导出类型枚举:客户端、服务器
|
||||
/// </summary>
|
||||
protected enum CustomExportType
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户端
|
||||
/// </summary>
|
||||
Client,
|
||||
/// <summary>
|
||||
/// 服务器
|
||||
/// </summary>
|
||||
Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部操作用于初始化、不明白原理不要修改这里
|
||||
/// </summary>
|
||||
/// <param name="excelExporter"></param>
|
||||
/// <param name="worksheets"></param>
|
||||
public void Init(ExcelExporter excelExporter, ExcelWorksheets worksheets)
|
||||
{
|
||||
ExcelExporter = excelExporter;
|
||||
Worksheets = worksheets;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行导出操作的抽象方法
|
||||
/// </summary>
|
||||
public abstract void Run();
|
||||
|
||||
/// <summary>
|
||||
/// 写入文件内容到指定位置
|
||||
/// </summary>
|
||||
/// <param name="fileName">文件名</param>
|
||||
/// <param name="fileContent">文件内容</param>
|
||||
/// <param name="filePath">相对的导出的目录</param>
|
||||
/// <param name="customExportType">自定义导出类型</param>
|
||||
protected void Write(string fileName, string fileContent, string filePath, CustomExportType customExportType)
|
||||
{
|
||||
if (filePath == null)
|
||||
{
|
||||
Log.Error($" {nameof(filePath)} is null");
|
||||
return;
|
||||
}
|
||||
|
||||
filePath = FileHelper.GetFullPath(filePath);
|
||||
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
FileHelper.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
var combine = Path.Combine(filePath, fileName);
|
||||
File.WriteAllText(combine, fileContent);
|
||||
|
||||
switch (customExportType)
|
||||
{
|
||||
case CustomExportType.Client:
|
||||
{
|
||||
Log.Info($"导出客户端自定义文件:{filePath}/{fileName}");
|
||||
return;
|
||||
}
|
||||
case CustomExportType.Server:
|
||||
{
|
||||
Log.Info($"导出服务器自定义文件:{filePath}/{fileName}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入文件内容到指定位置
|
||||
/// </summary>
|
||||
/// <param name="fileName">文件名</param>
|
||||
/// <param name="fileContent">文件内容</param>
|
||||
/// <param name="customExportType">自定义导出类型</param>
|
||||
protected void Write(string fileName, string fileContent, CustomExportType customExportType)
|
||||
{
|
||||
switch (customExportType)
|
||||
{
|
||||
case CustomExportType.Client:
|
||||
{
|
||||
if (string.IsNullOrEmpty(ExcelExporter.ClientCustomExportDirectory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(ExcelExporter.ClientCustomExportDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(ExcelExporter.ClientCustomExportDirectory);
|
||||
}
|
||||
|
||||
File.WriteAllText($"{ExcelExporter.ClientCustomExportDirectory}/{fileName}", fileContent);
|
||||
Log.Info($"导出客户端自定义文件:{ExcelExporter.ClientCustomExportDirectory}/{fileName}");
|
||||
return;
|
||||
}
|
||||
case CustomExportType.Server:
|
||||
{
|
||||
if (string.IsNullOrEmpty(ExcelExporter.ServerCustomExportDirectory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(ExcelExporter.ServerCustomExportDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(ExcelExporter.ServerCustomExportDirectory);
|
||||
}
|
||||
|
||||
File.WriteAllText($"{ExcelExporter.ServerCustomExportDirectory}/{fileName}", fileContent);
|
||||
Log.Info($"导出服务器自定义文件:{ExcelExporter.ServerCustomExportDirectory}/{fileName}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
public class VersionInfo
|
||||
{
|
||||
public SortedSet<long> WorksheetNames = [];
|
||||
public SortedDictionary<long, long> Tables = new();
|
||||
}
|
||||
21
Tools/SourceCode/Fantasy.Tools.ConfigTable/ExporterAges.cs
Normal file
21
Tools/SourceCode/Fantasy.Tools.ConfigTable/ExporterAges.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using CommandLine;
|
||||
using Fantasy.Tools.ConfigTable;
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
namespace Fantasy.Tools;
|
||||
|
||||
public class ExporterAges
|
||||
{
|
||||
public static ExporterAges Instance;
|
||||
/// <summary>
|
||||
/// 导出目标平台枚举,用于标识导出到哪个平台
|
||||
/// </summary>
|
||||
[Option('p',"ExportPlatform", Required = false, Default = ExportPlatform.None, HelpText = "Export target platform:\n/// Client target platform \nClient = 1\n/// Server target platform\nServer = 2\n/// Client and Server target platform\nAll = 3")]
|
||||
public ExportPlatform ExportPlatform { get; set; }
|
||||
/// <summary>
|
||||
/// 导出类型
|
||||
/// </summary>
|
||||
[Option('e',"ExportType", Required = false, Default = ExportType.None, HelpText = "Export Type:\n/// Incremental export of all data in Excel format.\nAllExcelIncrement = 1\n/// Export all data to Excel format.\nAllExcel = 2")]
|
||||
public ExportType ExportType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"Export": {
|
||||
"ExcelProgramPath": {
|
||||
"Value": "../../../Examples/Config/Excel/",
|
||||
"Comment": "Excel文件夹的根目录"
|
||||
},
|
||||
"ExcelVersionFile": {
|
||||
"Value": "../../../Examples/Config/Excel/Version.txt",
|
||||
"Comment": "Excel的Version文件位置、这个文件用于记录每次导出对比是否需要再次导出的文件"
|
||||
},
|
||||
"ExcelServerFileDirectory": {
|
||||
"Value": "../../../Examples/Server/Entity/Generate/ConfigTable/Entity/",
|
||||
"Comment": "Excel生成的代码文件、在服务端文件夹位置"
|
||||
},
|
||||
"ExcelClientFileDirectory": {
|
||||
"Value": "../../../Examples/Client/Unity/Assets/Scripts/Hotfix/Generate/ConfigTable/Entity/",
|
||||
"Comment": "Excel生成的代码文件、在客户端文件夹位置"
|
||||
},
|
||||
"ExcelServerBinaryDirectory": {
|
||||
"Value": "../../../Examples/Config/Binary/",
|
||||
"Comment": "Excel生成服务器二进制数据文件夹位置"
|
||||
},
|
||||
"ExcelClientBinaryDirectory": {
|
||||
"Value": "../../../Examples/Client/Unity/Assets/Bundles/Config/",
|
||||
"Comment": "Excel生成在客户端的二进制数据文件夹位置"
|
||||
},
|
||||
"ExcelServerJsonDirectory": {
|
||||
"Value": "../../../Examples/Config/Json/Server/",
|
||||
"Comment": "Excel生成在服务端的Json数据文件夹位置"
|
||||
},
|
||||
"ExcelClientJsonDirectory": {
|
||||
"Value": "../../../Examples/Config/Json/Client/",
|
||||
"Comment": "Excel生成在客户端的Json数据文件夹位置"
|
||||
},
|
||||
"ServerCustomExportDirectory": {
|
||||
"Value": "../../../Examples/Server/Entity/Generate/CustomExport/",
|
||||
"Comment": "Excel在服务端生成自定义代码的文件夹位置"
|
||||
},
|
||||
"ClientCustomExportDirectory": {
|
||||
"Value": "../../../Examples/Client/Unity/Assets/Scripts/Hotfix/Generate/CustomExport",
|
||||
"Comment": "Excel在客户端端生成自定义代码的文件夹位置"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Fantasy.Helper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
|
||||
namespace Fantasy.Tools.ConfigTable;
|
||||
|
||||
public class ExporterSettingsHelper
|
||||
{
|
||||
public static string? ExcelProgramPath { get; private set; }
|
||||
public static string? ExcelVersionFile { get; private set; }
|
||||
public static string? ExcelServerFileDirectory { get; private set; }
|
||||
public static string? ExcelClientFileDirectory { get; private set; }
|
||||
public static string? ExcelServerBinaryDirectory { get; private set; }
|
||||
public static string? ExcelClientBinaryDirectory { get; private set; }
|
||||
public static string? ExcelServerJsonDirectory { get; private set; }
|
||||
public static string? ExcelClientJsonDirectory { get; private set; }
|
||||
public static string? ServerCustomExportDirectory { get; private set; }
|
||||
public static string? ClientCustomExportDirectory { get; private set; }
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
const string settingsName = "ExporterSettings.json";
|
||||
var currentDirectory = Directory.GetCurrentDirectory();
|
||||
|
||||
if (!File.Exists(Path.Combine(currentDirectory, settingsName)))
|
||||
{
|
||||
throw new FileNotFoundException($"not found {settingsName} in OutputDirectory");
|
||||
}
|
||||
|
||||
var root = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(settingsName).Build();
|
||||
|
||||
ExcelProgramPath = FileHelper.GetFullPath(root["Export:ExcelProgramPath:Value"]);
|
||||
ExcelVersionFile = FileHelper.GetFullPath(root["Export:ExcelVersionFile:Value"]);
|
||||
ExcelServerFileDirectory = FileHelper.GetFullPath(root["Export:ExcelServerFileDirectory:Value"]);
|
||||
ExcelClientFileDirectory = FileHelper.GetFullPath(root["Export:ExcelClientFileDirectory:Value"]);
|
||||
ExcelServerBinaryDirectory = FileHelper.GetFullPath(root["Export:ExcelServerBinaryDirectory:Value"]);
|
||||
ExcelClientBinaryDirectory = FileHelper.GetFullPath(root["Export:ExcelClientBinaryDirectory:Value"]);
|
||||
ExcelServerJsonDirectory = FileHelper.GetFullPath(root["Export:ExcelServerJsonDirectory:Value"]);
|
||||
ExcelClientJsonDirectory = FileHelper.GetFullPath(root["Export:ExcelClientJsonDirectory:Value"]);
|
||||
ServerCustomExportDirectory = FileHelper.GetFullPath(root["Export:ServerCustomExportDirectory:Value"]);
|
||||
ClientCustomExportDirectory = FileHelper.GetFullPath(root["Export:ClientCustomExportDirectory:Value"]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>default</LangVersion>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants>TRACE;FANTASY_EXPORTER</DefineConstants>
|
||||
<OutputPath>../../Exporter/ConfigTable/</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants>TRACE;FANTASY_EXPORTER</DefineConstants>
|
||||
<OutputPath>../../Exporter/ConfigTable/</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="EPPlus" Version="8.0.5" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="protobuf-net" Version="3.2.52" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Pool\Normal\Pool.cs">
|
||||
<Link>Core\Base\Pool.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Packages\Fantasy.ConfigTable\Net\Dictionary\IntDictionaryConfig.cs">
|
||||
<Link>Core\Dictionary\IntDictionaryConfig.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Packages\Fantasy.ConfigTable\Net\Dictionary\StringDictionaryConfig.cs">
|
||||
<Link>Core\Dictionary\StringDictionaryConfig.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Packages\Fantasy.ConfigTable\Net\Interface\IConfigTable.cs">
|
||||
<Link>Core\Interface\IConfigTable.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\ProtoBufPackHelper\IProto.cs">
|
||||
<Link>Core\Serialize\ProtoBufPackHelper\IProto.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\TimeHelper.cs">
|
||||
<Link>Excel\Base\TimeHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Pool\Interface\IPool.cs">
|
||||
<Link>Excel\Base\IPool.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Assembly\AssemblyInfo.cs">
|
||||
<Link>Excel\Base\AssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\DataStructure\Collection\OneToManyListPool.cs">
|
||||
<Link>Excel\Base\OneToManyList.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Fantasy.Tools.NetworkProtocol\Core\Base\ConsoleLog.cs">
|
||||
<Link>Core\ConsoleLog.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Fantasy.Tools.NetworkProtocol\Core\Base\ExportPlatform.cs">
|
||||
<Link>Core\ExportPlatform.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\FileHelper.cs">
|
||||
<Link>Core\FileHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\HashCodeHelper.cs">
|
||||
<Link>Core\HashCodeHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\JsonHelper.cs">
|
||||
<Link>Core\JsonHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\BsonPackHelperNet.cs">
|
||||
<Link>Core\Serialize\BsonPack\BsonPackHelperNet.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\StructBsonSerialize.cs">
|
||||
<Link>Core\Serialize\BsonPack\StructBsonSerialize.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\BsonPack\SupportInitializeChecker.cs">
|
||||
<Link>Core\Serialize\BsonPack\SupportInitializeChecker.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\Interface\ASerialize.cs">
|
||||
<Link>Core\Serialize\Interface\ASerialize.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\Interface\ISerialize.cs">
|
||||
<Link>Core\Serialize\Interface\ISerialize.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\SerializerManager.cs">
|
||||
<Link>Core\Serialize\SerializerManager.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\ProtoBufPackHelper\ProtoBufPackHelperNet.cs">
|
||||
<Link>Core\Serialize\ProtoBufPackHelper\ProtoBufPackHelperNet.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Serialize\MemoryStreamBuffer.cs">
|
||||
<Link>Excel\Base\MemoryStreamBuffer.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="ExporterSettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Run.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Run.sh">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
67
Tools/SourceCode/Fantasy.Tools.ConfigTable/Program.cs
Normal file
67
Tools/SourceCode/Fantasy.Tools.ConfigTable/Program.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Text;
|
||||
using CommandLine;
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Tools;
|
||||
using Fantasy.Tools.ConfigTable;
|
||||
|
||||
try
|
||||
{
|
||||
Parser.Default.ParseArguments<ExporterAges>(Environment.GetCommandLineArgs())
|
||||
.WithNotParsed(error => throw new Exception("Command line format error!"))
|
||||
.WithParsed(ages => ExporterAges.Instance = ages);
|
||||
// 初始化配置
|
||||
ExporterSettingsHelper.Initialize();
|
||||
// 加载配置
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
// 判断启动参数,如果没有选择目标平台就让用户选择
|
||||
if (ExporterAges.Instance.ExportPlatform == ExportPlatform.None)
|
||||
{
|
||||
Log.Info("请输入你想要导出的目标平台:");
|
||||
Log.Info("1:Client(客户端)");
|
||||
Log.Info("2:Server(服务器)");
|
||||
Log.Info("3:All(客户端和服务器)");
|
||||
var inputKeyChar = Console.ReadKey().KeyChar;
|
||||
if (!int.TryParse(inputKeyChar.ToString(), out var exportPlatformKey) || exportPlatformKey is < 1 or >= (int)ExportPlatform.All)
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Log.Error("无法识别的导出类型请,输入正确导出的目标平台。");
|
||||
return;
|
||||
}
|
||||
ExporterAges.Instance.ExportPlatform = (ExportPlatform)exportPlatformKey;
|
||||
}
|
||||
|
||||
var selectExportType = ExporterAges.Instance.ExportType;
|
||||
|
||||
if (selectExportType == ExportType.None)
|
||||
{
|
||||
// 检查启动参数
|
||||
Log.Info("请输入你想要做的操作:");
|
||||
Log.Info("1:所有增量导出Excel(包含常量枚举)");
|
||||
Log.Info("2:所有全量导出Excel(包含常量枚举)");
|
||||
// 获取用户输入
|
||||
var keyChar = Console.ReadKey().KeyChar;
|
||||
// 判断用户输入
|
||||
if (!int.TryParse(keyChar.ToString(), out var key) || key is < 1 or >= (int)ExportType.Max)
|
||||
{
|
||||
Console.WriteLine("");
|
||||
Log.Error("无法识别的导出类型请,输入正确的操作类型。");
|
||||
return;
|
||||
}
|
||||
|
||||
selectExportType = (ExportType)key;
|
||||
}
|
||||
Log.Info($"selectExportType:{selectExportType} ExportPlatform:{ExporterAges.Instance.ExportPlatform}");
|
||||
// 转换用户输入
|
||||
Log.Info("");
|
||||
new ExcelExporter(selectExportType).Run();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.Info("按任意键退出程序");
|
||||
Console.ReadKey();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"Fantasy.Tools.ConfigTable": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {},
|
||||
"commandLineArgs": "--ExportPlatform 3"
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Tools/SourceCode/Fantasy.Tools.ConfigTable/Run.bat
Normal file
33
Tools/SourceCode/Fantasy.Tools.ConfigTable/Run.bat
Normal file
@@ -0,0 +1,33 @@
|
||||
@echo off
|
||||
|
||||
echo Please select an option:
|
||||
echo 1. Client Increment
|
||||
echo 2. Client all
|
||||
echo 3. Server Increment
|
||||
echo 4. Server all
|
||||
echo 5. Client and Server Increment
|
||||
echo 6. Client and Server all
|
||||
|
||||
set /p choice=Please select an option:
|
||||
|
||||
if "%choice%"=="1" (
|
||||
echo Client Increment
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 1 --e 1
|
||||
) else if "%choice%"=="2" (
|
||||
echo Client all
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 1 --e 2
|
||||
) else if "%choice%"=="3" (
|
||||
echo Server Increment
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 2 --e 1
|
||||
) else if "%choice%"=="4" (
|
||||
echo Server all
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 2 --e 2
|
||||
) else if "%choice%"=="5" (
|
||||
echo Client and Server Increment
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 3 --e 1
|
||||
) else if "%choice%"=="6" (
|
||||
echo Client and Server all
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 3 --e 2
|
||||
) else (
|
||||
echo Invalid option
|
||||
)
|
||||
34
Tools/SourceCode/Fantasy.Tools.ConfigTable/Run.sh
Normal file
34
Tools/SourceCode/Fantasy.Tools.ConfigTable/Run.sh
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "1. Client Increment"
|
||||
echo "2. Client all"
|
||||
echo "3. Server Increment"
|
||||
echo "4. Server all"
|
||||
echo "5. Client and Server Increment"
|
||||
echo "6. Client and Server all"
|
||||
|
||||
read -n 1 -p "Please select an option:" choice
|
||||
echo ""
|
||||
case $choice in
|
||||
1)
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 1 --e 1
|
||||
;;
|
||||
2)
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 1 --e 2
|
||||
;;
|
||||
3)
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 2 --e 1
|
||||
;;
|
||||
4)
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 2 --e 2
|
||||
;;
|
||||
5)
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 3 --e 1
|
||||
;;
|
||||
6)
|
||||
dotnet Fantasy.Tools.ConfigTable.dll --p 3 --e 2
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,176 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Fantasy.Exporter;
|
||||
|
||||
/// <summary>
|
||||
/// 定义日志记录功能的接口。
|
||||
/// </summary>
|
||||
public interface ILog
|
||||
{
|
||||
/// <summary>
|
||||
/// 记录跟踪级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
void Trace(string message);
|
||||
/// <summary>
|
||||
/// 记录警告级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
void Warning(string message);
|
||||
/// <summary>
|
||||
/// 记录信息级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
void Info(string message);
|
||||
/// <summary>
|
||||
/// 记录调试级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
void Debug(string message);
|
||||
/// <summary>
|
||||
/// 记录错误级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息。</param>
|
||||
void Error(string message);
|
||||
/// <summary>
|
||||
/// 记录跟踪级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
void Trace(string message, params object[] args);
|
||||
/// <summary>
|
||||
/// 记录警告级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
void Warning(string message, params object[] args);
|
||||
/// <summary>
|
||||
/// 记录信息级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
void Info(string message, params object[] args);
|
||||
/// <summary>
|
||||
/// 记录调试级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
void Debug(string message, params object[] args);
|
||||
/// <summary>
|
||||
/// 记录错误级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
void Error(string message, params object[] args);
|
||||
}
|
||||
|
||||
public static class Log
|
||||
{
|
||||
private static readonly ILog LogCore;
|
||||
|
||||
static Log()
|
||||
{
|
||||
LogCore = new ConsoleLog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录信息级别的日志消息。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息。</param>
|
||||
public static void Info(string msg)
|
||||
{
|
||||
LogCore.Info(msg);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录错误级别的日志消息,并附带调用栈信息。
|
||||
/// </summary>
|
||||
/// <param name="msg">日志消息。</param>
|
||||
public static void Error(string msg)
|
||||
{
|
||||
var st = new StackTrace(1, true);
|
||||
LogCore.Error($"{msg}\n{st}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录异常的错误级别的日志消息,并附带调用栈信息。
|
||||
/// </summary>
|
||||
/// <param name="e">异常对象。</param>
|
||||
public static void Error(Exception e)
|
||||
{
|
||||
if (e.Data.Contains("StackTrace"))
|
||||
{
|
||||
LogCore.Error($"{e.Data["StackTrace"]}\n{e}");
|
||||
return;
|
||||
}
|
||||
|
||||
var str = e.ToString();
|
||||
LogCore.Error(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录信息级别的格式化日志消息。
|
||||
/// </summary>
|
||||
/// <param name="message">日志消息模板。</param>
|
||||
/// <param name="args">格式化参数。</param>
|
||||
public static void Info(string message, params object[] args)
|
||||
{
|
||||
LogCore.Info(string.Format(message, args));
|
||||
}
|
||||
}
|
||||
|
||||
public class ConsoleLog : ILog
|
||||
{
|
||||
public void Info(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
{
|
||||
ConsoleColor color = Console.ForegroundColor;
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"{message}\n{new StackTrace(1, true)}");
|
||||
Console.ForegroundColor = color;
|
||||
}
|
||||
|
||||
public void Trace(string message)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Warning(string message)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Debug(string message)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Trace(string message, params object[] args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Warning(string message, params object[] args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Info(string message, params object[] args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Debug(string message, params object[] args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Error(string message, params object[] args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
namespace Fantasy.Tools.ProtocalExporter;
|
||||
|
||||
public sealed class CustomSerialize
|
||||
{
|
||||
public string NameSpace { get; set; }
|
||||
public int KeyIndex { get; set; }
|
||||
public string SerializeName { get; set; }
|
||||
public string Attribute { get; set; }
|
||||
public string Ignore { get; set; }
|
||||
public string Member { get; set; }
|
||||
public uint OpCodeType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Fantasy.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// 导出目标平台枚举,用于标识导出到哪个平台。
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ExportPlatform : byte
|
||||
{
|
||||
None = 0,
|
||||
Client = 1,
|
||||
Server = 1 << 1,
|
||||
All = Client | Server,
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
namespace Fantasy.Tools.ProtocalExporter;
|
||||
|
||||
public static class NetworkProtocolTemplate
|
||||
{
|
||||
public static readonly string Template ="""
|
||||
#if SERVER
|
||||
using ProtoBuf;
|
||||
(UsingNamespace)
|
||||
using System.Collections.Generic;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using Fantasy;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Serialize;
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
// ReSharper disable RedundantOverriddenMember
|
||||
// ReSharper disable PartialTypeWithSinglePart
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable CheckNamespace
|
||||
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
|
||||
#pragma warning disable CS8618
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
#else
|
||||
using ProtoBuf;
|
||||
(UsingNamespace)
|
||||
using System.Collections.Generic;
|
||||
using Fantasy;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Serialize;
|
||||
#pragma warning disable CS8618
|
||||
|
||||
namespace Fantasy
|
||||
{
|
||||
#endif
|
||||
(Content)}
|
||||
""";
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using Fantasy.Helper;
|
||||
|
||||
namespace Fantasy.Tools.ProtocalExporter;
|
||||
|
||||
internal class OpCodeCache
|
||||
{
|
||||
private readonly List<uint> _opCodes = new List<uint>();
|
||||
private readonly Dictionary<string, uint> _opcodeCache;
|
||||
private readonly Dictionary<string, uint> _saveOpCodeCache = new();
|
||||
private readonly string _opcodeCachePath = $"{ExporterSettingsHelper.NetworkProtocolDirectory}OpCode.Cache";
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数,用于初始化网络协议操作码缓存
|
||||
/// </summary>
|
||||
public OpCodeCache(bool regenerate)
|
||||
{
|
||||
if (File.Exists(_opcodeCachePath) && !regenerate)
|
||||
{
|
||||
var readAllText = File.ReadAllText(_opcodeCachePath);
|
||||
_opcodeCache = readAllText.Deserialize<Dictionary<string, uint>>();
|
||||
_opCodes.AddRange(_opcodeCache.Values);
|
||||
}
|
||||
else
|
||||
{
|
||||
_opcodeCache = new Dictionary<string, uint>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存网络协议操作码
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
File.WriteAllText(_opcodeCachePath, _saveOpCodeCache.ToJson());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据className获得OpCode、如果是新增的会产生一个新的OpCode
|
||||
/// </summary>
|
||||
/// <param name="className">协议名</param>
|
||||
/// <param name="opcode">操作码</param>
|
||||
/// <returns></returns>
|
||||
public uint GetOpcodeCache(string className, ref uint opcode)
|
||||
{
|
||||
if (!_opcodeCache.TryGetValue(className, out var opCode))
|
||||
{
|
||||
while (_opCodes.Contains(++opcode))
|
||||
{
|
||||
|
||||
}
|
||||
opCode = opcode;
|
||||
_opCodes.Add(opCode);
|
||||
}
|
||||
|
||||
_saveOpCodeCache.Add(className, opCode);
|
||||
return opCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,891 @@
|
||||
using System.Text;
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Helper;
|
||||
using Fantasy.Network;
|
||||
using OpCode = Fantasy.Network.OpCode;
|
||||
using OpCodeType = Fantasy.Network.OpCodeType;
|
||||
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
// ReSharper disable PossibleNullReferenceException
|
||||
// ReSharper disable ConditionIsAlwaysTrueOrFalse
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
|
||||
namespace Fantasy.Tools.ProtocalExporter;
|
||||
public enum NetworkProtocolOpCodeType
|
||||
{
|
||||
None = 0,
|
||||
Outer = 1,
|
||||
Inner = 2,
|
||||
}
|
||||
public sealed class OpcodeInfo
|
||||
{
|
||||
public uint Code;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public sealed class ProtocolExporter
|
||||
{
|
||||
private string _serverTemplate;
|
||||
private string _clientTemplate;
|
||||
private readonly List<OpcodeInfo> _opcodes = new();
|
||||
private static readonly char[] SplitChars = [' ', '\t'];
|
||||
private readonly string _networkProtocolDirectory;
|
||||
private readonly string _networkProtocolClientDirectory;
|
||||
private readonly string _networkProtocolServerDirectory;
|
||||
private readonly string _networkProtocolDirectoryOuter;
|
||||
private readonly string _networkProtocolDirectoryInner;
|
||||
|
||||
public ProtocolExporter()
|
||||
{
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
if (ExporterSettingsHelper.NetworkProtocolDirectory == null || ExporterSettingsHelper.NetworkProtocolDirectory.Trim() == "")
|
||||
{
|
||||
Log.Info($"NetworkProtocolDirectory Can not be empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
_networkProtocolDirectory = ExporterSettingsHelper.NetworkProtocolDirectory;
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Client))
|
||||
{
|
||||
if (ExporterSettingsHelper.NetworkProtocolClientDirectory?.Trim() == "")
|
||||
{
|
||||
Log.Info($"NetworkProtocolClientDirectory Can not be empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
_networkProtocolClientDirectory = ExporterSettingsHelper.NetworkProtocolClientDirectory ?? string.Empty;
|
||||
if (!Directory.Exists(_networkProtocolClientDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(_networkProtocolClientDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Server))
|
||||
{
|
||||
if (ExporterSettingsHelper.NetworkProtocolServerDirectory?.Trim() == "")
|
||||
{
|
||||
Log.Info($"NetworkProtocolServerDirectory Can not be empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
_networkProtocolServerDirectory = ExporterSettingsHelper.NetworkProtocolServerDirectory ?? string.Empty;
|
||||
if (!Directory.Exists(_networkProtocolServerDirectory))
|
||||
{
|
||||
Directory.CreateDirectory(_networkProtocolServerDirectory);
|
||||
}
|
||||
|
||||
_networkProtocolDirectoryInner = $"{_networkProtocolDirectory}Inner";
|
||||
|
||||
if (!Directory.Exists(_networkProtocolDirectoryInner))
|
||||
{
|
||||
Directory.CreateDirectory(_networkProtocolDirectoryInner);
|
||||
}
|
||||
}
|
||||
|
||||
_networkProtocolDirectoryOuter = $"{_networkProtocolDirectory}Outer";
|
||||
|
||||
if (!Directory.Exists(_networkProtocolDirectoryOuter))
|
||||
{
|
||||
Directory.CreateDirectory(_networkProtocolDirectoryOuter);
|
||||
}
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
var tasks = new Task[3];
|
||||
tasks[0] = Task.Run(RouteType);
|
||||
tasks[1] = Task.Run(RoamingType);
|
||||
tasks[2] = Task.Run(async () =>
|
||||
{
|
||||
LoadTemplate();
|
||||
await Start(NetworkProtocolOpCodeType.Outer);
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Server))
|
||||
{
|
||||
await Start(NetworkProtocolOpCodeType.Inner);
|
||||
}
|
||||
});
|
||||
Task.WaitAll(tasks);
|
||||
}
|
||||
|
||||
private async Task Start(NetworkProtocolOpCodeType opCodeType)
|
||||
{
|
||||
var className = "";
|
||||
var opCodeName = "";
|
||||
var file = new StringBuilder();
|
||||
var messageStr = new StringBuilder();
|
||||
var disposeStr = new StringBuilder();
|
||||
var errorCodeStr = new StringBuilder();
|
||||
var usingNamespace = new HashSet<string>();
|
||||
var saveDirectory = new Dictionary<string, string>();
|
||||
|
||||
OpcodeInfo opcodeInfo = null;
|
||||
ProtocolOpCode protocolOpCode = null;
|
||||
string[] protocolFiles = null;
|
||||
_opcodes.Clear();
|
||||
|
||||
switch (opCodeType)
|
||||
{
|
||||
case NetworkProtocolOpCodeType.Outer:
|
||||
{
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Server))
|
||||
{
|
||||
saveDirectory.Add(_networkProtocolServerDirectory, _serverTemplate);
|
||||
}
|
||||
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Client))
|
||||
{
|
||||
saveDirectory.Add(_networkProtocolClientDirectory, _clientTemplate);
|
||||
}
|
||||
|
||||
protocolOpCode = new ProtocolOpCode()
|
||||
{
|
||||
Message = OpCodeType.OuterMessage,
|
||||
Request = OpCodeType.OuterRequest,
|
||||
Response = OpCodeType.OuterResponse,
|
||||
RouteMessage = 0,
|
||||
RouteRequest = 0,
|
||||
RouteResponse = 0,
|
||||
AddressableMessage = OpCodeType.OuterAddressableMessage,
|
||||
AddressableRequest = OpCodeType.OuterAddressableRequest,
|
||||
AddressableResponse = OpCodeType.OuterAddressableResponse,
|
||||
CustomRouteMessage = OpCodeType.OuterCustomRouteMessage,
|
||||
CustomRouteRequest = OpCodeType.OuterCustomRouteRequest,
|
||||
CustomRouteResponse = OpCodeType.OuterCustomRouteResponse,
|
||||
RoamingMessage = OpCodeType.OuterRoamingMessage,
|
||||
RoamingRequest = OpCodeType.OuterRoamingRequest,
|
||||
RoamingResponse = OpCodeType.OuterRoamingResponse,
|
||||
};
|
||||
opCodeName = "OuterOpcode";
|
||||
protocolFiles = FileHelper.GetDirectoryFile(_networkProtocolDirectoryOuter, "*.proto", SearchOption.AllDirectories);
|
||||
break;
|
||||
}
|
||||
case NetworkProtocolOpCodeType.Inner:
|
||||
{
|
||||
protocolOpCode = new ProtocolOpCode()
|
||||
{
|
||||
Message = OpCodeType.InnerMessage,
|
||||
Request = OpCodeType.InnerRequest,
|
||||
Response = OpCodeType.InnerResponse,
|
||||
RouteMessage = OpCodeType.InnerRouteMessage,
|
||||
RouteRequest = OpCodeType.InnerRouteRequest,
|
||||
RouteResponse = OpCodeType.InnerRouteResponse,
|
||||
AddressableMessage = OpCodeType.InnerAddressableMessage,
|
||||
AddressableRequest = OpCodeType.InnerAddressableRequest,
|
||||
AddressableResponse = OpCodeType.InnerAddressableResponse,
|
||||
CustomRouteMessage = 0,
|
||||
CustomRouteRequest = 0,
|
||||
CustomRouteResponse = 0,
|
||||
RoamingMessage = OpCodeType.InnerRoamingMessage,
|
||||
RoamingRequest = OpCodeType.InnerRoamingRequest,
|
||||
RoamingResponse = OpCodeType.InnerRoamingResponse,
|
||||
};
|
||||
opCodeName = "InnerOpcode";
|
||||
saveDirectory.Add(_networkProtocolServerDirectory, _serverTemplate);
|
||||
protocolFiles = FileHelper.GetDirectoryFile(_networkProtocolDirectoryInner, "*.proto", SearchOption.AllDirectories);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (protocolFiles == null || protocolFiles.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#region GenerateFiles
|
||||
|
||||
foreach (var filePath in protocolFiles)
|
||||
{
|
||||
var keyIndex = 1;
|
||||
var parameter = "";
|
||||
var hasOpCode = false;
|
||||
var isMsgHead = false;
|
||||
var isSetProtocol = false;
|
||||
string responseTypeStr = null;
|
||||
string customRouteType = null;
|
||||
string protocolMember = "ProtoMember";
|
||||
string protocolType = "\t[ProtoContract]";
|
||||
string protocolIgnore = "\t\t[ProtoIgnore]";
|
||||
var protocolOpCodeType = OpCodeProtocolType.ProtoBuf;
|
||||
var fileText = await File.ReadAllTextAsync(filePath);
|
||||
|
||||
foreach (var line in fileText.Split('\n'))
|
||||
{
|
||||
var currentLine = line.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(currentLine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentLine.StartsWith("///"))
|
||||
{
|
||||
messageStr.AppendFormat(" /// <summary>\r\n" + " /// {0}\r\n" + " /// </summary>\r\n", currentLine.Substring("///".Length));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentLine.StartsWith("// Protocol"))
|
||||
{
|
||||
isSetProtocol = true;
|
||||
var protocol = currentLine.Substring("// Protocol".Length).Trim();
|
||||
|
||||
switch (protocol)
|
||||
{
|
||||
case "ProtoBuf":
|
||||
{
|
||||
protocolType = "\t[ProtoContract]";
|
||||
protocolIgnore = "\t\t[ProtoIgnore]";
|
||||
protocolMember = "ProtoMember";
|
||||
protocolOpCodeType = OpCodeProtocolType.ProtoBuf;
|
||||
break;
|
||||
}
|
||||
// case "MemoryPack":
|
||||
// {
|
||||
// keyIndex = 0;
|
||||
// protocolType = "\t[MemoryPackable]";
|
||||
// protocolIgnore = "\t\t[MemoryPackIgnore]";
|
||||
// protocolMember = "MemoryPackOrder";
|
||||
// // protocolOpCodeType = OpCodeProtocolType.MemoryPack;
|
||||
// break;
|
||||
// }
|
||||
case "Bson":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Outer)
|
||||
{
|
||||
Log.Error("Under Outer, /// does not support the Bson protocol!");
|
||||
return;
|
||||
}
|
||||
protocolType = null;
|
||||
protocolIgnore = "\t\t[BsonIgnore]";
|
||||
protocolMember = null;
|
||||
protocolOpCodeType = OpCodeProtocolType.Bson;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (!ExporterSettingsHelper.CustomSerializes.TryGetValue(protocol, out var customSerialize))
|
||||
{
|
||||
Log.Error($"// Protocol {protocol} is not supported!");
|
||||
return;
|
||||
}
|
||||
|
||||
usingNamespace.Add(customSerialize.NameSpace);
|
||||
keyIndex = customSerialize.KeyIndex;
|
||||
protocolType = customSerialize.Attribute;
|
||||
protocolIgnore = customSerialize.Ignore;
|
||||
protocolMember = customSerialize.Member;
|
||||
protocolOpCodeType = customSerialize.OpCodeType;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.StartsWith("message"))
|
||||
{
|
||||
isMsgHead = true;
|
||||
className = currentLine.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries)[1];
|
||||
var splits = currentLine.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (isSetProtocol)
|
||||
{
|
||||
if (protocolType != null)
|
||||
{
|
||||
messageStr.AppendLine(protocolType);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
messageStr.AppendLine("\t[ProtoContract]");
|
||||
}
|
||||
|
||||
if (splits.Length > 1)
|
||||
{
|
||||
hasOpCode = true;
|
||||
var parameterArray = currentLine.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim().Split(',');
|
||||
parameter = parameterArray[0].Trim();
|
||||
opcodeInfo = new OpcodeInfo()
|
||||
{
|
||||
Name = className
|
||||
};
|
||||
switch (parameterArray.Length)
|
||||
{
|
||||
case 2:
|
||||
{
|
||||
switch (parameter)
|
||||
{
|
||||
case "ICustomRouteMessage":
|
||||
{
|
||||
customRouteType = $"Fantasy.RouteType.{parameterArray[1].Trim()}";
|
||||
break;
|
||||
}
|
||||
case "IRoamingMessage":
|
||||
{
|
||||
customRouteType = $"Fantasy.RoamingType.{parameterArray[1].Trim()}";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
responseTypeStr = parameterArray[1].Trim();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
responseTypeStr = parameterArray[1].Trim();
|
||||
customRouteType = parameter.Contains("IRoaming") ? $"Fantasy.RoamingType.{parameterArray[2].Trim()}" : $"Fantasy.RouteType.{parameterArray[2].Trim()}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
parameter = "";
|
||||
hasOpCode = false;
|
||||
}
|
||||
|
||||
messageStr.Append(string.IsNullOrWhiteSpace(parameter)
|
||||
? $"\tpublic partial class {className} : AMessage"
|
||||
: $"\tpublic partial class {className} : AMessage, {parameter}");
|
||||
if (protocolMember == "ProtoMember")
|
||||
{
|
||||
messageStr.Append(", IProto");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isMsgHead)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (currentLine)
|
||||
{
|
||||
case "{":
|
||||
{
|
||||
messageStr.AppendLine("\n\t{");
|
||||
messageStr.AppendLine($"\t\tpublic static {className} Create(Scene scene)");
|
||||
messageStr.AppendLine($"\t\t{{\n\t\t\treturn scene.MessagePoolComponent.Rent<{className}>();\n\t\t}}");
|
||||
messageStr.AppendLine($"\t\tpublic override void Dispose()");
|
||||
messageStr.AppendLine($"\t\t{{");
|
||||
messageStr.AppendLine($"<<<<Dispose>>>#if FANTASY_NET || FANTASY_UNITY\n\t\t\tGetScene().MessagePoolComponent.Return<{className}>(this);\n#endif");
|
||||
messageStr.AppendLine($"\t\t}}");
|
||||
|
||||
if (parameter == "IMessage")
|
||||
{
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Message, protocolOpCode.AMessage++);
|
||||
messageStr.AppendLine($"\t\tpublic uint OpCode() {{ return {opCodeName}.{className}; }}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (responseTypeStr != null)
|
||||
{
|
||||
messageStr.AppendLine(protocolIgnore);
|
||||
messageStr.AppendLine($"\t\tpublic {responseTypeStr} ResponseType {{ get; set; }}");
|
||||
responseTypeStr = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parameter.Contains("RouteRequest"))
|
||||
{
|
||||
Log.Error($"{opcodeInfo.Name} 没指定ResponseType");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOpCode)
|
||||
{
|
||||
messageStr.AppendLine($"\t\tpublic uint OpCode() {{ return {opCodeName}.{className}; }}");
|
||||
}
|
||||
|
||||
if (customRouteType != null)
|
||||
{
|
||||
messageStr.AppendLine(protocolIgnore);
|
||||
messageStr.AppendLine($"\t\tpublic int RouteType => {customRouteType};");
|
||||
customRouteType = null;
|
||||
}
|
||||
|
||||
switch (parameter)
|
||||
{
|
||||
case "IRequest":
|
||||
{
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Request, protocolOpCode.ARequest++);
|
||||
break;
|
||||
}
|
||||
case "IResponse":
|
||||
{
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.Response, protocolOpCode.AResponse++);
|
||||
if (!string.IsNullOrEmpty(protocolMember))
|
||||
{
|
||||
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
|
||||
}
|
||||
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
|
||||
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
switch (parameter)
|
||||
{
|
||||
case "IAddressableRouteMessage":
|
||||
{
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.AddressableMessage, protocolOpCode.AAddressableMessage++);
|
||||
break;
|
||||
}
|
||||
case "IAddressableRouteRequest":
|
||||
{
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.AddressableRequest, protocolOpCode.AAddressableRequest++);
|
||||
break;
|
||||
}
|
||||
case "IAddressableRouteResponse":
|
||||
{
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.AddressableResponse, protocolOpCode.AAddressableResponse++);
|
||||
if (!string.IsNullOrEmpty(protocolMember))
|
||||
{
|
||||
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
|
||||
}
|
||||
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
|
||||
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
|
||||
break;
|
||||
}
|
||||
case "ICustomRouteMessage":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Inner)
|
||||
{
|
||||
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
|
||||
}
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.CustomRouteMessage, protocolOpCode.ACustomRouteMessage++);
|
||||
break;
|
||||
}
|
||||
case "ICustomRouteRequest":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Inner)
|
||||
{
|
||||
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
|
||||
}
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.CustomRouteRequest, protocolOpCode.ACustomRouteRequest++);
|
||||
break;
|
||||
}
|
||||
case "ICustomRouteResponse":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Inner)
|
||||
{
|
||||
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
|
||||
}
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.CustomRouteResponse, protocolOpCode.ACustomRouteResponse++);
|
||||
if (!string.IsNullOrEmpty(protocolMember))
|
||||
{
|
||||
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
|
||||
}
|
||||
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
|
||||
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
|
||||
break;
|
||||
}
|
||||
case "IRoamingMessage":
|
||||
{
|
||||
// if (opCodeType == NetworkProtocolOpCodeType.Inner)
|
||||
// {
|
||||
// throw new NotSupportedException("Under Inner, /// does not support the IRoamingMessage!");
|
||||
// }
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RoamingMessage, protocolOpCode.ARoamingMessage++);
|
||||
break;
|
||||
}
|
||||
case "IRoamingRequest":
|
||||
{
|
||||
// if (opCodeType == NetworkProtocolOpCodeType.Inner)
|
||||
// {
|
||||
// throw new NotSupportedException("Under Inner, /// does not support the IRoamingRequest!");
|
||||
// }
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RoamingRequest, protocolOpCode.ARoamingRequest++);
|
||||
break;
|
||||
}
|
||||
case "IRoamingResponse":
|
||||
{
|
||||
// if (opCodeType == NetworkProtocolOpCodeType.Inner)
|
||||
// {
|
||||
// throw new NotSupportedException("Under Inner, /// does not support the IRoamingResponse!");
|
||||
// }
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RoamingResponse, protocolOpCode.ARoamingResponse++);
|
||||
if (!string.IsNullOrEmpty(protocolMember))
|
||||
{
|
||||
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
|
||||
}
|
||||
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
|
||||
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
|
||||
break;
|
||||
}
|
||||
case "IRouteMessage":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Outer)
|
||||
{
|
||||
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
|
||||
}
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RouteMessage, protocolOpCode.ARouteMessage++);
|
||||
break;
|
||||
}
|
||||
case "IRouteRequest":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Outer)
|
||||
{
|
||||
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
|
||||
}
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RouteRequest, protocolOpCode.ARouteRequest++);
|
||||
break;
|
||||
}
|
||||
case "IRouteResponse":
|
||||
{
|
||||
if (opCodeType == NetworkProtocolOpCodeType.Outer)
|
||||
{
|
||||
throw new NotSupportedException("Under Inner, /// does not support the ICustomRouteMessage!");
|
||||
}
|
||||
opcodeInfo.Code = OpCode.Create(protocolOpCodeType, protocolOpCode.RouteResponse, protocolOpCode.ARouteResponse++);
|
||||
if (!string.IsNullOrEmpty(protocolMember))
|
||||
{
|
||||
errorCodeStr.AppendLine($"\t\t[{protocolMember}(ErrorCodeKeyIndex)]");
|
||||
}
|
||||
errorCodeStr.AppendLine("\t\tpublic uint ErrorCode { get; set; }");
|
||||
disposeStr.AppendLine($"\t\t\tErrorCode = default;");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasOpCode)
|
||||
{
|
||||
_opcodes.Add(opcodeInfo);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
case "}":
|
||||
{
|
||||
isMsgHead = false;
|
||||
errorCodeStr = errorCodeStr.Replace("ErrorCodeKeyIndex", keyIndex.ToString());
|
||||
messageStr = messageStr.Replace("<<<<Dispose>>>", disposeStr.ToString());
|
||||
messageStr.Append(errorCodeStr);
|
||||
messageStr.AppendLine("\t}");
|
||||
file.Append(messageStr);
|
||||
messageStr.Clear();
|
||||
disposeStr.Clear();
|
||||
errorCodeStr.Clear();
|
||||
keyIndex = 1;
|
||||
protocolType = "\t[ProtoContract]";
|
||||
protocolIgnore = "\t\t[ProtoIgnore]";
|
||||
protocolMember = "ProtoMember";
|
||||
protocolOpCodeType = OpCodeProtocolType.ProtoBuf;
|
||||
continue;
|
||||
}
|
||||
case "":
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentLine.StartsWith("//"))
|
||||
{
|
||||
messageStr.AppendFormat("\t\t///<summary>\r\n" + "\t\t/// {0}\r\n" + "\t\t///</summary>\r\n", currentLine.TrimStart('/', '/'));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (currentLine.StartsWith("repeated"))
|
||||
{
|
||||
Repeated(messageStr, disposeStr, currentLine, protocolMember, ref keyIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
Members(messageStr, disposeStr, currentLine, protocolMember, ref keyIndex);
|
||||
}
|
||||
}
|
||||
|
||||
var namespaceBuilder = new StringBuilder();
|
||||
|
||||
foreach (var @namespace in usingNamespace)
|
||||
{
|
||||
namespaceBuilder.Append($"using {@namespace};\n");
|
||||
}
|
||||
|
||||
var csName = $"{Path.GetFileNameWithoutExtension(filePath)}.cs";
|
||||
foreach (var (directory, template) in saveDirectory)
|
||||
{
|
||||
var csFile = Path.Combine(directory, csName);
|
||||
var content = template.Replace("(Content)", file.ToString());
|
||||
content = content.Replace("(UsingNamespace)", namespaceBuilder.ToString());
|
||||
await File.WriteAllTextAsync(csFile, content);
|
||||
}
|
||||
file.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GenerateOpCode
|
||||
|
||||
file.Clear();
|
||||
file.AppendLine("namespace Fantasy");
|
||||
file.AppendLine("{");
|
||||
file.AppendLine($"\tpublic static partial class {opCodeName}");
|
||||
file.AppendLine("\t{");
|
||||
|
||||
foreach (var opcode in _opcodes)
|
||||
{
|
||||
file.AppendLine($"\t\t public const uint {opcode.Name} = {opcode.Code};");
|
||||
}
|
||||
|
||||
_opcodes.Clear();
|
||||
file.AppendLine("\t}");
|
||||
file.AppendLine("}");
|
||||
|
||||
foreach (var (directory, _) in saveDirectory)
|
||||
{
|
||||
var csFile = Path.Combine(directory, $"{opCodeName}.cs");
|
||||
await File.WriteAllTextAsync(csFile, file.ToString());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
private void Repeated(StringBuilder file, StringBuilder disposeStr, string newline, string protocolMember, ref int keyIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
var index = newline.IndexOf(";", StringComparison.Ordinal);
|
||||
newline = newline.Remove(index);
|
||||
var property = newline.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
|
||||
var type = property[1];
|
||||
var name = property[2];
|
||||
// var memberIndex = int.Parse(property[4]);
|
||||
type = ConvertType(type);
|
||||
|
||||
file.AppendLine($"\t\t[{protocolMember}({keyIndex++})]");
|
||||
file.AppendLine($"\t\tpublic List<{type}> {name} = new List<{type}>();");
|
||||
disposeStr.AppendLine($"\t\t\t{name}.Clear();");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"{newline}\n {e}");
|
||||
}
|
||||
}
|
||||
|
||||
private void Members(StringBuilder file, StringBuilder disposeStr, string currentLine, string protocolMember, ref int keyIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
var index = currentLine.IndexOf(";", StringComparison.Ordinal);
|
||||
currentLine = currentLine.Remove(index);
|
||||
var property = currentLine.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
|
||||
var type = property[0];
|
||||
var name = property[1];
|
||||
// var memberIndex = int.Parse(property[3]);
|
||||
var typeCs = ConvertType(type);
|
||||
if (protocolMember != null)
|
||||
{
|
||||
file.AppendLine($"\t\t[{protocolMember}({keyIndex++})]");
|
||||
}
|
||||
file.AppendLine($"\t\tpublic {typeCs} {name} {{ get; set; }}");
|
||||
disposeStr.AppendLine($"\t\t\t{name} = default;");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"{currentLine}\n {e}");
|
||||
}
|
||||
}
|
||||
|
||||
private string ConvertType(string type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
"int[]" => "int[] { }",
|
||||
"int32[]" => "int[] { }",
|
||||
"int64[]" => "long[] { }",
|
||||
"int32" => "int",
|
||||
"uint32" => "uint",
|
||||
"int64" => "long",
|
||||
"uint64" => "ulong",
|
||||
_ => type
|
||||
};
|
||||
}
|
||||
|
||||
private async Task RoamingType()
|
||||
{
|
||||
var routeTypeFile = $"{_networkProtocolDirectory}RoamingType.Config";
|
||||
var protoFileText = "";
|
||||
if (!File.Exists(routeTypeFile))
|
||||
{
|
||||
protoFileText = "// Roaming协议定义(需要定义10000以上、因为10000以内的框架预留)\n";
|
||||
await File.WriteAllTextAsync(routeTypeFile, protoFileText);
|
||||
}
|
||||
else
|
||||
{
|
||||
protoFileText = await File.ReadAllTextAsync(routeTypeFile);
|
||||
}
|
||||
|
||||
var roamingTypes = new HashSet<int>();
|
||||
var roamingTypeFileSb = new StringBuilder();
|
||||
roamingTypeFileSb.AppendLine("using System.Collections.Generic;");
|
||||
roamingTypeFileSb.AppendLine("namespace Fantasy\n{");
|
||||
roamingTypeFileSb.AppendLine("\t// Roaming协议定义(需要定义10000以上、因为10000以内的框架预留)\t");
|
||||
roamingTypeFileSb.AppendLine("\tpublic static class RoamingType\n\t{");
|
||||
|
||||
foreach (var line in protoFileText.Split('\n'))
|
||||
{
|
||||
var currentLine = line.Trim();
|
||||
|
||||
if (currentLine == "" || currentLine.StartsWith("//"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var splits = currentLine.Split(["//"], StringSplitOptions.RemoveEmptyEntries);
|
||||
var routeTypeStr = splits[0].Split("=", StringSplitOptions.RemoveEmptyEntries);
|
||||
var roamingType = routeTypeStr[1].Trim();
|
||||
roamingTypes.Add(int.Parse(roamingType));
|
||||
roamingTypeFileSb.Append($"\t\tpublic const int {routeTypeStr[0].Trim()} = {roamingType};");
|
||||
|
||||
if (splits.Length > 1)
|
||||
{
|
||||
roamingTypeFileSb.Append($" // {splits[1].Trim()}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
roamingTypeFileSb.Append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
if (roamingTypes.Count > 0)
|
||||
{
|
||||
roamingTypeFileSb.AppendLine("\t\tpublic static IEnumerable<int> RoamingTypes");
|
||||
roamingTypeFileSb.AppendLine("\t\t{\n\t\t\tget\n\t\t\t{");
|
||||
foreach (var roamingType in roamingTypes)
|
||||
{
|
||||
roamingTypeFileSb.AppendLine($"\t\t\t\tyield return {roamingType};");
|
||||
}
|
||||
roamingTypeFileSb.AppendLine("\t\t\t}\n\t\t}");
|
||||
}
|
||||
|
||||
|
||||
roamingTypeFileSb.AppendLine("\t}\n}");
|
||||
var file = roamingTypeFileSb.ToString();
|
||||
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Server))
|
||||
{
|
||||
await File.WriteAllTextAsync($"{_networkProtocolServerDirectory}RoamingType.cs", file);
|
||||
}
|
||||
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Client))
|
||||
{
|
||||
await File.WriteAllTextAsync($"{_networkProtocolClientDirectory}RoamingType.cs", file);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RouteType()
|
||||
{
|
||||
var routeTypeFile = $"{_networkProtocolDirectory}RouteType.Config";
|
||||
var protoFileText = "";
|
||||
if (!File.Exists(routeTypeFile))
|
||||
{
|
||||
protoFileText = "// Route协议定义(需要定义1000以上、因为1000以内的框架预留)\n";
|
||||
await File.WriteAllTextAsync(routeTypeFile, protoFileText);
|
||||
}
|
||||
else
|
||||
{
|
||||
protoFileText = await File.ReadAllTextAsync(routeTypeFile);
|
||||
}
|
||||
var routeTypeFileSb = new StringBuilder();
|
||||
routeTypeFileSb.AppendLine("namespace Fantasy\n{");
|
||||
routeTypeFileSb.AppendLine("\t// Route协议定义(需要定义1000以上、因为1000以内的框架预留)\t");
|
||||
routeTypeFileSb.AppendLine("\tpublic static class RouteType\n\t{");
|
||||
|
||||
foreach (var line in protoFileText.Split('\n'))
|
||||
{
|
||||
var currentLine = line.Trim();
|
||||
|
||||
if (currentLine.StartsWith("//"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var splits = currentLine.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var routeTypeStr = splits[0].Split("=", StringSplitOptions.RemoveEmptyEntries);
|
||||
routeTypeFileSb.Append($"\t\tpublic const int {routeTypeStr[0].Trim()} = {routeTypeStr[1].Trim()};");
|
||||
|
||||
if (splits.Length > 1)
|
||||
{
|
||||
routeTypeFileSb.Append($" // {splits[1].Trim()}\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
routeTypeFileSb.Append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
routeTypeFileSb.AppendLine("\t}\n}");
|
||||
var file = routeTypeFileSb.ToString();
|
||||
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Server))
|
||||
{
|
||||
await File.WriteAllTextAsync($"{_networkProtocolServerDirectory}RouteType.cs", file);
|
||||
}
|
||||
|
||||
if (ExporterAges.Instance.ExportPlatform.HasFlag(ExportPlatform.Client))
|
||||
{
|
||||
await File.WriteAllTextAsync($"{_networkProtocolClientDirectory}RouteType.cs", file);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadTemplate()
|
||||
{
|
||||
string[] lines = NetworkProtocolTemplate.Template.Split(["\r\n", "\n"], StringSplitOptions.None);
|
||||
|
||||
StringBuilder serverSb = new StringBuilder();
|
||||
StringBuilder clientSb = new StringBuilder();
|
||||
|
||||
int flag = 0;
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string trim = line.Trim();
|
||||
|
||||
if (trim.StartsWith("#if") && trim.Contains("SERVER"))
|
||||
{
|
||||
flag = 1;
|
||||
continue;
|
||||
}
|
||||
else if (trim.StartsWith("#else"))
|
||||
{
|
||||
flag = 2;
|
||||
continue;
|
||||
}
|
||||
else if (trim.StartsWith($"#endif"))
|
||||
{
|
||||
flag = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case 1: // 服务端
|
||||
{
|
||||
serverSb.AppendLine(line);
|
||||
break;
|
||||
}
|
||||
case 2: // 客户端
|
||||
{
|
||||
clientSb.AppendLine(line);
|
||||
break;
|
||||
}
|
||||
default: // 双端
|
||||
{
|
||||
serverSb.AppendLine(line);
|
||||
clientSb.AppendLine(line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_serverTemplate = serverSb.Replace("(NetworkProtocol)", "ProtoBuf").ToString();
|
||||
_clientTemplate = clientSb.Replace("(NetworkProtocol)", "ProtoBuf").ToString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace Fantasy.Tools.ProtocalExporter;
|
||||
|
||||
public class ProtocolOpCode
|
||||
{
|
||||
private const int Start = 10001;
|
||||
|
||||
public uint Message;
|
||||
public uint Request;
|
||||
public uint Response;
|
||||
public uint RouteMessage;
|
||||
public uint RouteRequest;
|
||||
public uint RouteResponse;
|
||||
public uint AddressableMessage;
|
||||
public uint AddressableRequest;
|
||||
public uint AddressableResponse;
|
||||
public uint CustomRouteMessage;
|
||||
public uint CustomRouteRequest;
|
||||
public uint CustomRouteResponse;
|
||||
public uint RoamingMessage;
|
||||
public uint RoamingRequest;
|
||||
public uint RoamingResponse;
|
||||
|
||||
public uint AMessage = Start;
|
||||
public uint ARequest = Start;
|
||||
public uint AResponse = Start;
|
||||
public uint ARouteMessage = Start;
|
||||
public uint ARouteRequest = Start;
|
||||
public uint ARouteResponse = Start;
|
||||
public uint AAddressableMessage = Start;
|
||||
public uint AAddressableRequest = Start;
|
||||
public uint AAddressableResponse = Start;
|
||||
public uint ACustomRouteMessage = Start;
|
||||
public uint ACustomRouteRequest = Start;
|
||||
public uint ACustomRouteResponse = Start;
|
||||
public uint ARoamingMessage = Start;
|
||||
public uint ARoamingRequest = Start;
|
||||
public uint ARoamingResponse = Start;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using CommandLine;
|
||||
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
|
||||
namespace Fantasy.Tools;
|
||||
|
||||
public class ExporterAges
|
||||
{
|
||||
public static ExporterAges Instance;
|
||||
/// <summary>
|
||||
/// 导出目标平台枚举,用于标识导出到哪个平台
|
||||
/// </summary>
|
||||
[Option('p',"ExportPlatform", Required = false, Default = ExportPlatform.None, HelpText = "Export target platform:\n/// Client target platform \nClient = 1\n/// Server target platform\nServer = 2\n/// Client and Server target platform\nAll = 3")]
|
||||
public ExportPlatform ExportPlatform { get; set; }
|
||||
|
||||
[Option('f',"Folder", Required = false, HelpText = "ExporterSetting.json file path")]
|
||||
public string Folder { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"Export": {
|
||||
"NetworkProtocolDirectory": {
|
||||
"Value": "../../../Examples/Config/NetworkProtocol/",
|
||||
"Comment": "ProtoBuf文件所在的文件夹位置"
|
||||
},
|
||||
"NetworkProtocolServerDirectory": {
|
||||
"Value": "../../../Examples/Server/Entity/Generate/NetworkProtocol/",
|
||||
"Comment": "ProtoBuf生成到服务端的文件夹位置"
|
||||
},
|
||||
"NetworkProtocolClientDirectory": {
|
||||
"Value": "../../../Examples/Client/Unity/Assets/Scripts/Hotfix/Generate/NetworkProtocol/",
|
||||
"Comment": "ProtoBuf生成到客户端的文件夹位置"
|
||||
},
|
||||
"Serializes": {
|
||||
"Value": [
|
||||
// {
|
||||
// "KeyIndex": 0,
|
||||
// "NameSpace" : "MemoryPack",
|
||||
// "SerializeName": "MemoryPack",
|
||||
// "Attribute": "\t[MemoryPackable]",
|
||||
// "Ignore": "\t\t[MemoryPackIgnore]",
|
||||
// "Member": "MemoryPackOrder"
|
||||
// }
|
||||
],
|
||||
"Comment": "自定义序列化器"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Helper;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
#pragma warning disable CS8604 // Possible null reference argument.
|
||||
|
||||
namespace Fantasy.Tools.ProtocalExporter;
|
||||
|
||||
public class ExporterSettingsHelper
|
||||
{
|
||||
public static string? NetworkProtocolDirectory { get; private set; }
|
||||
public static string NetworkProtocolServerDirectory { get; private set; }
|
||||
public static string NetworkProtocolClientDirectory { get; private set; }
|
||||
public static Dictionary<string, CustomSerialize> CustomSerializes { get; private set; }
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
const string settingsName = "ExporterSettings.json";
|
||||
var currentDirectory = ExporterAges.Instance.Folder;
|
||||
if (string.IsNullOrEmpty(currentDirectory))
|
||||
{
|
||||
currentDirectory = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
if (!File.Exists(Path.Combine(currentDirectory, settingsName)))
|
||||
{
|
||||
throw new FileNotFoundException($"not found {settingsName} in OutputDirectory");
|
||||
}
|
||||
|
||||
var root = new ConfigurationBuilder().SetBasePath(currentDirectory).AddJsonFile(settingsName).Build();
|
||||
|
||||
NetworkProtocolDirectory = FileHelper.GetFullPath(root["Export:NetworkProtocolDirectory:Value"], currentDirectory);
|
||||
NetworkProtocolServerDirectory = FileHelper.GetFullPath(root["Export:NetworkProtocolServerDirectory:Value"], currentDirectory);
|
||||
NetworkProtocolClientDirectory = FileHelper.GetFullPath(root["Export:NetworkProtocolClientDirectory:Value"], currentDirectory);
|
||||
|
||||
CustomSerializes = [];
|
||||
var sort = new SortedList<long, CustomSerialize>();
|
||||
var arrayOfValuesSection = root.GetSection("Export:Serializes:Value");
|
||||
|
||||
foreach (var item in arrayOfValuesSection.GetChildren())
|
||||
{
|
||||
var serializeItem = new CustomSerialize
|
||||
{
|
||||
KeyIndex = Convert.ToInt32(item.GetSection("KeyIndex").Value),
|
||||
NameSpace = item.GetSection("NameSpace").Value,
|
||||
SerializeName = item.GetSection("SerializeName").Value,
|
||||
Attribute = item.GetSection("Attribute").Value,
|
||||
Ignore = item.GetSection("Ignore").Value,
|
||||
Member = item.GetSection("Member").Value
|
||||
};
|
||||
|
||||
sort.Add(HashCodeHelper.ComputeHash64(serializeItem.SerializeName), serializeItem);
|
||||
}
|
||||
|
||||
for (var i = 0; i < sort.Count; i++)
|
||||
{
|
||||
var customSerialize = sort.GetValueAtIndex(i);
|
||||
customSerialize.OpCodeType = (uint)(i + 2);
|
||||
CustomSerializes.Add(customSerialize.SerializeName, customSerialize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>default</LangVersion>
|
||||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<OutputPath>../../Exporter/NetworkProtocol/</OutputPath>
|
||||
<DefineConstants>TRACE;FANTASY_NET</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<OutputPath>../../Exporter/NetworkProtocol/</OutputPath>
|
||||
<DefineConstants>TRACE;FANTASY_NET</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\FileHelper.cs">
|
||||
<Link>Core\FileHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\HashCodeHelper.cs">
|
||||
<Link>Core\HashCodeHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Helper\JsonHelper.cs">
|
||||
<Link>Core\JsonHelper.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\..\Fantasy.Net\Fantasy.Net\Runtime\Core\Network\Message\PacketParser\OpCode.cs">
|
||||
<Link>ProtocalExporter\OpCode.cs</Link>
|
||||
</Compile>
|
||||
<Compile Update="ExporterSettingsHelper.cs">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="ExporterSettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Run.bat">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Run.sh">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
28
Tools/SourceCode/Fantasy.Tools.NetworkProtocol/Program.cs
Normal file
28
Tools/SourceCode/Fantasy.Tools.NetworkProtocol/Program.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Text;
|
||||
using CommandLine;
|
||||
using Fantasy.Exporter;
|
||||
using Fantasy.Tools;
|
||||
using Fantasy.Tools.ProtocalExporter;
|
||||
// 解析命令行参数
|
||||
Parser.Default.ParseArguments<ExporterAges>(Environment.GetCommandLineArgs())
|
||||
.WithNotParsed(error => throw new Exception("Command line format error!"))
|
||||
.WithParsed(ages => ExporterAges.Instance = ages);
|
||||
try
|
||||
{
|
||||
// 初始化配置
|
||||
ExporterSettingsHelper.Initialize();
|
||||
// 加载配置
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
// 运行导出协议的代码
|
||||
new ProtocolExporter().Run();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.Info("按任意键退出程序");
|
||||
Console.ReadKey();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"Fantasy.Tools.NetworkProtocol": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {},
|
||||
"commandLineArgs": "--ExportPlatform 3"
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Tools/SourceCode/Fantasy.Tools.NetworkProtocol/Run.bat
Normal file
21
Tools/SourceCode/Fantasy.Tools.NetworkProtocol/Run.bat
Normal file
@@ -0,0 +1,21 @@
|
||||
@echo off
|
||||
|
||||
echo Please select an option:
|
||||
echo 1. Client
|
||||
echo 2. Server
|
||||
echo 3. All
|
||||
|
||||
set /p choice=Please select an option:
|
||||
|
||||
if "%choice%"=="1" (
|
||||
echo Client
|
||||
dotnet Fantasy.Tools.NetworkProtocol.dll --p 1
|
||||
) else if "%choice%"=="2" (
|
||||
echo Server
|
||||
dotnet Fantasy.Tools.NetworkProtocol.dll --p 2
|
||||
) else if "%choice%"=="3" (
|
||||
echo All
|
||||
dotnet Fantasy.Tools.NetworkProtocol.dll --p 3
|
||||
) else (
|
||||
echo Invalid option
|
||||
)
|
||||
24
Tools/SourceCode/Fantasy.Tools.NetworkProtocol/Run.sh
Normal file
24
Tools/SourceCode/Fantasy.Tools.NetworkProtocol/Run.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "1. Client"
|
||||
echo "2. Server"
|
||||
echo "3. All"
|
||||
|
||||
read -n 1 -p "Please select an option:" choice
|
||||
echo ""
|
||||
echo ""
|
||||
script_dir=$(cd $(dirname $0) && pwd)
|
||||
case $choice in
|
||||
1)
|
||||
dotnet $script_dir/Fantasy.Tools.NetworkProtocol.dll --p 1 --f $script_dir
|
||||
;;
|
||||
2)
|
||||
dotnet $script_dir/Fantasy.Tools.NetworkProtocol.dll --p 2 --f $script_dir
|
||||
;;
|
||||
3)
|
||||
dotnet $script_dir/Fantasy.Tools.NetworkProtocol.dll --p 3 --f $script_dir
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option"
|
||||
;;
|
||||
esac
|
||||
44
Tools/SourceCode/Fantasy.Tools.SourceCode.sln
Normal file
44
Tools/SourceCode/Fantasy.Tools.SourceCode.sln
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Tools.NetworkProtocol", "Fantasy.Tools.NetworkProtocol\Fantasy.Tools.NetworkProtocol.csproj", "{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Tools.ConfigTable", "Fantasy.Tools.ConfigTable\Fantasy.Tools.ConfigTable.csproj", "{F01BD146-FDEA-46D6-9A08-F3CCF05D817E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{CCF6F6B1-50D8-4B0D-91B9-035CDCC4B1CA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Tools.ExporterNetworkProtocol", "..\NuGet\Fantasy.Tools.ExporterNetworkProtocol\Fantasy.Tools.ExporterNetworkProtocol.csproj", "{E0F9231E-F057-4121-B167-7AC47D48E7E3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fantasy.Tools.ExporterConfigTable", "..\NuGet\Fantasy.Tools.ExporterConfigTable\Fantasy.Tools.ExporterConfigTable.csproj", "{5A236869-283F-4046-860B-E295963139AB}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceCode", "SourceCode", "{A402EB74-8BF8-4A53-82F2-F77E59D9F4C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F01BD146-FDEA-46D6-9A08-F3CCF05D817E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F01BD146-FDEA-46D6-9A08-F3CCF05D817E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F01BD146-FDEA-46D6-9A08-F3CCF05D817E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F01BD146-FDEA-46D6-9A08-F3CCF05D817E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E0F9231E-F057-4121-B167-7AC47D48E7E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E0F9231E-F057-4121-B167-7AC47D48E7E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E0F9231E-F057-4121-B167-7AC47D48E7E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E0F9231E-F057-4121-B167-7AC47D48E7E3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5A236869-283F-4046-860B-E295963139AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5A236869-283F-4046-860B-E295963139AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5A236869-283F-4046-860B-E295963139AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5A236869-283F-4046-860B-E295963139AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{E0F9231E-F057-4121-B167-7AC47D48E7E3} = {CCF6F6B1-50D8-4B0D-91B9-035CDCC4B1CA}
|
||||
{5A236869-283F-4046-860B-E295963139AB} = {CCF6F6B1-50D8-4B0D-91B9-035CDCC4B1CA}
|
||||
{F01BD146-FDEA-46D6-9A08-F3CCF05D817E} = {A402EB74-8BF8-4A53-82F2-F77E59D9F4C6}
|
||||
{72D45E2D-EF78-4D80-8BFC-ED95FA8543C7} = {A402EB74-8BF8-4A53-82F2-F77E59D9F4C6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,21 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACastHelpers_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F12728b48859e5c339bb7819b9a9aedc55b0201e8e99c0f32215f4cca043287_003FCastHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConfigurationBuilder_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Ff8dbf677037c4363bdec07364295385fab18_003F87_003F71be921c_003FConfigurationBuilder_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACSharpGeneratorDriver_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8637bc4fbc6d4e3495b5bd3ae7833b3861ef08_003Fbd_003Fb41f481a_003FCSharpGeneratorDriver_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACSharpGeneratorDriver_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F498b2959bfd8bfbefbd602fb2a4c8cc15d227d6841bc34d6f6452b68bf62a_003FCSharpGeneratorDriver_002Ecs_002Fz_003A2_002D1/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExcelPackage_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5127915f4e764e0285562916e9114ab3411610_003F47_003Fb7da0161_003FExcelPackage_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AExcelWorksheet_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5dd516838a2a4619b1b1ee6c219d6063392600_003F69_003F3d3aa05c_003FExcelWorksheet_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AGenerateType_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F958e054c967b40b3a108913205d36c4933400_003Fe4_003Fe79913ba_003FGenerateType_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIncrementalContexts_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003F74cb734c6aa249ccb363835e7c127992395baae47bc74f35e41f308958e4e837_003FIncrementalContexts_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALicenseContext_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5127915f4e764e0285562916e9114ab3411610_003F47_003Fcbc79ab6_003FLicenseContext_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMemoryPackableAttribute_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F958e054c967b40b3a108913205d36c4933400_003Fcd_003Fa95eada9_003FMemoryPackableAttribute_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMemoryPackFormatter_00601_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F958e054c967b40b3a108913205d36c4933400_003F7e_003F8f320c8b_003FMemoryPackFormatter_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AParser_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fc453ace1e4574cfe83f15ca8c8f735bf37000_003F47_003F09aa3821_003FParser_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AProtoReader_002EState_002EReadMethods_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F37c1347d9c665a9c38de996b994b62177561c4c4515e4d49fdf93cd848fe49b_003FProtoReader_002EState_002EReadMethods_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARunResults_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fe923221d2ee660ba5d21ad70b29da65ed3a69653ab6311336652dc91242cb_003FRunResults_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASerializer_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F108d10ff2bc64d2b8f1489324799f70c45600_003F9d_003Fa7270692_003FSerializer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F8bc9cdb23bc146bcaaae0bb9e45e5d46d9dc00_003Fd7_003F28f0bda8_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASuppressDefaultInitialization_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F958e054c967b40b3a108913205d36c4933400_003F6d_003F99c9c03b_003FSuppressDefaultInitialization_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue"><AssemblyExplorer>
|
||||
<Assembly Path="/Users/sining/.nuget/packages/memorypack.core/1.21.1/lib/net8.0/MemoryPack.Core.dll" />
|
||||
</AssemblyExplorer></s:String></wpf:ResourceDictionary>
|
||||
Reference in New Issue
Block a user