Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DriveInfoInternal.cs
Go to the documentation of this file.
1
namespace
System.IO
;
2
3
internal
static
class
DriveInfoInternal
4
{
5
public
static
string
[]
GetLogicalDrives
()
6
{
7
int
logicalDrives = global::Interop.Kernel32.GetLogicalDrives();
8
if
(logicalDrives == 0)
9
{
10
throw
System
.
IO
.
Win32Marshal
.
GetExceptionForLastWin32Error
();
11
}
12
uint num = (uint)logicalDrives;
13
int
num2 = 0;
14
while
(num != 0)
15
{
16
if
((num & (
true
? 1u : 0u)) != 0)
17
{
18
num2++;
19
}
20
num >>= 1;
21
}
22
string
[]
array
=
new
string
[num2];
23
Span<char>
span = stackalloc
char
[3] {
'A'
,
':'
,
'\\'
};
24
num = (uint)logicalDrives;
25
num2 = 0;
26
while
(num != 0)
27
{
28
if
((num & (
true
? 1u : 0u)) != 0)
29
{
30
array
[num2++] = span.
ToString
();
31
}
32
num >>= 1;
33
span[0] +=
'\u0001'
;
34
}
35
return
array
;
36
}
37
38
public
static
string
NormalizeDriveName
(
string
driveName)
39
{
40
string
text
;
41
if
(driveName.Length == 1)
42
{
43
text
= driveName +
":\\"
;
44
}
45
else
46
{
47
text
=
Path
.
GetPathRoot
(driveName);
48
if
(
string
.IsNullOrEmpty(
text
) ||
text
.StartsWith(
"\\\\"
,
StringComparison
.Ordinal))
49
{
50
throw
new
ArgumentException
(
System
.
SR
.
Arg_MustBeDriveLetterOrRootDir
,
"driveName"
);
51
}
52
}
53
if
(
text
.Length == 2 &&
text
[1] ==
':'
)
54
{
55
text
+=
"\\"
;
56
}
57
char
c = driveName[0];
58
if
((c <
'A'
|| c >
'Z'
) && (c <
'a'
|| c >
'z'
))
59
{
60
throw
new
ArgumentException
(
System
.
SR
.
Arg_MustBeDriveLetterOrRootDir
,
"driveName"
);
61
}
62
return
text
;
63
}
64
}
System.ArgumentException
Definition
ArgumentException.cs:9
System.IO.DriveInfoInternal.GetLogicalDrives
static string[] GetLogicalDrives()
Definition
DriveInfoInternal.cs:5
System.IO.DriveInfoInternal.NormalizeDriveName
static string NormalizeDriveName(string driveName)
Definition
DriveInfoInternal.cs:38
System.IO.DriveInfoInternal
Definition
DriveInfoInternal.cs:4
System.IO.Path.GetPathRoot
static ? string GetPathRoot(string? path)
Definition
Path.cs:1008
System.IO.Path
Definition
Path.cs:8
System.IO.Win32Marshal.GetExceptionForLastWin32Error
static Exception GetExceptionForLastWin32Error(string path="")
Definition
Win32Marshal.cs:7
System.IO.Win32Marshal
Definition
Win32Marshal.cs:4
System.SR.Arg_MustBeDriveLetterOrRootDir
static string Arg_MustBeDriveLetterOrRootDir
Definition
SR.cs:14
System.SR
Definition
SR.cs:7
System.IO
Definition
ConsoleStream.cs:3
System.ExceptionArgument.text
@ text
System.ExceptionArgument.array
@ array
System.StringComparison
StringComparison
Definition
StringComparison.cs:4
System
Definition
BlockingCollection.cs:8
System.Span.ToString
override string ToString()
Definition
Span.cs:261
System.Span
Definition
Span.cs:14
source
System.IO.FileSystem.DriveInfo
System.IO
DriveInfoInternal.cs
Generated by
1.10.0