mirror of
https://github.com/MikuLeaks/KianaBH3.git
synced 2025-12-14 05:44:34 +01:00
Init enter game
This commit is contained in:
38
KianaBH/Tool/AssemblyGenerater.cs
Normal file
38
KianaBH/Tool/AssemblyGenerater.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using KianaBH.Util;
|
||||
using System.Reflection;
|
||||
|
||||
namespace KianaBH.KianaBH.Tool;
|
||||
|
||||
public class AssemblyGenerater
|
||||
{
|
||||
private static readonly string SourceSpace = "KianaBH.KianaBH.Source.";
|
||||
|
||||
public static async ValueTask LoadCustomData(Assembly assembly)
|
||||
{
|
||||
string[] embededRes = assembly.GetManifestResourceNames();
|
||||
foreach (var res in embededRes)
|
||||
{
|
||||
var stream = assembly.GetManifestResourceStream(res);
|
||||
if (stream != null && res.Contains(ConfigManager.Config.Path.DataPath.Split("/").Last()))
|
||||
await WriteOutputFiles(stream, res);
|
||||
}
|
||||
}
|
||||
|
||||
private async static ValueTask WriteOutputFiles(Stream stream, string resSpace)
|
||||
{
|
||||
if (stream == null) return;
|
||||
|
||||
string relativePath = resSpace.Replace(SourceSpace, "");
|
||||
int lastDotIndex = relativePath.LastIndexOf('.');
|
||||
string outputPath = string.Concat(
|
||||
ConfigManager.Config.Path.ConfigPath, "/",
|
||||
relativePath[..lastDotIndex].Replace('.', '/'),
|
||||
relativePath.AsSpan(lastDotIndex));
|
||||
|
||||
if (File.Exists(outputPath)) return; // Check if file exist
|
||||
|
||||
using var fileStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
|
||||
stream.Position = 0;
|
||||
await stream.CopyToAsync(fileStream);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user