diff options
| author | JP Dillingham <jp@dillingham.me> | 2023-06-21 10:55:04 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2023-06-21 10:55:04 -0500 |
| commit | 6a79a80932860b9c3ec78fcdd0d169d2efa09005 (patch) | |
| tree | 135b5cefe2ae7131471f28cf8977afe10ff2009e | |
| parent | a2ed01bf2610a8f615ef725322496cf910c39fe9 (diff) | |
| download | slskd-6a79a80932860b9c3ec78fcdd0d169d2efa09005.tar.gz | |
add types to represent files and dirs
| -rw-r--r-- | src/slskd/Files/Types/FilesystemDirectory.cs | 47 | ||||
| -rw-r--r-- | src/slskd/Files/Types/FilesystemFile.cs | 47 |
2 files changed, 94 insertions, 0 deletions
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 file="FilesystemDirectory.cs" company="slskd Team"> +// 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/. +// </copyright> + +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<FilesystemFile> 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 file="FilesystemFile.cs" company="slskd Team"> +// 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/. +// </copyright> + +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, + }; + } + } +} |
