Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Win32Marshal.cs
Go to the documentation of this file.
2
3namespace System.IO;
4
5internal static class Win32Marshal
6{
7 internal static Exception GetExceptionForLastWin32Error(string path = "")
8 {
10 }
11
12 internal static Exception GetExceptionForWin32Error(int errorCode, string path = "")
13 {
14 switch (errorCode)
15 {
16 case 2:
17 return new FileNotFoundException(string.IsNullOrEmpty(path) ? SR.IO_FileNotFound : SR.Format(SR.IO_FileNotFound_FileName, path), path);
18 case 3:
19 return new DirectoryNotFoundException(string.IsNullOrEmpty(path) ? SR.IO_PathNotFound_NoPathName : SR.Format(SR.IO_PathNotFound_Path, path));
20 case 5:
22 case 183:
23 if (!string.IsNullOrEmpty(path))
24 {
25 return new IOException(SR.Format(SR.IO_AlreadyExists_Name, path), MakeHRFromErrorCode(errorCode));
26 }
27 break;
28 case 206:
29 return new PathTooLongException(string.IsNullOrEmpty(path) ? SR.IO_PathTooLong : SR.Format(SR.IO_PathTooLong_Path, path));
30 case 32:
31 return new IOException(string.IsNullOrEmpty(path) ? SR.IO_SharingViolation_NoFileName : SR.Format(SR.IO_SharingViolation_File, path), MakeHRFromErrorCode(errorCode));
32 case 80:
33 if (!string.IsNullOrEmpty(path))
34 {
35 return new IOException(SR.Format(SR.IO_FileExists_Name, path), MakeHRFromErrorCode(errorCode));
36 }
37 break;
38 case 995:
39 return new OperationCanceledException();
40 }
41 return new IOException(string.IsNullOrEmpty(path) ? GetMessage(errorCode) : (GetMessage(errorCode) + " : '" + path + "'"), MakeHRFromErrorCode(errorCode));
42 }
43
44 internal static int MakeHRFromErrorCode(int errorCode)
45 {
46 if ((0xFFFF0000u & errorCode) != 0L)
47 {
48 return errorCode;
49 }
50 return -2147024896 | errorCode;
51 }
52
53 internal static string GetMessage(int errorCode)
54 {
55 return Interop.Kernel32.GetMessage(errorCode);
56 }
57}
static string GetMessage(int errorCode)
Definition Interop.cs:113
static int MakeHRFromErrorCode(int errorCode)
static Exception GetExceptionForLastWin32Error(string path="")
static string GetMessage(int errorCode)
static Exception GetExceptionForWin32Error(int errorCode, string path="")
static string IO_FileExists_Name
Definition SR.cs:36
static string IO_PathTooLong
Definition SR.cs:46
static string IO_AlreadyExists_Name
Definition SR.cs:34
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string IO_SharingViolation_File
Definition SR.cs:52
static string UnauthorizedAccess_IODenied_Path
Definition SR.cs:50
static string IO_SharingViolation_NoFileName
Definition SR.cs:54
static string IO_PathNotFound_NoPathName
Definition SR.cs:42
static string IO_FileNotFound
Definition SR.cs:38
static string IO_FileNotFound_FileName
Definition SR.cs:40
static string IO_PathTooLong_Path
Definition SR.cs:94
static string IO_PathNotFound_Path
Definition SR.cs:44
static string UnauthorizedAccess_IODenied_NoPathName
Definition SR.cs:48
Definition SR.cs:7