From 6a79a80932860b9c3ec78fcdd0d169d2efa09005 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 21 Jun 2023 10:55:04 -0500 Subject: add types to represent files and dirs --- src/slskd/Files/Types/FilesystemDirectory.cs | 47 ++++++++++++++++++++++++++++ src/slskd/Files/Types/FilesystemFile.cs | 47 ++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/slskd/Files/Types/FilesystemDirectory.cs create mode 100644 src/slskd/Files/Types/FilesystemFile.cs diff --git a/src/slskd/Files/Types/FilesystemDirectory.cs b/src/slskd/Files/Types/FilesystemDirectory.cs new file mode 100644 index 00000000..020b688c --- /dev/null +++ b/src/slskd/Files/Types/FilesystemDirectory.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Files +{ + using System; + using System.Collections.Generic; + using System.IO; + + public record FilesystemDirectory + { + public string Parent { get; init; } + public string Name { get; init; } + public string FullName { get; init; } + public FileAttributes Attributes { get; init; } + public DateTime CreatedAt { get; init; } + public DateTime ModifiedAt { get; init; } + public IEnumerable Files { get; init; } + + public static FilesystemDirectory FromDirectoryInfo(DirectoryInfo i) + { + return new FilesystemDirectory + { + Parent = Path.GetDirectoryName(i.FullName), + Name = i.Name, + FullName = i.FullName, + Attributes = i.Attributes, + CreatedAt = i.CreationTimeUtc, + ModifiedAt = i.LastWriteTimeUtc, + }; + } + } +} diff --git a/src/slskd/Files/Types/FilesystemFile.cs b/src/slskd/Files/Types/FilesystemFile.cs new file mode 100644 index 00000000..44242582 --- /dev/null +++ b/src/slskd/Files/Types/FilesystemFile.cs @@ -0,0 +1,47 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Files +{ + using System; + using System.IO; + + public record FilesystemFile + { + public string Parent { get; init; } + public string Name { get; init; } + public string FullName { get; init; } + public long Length { get; init; } + public FileAttributes Attributes { get; init; } + public DateTime CreatedAt { get; init; } + public DateTime ModifiedAt { get; init; } + + public static FilesystemFile FromFileInfo(FileInfo i) + { + return new FilesystemFile + { + Parent = Path.GetDirectoryName(i.FullName), + Name = i.Name, + FullName = i.FullName, + Length = i.Length, + Attributes = i.Attributes, + CreatedAt = i.CreationTimeUtc, + ModifiedAt = i.LastWriteTimeUtc, + }; + } + } +} -- cgit v1.2.3