diff --git a/Filesystem/Directory.cs b/Filesystem/Directory.cs index caa6e3d..1358d76 100644 --- a/Filesystem/Directory.cs +++ b/Filesystem/Directory.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace DTLib.Filesystem { @@ -134,5 +135,11 @@ namespace DTLib.Filesystem System.Security.AccessControl.AccessControlType.Allow)); dirInfo.SetAccessControl(dirSecurity); } + + public static void CreateSymlink(string symlinkName, string sourceName) + { + if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.Directory)) + throw new InvalidOperationException($"some error occured while creating symlink\nCreateSymlink({symlinkName}, {sourceName})"); + } } } diff --git a/Filesystem/File.cs b/Filesystem/File.cs index 4f14439..88f02e5 100644 --- a/Filesystem/File.cs +++ b/Filesystem/File.cs @@ -74,5 +74,11 @@ namespace DTLib.Filesystem File.Create(file); return System.IO.File.Open(file, System.IO.FileMode.Append); } + + public static void CreateSymlink(string symlinkName, string sourceName) + { + if (!Symlink.CreateSymbolicLink(symlinkName, sourceName, Symlink.SymlinkTarget.File)) + throw new InvalidOperationException($"some error occured while creating symlink\nCreateSymlink({symlinkName}, {sourceName})"); + } } } diff --git a/Filesystem/OldFilework.cs b/Filesystem/OldFilework.cs index 5fb26eb..aab83fe 100644 --- a/Filesystem/OldFilework.cs +++ b/Filesystem/OldFilework.cs @@ -8,13 +8,13 @@ namespace DTLib.Filesystem public static class OldFilework { // записывает текст в файл и закрывает файл - public static void LogToFile(string logfile, string msg) + /*public static void LogToFile(string logfile, string msg) { lock (new object()) { File.AppendAllText(logfile, msg); } - } + }*/ // чтение параметров из конфига public static string ReadFromConfig(string configfile, string key) diff --git a/Filesystem/Symlink.cs b/Filesystem/Symlink.cs new file mode 100644 index 0000000..66e8a5c --- /dev/null +++ b/Filesystem/Symlink.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DTLib.Filesystem +{ + internal class Symlink + { + [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] + static internal extern bool CreateSymbolicLink(string symlinkName, string sourceName, SymlinkTarget type); + + internal enum SymlinkTarget + { + File, + Directory + } + } +}