Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetImmediateLinkTarget()

static unsafe string System.IO.FileSystem.GetImmediateLinkTarget ( string linkPath,
bool isDirectory,
bool throwOnError,
bool returnFullPath )
inlinestaticpackage

Definition at line 594 of file FileSystem.cs.

595 {
597 {
598 if (safeFileHandle.IsInvalid)
599 {
600 if (!throwOnError)
601 {
602 return null;
603 }
604 int num = Marshal.GetLastWin32Error();
605 if (isDirectory && num == 2)
606 {
607 num = 3;
608 }
609 throw Win32Marshal.GetExceptionForWin32Error(num, linkPath);
610 }
611 byte[] array = ArrayPool<byte>.Shared.Rent(16384);
612 try
613 {
614 if (!Interop.Kernel32.DeviceIoControl(safeFileHandle, 589992u, IntPtr.Zero, 0u, array, 16384u, out var _, IntPtr.Zero))
615 {
616 if (!throwOnError)
617 {
618 return null;
619 }
621 if (lastWin32Error == 4390)
622 {
623 return null;
624 }
625 throw Win32Marshal.GetExceptionForWin32Error(lastWin32Error, linkPath);
626 }
629 if (value.ReparseTag == 2684354572u)
630 {
632 int substituteNameLength = value.SubstituteNameLength;
633 Span<char> span2 = MemoryMarshal.Cast<byte, char>(span.Slice(start, substituteNameLength));
634 if ((value.Flags & 1) == 0)
635 {
636 if (span2.StartsWith("\\??\\UNC\\".AsSpan()))
637 {
638 return Path.Join("\\\\".AsSpan(), span2.Slice("\\??\\UNC\\".Length));
639 }
641 }
642 if (returnFullPath)
643 {
644 return Path.Join(Path.GetDirectoryName(linkPath.AsSpan()), span2);
645 }
646 return span2.ToString();
647 }
648 if (value.ReparseTag == 2684354563u)
649 {
651 int start2 = sizeof(Interop.Kernel32.MountPointReparseBuffer) + value2.SubstituteNameOffset;
652 int substituteNameLength2 = value2.SubstituteNameLength;
655 }
656 return null;
657 }
658 finally
659 {
660 ArrayPool<byte>.Shared.Return(array);
661 }
662 }
664 {
665 return targetPath.Slice("\\??\\".Length).ToString();
666 }
667 }
static bool DeviceIoControl(SafeHandle hDevice, uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, byte[] lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned, IntPtr lpOverlapped)
static unsafe SafeFileHandle OpenSafeFileHandle(string path, int flags)

References System.array, Interop.Kernel32.DeviceIoControl(), System.IO.Path.GetDirectoryName(), System.IO.Win32Marshal.GetExceptionForWin32Error(), System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.IO.Path.Join(), System.IO.FileSystem.OpenSafeFileHandle(), System.start, Interop.Kernel32.SymbolicLinkReparseBuffer.SubstituteNameOffset, System.value, and System.IntPtr.Zero.

Referenced by System.IO.FileSystem.GetFinalLinkTarget(), System.IO.FileSystem.GetLinkTarget(), and System.IO.FileSystem.ResolveLinkTarget().