饭太稀

This commit is contained in:
bob
2025-06-30 10:51:37 +08:00
commit 8e45469c83
753 changed files with 87652 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using Fantasy.Platform.Net;
using Fantasy.Serialize;
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
// ReSharper disable SuspiciousTypeConversion.Global
namespace Fantasy.ConfigTable
{
/// <summary>
/// 配置表帮助类
/// </summary>
public static class ConfigTableHelper
{
private static string _configTableBinaryDirectory;
private static readonly object Lock = new object();
// 配置表数据缓存字典
private static readonly Dictionary<string, ASerialize> ConfigDic = new ();
/// <summary>
/// 初始化ConfigTableHelper
/// </summary>
/// <param name="configTableBinaryDirectory"></param>
public static void Initialize(string configTableBinaryDirectory)
{
_configTableBinaryDirectory = configTableBinaryDirectory;
}
/// <summary>
/// 加载配置表数据
/// </summary>
/// <typeparam name="T">配置表类型</typeparam>
/// <returns>配置表数据</returns>
public static T Load<T>() where T : ASerialize
{
lock (Lock)
{
try
{
var dataConfig = typeof(T).Name;
if (ConfigDic.TryGetValue(dataConfig, out var aProto))
{
return (T)aProto;
}
var configFile = GetConfigPath(dataConfig);
var bytes = File.ReadAllBytes(configFile);
// Log.Debug($"dataConfig:{dataConfig} {bytes.Length}");
var data = SerializerManager.GetSerializer(FantasySerializerType.ProtoBuf).Deserialize<T>(bytes);
ConfigDic[dataConfig] = data;
return data;
}
catch (Exception ex)
{
throw new Exception($"ConfigTableManage:{typeof(T).Name} 数据表加载之后反序列化时出错:{ex}");
}
}
}
/// <summary>
/// 获取配置表文件路径
/// </summary>
/// <param name="name">配置表名称</param>
/// <returns>配置表文件路径</returns>
private static string GetConfigPath(string name)
{
var configFile = Path.Combine(_configTableBinaryDirectory, $"{name}.bytes");
if (File.Exists(configFile))
{
return configFile;
}
throw new FileNotFoundException($"{name}.byte not found: {configFile}");
}
/// <summary>
/// 重新加载配置表数据
/// </summary>
public static void ReLoadConfigTable()
{
lock (Lock)
{
foreach (var (_, aProto) in ConfigDic)
{
((IDisposable) aProto).Dispose();
}
ConfigDic.Clear();
}
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Collections.Generic;
using ProtoBuf;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
// ReSharper disable CheckNamespace
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
namespace Fantasy.ConfigTable
{
[ProtoContract]
public partial class IntDictionaryConfig
{
[ProtoMember(1)]
public Dictionary<int, int> Dic;
public int this[int key] => GetValue(key);
public bool TryGetValue(int key, out int value)
{
value = default;
if (!Dic.ContainsKey(key))
{
return false;
}
value = Dic[key];
return true;
}
private int GetValue(int key)
{
return Dic.TryGetValue(key, out var value) ? value : 0;
}
}
}

View File

@@ -0,0 +1,35 @@
using System.Collections.Generic;
using ProtoBuf;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
// ReSharper disable CheckNamespace
// ReSharper disable CollectionNeverUpdated.Global
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
#pragma warning disable CS8603 // Possible null reference return.
namespace Fantasy.ConfigTable
{
[ProtoContract]
public sealed partial class StringDictionaryConfig
{
[ProtoMember(1)]
public Dictionary<int, string> Dic;
public string this[int key] => GetValue(key);
public bool TryGetValue(int key, out string value)
{
value = default;
if (!Dic.ContainsKey(key))
{
return false;
}
value = Dic[key];
return true;
}
private string GetValue(int key)
{
return Dic.TryGetValue(key, out var value) ? value : null;
}
}
}

View File

@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Fantasy-Net.ConfigTable</PackageId>
<PackageVersion>2024.2.0</PackageVersion>
<Title>Fantasy-Net.ConfigTable</Title>
<Authors>qq362946</Authors>
<owners>qq362946</owners>
<PackageOutputPath>../../../nupkg</PackageOutputPath>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<Description>
Fantasy is a high-performance network development framework based on .NET, supporting mainstream protocols. It is designed for development teams or individuals needing a quick start, scalability, and a distributed, cross-platform solution at the commercial level. Fantasy aims to provide easy-to-use tools while ensuring high system performance and scalability.</Description>
<Copyright>Copyright 2026 qq362946</Copyright>
<PackageProjectUrl>https://www.code-fantasy.com/</PackageProjectUrl>
<RepositoryUrl>https://github.com/qq362946/Fantasy</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>Net, c#, Server, Game, GameServer, Fantasy , Network</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>Fantasy-Net.ConfigTable</AssemblyName>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fantasy-Net" Version="2024.2.22" />
</ItemGroup>
<ItemGroup>
<None Include="icon.png" Pack="true" PackagePath="\"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
namespace Fantasy.ConfigTable
{
/// <summary>
/// 表示是一个配置文件
/// </summary>
public interface IConfigTable { }
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B