Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FileSystem.cs
Go to the documentation of this file.
4
5namespace System.IO;
6
7internal static class FileSystem
8{
9 public static bool DirectoryExists(string fullPath)
10 {
11 int lastError;
13 }
14
15 private static bool DirectoryExists(string path, out int lastError)
16 {
17 global::Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default(global::Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA);
19 if (lastError == 0 && data.dwFileAttributes != -1)
20 {
21 return (data.dwFileAttributes & 0x10) != 0;
22 }
23 return false;
24 }
25
26 public static bool FileExists(string fullPath)
27 {
28 global::Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default(global::Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA);
29 if (FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: true) == 0 && data.dwFileAttributes != -1)
30 {
31 return (data.dwFileAttributes & 0x10) == 0;
32 }
33 return false;
34 }
35
36 internal static int FillAttributeInfo(string path, ref global::Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound)
37 {
38 int num = 0;
41 {
42 if (!global::Interop.Kernel32.GetFileAttributesEx(path, global::Interop.Kernel32.GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, ref data))
43 {
45 if (!IsPathUnreachableError(num))
46 {
47 global::Interop.Kernel32.WIN32_FIND_DATA data2 = default(global::Interop.Kernel32.WIN32_FIND_DATA);
48 using Microsoft.Win32.SafeHandles.SafeFindHandle safeFindHandle = global::Interop.Kernel32.FindFirstFile(path, ref data2);
49 if (safeFindHandle.IsInvalid)
50 {
52 }
53 else
54 {
55 num = 0;
56 data.PopulateFrom(ref data2);
57 }
58 }
59 }
60 }
61 if (num != 0 && !returnErrorOnNotFound && ((uint)(num - 2) <= 1u || num == 21))
62 {
63 data.dwFileAttributes = -1;
64 return 0;
65 }
66 return num;
67 }
68
69 internal static bool IsPathUnreachableError(int errorCode)
70 {
71 switch (errorCode)
72 {
73 case 2:
74 case 3:
75 case 6:
76 case 21:
77 case 53:
78 case 65:
79 case 67:
80 case 87:
81 case 123:
82 case 161:
83 case 206:
84 case 1231:
85 return true;
86 default:
87 return false;
88 }
89 }
90
91 public unsafe static void CreateDirectory(string fullPath, byte[] securityDescriptor = null)
92 {
94 {
95 return;
96 }
98 bool flag = false;
99 int num = fullPath.Length;
100 if (num >= 2 && System.IO.PathInternal.EndsInDirectorySeparator(fullPath.AsSpan()))
101 {
102 num--;
103 }
105 if (num > rootLength)
106 {
107 int num2 = num - 1;
108 while (num2 >= rootLength && !flag)
109 {
110 string text = fullPath.Substring(0, num2 + 1);
111 if (!DirectoryExists(text))
112 {
113 list.Add(text);
114 }
115 else
116 {
117 flag = true;
118 }
120 {
121 num2--;
122 }
123 num2--;
124 }
125 }
126 int count = list.Count;
127 bool flag2 = true;
128 int num3 = 0;
129 string path = fullPath;
131 {
132 global::Interop.Kernel32.SECURITY_ATTRIBUTES sECURITY_ATTRIBUTES = default(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
133 sECURITY_ATTRIBUTES.nLength = (uint)sizeof(global::Interop.Kernel32.SECURITY_ATTRIBUTES);
134 sECURITY_ATTRIBUTES.lpSecurityDescriptor = (IntPtr)ptr;
135 global::Interop.Kernel32.SECURITY_ATTRIBUTES lpSecurityAttributes = sECURITY_ATTRIBUTES;
136 while (list.Count > 0)
137 {
138 string text2 = list[list.Count - 1];
139 list.RemoveAt(list.Count - 1);
140 flag2 = global::Interop.Kernel32.CreateDirectory(text2, ref lpSecurityAttributes);
141 if (!flag2 && num3 == 0)
142 {
144 if (lastError != 183)
145 {
146 num3 = lastError;
147 }
148 else if (FileExists(text2) || (!DirectoryExists(text2, out lastError) && lastError == 5))
149 {
150 num3 = lastError;
151 path = text2;
152 }
153 }
154 }
155 }
156 if (count == 0 && !flag)
157 {
160 {
162 }
163 }
164 else if (!flag2 && num3 != 0)
165 {
167 }
168 }
169}
void Add(TKey key, TValue value)
static bool DirectoryExists(string fullPath)
Definition FileSystem.cs:9
static unsafe void CreateDirectory(string fullPath, byte[] securityDescriptor=null)
Definition FileSystem.cs:91
static bool FileExists(string fullPath)
Definition FileSystem.cs:26
static bool DirectoryExists(string path, out int lastError)
Definition FileSystem.cs:15
static int FillAttributeInfo(string path, ref global::Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound)
Definition FileSystem.cs:36
static bool IsPathUnreachableError(int errorCode)
Definition FileSystem.cs:69
static bool EndsInDirectorySeparator(string path)
static int GetRootLength(ReadOnlySpan< char > path)
static string TrimEndingDirectorySeparator(string path)
static bool IsDirectorySeparator(char c)
static ? string GetPathRoot(string? path)
Definition Path.cs:1008
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static System.IO.DisableMediaInsertionPrompt Create()