first commit
commit
1fd4cf859b
|
@ -0,0 +1,7 @@
|
|||
|
||||
/obj
|
||||
/bin
|
||||
/**/bin
|
||||
/**/obj
|
||||
/.vs
|
||||
/.idea
|
|
@ -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
|
|
@ -0,0 +1,10 @@
|
|||
<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:Boolean x:Key="/Default/AddReferences/RecentPaths/=E_003A_005CProgram_005CAOTTools_005Cx64_005CDebug_005CFileUtilsCpp_002Edll/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ACastHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F59109b68aa8966a8b4c17bb8642684239e9598dc1f117d294c355534a932786_003FCastHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AChar_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5abecb93434c4299acd01d522fdf8da2c9a910_003F0d_003F51dd6967_003FChar_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConsole_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FLocal_003FSymbols_003Fsrc_003Fdotnet_003Fruntime_003F5535e31a712343a63f5d7d796cd874e563e5ac14_003Fsrc_003Flibraries_003FSystem_002EConsole_003Fsrc_003FSystem_003FConsole_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIntPtr_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5abecb93434c4299acd01d522fdf8da2c9a910_003Fb3_003F068f89c0_003FIntPtr_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMarshal_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5abecb93434c4299acd01d522fdf8da2c9a910_003F24_003F26a00c90_003FMarshal_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASpanHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5abecb93434c4299acd01d522fdf8da2c9a910_003Fc9_003Fa214c00f_003FSpanHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASpan_00601_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5abecb93434c4299acd01d522fdf8da2c9a910_003Fad_003Fa985391c_003FSpan_00601_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AString_002Ecs_002Fl_003AC_0021_003FUsers_003FCal_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F5abecb93434c4299acd01d522fdf8da2c9a910_003F96_003F8a65a48b_003FString_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>.net8</TargetFramework>
|
||||
<LangVersion>12</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -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*<nint, void> logInfoFunc);
|
||||
[DllImport("E:\\Program\\AOTTools\\FileUtilsCs\\bin\\Debug\\net8.0\\win-x64\\native\\FileUtilsCs.dll", EntryPoint = "SetLogError")]
|
||||
static extern unsafe void SetLogError(delegate*<nint, void> 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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FileUtilsCs;
|
||||
|
||||
public class EntryPoints
|
||||
{
|
||||
internal static Action<string>? logInfoAction;
|
||||
internal static Action<string>? logErrorAction;
|
||||
|
||||
static ConcurrentQueue<string> _logQueue = new ConcurrentQueue<string>();
|
||||
static ConcurrentQueue<string> _logErrorQueue = new ConcurrentQueue<string>();
|
||||
|
||||
[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<nint, void> 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<nint, void> 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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue