mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 18:27:21 +00:00
Added backups of all data, restorable on another computer (#1008)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
ab45580473
commit
936043319c
144 files changed
+10417
-424
No files matched your search
@@ -0,0 +1,45 @@
|
||||
namespace AIStudio.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Shared rules for comparing file system paths.
|
||||
/// </summary>
|
||||
public static class PathTools
|
||||
{
|
||||
/// <summary>
|
||||
/// How to compare file system paths: Windows treats them case-insensitively, Linux and
|
||||
/// macOS do not. There, two files may differ in casing alone.
|
||||
/// </summary>
|
||||
public static readonly StringComparison COMPARISON = OperatingSystem.IsWindows() ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
|
||||
|
||||
/// <summary>
|
||||
/// The comparer matching COMPARISON, for path-keyed lookups.
|
||||
/// </summary>
|
||||
public static readonly StringComparer COMPARER = OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a path lies below the given directory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The directory itself does not count as lying below itself. A path which cannot be resolved
|
||||
/// counts as lying elsewhere.
|
||||
/// </remarks>
|
||||
/// <param name="directory">The directory.</param>
|
||||
/// <param name="path">The path to check.</param>
|
||||
/// <returns>Whether the path lies below the directory.</returns>
|
||||
public static bool IsInsideDirectory(string directory, string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fullDirectory = Path.GetFullPath(directory);
|
||||
var directoryPrefix = fullDirectory.EndsWith(Path.DirectorySeparatorChar)
|
||||
? fullDirectory
|
||||
: fullDirectory + Path.DirectorySeparatorChar;
|
||||
|
||||
return Path.GetFullPath(path).StartsWith(directoryPrefix, COMPARISON);
|
||||
}
|
||||
catch (Exception exception) when (exception is ArgumentException or NotSupportedException or PathTooLongException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user