114 lines
5.0 KiB
C#
114 lines
5.0 KiB
C#
/*
|
|
* VirtualFS - Virtual File System library.
|
|
* Copyright (c) 2013-2026, Grzegorz Russek (grzegorz.russek@gmail.com)
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
using System;
|
|
|
|
namespace VirtualFS
|
|
{
|
|
/// <summary>Basic file system entry.</summary>
|
|
public class Entry
|
|
{
|
|
/// <summary>Gets file system on which entry is located.</summary>
|
|
public virtual IFileSystem FileSystem { get; internal set; }
|
|
|
|
/// <summary>Gets a value indicating whether this entry is read only.</summary>
|
|
public virtual bool IsReadOnly { get; internal set; }
|
|
|
|
/// <summary>Gets a value indicating whether this is a directory entry.</summary>
|
|
public virtual bool IsDirectory { get; internal set; }
|
|
|
|
/// <summary>Gets path to entry on local file system.</summary>
|
|
public virtual Path Path { get; internal set; }
|
|
|
|
/// <summary>Gets full path to entry including mount point.</summary>
|
|
public Path FullPath { get { return (FileSystem == null || FileSystem.RootFileSystem == null) ? null : Path.AddParent(FileSystem.RootFileSystem.GetMountPath(FileSystem)); } }
|
|
|
|
/// <summary>Gets or sets the creation time, in coordinated universal time (UTC), of the current file or directory.</summary>
|
|
public virtual DateTime CreationTime { get; set; }
|
|
|
|
/// <summary>Gets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed.</summary>
|
|
public virtual DateTime LastAccessTime { get; set; }
|
|
|
|
/// <summary>Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to.</summary>
|
|
public DateTime LastWriteTime { get; set; }
|
|
|
|
/// <summary>Gets or sets additional internal data for file system entry.</summary>
|
|
internal object Data { get; set; }
|
|
|
|
/// <summary>Updates information about file.</summary>
|
|
public virtual void UpdateInfo()
|
|
{
|
|
var up = IsDirectory ? FileSystem.GetDirectory(Path) : FileSystem.GetEntry(Path);
|
|
|
|
if (up != null)
|
|
{
|
|
IsReadOnly = up.IsReadOnly;
|
|
IsDirectory = up.IsDirectory;
|
|
CreationTime = up.CreationTime;
|
|
LastAccessTime = up.LastAccessTime;
|
|
LastWriteTime = up.LastWriteTime;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether the specified <see cref="System.Object" /> is equal to this instance.
|
|
/// </summary>
|
|
/// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
|
|
/// <returns> Returns <c>true</c> if the specified <see cref="System.Object" />
|
|
/// is equal to this instance; otherwise, <c>false</c>.</returns>
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (obj is Entry)
|
|
return Equals((Entry)obj);
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines whether the specified <see cref="Entry" /> is equal to this instance.
|
|
/// </summary>
|
|
/// <param name="other">The <see cref="Entry" /> to compare with this instance.</param>
|
|
/// <returns>Returns <c>true</c> if the specified <see cref="Entry" /> is equal
|
|
/// to this instance; otherwise, <c>false</c>.</returns>
|
|
public bool Equals(Entry other)
|
|
{
|
|
return other.Path.Equals(Path);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a hash code for this instance.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
|
/// </returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return Path.GetHashCode();
|
|
}
|
|
}
|
|
} |