From bb55c69108988ba5015b833753f6780a6a5abde6 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Wed, 5 Apr 2023 03:33:35 +0600 Subject: [PATCH] Filesystem bugfixes --- DTLib.Dtsod/DTLib.Dtsod.csproj | 4 ++-- DTLib.Logging/DTLib.Logging.csproj | 4 ++-- DTLib.Network/DTLib.Network.csproj | 2 +- DTLib.Tests/DTLib.Tests.csproj | 2 +- DTLib/DTLib.csproj | 2 +- DTLib/Filesystem/Directory.cs | 9 +++++---- DTLib/Filesystem/File.cs | 1 + DTLib/Filesystem/IOPath.cs | 19 ++++++++++++------- 8 files changed, 25 insertions(+), 18 deletions(-) diff --git a/DTLib.Dtsod/DTLib.Dtsod.csproj b/DTLib.Dtsod/DTLib.Dtsod.csproj index a0d6cf3..a17a3c1 100644 --- a/DTLib.Dtsod/DTLib.Dtsod.csproj +++ b/DTLib.Dtsod/DTLib.Dtsod.csproj @@ -2,7 +2,7 @@ DTLib.Dtsod - 1.2.0 + 1.2.1 Timerix Definitely not json GIT @@ -33,7 +33,7 @@ - + diff --git a/DTLib.Logging/DTLib.Logging.csproj b/DTLib.Logging/DTLib.Logging.csproj index f0a5899..b6da5e6 100644 --- a/DTLib.Logging/DTLib.Logging.csproj +++ b/DTLib.Logging/DTLib.Logging.csproj @@ -2,7 +2,7 @@ DTLib.Logging - 1.2.0 + 1.2.1 Timerix Loggers with dependency injection GIT @@ -30,7 +30,7 @@ - + diff --git a/DTLib.Network/DTLib.Network.csproj b/DTLib.Network/DTLib.Network.csproj index 6d0b35e..2c64878 100644 --- a/DTLib.Network/DTLib.Network.csproj +++ b/DTLib.Network/DTLib.Network.csproj @@ -2,7 +2,7 @@ DTLib.Network - 1.2.0 + 1.2.1 Timerix Some sick network protocols GIT diff --git a/DTLib.Tests/DTLib.Tests.csproj b/DTLib.Tests/DTLib.Tests.csproj index 496b10c..e8670b7 100644 --- a/DTLib.Tests/DTLib.Tests.csproj +++ b/DTLib.Tests/DTLib.Tests.csproj @@ -27,7 +27,7 @@ - + diff --git a/DTLib/DTLib.csproj b/DTLib/DTLib.csproj index c81ab69..f143e0f 100644 --- a/DTLib/DTLib.csproj +++ b/DTLib/DTLib.csproj @@ -2,7 +2,7 @@ DTLib - 1.2.1 + 1.2.2 Timerix Library for all my C# projects GIT diff --git a/DTLib/Filesystem/Directory.cs b/DTLib/Filesystem/Directory.cs index 1c5cdb2..d730eaa 100644 --- a/DTLib/Filesystem/Directory.cs +++ b/DTLib/Filesystem/Directory.cs @@ -54,6 +54,7 @@ public static class Directory Delete(target_path); else throw new Exception($"directory {target_path} already exists"); } + else Directory.Create(target_path.ParentDir()); System.IO.Directory.Move(current_path.Str, target_path.Str); } @@ -62,16 +63,16 @@ public static class Directory System.IO.Directory.Delete(dir.Str, true); public static IOPath[] GetFiles(IOPath dir) => - IOPath.ArrayCast(System.IO.Directory.GetFiles(dir.Str)); + IOPath.ArrayCast(System.IO.Directory.GetFiles(dir.Str), true); public static IOPath[] GetFiles(IOPath dir, string searchPattern) => - IOPath.ArrayCast(System.IO.Directory.GetFiles(dir.Str, searchPattern)); + IOPath.ArrayCast(System.IO.Directory.GetFiles(dir.Str, searchPattern), true); public static IOPath[] GetDirectories(IOPath dir) => - IOPath.ArrayCast(System.IO.Directory.GetDirectories(dir.Str)); + IOPath.ArrayCast(System.IO.Directory.GetDirectories(dir.Str), true); public static IOPath[] GetDirectories(IOPath dir, string searchPattern) => - IOPath.ArrayCast(System.IO.Directory.GetDirectories(dir.Str, searchPattern)); + IOPath.ArrayCast(System.IO.Directory.GetDirectories(dir.Str, searchPattern), true); /// выдает список всех файлов public static List GetAllFiles(IOPath dir) diff --git a/DTLib/Filesystem/File.cs b/DTLib/Filesystem/File.cs index 04f7953..cb1c97c 100644 --- a/DTLib/Filesystem/File.cs +++ b/DTLib/Filesystem/File.cs @@ -45,6 +45,7 @@ public static class File Delete(target_path); else throw new Exception($"file {target_path} already exists"); } + else Directory.Create(target_path.ParentDir()); System.IO.File.Move(current_path.Str, target_path.Str); } diff --git a/DTLib/Filesystem/IOPath.cs b/DTLib/Filesystem/IOPath.cs index 421a6d1..8aae5fa 100644 --- a/DTLib/Filesystem/IOPath.cs +++ b/DTLib/Filesystem/IOPath.cs @@ -40,18 +40,18 @@ public readonly struct IOPath return new string(fixed_path); } - public static IOPath[] ArrayCast(string[] a) + public static IOPath[] ArrayCast(string[] a, bool correct_separators=false) { IOPath[] b = new IOPath[a.Length]; - for (int i = 0; i < a.Length; i++) - b[i] = (IOPath)a[i]; + for (int i = 0; i < a.Length; i++) + b[i] = new IOPath(a[i], correct_separators); return b; } - public static IOPath[] ListCast(IList a) + public static IOPath[] ListCast(IList a, bool correct_separators=false) { IOPath[] b = new IOPath[a.Count]; - for (int i = 0; i < a.Count; i++) - b[i] = (IOPath)a[i]; + for (int i = 0; i < a.Count; i++) + b[i] = new IOPath(a[i], correct_separators); return b; } @@ -62,7 +62,12 @@ public readonly struct IOPath public static implicit operator IOPath(string s) => new(s); public static explicit operator string(IOPath p) => p.Str; public override string ToString() => Str; - public override bool Equals(object obj) => Str.Equals(obj); + + public override bool Equals(object obj) + { + if (obj is null) return false; + return Str == obj.ToString(); + } public override int GetHashCode() => Str.GetHashCode(); public char this[int i] => Str[i];