Replace DiskAccessLibrary.FileSystems.Abstractions with NuGet package reference

This commit is contained in:
Tal Aloni 2024-02-17 14:28:19 +02:00
parent db1410b74d
commit 5dff3875b6
6 changed files with 4 additions and 328 deletions

View file

@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net20;net40;netstandard2.0</TargetFrameworks>
<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>
<Copyright>Copyright © Tal Aloni 2012-2023</Copyright>
<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>

View file

@ -1,154 +0,0 @@
/* 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 + @"\";
}
}
}
}

View file

@ -1,52 +0,0 @@
/* 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;
}
}
}

View file

@ -1,96 +0,0 @@
/* 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;
}
}
}

View file

@ -16,8 +16,11 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DiskAccessLibrary.FileSystems.Abstractions\DiskAccessLibrary.FileSystems.Abstractions.csproj" />
<ProjectReference Include="..\SMBLibrary\SMBLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DiskAccessLibrary" Version="1.6.1" />
</ItemGroup>
</Project>

View file

@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiskAccessLibrary.FileSystems.Abstractions", "DiskAccessLibrary.FileSystems.Abstractions\DiskAccessLibrary.FileSystems.Abstractions.csproj", "{9119EC7E-AF78-4814-BF03-F3823A29A471}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utilities", "Utilities\Utilities.csproj", "{6E0F2D1E-6167-4032-BA90-DEE3A99207D0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMBLibrary", "SMBLibrary\SMBLibrary.csproj", "{8D9E8F5D-FD13-4E4C-9723-A333DA2034A7}"
@ -23,10 +21,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9119EC7E-AF78-4814-BF03-F3823A29A471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9119EC7E-AF78-4814-BF03-F3823A29A471}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9119EC7E-AF78-4814-BF03-F3823A29A471}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9119EC7E-AF78-4814-BF03-F3823A29A471}.Release|Any CPU.Build.0 = Release|Any CPU
{6E0F2D1E-6167-4032-BA90-DEE3A99207D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6E0F2D1E-6167-4032-BA90-DEE3A99207D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6E0F2D1E-6167-4032-BA90-DEE3A99207D0}.Release|Any CPU.ActiveCfg = Release|Any CPU