-
Notifications
You must be signed in to change notification settings - Fork 0
StorageInformation Class
Provides an abstract base for accessing and representing platform-specific information about a file or storage item, including attributes, size, timestamps, and ownership details.
Namespace: Rheo.Storage.Information
Assembly: Rheo.Storage.dll
public abstract class StorageInformation : IStorageInformationObject → StorageInformation
| Constructor | Description |
|---|---|
| StorageInformation(String) | Initializes a new instance of the StorageInformation class for the specified absolute file path. |
| Property | Type | Description |
|---|---|---|
| DisplayName | String | Gets the display name for the storage item. |
| Attributes | FileAttributes | Gets the file attributes of the storage item. |
| IsReadOnly | Boolean | Gets a value indicating whether the storage item is read-only. |
| IsHidden | Boolean | Gets a value indicating whether the storage item is hidden. |
| IsSystem | Boolean | Gets a value indicating whether the storage item is a system file. |
| IsTemporary | Boolean | Gets a value indicating whether the storage item is temporary. |
| Size | Int64 | Gets the size of the storage item in bytes. |
| FormattedSize | String | Gets a human-readable formatted string representing the size. |
| CreationTime | DateTime | Gets the creation time of the storage item. |
| LastWriteTime | DateTime | Gets the last write time of the storage item. |
| LastAccessTime | DateTime | Gets the last access time of the storage item. |
| IsSymbolicLink | Boolean | Gets a value indicating whether the storage item is a symbolic link. |
| LinkTarget | String | Gets the target path of the symbolic link, if applicable. |
| OwnerSid | String | Gets the security identifier (SID) of the owner (Windows only). |
| Icon | Icon | Gets the icon representing the storage item (Windows only). |
| OwnerId | Int32? | Gets the owner user ID (Unix only). |
| GroupId | Int32? | Gets the group ID (Unix only). |
| Mode | Int32? | Gets the file mode/permissions (Unix only). |
| Method | Description |
|---|---|
| GetSizeString(UOM?) | Returns a formatted string representation of the size using the specified unit of measurement. |
| TryGetWindowsStorageInfo(WindowsStorageInfo) | Attempts to retrieve storage information specific to Windows systems. |
| TryGetUnixStorageInfo(UnixStorageInfo) | Attempts to retrieve storage information specific to Unix-based systems. |
This class exposes a unified interface for retrieving storage metadata across different operating systems. It supports properties for common file attributes, symbolic link information, and platform-specific details such as owner identifiers and access modes. Implementations should provide the actual logic for retrieving the file size. Thread safety is ensured for property access. Use derived types to access additional platform-specific features as needed.
Storage information is retrieved asynchronously in the background upon construction to avoid blocking the calling thread.
Initializes a new instance of the StorageInformation class for the specified absolute file path.
public StorageInformation(string absolutePath)absolutePath String
The absolute path to the file or directory for which storage information will be retrieved. Cannot be null, empty, or consist only of white-space characters.
Thrown if absolutePath is null, empty, or consists only of white-space characters.
This constructor begins retrieving platform-specific storage information in the background upon initialization. Accessing storage information properties may block until retrieval is complete.
Gets the display name for the storage item.
public string DisplayName { get; }The display name as provided by Windows Shell, or the file name without extension on other platforms.
Gets the file attributes of the storage item.
public FileAttributes Attributes { get; }The file attributes.
Gets a value indicating whether the storage item is read-only.
public bool IsReadOnly { get; }true if the storage item has the ReadOnly attribute; otherwise, false.
Gets a value indicating whether the storage item is hidden.
public bool IsHidden { get; }true if the storage item has the Hidden attribute; otherwise, false.
Gets a value indicating whether the storage item is a system file.
public bool IsSystem { get; }true if the storage item has the System attribute; otherwise, false.
Gets a value indicating whether the storage item is temporary.
public bool IsTemporary { get; }true if the storage item has the Temporary attribute; otherwise, false.
Gets the size of the storage item in bytes.
public abstract long Size { get; }The size in bytes.
This property must be implemented by derived classes.
Gets a human-readable formatted string representing the size.
public string FormattedSize { get; }A formatted size string (e.g., "1.5 MB", "250 KB").
Gets the creation time of the storage item.
public DateTime CreationTime { get; }The creation timestamp.
Gets the last write time of the storage item.
public DateTime LastWriteTime { get; }The last write timestamp.
Gets the last access time of the storage item.
public DateTime LastAccessTime { get; }The last access timestamp.
Gets a value indicating whether the storage item is a symbolic link.
public bool IsSymbolicLink { get; }true if the item is a symbolic link; otherwise, false.
Gets the target path of the symbolic link, if applicable.
public string? LinkTarget { get; }The target path, or null if not a symbolic link.
Gets the security identifier (SID) of the owner (Windows only).
public string? OwnerSid { get; }The owner SID on Windows, or null on other platforms.
Gets the icon representing the storage item (Windows only).
public Icon? Icon { get; }The icon on Windows, or null on other platforms.
Gets the owner user ID (Unix only).
public int? OwnerId { get; }The owner UID on Unix systems, or null on other platforms.
Gets the group ID (Unix only).
public int? GroupId { get; }The group GID on Unix systems, or null on other platforms.
Gets the file mode/permissions (Unix only).
public int? Mode { get; }The file mode on Unix systems, or null on other platforms.
Returns a formatted string representation of the size using the specified unit of measurement.
public string GetSizeString(UOM? uom = null)uom UOM?
The unit of measurement to use. If null, the appropriate unit is selected automatically.
A formatted size string.
Attempts to retrieve storage information specific to Windows systems.
protected bool TryGetWindowsStorageInfo(out WindowsStorageInfo info)info WindowsStorageInfo
When this method returns, contains a WindowsStorageInfo object with Windows-specific storage details if available; otherwise, the default value.
true if Windows storage information was successfully retrieved; otherwise, false.
This method does not throw exceptions. If the underlying storage information is not compatible with Windows or an error occurs, the method returns false and info is set to its default value.
Attempts to retrieve storage information specific to Unix-based systems.
protected bool TryGetUnixStorageInfo(out UnixStorageInfo info)info UnixStorageInfo
When this method returns, contains a UnixStorageInfo structure with the Unix storage information if available; otherwise, the default value.
true if Unix storage information is available and was retrieved successfully; otherwise, false.
This method does not throw exceptions. If the underlying storage information is not compatible with Unix systems or an error occurs during retrieval, the method returns false and info is set to its default value.
Represents units of measurement for data storage sizes.
public enum UOM| Field | Description |
|---|---|
| Bytes | Bytes unit of measurement. |
| KB | Kilobytes unit of measurement. |
| MB | Megabytes unit of measurement. |
| GB | Gigabytes unit of measurement. |
| TB | Terabytes unit of measurement. |
The following example demonstrates accessing basic storage properties:
using Rheo.Storage.Information;
var fileInfo = new FileInformation(@"C:\Documents\photo.jpg");
Console.WriteLine($"Display Name: {fileInfo.DisplayName}");
Console.WriteLine($"Size: {fileInfo.FormattedSize}");
Console.WriteLine($"Created: {fileInfo.CreationTime}");
Console.WriteLine($"Modified: {fileInfo.LastWriteTime}");
Console.WriteLine($"Is Hidden: {fileInfo.IsHidden}");
Console.WriteLine($"Is Read-Only: {fileInfo.IsReadOnly}");The following example shows how to work with symbolic links:
using Rheo.Storage.Information;
var fileInfo = new FileInformation(@"C:\Links\shortcut.lnk");
if (fileInfo.IsSymbolicLink)
{
Console.WriteLine($"This is a symbolic link pointing to: {fileInfo.LinkTarget}");
}
else
{
Console.WriteLine("This is not a symbolic link.");
}The following example demonstrates accessing platform-specific details:
using Rheo.Storage.Information;
var fileInfo = new FileInformation(@"C:\Documents\file.txt");
if (OperatingSystem.IsWindows() && fileInfo.OwnerSid != null)
{
Console.WriteLine($"Owner SID: {fileInfo.OwnerSid}");
}
else if ((OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) && fileInfo.OwnerId.HasValue)
{
Console.WriteLine($"Owner UID: {fileInfo.OwnerId}");
Console.WriteLine($"Group GID: {fileInfo.GroupId}");
Console.WriteLine($"Mode: {fileInfo.Mode:X}");
}Property access is thread-safe. The underlying storage information is retrieved asynchronously but is cached once loaded.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress