fix: Adds CUO settings support and adds more robust 7.0.9 support (#945)
This commit is contained in:
parent
941452de4a
commit
5b7b99e0de
12 changed files with 958 additions and 773 deletions
|
|
@ -17,70 +17,69 @@ using System;
|
|||
using System.IO;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server
|
||||
namespace Server;
|
||||
|
||||
public static class PathUtility
|
||||
{
|
||||
public static class PathUtility
|
||||
public static string EnsureDirectory(string dir)
|
||||
{
|
||||
public static string EnsureDirectory(string dir)
|
||||
var path = GetFullPath(dir, Core.BaseDirectory);
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(this FileInfo fi)
|
||||
{
|
||||
var dir = GetFullPath(fi.DirectoryName, Core.BaseDirectory);
|
||||
if (dir != null)
|
||||
{
|
||||
var path = GetFullPath(dir, Core.BaseDirectory);
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(this FileInfo fi)
|
||||
{
|
||||
var dir = GetFullPath(fi.DirectoryName, Core.BaseDirectory);
|
||||
if (dir != null)
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(this DirectoryInfo di)
|
||||
{
|
||||
var file = GetFullPath(di.FullName, Core.BaseDirectory);
|
||||
Directory.CreateDirectory(file);
|
||||
}
|
||||
|
||||
public static string GetFullPath(string relativeOrAbsolutePath) =>
|
||||
GetFullPath(relativeOrAbsolutePath, Core.BaseDirectory);
|
||||
|
||||
public static string GetFullPath(string relativeOrAbsolutePath, string basePath) =>
|
||||
relativeOrAbsolutePath switch
|
||||
{
|
||||
null => null,
|
||||
"" => basePath,
|
||||
_ => Path.IsPathRooted(relativeOrAbsolutePath)
|
||||
? relativeOrAbsolutePath
|
||||
: Path.GetFullPath(relativeOrAbsolutePath, basePath)
|
||||
};
|
||||
|
||||
public static string EnsureRandomPath(string basePath)
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[8];
|
||||
Utility.RandomBytes(bytes);
|
||||
return EnsureDirectory(Path.Combine(basePath, bytes.ToHexString()));
|
||||
}
|
||||
|
||||
public static void CopyDirectory(string sourcePath, string destinationPath, bool recursive = true)
|
||||
{
|
||||
var searchOptions = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
foreach (var file in Directory.EnumerateFiles(sourcePath, "*", searchOptions))
|
||||
{
|
||||
var fi = new FileInfo(file);
|
||||
var relativePath = Path.GetRelativePath(sourcePath, fi.DirectoryName!);
|
||||
var destFolder = Path.Combine(destinationPath, relativePath);
|
||||
EnsureDirectory(destFolder);
|
||||
fi.CopyTo(Path.Combine(destFolder, fi.Name));
|
||||
}
|
||||
}
|
||||
|
||||
public static void MoveDirectory(string sourcePath, string destinationPath)
|
||||
{
|
||||
CopyDirectory(sourcePath, destinationPath);
|
||||
Directory.Delete(sourcePath, true);
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(this DirectoryInfo di)
|
||||
{
|
||||
var file = GetFullPath(di.FullName, Core.BaseDirectory);
|
||||
Directory.CreateDirectory(file);
|
||||
}
|
||||
|
||||
public static string GetFullPath(string relativeOrAbsolutePath) =>
|
||||
GetFullPath(relativeOrAbsolutePath, Core.BaseDirectory);
|
||||
|
||||
public static string GetFullPath(string relativeOrAbsolutePath, string basePath) =>
|
||||
relativeOrAbsolutePath switch
|
||||
{
|
||||
null => null,
|
||||
"" => basePath,
|
||||
_ => Path.IsPathRooted(relativeOrAbsolutePath)
|
||||
? relativeOrAbsolutePath
|
||||
: Path.GetFullPath(relativeOrAbsolutePath, basePath)
|
||||
};
|
||||
|
||||
public static string EnsureRandomPath(string basePath)
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[8];
|
||||
Utility.RandomBytes(bytes);
|
||||
return EnsureDirectory(Path.Combine(basePath, bytes.ToHexString()));
|
||||
}
|
||||
|
||||
public static void CopyDirectory(string sourcePath, string destinationPath, bool recursive = true)
|
||||
{
|
||||
var searchOptions = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
foreach (var file in Directory.EnumerateFiles(sourcePath, "*", searchOptions))
|
||||
{
|
||||
var fi = new FileInfo(file);
|
||||
var relativePath = Path.GetRelativePath(sourcePath, fi.DirectoryName!);
|
||||
var destFolder = Path.Combine(destinationPath, relativePath);
|
||||
EnsureDirectory(destFolder);
|
||||
fi.CopyTo(Path.Combine(destFolder, fi.Name));
|
||||
}
|
||||
}
|
||||
|
||||
public static void MoveDirectory(string sourcePath, string destinationPath)
|
||||
{
|
||||
CopyDirectory(sourcePath, destinationPath);
|
||||
Directory.Delete(sourcePath, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue