390 lines
14 KiB
C#
390 lines
14 KiB
C#
using System;
|
|
using System.IO.IsolatedStorage;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.IO
|
|
{
|
|
// Token: 0x020001C1 RID: 449
|
|
internal sealed class MonoIO
|
|
{
|
|
// Token: 0x06001715 RID: 5909 RVA: 0x00058FA0 File Offset: 0x000571A0
|
|
public static Exception GetException(MonoIOError error)
|
|
{
|
|
if (error == MonoIOError.ERROR_ACCESS_DENIED)
|
|
{
|
|
return new UnauthorizedAccessException("Access to the path is denied.");
|
|
}
|
|
if (error != MonoIOError.ERROR_FILE_EXISTS)
|
|
{
|
|
return MonoIO.GetException(string.Empty, error);
|
|
}
|
|
string text = "Cannot create a file that already exist.";
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
|
|
// Token: 0x06001716 RID: 5910 RVA: 0x00058FF0 File Offset: 0x000571F0
|
|
public static Exception GetException(string path, MonoIOError error)
|
|
{
|
|
switch (error)
|
|
{
|
|
case MonoIOError.ERROR_FILE_NOT_FOUND:
|
|
{
|
|
string text = string.Format("Could not find file \"{0}\"", path);
|
|
return new IsolatedStorageException(text);
|
|
}
|
|
case MonoIOError.ERROR_PATH_NOT_FOUND:
|
|
{
|
|
string text = string.Format("Could not find a part of the path \"{0}\"", path);
|
|
return new IsolatedStorageException(text);
|
|
}
|
|
case MonoIOError.ERROR_TOO_MANY_OPEN_FILES:
|
|
return new IOException("Too many open files", (int)((MonoIOError)(-2147024896) | error));
|
|
case MonoIOError.ERROR_ACCESS_DENIED:
|
|
{
|
|
string text = string.Format("Access to the path \"{0}\" is denied.", path);
|
|
return new UnauthorizedAccessException(text);
|
|
}
|
|
case MonoIOError.ERROR_INVALID_HANDLE:
|
|
{
|
|
string text = string.Format("Invalid handle to path \"{0}\"", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
default:
|
|
switch (error)
|
|
{
|
|
case MonoIOError.ERROR_WRITE_FAULT:
|
|
{
|
|
string text = string.Format("Write fault on path {0}", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
default:
|
|
switch (error)
|
|
{
|
|
case MonoIOError.ERROR_INVALID_DRIVE:
|
|
{
|
|
string text = string.Format("Could not find the drive '{0}'. The drive might not be ready or might not be mapped.", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
default:
|
|
switch (error)
|
|
{
|
|
case MonoIOError.ERROR_FILE_EXISTS:
|
|
{
|
|
string text = string.Format("Could not create file \"{0}\". File already exists.", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
default:
|
|
if (error == MonoIOError.ERROR_HANDLE_DISK_FULL)
|
|
{
|
|
string text = string.Format("Disk full. Path {0}", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
if (error == MonoIOError.ERROR_INVALID_PARAMETER)
|
|
{
|
|
string text = string.Format("Invalid parameter", new object[0]);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
if (error == MonoIOError.ERROR_DIR_NOT_EMPTY)
|
|
{
|
|
string text = string.Format("Directory {0} is not empty", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
if (error == MonoIOError.ERROR_FILENAME_EXCED_RANGE)
|
|
{
|
|
string text = string.Format("Path is too long. Path: {0}", path);
|
|
return new PathTooLongException(text);
|
|
}
|
|
if (error != MonoIOError.ERROR_ENCRYPTION_FAILED)
|
|
{
|
|
string text = string.Format("Win32 IO returned {0}. Path: {1}", error, path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
return new IOException("Encryption failed", (int)((MonoIOError)(-2147024896) | error));
|
|
case MonoIOError.ERROR_CANNOT_MAKE:
|
|
{
|
|
string text = string.Format("Path {0} is a directory", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
}
|
|
break;
|
|
case MonoIOError.ERROR_NOT_SAME_DEVICE:
|
|
{
|
|
string text = "Source and destination are not on the same device";
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
}
|
|
break;
|
|
case MonoIOError.ERROR_SHARING_VIOLATION:
|
|
{
|
|
string text = string.Format("Sharing violation on path {0}", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
case MonoIOError.ERROR_LOCK_VIOLATION:
|
|
{
|
|
string text = string.Format("Lock violation on path {0}", path);
|
|
return new IOException(text, (int)((MonoIOError)(-2147024896) | error));
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001717 RID: 5911
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool CreateDirectory(string path, out MonoIOError error);
|
|
|
|
// Token: 0x06001718 RID: 5912
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool RemoveDirectory(string path, out MonoIOError error);
|
|
|
|
// Token: 0x06001719 RID: 5913
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern string[] GetFileSystemEntries(string path, string path_with_pattern, int attrs, int mask, out MonoIOError error);
|
|
|
|
// Token: 0x0600171A RID: 5914
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern string GetCurrentDirectory(out MonoIOError error);
|
|
|
|
// Token: 0x0600171B RID: 5915
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool SetCurrentDirectory(string path, out MonoIOError error);
|
|
|
|
// Token: 0x0600171C RID: 5916
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool MoveFile(string path, string dest, out MonoIOError error);
|
|
|
|
// Token: 0x0600171D RID: 5917
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool CopyFile(string path, string dest, bool overwrite, out MonoIOError error);
|
|
|
|
// Token: 0x0600171E RID: 5918
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool DeleteFile(string path, out MonoIOError error);
|
|
|
|
// Token: 0x0600171F RID: 5919
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool ReplaceFile(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors, out MonoIOError error);
|
|
|
|
// Token: 0x06001720 RID: 5920
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern FileAttributes GetFileAttributes(string path, out MonoIOError error);
|
|
|
|
// Token: 0x06001721 RID: 5921
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool SetFileAttributes(string path, FileAttributes attrs, out MonoIOError error);
|
|
|
|
// Token: 0x06001722 RID: 5922
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern MonoFileType GetFileType(IntPtr handle, out MonoIOError error);
|
|
|
|
// Token: 0x06001723 RID: 5923 RVA: 0x00059244 File Offset: 0x00057444
|
|
public static bool Exists(string path, out MonoIOError error)
|
|
{
|
|
FileAttributes fileAttributes = MonoIO.GetFileAttributes(path, out error);
|
|
return fileAttributes != MonoIO.InvalidFileAttributes;
|
|
}
|
|
|
|
// Token: 0x06001724 RID: 5924 RVA: 0x00059268 File Offset: 0x00057468
|
|
public static bool ExistsFile(string path, out MonoIOError error)
|
|
{
|
|
FileAttributes fileAttributes = MonoIO.GetFileAttributes(path, out error);
|
|
return fileAttributes != MonoIO.InvalidFileAttributes && (fileAttributes & FileAttributes.Directory) == (FileAttributes)0;
|
|
}
|
|
|
|
// Token: 0x06001725 RID: 5925 RVA: 0x00059298 File Offset: 0x00057498
|
|
public static bool ExistsDirectory(string path, out MonoIOError error)
|
|
{
|
|
FileAttributes fileAttributes = MonoIO.GetFileAttributes(path, out error);
|
|
if (error == MonoIOError.ERROR_FILE_NOT_FOUND)
|
|
{
|
|
error = MonoIOError.ERROR_PATH_NOT_FOUND;
|
|
}
|
|
return fileAttributes != MonoIO.InvalidFileAttributes && (fileAttributes & FileAttributes.Directory) != (FileAttributes)0;
|
|
}
|
|
|
|
// Token: 0x06001726 RID: 5926 RVA: 0x000592D4 File Offset: 0x000574D4
|
|
public static bool ExistsSymlink(string path, out MonoIOError error)
|
|
{
|
|
FileAttributes fileAttributes = MonoIO.GetFileAttributes(path, out error);
|
|
return fileAttributes != MonoIO.InvalidFileAttributes && (fileAttributes & FileAttributes.ReparsePoint) != (FileAttributes)0;
|
|
}
|
|
|
|
// Token: 0x06001727 RID: 5927
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool GetFileStat(string path, out MonoIOStat stat, out MonoIOError error);
|
|
|
|
// Token: 0x06001728 RID: 5928
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern IntPtr Open(string filename, FileMode mode, FileAccess access, FileShare share, FileOptions options, out MonoIOError error);
|
|
|
|
// Token: 0x06001729 RID: 5929
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool Close(IntPtr handle, out MonoIOError error);
|
|
|
|
// Token: 0x0600172A RID: 5930
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern int Read(IntPtr handle, byte[] dest, int dest_offset, int count, out MonoIOError error);
|
|
|
|
// Token: 0x0600172B RID: 5931
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern int Write(IntPtr handle, [In] byte[] src, int src_offset, int count, out MonoIOError error);
|
|
|
|
// Token: 0x0600172C RID: 5932
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern long Seek(IntPtr handle, long offset, SeekOrigin origin, out MonoIOError error);
|
|
|
|
// Token: 0x0600172D RID: 5933
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool Flush(IntPtr handle, out MonoIOError error);
|
|
|
|
// Token: 0x0600172E RID: 5934
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern long GetLength(IntPtr handle, out MonoIOError error);
|
|
|
|
// Token: 0x0600172F RID: 5935
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool SetLength(IntPtr handle, long length, out MonoIOError error);
|
|
|
|
// Token: 0x06001730 RID: 5936
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool SetFileTime(IntPtr handle, long creation_time, long last_access_time, long last_write_time, out MonoIOError error);
|
|
|
|
// Token: 0x06001731 RID: 5937 RVA: 0x00059308 File Offset: 0x00057508
|
|
public static bool SetFileTime(string path, long creation_time, long last_access_time, long last_write_time, out MonoIOError error)
|
|
{
|
|
return MonoIO.SetFileTime(path, 0, creation_time, last_access_time, last_write_time, DateTime.MinValue, out error);
|
|
}
|
|
|
|
// Token: 0x06001732 RID: 5938 RVA: 0x0005931C File Offset: 0x0005751C
|
|
public static bool SetCreationTime(string path, DateTime dateTime, out MonoIOError error)
|
|
{
|
|
return MonoIO.SetFileTime(path, 1, -1L, -1L, -1L, dateTime, out error);
|
|
}
|
|
|
|
// Token: 0x06001733 RID: 5939 RVA: 0x00059330 File Offset: 0x00057530
|
|
public static bool SetLastAccessTime(string path, DateTime dateTime, out MonoIOError error)
|
|
{
|
|
return MonoIO.SetFileTime(path, 2, -1L, -1L, -1L, dateTime, out error);
|
|
}
|
|
|
|
// Token: 0x06001734 RID: 5940 RVA: 0x00059344 File Offset: 0x00057544
|
|
public static bool SetLastWriteTime(string path, DateTime dateTime, out MonoIOError error)
|
|
{
|
|
return MonoIO.SetFileTime(path, 3, -1L, -1L, -1L, dateTime, out error);
|
|
}
|
|
|
|
// Token: 0x06001735 RID: 5941 RVA: 0x00059358 File Offset: 0x00057558
|
|
public static bool SetFileTime(string path, int type, long creation_time, long last_access_time, long last_write_time, DateTime dateTime, out MonoIOError error)
|
|
{
|
|
IntPtr intPtr = MonoIO.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, FileOptions.None, out error);
|
|
if (intPtr == MonoIO.InvalidHandle)
|
|
{
|
|
return false;
|
|
}
|
|
switch (type)
|
|
{
|
|
case 1:
|
|
creation_time = dateTime.ToFileTime();
|
|
break;
|
|
case 2:
|
|
last_access_time = dateTime.ToFileTime();
|
|
break;
|
|
case 3:
|
|
last_write_time = dateTime.ToFileTime();
|
|
break;
|
|
}
|
|
bool flag = MonoIO.SetFileTime(intPtr, creation_time, last_access_time, last_write_time, out error);
|
|
MonoIOError monoIOError;
|
|
MonoIO.Close(intPtr, out monoIOError);
|
|
return flag;
|
|
}
|
|
|
|
// Token: 0x06001736 RID: 5942
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern void Lock(IntPtr handle, long position, long length, out MonoIOError error);
|
|
|
|
// Token: 0x06001737 RID: 5943
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern void Unlock(IntPtr handle, long position, long length, out MonoIOError error);
|
|
|
|
// Token: 0x17000418 RID: 1048
|
|
// (get) Token: 0x06001738 RID: 5944
|
|
public static extern IntPtr ConsoleOutput
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x17000419 RID: 1049
|
|
// (get) Token: 0x06001739 RID: 5945
|
|
public static extern IntPtr ConsoleInput
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x1700041A RID: 1050
|
|
// (get) Token: 0x0600173A RID: 5946
|
|
public static extern IntPtr ConsoleError
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x0600173B RID: 5947
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool CreatePipe(out IntPtr read_handle, out IntPtr write_handle);
|
|
|
|
// Token: 0x0600173C RID: 5948
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool DuplicateHandle(IntPtr source_process_handle, IntPtr source_handle, IntPtr target_process_handle, out IntPtr target_handle, int access, int inherit, int options);
|
|
|
|
// Token: 0x1700041B RID: 1051
|
|
// (get) Token: 0x0600173D RID: 5949
|
|
public static extern char VolumeSeparatorChar
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x1700041C RID: 1052
|
|
// (get) Token: 0x0600173E RID: 5950
|
|
public static extern char DirectorySeparatorChar
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x1700041D RID: 1053
|
|
// (get) Token: 0x0600173F RID: 5951
|
|
public static extern char AltDirectorySeparatorChar
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x1700041E RID: 1054
|
|
// (get) Token: 0x06001740 RID: 5952
|
|
public static extern char PathSeparator
|
|
{
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
get;
|
|
}
|
|
|
|
// Token: 0x06001741 RID: 5953
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern int GetTempPath(out string path);
|
|
|
|
// Token: 0x06001742 RID: 5954
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
public static extern bool RemapPath(string path, out string newPath);
|
|
|
|
// Token: 0x040006BD RID: 1725
|
|
public static readonly FileAttributes InvalidFileAttributes = (FileAttributes)(-1);
|
|
|
|
// Token: 0x040006BE RID: 1726
|
|
public static readonly IntPtr InvalidHandle = (IntPtr)(-1L);
|
|
}
|
|
}
|