/
CosmosDriveInfo.cs
115 lines (93 loc) · 3.83 KB
/
CosmosDriveInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//#define COSMOSDEBUG
using Cosmos.System;
using Cosmos.System.FileSystem;
using Cosmos.System.FileSystem.VFS;
using IL2CPU.API.Attribs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cosmos.System_Plugs.System.IO
{
[Plug(Target = typeof(DriveInfo))]
public static class DriveInfoImpl
{
public static string NormalizeDriveName(string driveName)
{
string name;
if (driveName.Length == 1)
name = driveName + ":\\";
else
{
name = Path.GetPathRoot(driveName);
// Disallow null or empty drive letters and UNC paths
if (name == null || name.Length == 0 || name.StartsWith("\\\\", StringComparison.Ordinal))
throw new ArgumentException("Argument must be drive identifier or root dir");
}
// We want to normalize to have a trailing backslash so we don't have two equivalent forms and
// because some Win32 API don't work without it.
if (name.Length == 2 && name[1] == ':')
{
name = name + "\\";
}
if (!VFSManager.IsValidDriveId(name))
{
throw new ArgumentException("Argument must be drive identifier or root dir");
}
return name;
}
public static long get_AvailableFreeSpace(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting Available Free Space of {aThis.Name}");
return VFSManager.GetAvailableFreeSpace(aThis.Name);
}
public static long get_TotalFreeSpace(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting Total Free Space of {aThis.Name}");
return VFSManager.GetTotalFreeSpace(aThis.Name);
}
public static long get_TotalSize(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting size of {aThis.Name}");
return VFSManager.GetTotalSize(aThis.Name);
}
public static string get_DriveFormat(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting format of {aThis.Name}");
return VFSManager.GetFileSystemType(aThis.Name);
}
public static string get_VolumeLabel(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting label of {aThis.Name}");
return VFSManager.GetFileSystemLabel(aThis.Name);
}
public static void set_VolumeLabel(DriveInfo aThis, string aLabel)
{
Global.mFileSystemDebugger.SendInternal($"Setting label of {aThis.Name} with {aLabel}");
VFSManager.SetFileSystemLabel(aThis.Name, aLabel);
}
/* For now I'm forcing IsReady to be always true as only fixed drives are supported in Cosmos for now */
public static bool get_IsReady(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting isReady status of {aThis.Name}");
return true;
}
/* For now I'm forcing DriveType to always be 'Fixed' as only fixed drives are supported in Cosmos for now */
public static DriveType get_DriveType(DriveInfo aThis)
{
Global.mFileSystemDebugger.SendInternal($"Getting DriveType of {aThis.Name}");
return DriveType.Fixed;
}
public static DriveInfo[] GetDrives()
{
Global.mFileSystemDebugger.SendInternal("GetDrives called");
List<string> drives = VFSManager.GetLogicalDrives();
DriveInfo[] result = new DriveInfo[drives.Count];
for (int i = 0; i < drives.Count; i++)
{
result[i] = new DriveInfo(drives[i]);
}
return result;
}
}
}