From 43446d4443222b659fd4a41a08ca19a42c75c547 Mon Sep 17 00:00:00 2001 From: ikpil Date: Mon, 28 Oct 2024 22:36:20 +0900 Subject: [PATCH] add publish to unirecast --- DotRecast.sln | 9 + .../CsProj.cs | 15 ++ .../DotRecast.Tool.PublishToUniRecast.csproj | 9 + .../Program.cs | 169 ++++++++++++++++++ 4 files changed, 202 insertions(+) create mode 100644 tool/DotRecast.Tool.PublishToUniRecast/CsProj.cs create mode 100644 tool/DotRecast.Tool.PublishToUniRecast/DotRecast.Tool.PublishToUniRecast.csproj create mode 100644 tool/DotRecast.Tool.PublishToUniRecast/Program.cs diff --git a/DotRecast.sln b/DotRecast.sln index 581b760..006fc1f 100644 --- a/DotRecast.sln +++ b/DotRecast.sln @@ -41,6 +41,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRecast.Detour.TileCache. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRecast.Benchmark", "test\DotRecast.Benchmark\DotRecast.Benchmark.csproj", "{D1EFC625-D095-4208-98A2-112B73CB40B0}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tool", "tool", "{9C213609-BF13-4024-816E-A6ADD641DF24}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotRecast.Tool.PublishToUniRecast", "tool\DotRecast.Tool.PublishToUniRecast\DotRecast.Tool.PublishToUniRecast.csproj", "{1822BBA8-FE4E-4C5F-B9C0-3E20E6353446}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -118,6 +122,10 @@ Global {D1EFC625-D095-4208-98A2-112B73CB40B0}.Debug|Any CPU.Build.0 = Debug|Any CPU {D1EFC625-D095-4208-98A2-112B73CB40B0}.Release|Any CPU.ActiveCfg = Release|Any CPU {D1EFC625-D095-4208-98A2-112B73CB40B0}.Release|Any CPU.Build.0 = Release|Any CPU + {1822BBA8-FE4E-4C5F-B9C0-3E20E6353446}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1822BBA8-FE4E-4C5F-B9C0-3E20E6353446}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1822BBA8-FE4E-4C5F-B9C0-3E20E6353446}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1822BBA8-FE4E-4C5F-B9C0-3E20E6353446}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {FFE40BBF-843B-41FA-8504-F4ABD166762E} = {8ED75CF7-A3D6-423D-8499-9316DD413DAD} @@ -137,5 +145,6 @@ Global {3CAA7306-088E-4373-A406-99755CC2B605} = {A7CB8D8B-70DA-4567-8316-0659FCAE1C73} {10395C8F-DFBD-4263-8A20-EA3500A6E55A} = {A7CB8D8B-70DA-4567-8316-0659FCAE1C73} {D1EFC625-D095-4208-98A2-112B73CB40B0} = {A7CB8D8B-70DA-4567-8316-0659FCAE1C73} + {1822BBA8-FE4E-4C5F-B9C0-3E20E6353446} = {9C213609-BF13-4024-816E-A6ADD641DF24} EndGlobalSection EndGlobal diff --git a/tool/DotRecast.Tool.PublishToUniRecast/CsProj.cs b/tool/DotRecast.Tool.PublishToUniRecast/CsProj.cs new file mode 100644 index 0000000..bd545ce --- /dev/null +++ b/tool/DotRecast.Tool.PublishToUniRecast/CsProj.cs @@ -0,0 +1,15 @@ +namespace DotRecast.Tool.PublishToUniRecast; + +public class CsProj +{ + public readonly string RootPath; + public readonly string Name; + public readonly string TargetPath; + + public CsProj(string rootPath, string name, string targetPath) + { + RootPath = rootPath; + Name = name; + TargetPath = targetPath; + } +} \ No newline at end of file diff --git a/tool/DotRecast.Tool.PublishToUniRecast/DotRecast.Tool.PublishToUniRecast.csproj b/tool/DotRecast.Tool.PublishToUniRecast/DotRecast.Tool.PublishToUniRecast.csproj new file mode 100644 index 0000000..70cfa9d --- /dev/null +++ b/tool/DotRecast.Tool.PublishToUniRecast/DotRecast.Tool.PublishToUniRecast.csproj @@ -0,0 +1,9 @@ + + + + Exe + net6.0;net8.0 + false + + + diff --git a/tool/DotRecast.Tool.PublishToUniRecast/Program.cs b/tool/DotRecast.Tool.PublishToUniRecast/Program.cs new file mode 100644 index 0000000..e5300e0 --- /dev/null +++ b/tool/DotRecast.Tool.PublishToUniRecast/Program.cs @@ -0,0 +1,169 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.IO; +using System.Linq; + +namespace DotRecast.Tool.PublishToUniRecast; + +public static class Program +{ + public static void Main(string[] args) + { + var source = SearchDirectory("DotRecast"); + var destination = SearchDirectory("UniRecast"); + + if (!Directory.Exists(source)) + { + throw new Exception("not found source directory"); + } + + if (!Directory.Exists(destination)) + { + throw new Exception("not found destination directory"); + } + + var ignorePaths = ImmutableArray.Create("bin", "obj"); + var projs = ImmutableArray.Create( + // src + new CsProj("src", "DotRecast.Core", "Runtime"), + new CsProj("src", "DotRecast.Recast", "Runtime"), + new CsProj("src", "DotRecast.Detour", "Runtime"), + new CsProj("src", "DotRecast.Detour.Crowd", "Runtime"), + new CsProj("src", "DotRecast.Detour.Dynamic", "Runtime"), + new CsProj("src", "DotRecast.Detour.Extras", "Runtime"), + new CsProj("src", "DotRecast.Detour.TileCache", "Runtime"), + new CsProj("src", "DotRecast.Recast.Toolset", "Runtime") + ); + + + foreach (var proj in projs) + { + var sourcePath = Path.Combine(source, proj.RootPath, $"{proj.Name}"); + var destPath = Path.Combine(destination, $"{proj.TargetPath}", $"{proj.Name}"); + + SyncFiles(sourcePath, destPath, ignorePaths, "*.cs"); + } + + // // 몇몇 필요한 리소스 복사 하기 + // string destResourcePath = destDotRecast + "/resources"; + // if (!Directory.Exists(destResourcePath)) + // { + // Directory.CreateDirectory(destResourcePath); + // } + + // string sourceResourcePath = Path.Combine(dotRecastPath, "resources/nav_test.obj"); + // File.Copy(sourceResourcePath, destResourcePath + "/nav_test.obj", true); + } + + public static string SearchPath(string searchPath, int depth, out bool isDir) + { + isDir = false; + + for (int i = 0; i < depth; ++i) + { + var relativePath = string.Join("", Enumerable.Range(0, i).Select(x => "../")); + var searchingPath = Path.Combine(relativePath, searchPath); + var fullSearchingPath = Path.GetFullPath(searchingPath); + + if (File.Exists(fullSearchingPath)) + { + return fullSearchingPath; + } + + if (Directory.Exists(fullSearchingPath)) + { + isDir = true; + return fullSearchingPath; + } + } + + return string.Empty; + } + + // only directory + public static string SearchDirectory(string dirname, int depth = 10) + { + var searchingPath = SearchPath(dirname, depth, out var isDir); + if (isDir) + { + return searchingPath; + } + + var path = Path.GetDirectoryName(searchingPath) ?? string.Empty; + return path; + } + + public static string SearchFile(string filename, int depth = 10) + { + var searchingPath = SearchPath(filename, depth, out var isDir); + if (!isDir) + { + return searchingPath; + } + + return string.Empty; + } + + private static void SyncFiles(string srcRootPath, string dstRootPath, IList ignoreFolders, string searchPattern = "*") + { + // 끝에서부터 이그노어 폴더일 경우 패스 + var destLastFolderName = Path.GetFileName(dstRootPath); + if (ignoreFolders.Any(x => x == destLastFolderName)) + return; + + if (!Directory.Exists(dstRootPath)) + Directory.CreateDirectory(dstRootPath); + + // 소스파일 추출 + var sourceFiles = Directory.GetFiles(srcRootPath, searchPattern).ToList(); + var sourceFolders = Directory.GetDirectories(srcRootPath) + .Select(x => new DirectoryInfo(x)) + .ToList(); + + // 대상 파일 추출 + var destinationFiles = Directory.GetFiles(dstRootPath, searchPattern).ToList(); + var destinationFolders = Directory.GetDirectories(dstRootPath) + .Select(x => new DirectoryInfo(x)) + .ToList(); + + // 대상에 파일이 있는데, 소스에 없을 경우, 대상 파일을 삭제 한다. + foreach (var destinationFile in destinationFiles) + { + var destName = Path.GetFileName(destinationFile); + var found = sourceFiles.Any(x => Path.GetFileName(x) == destName); + if (found) + continue; + + File.Delete(destinationFile); + Console.WriteLine($"delete file - {destinationFile}"); + } + + // 대상에 폴더가 있는데, 소스에 없을 경우, 대상 폴더를 삭제 한다. + foreach (var destinationFolder in destinationFolders) + { + var found = sourceFolders.Any(sourceFolder => sourceFolder.Name == destinationFolder.Name); + if (found) + continue; + + Directory.Delete(destinationFolder.FullName, true); + Console.WriteLine($"delete folder - {destinationFolder.FullName}"); + } + + // 소스 파일을 복사 한다. + foreach (var sourceFile in sourceFiles) + { + var name = Path.GetFileName(sourceFile); + var dest = Path.Combine(dstRootPath, name); + File.Copy(sourceFile, dest, true); + Console.WriteLine($"copy - {sourceFile} => {dest}"); + } + + // 대상 폴더를 복사 한다 + foreach (var sourceFolder in sourceFolders) + { + var dest = Path.Combine(dstRootPath, sourceFolder.Name); + SyncFiles(sourceFolder.FullName, dest, ignoreFolders, searchPattern); + } + } +} \ No newline at end of file