commit 1fd4cf859b0a4ef1a174dd7b3ce9015cca3751f4
Author: Cal <42492716+ly3027929699@users.noreply.github.com>
Date: Fri Dec 6 10:36:22 2024 +0800
first commit
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d606010
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+
+/obj
+/bin
+/**/bin
+/**/obj
+/.vs
+/.idea
\ No newline at end of file
diff --git a/AOTTools.sln b/AOTTools.sln
new file mode 100644
index 0000000..fc1739f
--- /dev/null
+++ b/AOTTools.sln
@@ -0,0 +1,32 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileUtilsCs", "FileUtilsCs\FileUtilsCs.csproj", "{79C05D95-9B9E-4F00-809A-BA0ED2334F2C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console\Console.csproj", "{85DB4934-1B66-46DA-903B-A2BD809ABF2B}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Debug|x64 = Debug|x64
+ Release|Win32 = Release|Win32
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Debug|Win32.ActiveCfg = Debug|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Debug|Win32.Build.0 = Debug|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Debug|x64.Build.0 = Debug|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Release|Win32.ActiveCfg = Release|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Release|Win32.Build.0 = Release|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Release|x64.ActiveCfg = Release|Any CPU
+ {79C05D95-9B9E-4F00-809A-BA0ED2334F2C}.Release|x64.Build.0 = Release|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Debug|Win32.ActiveCfg = Debug|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Debug|Win32.Build.0 = Debug|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Debug|x64.Build.0 = Debug|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Release|Win32.ActiveCfg = Release|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Release|Win32.Build.0 = Release|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Release|x64.ActiveCfg = Release|Any CPU
+ {85DB4934-1B66-46DA-903B-A2BD809ABF2B}.Release|x64.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal
diff --git a/AOTTools.sln.DotSettings.user b/AOTTools.sln.DotSettings.user
new file mode 100644
index 0000000..3cf148f
--- /dev/null
+++ b/AOTTools.sln.DotSettings.user
@@ -0,0 +1,10 @@
+
+ True
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
+ ForceIncluded
\ No newline at end of file
diff --git a/Console/Console.csproj b/Console/Console.csproj
new file mode 100644
index 0000000..05aa491
--- /dev/null
+++ b/Console/Console.csproj
@@ -0,0 +1,10 @@
+
+
+ Exe
+ .net8
+ 12
+ enable
+ true
+ true
+
+
diff --git a/Console/Program.cs b/Console/Program.cs
new file mode 100644
index 0000000..93e5012
--- /dev/null
+++ b/Console/Program.cs
@@ -0,0 +1,47 @@
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+unsafe
+{
+ Console.WriteLine(1);
+ SetLogInfo(& LogInfo);
+ SetLogError(& LogError);
+ TimeProvider.System.CreateTimer(Callback, null, TimeSpan.FromMilliseconds(16), TimeSpan.FromMilliseconds(16));
+
+ void Callback(object? state)
+ {
+ Tick();
+ }
+
+ TestLog();
+ TestLogError();
+ MoveFolder(
+ (char*)Unsafe.AsPointer(ref Unsafe.AsRef(in "C:\\A".GetPinnableReference())),
+ (char*)Unsafe.AsPointer(ref Unsafe.AsRef(in "C:\\B".GetPinnableReference())));
+ Console.ReadKey();
+
+ [DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "TestLog")]
+ static extern void TestLog();
+
+ [DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "SetLogInfo")]
+ static extern unsafe void SetLogInfo(delegate* logInfoFunc);
+ [DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "SetLogError")]
+ static extern unsafe void SetLogError(delegate* logInfoFunc);
+ [DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "TestLogError")]
+ static extern unsafe void TestLogError();
+ [DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "Tick")]
+ static extern unsafe void Tick();
+ [DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "MoveFolder")]
+ static extern unsafe void MoveFolder(char* sourcePath, char* destinationPath);
+
+ static unsafe void LogInfo(nint obj)
+ {
+ var addrOfPinnedObject = new string((char*)obj);
+ System.Console.WriteLine(addrOfPinnedObject);
+ }
+ static unsafe void LogError(nint obj)
+ {
+ var addrOfPinnedObject = new string((char*)obj);
+ System.Console.WriteLine(addrOfPinnedObject);
+ }
+}
\ No newline at end of file
diff --git a/FileUtilsCs/EntryPoints.cs b/FileUtilsCs/EntryPoints.cs
new file mode 100644
index 0000000..35bd613
--- /dev/null
+++ b/FileUtilsCs/EntryPoints.cs
@@ -0,0 +1,140 @@
+using System.Collections.Concurrent;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace FileUtilsCs;
+
+public class EntryPoints
+{
+ internal static Action? logInfoAction;
+ internal static Action? logErrorAction;
+
+ static ConcurrentQueue _logQueue = new ConcurrentQueue();
+ static ConcurrentQueue _logErrorQueue = new ConcurrentQueue();
+
+ [UnmanagedCallersOnly(EntryPoint = "Tick")]
+ static void Tick()
+ {
+ if (_logErrorQueue.TryDequeue(out var error))
+ {
+ logErrorAction?.Invoke(error);
+ }
+ _logErrorQueue.Clear();
+ if (_logQueue.TryDequeue(out var message))
+ {
+ logInfoAction?.Invoke(message);
+ }
+ _logQueue.Clear();
+ }
+
+ public static void LogError(string message)
+ {
+ _logErrorQueue.Enqueue(message);
+ }
+
+ public static void Log(string message)
+ {
+ _logQueue.Enqueue(message);
+ }
+ [UnmanagedCallersOnly(EntryPoint = "SetLogInfo")]
+ public static unsafe void SetLogInfo(delegate* managed logAction)
+ {
+ logInfoAction = (o) =>
+ {
+ var pp = (nint)Unsafe.AsPointer(ref Unsafe.AsRef(in o.GetPinnableReference()));
+ logAction(pp);
+ };
+ }
+
+ [UnmanagedCallersOnly(EntryPoint = "SetLogError")]
+ public static unsafe void SetLogError(delegate* managed logAction)
+ {
+ logErrorAction = (o) =>
+ {
+ var pp = (nint)Unsafe.AsPointer(ref Unsafe.AsRef(in o.GetPinnableReference()));
+ logAction(pp);
+ };
+ }
+
+
+ [UnmanagedCallersOnly(EntryPoint = "TestLog")]
+ public static unsafe void TestLog()
+ {
+ Log($"dgvrthdhstgse234wsfsf");
+ }
+
+ [UnmanagedCallersOnly(EntryPoint = "TestLogError")]
+ public static unsafe void TestLogError()
+ {
+ LogError($"sadsagfas2qsafssaf");
+ }
+
+
+ [UnmanagedCallersOnly(EntryPoint = "MoveFolder")]
+ public static unsafe void MoveFolder(char* source, char* destination)
+ {
+ var srcRootPath = new string(source);
+ var destRootPath = new string(destination);
+ MoveFolder(srcRootPath, destRootPath, true);
+ }
+
+ static void MoveFolder(string srcRootPath, string destRootPath, bool isRoot)
+ {
+ try
+ {
+ if (isRoot && !Directory.Exists(srcRootPath))
+ throw new Exception($"srcRootPath : {srcRootPath} not exists!");
+ if (isRoot && !Directory.Exists(destRootPath))
+ throw new Exception($"srcRootPath : {destRootPath} not exists!");
+ if (Path.GetFullPath(srcRootPath) == Path.GetFullPath(destRootPath))
+ return;
+ srcRootPath = srcRootPath[srcRootPath.Length - 1] != Path.DirectorySeparatorChar ? srcRootPath + Path.DirectorySeparatorChar : srcRootPath;
+ destRootPath = destRootPath[destRootPath.Length - 1] != Path.DirectorySeparatorChar ? destRootPath + Path.DirectorySeparatorChar : destRootPath;
+ var files = Directory.GetFiles(srcRootPath, "*.*", SearchOption.TopDirectoryOnly);
+ for (int i = 0; i < files.Length; i++)
+ {
+ String srcFileFullName = files[i];
+
+ Task.Run(() =>
+ {
+ try
+ {
+ var srcFileNameBaseRoot = srcFileFullName.Replace(srcRootPath, String.Empty);
+
+ var destFileFullName = Path.Combine(destRootPath, srcFileNameBaseRoot);
+ var destDirectoryInfo = new FileInfo(destFileFullName).Directory;
+ if (destDirectoryInfo == null)
+ {
+ LogError($"destDirectoryInfo is null where path is :{destFileFullName}");
+ return;
+ }
+
+ if (!destDirectoryInfo.Exists)
+ {
+ destDirectoryInfo.Create();
+ }
+
+ File.Copy(srcFileFullName, destFileFullName, true);
+ Log($"Copy [{srcFileFullName}] to [{destFileFullName}]");
+ }
+ catch (Exception e)
+ {
+ LogError(e.ToString());
+ }
+ });
+ }
+
+ var directories = Directory.GetDirectories(srcRootPath, "*", SearchOption.TopDirectoryOnly);
+ for (int i = 0; i < directories.Length; i++)
+ {
+ var srcDirectoryFullName = directories[i];
+ var srcDirectoryBaseRootPath = srcDirectoryFullName.Replace(srcRootPath, String.Empty);
+ MoveFolder(srcDirectoryFullName, Path.Combine(destRootPath, srcDirectoryBaseRootPath), false);
+ }
+ }
+ catch (Exception e)
+ {
+ LogError(e.ToString());
+ }
+ }
+}
\ No newline at end of file
diff --git a/FileUtilsCs/FileUtilsCs.csproj b/FileUtilsCs/FileUtilsCs.csproj
new file mode 100644
index 0000000..fcce192
--- /dev/null
+++ b/FileUtilsCs/FileUtilsCs.csproj
@@ -0,0 +1,11 @@
+
+
+
+ net8.0
+ enable
+ enable
+ true
+ true
+
+
+