mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-12 04:18:09 +02:00
Moved FileSystem declarations to DiskAccessLibrary.FileSystems.Abstractions
This commit is contained in:
parent
e1d06e72da
commit
f1c34e9b14
16 changed files with 133 additions and 22 deletions
|
@ -0,0 +1,47 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9119EC7E-AF78-4814-BF03-F3823A29A471}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DiskAccessLibrary.FileSystems.Abstractions</RootNamespace>
|
||||
<AssemblyName>DiskAccessLibrary.FileSystems.Abstractions</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileSystem.cs" />
|
||||
<Compile Include="FileSystemEntry.cs" />
|
||||
<Compile Include="IFileSystem.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,19 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net20;net40;netstandard2.0</TargetFrameworks>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AssemblyName>DiskAccessLibrary.FileSystems.Abstractions</AssemblyName>
|
||||
<Version>1.0.0</Version>
|
||||
<NoWarn>1573;1591</NoWarn>
|
||||
<RootNamespace>DiskAccessLibrary.FileSystems.Abstractions</RootNamespace>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Authors>Tal Aloni</Authors>
|
||||
<PackageDescription>DiskAccessLibrary abstractions and interfaces for FileSystem implementations</PackageDescription>
|
||||
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
|
||||
<PackageProjectUrl>https://github.com/TalAloni/DynamicDiskPartitioner</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/TalAloni/DynamicDiskPartitioner</RepositoryUrl>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
154
DiskAccessLibrary.FileSystems.Abstractions/FileSystem.cs
Normal file
154
DiskAccessLibrary.FileSystems.Abstractions/FileSystem.cs
Normal file
|
@ -0,0 +1,154 @@
|
|||
/* Copyright (C) 2014-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||
*
|
||||
* You can redistribute this program and/or modify it under the terms of
|
||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace DiskAccessLibrary.FileSystems.Abstractions
|
||||
{
|
||||
public abstract class FileSystem : IFileSystem
|
||||
{
|
||||
public abstract FileSystemEntry GetEntry(string path);
|
||||
public abstract FileSystemEntry CreateFile(string path);
|
||||
public abstract FileSystemEntry CreateDirectory(string path);
|
||||
public abstract void Move(string source, string destination);
|
||||
public abstract void Delete(string path);
|
||||
public abstract List<FileSystemEntry> ListEntriesInDirectory(string path);
|
||||
public abstract Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share, FileOptions options);
|
||||
public abstract void SetAttributes(string path, bool? isHidden, bool? isReadonly, bool? isArchived);
|
||||
public abstract void SetDates(string path, DateTime? creationDT, DateTime? lastWriteDT, DateTime? lastAccessDT);
|
||||
|
||||
public List<FileSystemEntry> ListEntriesInRootDirectory()
|
||||
{
|
||||
return ListEntriesInDirectory(@"\");
|
||||
}
|
||||
|
||||
public virtual List<KeyValuePair<string, ulong>> ListDataStreams(string path)
|
||||
{
|
||||
FileSystemEntry entry = GetEntry(path);
|
||||
List<KeyValuePair<string, ulong>> result = new List<KeyValuePair<string, ulong>>();
|
||||
if (!entry.IsDirectory)
|
||||
{
|
||||
result.Add(new KeyValuePair<string, ulong>("::$DATA", entry.Size));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share)
|
||||
{
|
||||
return OpenFile(path, mode, access, share, FileOptions.None);
|
||||
}
|
||||
|
||||
public void CopyFile(string sourcePath, string destinationPath)
|
||||
{
|
||||
const int bufferLength = 1024 * 1024;
|
||||
FileSystemEntry sourceFile = GetEntry(sourcePath);
|
||||
FileSystemEntry destinationFile = GetEntry(destinationPath);
|
||||
if (sourceFile == null | sourceFile.IsDirectory)
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
if (destinationFile != null && destinationFile.IsDirectory)
|
||||
{
|
||||
throw new ArgumentException("Destination cannot be a directory");
|
||||
}
|
||||
|
||||
if (destinationFile == null)
|
||||
{
|
||||
destinationFile = CreateFile(destinationPath);
|
||||
}
|
||||
Stream sourceStream = OpenFile(sourcePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, FileOptions.SequentialScan);
|
||||
Stream destinationStream = OpenFile(destinationPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, FileOptions.None);
|
||||
while (sourceStream.Position < sourceStream.Length)
|
||||
{
|
||||
int readSize = (int)Math.Max(bufferLength, sourceStream.Length - sourceStream.Position);
|
||||
byte[] buffer = new byte[readSize];
|
||||
sourceStream.Read(buffer, 0, buffer.Length);
|
||||
destinationStream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
sourceStream.Close();
|
||||
destinationStream.Close();
|
||||
}
|
||||
|
||||
public virtual bool Exists(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetEntry(path);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract long Size
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract long FreeSpace
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public abstract bool SupportsNamedStreams
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
public static string GetParentDirectory(string path)
|
||||
{
|
||||
if (path == String.Empty)
|
||||
{
|
||||
path = @"\";
|
||||
}
|
||||
|
||||
if (!path.StartsWith(@"\"))
|
||||
{
|
||||
throw new ArgumentException("Invalid path");
|
||||
}
|
||||
|
||||
if (path.Length > 1 && path.EndsWith(@"\"))
|
||||
{
|
||||
path = path.Substring(0, path.Length - 1);
|
||||
}
|
||||
|
||||
int separatorIndex = path.LastIndexOf(@"\");
|
||||
return path.Substring(0, separatorIndex + 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will append a trailing slash to a directory path if not already present
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDirectoryPath(string path)
|
||||
{
|
||||
if (path.EndsWith(@"\"))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
else
|
||||
{
|
||||
return path + @"\";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/* Copyright (C) 2014-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||
*
|
||||
* You can redistribute this program and/or modify it under the terms of
|
||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace DiskAccessLibrary.FileSystems.Abstractions
|
||||
{
|
||||
public class FileSystemEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// Full Path. Directory path should end with a trailing slash.
|
||||
/// </summary>
|
||||
public string FullName;
|
||||
public string Name;
|
||||
public bool IsDirectory;
|
||||
public ulong Size;
|
||||
public DateTime CreationTime;
|
||||
public DateTime LastWriteTime;
|
||||
public DateTime LastAccessTime;
|
||||
public bool IsHidden;
|
||||
public bool IsReadonly;
|
||||
public bool IsArchived;
|
||||
|
||||
public FileSystemEntry(string fullName, string name, bool isDirectory, ulong size, DateTime creationTime, DateTime lastWriteTime, DateTime lastAccessTime, bool isHidden, bool isReadonly, bool isArchived)
|
||||
{
|
||||
FullName = fullName;
|
||||
Name = name;
|
||||
IsDirectory = isDirectory;
|
||||
Size = size;
|
||||
CreationTime = creationTime;
|
||||
LastWriteTime = lastWriteTime;
|
||||
LastAccessTime = lastAccessTime;
|
||||
IsHidden = isHidden;
|
||||
IsReadonly = isHidden;
|
||||
IsArchived = isHidden;
|
||||
|
||||
if (isDirectory)
|
||||
{
|
||||
FullName = FileSystem.GetDirectoryPath(FullName);
|
||||
}
|
||||
}
|
||||
|
||||
public FileSystemEntry Clone()
|
||||
{
|
||||
FileSystemEntry clone = (FileSystemEntry)MemberwiseClone();
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
96
DiskAccessLibrary.FileSystems.Abstractions/IFileSystem.cs
Normal file
96
DiskAccessLibrary.FileSystems.Abstractions/IFileSystem.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
/* Copyright (C) 2014-2020 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||
*
|
||||
* You can redistribute this program and/or modify it under the terms of
|
||||
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later version.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace DiskAccessLibrary.FileSystems.Abstractions
|
||||
{
|
||||
public interface IFileSystem
|
||||
{
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
FileSystemEntry GetEntry(string path);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
FileSystemEntry CreateFile(string path);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
FileSystemEntry CreateDirectory(string path);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
void Move(string source, string destination);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
void Delete(string path);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
List<FileSystemEntry> ListEntriesInDirectory(string path);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
List<KeyValuePair<string, ulong>> ListDataStreams(string path);
|
||||
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
Stream OpenFile(string path, FileMode mode, FileAccess access, FileShare share, FileOptions options);
|
||||
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
void SetAttributes(string path, bool? isHidden, bool? isReadonly, bool? isArchived);
|
||||
|
||||
/// <exception cref="System.IO.FileNotFoundException"></exception>
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
/// <exception cref="System.UnauthorizedAccessException"></exception>
|
||||
void SetDates(string path, DateTime? creationDT, DateTime? lastWriteDT, DateTime? lastAccessDT);
|
||||
|
||||
string Name
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
long Size
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <exception cref="System.IO.IOException"></exception>
|
||||
long FreeSpace
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates support for opening named streams (alternate data streams).
|
||||
/// Named streams are opened using the filename:stream syntax.
|
||||
/// </summary>
|
||||
bool SupportsNamedStreams
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DiskAccessLibrary.FileSystems.Abstractions")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Tal Aloni")]
|
||||
[assembly: AssemblyProduct("DiskAccessLibrary.FileSystems.Abstractions")]
|
||||
[assembly: AssemblyCopyright("Copyright © Tal Aloni 2012-2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e71e5d6b-84ac-4889-810a-d18c2f6fbcbe")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
Loading…
Add table
Add a link
Reference in a new issue